diff --git a/docs/oxmysql/Usage/insert.md b/docs/oxmysql/Usage/insert.md index 1ced34d2..74a6540e 100644 --- a/docs/oxmysql/Usage/insert.md +++ b/docs/oxmysql/Usage/insert.md @@ -3,7 +3,7 @@ title: insert --- Inserts a new entry into the database and returns the insert id for the row, if valid. -:::tip Example +:::info Example Lua **Callback** @@ -23,19 +23,19 @@ local id = MySQL.insert.await('INSERT INTO users (identifier, firstname, lastnam print(id) end) ``` -=== JavaScript" - **Callback** - ```js - exports.oxmysql.insert('INSERT INTO users (identifier, firstname, lastname) VALUES (?, ?, ?) ', [playerIdentifier, -firstName, lastName], function(id) { - console.log(id) - }) - ``` - **Promise** - ```js - (async () => { - const id = exports.oxmysql.insert_async('INSERT INTO users (identifier, firstname, lastname) VALUES (?, ?, ?) ', +JavaScript + +**Callback** +```js +exports.oxmysql.insert('INSERT INTO users (identifier, firstname, lastname) VALUES (?, ?, ?) ', [playerIdentifier, firstName, lastName], function(id) { + console.log(id) +}) +``` +**Promise** +```js +(async () => { + const id = exports.oxmysql.insert_async('INSERT INTO users (identifier, firstname, lastname) VALUES (?, ?, ?) ', [playerIdentifier, firstName, lastName]) { - console.log(id) - })() - ``` \ No newline at end of file + console.log(id) +})() +``` \ No newline at end of file diff --git a/docs/oxmysql/Usage/prepare.md b/docs/oxmysql/Usage/prepare.md index bea72b6c..99119091 100644 --- a/docs/oxmysql/Usage/prepare.md +++ b/docs/oxmysql/Usage/prepare.md @@ -10,61 +10,61 @@ Prepare can be used to execute frequently called queries faster and accepts mult When using SELECT, the return value will match `fetchAll, fetchSingle, or fetchScalar` depending on the number of columns and rows selected. -!!! info "Example" - === "Lua" +:::info Example +Lua - **Callback** - ```lua - -- Alias: exports.oxmysql:prepare - -- Alias: MySQL.Async.prepare +**Callback** +```lua +-- Alias: exports.oxmysql:prepare +-- Alias: MySQL.Async.prepare - MySQL.prepare('SELECT * FROM users WHERE identifier = ?', {playerIdentifier}, function(result) - if result then - for _, v in pairs(result) do - print(v.identifier, v.firstname, v.lastname) - end - end - end) - ``` - **Promise** - ```lua - -- Alias: exports.oxmysql:prepare_async - -- Alias: MySQL.Sync.prepare +MySQL.prepare('SELECT * FROM users WHERE identifier = ?', {playerIdentifier}, function(result) + if result then + for _, v in pairs(result) do + print(v.identifier, v.firstname, v.lastname) + end + end +end) +``` +**Promise** +```lua +-- Alias: exports.oxmysql:prepare_async +-- Alias: MySQL.Sync.prepare - - CreateThread(function() - local result = MySQL.prepare.await('SELECT * FROM users WHERE identifier = ?', {playerIdentifier}) - if result then - for _, v in pairs(result) do - print(v.identifier, v.firstname, v.lastname) - end - end - end) - ``` +CreateThread(function() + local result = MySQL.prepare.await('SELECT * FROM users WHERE identifier = ?', {playerIdentifier}) + if result then + for _, v in pairs(result) do + print(v.identifier, v.firstname, v.lastname) + end + end +end) +``` - === "JavaScript" +JavaScript - **Callback** - ```js - exports.oxmysql.prepare('SELECT * FROM users WHERE identifier = ?', [playerIdentifier], function(result) { - if (result) { - result.forEach((v) => { - console.log(v.identifier, v.firstname, v.lastname) - }) - } - }) - ``` - **Promise** - ```js - (async () => { - const result = await exports.oxmysql.prepare_async('SELECT * FROM users WHERE identifier = ?', [playerIdentifier]) { - if (result) { - result.forEach((v) => { - console.log(v.identifier, v.firstname, v.lastname) - }) - } - })() - ``` +**Callback** +```js +exports.oxmysql.prepare('SELECT * FROM users WHERE identifier = ?', [playerIdentifier], function(result) { + if (result) { + result.forEach((v) => { + console.log(v.identifier, v.firstname, v.lastname) + }) + } +}) +``` +**Promise** +```js +(async () => { + const result = await exports.oxmysql.prepare_async('SELECT * FROM users WHERE identifier = ?', [playerIdentifier]) { + if (result) { + result.forEach((v) => { + console.log(v.identifier, v.firstname, v.lastname) + }) + } +})() +``` +::: 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. @@ -111,4 +111,4 @@ ESX.SavePlayers = function(cb) end) end end -``` \ No newline at end of file +``` diff --git a/docs/oxmysql/Usage/query.md b/docs/oxmysql/Usage/query.md index 1cd28fac..885ac5ef 100644 --- a/docs/oxmysql/Usage/query.md +++ b/docs/oxmysql/Usage/query.md @@ -4,57 +4,58 @@ title: 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. -!!! info "Example" - === "Lua" +:::info Example +Lua - **Callback** - ```lua - -- Alias: exports.oxmysql:query - -- Alias: MySQL.Async.query +**Callback** +```lua +-- Alias: exports.oxmysql:query +-- Alias: MySQL.Async.query - MySQL.query('SELECT * FROM users WHERE identifier = ?', {playerIdentifier}, function(result) - if result then - for _, v in pairs(result) do - print(v.identifier, v.firstname, v.lastname) - end - end - end) - ``` - **Promise** - ```lua - -- Alias: exports.oxmysql:query - -- Alias: MySQL.Sync.query +MySQL.query('SELECT * FROM users WHERE identifier = ?', {playerIdentifier}, function(result) + if result then + for _, v in pairs(result) do + print(v.identifier, v.firstname, v.lastname) + end + end +end) +``` +**Promise** +```lua +-- Alias: exports.oxmysql:query +-- Alias: MySQL.Sync.query - CreateThread(function() - local result = MySQL.query.await('SELECT * FROM users WHERE identifier = ?', {playerIdentifier}) - if result then - for _, v in pairs(result) do - print(v.identifier, v.firstname, v.lastname) - end - end - end) - ``` +CreateThread(function() + local result = MySQL.query.await('SELECT * FROM users WHERE identifier = ?', {playerIdentifier}) + if result then + for _, v in pairs(result) do + print(v.identifier, v.firstname, v.lastname) + end + end +end) +``` - === "JavaScript" +JavaScript - **Callback** - ```js - exports.oxmysql.query('SELECT * FROM users WHERE identifier = ?', [playerIdentifier], function(result) { - if (result) { - result.forEach((v) => { - console.log(v.identifier, v.firstname, v.lastname) - }) - } - }) - ``` - **Promise** - ```js - (async () => { - const result = await exports.oxmysql.query_async('SELECT * FROM users WHERE identifier = ?', [playerIdentifier]) { - if (result) { - result.forEach((v) => { - console.log(v.identifier, v.firstname, v.lastname) - }) - } - })() - ``` \ No newline at end of file +**Callback** +```js +exports.oxmysql.query('SELECT * FROM users WHERE identifier = ?', [playerIdentifier], function(result) { + if (result) { + result.forEach((v) => { + console.log(v.identifier, v.firstname, v.lastname) + }) + } +}) +``` +**Promise** +```js +(async () => { + const result = await exports.oxmysql.query_async('SELECT * FROM users WHERE identifier = ?', [playerIdentifier]) { + if (result) { + result.forEach((v) => { + console.log(v.identifier, v.firstname, v.lastname) + }) + } +})() +``` +::: \ No newline at end of file diff --git a/docs/oxmysql/Usage/scalar.md b/docs/oxmysql/Usage/scalar.md index b99ef712..a09b742b 100644 --- a/docs/oxmysql/Usage/scalar.md +++ b/docs/oxmysql/Usage/scalar.md @@ -3,41 +3,42 @@ title: scalar --- Returns the first column for a single row. -!!! info "Example" - === "Lua" +:::info Example +Lua - **Callback** - ```lua - -- Alias: exports.oxmysql:scalar - -- Alias: MySQL.Async.fetchScalar +**Callback** +```lua +-- Alias: exports.oxmysql:scalar +-- Alias: MySQL.Async.fetchScalar - MySQL.scalar('SELECT firstname FROM users WHERE identifier = ?', {playerIdentifier}, function(firstname) - print(firstname) - end) - ``` - **Promise** - ```lua - -- Alias: exports.oxmysql:scalar_async - -- Alias: MySQL.Sync.fetchScalar +MySQL.scalar('SELECT firstname FROM users WHERE identifier = ?', {playerIdentifier}, function(firstname) + print(firstname) +end) +``` +**Promise** +```lua +-- Alias: exports.oxmysql:scalar_async +-- Alias: MySQL.Sync.fetchScalar - CreateThread(function() - local firstname = MySQL.scalar.await('SELECT firstname FROM users WHERE identifier = ?', {playerIdentifier}) - print(firstname) - end) - ``` +CreateThread(function() + local firstname = MySQL.scalar.await('SELECT firstname FROM users WHERE identifier = ?', {playerIdentifier}) + print(firstname) +end) +``` - === "JavaScript" +JavaScript - **Callback** - ```js - exports.oxmysql.scalar('SELECT firstname FROM users WHERE identifier = ?', [playerIdentifier], function(firstname) { - console.log(firstname) - }) - ``` - **Promise** - ```js - (async () => { - const firstname = await exports.oxmysql.scalar_async('SELECT firstname FROM users WHERE identifier = ?', [playerIdentifier]) { - console.log(firstname) - })() - ``` \ No newline at end of file +**Callback** +```js +exports.oxmysql.scalar('SELECT firstname FROM users WHERE identifier = ?', [playerIdentifier], function(firstname) { + console.log(firstname) +}) +``` +**Promise** +```js +(async () => { + const firstname = await exports.oxmysql.scalar_async('SELECT firstname FROM users WHERE identifier = ?', [playerIdentifier]) { + console.log(firstname) +})() +``` +::: \ No newline at end of file diff --git a/docs/oxmysql/Usage/single.md b/docs/oxmysql/Usage/single.md index bb3389c0..6ccf37be 100644 --- a/docs/oxmysql/Usage/single.md +++ b/docs/oxmysql/Usage/single.md @@ -3,47 +3,48 @@ title: single --- Returns the columns for a single row. -!!! info "Example" - === "Lua" +:::info Example +Lua - **Callback** - ```lua - -- Alias: exports.oxmysql:single - -- Alias: MySQL.Async.fetchSingle +**Callback** +```lua +-- Alias: exports.oxmysql:single +-- Alias: MySQL.Async.fetchSingle - MySQL.single('SELECT * FROM users WHERE identifier = ?', {playerIdentifier}, function(result) - if result then - print(result.identifier, result.firstname, result.lastname) - end - end) - ``` - **Promise** - ```lua - -- Alias: exports.oxmysql:single_async - -- Alias: MySQL.Sync.fetchSingle +MySQL.single('SELECT * FROM users WHERE identifier = ?', {playerIdentifier}, function(result) + if result then + print(result.identifier, result.firstname, result.lastname) + end +end) +``` +**Promise** +```lua +-- Alias: exports.oxmysql:single_async +-- Alias: MySQL.Sync.fetchSingle - CreateThread(function() - local result = MySQL.single.await('SELECT * FROM users WHERE identifier = ?', {playerIdentifier}) - if result then - print(result.identifier, result.firstname, result.lastname) - end - end) - ``` +CreateThread(function() + local result = MySQL.single.await('SELECT * FROM users WHERE identifier = ?', {playerIdentifier}) + if result then + print(result.identifier, result.firstname, result.lastname) + end +end) +``` - === "JavaScript" +JavaScript - **Callback** - ```js - exports.oxmysql.single('SELECT * FROM users WHERE identifier = ?', [playerIdentifier], function(result) { - if (result) - console.log(result.identifier, result.firstname, result.lastname) - }) - ``` - **Promise** - ```js - setImmediate(async () => { - const result = await exports.oxmysql.single_async('SELECT * FROM users WHERE identifier = ?', [playerIdentifier]) { - if (result) - console.log(result.identifier, result.firstname, result.lastname) - }) - ``` \ No newline at end of file +**Callback** +```js +exports.oxmysql.single('SELECT * FROM users WHERE identifier = ?', [playerIdentifier], function(result) { + if (result) + console.log(result.identifier, result.firstname, result.lastname) +}) +``` +**Promise** +```js +setImmediate(async () => { + const result = await exports.oxmysql.single_async('SELECT * FROM users WHERE identifier = ?', [playerIdentifier]) { + if (result) + console.log(result.identifier, result.firstname, result.lastname) +}) +``` +::: \ No newline at end of file diff --git a/docs/oxmysql/Usage/update.md b/docs/oxmysql/Usage/update.md index 4545e2fb..561b4764 100644 --- a/docs/oxmysql/Usage/update.md +++ b/docs/oxmysql/Usage/update.md @@ -3,47 +3,48 @@ title: update --- Returns the number of affected rows by the query. -!!! info "Example" - === "Lua" +:::info Example +Lua - **Callback** - ```lua - -- Alias: exports.oxmysql:update - -- Alias: MySQL.Async.update +**Callback** +```lua +-- Alias: exports.oxmysql:update +-- Alias: MySQL.Async.update - MySQL.Async.update('UPDATE users SET firstname = ? WHERE identifier = ? ', {newName, playerIdentifier}, function(affectedRows) - if affectedRows then - print(affectedRows) - end - end) - ``` - **Promise** - ```lua - -- Alias: exports.oxmysql:update_async - -- Alias: MySQL.update +MySQL.Async.update('UPDATE users SET firstname = ? WHERE identifier = ? ', {newName, playerIdentifier}, function(affectedRows) + if affectedRows then + print(affectedRows) + end +end) +``` +**Promise** +```lua +-- Alias: exports.oxmysql:update_async +-- Alias: MySQL.update - CreateThread(function() - local affectedRows = MySQL.update.await('UPDATE users SET firstname = ? WHERE identifier = ? ', {newName, playerIdentifier}) - if affectedRows then - print(affectedRows) - end - end) - ``` +CreateThread(function() + local affectedRows = MySQL.update.await('UPDATE users SET firstname = ? WHERE identifier = ? ', {newName, playerIdentifier}) + if affectedRows then + print(affectedRows) + end +end) +``` - === "JavaScript" +JavaScript - **Callback** - ```js - exports.oxmysql.update('UPDATE users SET firstname = ? WHERE identifier = ? ', [newName, playerIdentifier], function(affectedRows) { - if (affectedRows) - console.log(affectedRows) - }) - ``` - **Promise** - ```js - setImmediate(async () => { - const id = exports.oxmysql.update_async('UPDATE users SET firstname = ? WHERE identifier = ? ', [newName, playerIdentifier]) { - if (affectedRows) - console.log(affectedRows) - }) - ``` +**Callback** +```js +exports.oxmysql.update('UPDATE users SET firstname = ? WHERE identifier = ? ', [newName, playerIdentifier], function(affectedRows) { + if (affectedRows) + console.log(affectedRows) +}) +``` +**Promise** +```js +setImmediate(async () => { + const id = exports.oxmysql.update_async('UPDATE users SET firstname = ? WHERE identifier = ? ', [newName, playerIdentifier]) { + if (affectedRows) + console.log(affectedRows) +}) +``` +::: \ No newline at end of file