mirror of
https://github.com/darksaid98/overextended.github.io.git
synced 2026-12-03 06:28:53 +00:00
Updated docs for oxmysql
This commit is contained in:
1 parent
b174c89d66
commit
81223ffd47
5 files changed
+52
-11
No files matched your search
@@ -0,0 +1,11 @@
|
|||||||
|
# Placeholders
|
||||||
|
|
||||||
|
This allows queries to be properly prepared and escaped; the following lines are equivalent.
|
||||||
|
|
||||||
|
```
|
||||||
|
"SELECT group FROM users WHERE identifier = ?", {identifier}
|
||||||
|
"SELECT group FROM users WHERE identifier = :identifier", {identifier = identifier}
|
||||||
|
"SELECT group FROM users WHERE identifier = @identifier", {['@identifier'] = identifier}
|
||||||
|
```
|
||||||
|
|
||||||
|
Named placeholders are deprecated and should be avoided as much as possible.
|
||||||
@@ -2,4 +2,28 @@
|
|||||||
title: Usage
|
title: Usage
|
||||||
---
|
---
|
||||||
|
|
||||||
todo - include some information about proper formatting, placeholders, bad practices, etc.
|
```lua
|
||||||
|
-- Lua
|
||||||
|
MySQL.query('SELECT * from users WHERE identifier = ?', {identifier}, function(result)
|
||||||
|
-- callback response
|
||||||
|
-- same as MySQL.Async.fetchAll
|
||||||
|
end)
|
||||||
|
CreateThread(function()
|
||||||
|
local result = MySQL.query.await('SELECT * from users WHERE identifier = ?', {identifier})
|
||||||
|
-- await a promise to resolve
|
||||||
|
-- same as MySQL.Sync.fetchAll
|
||||||
|
end)
|
||||||
|
```
|
||||||
|
|
||||||
|
```js
|
||||||
|
// JS
|
||||||
|
exports.oxmysql.query('SELECT * from users WHERE identifier = ?', [identifier], (result) => {
|
||||||
|
// callback response
|
||||||
|
})(async () => {
|
||||||
|
const result = await exports.oxmysql.query_async('SELECT * from users WHERE identifier = ?', [identifier]);
|
||||||
|
// await a promise to resolve
|
||||||
|
})();
|
||||||
|
exports.oxmysql.query_async('SELECT * from users WHERE identifier = ?', [identifier]).then((result) => {
|
||||||
|
// utilise .then to resolve a promise like a callback
|
||||||
|
});
|
||||||
|
```
|
||||||
@@ -19,7 +19,7 @@ end)
|
|||||||
```
|
```
|
||||||
### Promise
|
### Promise
|
||||||
```lua
|
```lua
|
||||||
-- Alias: exports.oxmysql:query
|
-- Alias: exports.oxmysql:query_async
|
||||||
-- Alias: MySQL.Sync.query
|
-- Alias: MySQL.Sync.query
|
||||||
|
|
||||||
CreateThread(function()
|
CreateThread(function()
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
# Transaction
|
# Transaction
|
||||||
todo - update formatting and information
|
|
||||||
|
|
||||||
|
|
||||||
## Transactions
|
## Transactions
|
||||||
A transaction executes multiple queries and commits them only if all succeed. If one fails, none of the queries are committed. The return value is a `boolean`, which is the result of the transaction.
|
A transaction executes multiple queries and commits them only if all succeed. If one fails, none of the queries are committed. The return value is a `boolean`, which is the result of the transaction.
|
||||||
@@ -19,12 +17,16 @@ local queries = {
|
|||||||
} -- NOTE, the 'values' tables can be named 'parameters' here for MySQL-Async compatibility.
|
} -- NOTE, the 'values' tables can be named 'parameters' here for MySQL-Async compatibility.
|
||||||
|
|
||||||
-- Async
|
-- Async
|
||||||
exports.oxmysql:transaction(queries, function(result)
|
-- Alias: exports.oxmysql:transaction
|
||||||
|
-- Alias: MySQL.Async.transaction
|
||||||
|
MySQL.transaction(queries, function(result)
|
||||||
print(result)
|
print(result)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- Sync
|
-- Sync
|
||||||
local result = exports.oxmysql:transactionSync(queries)
|
-- Alias: exports.oxmysql:transaction_async
|
||||||
|
-- Alias: MySQL.Sync.transaction
|
||||||
|
local result = MySQL.transaction.await(queries)
|
||||||
print(result)
|
print(result)
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -59,12 +61,16 @@ local queries = {
|
|||||||
local parameters = { ['someid'] = 2, ['somename'] = 'John Doe', ['newname'] = 'John Notdoe' }
|
local parameters = { ['someid'] = 2, ['somename'] = 'John Doe', ['newname'] = 'John Notdoe' }
|
||||||
|
|
||||||
-- Async
|
-- Async
|
||||||
exports.oxmysql:transaction(queries, parameters, function(result)
|
-- Alias: exports.oxmysql:transaction
|
||||||
|
-- Alias: MySQL.Async.transaction
|
||||||
|
MySQL.transaction(queries, parameters, function(result)
|
||||||
print(result)
|
print(result)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- Sync
|
-- Sync
|
||||||
local result = exports.oxmysql:transactionSync(queries, parameters)
|
-- Alias: exports.oxmysql:transaction_async
|
||||||
|
-- Alias: MySQL.Sync.transaction
|
||||||
|
local result = MySQL.transaction.await(queries, parameters)
|
||||||
print(result)
|
print(result)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -6,9 +6,9 @@ Returns the number of affected rows by the query.
|
|||||||
### Callback
|
### Callback
|
||||||
```lua
|
```lua
|
||||||
-- Alias: exports.oxmysql:update
|
-- Alias: exports.oxmysql:update
|
||||||
-- Alias: MySQL.Async.update
|
-- Alias: MySQL.Async.execute
|
||||||
|
|
||||||
MySQL.Async.update('UPDATE users SET firstname = ? WHERE identifier = ? ', {newName, playerIdentifier}, function(affectedRows)
|
MySQL.update('UPDATE users SET firstname = ? WHERE identifier = ?', {newName, playerIdentifier}, function(affectedRows)
|
||||||
if affectedRows then
|
if affectedRows then
|
||||||
print(affectedRows)
|
print(affectedRows)
|
||||||
end
|
end
|
||||||
@@ -18,7 +18,7 @@ end)
|
|||||||
### Promise
|
### Promise
|
||||||
```lua
|
```lua
|
||||||
-- Alias: exports.oxmysql:update_async
|
-- Alias: exports.oxmysql:update_async
|
||||||
-- Alias: MySQL.update
|
-- Alias: MySQL.Sync.execute
|
||||||
|
|
||||||
CreateThread(function()
|
CreateThread(function()
|
||||||
local affectedRows = MySQL.update.await('UPDATE users SET firstname = ? WHERE identifier = ?', {newName, playerIdentifier})
|
local affectedRows = MySQL.update.await('UPDATE users SET firstname = ? WHERE identifier = ?', {newName, playerIdentifier})
|
||||||
|
|||||||
Reference in new issue
Block a user