Compare commits

..
10 Commits
Author SHA1 Message Date
dunak-debug 6acd0ac352 chore: Bump to 1.5.0 2021-10-06 23:52:38 +02:00
Dunak 55d8d46334 feat(ci): Include mysql-async compat library 2021-10-06 22:59:46 +02:00
Linden 4b179191d4 feat: Imports file for "mysql-async" like usage
- Include `server_script '@oxmysql/lib/MySQL.lua'` in the resource manifest

Mostly untested
2021-10-07 07:42:03 +11:00
Linden 1ec52903ca feat: Add support for semicolon connection strings 2021-10-07 06:26:07 +11:00
Linden 7e5d4cce06 chore: Version bump and set to production 2021-09-27 10:13:36 +10:00
Linden 681b39692a fix(pool): Increase default connection timeout
- Servers taking a while to start may experience a timeout; this should alleviate the issue
2021-09-27 10:13:11 +10:00
1A3 39c485644d fix: Regex fix for queries with commas (#31)
Fixes #24
2021-09-24 20:13:01 +02:00
darksaid98 634bbffd46 feat: version check on startup (#28) 2021-09-23 20:55:08 +02:00
Linden 273a4a8a89 Merge pull request #27 from gixels/main
Implemented the ability to change the port.
2021-09-23 05:03:27 +10:00
gixels b8249d5457 Implemented the ability to change the port. 2021-09-22 12:12:50 -04:00
10 changed files with 272 additions and 33 deletions

No files matched your search

+2
View File
@@ -32,6 +32,8 @@ jobs:
- name: Bundle files - name: Bundle files
run: | run: |
mv dist oxmysql mv dist oxmysql
mkdir oxmysql/lib
mv lib/MySQL.lua oxmysql/lib/MySQL.lua
zip -r oxmysql-${{ env.RELEASE_VERSION }}.zip oxmysql zip -r oxmysql-${{ env.RELEASE_VERSION }}.zip oxmysql
- name: Create Release - name: Create Release
+1 -1
View File
@@ -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.4.0' version '1.5.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'
+146
View File
@@ -0,0 +1,146 @@
-- This file allows simple conversion from MySQL-Async to Oxmysql
-- Replace any references to '@mysql-async' in your resource manifests to use '@oxmysql' instead
-- Store is used for compatibility only
local Ox = exports.oxmysql
local Resource = GetCurrentResourceName()
local function safeParameters(parameters)
if not parameters or next(parameters) == nil then
return {[''] = ''}
end
assert(type(parameters) == 'table', 'Parameters must be a table')
return parameters
end
local Store = {}
MySQL = {
Async = {
execute = function(query, parameters, cb)
assert(type(query) == 'string', 'The SQL Query must be a string')
Ox:update(query, safeParameters(parameters), cb)
end,
fetchAll = function(query, parameters, cb)
assert(type(query) == 'string', 'The SQL Query must be a string')
Ox:execute(query, safeParameters(parameters), cb)
end,
fetchScalar = function(query, parameters, cb)
assert(type(query) == 'string', 'The SQL Query must be a string')
Ox:scalar(query, safeParameters(parameters), cb)
end,
fetchSingle = function(query, parameters, cb)
assert(type(query) == 'string', 'The SQL Query must be a string')
Ox:single(query, safeParameters(parameters), cb)
end,
insert = function(query, parameters, cb)
assert(type(query) == 'string', 'The SQL Query must be a string')
Ox:insert(query, safeParameters(parameters), cb)
end,
transaction = function(query, parameters, cb)
assert(type(query) == 'string', 'The SQL Query must be a string')
Ox:transaction(query, safeParameters(parameters), cb)
end,
store = function(query, cb)
assert(type(query) == 'string', 'The SQL Query must be a string')
local store = #Store+1
Store[store] = query
cb(store)
end,
},
Sync = {
execute = function(query, parameters)
if type(query) == 'number' then
query = Store[query]
end
assert(type(query) == 'string', 'The SQL Query must be a string')
local promise = promise.new()
Ox:update(query, safeParameters(parameters), function(result)
promise:resolve(result)
end, Resource)
return Citizen.Await(promise)
end,
fetchAll = function(query, parameters)
if type(query) == 'number' then
query = Store[query]
end
assert(type(query) == 'string', 'The SQL Query must be a string')
local promise = promise.new()
Ox:execute(query, safeParameters(parameters), function(result)
promise:resolve(result)
end, Resource)
return Citizen.Await(promise)
end,
fetchScalar = function(query, parameters)
if type(query) == 'number' then
query = Store[query]
end
assert(type(query) == 'string', 'The SQL Query must be a string')
local promise = promise.new()
Ox:scalar(query, safeParameters(parameters), function(result)
promise:resolve(result)
end, Resource)
return Citizen.Await(promise)
end,
fetchSingle = function(query, parameters)
if type(query) == 'number' then
query = Store[query]
end
assert(type(query) == 'string', 'The SQL Query must be a string')
local promise = promise.new()
Ox:scalar(query, safeParameters(parameters), function(result)
promise:resolve(result)
end, Resource)
return Citizen.Await(promise)
end,
insert = function(query, parameters)
if type(query) == 'number' then
query = Store[query]
end
assert(type(query) == 'string', 'The SQL Query must be a string')
local promise = promise.new()
Ox:scalar(query, safeParameters(parameters), function(result)
promise:resolve(result)
end, Resource)
return Citizen.Await(promise)
end,
transaction = function(query, parameters)
if type(query) == 'number' then
query = Store[query]
end
assert(type(query) == 'string', 'The SQL Query must be a string')
local promise = promise.new()
Ox:scalar(query, safeParameters(parameters), function(result)
promise:resolve(result)
end, Resource)
return Citizen.Await(promise)
end,
store = function(query, parameters)
assert(type(query) == 'string', 'The SQL Query must be a string')
local store = #Store+1
Store[store] = query
return store
end,
},
ready = function(cb)
CreateThread(function()
repeat
Wait(50)
until GetResourceState('oxmysql') == 'started'
cb()
end)
end
}
+2 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "oxmysql", "name": "oxmysql",
"version": "1.4.0", "version": "1.5.0",
"main": "oxmysql.js", "main": "oxmysql.js",
"description": "FiveM MySQL wrapper using faster mysql2", "description": "FiveM MySQL wrapper using faster mysql2",
"repository": "[email protected]:overextended/oxmysql.git", "repository": "[email protected]:overextended/oxmysql.git",
@@ -14,6 +14,7 @@
"dependencies": { "dependencies": {
"@citizenfx/server": "^2.0.4376-1", "@citizenfx/server": "^2.0.4376-1",
"connection-string-parser": "^1.0.4", "connection-string-parser": "^1.0.4",
"github-version-checker": "^2.2.0",
"mysql2": "^2.3.0", "mysql2": "^2.3.0",
"postinstall-postinstall": "^2.1.0" "postinstall-postinstall": "^2.1.0"
}, },
@@ -0,0 +1,12 @@
diff --git a/node_modules/github-version-checker/lib/check.js b/node_modules/github-version-checker/lib/check.js
index 7f00060..cf0e231 100644
--- a/node_modules/github-version-checker/lib/check.js
+++ b/node_modules/github-version-checker/lib/check.js
@@ -88,7 +88,6 @@ const rest = (options, callback) => {
if (found) {
const mapped = schemeMapper[options.fetchTags ? 'tag' : 'release'](version);
- console.log(mapped);
callback(null, mapped);
} else {
callback(null, null);
+1 -1
View File
@@ -7,7 +7,7 @@ index 527d723..f47b591 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;
+25 -16
View File
@@ -1,18 +1,7 @@
import { ConnectionStringParser } from 'connection-string-parser'; import versionCheck from 'github-version-checker';
import currentVersion from '../package.json';
const connectionString = GetConvar('mysql_connection_string', ''); const slowQueryWarning = GetConvarInt('mysql_slow_query_warning', 150);
if (connectionString === '') throw new Error(`Set up mysql_connection_string in server.cfg`);
const config = new ConnectionStringParser({
scheme: 'mysql',
hosts: [],
}).parse(connectionString);
if (Object.keys(config).length === 0)
throw new Error(`Set up mysql_connection_string in correct format - 'mysql://user:password@host/database'`);
const slowQueryWarning = GetConvarInt('mysql_slow_query_warning', 100);
const debug = GetConvar('mysql_debug', 'false') === 'true'; const debug = GetConvar('mysql_debug', 'false') === 'true';
const isolationLevel = (() => { const isolationLevel = (() => {
@@ -27,9 +16,29 @@ const isolationLevel = (() => {
return 'SET TRANSACTION ISOLATION LEVEL SERIALIZABLE'; return 'SET TRANSACTION ISOLATION LEVEL SERIALIZABLE';
default: default:
return 'SET TRANSACTION ISOLATION LEVEL READ COMMITTED'; return 'SET TRANSACTION ISOLATION LEVEL READ COMMITTED';
}; }
})(); })();
const resourceName = GetCurrentResourceName() || 'oxmysql'; const resourceName = GetCurrentResourceName() || 'oxmysql';
export { config, slowQueryWarning, debug, isolationLevel, resourceName }; export { slowQueryWarning, debug, isolationLevel, resourceName };
setImmediate(async () => {
const versionCheckConfig = {
repo: 'oxmysql',
owner: 'overextended',
currentVersion: currentVersion.version,
latest: true,
};
try {
const update = await versionCheck(versionCheckConfig);
if (update) {
console.log(
`^3Your version of oxmysql is outdated (v${versionCheckConfig.currentVersion})! Please update to the latest version (${update.name}) here: \nhttps://github.com/overextended/oxmysql/releases/latest`
);
}
} catch (e) {
console.log(`^3Could not fetch updates for oxmysql!^0\n${e}`);
}
});
+68 -11
View File
@@ -1,14 +1,71 @@
import { createPool } from 'mysql2/promise'; import { createPool } from 'mysql2/promise';
import { config } from './config'; import { debug } from './config';
import { parseTypes } from './parser'; import { parseTypes } from './parser';
import { ConnectionStringParser } from 'connection-string-parser';
export const pool = createPool({ const connectionString = GetConvar('mysql_connection_string', '');
host: config.hosts[0].host || 'localhost',
user: config.username || 'root', if (connectionString === '') {
password: config.password || '', throw new Error(`Set up mysql_connection_string in server.cfg`);
database: config.endpoint || 'es_extended', }
charset: 'utf8mb4_unicode_ci',
...config.options, const parseSemiColons = () => {
namedPlaceholders: true, const parts = connectionString.split(';');
typeCast: parseTypes, if (parseTypes.length === 1) {
}); throw new Error(
`Set up mysql_connection_string in correct format - 'username=root;password=password;database=db;host=127.0.0.1'`
);
}
return parts.reduce((connectionInfo, parameter) => {
const [key, value] = parameter.split('=');
connectionInfo[key] = value;
return connectionInfo;
}, {});
};
const createConnection = () => {
if (connectionString.includes('database=')) {
const options = parseSemiColons();
return createPool({
host: options.host || 'localhost',
port: options.port || 3306,
user: options.username || options.user || options.userid || 'root',
password: options.password || options.pass || '',
database: options.endpoint || options.database || 'es_extended',
charset: 'utf8mb4_unicode_ci',
connectTimeout: 30000,
trace: debug || false,
debug: debug || false,
...options.options,
namedPlaceholders: true,
typeCast: parseTypes,
});
} else {
const options = new ConnectionStringParser({
scheme: 'mysql',
hosts: [],
}).parse(connectionString);
if (Object.keys(options).length === 0) {
throw new Error(`Set up mysql_connection_string in correct format - 'mysql://user:password@host/database'`);
}
return createPool({
host: options.hosts[0].host || 'localhost',
port: options.hosts[0].port || 3306,
user: options.username || 'root',
password: options.password || '',
database: options.endpoint || 'es_extended',
charset: 'utf8mb4_unicode_ci',
connectTimeout: 30000,
trace: debug || false,
debug: debug || false,
...options.options,
namedPlaceholders: true,
typeCast: parseTypes,
});
}
};
export const pool = createConnection();
+1 -2
View File
@@ -3,8 +3,7 @@ const { DefinePlugin, IgnorePlugin } = require("webpack");
const CopyPlugin = require("copy-webpack-plugin"); const CopyPlugin = require("copy-webpack-plugin");
module.exports = { module.exports = {
mode: "development", mode: "production",
devtool: "eval-source-map",
entry: "./src/index.js", entry: "./src/index.js",
resolve: { resolve: {
extensions: [".js"], extensions: [".js"],
+14 -1
View File
@@ -571,6 +571,19 @@ get-stream@^6.0.0:
resolved "https://registry.yarnpkg.com/get-stream/-/get-stream-6.0.1.tgz#a262d8eef67aced57c2852ad6167526a43cbf7b7" resolved "https://registry.yarnpkg.com/get-stream/-/get-stream-6.0.1.tgz#a262d8eef67aced57c2852ad6167526a43cbf7b7"
integrity sha512-ts6Wi+2j3jQjqi70w5AlN8DFnkSwC+MqmxEzdEALB2qXZYV3X/b1CTfgPLGJNMeAWxdPfU8FO1ms3NUfaHCPYg== integrity sha512-ts6Wi+2j3jQjqi70w5AlN8DFnkSwC+MqmxEzdEALB2qXZYV3X/b1CTfgPLGJNMeAWxdPfU8FO1ms3NUfaHCPYg==
github-graphql-client@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/github-graphql-client/-/github-graphql-client-1.0.0.tgz#d5acacc31bb9f6b77e5c502812e90c844f727bca"
integrity sha1-1ayswxu59rd+XFAoEukMhE9ye8o=
github-version-checker@^2.2.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/github-version-checker/-/github-version-checker-2.2.0.tgz#08a2b52f9ef9cd3dd05b898537750a91b73facec"
integrity sha512-Ttj/Uzg++TGfycfn5ga8BfMJ8QYB1+DhG24rtasrN8tHYWgqqrEMAQ52y2qGnPNWzSF8AUdjm6dBcoPdUhKhDQ==
dependencies:
github-graphql-client "^1.0.0"
semver "^5.5.1"
glob-parent@^5.1.2: glob-parent@^5.1.2:
version "5.1.2" version "5.1.2"
resolved "https://registry.yarnpkg.com/glob-parent/-/glob-parent-5.1.2.tgz#869832c58034fe68a4093c17dc15e8340d8401c4" resolved "https://registry.yarnpkg.com/glob-parent/-/glob-parent-5.1.2.tgz#869832c58034fe68a4093c17dc15e8340d8401c4"
@@ -1120,7 +1133,7 @@ schema-utils@^3.0.0, schema-utils@^3.1.0, schema-utils@^3.1.1:
ajv "^6.12.5" ajv "^6.12.5"
ajv-keywords "^3.5.2" ajv-keywords "^3.5.2"
semver@^5.5.0, semver@^5.6.0: semver@^5.5.0, semver@^5.5.1, semver@^5.6.0:
version "5.7.1" version "5.7.1"
resolved "https://registry.yarnpkg.com/semver/-/semver-5.7.1.tgz#a954f931aeba508d307bbf069eff0c01c96116f7" resolved "https://registry.yarnpkg.com/semver/-/semver-5.7.1.tgz#a954f931aeba508d307bbf069eff0c01c96116f7"
integrity sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ== integrity sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==