mirror of
https://github.com/darksaid98/oxmysql.git
synced 2026-12-01 14:38:50 +00:00
Wrap Sync exports in CreateThread/setImmediate
This commit is contained in:
1 parent
9af6205bb7
commit
2c2f4e0661
5 files changed
+59
-39
No files matched your search
+15
-11
@@ -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)
|
||||
})
|
||||
}
|
||||
})
|
||||
```
|
||||
+11
-7
@@ -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)
|
||||
})
|
||||
```
|
||||
+11
-7
@@ -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)
|
||||
})
|
||||
```
|
||||
+11
-7
@@ -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)
|
||||
})
|
||||
```
|
||||
+11
-7
@@ -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)
|
||||
})
|
||||
```
|
||||
Reference in new issue
Block a user