mirror of
https://github.com/darksaid98/overextended.github.io.git
synced 2026-12-01 14:38:50 +00:00
Updated docs for oxmysql
This commit is contained in:
1 parent
b174c89d66
commit
81223ffd47
6 files changed
+60
-19
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
|
||||
---
|
||||
|
||||
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
|
||||
});
|
||||
```
|
||||
@@ -8,7 +8,7 @@ Inserts a new entry into the database and returns the insert id for the row, if
|
||||
```lua
|
||||
-- Alias: exports.oxmysql:insert
|
||||
-- Alias: MySQL.Async.insert
|
||||
MySQL.insert('INSERT INTO users (identifier, firstname, lastname) VALUES (?, ?, ?) ', {playerIdentifier, firstName,lastName}, function(id)
|
||||
MySQL.insert('INSERT INTO users (identifier, firstname, lastname) VALUES (?, ?, ?)', {playerIdentifier, firstName, lastName}, function(id)
|
||||
print(id)
|
||||
end)
|
||||
```
|
||||
@@ -18,7 +18,7 @@ end)
|
||||
-- Alias: exports.oxmysql:insert_async
|
||||
-- Alias: MySQL.Sync.insert
|
||||
CreateThread(function()
|
||||
local id = MySQL.insert.await('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)
|
||||
end)
|
||||
```
|
||||
@@ -27,7 +27,7 @@ end)
|
||||
|
||||
### Callback
|
||||
```js
|
||||
exports.oxmysql.insert('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)
|
||||
})
|
||||
```
|
||||
@@ -35,8 +35,8 @@ exports.oxmysql.insert('INSERT INTO users (identifier, firstname, lastname) VALU
|
||||
### Promise
|
||||
```js
|
||||
(async () => {
|
||||
const id = exports.oxmysql.insert_async('INSERT INTO users (identifier, firstname, lastname) VALUES (?, ?, ?) ',
|
||||
const id = exports.oxmysql.insert_async('INSERT INTO users (identifier, firstname, lastname) VALUES (?, ?, ?)',
|
||||
[playerIdentifier, firstName, lastName]) {
|
||||
console.log(id)
|
||||
})()
|
||||
```
|
||||
```
|
||||
@@ -19,7 +19,7 @@ end)
|
||||
```
|
||||
### Promise
|
||||
```lua
|
||||
-- Alias: exports.oxmysql:query
|
||||
-- Alias: exports.oxmysql:query_async
|
||||
-- Alias: MySQL.Sync.query
|
||||
|
||||
CreateThread(function()
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
# Transaction
|
||||
todo - update formatting and information
|
||||
|
||||
|
||||
## 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.
|
||||
@@ -19,12 +17,16 @@ local queries = {
|
||||
} -- NOTE, the 'values' tables can be named 'parameters' here for MySQL-Async compatibility.
|
||||
|
||||
-- Async
|
||||
exports.oxmysql:transaction(queries, function(result)
|
||||
print(result)
|
||||
-- Alias: exports.oxmysql:transaction
|
||||
-- Alias: MySQL.Async.transaction
|
||||
MySQL.transaction(queries, function(result)
|
||||
print(result)
|
||||
end)
|
||||
|
||||
-- Sync
|
||||
local result = exports.oxmysql:transactionSync(queries)
|
||||
-- Alias: exports.oxmysql:transaction_async
|
||||
-- Alias: MySQL.Sync.transaction
|
||||
local result = MySQL.transaction.await(queries)
|
||||
print(result)
|
||||
```
|
||||
|
||||
@@ -59,12 +61,16 @@ local queries = {
|
||||
local parameters = { ['someid'] = 2, ['somename'] = 'John Doe', ['newname'] = 'John Notdoe' }
|
||||
|
||||
-- Async
|
||||
exports.oxmysql:transaction(queries, parameters, function(result)
|
||||
print(result)
|
||||
-- Alias: exports.oxmysql:transaction
|
||||
-- Alias: MySQL.Async.transaction
|
||||
MySQL.transaction(queries, parameters, function(result)
|
||||
print(result)
|
||||
end)
|
||||
|
||||
-- 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)
|
||||
```
|
||||
|
||||
|
||||
@@ -6,9 +6,9 @@ Returns the number of affected rows by the query.
|
||||
### Callback
|
||||
```lua
|
||||
-- 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
|
||||
print(affectedRows)
|
||||
end
|
||||
@@ -18,10 +18,10 @@ end)
|
||||
### Promise
|
||||
```lua
|
||||
-- Alias: exports.oxmysql:update_async
|
||||
-- Alias: MySQL.update
|
||||
-- Alias: MySQL.Sync.execute
|
||||
|
||||
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})
|
||||
if affectedRows then
|
||||
print(affectedRows)
|
||||
end
|
||||
|
||||
Reference in new issue
Block a user