Skip to content
This repository was archived by the owner on Apr 29, 2025. It is now read-only.

Commit f005a2f

Browse files
authored
Merge pull request #232 from overextended/dev
2 parents 19d55a2 + a92b958 commit f005a2f

22 files changed

+1206
-799
lines changed

.github/workflows/release.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,10 @@ jobs:
5757
5858
- name: Bundle files
5959
run: |
60-
mkdir -p ./temp/oxmysql
61-
mkdir -p ./temp/oxmysql/web/
62-
mkdir -p ./temp/oxmysql/lib/
60+
mkdir -p ./temp/oxmysql/{web,lib}
6361
cp ./{LICENSE,README.md,fxmanifest.lua,ui.lua} ./temp/oxmysql
6462
cp ./lib/MySQL.lua ./temp/oxmysql/lib
65-
cp -r ./dist ./temp/oxmysql
63+
cp -r ./dist ./logger ./temp/oxmysql
6664
cp -r ./web/build ./temp/oxmysql/web/
6765
cd ./temp && zip -r ../oxmysql.zip ./oxmysql
6866

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ A FiveM resource to communicate with a MySQL database using [node-mysql2](https:
77
![](https://img.shields.io/github/contributors/overextended/oxmysql?logo=github)
88
![](https://img.shields.io/github/v/release/overextended/oxmysql?logo=github)
99

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

1818
## ✨ Features
1919

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

27-
## npm Package
27+
## 🧾 Logging
2828

29-
https://www.npmjs.com/package/@overextended/oxmysql
29+
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.
3030

3131
## Lua Language Server
3232

build.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ dependencies {
3737
}
3838
3939
client_script 'ui.lua'
40-
server_script 'dist/build.js'
40+
server_scripts {
41+
'dist/build.js',
42+
'logger/fivemanage.js'
43+
}
4144
4245
files {
4346
'web/build/index.html',

logger/fivemanage.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// https://fivemanage.com/?ref=overextended
2+
3+
const apiKey = GetConvar('FIVEMANAGE_LOGS_API_KEY', '');
4+
const endpoint = 'https://api.fivemanage.com/api/logs/batch';
5+
6+
const headers = {
7+
['Content-Type']: 'application/json',
8+
['Authorization']: apiKey,
9+
['User-Agent']: 'oxmysql',
10+
};
11+
12+
const batchedLogs = [];
13+
14+
async function sendLogs() {
15+
try {
16+
const body = JSON.stringify(batchedLogs);
17+
batchedLogs.length = 0;
18+
19+
const response = await fetch(endpoint, {
20+
method: 'POST',
21+
body: body,
22+
headers: headers,
23+
});
24+
25+
if (response.ok) return;
26+
27+
console.error(`Failed to submit logs to fivemanage - ${response.status} ${response.statusText}`);
28+
} catch (err) {
29+
console.error(err);
30+
}
31+
}
32+
33+
async function logger(level, resource, message, metadata) {
34+
if (!apiKey) return;
35+
36+
if (batchedLogs.length === 0) setTimeout(sendLogs, 500);
37+
38+
batchedLogs.push({
39+
level: level,
40+
message: message,
41+
resource: resource,
42+
metadata: metadata,
43+
});
44+
}
45+
46+
function errorEvent(data) {
47+
delete data.err.sqlMessage;
48+
logger('error', data.resource, `${data.resource} was unable to execute a query!`, data.err);
49+
}
50+
51+
on('oxmysql:error', errorEvent);
52+
on('oxmysql:transaction-error', errorEvent);

package.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,19 @@
2525
"postinstall": "patch-package && pnpm bootstrap"
2626
},
2727
"dependencies": {
28-
"@citizenfx/server": "2.0.5132-1",
2928
"@milahu/patch-package": "^6.4.14",
30-
"@types/node": "^17.0.45",
31-
"mysql2": "3.5.1",
29+
"mysql2": "3.11.0",
3230
"named-placeholders": "^1.1.3",
33-
"node-fetch": "^3.3.1",
34-
"prettier": "^2.8.8"
31+
"node-fetch": "^3.3.2"
3532
},
3633
"devDependencies": {
37-
"esbuild": "^0.20.0",
34+
"@citizenfx/server": "2.0.5132-1",
35+
"@types/node": "^17.0.45",
36+
"esbuild": "^0.21.5",
3837
"lerna": "^4.0.0",
3938
"postinstall-postinstall": "^2.1.0",
40-
"pretty-quick": "^3.1.3",
41-
"typescript": "^5.3.3"
39+
"prettier": "^2.8.8",
40+
"pretty-quick": "^3.3.1",
41+
"typescript": "^5.5.4"
4242
}
43-
}
43+
}

patches/mysql2+3.5.1.patch renamed to patches/mysql2+3.10.2.patch

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# generated by patch-package 6.4.14
22
#
33
# declared package:
4-
# mysql2: 3.5.1
4+
# mysql2: 3.10.2
55
#
66
diff --git a/node_modules/mysql2/lib/connection.js b/node_modules/mysql2/lib/connection.js
7-
index d6ad7a4..ceac670 100644
7+
index 113fc7d..3a997a4 100644
88
--- a/node_modules/mysql2/lib/connection.js
99
+++ b/node_modules/mysql2/lib/connection.js
1010
@@ -32,7 +32,7 @@ const CharsetToEncoding = require('./constants/charset_encodings.js');
@@ -16,7 +16,7 @@ index d6ad7a4..ceac670 100644
1616

1717
class Connection extends EventEmitter {
1818
constructor(opts) {
19-
@@ -521,7 +521,7 @@ class Connection extends EventEmitter {
19+
@@ -524,7 +524,7 @@ class Connection extends EventEmitter {
2020
sql: sql,
2121
values: values
2222
};
@@ -25,7 +25,7 @@ index d6ad7a4..ceac670 100644
2525
return SqlString.format(
2626
opts.sql,
2727
opts.values,
28-
@@ -543,20 +543,20 @@ class Connection extends EventEmitter {
28+
@@ -546,20 +546,20 @@ class Connection extends EventEmitter {
2929
}
3030

3131
_resolveNamedPlaceholders(options) {
@@ -60,7 +60,7 @@ index d6ad7a4..ceac670 100644
6060
}
6161

6262
query(sql, values, cb) {
63-
@@ -566,7 +566,7 @@ class Connection extends EventEmitter {
63+
@@ -569,7 +569,7 @@ class Connection extends EventEmitter {
6464
} else {
6565
cmdQuery = Connection.createQuery(sql, values, cb, this.config);
6666
}
@@ -69,7 +69,7 @@ index d6ad7a4..ceac670 100644
6969
const rawSql = this.format(cmdQuery.sql, cmdQuery.values !== undefined ? cmdQuery.values : []);
7070
cmdQuery.sql = rawSql;
7171
return this.addCommand(cmdQuery);
72-
@@ -634,26 +634,27 @@ class Connection extends EventEmitter {
72+
@@ -644,26 +644,27 @@ class Connection extends EventEmitter {
7373
options.sql = sql;
7474
options.values = values;
7575
}
@@ -128,10 +128,10 @@ index daf1df9..0862ce1 100644
128128
case 'number':
129129
type = Types.DOUBLE;
130130
diff --git a/node_modules/mysql2/lib/parsers/binary_parser.js b/node_modules/mysql2/lib/parsers/binary_parser.js
131-
index bbd2959..80ab00d 100644
131+
index c80bf96..da453ca 100644
132132
--- a/node_modules/mysql2/lib/parsers/binary_parser.js
133133
+++ b/node_modules/mysql2/lib/parsers/binary_parser.js
134-
@@ -72,7 +72,7 @@ function readCodeFor(field, config, options, fieldNum) {
134+
@@ -75,7 +75,7 @@ function readCodeFor(field, config, options, fieldNum) {
135135

136136
default:
137137
if (field.characterSet === Charsets.BINARY) {
@@ -140,29 +140,35 @@ index bbd2959..80ab00d 100644
140140
}
141141
return `packet.readLengthCodedString(fields[${fieldNum}].encoding)`;
142142
}
143+
@@ -92,6 +92,7 @@ function compile(fields, options, config) {
144+
db: field.schema,
145+
table: field.table,
146+
name: field.name,
147+
+ charset: field.characterSet,
148+
string: function (encoding = field.encoding) {
149+
if (field.columnType === Types.JSON && encoding === field.encoding) {
150+
// Since for JSON columns mysql always returns charset 63 (BINARY),
143151
diff --git a/node_modules/mysql2/lib/parsers/text_parser.js b/node_modules/mysql2/lib/parsers/text_parser.js
144-
index 49a128c..7eafb2c 100644
152+
index f66a185..55c8b63 100644
145153
--- a/node_modules/mysql2/lib/parsers/text_parser.js
146154
+++ b/node_modules/mysql2/lib/parsers/text_parser.js
147-
@@ -85,6 +85,7 @@ function compile(fields, options, config) {
155+
@@ -88,6 +88,7 @@ function compile(fields, options, config) {
148156
db: field.schema,
149157
table: field.table,
150158
name: field.name,
151159
+ charset: field.characterSet,
152-
string: function(encoding = field.encoding) {
160+
string: function (encoding = field.encoding) {
153161
if (field.columnType === Types.JSON && encoding === field.encoding) {
154162
// Since for JSON columns mysql always returns charset 63 (BINARY),
155-
diff --git a/node_modules/mysql2/lib/pool.js b/node_modules/mysql2/lib/pool.js
156-
index db54a7a..f104061 100644
157-
--- a/node_modules/mysql2/lib/pool.js
158-
+++ b/node_modules/mysql2/lib/pool.js
159-
@@ -155,7 +155,8 @@ class Pool extends EventEmitter {
160-
});
161-
} catch (e) {
162-
conn.release();
163-
- throw e;
164-
+ // throw e;
165-
+ return cb(e);
166-
}
167-
});
168-
return cmdQuery;
163+
diff --git a/node_modules/mysql2/typings/mysql/lib/parsers/typeCast.d.ts b/node_modules/mysql2/typings/mysql/lib/parsers/typeCast.d.ts
164+
index 65bfaa8..52ab677 100644
165+
--- a/node_modules/mysql2/typings/mysql/lib/parsers/typeCast.d.ts
166+
+++ b/node_modules/mysql2/typings/mysql/lib/parsers/typeCast.d.ts
167+
@@ -43,6 +43,7 @@ export type Field = Type & {
168+
db: string;
169+
table: string;
170+
name: string;
171+
+ charset: number;
172+
string: (encoding?: BufferEncoding | string | undefined) => string | null;
173+
buffer: () => Buffer | null;
174+
geometry: () => Geometry | Geometry[] | null;

0 commit comments

Comments
 (0)