mirror of
https://github.com/darksaid98/overextended.github.io.git
synced 2026-12-02 06:28:54 +00:00
Update mysql docs
This commit is contained in:
1 parent
b912eec843
commit
0d2d82cfce
11 files changed
+136
-187
No files matched your search
@@ -0,0 +1,63 @@
|
|||||||
|
# Benchmark
|
||||||
|
|
||||||
|
Internal benchmark
|
||||||
|
```
|
||||||
|
Low: 0.1222ms | Avg: 0.14188357ms | Total: 1418.8357ms (10000 queries)
|
||||||
|
```
|
||||||
|
|
||||||
|
Round-trip-time for exports
|
||||||
|
```
|
||||||
|
Low: 0.1997ms | Avg: 0.25898800ms | Total: 2589.8800ms (10000 queries)
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Lua (5.4)
|
||||||
|
```lua
|
||||||
|
local val = 10000
|
||||||
|
RegisterCommand('luasync', function()
|
||||||
|
local queryTimesLocal = {}
|
||||||
|
local result
|
||||||
|
MySQL.prepare.await('SELECT identifier from users WHERE lastname = ?', {'Linden'})
|
||||||
|
|
||||||
|
for i=1, val do
|
||||||
|
local time = os.nanotime()
|
||||||
|
local r = MySQL.prepare.await('SELECT identifier from users WHERE lastname = ?', {'Linden'})
|
||||||
|
queryTimesLocal[#queryTimesLocal+1] = (os.nanotime() - time) / 1000000
|
||||||
|
if i==1 then result = r end
|
||||||
|
end
|
||||||
|
|
||||||
|
local queryMsLow, queryMsSum = 1000, 0
|
||||||
|
|
||||||
|
for _, v in pairs(queryTimesLocal) do queryMsSum = queryMsSum + v end
|
||||||
|
for _, v in pairs(queryTimesLocal) do
|
||||||
|
if v < queryMsLow then queryMsLow = v end
|
||||||
|
end
|
||||||
|
|
||||||
|
local averageQueryTime = queryMsSum / #queryTimesLocal
|
||||||
|
print(json.encode(result))
|
||||||
|
print('Low: '.. queryMsLow ..'ms | Avg: '..averageQueryTime..'ms | Total: '..queryMsSum..'ms ('..#queryTimesLocal..' queries)')
|
||||||
|
end)
|
||||||
|
```
|
||||||
|
|
||||||
|
#### JavaScript
|
||||||
|
```js
|
||||||
|
const val = 10000
|
||||||
|
RegisterCommand('jssync', async() => {
|
||||||
|
const queryTimesLocal = [];
|
||||||
|
let result
|
||||||
|
await exports.oxmysql.prepare_async('SELECT identifier from users WHERE lastname = ?', ['Linden'])
|
||||||
|
|
||||||
|
for(let i=0; i < val; i++) {
|
||||||
|
const startTime = process.hrtime()
|
||||||
|
const r = await exports.oxmysql.prepare_async('SELECT identifier from users WHERE lastname = ?', ['Linden'])
|
||||||
|
queryTimesLocal.push(process.hrtime(startTime)[1] / 1000000)
|
||||||
|
if (i === 0) result = r
|
||||||
|
}
|
||||||
|
|
||||||
|
const queryMsSum = queryTimesLocal.reduce((a, b) => a + b, 0)
|
||||||
|
const queryMsLow = queryTimesLocal.sort((a, b) => a - b)[0]
|
||||||
|
const averageQueryTime = queryMsSum / queryTimesLocal.length
|
||||||
|
|
||||||
|
console.log(result)
|
||||||
|
console.log('Low: '+ queryMsLow +'ms | Avg: '+averageQueryTime+'ms | Total: '+queryMsSum+'ms ('+queryTimesLocal.length+' queries)')
|
||||||
|
})
|
||||||
|
```
|
||||||
@@ -1,6 +1,4 @@
|
|||||||
---
|
# Getting Started
|
||||||
title: Getting Started
|
|
||||||
---
|
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
- Download the [latest build](https://github.com/overextended/oxmysql/releases/latest) of oxmysql (not the source code).
|
- Download the [latest build](https://github.com/overextended/oxmysql/releases/latest) of oxmysql (not the source code).
|
||||||
@@ -18,6 +16,9 @@ set mysql_connection_string "mysql://root:12345@localhost/es_extended?charset=ut
|
|||||||
set mysql_connection_string "user=root;database=es_extended;password=12345;charset=utf8mb4"
|
set mysql_connection_string "user=root;database=es_extended;password=12345;charset=utf8mb4"
|
||||||
```
|
```
|
||||||
Certain special characters are reserved or blocked and may cause issues when used in your password.
|
Certain special characters are reserved or blocked and may cause issues when used in your password.
|
||||||
|
For more optional settings (such as multiple statements) you can reference [pool.d.ts](https://github.com/sidorares/node-mysql2/blob/master/typings/mysql/lib/Pool.d.ts#L10) and [connection.d.ts](https://github.com/sidorares/node-mysql2/blob/master/typings/mysql/lib/Connection.d.ts#L8).
|
||||||
|
|
||||||
|
|
||||||
You can also add the following convars if you require extra information when testing queries.
|
You can also add the following convars if you require extra information when testing queries.
|
||||||
```
|
```
|
||||||
set mysql_slow_query_warning 150
|
set mysql_slow_query_warning 150
|
||||||
@@ -32,5 +33,4 @@ set mysql_ui true
|
|||||||
Also make sure that you have `command` ace permission access, then you should be able to use the
|
Also make sure that you have `command` ace permission access, then you should be able to use the
|
||||||
`mysql` command in game to open up the UI and see your query data.
|
`mysql` command in game to open up the UI and see your query data.
|
||||||
:::
|
:::
|
||||||
For more optional settings (such as multiple statements) you can reference [pool.d.ts](https://github.com/sidorares/node-mysql2/blob/master/typings/mysql/lib/Pool.d.ts#L10) and [connection.d.ts](https://github.com/sidorares/node-mysql2/blob/master/typings/mysql/lib/Connection.d.ts#L8).
|
|
||||||
|
|
||||||
@@ -1,11 +1,12 @@
|
|||||||
---
|
# Common Issues
|
||||||
title: Common issues
|
|
||||||
---
|
|
||||||
### Unable to establish a connection
|
### Unable to establish a connection
|
||||||
This is usually the result of incorrect database settings or your password containing reserved characters (typically `; , / ? : @ & = + $ #`).
|
This is usually the result of incorrect database settings or your password containing reserved characters (`; , / ? : @ & = + $ #`).
|
||||||
:::tip Solution
|
:::tip Solution
|
||||||
Ensure you have entered the correct database settings in the mysql_connection_string convar. You can try using the semicolon-separated format if your password contains reserved characters.
|
Ensure you have entered the correct database settings in the mysql_connection_string convar.
|
||||||
|
You can try using the semicolon-separated format if your password contains reserved characters.
|
||||||
:::
|
:::
|
||||||
|
|
||||||
### No such export ... in resource oxmysql
|
### No such export ... in resource oxmysql
|
||||||
Typically the result of failing to follow instructions.
|
Typically the result of failing to follow instructions.
|
||||||
:::tip Solution
|
:::tip Solution
|
||||||
@@ -1,56 +0,0 @@
|
|||||||
---
|
|
||||||
title: Benchmark
|
|
||||||
---
|
|
||||||
```
|
|
||||||
Lua: Low: 0.2167ms | Avg: 0.28788843ms | Total: 2878.8843ms (10000 queries)
|
|
||||||
JS: Low: 0.2098ms | Avg: 0.29384436ms | Total: 2938.4436ms (10000 queries)
|
|
||||||
```
|
|
||||||
These benchmarks await the previous response rather than occuring asynchronously, and measure the total time spent executing the export.
|
|
||||||
The `MySQL.Sync.prepare` function calls `exports.oxmysql:execute_async`, as used in the JS sample.
|
|
||||||
|
|
||||||
#### Lua (5.4)
|
|
||||||
```lua
|
|
||||||
local val = 10000
|
|
||||||
RegisterCommand('luasync', function()
|
|
||||||
local queryTimesLocal = {}
|
|
||||||
local result
|
|
||||||
local r = MySQL.Sync.prepare('SELECT identifier from users WHERE lastname = ?', {'Linden'})
|
|
||||||
for i=1, val do
|
|
||||||
local time = os.nanotime()
|
|
||||||
local r = MySQL.Sync.prepare('SELECT identifier from users WHERE lastname = ?', {'Linden'})
|
|
||||||
queryTimesLocal[#queryTimesLocal+1] = (os.nanotime() - time) / 1000000
|
|
||||||
if i==1 then result = r end
|
|
||||||
end
|
|
||||||
local queryMsLow, queryMsSum = 1000, 0
|
|
||||||
for _, v in pairs(queryTimesLocal) do
|
|
||||||
queryMsSum = queryMsSum + v
|
|
||||||
end
|
|
||||||
for _, v in pairs(queryTimesLocal) do
|
|
||||||
if v < queryMsLow then queryMsLow = v end
|
|
||||||
end
|
|
||||||
local averageQueryTime = queryMsSum / #queryTimesLocal
|
|
||||||
print(json.encode(result))
|
|
||||||
print('Low: '.. queryMsLow ..'ms | Avg: '..averageQueryTime..'ms | Total: '..queryMsSum..'ms ('..#queryTimesLocal..' queries)')
|
|
||||||
end)
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
#### JavaScript
|
|
||||||
```js
|
|
||||||
const val = 10000
|
|
||||||
RegisterCommand('jssync', async() => {
|
|
||||||
const queryTimesLocal = [];
|
|
||||||
let result
|
|
||||||
for(let i=0; i < val; i++) {
|
|
||||||
const startTime = process.hrtime()
|
|
||||||
const r = await exports.oxmysql.execute_async('SELECT identifier from users WHERE lastname = ?', ['Linden'])
|
|
||||||
queryTimesLocal.push(process.hrtime(startTime)[1] / 1000000)
|
|
||||||
if (i === 0) result = r
|
|
||||||
}
|
|
||||||
const queryMsSum = queryTimesLocal.reduce((a, b) => a + b, 0)
|
|
||||||
const queryMsLow = queryTimesLocal.sort((a, b) => a - b)[0]
|
|
||||||
const averageQueryTime = queryMsSum / queryTimesLocal.length
|
|
||||||
console.log(result)
|
|
||||||
console.log('Low: '+ queryMsLow +'ms | Avg: '+averageQueryTime+'ms | Total: '+queryMsSum+'ms ('+queryTimesLocal.length+' queries)')
|
|
||||||
})
|
|
||||||
```
|
|
||||||
@@ -1,12 +1,10 @@
|
|||||||
---
|
# Insert
|
||||||
title: insert
|
|
||||||
---
|
|
||||||
Inserts a new entry into the database and returns the insert id for the row, if valid.
|
Inserts a new entry into the database and returns the insert id for the row, if valid.
|
||||||
|
|
||||||
:::info Example
|
## Lua
|
||||||
Lua
|
|
||||||
|
|
||||||
**Callback**
|
### Callback
|
||||||
```lua
|
```lua
|
||||||
-- Alias: exports.oxmysql:insert
|
-- Alias: exports.oxmysql:insert
|
||||||
-- Alias: MySQL.Async.insert
|
-- Alias: MySQL.Async.insert
|
||||||
@@ -14,7 +12,8 @@ MySQL.insert('INSERT INTO users (identifier, firstname, lastname) VALUES (?, ?,
|
|||||||
print(id)
|
print(id)
|
||||||
end)
|
end)
|
||||||
```
|
```
|
||||||
**Promise**
|
|
||||||
|
### Promise
|
||||||
```lua
|
```lua
|
||||||
-- Alias: exports.oxmysql:insert_async
|
-- Alias: exports.oxmysql:insert_async
|
||||||
-- Alias: MySQL.Sync.insert
|
-- Alias: MySQL.Sync.insert
|
||||||
@@ -23,15 +22,17 @@ local id = MySQL.insert.await('INSERT INTO users (identifier, firstname, lastnam
|
|||||||
print(id)
|
print(id)
|
||||||
end)
|
end)
|
||||||
```
|
```
|
||||||
JavaScript
|
|
||||||
|
|
||||||
**Callback**
|
## JavaScript
|
||||||
|
|
||||||
|
### Callback
|
||||||
```js
|
```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)
|
console.log(id)
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
**Promise**
|
|
||||||
|
### Promise
|
||||||
```js
|
```js
|
||||||
(async () => {
|
(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 (?, ?, ?) ',
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
---
|
# Prepare
|
||||||
title: prepare
|
|
||||||
---
|
|
||||||
The only function that provides true [prepared statements](https://github.com/sidorares/node-mysql2#using-prepared-statements), granting native protection and query planning by MySQL.
|
The only function that provides true [prepared statements](https://github.com/sidorares/node-mysql2#using-prepared-statements), granting native protection and query planning by MySQL.
|
||||||
Prepare can be used to execute frequently called queries faster and accepts multiple sets of parameters to be used with a single query.
|
Prepare can be used to execute frequently called queries faster and accepts multiple sets of parameters to be used with a single query.
|
||||||
|
|
||||||
@@ -8,12 +7,11 @@ Prepare can be used to execute frequently called queries faster and accepts mult
|
|||||||
- TINYINT 1 and BIT will not return a boolean
|
- TINYINT 1 and BIT will not return a boolean
|
||||||
- You can only use `?` value placeholders, `??` column placeholders and named placeholders will throw an error
|
- You can only use `?` value placeholders, `??` column placeholders and named placeholders will throw an error
|
||||||
|
|
||||||
When using SELECT, the return value will match `fetchAll, fetchSingle, or fetchScalar` depending on the number of columns and rows selected.
|
When using SELECT, the return value will match `query, single, or scalar` depending on the number of columns and rows selected.
|
||||||
|
|
||||||
:::info Example
|
## Lua
|
||||||
Lua
|
|
||||||
|
|
||||||
**Callback**
|
### Callback
|
||||||
```lua
|
```lua
|
||||||
-- Alias: exports.oxmysql:prepare
|
-- Alias: exports.oxmysql:prepare
|
||||||
-- Alias: MySQL.Async.prepare
|
-- Alias: MySQL.Async.prepare
|
||||||
@@ -26,7 +24,8 @@ MySQL.prepare('SELECT * FROM users WHERE identifier = ?', {playerIdentifier}, fu
|
|||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
```
|
```
|
||||||
**Promise**
|
|
||||||
|
### Promise
|
||||||
```lua
|
```lua
|
||||||
-- Alias: exports.oxmysql:prepare_async
|
-- Alias: exports.oxmysql:prepare_async
|
||||||
-- Alias: MySQL.Sync.prepare
|
-- Alias: MySQL.Sync.prepare
|
||||||
@@ -41,9 +40,9 @@ CreateThread(function()
|
|||||||
end)
|
end)
|
||||||
```
|
```
|
||||||
|
|
||||||
JavaScript
|
## JavaScript
|
||||||
|
|
||||||
**Callback**
|
### Callback
|
||||||
```js
|
```js
|
||||||
exports.oxmysql.prepare('SELECT * FROM users WHERE identifier = ?', [playerIdentifier], function(result) {
|
exports.oxmysql.prepare('SELECT * FROM users WHERE identifier = ?', [playerIdentifier], function(result) {
|
||||||
if (result) {
|
if (result) {
|
||||||
@@ -53,7 +52,8 @@ exports.oxmysql.prepare('SELECT * FROM users WHERE identifier = ?', [playerIdent
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
**Promise**
|
|
||||||
|
### Promise
|
||||||
```js
|
```js
|
||||||
(async () => {
|
(async () => {
|
||||||
const result = await exports.oxmysql.prepare_async('SELECT * FROM users WHERE identifier = ?', [playerIdentifier]) {
|
const result = await exports.oxmysql.prepare_async('SELECT * FROM users WHERE identifier = ?', [playerIdentifier]) {
|
||||||
@@ -64,51 +64,3 @@ exports.oxmysql.prepare('SELECT * FROM users WHERE identifier = ?', [playerIdent
|
|||||||
}
|
}
|
||||||
})()
|
})()
|
||||||
```
|
```
|
||||||
:::
|
|
||||||
|
|
||||||
As mentioned above, you can utilise an array of parameters for a transaction-like query without the rollback; reducing the number of exports being performed reduces strain on the server. Included below is some examples of using prepare in ESX Legacy.
|
|
||||||
|
|
||||||
```lua
|
|
||||||
ESX.SavePlayer = function(xPlayer, cb)
|
|
||||||
MySQL.Async.prepare("UPDATE `users` SET `accounts` = ?, `job` = ?, `job_grade` = ?, `group` = ?, `position` = ?, `inventory` = ? WHERE `identifier` = ?", {{
|
|
||||||
json.encode(xPlayer.getAccounts(true)),
|
|
||||||
xPlayer.job.name,
|
|
||||||
xPlayer.job.grade,
|
|
||||||
xPlayer.group,
|
|
||||||
json.encode(xPlayer.getCoords()),
|
|
||||||
json.encode(xPlayer.getInventory(true)),
|
|
||||||
xPlayer.identifier
|
|
||||||
}}, function(affectedRows)
|
|
||||||
if affectedRows == 1 then
|
|
||||||
print(('[^2INFO^7] Saved player ^5"%s^7"'):format(xPlayer.name))
|
|
||||||
end
|
|
||||||
if cb then cb() end
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
|
|
||||||
ESX.SavePlayers = function(cb)
|
|
||||||
local xPlayers = ESX.GetExtendedPlayers()
|
|
||||||
local count = #xPlayers
|
|
||||||
if count > 0 then
|
|
||||||
local parameters = {}
|
|
||||||
for i=1, count do
|
|
||||||
local xPlayer = xPlayers[i]
|
|
||||||
parameters[#parameters+1] = {
|
|
||||||
json.encode(xPlayer.getAccounts(true)),
|
|
||||||
xPlayer.job.name,
|
|
||||||
xPlayer.job.grade,
|
|
||||||
xPlayer.group,
|
|
||||||
json.encode(xPlayer.getCoords()),
|
|
||||||
json.encode(xPlayer.getInventory(true)),
|
|
||||||
xPlayer.identifier
|
|
||||||
}
|
|
||||||
end
|
|
||||||
MySQL.Async.prepare("UPDATE `users` SET `accounts` = ?, `job` = ?, `job_grade` = ?, `group` = ?, `position` = ?, `inventory` = ? WHERE `identifier` = ?", parameters,
|
|
||||||
function(results)
|
|
||||||
if results then
|
|
||||||
if type(cb) == 'function' then cb() else print(('[^2INFO^7] Saved %s %s'):format(count, count > 1 and 'players' or 'player') end
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
```
|
|
||||||
@@ -1,13 +1,10 @@
|
|||||||
---
|
# Query
|
||||||
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
|
## Lua
|
||||||
Lua
|
|
||||||
|
|
||||||
**Callback**
|
### Callback
|
||||||
```lua
|
```lua
|
||||||
-- Alias: exports.oxmysql:query
|
-- Alias: exports.oxmysql:query
|
||||||
-- Alias: MySQL.Async.query
|
-- Alias: MySQL.Async.query
|
||||||
@@ -20,7 +17,7 @@ MySQL.query('SELECT * FROM users WHERE identifier = ?', {playerIdentifier}, func
|
|||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
```
|
```
|
||||||
**Promise**
|
### Promise
|
||||||
```lua
|
```lua
|
||||||
-- Alias: exports.oxmysql:query
|
-- Alias: exports.oxmysql:query
|
||||||
-- Alias: MySQL.Sync.query
|
-- Alias: MySQL.Sync.query
|
||||||
@@ -35,9 +32,9 @@ CreateThread(function()
|
|||||||
end)
|
end)
|
||||||
```
|
```
|
||||||
|
|
||||||
JavaScript
|
## JavaScript
|
||||||
|
|
||||||
**Callback**
|
### Callback
|
||||||
```js
|
```js
|
||||||
exports.oxmysql.query('SELECT * FROM users WHERE identifier = ?', [playerIdentifier], function(result) {
|
exports.oxmysql.query('SELECT * FROM users WHERE identifier = ?', [playerIdentifier], function(result) {
|
||||||
if (result) {
|
if (result) {
|
||||||
@@ -47,7 +44,7 @@ exports.oxmysql.query('SELECT * FROM users WHERE identifier = ?', [playerIdentif
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
**Promise**
|
### Promise
|
||||||
```js
|
```js
|
||||||
(async () => {
|
(async () => {
|
||||||
const result = await exports.oxmysql.query_async('SELECT * FROM users WHERE identifier = ?', [playerIdentifier]) {
|
const result = await exports.oxmysql.query_async('SELECT * FROM users WHERE identifier = ?', [playerIdentifier]) {
|
||||||
@@ -58,4 +55,3 @@ exports.oxmysql.query('SELECT * FROM users WHERE identifier = ?', [playerIdentif
|
|||||||
}
|
}
|
||||||
})()
|
})()
|
||||||
```
|
```
|
||||||
:::
|
|
||||||
@@ -1,12 +1,9 @@
|
|||||||
---
|
# Scalar
|
||||||
title: scalar
|
|
||||||
---
|
|
||||||
Returns the first column for a single row.
|
Returns the first column for a single row.
|
||||||
|
|
||||||
:::info Example
|
## Lua
|
||||||
Lua
|
|
||||||
|
|
||||||
**Callback**
|
### Callback
|
||||||
```lua
|
```lua
|
||||||
-- Alias: exports.oxmysql:scalar
|
-- Alias: exports.oxmysql:scalar
|
||||||
-- Alias: MySQL.Async.fetchScalar
|
-- Alias: MySQL.Async.fetchScalar
|
||||||
@@ -15,7 +12,8 @@ MySQL.scalar('SELECT firstname FROM users WHERE identifier = ?', {playerIdentifi
|
|||||||
print(firstname)
|
print(firstname)
|
||||||
end)
|
end)
|
||||||
```
|
```
|
||||||
**Promise**
|
|
||||||
|
### Promise
|
||||||
```lua
|
```lua
|
||||||
-- Alias: exports.oxmysql:scalar_async
|
-- Alias: exports.oxmysql:scalar_async
|
||||||
-- Alias: MySQL.Sync.fetchScalar
|
-- Alias: MySQL.Sync.fetchScalar
|
||||||
@@ -26,19 +24,19 @@ CreateThread(function()
|
|||||||
end)
|
end)
|
||||||
```
|
```
|
||||||
|
|
||||||
JavaScript
|
## JavaScript
|
||||||
|
|
||||||
**Callback**
|
### Callback
|
||||||
```js
|
```js
|
||||||
exports.oxmysql.scalar('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)
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
**Promise**
|
|
||||||
|
### Promise
|
||||||
```js
|
```js
|
||||||
(async () => {
|
(async () => {
|
||||||
const firstname = await exports.oxmysql.scalar_async('SELECT firstname FROM users WHERE identifier = ?', [playerIdentifier]) {
|
const firstname = await exports.oxmysql.scalar_async('SELECT firstname FROM users WHERE identifier = ?', [playerIdentifier]) {
|
||||||
console.log(firstname)
|
console.log(firstname)
|
||||||
})()
|
})()
|
||||||
```
|
```
|
||||||
:::
|
|
||||||
@@ -1,12 +1,9 @@
|
|||||||
---
|
# Single
|
||||||
title: single
|
|
||||||
---
|
|
||||||
Returns the columns for a single row.
|
Returns the columns for a single row.
|
||||||
|
|
||||||
:::info Example
|
## Lua
|
||||||
Lua
|
|
||||||
|
|
||||||
**Callback**
|
### Callback
|
||||||
```lua
|
```lua
|
||||||
-- Alias: exports.oxmysql:single
|
-- Alias: exports.oxmysql:single
|
||||||
-- Alias: MySQL.Async.fetchSingle
|
-- Alias: MySQL.Async.fetchSingle
|
||||||
@@ -17,7 +14,8 @@ MySQL.single('SELECT * FROM users WHERE identifier = ?', {playerIdentifier}, fun
|
|||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
```
|
```
|
||||||
**Promise**
|
|
||||||
|
### Promise
|
||||||
```lua
|
```lua
|
||||||
-- Alias: exports.oxmysql:single_async
|
-- Alias: exports.oxmysql:single_async
|
||||||
-- Alias: MySQL.Sync.fetchSingle
|
-- Alias: MySQL.Sync.fetchSingle
|
||||||
@@ -30,16 +28,17 @@ CreateThread(function()
|
|||||||
end)
|
end)
|
||||||
```
|
```
|
||||||
|
|
||||||
JavaScript
|
## JavaScript
|
||||||
|
|
||||||
**Callback**
|
### Callback
|
||||||
```js
|
```js
|
||||||
exports.oxmysql.single('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)
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
**Promise**
|
|
||||||
|
### Promise
|
||||||
```js
|
```js
|
||||||
setImmediate(async () => {
|
setImmediate(async () => {
|
||||||
const result = await exports.oxmysql.single_async('SELECT * FROM users WHERE identifier = ?', [playerIdentifier]) {
|
const result = await exports.oxmysql.single_async('SELECT * FROM users WHERE identifier = ?', [playerIdentifier]) {
|
||||||
@@ -47,4 +46,3 @@ setImmediate(async () => {
|
|||||||
console.log(result.identifier, result.firstname, result.lastname)
|
console.log(result.identifier, result.firstname, result.lastname)
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
:::
|
|
||||||
@@ -1,19 +1,17 @@
|
|||||||
---
|
# Transaction
|
||||||
title: transaction
|
|
||||||
---
|
|
||||||
todo - update formatting and information
|
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.
|
||||||
|
|
||||||
## Specific Format
|
### Specific Format
|
||||||
When using the `Specific` format you must pass one parameter to the oxmysql export. In this case, the `queries` parameter contains your queries and the SQL variables unique to each query.
|
When using the `Specific` format you must pass one parameter to the oxmysql export. In this case, the `queries` parameter contains your queries and the SQL variables unique to each query.
|
||||||
|
|
||||||
This is useful for transactions where the queries do not share many SQL variables.
|
This is useful for transactions where the queries do not share many SQL variables.
|
||||||
|
|
||||||
### Usage
|
### Usage
|
||||||
Lua
|
#### Lua
|
||||||
```lua
|
```lua
|
||||||
local queries = {
|
local queries = {
|
||||||
{ query = 'INSERT INTO `test` (id) VALUES (:someid)', values = { ['someid'] = 1 } },
|
{ query = 'INSERT INTO `test` (id) VALUES (:someid)', values = { ['someid'] = 1 } },
|
||||||
@@ -30,7 +28,7 @@ local result = exports.oxmysql:transactionSync(queries)
|
|||||||
print(result)
|
print(result)
|
||||||
```
|
```
|
||||||
|
|
||||||
JavaScript
|
#### JavaScript
|
||||||
```js
|
```js
|
||||||
const queries = [
|
const queries = [
|
||||||
{ query = 'INSERT INTO `test` (id) VALUES (:someid)', values = { someid = 1 } },
|
{ query = 'INSERT INTO `test` (id) VALUES (:someid)', values = { someid = 1 } },
|
||||||
@@ -51,7 +49,7 @@ console.log(result)
|
|||||||
When using the `Shared` format you must pass two parameters to the oxmysql export. The `queries` and the `parameters` those queries will use.
|
When using the `Shared` format you must pass two parameters to the oxmysql export. The `queries` and the `parameters` those queries will use.
|
||||||
This is useful if your queries use the same SQL variables.
|
This is useful if your queries use the same SQL variables.
|
||||||
|
|
||||||
Lua
|
#### Lua
|
||||||
```lua
|
```lua
|
||||||
local queries = {
|
local queries = {
|
||||||
'INSERT INTO `test` (id, name) VALUES (:someid, :somename)',
|
'INSERT INTO `test` (id, name) VALUES (:someid, :somename)',
|
||||||
@@ -70,7 +68,7 @@ local result = exports.oxmysql:transactionSync(queries, parameters)
|
|||||||
print(result)
|
print(result)
|
||||||
```
|
```
|
||||||
|
|
||||||
JavaScript
|
#### JavaScript
|
||||||
```js
|
```js
|
||||||
const queries = [
|
const queries = [
|
||||||
'INSERT INTO `test` (id, name) VALUES (:someid, :somename)',
|
'INSERT INTO `test` (id, name) VALUES (:someid, :somename)',
|
||||||
|
|||||||
@@ -1,12 +1,9 @@
|
|||||||
---
|
# Update
|
||||||
title: update
|
|
||||||
---
|
|
||||||
Returns the number of affected rows by the query.
|
Returns the number of affected rows by the query.
|
||||||
|
|
||||||
:::info Example
|
## Lua
|
||||||
Lua
|
|
||||||
|
|
||||||
**Callback**
|
### Callback
|
||||||
```lua
|
```lua
|
||||||
-- Alias: exports.oxmysql:update
|
-- Alias: exports.oxmysql:update
|
||||||
-- Alias: MySQL.Async.update
|
-- Alias: MySQL.Async.update
|
||||||
@@ -17,7 +14,8 @@ MySQL.Async.update('UPDATE users SET firstname = ? WHERE identifier = ? ', {newN
|
|||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
```
|
```
|
||||||
**Promise**
|
|
||||||
|
### Promise
|
||||||
```lua
|
```lua
|
||||||
-- Alias: exports.oxmysql:update_async
|
-- Alias: exports.oxmysql:update_async
|
||||||
-- Alias: MySQL.update
|
-- Alias: MySQL.update
|
||||||
@@ -30,16 +28,17 @@ CreateThread(function()
|
|||||||
end)
|
end)
|
||||||
```
|
```
|
||||||
|
|
||||||
JavaScript
|
## JavaScript
|
||||||
|
|
||||||
**Callback**
|
### Callback
|
||||||
```js
|
```js
|
||||||
exports.oxmysql.update('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)
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
**Promise**
|
|
||||||
|
### Promise
|
||||||
```js
|
```js
|
||||||
setImmediate(async () => {
|
setImmediate(async () => {
|
||||||
const id = exports.oxmysql.update_async('UPDATE users SET firstname = ? WHERE identifier = ? ', [newName, playerIdentifier]) {
|
const id = exports.oxmysql.update_async('UPDATE users SET firstname = ? WHERE identifier = ? ', [newName, playerIdentifier]) {
|
||||||
@@ -47,4 +46,3 @@ setImmediate(async () => {
|
|||||||
console.log(affectedRows)
|
console.log(affectedRows)
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
:::
|
|
||||||
Reference in new issue
Block a user