mirror of
https://github.com/darksaid98/oxmysql.git
synced 2026-12-03 14:38:50 +00:00
update syntax and include aliases
This commit is contained in:
1 parent
6cf83ac4d1
commit
e6da9843ea
8 files changed
+73
-24
No files matched your search
+1
-1
@@ -2,4 +2,4 @@
|
|||||||
title: Index
|
title: Index
|
||||||
---
|
---
|
||||||
|
|
||||||
todo: include some information about proper formatting, placeholders, bad practices, etc.
|
todo - include some information about proper formatting, placeholders, bad practices, etc.
|
||||||
+11
-3
@@ -5,24 +5,32 @@ Inserts a new entry into the database and returns the insert id for the row, if
|
|||||||
|
|
||||||
!!! info "Example"
|
!!! info "Example"
|
||||||
=== "Lua"
|
=== "Lua"
|
||||||
|
|
||||||
**Callback**
|
**Callback**
|
||||||
```lua
|
```lua
|
||||||
MySQL.Async.insert('INSERT INTO users (identifier, firstname, lastname) VALUES (?, ?, ?) ', {playerIdentifier, firstName, lastName}, function(id)
|
-- Alias: exports.oxmysql:insert
|
||||||
|
-- Alias: MySQL.Async.insert
|
||||||
|
|
||||||
|
MySQL.insert('INSERT INTO users (identifier, firstname, lastname) VALUES (?, ?, ?) ', {playerIdentifier, firstName, lastName}, function(id)
|
||||||
print(id)
|
print(id)
|
||||||
end)
|
end)
|
||||||
```
|
```
|
||||||
**Promise**
|
**Promise**
|
||||||
```lua
|
```lua
|
||||||
|
-- Alias: exports.oxmysql:insert_async
|
||||||
|
-- Alias: MySQL.Sync.insert
|
||||||
|
|
||||||
CreateThread(function()
|
CreateThread(function()
|
||||||
local id = MySQL.Sync.insert('INSERT INTO users (identifier, firstname, lastname) VALUES (?, ?, ?) ', {playerIdentifier, firstName, lastName})
|
local id = MySQL.insert.await('INSERT INTO users (identifier, firstname, lastname) VALUES (?, ?, ?) ', {playerIdentifier, firstName, lastName})
|
||||||
print(id)
|
print(id)
|
||||||
end)
|
end)
|
||||||
```
|
```
|
||||||
|
|
||||||
=== "JavaScript"
|
=== "JavaScript"
|
||||||
|
|
||||||
**Callback**
|
**Callback**
|
||||||
```js
|
```js
|
||||||
exports.oxmysql.insert_callback('INSERT INTO users (identifier, firstname, lastname) VALUES (?, ?, ?) ', [playerIdentifier, firstName, lastName], function(id) {
|
exports.oxmysql.insert('INSERT INTO users (identifier, firstname, lastname) VALUES (?, ?, ?) ', [playerIdentifier, firstName, lastName], function(id) {
|
||||||
console.log(id)
|
console.log(id)
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|||||||
+13
-4
@@ -12,9 +12,13 @@ When using SELECT, the return value will match `fetchAll, fetchSingle, or fetchS
|
|||||||
|
|
||||||
!!! info "Example"
|
!!! info "Example"
|
||||||
=== "Lua"
|
=== "Lua"
|
||||||
|
|
||||||
**Callback**
|
**Callback**
|
||||||
```lua
|
```lua
|
||||||
MySQL.Async.prepare('SELECT * FROM users WHERE identifier = ?', {playerIdentifier}, function(result)
|
-- Alias: exports.oxmysql:prepare
|
||||||
|
-- Alias: MySQL.Async.prepare
|
||||||
|
|
||||||
|
MySQL.prepare('SELECT * FROM users WHERE identifier = ?', {playerIdentifier}, function(result)
|
||||||
if result then
|
if result then
|
||||||
for _, v in pairs(result) do
|
for _, v in pairs(result) do
|
||||||
print(v.identifier, v.firstname, v.lastname)
|
print(v.identifier, v.firstname, v.lastname)
|
||||||
@@ -24,8 +28,12 @@ When using SELECT, the return value will match `fetchAll, fetchSingle, or fetchS
|
|||||||
```
|
```
|
||||||
**Promise**
|
**Promise**
|
||||||
```lua
|
```lua
|
||||||
|
-- Alias: exports.oxmysql:prepare_async
|
||||||
|
-- Alias: MySQL.Sync.prepare
|
||||||
|
|
||||||
|
|
||||||
CreateThread(function()
|
CreateThread(function()
|
||||||
local result = MySQL.Sync.prepare('SELECT * FROM users WHERE identifier = ?', {playerIdentifier})
|
local result = MySQL.prepare.await('SELECT * FROM users WHERE identifier = ?', {playerIdentifier})
|
||||||
if result then
|
if result then
|
||||||
for _, v in pairs(result) do
|
for _, v in pairs(result) do
|
||||||
print(v.identifier, v.firstname, v.lastname)
|
print(v.identifier, v.firstname, v.lastname)
|
||||||
@@ -35,9 +43,10 @@ When using SELECT, the return value will match `fetchAll, fetchSingle, or fetchS
|
|||||||
```
|
```
|
||||||
|
|
||||||
=== "JavaScript"
|
=== "JavaScript"
|
||||||
|
|
||||||
**Callback**
|
**Callback**
|
||||||
```js
|
```js
|
||||||
exports.oxmysql.execute_callback('SELECT * FROM users WHERE identifier = ?', [playerIdentifier], function(result) {
|
exports.oxmysql.prepare('SELECT * FROM users WHERE identifier = ?', [playerIdentifier], function(result) {
|
||||||
if (result) {
|
if (result) {
|
||||||
result.forEach((v) => {
|
result.forEach((v) => {
|
||||||
console.log(v.identifier, v.firstname, v.lastname)
|
console.log(v.identifier, v.firstname, v.lastname)
|
||||||
@@ -48,7 +57,7 @@ When using SELECT, the return value will match `fetchAll, fetchSingle, or fetchS
|
|||||||
**Promise**
|
**Promise**
|
||||||
```js
|
```js
|
||||||
(async () => {
|
(async () => {
|
||||||
const result = await exports.oxmysql.execute_async('SELECT * FROM users WHERE identifier = ?', [playerIdentifier]) {
|
const result = await exports.oxmysql.prepare_async('SELECT * FROM users WHERE identifier = ?', [playerIdentifier]) {
|
||||||
if (result) {
|
if (result) {
|
||||||
result.forEach((v) => {
|
result.forEach((v) => {
|
||||||
console.log(v.identifier, v.firstname, v.lastname)
|
console.log(v.identifier, v.firstname, v.lastname)
|
||||||
|
|||||||
@@ -1,14 +1,18 @@
|
|||||||
---
|
---
|
||||||
title: fetchAll
|
title: query
|
||||||
---
|
---
|
||||||
Generic function that can be utilised for any query.
|
Generic function that can be utilised for any query.
|
||||||
When selecting data it will return all matching rows and columns, otherwise it will return field data such as insertid, affectedRows, etc.
|
When selecting data it will return all matching rows and columns, otherwise it will return field data such as insertid, affectedRows, etc.
|
||||||
|
|
||||||
!!! info "Example"
|
!!! info "Example"
|
||||||
=== "Lua"
|
=== "Lua"
|
||||||
|
|
||||||
**Callback**
|
**Callback**
|
||||||
```lua
|
```lua
|
||||||
MySQL.Async.fetchAll('SELECT * FROM users WHERE identifier = ?', {playerIdentifier}, function(result)
|
-- Alias: exports.oxmysql:query
|
||||||
|
-- Alias: MySQL.Async.query
|
||||||
|
|
||||||
|
MySQL.query('SELECT * FROM users WHERE identifier = ?', {playerIdentifier}, function(result)
|
||||||
if result then
|
if result then
|
||||||
for _, v in pairs(result) do
|
for _, v in pairs(result) do
|
||||||
print(v.identifier, v.firstname, v.lastname)
|
print(v.identifier, v.firstname, v.lastname)
|
||||||
@@ -18,8 +22,11 @@ When selecting data it will return all matching rows and columns, otherwise it w
|
|||||||
```
|
```
|
||||||
**Promise**
|
**Promise**
|
||||||
```lua
|
```lua
|
||||||
|
-- Alias: exports.oxmysql:query
|
||||||
|
-- Alias: MySQL.Sync.query
|
||||||
|
|
||||||
CreateThread(function()
|
CreateThread(function()
|
||||||
local result = MySQL.Sync.fetchAll('SELECT * FROM users WHERE identifier = ?', {playerIdentifier})
|
local result = MySQL.query.await('SELECT * FROM users WHERE identifier = ?', {playerIdentifier})
|
||||||
if result then
|
if result then
|
||||||
for _, v in pairs(result) do
|
for _, v in pairs(result) do
|
||||||
print(v.identifier, v.firstname, v.lastname)
|
print(v.identifier, v.firstname, v.lastname)
|
||||||
@@ -29,9 +36,10 @@ When selecting data it will return all matching rows and columns, otherwise it w
|
|||||||
```
|
```
|
||||||
|
|
||||||
=== "JavaScript"
|
=== "JavaScript"
|
||||||
|
|
||||||
**Callback**
|
**Callback**
|
||||||
```js
|
```js
|
||||||
exports.oxmysql.query_callback('SELECT * FROM users WHERE identifier = ?', [playerIdentifier], function(result) {
|
exports.oxmysql.query('SELECT * FROM users WHERE identifier = ?', [playerIdentifier], function(result) {
|
||||||
if (result) {
|
if (result) {
|
||||||
result.forEach((v) => {
|
result.forEach((v) => {
|
||||||
console.log(v.identifier, v.firstname, v.lastname)
|
console.log(v.identifier, v.firstname, v.lastname)
|
||||||
@@ -1,28 +1,36 @@
|
|||||||
---
|
---
|
||||||
title: fetchScalar
|
title: scalar
|
||||||
---
|
---
|
||||||
Returns the first column for a single row.
|
Returns the first column for a single row.
|
||||||
|
|
||||||
!!! info "Example"
|
!!! info "Example"
|
||||||
=== "Lua"
|
=== "Lua"
|
||||||
|
|
||||||
**Callback**
|
**Callback**
|
||||||
```lua
|
```lua
|
||||||
MySQL.Async.fetchScalar('SELECT firstname FROM users WHERE identifier = ?', {playerIdentifier}, function(firstname)
|
-- Alias: exports.oxmysql:scalar
|
||||||
|
-- Alias: MySQL.Async.fetchScalar
|
||||||
|
|
||||||
|
MySQL.scalar('SELECT firstname FROM users WHERE identifier = ?', {playerIdentifier}, function(firstname)
|
||||||
print(firstname)
|
print(firstname)
|
||||||
end)
|
end)
|
||||||
```
|
```
|
||||||
**Promise**
|
**Promise**
|
||||||
```lua
|
```lua
|
||||||
|
-- Alias: exports.oxmysql:scalar_async
|
||||||
|
-- Alias: MySQL.Sync.fetchScalar
|
||||||
|
|
||||||
CreateThread(function()
|
CreateThread(function()
|
||||||
local firstname = MySQL.Async.fetchScalar('SELECT firstname FROM users WHERE identifier = ?', {playerIdentifier})
|
local firstname = MySQL.scalar.await('SELECT firstname FROM users WHERE identifier = ?', {playerIdentifier})
|
||||||
print(firstname)
|
print(firstname)
|
||||||
end)
|
end)
|
||||||
```
|
```
|
||||||
|
|
||||||
=== "JavaScript"
|
=== "JavaScript"
|
||||||
|
|
||||||
**Callback**
|
**Callback**
|
||||||
```js
|
```js
|
||||||
exports.oxmysql.scalar_callback('SELECT firstname FROM users WHERE identifier = ?', [playerIdentifier], function(firstname) {
|
exports.oxmysql.scalar('SELECT firstname FROM users WHERE identifier = ?', [playerIdentifier], function(firstname) {
|
||||||
console.log(firstname)
|
console.log(firstname)
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
@@ -1,13 +1,17 @@
|
|||||||
---
|
---
|
||||||
title: fetchSingle
|
title: single
|
||||||
---
|
---
|
||||||
Returns the columns for a single row.
|
Returns the columns for a single row.
|
||||||
|
|
||||||
!!! info "Example"
|
!!! info "Example"
|
||||||
=== "Lua"
|
=== "Lua"
|
||||||
|
|
||||||
**Callback**
|
**Callback**
|
||||||
```lua
|
```lua
|
||||||
MySQL.Async.fetchSingle('SELECT * FROM users WHERE identifier = ?', {playerIdentifier}, function(result)
|
-- Alias: exports.oxmysql:single
|
||||||
|
-- Alias: MySQL.Async.fetchSingle
|
||||||
|
|
||||||
|
MySQL.single('SELECT * FROM users WHERE identifier = ?', {playerIdentifier}, function(result)
|
||||||
if result then
|
if result then
|
||||||
print(result.identifier, result.firstname, result.lastname)
|
print(result.identifier, result.firstname, result.lastname)
|
||||||
end
|
end
|
||||||
@@ -15,8 +19,11 @@ Returns the columns for a single row.
|
|||||||
```
|
```
|
||||||
**Promise**
|
**Promise**
|
||||||
```lua
|
```lua
|
||||||
|
-- Alias: exports.oxmysql:single_async
|
||||||
|
-- Alias: MySQL.Sync.fetchSingle
|
||||||
|
|
||||||
CreateThread(function()
|
CreateThread(function()
|
||||||
local result = MySQL.Sync.fetchSingle('SELECT * FROM users WHERE identifier = ?', {playerIdentifier})
|
local result = MySQL.single.await('SELECT * FROM users WHERE identifier = ?', {playerIdentifier})
|
||||||
if result then
|
if result then
|
||||||
print(result.identifier, result.firstname, result.lastname)
|
print(result.identifier, result.firstname, result.lastname)
|
||||||
end
|
end
|
||||||
@@ -24,9 +31,10 @@ Returns the columns for a single row.
|
|||||||
```
|
```
|
||||||
|
|
||||||
=== "JavaScript"
|
=== "JavaScript"
|
||||||
|
|
||||||
**Callback**
|
**Callback**
|
||||||
```js
|
```js
|
||||||
exports.oxmysql.single_callback('SELECT * FROM users WHERE identifier = ?', [playerIdentifier], function(result) {
|
exports.oxmysql.single('SELECT * FROM users WHERE identifier = ?', [playerIdentifier], function(result) {
|
||||||
if (result)
|
if (result)
|
||||||
console.log(result.identifier, result.firstname, result.lastname)
|
console.log(result.identifier, result.firstname, result.lastname)
|
||||||
})
|
})
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
---
|
---
|
||||||
title: transaction
|
title: transaction
|
||||||
---
|
---
|
||||||
|
todo - update formatting and information
|
||||||
|
|
||||||
|
|
||||||
# Transactions
|
# Transactions
|
||||||
|
|||||||
@@ -1,12 +1,16 @@
|
|||||||
---
|
---
|
||||||
title: execute
|
title: update
|
||||||
---
|
---
|
||||||
Returns the number of affected rows by the query.
|
Returns the number of affected rows by the query.
|
||||||
|
|
||||||
!!! info "Example"
|
!!! info "Example"
|
||||||
=== "Lua"
|
=== "Lua"
|
||||||
|
|
||||||
**Callback**
|
**Callback**
|
||||||
```lua
|
```lua
|
||||||
|
-- Alias: exports.oxmysql:update
|
||||||
|
-- Alias: MySQL.Async.update
|
||||||
|
|
||||||
MySQL.Async.update('UPDATE users SET firstname = ? WHERE identifier = ? ', {newName, playerIdentifier}, function(affectedRows)
|
MySQL.Async.update('UPDATE users SET firstname = ? WHERE identifier = ? ', {newName, playerIdentifier}, function(affectedRows)
|
||||||
if affectedRows then
|
if affectedRows then
|
||||||
print(affectedRows)
|
print(affectedRows)
|
||||||
@@ -15,8 +19,11 @@ Returns the number of affected rows by the query.
|
|||||||
```
|
```
|
||||||
**Promise**
|
**Promise**
|
||||||
```lua
|
```lua
|
||||||
|
-- Alias: exports.oxmysql:update_async
|
||||||
|
-- Alias: MySQL.update
|
||||||
|
|
||||||
CreateThread(function()
|
CreateThread(function()
|
||||||
local id = MySQL.Sync.update('UPDATE users SET firstname = ? WHERE identifier = ? ', {newName, playerIdentifier})
|
local id = MySQL.update.await('UPDATE users SET firstname = ? WHERE identifier = ? ', {newName, playerIdentifier})
|
||||||
if affectedRows then
|
if affectedRows then
|
||||||
print(affectedRows)
|
print(affectedRows)
|
||||||
end
|
end
|
||||||
@@ -24,9 +31,10 @@ Returns the number of affected rows by the query.
|
|||||||
```
|
```
|
||||||
|
|
||||||
=== "JavaScript"
|
=== "JavaScript"
|
||||||
|
|
||||||
**Callback**
|
**Callback**
|
||||||
```js
|
```js
|
||||||
exports.oxmysql.update_callback('UPDATE users SET firstname = ? WHERE identifier = ? ', [newName, playerIdentifier], function(affectedRows) {
|
exports.oxmysql.update('UPDATE users SET firstname = ? WHERE identifier = ? ', [newName, playerIdentifier], function(affectedRows) {
|
||||||
if (affectedRows)
|
if (affectedRows)
|
||||||
console.log(affectedRows)
|
console.log(affectedRows)
|
||||||
})
|
})
|
||||||
Reference in new issue
Block a user