mirror of
https://github.com/darksaid98/oxmysql.git
synced 2026-12-02 14:38:50 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4e29905179 | ||
|
|
78ce45f1de | ||
|
|
193da3e6c7 | ||
|
|
cd2e73953f | ||
|
|
3928415930 | ||
|
|
b27662d138 | ||
|
|
45b90c4ad3 |
No files matched your search
@@ -2,7 +2,7 @@
|
|||||||
name: Bug report
|
name: Bug report
|
||||||
about: Create a report to help us improve
|
about: Create a report to help us improve
|
||||||
title: ''
|
title: ''
|
||||||
labels: ''
|
labels: bug
|
||||||
assignees: ''
|
assignees: ''
|
||||||
|
|
||||||
---
|
---
|
||||||
@@ -23,7 +23,7 @@ If applicable, add screenshots to help explain your problem.
|
|||||||
|
|
||||||
**Code**
|
**Code**
|
||||||
```lua
|
```lua
|
||||||
If applicable, include the query and relevant code
|
-- If applicable, include the query and relevant code
|
||||||
```
|
```
|
||||||
|
|
||||||
**Expected behavior**
|
**Expected behavior**
|
||||||
@@ -33,6 +33,9 @@ A clear and concise description of what you expected to happen.
|
|||||||
Add any other context about the problem here.
|
Add any other context about the problem here.
|
||||||
|
|
||||||
**Server details**
|
**Server details**
|
||||||
- FX Server artifact
|
- FXServer artifact
|
||||||
- Operating system
|
- Operating system
|
||||||
- Framework
|
|
||||||
|
**Database details**
|
||||||
|
- MariaDB or MySQL
|
||||||
|
- Version
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
---
|
||||||
|
name: Feature request
|
||||||
|
about: Suggest an idea for this project
|
||||||
|
title: ''
|
||||||
|
labels: enhancement
|
||||||
|
assignees: ''
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**Is your feature request related to a problem? Please describe.**
|
||||||
|
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
||||||
|
|
||||||
|
**Describe the solution you'd like**
|
||||||
|
A clear and concise description of what you want to happen.
|
||||||
|
|
||||||
|
**Describe alternatives you've considered**
|
||||||
|
A clear and concise description of any alternative solutions or features you've considered.
|
||||||
|
|
||||||
|
**Additional context**
|
||||||
|
Add any other context or screenshots about the feature request here.
|
||||||
+5
-2
@@ -3,14 +3,17 @@ game 'common'
|
|||||||
|
|
||||||
name 'oxmysql'
|
name 'oxmysql'
|
||||||
description 'Database wrapper for FiveM utilising node-mysql2 offering improved performance and security.'
|
description 'Database wrapper for FiveM utilising node-mysql2 offering improved performance and security.'
|
||||||
version '1.8.4'
|
version '1.8.7'
|
||||||
url 'https://github.com/overextended/oxmysql'
|
url 'https://github.com/overextended/oxmysql'
|
||||||
author 'overextended'
|
author 'overextended'
|
||||||
use_fxv2_oal 'yes'
|
use_fxv2_oal 'yes'
|
||||||
lua54 'yes'
|
lua54 'yes'
|
||||||
|
|
||||||
server_scripts {
|
--dependencies {
|
||||||
-- '/server:4837', Disabled until the heat death of the universe (or recommended artifact updates)
|
-- '/server:4837', Disabled until the heat death of the universe (or recommended artifact updates)
|
||||||
|
--}
|
||||||
|
|
||||||
|
server_scripts {
|
||||||
'oxmysql.js',
|
'oxmysql.js',
|
||||||
'wrapper.lua'
|
'wrapper.lua'
|
||||||
}
|
}
|
||||||
|
|||||||
+90
-95
@@ -28,105 +28,100 @@ CreateThread(function()
|
|||||||
end, 'GET')
|
end, 'GET')
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- Check for the existance of a native from FXServer 4837 to disable Lua exports
|
---@param query string
|
||||||
-- Shame dependency constraints were added immediately after the recommended build
|
---@param parameters? table
|
||||||
if not MumbleSetPlayerMuted then
|
---@return integer result
|
||||||
|
---returns array of matching rows or result data
|
||||||
|
exports('executeSync', function(query, parameters)
|
||||||
|
local p = promise.new()
|
||||||
|
oxmysql:execute(query, parameters, function(result)
|
||||||
|
p:resolve(result)
|
||||||
|
end, GetInvokingResource())
|
||||||
|
return Citizen.Await(p)
|
||||||
|
end)
|
||||||
|
|
||||||
---@param query string
|
---@param query string
|
||||||
---@param parameters? table
|
---@param parameters? table
|
||||||
---@return integer result
|
---@return table result
|
||||||
---returns array of matching rows or result data
|
---returns array of matching rows or result data
|
||||||
exports('executeSync', function(query, parameters)
|
exports('fetchSync', function(query, parameters)
|
||||||
local p = promise.new()
|
local p = promise.new()
|
||||||
oxmysql:execute(query, parameters, function(result)
|
oxmysql:fetch(query, parameters, function(result)
|
||||||
p:resolve(result)
|
p:resolve(result)
|
||||||
end, GetInvokingResource())
|
end, GetInvokingResource())
|
||||||
return Citizen.Await(p)
|
return Citizen.Await(p)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
---@param query string
|
---@param query string
|
||||||
---@param parameters? table
|
---@param parameters? table
|
||||||
---@return table result
|
---@return table result
|
||||||
---returns array of matching rows or result data
|
---returns table containing key value pairs
|
||||||
exports('fetchSync', function(query, parameters)
|
exports('singleSync', function(query, parameters)
|
||||||
local p = promise.new()
|
local p = promise.new()
|
||||||
oxmysql:fetch(query, parameters, function(result)
|
oxmysql:single(query, parameters, function(result)
|
||||||
p:resolve(result)
|
p:resolve(result)
|
||||||
end, GetInvokingResource())
|
end, GetInvokingResource())
|
||||||
return Citizen.Await(p)
|
return Citizen.Await(p)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
---@param query string
|
---@param query string
|
||||||
---@param parameters? table
|
---@param parameters? table
|
||||||
---@return table result
|
---@return integer|string
|
||||||
---returns table containing key value pairs
|
---returns value of the first column of a single row
|
||||||
exports('singleSync', function(query, parameters)
|
exports('scalarSync', function(query, parameters)
|
||||||
local p = promise.new()
|
local p = promise.new()
|
||||||
oxmysql:single(query, parameters, function(result)
|
oxmysql:scalar(query, parameters, function(result)
|
||||||
p:resolve(result)
|
p:resolve(result)
|
||||||
end, GetInvokingResource())
|
end, GetInvokingResource())
|
||||||
return Citizen.Await(p)
|
return Citizen.Await(p)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
---@param query string
|
---@param query string
|
||||||
---@param parameters? table
|
---@param parameters? table
|
||||||
---@return integer|string
|
---@return table result
|
||||||
---returns value of the first column of a single row
|
---returns the last inserted id
|
||||||
exports('scalarSync', function(query, parameters)
|
exports('insertSync', function(query, parameters)
|
||||||
local p = promise.new()
|
local p = promise.new()
|
||||||
oxmysql:scalar(query, parameters, function(result)
|
oxmysql:insert(query, parameters, function(result)
|
||||||
p:resolve(result)
|
p:resolve(result)
|
||||||
end, GetInvokingResource())
|
end, GetInvokingResource())
|
||||||
return Citizen.Await(p)
|
return Citizen.Await(p)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
---@param query string
|
---@param query string
|
||||||
---@param parameters? table
|
---@param parameters? table
|
||||||
---@return table result
|
---@return integer result
|
||||||
---returns the last inserted id
|
---returns number of rows updated by the executed query
|
||||||
exports('insertSync', function(query, parameters)
|
exports('updateSync', function(query, parameters)
|
||||||
local p = promise.new()
|
local p = promise.new()
|
||||||
oxmysql:insert(query, parameters, function(result)
|
oxmysql:update(query, parameters, function(result)
|
||||||
p:resolve(result)
|
p:resolve(result)
|
||||||
end, GetInvokingResource())
|
end, GetInvokingResource())
|
||||||
return Citizen.Await(p)
|
return Citizen.Await(p)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
---@param query string
|
---@param queries table
|
||||||
---@param parameters? table
|
---@param parameters? table
|
||||||
---@return integer result
|
---@return boolean result
|
||||||
---returns number of rows updated by the executed query
|
---returns true when the transaction has succeeded
|
||||||
exports('updateSync', function(query, parameters)
|
exports('transactionSync', function(queries, parameters)
|
||||||
local p = promise.new()
|
local p = promise.new()
|
||||||
oxmysql:update(query, parameters, function(result)
|
oxmysql:transaction(queries, parameters, function(result)
|
||||||
p:resolve(result)
|
p:resolve(result)
|
||||||
end, GetInvokingResource())
|
end, GetInvokingResource())
|
||||||
return Citizen.Await(p)
|
return Citizen.Await(p)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
---@param queries table
|
---@param query string
|
||||||
---@param parameters? table
|
---@param parameters table
|
||||||
---@return boolean result
|
---@return any result
|
||||||
---returns true when the transaction has succeeded
|
---supports SELECT, INSERT, UPDATE, and DELETE
|
||||||
exports('transactionSync', function(queries, parameters)
|
---
|
||||||
local p = promise.new()
|
---return value is based on the number of results and the type of query used
|
||||||
oxmysql:transaction(queries, parameters, function(result)
|
exports('prepareSync', function(query, parameters)
|
||||||
p:resolve(result)
|
local p = promise.new()
|
||||||
end, GetInvokingResource())
|
oxmysql:prepare(query, parameters, function(result)
|
||||||
return Citizen.Await(p)
|
p:resolve(result)
|
||||||
end)
|
end, GetInvokingResource())
|
||||||
|
return Citizen.Await(p)
|
||||||
---@param query string
|
end)
|
||||||
---@param parameters table
|
|
||||||
---@return any result
|
|
||||||
---supports SELECT, INSERT, UPDATE, and DELETE
|
|
||||||
---
|
|
||||||
---return value is based on the number of results and the type of query used
|
|
||||||
exports('prepareSync', function(query, parameters)
|
|
||||||
local p = promise.new()
|
|
||||||
oxmysql:prepare(query, parameters, function(result)
|
|
||||||
p:resolve(result)
|
|
||||||
end, GetInvokingResource())
|
|
||||||
return Citizen.Await(p)
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
diff --git a/node_modules/named-placeholders/index.js b/node_modules/named-placeholders/index.js
|
diff --git a/node_modules/named-placeholders/index.js b/node_modules/named-placeholders/index.js
|
||||||
index 527d723..f63ce28 100644
|
index 527d723..728188b 100644
|
||||||
--- a/node_modules/named-placeholders/index.js
|
--- a/node_modules/named-placeholders/index.js
|
||||||
+++ b/node_modules/named-placeholders/index.js
|
+++ b/node_modules/named-placeholders/index.js
|
||||||
@@ -3,7 +3,7 @@
|
@@ -3,7 +3,7 @@
|
||||||
@@ -11,12 +11,13 @@ index 527d723..f63ce28 100644
|
|||||||
DQUOTE = 34,
|
DQUOTE = 34,
|
||||||
SQUOTE = 39,
|
SQUOTE = 39,
|
||||||
BSLASH = 92;
|
BSLASH = 92;
|
||||||
@@ -94,15 +94,22 @@ function createCompiler(config) {
|
@@ -94,6 +94,14 @@ function createCompiler(config) {
|
||||||
if (typeof params == 'undefined')
|
if (typeof params == 'undefined')
|
||||||
throw new Error('Named query contains placeholders, but parameters object is undefined');
|
throw new Error('Named query contains placeholders, but parameters object is undefined');
|
||||||
|
|
||||||
+ for(const key in params) {
|
+ for(const key in params) {
|
||||||
+ if(key.charAt(0) === '@' || key.charAt(0) === ':') {
|
+ const char = key[0]
|
||||||
|
+ if(char == '@' || char == ':') {
|
||||||
+ params[key.substring(1)] = params[key];
|
+ params[key.substring(1)] = params[key];
|
||||||
+ delete params[key];
|
+ delete params[key];
|
||||||
+ }
|
+ }
|
||||||
@@ -24,33 +25,34 @@ index 527d723..f63ce28 100644
|
|||||||
+
|
+
|
||||||
const tokens = tree[1];
|
const tokens = tree[1];
|
||||||
for (let i=0; i < tokens.length; ++i) {
|
for (let i=0; i < tokens.length; ++i) {
|
||||||
- arr.push(params[tokens[i]]);
|
arr.push(params[tokens[i]]);
|
||||||
+ arr.push(params[tokens[i]] === undefined ? null : params[tokens[i]]);
|
@@ -102,7 +110,8 @@ function createCompiler(config) {
|
||||||
}
|
|
||||||
return [tree[0], arr];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function noTailingSemicolon(s) {
|
function noTailingSemicolon(s) {
|
||||||
- if (s.slice(-1) == ':') {
|
- if (s.slice(-1) == ':') {
|
||||||
+ if (s.slice(-1) == ':' || s.slice(-1) == '@') {
|
+ const char = s.slice(-1)
|
||||||
|
+ if (char == ':' || char == '@') {
|
||||||
return s.slice(0, -1);
|
return s.slice(0, -1);
|
||||||
}
|
}
|
||||||
return s;
|
return s;
|
||||||
@@ -115,7 +122,7 @@ function createCompiler(config) {
|
@@ -115,7 +124,8 @@ function createCompiler(config) {
|
||||||
|
|
||||||
let unnamed = noTailingSemicolon(tree[0][0]);
|
let unnamed = noTailingSemicolon(tree[0][0]);
|
||||||
for (let i=1; i < tree[0].length; ++i) {
|
for (let i=1; i < tree[0].length; ++i) {
|
||||||
- if (tree[0][i-1].slice(-1) == ':') {
|
- if (tree[0][i-1].slice(-1) == ':') {
|
||||||
+ if (tree[0][i-1].slice(-1) == ':' || tree[0][i-1].slice(-1) == '@') {
|
+ const char = tree[0][i-1].slice(-1)
|
||||||
|
+ if (char == ':' || char == '@') {
|
||||||
unnamed += config.placeholder;
|
unnamed += config.placeholder;
|
||||||
}
|
}
|
||||||
unnamed += config.placeholder;
|
unnamed += config.placeholder;
|
||||||
@@ -124,7 +131,7 @@ function createCompiler(config) {
|
@@ -124,7 +134,8 @@ function createCompiler(config) {
|
||||||
|
|
||||||
const last = tree[0][tree[0].length -1];
|
const last = tree[0][tree[0].length -1];
|
||||||
if (tree[0].length == tree[1].length) {
|
if (tree[0].length == tree[1].length) {
|
||||||
- if (last.slice(-1) == ':') {
|
- if (last.slice(-1) == ':') {
|
||||||
+ if (last.slice(-1) == ':' || last.slice(-1) == '@') {
|
+ const char = last.slice(-1)
|
||||||
|
+ if (char == ':' || char == '@') {
|
||||||
unnamed += config.placeholder;
|
unnamed += config.placeholder;
|
||||||
}
|
}
|
||||||
unnamed += config.placeholder;
|
unnamed += config.placeholder;
|
||||||
+31
-10
@@ -1,16 +1,38 @@
|
|||||||
import { pool } from './pool';
|
import { pool } from './pool';
|
||||||
import { parseParameters } from './parser';
|
import { parseParameters } from './parser';
|
||||||
import { slowQueryWarning, debug, resourceName } from './config';
|
import { slowQueryWarning, debug, resourceName, isolationLevel } from './config';
|
||||||
import { FormatError } from './errors';
|
import { FormatError } from './errors';
|
||||||
|
|
||||||
|
let isReady = false;
|
||||||
|
|
||||||
|
const serverReady = async () => {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
const id = setInterval(() => {
|
||||||
|
if (GetResourceState(resourceName) == 'started') resolve(id);
|
||||||
|
}, 50);
|
||||||
|
}).then((id) => {
|
||||||
|
clearInterval(id);
|
||||||
|
isReady = true;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
setImmediate(async () => {
|
||||||
|
try {
|
||||||
|
await pool.query(isolationLevel);
|
||||||
|
console.log(`^2Database server connection established!^0`);
|
||||||
|
} catch (error) {
|
||||||
|
console.log(`^3Unable to establish a connection to the database! [${error.code}]\n${error.message}^0`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
const execute = async (query, parameters, resource) => {
|
const execute = async (query, parameters, resource) => {
|
||||||
|
if (!isReady) await serverReady();
|
||||||
try {
|
try {
|
||||||
[query, parameters] = parseParameters(query, parameters);
|
[query, parameters] = parseParameters(query, parameters);
|
||||||
const connection = await pool.getConnection();
|
|
||||||
ScheduleResourceTick(resourceName);
|
|
||||||
|
|
||||||
|
ScheduleResourceTick(resourceName);
|
||||||
const startTime = process.hrtime();
|
const startTime = process.hrtime();
|
||||||
const [rows] = await connection.query(query, parameters);
|
const [rows] = await pool.query(query, parameters);
|
||||||
const executionTime = process.hrtime(startTime)[1] / 1000000; // nanosecond to millisecond
|
const executionTime = process.hrtime(startTime)[1] / 1000000; // nanosecond to millisecond
|
||||||
|
|
||||||
if (executionTime >= slowQueryWarning || debug)
|
if (executionTime >= slowQueryWarning || debug)
|
||||||
@@ -19,7 +41,6 @@ const execute = async (query, parameters, resource) => {
|
|||||||
${query} ${JSON.stringify(parameters)}^0`
|
${query} ${JSON.stringify(parameters)}^0`
|
||||||
);
|
);
|
||||||
|
|
||||||
connection.release();
|
|
||||||
return rows;
|
return rows;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(
|
console.log(
|
||||||
@@ -47,6 +68,9 @@ const queryType = (query) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const preparedStatement = async (query, parameters, resource) => {
|
const preparedStatement = async (query, parameters, resource) => {
|
||||||
|
if (!isReady) await serverReady();
|
||||||
|
ScheduleResourceTick(resourceName);
|
||||||
|
const connection = await pool.getConnection();
|
||||||
try {
|
try {
|
||||||
if (!Array.isArray(parameters))
|
if (!Array.isArray(parameters))
|
||||||
throw new FormatError(`Placeholders were defined, but query received no parameters!`, query);
|
throw new FormatError(`Placeholders were defined, but query received no parameters!`, query);
|
||||||
@@ -56,9 +80,6 @@ const preparedStatement = async (query, parameters, resource) => {
|
|||||||
const type = queryType(query);
|
const type = queryType(query);
|
||||||
if (!type) throw new FormatError(`Prepared statements only accept SELECT, INSERT, UPDATE, and DELETE methods!`);
|
if (!type) throw new FormatError(`Prepared statements only accept SELECT, INSERT, UPDATE, and DELETE methods!`);
|
||||||
|
|
||||||
const connection = await pool.getConnection();
|
|
||||||
ScheduleResourceTick(resourceName);
|
|
||||||
|
|
||||||
const results = [];
|
const results = [];
|
||||||
let queryCount = parameters.length;
|
let queryCount = parameters.length;
|
||||||
const startTime = process.hrtime();
|
const startTime = process.hrtime();
|
||||||
@@ -77,8 +98,6 @@ const preparedStatement = async (query, parameters, resource) => {
|
|||||||
${query} ${JSON.stringify(parameters)}^0`
|
${query} ${JSON.stringify(parameters)}^0`
|
||||||
);
|
);
|
||||||
|
|
||||||
connection.release();
|
|
||||||
|
|
||||||
if (results.length === 1) {
|
if (results.length === 1) {
|
||||||
if (type === 1) {
|
if (type === 1) {
|
||||||
if (results[0][0] && Object.keys(results[0][0]).length === 1) {
|
if (results[0][0] && Object.keys(results[0][0]).length === 1) {
|
||||||
@@ -96,6 +115,8 @@ const preparedStatement = async (query, parameters, resource) => {
|
|||||||
${error.sql || `${query} ${JSON.stringify(parameters)}`}^0`
|
${error.sql || `${query} ${JSON.stringify(parameters)}`}^0`
|
||||||
);
|
);
|
||||||
debug && console.trace(error);
|
debug && console.trace(error);
|
||||||
|
} finally {
|
||||||
|
connection.release();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
+34
-51
@@ -1,16 +1,6 @@
|
|||||||
import { pool } from './pool';
|
|
||||||
import { execute, preparedStatement } from './execute';
|
import { execute, preparedStatement } from './execute';
|
||||||
import { transaction } from './transaction';
|
import { transaction } from './transaction';
|
||||||
import { debug, isolationLevel } from './config';
|
import { debug } from './config';
|
||||||
|
|
||||||
setImmediate(async () => {
|
|
||||||
try {
|
|
||||||
await pool.query(isolationLevel);
|
|
||||||
console.log(`^2Database server connection established!^0`);
|
|
||||||
} catch (error) {
|
|
||||||
console.log(`^3Unable to establish a connection to the database! [${error.code}]\n${error.message}^0`);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
const safeCallback = (callback, result) => {
|
const safeCallback = (callback, result) => {
|
||||||
if (typeof callback === 'function') callback(result);
|
if (typeof callback === 'function') callback(result);
|
||||||
@@ -52,51 +42,44 @@ global.exports('prepare', (query, parameters, cb, resource = GetInvokingResource
|
|||||||
preparedStatement(query, parameters, resource).then((result) => safeCallback(cb || parameters, result));
|
preparedStatement(query, parameters, resource).then((result) => safeCallback(cb || parameters, result));
|
||||||
});
|
});
|
||||||
|
|
||||||
try {
|
if (!GetResourceMetadata(GetCurrentResourceName(), 'server_script', 1)) {
|
||||||
// Check for the existance of a native from FXServer 4837 to enable JS exports
|
global.exports('prepareSync', async (query, parameters) => {
|
||||||
if (MumbleSetPlayerMuted || !GetResourceMetadata(GetCurrentResourceName(), 'server_script', 1)) {
|
const result = await preparedStatement(query, parameters, GetInvokingResource());
|
||||||
global.exports('prepareSync', async (query, parameters) => {
|
return result;
|
||||||
const result = await preparedStatement(query, parameters, GetInvokingResource());
|
});
|
||||||
return result;
|
|
||||||
});
|
|
||||||
|
|
||||||
global.exports('executeSync', async (query, parameters) => {
|
global.exports('executeSync', async (query, parameters) => {
|
||||||
const result = await execute(query, parameters, GetInvokingResource());
|
const result = await execute(query, parameters, GetInvokingResource());
|
||||||
return result;
|
return result;
|
||||||
});
|
});
|
||||||
|
|
||||||
global.exports('insertSync', async (query, parameters) => {
|
global.exports('insertSync', async (query, parameters) => {
|
||||||
const result = await execute(query, parameters, GetInvokingResource());
|
const result = await execute(query, parameters, GetInvokingResource());
|
||||||
return result && result.insertId;
|
return result && result.insertId;
|
||||||
});
|
});
|
||||||
|
|
||||||
global.exports('updateSync', async (query, parameters) => {
|
global.exports('updateSync', async (query, parameters) => {
|
||||||
const result = await execute(query, parameters, GetInvokingResource());
|
const result = await execute(query, parameters, GetInvokingResource());
|
||||||
return result && result.affectedRows;
|
return result && result.affectedRows;
|
||||||
});
|
});
|
||||||
|
|
||||||
global.exports('fetchSync', async (query, parameters) => {
|
global.exports('fetchSync', async (query, parameters) => {
|
||||||
const result = await execute(query, parameters, GetInvokingResource());
|
const result = await execute(query, parameters, GetInvokingResource());
|
||||||
return result;
|
return result;
|
||||||
});
|
});
|
||||||
|
|
||||||
global.exports('singleSync', async (query, parameters) => {
|
global.exports('singleSync', async (query, parameters) => {
|
||||||
const result = await execute(query, parameters, GetInvokingResource());
|
const result = await execute(query, parameters, GetInvokingResource());
|
||||||
return result && result[0];
|
return result && result[0];
|
||||||
});
|
});
|
||||||
|
|
||||||
global.exports('scalarSync', async (query, parameters) => {
|
global.exports('scalarSync', async (query, parameters) => {
|
||||||
const result = await execute(query, parameters, GetInvokingResource());
|
const result = await execute(query, parameters, GetInvokingResource());
|
||||||
return result && result[0] && Object.values(result[0])[0];
|
return result && result[0] && Object.values(result[0])[0];
|
||||||
});
|
});
|
||||||
|
|
||||||
global.exports('transactionSync', async (queries, parameters) => {
|
global.exports('transactionSync', async (queries, parameters) => {
|
||||||
const result = await transaction(queries, parameters, GetInvokingResource());
|
const result = await transaction(queries, parameters, GetInvokingResource());
|
||||||
return result;
|
return result;
|
||||||
});
|
});
|
||||||
}
|
|
||||||
} catch(e) {
|
|
||||||
setTimeout(() => {
|
|
||||||
console.log(`^3Unable to load enhanced sync exports (download FXServer 4837+)^0`);
|
|
||||||
}, 1000)
|
|
||||||
}
|
}
|
||||||
+7
-1
@@ -22,8 +22,14 @@ const dbOptions = (() => {
|
|||||||
return connectionInfo;
|
return connectionInfo;
|
||||||
}, {});
|
}, {});
|
||||||
|
|
||||||
options.namedPlaceholders = true;
|
|
||||||
options.typeCast = parseTypes;
|
options.typeCast = parseTypes;
|
||||||
|
options.namedPlaceholders = true;
|
||||||
|
|
||||||
|
// increase the default timeout for slow servers
|
||||||
|
options.connectTimeout = options.connectTimeout || 60000;
|
||||||
|
|
||||||
|
// disabled to prevent SQL injection
|
||||||
|
options.multipleStatements = options.multipleStatements || false;
|
||||||
|
|
||||||
return options;
|
return options;
|
||||||
})();
|
})();
|
||||||
|
|||||||
+1
-1
@@ -13,10 +13,10 @@ const transaction = async (queries, parameters, resource) => {
|
|||||||
ScheduleResourceTick(resourceName);
|
ScheduleResourceTick(resourceName);
|
||||||
const connection = await pool.getConnection();
|
const connection = await pool.getConnection();
|
||||||
try {
|
try {
|
||||||
const startTime = process.hrtime();
|
|
||||||
|
|
||||||
const fullQuery = parseTransaction(queries, parameters);
|
const fullQuery = parseTransaction(queries, parameters);
|
||||||
const transactionAmount = fullQuery.length;
|
const transactionAmount = fullQuery.length;
|
||||||
|
const startTime = process.hrtime();
|
||||||
|
|
||||||
await connection.beginTransaction();
|
await connection.beginTransaction();
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user