mirror of
https://github.com/darksaid98/oxmysql.git
synced 2026-12-02 06:28:54 +00:00
Fix formatting
This commit is contained in:
1 parent
5bcec3a0b1
commit
2b40fafa7f
7 files changed
+39
-40
No files matched your search
@@ -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.
|
||||
|
||||
!!! info "Example"
|
||||
=== "Lua
|
||||
=== "Async"
|
||||
=== "Lua"
|
||||
**Async**
|
||||
```lua
|
||||
exports.oxmysql:execute('SELECT * FROM users WHERE identifier = ?', {playerIdentifier}, function(result)
|
||||
if result then
|
||||
@@ -16,7 +16,7 @@ When selecting data it will return all matching rows and columns, otherwise it w
|
||||
end
|
||||
end)
|
||||
```
|
||||
=== "Sync"
|
||||
**Sync**
|
||||
```lua
|
||||
local result = exports.oxmysql:executeSync('SELECT * FROM users WHERE identifier = ?', {playerIdentifier})
|
||||
if result then
|
||||
@@ -25,18 +25,18 @@ When selecting data it will return all matching rows and columns, otherwise it w
|
||||
end
|
||||
end
|
||||
```
|
||||
=== "JavaScript
|
||||
=== "Async"
|
||||
=== "JavaScript"
|
||||
**Async**
|
||||
```js
|
||||
exports.oxmysql.execute('SELECT * FROM users WHERE identifier = ?', [playerIdentifier], function(result) {
|
||||
if (result) {
|
||||
result.forEach((v) => {
|
||||
console.log(v.identifier, v.firstname, v.lastname)
|
||||
})
|
||||
})
|
||||
}
|
||||
})
|
||||
```
|
||||
=== "Sync"
|
||||
**Sync**
|
||||
```js
|
||||
const result = exports.oxmysql.executeSync('SELECT * FROM users WHERE identifier = ?', [playerIdentifier]) {
|
||||
if (result) {
|
||||
|
||||
@@ -4,8 +4,8 @@ title: Insert
|
||||
Inserts a new entry into the database and returns the insert id for the row, if valid.
|
||||
|
||||
!!! info "Example"
|
||||
=== "Lua
|
||||
=== "Async"
|
||||
=== "Lua"
|
||||
**Async**
|
||||
```lua
|
||||
exports.oxmysql:insert('INSERT INTO users (identifier, firstname, lastname) VALUES (?, ?, ?) ', {playerIdentifier, firstName, lastName}, function(id)
|
||||
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)
|
||||
```
|
||||
=== "Sync"
|
||||
**Sync**
|
||||
```lua
|
||||
local id = exports.oxmysql:insertSync('INSERT INTO users (identifier, firstname, lastname) VALUES (?, ?, ?) ', {playerIdentifier, firstName, lastName})
|
||||
if id then
|
||||
print(id)
|
||||
end
|
||||
```
|
||||
=== "JavaScript
|
||||
=== "Async"
|
||||
=== "JavaScript"
|
||||
**Async**
|
||||
```js
|
||||
exports.oxmysql.insert('INSERT INTO users (identifier, firstname, lastname) VALUES (?, ?, ?) ', [playerIdentifier, firstName, lastName], function(id) {
|
||||
if (id)
|
||||
console.log(id)
|
||||
})
|
||||
```
|
||||
=== "Sync"
|
||||
**Sync**
|
||||
```js
|
||||
const id = exports.oxmysql.insertSync('INSERT INTO users (identifier, firstname, lastname) VALUES (?, ?, ?) ', [playerIdentifier, firstName, lastName]) {
|
||||
if (id)
|
||||
|
||||
@@ -4,8 +4,8 @@ title: Scalar
|
||||
Returns the first column for a single row.
|
||||
|
||||
!!! info "Example"
|
||||
=== "Lua
|
||||
=== "Async"
|
||||
=== "Lua"
|
||||
**Async**
|
||||
```lua
|
||||
exports.oxmysql:scalar('SELECT firstname FROM users WHERE identifier = ?', {playerIdentifier}, function(result)
|
||||
if result then
|
||||
@@ -13,22 +13,22 @@ Returns the first column for a single row.
|
||||
end
|
||||
end)
|
||||
```
|
||||
=== "Sync"
|
||||
**Sync**
|
||||
```lua
|
||||
local result = exports.oxmysql:scalarSync('SELECT firstname FROM users WHERE identifier = ?', {playerIdentifier})
|
||||
if result then
|
||||
print(result.firstname)
|
||||
end
|
||||
```
|
||||
=== "JavaScript
|
||||
=== "Async"
|
||||
=== "JavaScript"
|
||||
**Async**
|
||||
```js
|
||||
exports.oxmysql.scalar('SELECT firstname FROM users WHERE identifier = ?', [playerIdentifier], function(result) {
|
||||
if (result)
|
||||
console.log(result.firstname)
|
||||
})
|
||||
```
|
||||
=== "Sync"
|
||||
**Sync**
|
||||
```js
|
||||
const result = exports.oxmysql.scalarSync('SELECT firstname FROM users WHERE identifier = ?', [playerIdentifier]) {
|
||||
if (result)
|
||||
|
||||
@@ -4,8 +4,8 @@ title: Single
|
||||
Returns the columns for a single row.
|
||||
|
||||
!!! info "Example"
|
||||
=== "Lua
|
||||
=== "Async"
|
||||
=== "Lua"
|
||||
**Async**
|
||||
```lua
|
||||
exports.oxmysql:single('SELECT * FROM users WHERE identifier = ?', {playerIdentifier}, function(result)
|
||||
if result then
|
||||
@@ -13,22 +13,22 @@ Returns the columns for a single row.
|
||||
end
|
||||
end)
|
||||
```
|
||||
=== "Sync"
|
||||
**Sync**
|
||||
```lua
|
||||
local result = exports.oxmysql:singleSync('SELECT * FROM users WHERE identifier = ?', {playerIdentifier})
|
||||
if result then
|
||||
print(result.identifier, result.firstname, result.lastname)
|
||||
end
|
||||
```
|
||||
=== "JavaScript
|
||||
=== "Async"
|
||||
=== "JavaScript"
|
||||
**Async**
|
||||
```js
|
||||
exports.oxmysql.single('SELECT * FROM users WHERE identifier = ?', [playerIdentifier], function(result) {
|
||||
if (result)
|
||||
console.log(result.identifier, result.firstname, result.lastname)
|
||||
})
|
||||
```
|
||||
=== "Sync"
|
||||
**Sync**
|
||||
```js
|
||||
const result = exports.oxmysql.singleSync('SELECT * FROM users WHERE identifier = ?', [playerIdentifier]) {
|
||||
if (result)
|
||||
|
||||
@@ -30,7 +30,7 @@ local result = exports.oxmysql:transactionSync(queries)
|
||||
print(result)
|
||||
```
|
||||
|
||||
Javascript
|
||||
JavaScript
|
||||
```js
|
||||
const queries = [
|
||||
{ query = 'INSERT INTO `test` (id) VALUES (:someid)', values = { someid = 1 } },
|
||||
@@ -70,7 +70,7 @@ local result = exports.oxmysql:transactionSync(queries, parameters)
|
||||
print(result)
|
||||
```
|
||||
|
||||
Javascript
|
||||
JavaScript
|
||||
```js
|
||||
const queries = [
|
||||
'INSERT INTO `test` (id, name) VALUES (:someid, :somename)',
|
||||
|
||||
@@ -4,8 +4,8 @@ title: Update
|
||||
Updates an entry in the database and returns the number of affected rows.
|
||||
|
||||
!!! info "Example"
|
||||
=== "Lua
|
||||
=== "Async"
|
||||
=== "Lua"
|
||||
**Async**
|
||||
```lua
|
||||
exports.oxmysql:insert('UPDATE users SET firstname = ? WHERE identifier = ? ', {newName, playerIdentifier}, function(affectedRows)
|
||||
if affectedRows then
|
||||
@@ -13,22 +13,22 @@ Updates an entry in the database and returns the number of affected rows.
|
||||
end
|
||||
end)
|
||||
```
|
||||
=== "Sync"
|
||||
**Sync**
|
||||
```lua
|
||||
local id = exports.oxmysql:insertSync('UPDATE users SET firstname = ? WHERE identifier = ? ', {newName, playerIdentifier})
|
||||
if affectedRows then
|
||||
print(affectedRows)
|
||||
end
|
||||
```
|
||||
=== "JavaScript
|
||||
=== "Async"
|
||||
=== "JavaScript"
|
||||
**Async**
|
||||
```js
|
||||
exports.oxmysql.insert('UPDATE users SET firstname = ? WHERE identifier = ? ', [newName, playerIdentifier], function(affectedRows) {
|
||||
if (affectedRows)
|
||||
console.log(affectedRows)
|
||||
})
|
||||
```
|
||||
=== "Sync"
|
||||
**Sync**
|
||||
```js
|
||||
const id = exports.oxmysql.insertSync('UPDATE users SET firstname = ? WHERE identifier = ? ', [newName, playerIdentifier]) {
|
||||
if (affectedRows)
|
||||
|
||||
+6
-7
@@ -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 "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.
|
||||
```
|
||||
set mysql_slow_query_warning 100
|
||||
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
|
||||
Asychronous behaviour does not _truly_ exist in any of the scripting runtimes utilised, with tasks being performed in 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.
|
||||
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 "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.
|
||||
```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)
|
||||
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
|
||||
local val = 10000
|
||||
@@ -85,7 +84,7 @@ RegisterCommand('luasync', function()
|
||||
end)
|
||||
```
|
||||
|
||||
####
|
||||
#### JavaScript
|
||||
```js
|
||||
const val = 10000
|
||||
RegisterCommand('jssync', async() => {
|
||||
|
||||
Reference in new issue
Block a user