@dbml/connector 3.9.0 → 3.9.2-alpha.0
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/.babelrc +0 -0
- package/LICENSE +0 -0
- package/README.md +0 -0
- package/__tests__/connector.test.ts +0 -0
- package/__tests__/connectors/mssql/connection.json +0 -0
- package/__tests__/connectors/mssql/expect-out-files/schema.json +203 -59
- package/__tests__/connectors/mysql/connection.json +0 -0
- package/__tests__/connectors/mysql/expect-out-files/schema.json +2 -2
- package/__tests__/connectors/postgres/connection.json +0 -0
- package/__tests__/connectors/postgres/expect-out-files/schema.json +3 -3
- package/dist/connectors/bigqueryConnector.d.ts +0 -0
- package/dist/connectors/bigqueryConnector.js +0 -0
- package/dist/connectors/connector.d.ts +0 -0
- package/dist/connectors/connector.js +0 -0
- package/dist/connectors/mssqlConnector.d.ts +0 -0
- package/dist/connectors/mssqlConnector.js +33 -7
- package/dist/connectors/mysqlConnector.d.ts +0 -0
- package/dist/connectors/mysqlConnector.js +0 -0
- package/dist/connectors/postgresConnector.d.ts +0 -0
- package/dist/connectors/postgresConnector.js +0 -0
- package/dist/connectors/snowflakeConnector.d.ts +0 -0
- package/dist/connectors/snowflakeConnector.js +0 -0
- package/dist/connectors/types.d.ts +0 -0
- package/dist/connectors/types.js +0 -0
- package/dist/index.d.ts +0 -0
- package/dist/index.js +0 -0
- package/dist/utils/credential-loader.d.ts +0 -0
- package/dist/utils/credential-loader.js +0 -0
- package/dist/utils/helpers.d.ts +0 -0
- package/dist/utils/helpers.js +0 -0
- package/dist/utils/parseSchema.d.ts +0 -0
- package/dist/utils/parseSchema.js +0 -0
- package/jest.config.ts +0 -0
- package/jestHelpers.ts +0 -0
- package/package.json +2 -2
- package/src/connectors/bigqueryConnector.ts +0 -0
- package/src/connectors/connector.ts +0 -0
- package/src/connectors/mssqlConnector.ts +40 -7
- package/src/connectors/mysqlConnector.ts +0 -0
- package/src/connectors/postgresConnector.ts +0 -0
- package/src/connectors/snowflakeConnector.ts +0 -0
- package/src/connectors/types.ts +0 -0
- package/src/ddl_samples/bigquery.sql +0 -0
- package/src/ddl_samples/snowflake.sql +0 -0
- package/src/index.ts +0 -0
- package/src/utils/credential-loader.ts +0 -0
- package/src/utils/helpers.ts +0 -0
- package/src/utils/parseSchema.ts +0 -0
- package/tsconfig.json +0 -0
- package/__tests__/connectors/bigquery/out-files/schema.json +0 -565
- package/__tests__/connectors/mysql/out-files/schema.json +0 -1390
- package/__tests__/connectors/postgres/out-files/schema.json +0 -1411
|
@@ -81,7 +81,7 @@
|
|
|
81
81
|
"name": "table_with_comments",
|
|
82
82
|
"schemaName": "public",
|
|
83
83
|
"note": {
|
|
84
|
-
"value": "This table stores information about various items."
|
|
84
|
+
"value": "This table stores information about various items. Such as: 'id', 'name', 'description'"
|
|
85
85
|
}
|
|
86
86
|
},
|
|
87
87
|
{
|
|
@@ -1007,7 +1007,7 @@
|
|
|
1007
1007
|
"not_null": false,
|
|
1008
1008
|
"increment": false,
|
|
1009
1009
|
"note": {
|
|
1010
|
-
"value": "
|
|
1010
|
+
"value": "Item's name."
|
|
1011
1011
|
}
|
|
1012
1012
|
},
|
|
1013
1013
|
{
|
|
@@ -1020,7 +1020,7 @@
|
|
|
1020
1020
|
"not_null": false,
|
|
1021
1021
|
"increment": false,
|
|
1022
1022
|
"note": {
|
|
1023
|
-
"value": "
|
|
1023
|
+
"value": "Item's description"
|
|
1024
1024
|
}
|
|
1025
1025
|
},
|
|
1026
1026
|
{
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -7,6 +7,7 @@ exports.fetchSchemaJson = void 0;
|
|
|
7
7
|
/* eslint-disable camelcase */
|
|
8
8
|
const mssql_1 = __importDefault(require("mssql"));
|
|
9
9
|
const parseSchema_1 = require("../utils/parseSchema");
|
|
10
|
+
// https://learn.microsoft.com/en-us/sql/t-sql/data-types/date-and-time-types?view=sql-server-ver15
|
|
10
11
|
const MSSQL_DATE_TYPES = [
|
|
11
12
|
'date',
|
|
12
13
|
'datetime',
|
|
@@ -36,18 +37,43 @@ const getValidatedClient = async (connection) => {
|
|
|
36
37
|
}
|
|
37
38
|
};
|
|
38
39
|
const convertQueryBoolean = (val) => val === 'YES';
|
|
39
|
-
const getFieldType = (data_type,
|
|
40
|
+
const getFieldType = (data_type, character_maximum_length, numeric_precision, numeric_scale) => {
|
|
40
41
|
if (MSSQL_DATE_TYPES.includes(data_type)) {
|
|
41
42
|
return data_type;
|
|
42
43
|
}
|
|
44
|
+
// timestamp is a synonym of rowversion and we cannot specify the precision for it
|
|
45
|
+
// https://learn.microsoft.com/en-us/sql/t-sql/data-types/rowversion-transact-sql?view=sql-server-ver15
|
|
46
|
+
if (data_type === 'timestamp') {
|
|
47
|
+
return data_type;
|
|
48
|
+
}
|
|
49
|
+
// process numeric-based type
|
|
43
50
|
if (data_type === 'bit') {
|
|
44
51
|
return data_type;
|
|
45
52
|
}
|
|
46
|
-
if
|
|
47
|
-
|
|
53
|
+
// if precision != 0 => numeric-based column
|
|
54
|
+
if (numeric_precision) {
|
|
55
|
+
return numeric_scale
|
|
56
|
+
? `${data_type}(${numeric_precision},${numeric_scale})`
|
|
57
|
+
: `${data_type}(${numeric_precision})`;
|
|
58
|
+
}
|
|
59
|
+
// process string-based type
|
|
60
|
+
// ntext, text & image
|
|
61
|
+
if (['ntext', 'text', 'image'].includes(data_type)) {
|
|
62
|
+
return data_type;
|
|
63
|
+
}
|
|
64
|
+
// Column data type is varchar(max), nvarchar(max), varbinary(max), or xml
|
|
65
|
+
if (character_maximum_length < 0) {
|
|
66
|
+
return data_type === 'xml' ? data_type : `${data_type}(MAX)`;
|
|
48
67
|
}
|
|
49
|
-
|
|
50
|
-
|
|
68
|
+
// character_maximum_length is the lenght in bytes
|
|
69
|
+
// nchar and nvarchar store Unicode characters, each character needs 2 bytes
|
|
70
|
+
// so we have to divide it by 2 to get the correct maximum lenght in character.
|
|
71
|
+
// ref: https://learn.microsoft.com/en-us/sql/t-sql/data-types/nchar-and-nvarchar-transact-sql?view=sql-server-ver15
|
|
72
|
+
if (character_maximum_length > 0) {
|
|
73
|
+
const maximum_length_in_character = (data_type === 'nchar' || data_type === 'nvarchar')
|
|
74
|
+
? character_maximum_length / 2
|
|
75
|
+
: character_maximum_length;
|
|
76
|
+
return `${data_type}(${maximum_length_in_character})`;
|
|
51
77
|
}
|
|
52
78
|
return data_type;
|
|
53
79
|
};
|
|
@@ -90,7 +116,7 @@ const generateField = (row) => {
|
|
|
90
116
|
const { column_name, data_type, character_maximum_length, numeric_precision, numeric_scale, identity_increment, is_nullable, column_default, default_type, column_comment, } = row;
|
|
91
117
|
const dbdefault = column_default && default_type !== 'increment' ? getDbdefault(data_type, column_default, default_type) : null;
|
|
92
118
|
const fieldType = {
|
|
93
|
-
type_name: getFieldType(data_type,
|
|
119
|
+
type_name: getFieldType(data_type, character_maximum_length, numeric_precision, numeric_scale),
|
|
94
120
|
schemaName: null,
|
|
95
121
|
};
|
|
96
122
|
return {
|
|
@@ -194,7 +220,7 @@ const generateTablesFieldsAndEnums = async (client, schemas) => {
|
|
|
194
220
|
constraints_with_row_number
|
|
195
221
|
WHERE
|
|
196
222
|
rn = 1
|
|
197
|
-
${(0, parseSchema_1.buildSchemaQuery)('table_schema', schemas
|
|
223
|
+
${(0, parseSchema_1.buildSchemaQuery)('table_schema', schemas)}
|
|
198
224
|
ORDER BY
|
|
199
225
|
table_schema,
|
|
200
226
|
table_name,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/dist/connectors/types.js
CHANGED
|
File without changes
|
package/dist/index.d.ts
CHANGED
|
File without changes
|
package/dist/index.js
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/dist/utils/helpers.d.ts
CHANGED
|
File without changes
|
package/dist/utils/helpers.js
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/jest.config.ts
CHANGED
|
File without changes
|
package/jestHelpers.ts
CHANGED
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dbml/connector",
|
|
3
|
-
"version": "3.9.0",
|
|
3
|
+
"version": "3.9.2-alpha.0",
|
|
4
4
|
"description": "This package was created to fetch the schema JSON from many kind of databases.",
|
|
5
5
|
"author": "huy.phung.sw@gmail.com",
|
|
6
6
|
"license": "MIT",
|
|
@@ -40,5 +40,5 @@
|
|
|
40
40
|
"engines": {
|
|
41
41
|
"node": ">=18"
|
|
42
42
|
},
|
|
43
|
-
"gitHead": "
|
|
43
|
+
"gitHead": "269532f01f0475328ef08c72ec2ca901a91b0846"
|
|
44
44
|
}
|
|
File without changes
|
|
File without changes
|
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
TableConstraintsDictionary,
|
|
17
17
|
} from './types';
|
|
18
18
|
|
|
19
|
+
// https://learn.microsoft.com/en-us/sql/t-sql/data-types/date-and-time-types?view=sql-server-ver15
|
|
19
20
|
const MSSQL_DATE_TYPES = [
|
|
20
21
|
'date',
|
|
21
22
|
'datetime',
|
|
@@ -49,19 +50,51 @@ const getValidatedClient = async (connection: string): Promise<sql.ConnectionPoo
|
|
|
49
50
|
|
|
50
51
|
const convertQueryBoolean = (val: string | null): boolean => val === 'YES';
|
|
51
52
|
|
|
52
|
-
const getFieldType = (data_type: string,
|
|
53
|
+
const getFieldType = (data_type: string, character_maximum_length: number, numeric_precision: number, numeric_scale: number): string => {
|
|
53
54
|
if (MSSQL_DATE_TYPES.includes(data_type)) {
|
|
54
55
|
return data_type;
|
|
55
56
|
}
|
|
57
|
+
|
|
58
|
+
// timestamp is a synonym of rowversion and we cannot specify the precision for it
|
|
59
|
+
// https://learn.microsoft.com/en-us/sql/t-sql/data-types/rowversion-transact-sql?view=sql-server-ver15
|
|
60
|
+
if (data_type === 'timestamp') {
|
|
61
|
+
return data_type;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// process numeric-based type
|
|
56
65
|
if (data_type === 'bit') {
|
|
57
66
|
return data_type;
|
|
58
67
|
}
|
|
59
|
-
if
|
|
60
|
-
|
|
68
|
+
// if precision != 0 => numeric-based column
|
|
69
|
+
if (numeric_precision) {
|
|
70
|
+
return numeric_scale
|
|
71
|
+
? `${data_type}(${numeric_precision},${numeric_scale})`
|
|
72
|
+
: `${data_type}(${numeric_precision})`;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// process string-based type
|
|
76
|
+
// ntext, text & image
|
|
77
|
+
if (['ntext', 'text', 'image'].includes(data_type)) {
|
|
78
|
+
return data_type;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Column data type is varchar(max), nvarchar(max), varbinary(max), or xml
|
|
82
|
+
if (character_maximum_length < 0) {
|
|
83
|
+
return data_type === 'xml' ? data_type : `${data_type}(MAX)`;
|
|
61
84
|
}
|
|
62
|
-
|
|
63
|
-
|
|
85
|
+
|
|
86
|
+
// character_maximum_length is the lenght in bytes
|
|
87
|
+
// nchar and nvarchar store Unicode characters, each character needs 2 bytes
|
|
88
|
+
// so we have to divide it by 2 to get the correct maximum lenght in character.
|
|
89
|
+
// ref: https://learn.microsoft.com/en-us/sql/t-sql/data-types/nchar-and-nvarchar-transact-sql?view=sql-server-ver15
|
|
90
|
+
if (character_maximum_length > 0) {
|
|
91
|
+
const maximum_length_in_character = (data_type === 'nchar' || data_type === 'nvarchar')
|
|
92
|
+
? character_maximum_length / 2
|
|
93
|
+
: character_maximum_length;
|
|
94
|
+
|
|
95
|
+
return `${data_type}(${maximum_length_in_character})`;
|
|
64
96
|
}
|
|
97
|
+
|
|
65
98
|
return data_type;
|
|
66
99
|
};
|
|
67
100
|
|
|
@@ -119,7 +152,7 @@ const generateField = (row: Record<string, any>): Field => {
|
|
|
119
152
|
const dbdefault = column_default && default_type !== 'increment' ? getDbdefault(data_type, column_default, default_type) : null;
|
|
120
153
|
|
|
121
154
|
const fieldType = {
|
|
122
|
-
type_name: getFieldType(data_type,
|
|
155
|
+
type_name: getFieldType(data_type, character_maximum_length, numeric_precision, numeric_scale),
|
|
123
156
|
schemaName: null,
|
|
124
157
|
};
|
|
125
158
|
|
|
@@ -229,7 +262,7 @@ const generateTablesFieldsAndEnums = async (client: sql.ConnectionPool, schemas:
|
|
|
229
262
|
constraints_with_row_number
|
|
230
263
|
WHERE
|
|
231
264
|
rn = 1
|
|
232
|
-
${buildSchemaQuery('table_schema', schemas
|
|
265
|
+
${buildSchemaQuery('table_schema', schemas)}
|
|
233
266
|
ORDER BY
|
|
234
267
|
table_schema,
|
|
235
268
|
table_name,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/src/connectors/types.ts
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/src/index.ts
CHANGED
|
File without changes
|
|
File without changes
|
package/src/utils/helpers.ts
CHANGED
|
File without changes
|
package/src/utils/parseSchema.ts
CHANGED
|
File without changes
|
package/tsconfig.json
CHANGED
|
File without changes
|