From 2c2f4e066147381f99f17430db332301066e196d Mon Sep 17 00:00:00 2001 From: Linden <65407488+thelindat@users.noreply.github.com> Date: Mon, 25 Oct 2021 08:09:00 +1100 Subject: [PATCH] Wrap Sync exports in CreateThread/setImmediate --- docs/usage/execute.md | 26 +++++++++++++++----------- docs/usage/insert.md | 18 +++++++++++------- docs/usage/scalar.md | 18 +++++++++++------- docs/usage/single.md | 18 +++++++++++------- docs/usage/update.md | 18 +++++++++++------- 5 files changed, 59 insertions(+), 39 deletions(-) diff --git a/docs/usage/execute.md b/docs/usage/execute.md index ab837b8..5784759 100644 --- a/docs/usage/execute.md +++ b/docs/usage/execute.md @@ -18,12 +18,14 @@ When selecting data it will return all matching rows and columns, otherwise it w ``` **Sync** ```lua - local result = exports.oxmysql:executeSync('SELECT * FROM users WHERE identifier = ?', {playerIdentifier}) - if result then - for _, v in pairs(result) do - print(v.identifier, v.firstname, v.lastname) + CreateThread(function() + local result = exports.oxmysql:executeSync('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 + end) ``` === "JavaScript" **Async** @@ -38,10 +40,12 @@ When selecting data it will return all matching rows and columns, otherwise it w ``` **Sync** ```js - const result = await exports.oxmysql.executeSync('SELECT * FROM users WHERE identifier = ?', [playerIdentifier]) { - if (result) { - result.forEach((v) => { - console.log(v.identifier, v.firstname, v.lastname) - }) - } + setImmediate(async () => { + const result = await exports.oxmysql.executeSync('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/usage/insert.md b/docs/usage/insert.md index 15cf0ba..329b47d 100644 --- a/docs/usage/insert.md +++ b/docs/usage/insert.md @@ -15,10 +15,12 @@ Inserts a new entry into the database and returns the insert id for the row, if ``` **Sync** ```lua - local id = exports.oxmysql:insertSync('INSERT INTO users (identifier, firstname, lastname) VALUES (?, ?, ?) ', {playerIdentifier, firstName, lastName}) - if id then - print(id) - end + CreateThread(function() + local id = exports.oxmysql:insertSync('INSERT INTO users (identifier, firstname, lastname) VALUES (?, ?, ?) ', {playerIdentifier, firstName, lastName}) + if id then + print(id) + end + end) ``` === "JavaScript" **Async** @@ -30,7 +32,9 @@ Inserts a new entry into the database and returns the insert id for the row, if ``` **Sync** ```js - const id = exports.oxmysql.insertSync('INSERT INTO users (identifier, firstname, lastname) VALUES (?, ?, ?) ', [playerIdentifier, firstName, lastName]) { - if (id) - console.log(id) + setImmediate(async () => { + const id = exports.oxmysql.insertSync('INSERT INTO users (identifier, firstname, lastname) VALUES (?, ?, ?) ', [playerIdentifier, firstName, lastName]) { + if (id) + console.log(id) + }) ``` \ No newline at end of file diff --git a/docs/usage/scalar.md b/docs/usage/scalar.md index c6761a5..9a228b6 100644 --- a/docs/usage/scalar.md +++ b/docs/usage/scalar.md @@ -15,10 +15,12 @@ Returns the first column for a single row. ``` **Sync** ```lua - local result = exports.oxmysql:scalarSync('SELECT firstname FROM users WHERE identifier = ?', {playerIdentifier}) - if result then - print(result.firstname) - end + CreateThread(function() + local result = exports.oxmysql:scalarSync('SELECT firstname FROM users WHERE identifier = ?', {playerIdentifier}) + if result then + print(result.firstname) + end + end) ``` === "JavaScript" **Async** @@ -30,7 +32,9 @@ Returns the first column for a single row. ``` **Sync** ```js - const result = await exports.oxmysql.scalarSync('SELECT firstname FROM users WHERE identifier = ?', [playerIdentifier]) { - if (result) - console.log(result.firstname) + setImmediate(async () => { + const result = await exports.oxmysql.scalarSync('SELECT firstname FROM users WHERE identifier = ?', [playerIdentifier]) { + if (result) + console.log(result.firstname) + }) ``` \ No newline at end of file diff --git a/docs/usage/single.md b/docs/usage/single.md index fa9768c..b7edbb0 100644 --- a/docs/usage/single.md +++ b/docs/usage/single.md @@ -15,10 +15,12 @@ Returns the columns for a single row. ``` **Sync** ```lua - local result = exports.oxmysql:singleSync('SELECT * FROM users WHERE identifier = ?', {playerIdentifier}) - if result then - print(result.identifier, result.firstname, result.lastname) - end + CreateThread(function() + local result = exports.oxmysql:singleSync('SELECT * FROM users WHERE identifier = ?', {playerIdentifier}) + if result then + print(result.identifier, result.firstname, result.lastname) + end + end) ``` === "JavaScript" **Async** @@ -30,7 +32,9 @@ Returns the columns for a single row. ``` **Sync** ```js - const result = await exports.oxmysql.singleSync('SELECT * FROM users WHERE identifier = ?', [playerIdentifier]) { - if (result) - console.log(result.identifier, result.firstname, result.lastname) + setImmediate(async () => { + const result = await exports.oxmysql.singleSync('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/usage/update.md b/docs/usage/update.md index 1832d4f..51857ca 100644 --- a/docs/usage/update.md +++ b/docs/usage/update.md @@ -15,10 +15,12 @@ Updates an entry in the database and returns the number of affected rows. ``` **Sync** ```lua - local id = exports.oxmysql:insertSync('UPDATE users SET firstname = ? WHERE identifier = ? ', {newName, playerIdentifier}) - if affectedRows then - print(affectedRows) - end + CreateThread(function() + local id = exports.oxmysql:insertSync('UPDATE users SET firstname = ? WHERE identifier = ? ', {newName, playerIdentifier}) + if affectedRows then + print(affectedRows) + end + end) ``` === "JavaScript" **Async** @@ -30,7 +32,9 @@ Updates an entry in the database and returns the number of affected rows. ``` **Sync** ```js - const id = exports.oxmysql.insertSync('UPDATE users SET firstname = ? WHERE identifier = ? ', [newName, playerIdentifier]) { - if (affectedRows) - console.log(affectedRows) + setImmediate(async () => { + const id = exports.oxmysql.insertSync('UPDATE users SET firstname = ? WHERE identifier = ? ', [newName, playerIdentifier]) { + if (affectedRows) + console.log(affectedRows) + }) ``` \ No newline at end of file