@naturalcycles/mysql-lib 3.12.1 → 3.12.2
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.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CommonLogger, JsonSchemaObject, JsonSchemaRootObject } from '@naturalcycles/js-lib';
|
|
1
|
+
import { AnyObject, CommonLogger, JsonSchemaObject, JsonSchemaRootObject } from '@naturalcycles/js-lib';
|
|
2
2
|
export interface MySQLTableStats {
|
|
3
3
|
Field: string;
|
|
4
4
|
Type: string;
|
|
@@ -14,7 +14,7 @@ export interface MySQLSchemaOptions {
|
|
|
14
14
|
* It currently skips nullability and declares everything as "DEFAULT NULL".
|
|
15
15
|
*/
|
|
16
16
|
export declare function jsonSchemaToMySQLDDL(table: string, schema: JsonSchemaObject<any>, opt?: MySQLSchemaOptions): string;
|
|
17
|
-
export declare function mysqlTableStatsToJsonSchemaField<T = any>(table: string, stats: MySQLTableStats[], logger: CommonLogger): JsonSchemaRootObject<T>;
|
|
17
|
+
export declare function mysqlTableStatsToJsonSchemaField<T extends AnyObject = any>(table: string, stats: MySQLTableStats[], logger: CommonLogger): JsonSchemaRootObject<T>;
|
|
18
18
|
/**
|
|
19
19
|
* Because MySQL doesn't support `.` in field names and escapes them as tableName + fieldName.
|
|
20
20
|
*
|
package/package.json
CHANGED
|
@@ -11,10 +11,10 @@
|
|
|
11
11
|
"mysql": "^2.17.1"
|
|
12
12
|
},
|
|
13
13
|
"devDependencies": {
|
|
14
|
-
"@naturalcycles/dev-lib": "^
|
|
15
|
-
"@types/node": "^
|
|
14
|
+
"@naturalcycles/dev-lib": "^13.2.1",
|
|
15
|
+
"@types/node": "^18.7.13",
|
|
16
16
|
"dotenv": "^16.0.0",
|
|
17
|
-
"jest": "^
|
|
17
|
+
"jest": "^29.0.0"
|
|
18
18
|
},
|
|
19
19
|
"files": [
|
|
20
20
|
"dist",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"engines": {
|
|
37
37
|
"node": ">=14.15.0"
|
|
38
38
|
},
|
|
39
|
-
"version": "3.12.
|
|
39
|
+
"version": "3.12.2",
|
|
40
40
|
"description": "MySQL client implementing CommonDB interface",
|
|
41
41
|
"keywords": [
|
|
42
42
|
"mysql",
|
package/src/query.util.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { DBQuery } from '@naturalcycles/db-lib'
|
|
2
|
-
import { DBQueryFilterOperator } from '@naturalcycles/db-lib/src/query/dbQuery'
|
|
1
|
+
import { DBQuery, DBQueryFilterOperator } from '@naturalcycles/db-lib'
|
|
3
2
|
import { _hb, CommonLogger } from '@naturalcycles/js-lib'
|
|
4
3
|
import { white, yellow } from '@naturalcycles/nodejs-lib/dist/colors'
|
|
5
4
|
import { QueryOptions } from 'mysql'
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
+
AnyObject,
|
|
2
3
|
CommonLogger,
|
|
3
4
|
JsonSchemaBoolean,
|
|
4
5
|
JsonSchemaNumber,
|
|
@@ -79,7 +80,7 @@ export function jsonSchemaToMySQLDDL(
|
|
|
79
80
|
return lines.join('\n')
|
|
80
81
|
}
|
|
81
82
|
|
|
82
|
-
export function mysqlTableStatsToJsonSchemaField<T = any>(
|
|
83
|
+
export function mysqlTableStatsToJsonSchemaField<T extends AnyObject = any>(
|
|
83
84
|
table: string,
|
|
84
85
|
stats: MySQLTableStats[],
|
|
85
86
|
logger: CommonLogger,
|
|
@@ -93,7 +94,7 @@ export function mysqlTableStatsToJsonSchemaField<T = any>(
|
|
|
93
94
|
}
|
|
94
95
|
|
|
95
96
|
stats.forEach(stat => {
|
|
96
|
-
const name = stat.Field
|
|
97
|
+
const name = stat.Field as keyof T
|
|
97
98
|
const t = stat.Type.toLowerCase()
|
|
98
99
|
const notNull = stat.Null?.toUpperCase() !== 'YES'
|
|
99
100
|
if (notNull) {
|
|
@@ -112,7 +113,7 @@ export function mysqlTableStatsToJsonSchemaField<T = any>(
|
|
|
112
113
|
s.properties[name] = { type: 'number' } as JsonSchemaNumber
|
|
113
114
|
} else {
|
|
114
115
|
logger.log(s)
|
|
115
|
-
throw new Error(`Unknown mysql field type ${name} ${stat.Type}`)
|
|
116
|
+
throw new Error(`Unknown mysql field type ${name as string} ${stat.Type}`)
|
|
116
117
|
}
|
|
117
118
|
})
|
|
118
119
|
|