Fix formatting

This commit is contained in:
Linden committed 2021-10-25 03:48:14 +11:00
1 parent 5bcec3a0b1
commit 2b40fafa7f
7 files changed
+39 -40

No files matched your search

+7 -7
View File
@@ -5,8 +5,8 @@ Generic function that can be utilised for any query, synonymous with fetch.
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"
=== "Async" **Async**
```lua ```lua
exports.oxmysql:execute('SELECT * FROM users WHERE identifier = ?', {playerIdentifier}, function(result) exports.oxmysql:execute('SELECT * FROM users WHERE identifier = ?', {playerIdentifier}, function(result)
if result then if result then
@@ -16,7 +16,7 @@ When selecting data it will return all matching rows and columns, otherwise it w
end end
end) end)
``` ```
=== "Sync" **Sync**
```lua ```lua
local result = exports.oxmysql:executeSync('SELECT * FROM users WHERE identifier = ?', {playerIdentifier}) local result = exports.oxmysql:executeSync('SELECT * FROM users WHERE identifier = ?', {playerIdentifier})
if result then if result then
@@ -25,18 +25,18 @@ When selecting data it will return all matching rows and columns, otherwise it w
end end
end end
``` ```
=== "JavaScript === "JavaScript"
=== "Async" **Async**
```js ```js
exports.oxmysql.execute('SELECT * FROM users WHERE identifier = ?', [playerIdentifier], function(result) { exports.oxmysql.execute('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)
}) })
} }
}) })
``` ```
=== "Sync" **Sync**
```js ```js
const result = exports.oxmysql.executeSync('SELECT * FROM users WHERE identifier = ?', [playerIdentifier]) { const result = exports.oxmysql.executeSync('SELECT * FROM users WHERE identifier = ?', [playerIdentifier]) {
if (result) { if (result) {
+6 -6
View File
@@ -4,8 +4,8 @@ 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" !!! info "Example"
=== "Lua === "Lua"
=== "Async" **Async**
```lua ```lua
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)
if id then if id then
@@ -13,22 +13,22 @@ Inserts a new entry into the database and returns the insert id for the row, if
end end
end) end)
``` ```
=== "Sync" **Sync**
```lua ```lua
local id = exports.oxmysql:insertSync('INSERT INTO users (identifier, firstname, lastname) VALUES (?, ?, ?) ', {playerIdentifier, firstName, lastName}) local id = exports.oxmysql:insertSync('INSERT INTO users (identifier, firstname, lastname) VALUES (?, ?, ?) ', {playerIdentifier, firstName, lastName})
if id then if id then
print(id) print(id)
end end
``` ```
=== "JavaScript === "JavaScript"
=== "Async" **Async**
```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) {
if (id) if (id)
console.log(id) console.log(id)
}) })
``` ```
=== "Sync" **Sync**
```js ```js
const id = exports.oxmysql.insertSync('INSERT INTO users (identifier, firstname, lastname) VALUES (?, ?, ?) ', [playerIdentifier, firstName, lastName]) { const id = exports.oxmysql.insertSync('INSERT INTO users (identifier, firstname, lastname) VALUES (?, ?, ?) ', [playerIdentifier, firstName, lastName]) {
if (id) if (id)
+6 -6
View File
@@ -4,8 +4,8 @@ title: Scalar
Returns the first column for a single row. Returns the first column for a single row.
!!! info "Example" !!! info "Example"
=== "Lua === "Lua"
=== "Async" **Async**
```lua ```lua
exports.oxmysql:scalar('SELECT firstname FROM users WHERE identifier = ?', {playerIdentifier}, function(result) exports.oxmysql:scalar('SELECT firstname FROM users WHERE identifier = ?', {playerIdentifier}, function(result)
if result then if result then
@@ -13,22 +13,22 @@ Returns the first column for a single row.
end end
end) end)
``` ```
=== "Sync" **Sync**
```lua ```lua
local result = exports.oxmysql:scalarSync('SELECT firstname FROM users WHERE identifier = ?', {playerIdentifier}) local result = exports.oxmysql:scalarSync('SELECT firstname FROM users WHERE identifier = ?', {playerIdentifier})
if result then if result then
print(result.firstname) print(result.firstname)
end end
``` ```
=== "JavaScript === "JavaScript"
=== "Async" **Async**
```js ```js
exports.oxmysql.scalar('SELECT firstname FROM users WHERE identifier = ?', [playerIdentifier], function(result) { exports.oxmysql.scalar('SELECT firstname FROM users WHERE identifier = ?', [playerIdentifier], function(result) {
if (result) if (result)
console.log(result.firstname) console.log(result.firstname)
}) })
``` ```
=== "Sync" **Sync**
```js ```js
const result = exports.oxmysql.scalarSync('SELECT firstname FROM users WHERE identifier = ?', [playerIdentifier]) { const result = exports.oxmysql.scalarSync('SELECT firstname FROM users WHERE identifier = ?', [playerIdentifier]) {
if (result) if (result)
+6 -6
View File
@@ -4,8 +4,8 @@ title: Single
Returns the columns for a single row. Returns the columns for a single row.
!!! info "Example" !!! info "Example"
=== "Lua === "Lua"
=== "Async" **Async**
```lua ```lua
exports.oxmysql:single('SELECT * FROM users WHERE identifier = ?', {playerIdentifier}, function(result) exports.oxmysql:single('SELECT * FROM users WHERE identifier = ?', {playerIdentifier}, function(result)
if result then if result then
@@ -13,22 +13,22 @@ Returns the columns for a single row.
end end
end) end)
``` ```
=== "Sync" **Sync**
```lua ```lua
local result = exports.oxmysql:singleSync('SELECT * FROM users WHERE identifier = ?', {playerIdentifier}) local result = exports.oxmysql:singleSync('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
``` ```
=== "JavaScript === "JavaScript"
=== "Async" **Async**
```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)
}) })
``` ```
=== "Sync" **Sync**
```js ```js
const result = exports.oxmysql.singleSync('SELECT * FROM users WHERE identifier = ?', [playerIdentifier]) { const result = exports.oxmysql.singleSync('SELECT * FROM users WHERE identifier = ?', [playerIdentifier]) {
if (result) if (result)
+2 -2
View File
@@ -30,7 +30,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 } },
@@ -70,7 +70,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)',
+6 -6
View File
@@ -4,8 +4,8 @@ title: Update
Updates an entry in the database and returns the number of affected rows. Updates an entry in the database and returns the number of affected rows.
!!! info "Example" !!! info "Example"
=== "Lua === "Lua"
=== "Async" **Async**
```lua ```lua
exports.oxmysql:insert('UPDATE users SET firstname = ? WHERE identifier = ? ', {newName, playerIdentifier}, function(affectedRows) exports.oxmysql:insert('UPDATE users SET firstname = ? WHERE identifier = ? ', {newName, playerIdentifier}, function(affectedRows)
if affectedRows then if affectedRows then
@@ -13,22 +13,22 @@ Updates an entry in the database and returns the number of affected rows.
end end
end) end)
``` ```
=== "Sync" **Sync**
```lua ```lua
local id = exports.oxmysql:insertSync('UPDATE users SET firstname = ? WHERE identifier = ? ', {newName, playerIdentifier}) local id = exports.oxmysql:insertSync('UPDATE users SET firstname = ? WHERE identifier = ? ', {newName, playerIdentifier})
if affectedRows then if affectedRows then
print(affectedRows) print(affectedRows)
end end
``` ```
=== "JavaScript === "JavaScript"
=== "Async" **Async**
```js ```js
exports.oxmysql.insert('UPDATE users SET firstname = ? WHERE identifier = ? ', [newName, playerIdentifier], function(affectedRows) { exports.oxmysql.insert('UPDATE users SET firstname = ? WHERE identifier = ? ', [newName, playerIdentifier], function(affectedRows) {
if (affectedRows) if (affectedRows)
console.log(affectedRows) console.log(affectedRows)
}) })
``` ```
=== "Sync" **Sync**
```js ```js
const id = exports.oxmysql.insertSync('UPDATE users SET firstname = ? WHERE identifier = ? ', [newName, playerIdentifier]) { const id = exports.oxmysql.insertSync('UPDATE users SET firstname = ? WHERE identifier = ? ', [newName, playerIdentifier]) {
if (affectedRows) if (affectedRows)
+6 -7
View File
@@ -17,18 +17,17 @@ You must include one of the following lines, adjusted for your connection and da
set mysql_connection_string "mysql://root:12345@localhost/es_extended?charset=utf8mb4" set mysql_connection_string "mysql://root:12345@localhost/es_extended?charset=utf8mb4"
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"
``` ```
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 100 set mysql_slow_query_warning 100
set mysql_debug true set mysql_debug true
``` ```
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).
## Sync vs. async ## Sync vs. async
Asychronous behaviour does not _truly_ exist in any of the scripting runtimes utilised, with tasks being performed in a queue each tick. Asychronous behaviour does not _truly_ exist in any of the scripting runtimes utilised, with tasks being performed as part of a queue each tick.
Two variants of exports are provided for users, and their names describe their behaviour as part of the active "thread" being executed. Two variants of exports are provided for users, and their names describe their behaviour as part of the "thread" being executed.
The following export is "asynchronous" and will execute in order, however the result will be delayed until a result is returned rather than pausing execution of following code. The following export is "asynchronous" and will execute in order, however the result will be delayed until a result is returned rather than pausing execution of following code.
```lua ```lua
@@ -54,9 +53,9 @@ Furthermore, the result will be returned inline (left-hand assignment) rather th
Lua: Low: 0.2955ms | High: 16.7566ms | Avg: 0.36956378ms | Total: 3695.6378ms (10000 queries) Lua: Low: 0.2955ms | High: 16.7566ms | Avg: 0.36956378ms | Total: 3695.6378ms (10000 queries)
JS: Low: 0.2831ms | High: 5.1899ms | Avg: 0.33495788ms | Total: 3349.5788ms (10000 queries) JS: Low: 0.2831ms | High: 5.1899ms | Avg: 0.33495788ms | Total: 3349.5788ms (10000 queries)
``` ```
These benchmark _exports_ rather than actual query speed, resulting in extra delays due to serialisation and overhead. Lua generally falls _slightly_ behind, but the amount is negligible. Furthermore we utilise the _sync_ variants for this, so a query will only execute once the previous one has returned. These benchmark _exports_ rather than actual query speed, resulting in extra delays due to serialisation and overhead. Lua generally falls _slightly_ behind, but the amount is negligible.
Furthermore we utilise the _sync_ variants for this, so a query will only execute once the previous one has returned.
Feel free to run your own tests.
#### Lua (5.4) #### Lua (5.4)
```lua ```lua
local val = 10000 local val = 10000
@@ -85,7 +84,7 @@ RegisterCommand('luasync', function()
end) end)
``` ```
#### #### JavaScript
```js ```js
const val = 10000 const val = 10000
RegisterCommand('jssync', async() => { RegisterCommand('jssync', async() => {