Skip to content

Commit

Permalink
Merge pull request #232 from overextended/dev
Browse files Browse the repository at this point in the history
  • Loading branch information
thelindat authored Aug 8, 2024
2 parents 19d55a2 + a92b958 commit f005a2f
Show file tree
Hide file tree
Showing 22 changed files with 1,206 additions and 799 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,10 @@ jobs:
- name: Bundle files
run: |
mkdir -p ./temp/oxmysql
mkdir -p ./temp/oxmysql/web/
mkdir -p ./temp/oxmysql/lib/
mkdir -p ./temp/oxmysql/{web,lib}
cp ./{LICENSE,README.md,fxmanifest.lua,ui.lua} ./temp/oxmysql
cp ./lib/MySQL.lua ./temp/oxmysql/lib
cp -r ./dist ./temp/oxmysql
cp -r ./dist ./logger ./temp/oxmysql
cp -r ./web/build ./temp/oxmysql/web/
cd ./temp && zip -r ../oxmysql.zip ./oxmysql
Expand Down
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ A FiveM resource to communicate with a MySQL database using [node-mysql2](https:
![](https://img.shields.io/github/contributors/overextended/oxmysql?logo=github)
![](https://img.shields.io/github/v/release/overextended/oxmysql?logo=github)

## 📚 Documentation

https://overextended.dev/oxmysql

## 💾 Download

https://github.com/overextended/oxmysql/releases/latest/download/oxmysql.zip
## 🔗 Links
- 💾 [Download](https://github.com/overextended/oxmysql/releases/latest/download/oxmysql.zip)
- Download the latest release directly.
- 📚 [Documentation](https://overextended.dev/oxmysql)
- For installation, setup, and everything else.
- 📦 [npm](https://www.npmjs.com/package/@overextended/oxmysql)
- Use our npm package for enhanced functionality and TypeScript support.

## ✨ Features

Expand All @@ -24,9 +24,9 @@ https://github.com/overextended/oxmysql/releases/latest/download/oxmysql.zip
- Support for URI connection strings and semicolon separated values.
- Improved parameter checking and error handling.

## npm Package
## 🧾 Logging

https://www.npmjs.com/package/@overextended/oxmysql
We have included a module for submitting error logs to [Fivemanage](https://fivemanage.com/?ref=overextended), a cloud management service tailored for game servers. Additional logging options and support for other services will be available in the future.

## Lua Language Server

Expand Down
5 changes: 4 additions & 1 deletion build.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ dependencies {
}
client_script 'ui.lua'
server_script 'dist/build.js'
server_scripts {
'dist/build.js',
'logger/fivemanage.js'
}
files {
'web/build/index.html',
Expand Down
52 changes: 52 additions & 0 deletions logger/fivemanage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// https://fivemanage.com/?ref=overextended

const apiKey = GetConvar('FIVEMANAGE_LOGS_API_KEY', '');
const endpoint = 'https://api.fivemanage.com/api/logs/batch';

const headers = {
['Content-Type']: 'application/json',
['Authorization']: apiKey,
['User-Agent']: 'oxmysql',
};

const batchedLogs = [];

async function sendLogs() {
try {
const body = JSON.stringify(batchedLogs);
batchedLogs.length = 0;

const response = await fetch(endpoint, {
method: 'POST',
body: body,
headers: headers,
});

if (response.ok) return;

console.error(`Failed to submit logs to fivemanage - ${response.status} ${response.statusText}`);
} catch (err) {
console.error(err);
}
}

async function logger(level, resource, message, metadata) {
if (!apiKey) return;

if (batchedLogs.length === 0) setTimeout(sendLogs, 500);

batchedLogs.push({
level: level,
message: message,
resource: resource,
metadata: metadata,
});
}

function errorEvent(data) {
delete data.err.sqlMessage;
logger('error', data.resource, `${data.resource} was unable to execute a query!`, data.err);
}

on('oxmysql:error', errorEvent);
on('oxmysql:transaction-error', errorEvent);
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,19 @@
"postinstall": "patch-package && pnpm bootstrap"
},
"dependencies": {
"@citizenfx/server": "2.0.5132-1",
"@milahu/patch-package": "^6.4.14",
"@types/node": "^17.0.45",
"mysql2": "3.5.1",
"mysql2": "3.11.0",
"named-placeholders": "^1.1.3",
"node-fetch": "^3.3.1",
"prettier": "^2.8.8"
"node-fetch": "^3.3.2"
},
"devDependencies": {
"esbuild": "^0.20.0",
"@citizenfx/server": "2.0.5132-1",
"@types/node": "^17.0.45",
"esbuild": "^0.21.5",
"lerna": "^4.0.0",
"postinstall-postinstall": "^2.1.0",
"pretty-quick": "^3.1.3",
"typescript": "^5.3.3"
"prettier": "^2.8.8",
"pretty-quick": "^3.3.1",
"typescript": "^5.5.4"
}
}
}
56 changes: 31 additions & 25 deletions patches/mysql2+3.5.1.patch → patches/mysql2+3.10.2.patch
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# generated by patch-package 6.4.14
#
# declared package:
# mysql2: 3.5.1
# mysql2: 3.10.2
#
diff --git a/node_modules/mysql2/lib/connection.js b/node_modules/mysql2/lib/connection.js
index d6ad7a4..ceac670 100644
index 113fc7d..3a997a4 100644
--- a/node_modules/mysql2/lib/connection.js
+++ b/node_modules/mysql2/lib/connection.js
@@ -32,7 +32,7 @@ const CharsetToEncoding = require('./constants/charset_encodings.js');
Expand All @@ -16,7 +16,7 @@ index d6ad7a4..ceac670 100644

class Connection extends EventEmitter {
constructor(opts) {
@@ -521,7 +521,7 @@ class Connection extends EventEmitter {
@@ -524,7 +524,7 @@ class Connection extends EventEmitter {
sql: sql,
values: values
};
Expand All @@ -25,7 +25,7 @@ index d6ad7a4..ceac670 100644
return SqlString.format(
opts.sql,
opts.values,
@@ -543,20 +543,20 @@ class Connection extends EventEmitter {
@@ -546,20 +546,20 @@ class Connection extends EventEmitter {
}

_resolveNamedPlaceholders(options) {
Expand Down Expand Up @@ -60,7 +60,7 @@ index d6ad7a4..ceac670 100644
}

query(sql, values, cb) {
@@ -566,7 +566,7 @@ class Connection extends EventEmitter {
@@ -569,7 +569,7 @@ class Connection extends EventEmitter {
} else {
cmdQuery = Connection.createQuery(sql, values, cb, this.config);
}
Expand All @@ -69,7 +69,7 @@ index d6ad7a4..ceac670 100644
const rawSql = this.format(cmdQuery.sql, cmdQuery.values !== undefined ? cmdQuery.values : []);
cmdQuery.sql = rawSql;
return this.addCommand(cmdQuery);
@@ -634,26 +634,27 @@ class Connection extends EventEmitter {
@@ -644,26 +644,27 @@ class Connection extends EventEmitter {
options.sql = sql;
options.values = values;
}
Expand Down Expand Up @@ -128,10 +128,10 @@ index daf1df9..0862ce1 100644
case 'number':
type = Types.DOUBLE;
diff --git a/node_modules/mysql2/lib/parsers/binary_parser.js b/node_modules/mysql2/lib/parsers/binary_parser.js
index bbd2959..80ab00d 100644
index c80bf96..da453ca 100644
--- a/node_modules/mysql2/lib/parsers/binary_parser.js
+++ b/node_modules/mysql2/lib/parsers/binary_parser.js
@@ -72,7 +72,7 @@ function readCodeFor(field, config, options, fieldNum) {
@@ -75,7 +75,7 @@ function readCodeFor(field, config, options, fieldNum) {

default:
if (field.characterSet === Charsets.BINARY) {
Expand All @@ -140,29 +140,35 @@ index bbd2959..80ab00d 100644
}
return `packet.readLengthCodedString(fields[${fieldNum}].encoding)`;
}
@@ -92,6 +92,7 @@ function compile(fields, options, config) {
db: field.schema,
table: field.table,
name: field.name,
+ charset: field.characterSet,
string: function (encoding = field.encoding) {
if (field.columnType === Types.JSON && encoding === field.encoding) {
// Since for JSON columns mysql always returns charset 63 (BINARY),
diff --git a/node_modules/mysql2/lib/parsers/text_parser.js b/node_modules/mysql2/lib/parsers/text_parser.js
index 49a128c..7eafb2c 100644
index f66a185..55c8b63 100644
--- a/node_modules/mysql2/lib/parsers/text_parser.js
+++ b/node_modules/mysql2/lib/parsers/text_parser.js
@@ -85,6 +85,7 @@ function compile(fields, options, config) {
@@ -88,6 +88,7 @@ function compile(fields, options, config) {
db: field.schema,
table: field.table,
name: field.name,
+ charset: field.characterSet,
string: function(encoding = field.encoding) {
string: function (encoding = field.encoding) {
if (field.columnType === Types.JSON && encoding === field.encoding) {
// Since for JSON columns mysql always returns charset 63 (BINARY),
diff --git a/node_modules/mysql2/lib/pool.js b/node_modules/mysql2/lib/pool.js
index db54a7a..f104061 100644
--- a/node_modules/mysql2/lib/pool.js
+++ b/node_modules/mysql2/lib/pool.js
@@ -155,7 +155,8 @@ class Pool extends EventEmitter {
});
} catch (e) {
conn.release();
- throw e;
+ // throw e;
+ return cb(e);
}
});
return cmdQuery;
diff --git a/node_modules/mysql2/typings/mysql/lib/parsers/typeCast.d.ts b/node_modules/mysql2/typings/mysql/lib/parsers/typeCast.d.ts
index 65bfaa8..52ab677 100644
--- a/node_modules/mysql2/typings/mysql/lib/parsers/typeCast.d.ts
+++ b/node_modules/mysql2/typings/mysql/lib/parsers/typeCast.d.ts
@@ -43,6 +43,7 @@ export type Field = Type & {
db: string;
table: string;
name: string;
+ charset: number;
string: (encoding?: BufferEncoding | string | undefined) => string | null;
buffer: () => Buffer | null;
geometry: () => Geometry | Geometry[] | null;
Loading

0 comments on commit f005a2f

Please sign in to comment.