@travetto/model-mysql 7.1.4 → 8.0.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +8 -8
- package/src/connection.ts +12 -7
- package/support/service.mysql.ts +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@travetto/model-mysql",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "8.0.0-alpha.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "MySQL backing for the travetto model module, with real-time modeling support for SQL schemas.",
|
|
6
6
|
"keywords": [
|
|
@@ -28,15 +28,15 @@
|
|
|
28
28
|
"directory": "module/model-mysql"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@travetto/config": "^
|
|
32
|
-
"@travetto/context": "^
|
|
33
|
-
"@travetto/model": "^
|
|
34
|
-
"@travetto/model-query": "^
|
|
35
|
-
"@travetto/model-sql": "^
|
|
36
|
-
"mysql2": "^3.
|
|
31
|
+
"@travetto/config": "^8.0.0-alpha.1",
|
|
32
|
+
"@travetto/context": "^8.0.0-alpha.1",
|
|
33
|
+
"@travetto/model": "^8.0.0-alpha.1",
|
|
34
|
+
"@travetto/model-query": "^8.0.0-alpha.1",
|
|
35
|
+
"@travetto/model-sql": "^8.0.0-alpha.1",
|
|
36
|
+
"mysql2": "^3.19.0"
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
|
-
"@travetto/cli": "^
|
|
39
|
+
"@travetto/cli": "^8.0.0-alpha.1"
|
|
40
40
|
},
|
|
41
41
|
"peerDependenciesMeta": {
|
|
42
42
|
"@travetto/cli": {
|
package/src/connection.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createPool } from 'mysql2';
|
|
2
|
-
import type { PoolConnection, Pool, OkPacket, ResultSetHeader } from 'mysql2/promise';
|
|
2
|
+
import type { PoolConnection, Pool, OkPacket, ResultSetHeader, TypeCastField } from 'mysql2/promise';
|
|
3
3
|
|
|
4
4
|
import { castTo, JSONUtil, ShutdownManager } from '@travetto/runtime';
|
|
5
5
|
import type { AsyncContext } from '@travetto/context';
|
|
@@ -35,6 +35,7 @@ export class MySQLConnection extends Connection<PoolConnection> {
|
|
|
35
35
|
database: this.#config.database,
|
|
36
36
|
host: this.#config.host,
|
|
37
37
|
port: this.#config.port,
|
|
38
|
+
supportBigNumbers: true,
|
|
38
39
|
timezone: '+00:00',
|
|
39
40
|
typeCast: this.typeCast.bind(this),
|
|
40
41
|
...(this.#config.options || {})
|
|
@@ -47,13 +48,17 @@ export class MySQLConnection extends Connection<PoolConnection> {
|
|
|
47
48
|
/**
|
|
48
49
|
* Support some basic type support for JSON data
|
|
49
50
|
*/
|
|
50
|
-
typeCast(field:
|
|
51
|
+
typeCast(field: TypeCastField, next: () => unknown): unknown {
|
|
51
52
|
const result = next();
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
53
|
+
switch (field.type) {
|
|
54
|
+
case 'JSON':
|
|
55
|
+
case 'BLOB': {
|
|
56
|
+
if (typeof result === 'string' && result.charAt(0) === '{' && result.charAt(result.length - 1) === '}') {
|
|
57
|
+
try {
|
|
58
|
+
return JSONUtil.fromUTF8(result);
|
|
59
|
+
} catch { }
|
|
60
|
+
}
|
|
61
|
+
break;
|
|
57
62
|
}
|
|
58
63
|
}
|
|
59
64
|
return result;
|
package/support/service.mysql.ts
CHANGED