mirror of
https://github.com/darksaid98/oxmysql.git
synced 2026-12-02 14:38:50 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4913d6e50a | ||
|
|
ca8cef4e26 | ||
|
|
2a8f4b1ea9 | ||
|
|
1d0a5bcfd9 | ||
|
|
5965442e48 | ||
|
|
f7ed2d5b60 | ||
|
|
ec9d787be4 | ||
|
|
abf259543d | ||
|
|
9d8a29388c | ||
|
|
00f9d0449c | ||
|
|
a46b586832 | ||
|
|
dc50fe6dbb | ||
|
|
a6d483ca48 | ||
|
|
b1babdbc09 | ||
|
|
f8f97344fd | ||
|
|
48ee030372 |
No files matched your search
@@ -0,0 +1,38 @@
|
|||||||
|
---
|
||||||
|
name: Bug report
|
||||||
|
about: Create a report to help us improve
|
||||||
|
title: ''
|
||||||
|
labels: ''
|
||||||
|
assignees: ''
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Issue checklist
|
||||||
|
> Please put `x` inside of the box that matches your issue.
|
||||||
|
|
||||||
|
- [ ] I am using the latest release
|
||||||
|
- [ ] I have referenced previously reported issues
|
||||||
|
- [ ] I have referenced available documentation and cannot resolve the issue
|
||||||
|
- [ ] I'm certain this is an issue with oxymysql, and not with my resource
|
||||||
|
|
||||||
|
**Describe the bug**
|
||||||
|
A clear and concise description of what the bug is.
|
||||||
|
|
||||||
|
**Screenshots**
|
||||||
|
If applicable, add screenshots to help explain your problem.
|
||||||
|
|
||||||
|
**Code**
|
||||||
|
```lua
|
||||||
|
If applicable, include the query and relevant code
|
||||||
|
```
|
||||||
|
|
||||||
|
**Expected behavior**
|
||||||
|
A clear and concise description of what you expected to happen.
|
||||||
|
|
||||||
|
**Additional context**
|
||||||
|
Add any other context about the problem here.
|
||||||
|
|
||||||
|
**Server details**
|
||||||
|
- FX Server artifact
|
||||||
|
- Operating system
|
||||||
|
- Framework
|
||||||
+1
-1
@@ -3,7 +3,7 @@ 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.6.0'
|
version '1.7.0'
|
||||||
url 'https://github.com/overextended/oxmysql'
|
url 'https://github.com/overextended/oxmysql'
|
||||||
author 'overextended'
|
author 'overextended'
|
||||||
use_fxv2_oal 'yes'
|
use_fxv2_oal 'yes'
|
||||||
|
|||||||
+149
-155
@@ -23,172 +23,166 @@ local function safeArgs(query, parameters, cb, transaction)
|
|||||||
return query, parameters, cb
|
return query, parameters, cb
|
||||||
end
|
end
|
||||||
|
|
||||||
MySQL = {
|
MySQL = { Async = {}, Sync = {} }
|
||||||
--- Result is returned to a callback function, without interupting the execution of code
|
|
||||||
Async = {
|
|
||||||
---@param query string
|
|
||||||
---@param parameters? table|function
|
|
||||||
---@param cb? function
|
|
||||||
---@return integer result
|
|
||||||
---returns number of rows updated by the executed query
|
|
||||||
execute = function(query, parameters, cb)
|
|
||||||
Ox:update(safeArgs(query, parameters, cb))
|
|
||||||
end,
|
|
||||||
|
|
||||||
---@param query string
|
---@param query string
|
||||||
---@param parameters? table|function
|
---@param parameters? table|function
|
||||||
---@param cb? function
|
---@param cb? function
|
||||||
---@return table result
|
---@return integer result
|
||||||
---returns array of matching rows or result data
|
---returns number of rows updated by the executed query
|
||||||
fetchAll = function(query, parameters, cb)
|
MySQL.Async.execute = function(query, parameters, cb)
|
||||||
Ox:execute(safeArgs(query, parameters, cb))
|
Ox:update(safeArgs(query, parameters, cb))
|
||||||
end,
|
end
|
||||||
|
|
||||||
---@param query string
|
---@param query string
|
||||||
---@param parameters? table|function
|
---@param parameters? table|function
|
||||||
---@param cb? function
|
---@param cb? function
|
||||||
---@return integer|string
|
---@return table result
|
||||||
---returns value of the first column of a single row
|
---returns array of matching rows or result data
|
||||||
fetchScalar = function(query, parameters, cb)
|
MySQL.Async.fetchAll = function(query, parameters, cb)
|
||||||
Ox:scalar(safeArgs(query, parameters, cb))
|
Ox:execute(safeArgs(query, parameters, cb))
|
||||||
end,
|
end
|
||||||
|
|
||||||
---@param query string
|
---@param query string
|
||||||
---@param parameters? table|function
|
---@param parameters? table|function
|
||||||
---@param cb? function
|
---@param cb? function
|
||||||
---@return table result
|
---@return integer|string
|
||||||
---returns table containing key value pairs
|
---returns value of the first column of a single row
|
||||||
fetchSingle = function(query, parameters, cb)
|
MySQL.Async.fetchScalar = function(query, parameters, cb)
|
||||||
Ox:single(safeArgs(query, parameters, cb))
|
Ox:scalar(safeArgs(query, parameters, cb))
|
||||||
end,
|
end
|
||||||
|
|
||||||
---@param query string
|
---@param query string
|
||||||
---@param parameters? table|function
|
---@param parameters? table|function
|
||||||
---@param cb? function
|
---@param cb? function
|
||||||
---@return table result
|
---@return table result
|
||||||
---returns the last inserted id
|
---returns table containing key value pairs
|
||||||
insert = function(query, parameters, cb)
|
MySQL.Async.fetchSingle = function(query, parameters, cb)
|
||||||
Ox:insert(safeArgs(query, parameters, cb))
|
Ox:single(safeArgs(query, parameters, cb))
|
||||||
end,
|
end
|
||||||
|
|
||||||
---@param queries table
|
---@param query string
|
||||||
---@param parameters? table|function
|
---@param parameters? table|function
|
||||||
---@param cb? function
|
---@param cb? function
|
||||||
---@return boolean result
|
---@return table result
|
||||||
---returns true when the transaction has succeeded
|
---returns the last inserted id
|
||||||
transaction = function(queries, parameters, cb)
|
MySQL.Async.insert = function(query, parameters, cb)
|
||||||
Ox:transaction(safeArgs(queries, parameters, cb, true))
|
Ox:insert(safeArgs(query, parameters, cb))
|
||||||
end,
|
end
|
||||||
|
|
||||||
---@param query string
|
---@param queries table
|
||||||
---@param cb? function
|
---@param parameters? table|function
|
||||||
---@return integer result
|
---@param cb? function
|
||||||
---returns the id used to reference a stored query string
|
---@return boolean result
|
||||||
store = function(query, cb)
|
---returns true when the transaction has succeeded
|
||||||
assert(type(query) == 'string', 'The SQL Query must be a string')
|
MySQL.Async.transaction = function(queries, parameters, cb)
|
||||||
local store = #Store+1
|
Ox:transaction(safeArgs(queries, parameters, cb, true))
|
||||||
Store[store] = query
|
end
|
||||||
cb(store)
|
|
||||||
end,
|
|
||||||
},
|
|
||||||
|
|
||||||
--- Result is assigned in-line to a variable, causing the current thread to await the result
|
---@param query string
|
||||||
Sync = {
|
---@param cb? function
|
||||||
---@param query string
|
---@return integer result
|
||||||
---@param parameters? table|function
|
---returns the id used to reference a stored query string
|
||||||
---@return integer result
|
MySQL.Async.store = function(query, cb)
|
||||||
---returns number of rows updated by the executed query
|
assert(type(query) == 'string', 'The SQL Query must be a string')
|
||||||
execute = function(query, parameters)
|
local store = #Store+1
|
||||||
query, parameters = safeArgs(query, parameters)
|
Store[store] = query
|
||||||
local promise = promise.new()
|
cb(store)
|
||||||
Ox:update(query, parameters, function(result)
|
end
|
||||||
promise:resolve(result)
|
|
||||||
end, Resource)
|
|
||||||
return Citizen.Await(promise)
|
|
||||||
end,
|
|
||||||
|
|
||||||
---@param query string
|
---@param query string
|
||||||
---@param parameters? table|function
|
---@param parameters? table|function
|
||||||
---@return table result
|
---@return integer result
|
||||||
---returns array of matching rows or result data
|
---returns number of rows updated by the executed query
|
||||||
fetchAll = function(query, parameters)
|
MySQL.Sync.execute = function(query, parameters)
|
||||||
query, parameters = safeArgs(query, parameters)
|
query, parameters = safeArgs(query, parameters)
|
||||||
local promise = promise.new()
|
local promise = promise.new()
|
||||||
Ox:execute(query, parameters, function(result)
|
Ox:update(query, parameters, function(result)
|
||||||
promise:resolve(result)
|
promise:resolve(result)
|
||||||
end, Resource)
|
end, Resource)
|
||||||
return Citizen.Await(promise)
|
return Citizen.Await(promise)
|
||||||
end,
|
end
|
||||||
|
|
||||||
---@param query string
|
---@param query string
|
||||||
---@param parameters? table|function
|
---@param parameters? table|function
|
||||||
---@return integer|string
|
---@return table result
|
||||||
---returns value of the first column of a single row
|
---returns array of matching rows or result data
|
||||||
fetchScalar = function(query, parameters)
|
MySQL.Sync.fetchAll = function(query, parameters)
|
||||||
query, parameters = safeArgs(query, parameters)
|
query, parameters = safeArgs(query, parameters)
|
||||||
local promise = promise.new()
|
local promise = promise.new()
|
||||||
Ox:scalar(query, parameters, function(result)
|
Ox:execute(query, parameters, function(result)
|
||||||
promise:resolve(result)
|
promise:resolve(result)
|
||||||
end, Resource)
|
end, Resource)
|
||||||
return Citizen.Await(promise)
|
return Citizen.Await(promise)
|
||||||
end,
|
end
|
||||||
|
|
||||||
---@param query string
|
---@param query string
|
||||||
---@param parameters? table|function
|
---@param parameters? table|function
|
||||||
---@return table result
|
---@return integer|string
|
||||||
---returns table containing key value pairs
|
---returns value of the first column of a single row
|
||||||
fetchSingle = function(query, parameters)
|
MySQL.Sync.fetchScalar = function(query, parameters)
|
||||||
query, parameters = safeArgs(query, parameters)
|
query, parameters = safeArgs(query, parameters)
|
||||||
local promise = promise.new()
|
local promise = promise.new()
|
||||||
Ox:single(query, parameters, function(result)
|
Ox:scalar(query, parameters, function(result)
|
||||||
promise:resolve(result)
|
promise:resolve(result)
|
||||||
end, Resource)
|
end, Resource)
|
||||||
return Citizen.Await(promise)
|
return Citizen.Await(promise)
|
||||||
end,
|
end
|
||||||
|
|
||||||
---@param query string
|
---@param query string
|
||||||
---@param parameters? table|function
|
---@param parameters? table|function
|
||||||
---@return table result
|
---@return table result
|
||||||
---returns the last inserted id
|
---returns table containing key value pairs
|
||||||
insert = function(query, parameters)
|
MySQL.Sync.fetchSingle = function(query, parameters)
|
||||||
query, parameters = safeArgs(query, parameters)
|
query, parameters = safeArgs(query, parameters)
|
||||||
local promise = promise.new()
|
local promise = promise.new()
|
||||||
Ox:insert(query, parameters, function(result)
|
Ox:single(query, parameters, function(result)
|
||||||
promise:resolve(result)
|
promise:resolve(result)
|
||||||
end, Resource)
|
end, Resource)
|
||||||
return Citizen.Await(promise)
|
return Citizen.Await(promise)
|
||||||
end,
|
end
|
||||||
|
|
||||||
---@param queries table
|
---@param query string
|
||||||
---@param parameters? table|function
|
---@param parameters? table|function
|
||||||
---@return boolean result
|
---@return table result
|
||||||
---returns true when the transaction has succeeded
|
---returns the last inserted id
|
||||||
transaction = function(queries, parameters)
|
MySQL.Sync.insert = function(query, parameters)
|
||||||
queries, parameters = safeArgs(queries, parameters, true)
|
query, parameters = safeArgs(query, parameters)
|
||||||
local promise = promise.new()
|
local promise = promise.new()
|
||||||
Ox:transaction(queries, parameters, function(result)
|
Ox:insert(query, parameters, function(result)
|
||||||
promise:resolve(result)
|
promise:resolve(result)
|
||||||
end, Resource)
|
end, Resource)
|
||||||
return Citizen.Await(promise)
|
return Citizen.Await(promise)
|
||||||
end,
|
end
|
||||||
|
|
||||||
---@param query string
|
---@param queries table
|
||||||
---@return integer result
|
---@param parameters? table|function
|
||||||
---returns the id used to reference a stored query string
|
---@return boolean result
|
||||||
store = function(query)
|
---returns true when the transaction has succeeded
|
||||||
assert(type(query) == 'string', 'The SQL Query must be a string')
|
MySQL.Sync.transaction = function(queries, parameters)
|
||||||
local store = #Store+1
|
queries, parameters = safeArgs(queries, parameters, true)
|
||||||
Store[store] = query
|
local promise = promise.new()
|
||||||
return store
|
Ox:transaction(queries, parameters, function(result)
|
||||||
end,
|
promise:resolve(result)
|
||||||
},
|
end, Resource)
|
||||||
|
return Citizen.Await(promise)
|
||||||
|
end
|
||||||
|
|
||||||
ready = function(cb)
|
---@param query string
|
||||||
CreateThread(function()
|
---@return integer result
|
||||||
repeat
|
---returns the id used to reference a stored query string
|
||||||
Wait(50)
|
MySQL.Sync.store = function(query)
|
||||||
until GetResourceState('oxmysql') == 'started'
|
assert(type(query) == 'string', 'The SQL Query must be a string')
|
||||||
cb()
|
local store = #Store+1
|
||||||
end)
|
Store[store] = query
|
||||||
end
|
return store
|
||||||
}
|
end
|
||||||
|
|
||||||
|
MySQL.ready = function(cb)
|
||||||
|
CreateThread(function()
|
||||||
|
repeat
|
||||||
|
Wait(50)
|
||||||
|
until GetResourceState('oxmysql') == 'started'
|
||||||
|
cb()
|
||||||
|
end)
|
||||||
|
end
|
||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "oxmysql",
|
"name": "oxmysql",
|
||||||
"version": "1.6.0",
|
"version": "1.7.0",
|
||||||
"main": "oxmysql.js",
|
"main": "oxmysql.js",
|
||||||
"description": "node-mysql2 resource for Cfx",
|
"description": "node-mysql2 resource for Cfx",
|
||||||
"repository": "[email protected]:overextended/oxmysql.git",
|
"repository": "[email protected]:overextended/oxmysql.git",
|
||||||
|
|||||||
@@ -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..e50595d 100644
|
index 527d723..f63ce28 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 @@
|
||||||
@@ -7,12 +7,21 @@ index 527d723..e50595d 100644
|
|||||||
// License: https://github.com/mscdex/node-mariasql/blob/master/LICENSE
|
// License: https://github.com/mscdex/node-mariasql/blob/master/LICENSE
|
||||||
|
|
||||||
-const RE_PARAM = /(?:\?)|(?::(\d+|(?:[a-zA-Z][a-zA-Z0-9_]*)))/g,
|
-const RE_PARAM = /(?:\?)|(?::(\d+|(?:[a-zA-Z][a-zA-Z0-9_]*)))/g,
|
||||||
+const RE_PARAM = /(?:\?)|(?:[:@](\d+|(?:[a-zA-Z][a-zA-Z0-9_]*)))/g,
|
+const RE_PARAM = /(?:\?)|(?:(?<!["'])[:@](\d+|(?:[a-zA-Z][a-zA-Z0-9_]*)))/g,
|
||||||
DQUOTE = 34,
|
DQUOTE = 34,
|
||||||
SQUOTE = 39,
|
SQUOTE = 39,
|
||||||
BSLASH = 92;
|
BSLASH = 92;
|
||||||
@@ -96,13 +96,13 @@ function createCompiler(config) {
|
@@ -94,15 +94,22 @@ function createCompiler(config) {
|
||||||
|
if (typeof params == 'undefined')
|
||||||
|
throw new Error('Named query contains placeholders, but parameters object is undefined');
|
||||||
|
|
||||||
|
+ for(const key in params) {
|
||||||
|
+ if(key.charAt(0) === '@' || key.charAt(0) === ':') {
|
||||||
|
+ params[key.substring(1)] = params[key];
|
||||||
|
+ delete params[key];
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+
|
||||||
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]]);
|
||||||
@@ -27,7 +36,7 @@ index 527d723..e50595d 100644
|
|||||||
return s.slice(0, -1);
|
return s.slice(0, -1);
|
||||||
}
|
}
|
||||||
return s;
|
return s;
|
||||||
@@ -115,7 +115,7 @@ function createCompiler(config) {
|
@@ -115,7 +122,7 @@ 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) {
|
||||||
@@ -36,7 +45,7 @@ index 527d723..e50595d 100644
|
|||||||
unnamed += config.placeholder;
|
unnamed += config.placeholder;
|
||||||
}
|
}
|
||||||
unnamed += config.placeholder;
|
unnamed += config.placeholder;
|
||||||
@@ -124,7 +124,7 @@ function createCompiler(config) {
|
@@ -124,7 +131,7 @@ 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) {
|
||||||
|
|||||||
+69
-5
@@ -1,14 +1,13 @@
|
|||||||
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 } from './config';
|
||||||
|
import { FormatError } from './errors';
|
||||||
|
|
||||||
const execute = async (query, parameters, resource) => {
|
const execute = async (query, parameters, resource) => {
|
||||||
ScheduleResourceTick(resourceName);
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
[query, parameters] = parseParameters(query, parameters);
|
[query, parameters] = parseParameters(query, parameters);
|
||||||
|
ScheduleResourceTick(resourceName);
|
||||||
const [rows, _, executionTime] = await pool.query(query, parameters);
|
const [executionTime, rows] = await pool.query(query, parameters);
|
||||||
|
|
||||||
if (executionTime >= slowQueryWarning || debug)
|
if (executionTime >= slowQueryWarning || debug)
|
||||||
console.log(
|
console.log(
|
||||||
@@ -27,4 +26,69 @@ const execute = async (query, parameters, resource) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export { execute };
|
const queryType = (query) => {
|
||||||
|
switch (query.replace(/\s.*/, '')) {
|
||||||
|
case 'SELECT':
|
||||||
|
return 1;
|
||||||
|
case 'INSERT':
|
||||||
|
return 2;
|
||||||
|
case 'UPDATE':
|
||||||
|
return 3;
|
||||||
|
case 'DELETE':
|
||||||
|
return 3;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const preparedStatement = async (query, parameters, resource) => {
|
||||||
|
try {
|
||||||
|
if (!Array.isArray(parameters))
|
||||||
|
throw new FormatError(`Placeholders were defined, but query received no parameters!`, query);
|
||||||
|
|
||||||
|
if (typeof query !== 'string') throw new FormatError(`Prepared statements must utilise a single query`);
|
||||||
|
|
||||||
|
const type = queryType(query);
|
||||||
|
if (!type) throw new FormatError(`Prepared statements only accept SELECT, INSERT, UPDATE, and DELETE methods!`);
|
||||||
|
|
||||||
|
ScheduleResourceTick(resourceName);
|
||||||
|
const results = [];
|
||||||
|
let totalTime = 0;
|
||||||
|
let queryCount = parameters.length;
|
||||||
|
|
||||||
|
for (let i = 0; i < queryCount; i++) {
|
||||||
|
const [executionTime, rows] = await pool.execute(query, parameters[i]);
|
||||||
|
totalTime + executionTime;
|
||||||
|
results[i] = rows && (type === 3 ? rows.affectedRows : type === 2 ? rows.insertId : rows);
|
||||||
|
}
|
||||||
|
|
||||||
|
totalTime = totalTime / queryCount;
|
||||||
|
if (totalTime >= slowQueryWarning || debug)
|
||||||
|
console.log(
|
||||||
|
`^3[${debug ? 'DEBUG' : 'WARNING'}] ${resource} took ${totalTime}ms to execute ${
|
||||||
|
queryCount > 1 ? queryCount + ' queries' : 'a query'
|
||||||
|
}!
|
||||||
|
${query} ${JSON.stringify(parameters)}^0`
|
||||||
|
);
|
||||||
|
|
||||||
|
if (results.length === 1) {
|
||||||
|
if (type === 1) {
|
||||||
|
if (results[0][0] && Object.keys(results[0][0]).length === 1) {
|
||||||
|
return Object.values(results[0][0])[0];
|
||||||
|
}
|
||||||
|
return results[0][0];
|
||||||
|
}
|
||||||
|
return results[0];
|
||||||
|
}
|
||||||
|
return results;
|
||||||
|
} catch (error) {
|
||||||
|
console.log(
|
||||||
|
`^1[ERROR] ${resource} was unable to execute a query!
|
||||||
|
${error.message}
|
||||||
|
${error.sql || `${query} ${JSON.stringify(parameters)}`}^0`
|
||||||
|
);
|
||||||
|
debug && console.trace(error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export { execute, preparedStatement };
|
||||||
+11
-1
@@ -1,5 +1,5 @@
|
|||||||
import { pool } from './pool';
|
import { pool } from './pool';
|
||||||
import { execute } from './execute';
|
import { execute, preparedStatement } from './execute';
|
||||||
import { transaction } from './transaction';
|
import { transaction } from './transaction';
|
||||||
import { debug, isolationLevel } from './config';
|
import { debug, isolationLevel } from './config';
|
||||||
|
|
||||||
@@ -55,7 +55,17 @@ global.exports('transaction', (queries, parameters, cb, resource = GetInvokingRe
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
global.exports('prepare', (query, parameters, cb, resource = GetInvokingResource()) => {
|
||||||
|
preparedStatement(query, parameters, resource).then((result) =>
|
||||||
|
safeCallback(cb || parameters, result, resource, query))
|
||||||
|
});
|
||||||
|
|
||||||
if (!GetResourceMetadata(GetCurrentResourceName(), 'server_script', 1)) {
|
if (!GetResourceMetadata(GetCurrentResourceName(), 'server_script', 1)) {
|
||||||
|
global.exports('prepareSync', async (query, parameters) => {
|
||||||
|
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;
|
||||||
|
|||||||
+17
-2
@@ -1,4 +1,7 @@
|
|||||||
import { FormatError } from './errors';
|
import { FormatError } from './errors';
|
||||||
|
import * as createCompiler from 'named-placeholders';
|
||||||
|
|
||||||
|
const convertNamedPlaceholders = createCompiler();
|
||||||
|
|
||||||
const parseTypes = (field, next) => {
|
const parseTypes = (field, next) => {
|
||||||
//https://github.com/GHMatti/ghmattimysql/blob/37f1d2ae5c53f91782d168fe81fba80512d3c46d/packages/ghmattimysql/src/server/utility/typeCast.ts#L3
|
//https://github.com/GHMatti/ghmattimysql/blob/37f1d2ae5c53f91782d168fe81fba80512d3c46d/packages/ghmattimysql/src/server/utility/typeCast.ts#L3
|
||||||
@@ -25,9 +28,21 @@ const parseTypes = (field, next) => {
|
|||||||
const parseParameters = (query, parameters) => {
|
const parseParameters = (query, parameters) => {
|
||||||
if (query === undefined) throw new FormatError(`Undefined query passed`);
|
if (query === undefined) throw new FormatError(`Undefined query passed`);
|
||||||
|
|
||||||
if (typeof parameters === 'function') return [query, []];
|
if (!parameters || typeof parameters === 'function') return [query, []];
|
||||||
|
|
||||||
if (query.includes('@') || query.includes(':')) return [query, parameters];
|
if (query.includes('@') || query.includes(':')) {
|
||||||
|
const obj = parameters.length !== 0 ? parameters : (() => {
|
||||||
|
let obj = {};
|
||||||
|
const [_, paramNames] = convertNamedPlaceholders.parse(query);
|
||||||
|
if (paramNames) {
|
||||||
|
for (let i = 0; i < paramNames.length; i++)
|
||||||
|
obj[paramNames[i]] = null;
|
||||||
|
}
|
||||||
|
return obj;
|
||||||
|
})();
|
||||||
|
|
||||||
|
return [query, obj]
|
||||||
|
};
|
||||||
|
|
||||||
const queryParams = query.match(/\?(?!\?)/g);
|
const queryParams = query.match(/\?(?!\?)/g);
|
||||||
|
|
||||||
|
|||||||
+22
-9
@@ -1,7 +1,7 @@
|
|||||||
---@param query string
|
---@param query string
|
||||||
---@param parameters? table|function
|
---@param parameters? table
|
||||||
---@return integer result
|
---@return integer result
|
||||||
---returns number of rows updated by the executed query
|
---returns array of matching rows or result data
|
||||||
exports('executeSync', function(query, parameters)
|
exports('executeSync', function(query, parameters)
|
||||||
local p = promise.new()
|
local p = promise.new()
|
||||||
exports['oxmysql']:execute(query, parameters, function(result)
|
exports['oxmysql']:execute(query, parameters, function(result)
|
||||||
@@ -10,9 +10,8 @@ exports('executeSync', function(query, parameters)
|
|||||||
return Citizen.Await(p)
|
return Citizen.Await(p)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
---@deprecated true
|
|
||||||
---@param query string
|
---@param query string
|
||||||
---@param parameters? table|function
|
---@param parameters? table
|
||||||
---@return table result
|
---@return table result
|
||||||
---returns array of matching rows or result data
|
---returns array of matching rows or result data
|
||||||
exports('fetchSync', function(query, parameters)
|
exports('fetchSync', function(query, parameters)
|
||||||
@@ -24,7 +23,7 @@ exports('fetchSync', function(query, parameters)
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
---@param query string
|
---@param query string
|
||||||
---@param parameters? table|function
|
---@param parameters? table
|
||||||
---@return table result
|
---@return table result
|
||||||
---returns table containing key value pairs
|
---returns table containing key value pairs
|
||||||
exports('singleSync', function(query, parameters)
|
exports('singleSync', function(query, parameters)
|
||||||
@@ -36,7 +35,7 @@ exports('singleSync', function(query, parameters)
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
---@param query string
|
---@param query string
|
||||||
---@param parameters? table|function
|
---@param parameters? table
|
||||||
---@return integer|string
|
---@return integer|string
|
||||||
---returns value of the first column of a single row
|
---returns value of the first column of a single row
|
||||||
exports('scalarSync', function(query, parameters)
|
exports('scalarSync', function(query, parameters)
|
||||||
@@ -48,7 +47,7 @@ exports('scalarSync', function(query, parameters)
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
---@param query string
|
---@param query string
|
||||||
---@param parameters? table|function
|
---@param parameters? table
|
||||||
---@return table result
|
---@return table result
|
||||||
---returns the last inserted id
|
---returns the last inserted id
|
||||||
exports('insertSync', function(query, parameters)
|
exports('insertSync', function(query, parameters)
|
||||||
@@ -60,7 +59,7 @@ exports('insertSync', function(query, parameters)
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
---@param query string
|
---@param query string
|
||||||
---@param parameters? table|function
|
---@param parameters? table
|
||||||
---@return integer result
|
---@return integer result
|
||||||
---returns number of rows updated by the executed query
|
---returns number of rows updated by the executed query
|
||||||
exports('updateSync', function(query, parameters)
|
exports('updateSync', function(query, parameters)
|
||||||
@@ -72,7 +71,7 @@ exports('updateSync', function(query, parameters)
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
---@param queries table
|
---@param queries table
|
||||||
---@param parameters? table|function
|
---@param parameters? table
|
||||||
---@return boolean result
|
---@return boolean result
|
||||||
---returns true when the transaction has succeeded
|
---returns true when the transaction has succeeded
|
||||||
exports('transactionSync', function(queries, parameters)
|
exports('transactionSync', function(queries, parameters)
|
||||||
@@ -81,4 +80,18 @@ exports('transactionSync', function(queries, parameters)
|
|||||||
p:resolve(result)
|
p:resolve(result)
|
||||||
end, GetInvokingResource())
|
end, GetInvokingResource())
|
||||||
return Citizen.Await(p)
|
return Citizen.Await(p)
|
||||||
|
end)
|
||||||
|
|
||||||
|
---@param query string
|
||||||
|
---@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()
|
||||||
|
exports['oxmysql']:prepare(query, parameters, function(result)
|
||||||
|
p:resolve(result)
|
||||||
|
end, GetInvokingResource())
|
||||||
|
return Citizen.Await(p)
|
||||||
end)
|
end)
|
||||||
@@ -42,9 +42,9 @@
|
|||||||
"@types/estree" "*"
|
"@types/estree" "*"
|
||||||
|
|
||||||
"@types/eslint@*":
|
"@types/eslint@*":
|
||||||
version "7.28.1"
|
version "7.28.2"
|
||||||
resolved "https://registry.yarnpkg.com/@types/eslint/-/eslint-7.28.1.tgz#50b07747f1f84c2ba8cd394cf0fe0ba07afce320"
|
resolved "https://registry.yarnpkg.com/@types/eslint/-/eslint-7.28.2.tgz#0ff2947cdd305897c52d5372294e8c76f351db68"
|
||||||
integrity sha512-XhZKznR3i/W5dXqUhgU9fFdJekufbeBd5DALmkuXoeFcjbQcPk+2cL+WLHf6Q81HWAnM2vrslIHpGVyCAviRwg==
|
integrity sha512-KubbADPkfoU75KgKeKLsFHXnU4ipH7wYg0TRT33NK3N3yiu7jlFAAoygIWBV+KbuHx/G+AvuGX6DllnK35gfJA==
|
||||||
dependencies:
|
dependencies:
|
||||||
"@types/estree" "*"
|
"@types/estree" "*"
|
||||||
"@types/json-schema" "*"
|
"@types/json-schema" "*"
|
||||||
@@ -60,9 +60,9 @@
|
|||||||
integrity sha512-qcUXuemtEu+E5wZSJHNxUXeCZhAfXKQ41D+duX+VYPde7xyEVZci+/oXKJL13tnRs9lR2pr4fod59GT6/X1/yQ==
|
integrity sha512-qcUXuemtEu+E5wZSJHNxUXeCZhAfXKQ41D+duX+VYPde7xyEVZci+/oXKJL13tnRs9lR2pr4fod59GT6/X1/yQ==
|
||||||
|
|
||||||
"@types/node@*":
|
"@types/node@*":
|
||||||
version "16.11.0"
|
version "16.11.2"
|
||||||
resolved "https://registry.yarnpkg.com/@types/node/-/node-16.11.0.tgz#4b95f2327bacd1ef8f08d8ceda193039c5d7f52e"
|
resolved "https://registry.yarnpkg.com/@types/node/-/node-16.11.2.tgz#31c249c136c3f9b35d4b60fb8e50e01a1f0cc9a5"
|
||||||
integrity sha512-8MLkBIYQMuhRBQzGN9875bYsOhPnf/0rgXGo66S2FemHkhbn9qtsz9ywV1iCG+vbjigE4WUNVvw37Dx+L0qsPg==
|
integrity sha512-w34LtBB0OkDTs19FQHXy4Ig/TOXI4zqvXS2Kk1PAsRKZ0I+nik7LlMYxckW0tSNGtvWmzB+mrCTbuEjuB9DVsw==
|
||||||
|
|
||||||
"@webassemblyjs/[email protected]":
|
"@webassemblyjs/[email protected]":
|
||||||
version "1.11.1"
|
version "1.11.1"
|
||||||
@@ -291,9 +291,9 @@ buffer-from@^1.0.0:
|
|||||||
integrity sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==
|
integrity sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==
|
||||||
|
|
||||||
caniuse-lite@^1.0.30001265:
|
caniuse-lite@^1.0.30001265:
|
||||||
version "1.0.30001267"
|
version "1.0.30001270"
|
||||||
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001267.tgz#b1cf2937175afc0570e4615fc2d2f9069fa0ed30"
|
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001270.tgz#cc9c37a4ec5c1a8d616fc7bace902bb053b0cdea"
|
||||||
integrity sha512-r1mjTzAuJ9W8cPBGbbus8E0SKcUP7gn03R14Wk8FlAlqhH9hroy9nLqmpuXlfKEw/oILW+FGz47ipXV2O7x8lg==
|
integrity sha512-TcIC7AyNWXhcOmv2KftOl1ShFAaHQYcB/EPL/hEyMrcS7ZX0/DvV1aoy6BzV0+16wTpoAyTMGDNAJfSqS/rz7A==
|
||||||
|
|
||||||
chalk@^2.4.2:
|
chalk@^2.4.2:
|
||||||
version "2.4.2"
|
version "2.4.2"
|
||||||
@@ -408,9 +408,9 @@ dir-glob@^3.0.1:
|
|||||||
path-type "^4.0.0"
|
path-type "^4.0.0"
|
||||||
|
|
||||||
electron-to-chromium@^1.3.867:
|
electron-to-chromium@^1.3.867:
|
||||||
version "1.3.871"
|
version "1.3.877"
|
||||||
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.871.tgz#6e87365fd72037a6c898fb46050ad4be3ac9ef62"
|
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.877.tgz#956870eea7c9d8cf43cc54ea40687fee4dc0c12a"
|
||||||
integrity sha512-qcLvDUPf8DSIMWarHT2ptgcqrYg62n3vPA7vhrOF24d8UNzbUBaHu2CySiENR3nEDzYgaN60071t0F6KLYMQ7Q==
|
integrity sha512-fT5mW5Giw5iyVukeHb2XvB4joBKvzHtl8Vs3QzE7APATpFMt/T7RWyUcIKSZzYkKQgpMbu+vDBTCHfQZvh8klA==
|
||||||
|
|
||||||
enhanced-resolve@^5.8.3:
|
enhanced-resolve@^5.8.3:
|
||||||
version "5.8.3"
|
version "5.8.3"
|
||||||
@@ -763,9 +763,9 @@ isobject@^3.0.1:
|
|||||||
integrity sha1-TkMekrEalzFjaqH5yNHMvP2reN8=
|
integrity sha1-TkMekrEalzFjaqH5yNHMvP2reN8=
|
||||||
|
|
||||||
jest-worker@^27.0.6:
|
jest-worker@^27.0.6:
|
||||||
version "27.2.5"
|
version "27.3.1"
|
||||||
resolved "https://registry.yarnpkg.com/jest-worker/-/jest-worker-27.2.5.tgz#ed42865661959488aa020e8a325df010597c36d4"
|
resolved "https://registry.yarnpkg.com/jest-worker/-/jest-worker-27.3.1.tgz#0def7feae5b8042be38479799aeb7b5facac24b2"
|
||||||
integrity sha512-HTjEPZtcNKZ4LnhSp02NEH4vE+5OpJ0EsOWYvGQpHgUMLngydESAAMH5Wd/asPf29+XUDQZszxpLg1BkIIA2aw==
|
integrity sha512-ks3WCzsiZaOPJl/oMsDjaf0TRiSv7ctNgs0FqRr2nARsovz6AWWy4oLElwcquGSz692DzgZQrCLScPNs5YlC4g==
|
||||||
dependencies:
|
dependencies:
|
||||||
"@types/node" "*"
|
"@types/node" "*"
|
||||||
merge-stream "^2.0.0"
|
merge-stream "^2.0.0"
|
||||||
@@ -880,8 +880,8 @@ minimist@^1.2.0:
|
|||||||
integrity sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==
|
integrity sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==
|
||||||
|
|
||||||
"mysql2@https://github.com/overextended/node-mysql2.git":
|
"mysql2@https://github.com/overextended/node-mysql2.git":
|
||||||
version "2.3.0"
|
version "2.3.2"
|
||||||
resolved "https://github.com/overextended/node-mysql2.git#0bd156905d3093d33dddbde10adf1ca8ede18680"
|
resolved "https://github.com/overextended/node-mysql2.git#0621bdc95f3bc6db1e5cd06efd52663ea9410c9a"
|
||||||
dependencies:
|
dependencies:
|
||||||
denque "^2.0.1"
|
denque "^2.0.1"
|
||||||
generate-function "^2.3.1"
|
generate-function "^2.3.1"
|
||||||
@@ -910,9 +910,9 @@ nice-try@^1.0.4:
|
|||||||
integrity sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ==
|
integrity sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ==
|
||||||
|
|
||||||
node-releases@^2.0.0:
|
node-releases@^2.0.0:
|
||||||
version "2.0.0"
|
version "2.0.1"
|
||||||
resolved "https://registry.yarnpkg.com/node-releases/-/node-releases-2.0.0.tgz#67dc74903100a7deb044037b8a2e5f453bb05400"
|
resolved "https://registry.yarnpkg.com/node-releases/-/node-releases-2.0.1.tgz#3d1d395f204f1f2f29a54358b9fb678765ad2fc5"
|
||||||
integrity sha512-aA87l0flFYMzCHpTM3DERFSYxc6lv/BltdbRTOMZuxZ0cwZCD3mejE5n9vLhSJCN++/eOqr77G1IO5uXxlQYWA==
|
integrity sha512-CqyzN6z7Q6aMeF/ktcMVTzhAHCEpf8SOarwpzpf8pNBY2k5/oM34UHldUwp8VKI7uxct2HxSRdJjBaZeESzcxA==
|
||||||
|
|
||||||
normalize-path@^3.0.0:
|
normalize-path@^3.0.0:
|
||||||
version "3.0.0"
|
version "3.0.0"
|
||||||
@@ -1304,11 +1304,6 @@ uri-js@^4.2.2:
|
|||||||
dependencies:
|
dependencies:
|
||||||
punycode "^2.1.0"
|
punycode "^2.1.0"
|
||||||
|
|
||||||
v8-compile-cache@^2.2.0:
|
|
||||||
version "2.3.0"
|
|
||||||
resolved "https://registry.yarnpkg.com/v8-compile-cache/-/v8-compile-cache-2.3.0.tgz#2de19618c66dc247dcfb6f99338035d8245a2cee"
|
|
||||||
integrity sha512-l8lCEmLcLYZh4nbunNZvQCJc5pv7+RCwa8q/LdUx8u7lsWvPDKmpodJAJNwkAhJC//dFY48KuIEmjtd4RViDrA==
|
|
||||||
|
|
||||||
watchpack@^2.2.0:
|
watchpack@^2.2.0:
|
||||||
version "2.2.0"
|
version "2.2.0"
|
||||||
resolved "https://registry.yarnpkg.com/watchpack/-/watchpack-2.2.0.tgz#47d78f5415fe550ecd740f99fe2882323a58b1ce"
|
resolved "https://registry.yarnpkg.com/watchpack/-/watchpack-2.2.0.tgz#47d78f5415fe550ecd740f99fe2882323a58b1ce"
|
||||||
@@ -1318,9 +1313,9 @@ watchpack@^2.2.0:
|
|||||||
graceful-fs "^4.1.2"
|
graceful-fs "^4.1.2"
|
||||||
|
|
||||||
webpack-cli@^4.8.0:
|
webpack-cli@^4.8.0:
|
||||||
version "4.9.0"
|
version "4.9.1"
|
||||||
resolved "https://registry.yarnpkg.com/webpack-cli/-/webpack-cli-4.9.0.tgz#dc43e6e0f80dd52e89cbf73d5294bcd7ad6eb343"
|
resolved "https://registry.yarnpkg.com/webpack-cli/-/webpack-cli-4.9.1.tgz#b64be825e2d1b130f285c314caa3b1ba9a4632b3"
|
||||||
integrity sha512-n/jZZBMzVEl4PYIBs+auy2WI0WTQ74EnJDiyD98O2JZY6IVIHJNitkYp/uTXOviIOMfgzrNvC9foKv/8o8KSZw==
|
integrity sha512-JYRFVuyFpzDxMDB+v/nanUdQYcZtqFPGzmlW4s+UkPMFhSpfRNmf1z4AwYcHJVdvEFAM7FFCQdNTpsBYhDLusQ==
|
||||||
dependencies:
|
dependencies:
|
||||||
"@discoveryjs/json-ext" "^0.5.0"
|
"@discoveryjs/json-ext" "^0.5.0"
|
||||||
"@webpack-cli/configtest" "^1.1.0"
|
"@webpack-cli/configtest" "^1.1.0"
|
||||||
@@ -1333,7 +1328,6 @@ webpack-cli@^4.8.0:
|
|||||||
import-local "^3.0.2"
|
import-local "^3.0.2"
|
||||||
interpret "^2.2.0"
|
interpret "^2.2.0"
|
||||||
rechoir "^0.7.0"
|
rechoir "^0.7.0"
|
||||||
v8-compile-cache "^2.2.0"
|
|
||||||
webpack-merge "^5.7.3"
|
webpack-merge "^5.7.3"
|
||||||
|
|
||||||
webpack-merge@^5.7.3:
|
webpack-merge@^5.7.3:
|
||||||
@@ -1350,9 +1344,9 @@ webpack-sources@^3.2.0:
|
|||||||
integrity sha512-t6BMVLQ0AkjBOoRTZgqrWm7xbXMBzD+XDq2EZ96+vMfn3qKgsvdXZhbPZ4ElUOpdv4u+iiGe+w3+J75iy/bYGA==
|
integrity sha512-t6BMVLQ0AkjBOoRTZgqrWm7xbXMBzD+XDq2EZ96+vMfn3qKgsvdXZhbPZ4ElUOpdv4u+iiGe+w3+J75iy/bYGA==
|
||||||
|
|
||||||
webpack@^5.52.1:
|
webpack@^5.52.1:
|
||||||
version "5.58.2"
|
version "5.59.1"
|
||||||
resolved "https://registry.yarnpkg.com/webpack/-/webpack-5.58.2.tgz#6b4af12fc9bd5cbedc00dc0a2fc2b9592db16b44"
|
resolved "https://registry.yarnpkg.com/webpack/-/webpack-5.59.1.tgz#60c77e9aad796252153d4d7ab6b2d4c11f0e548c"
|
||||||
integrity sha512-3S6e9Vo1W2ijk4F4PPWRIu6D/uGgqaPmqw+av3W3jLDujuNkdxX5h5c+RQ6GkjVR+WwIPOfgY8av+j5j4tMqJw==
|
integrity sha512-I01IQV9K96FlpXX3V0L4nvd7gb0r7thfuu1IfT2P4uOHOA77nKARAKDYGe/tScSHKnffNIyQhLC8kRXzY4KEHQ==
|
||||||
dependencies:
|
dependencies:
|
||||||
"@types/eslint-scope" "^3.7.0"
|
"@types/eslint-scope" "^3.7.0"
|
||||||
"@types/estree" "^0.0.50"
|
"@types/estree" "^0.0.50"
|
||||||
|
|||||||
Reference in new issue
Block a user