diff --git a/docs/exports/execute.md b/docs/exports/execute.md index 9976446..521855b 100644 --- a/docs/exports/execute.md +++ b/docs/exports/execute.md @@ -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) { diff --git a/docs/exports/insert.md b/docs/exports/insert.md index 6148b80..15cf0ba 100644 --- a/docs/exports/insert.md +++ b/docs/exports/insert.md @@ -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) diff --git a/docs/exports/scalar.md b/docs/exports/scalar.md index 1f8cce8..88296b7 100644 --- a/docs/exports/scalar.md +++ b/docs/exports/scalar.md @@ -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) diff --git a/docs/exports/single.md b/docs/exports/single.md index 87719ce..de17df4 100644 --- a/docs/exports/single.md +++ b/docs/exports/single.md @@ -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) diff --git a/docs/exports/transaction.md b/docs/exports/transaction.md index 77da752..82879ba 100644 --- a/docs/exports/transaction.md +++ b/docs/exports/transaction.md @@ -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)', diff --git a/docs/exports/update.md b/docs/exports/update.md index 688cc92..1832d4f 100644 --- a/docs/exports/update.md +++ b/docs/exports/update.md @@ -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) diff --git a/docs/index.md b/docs/index.md index ae24d46..e6cfc8a 100644 --- a/docs/index.md +++ b/docs/index.md @@ -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() => {