@dbml/cli 3.7.4 → 3.8.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/__test__/db2dbml/postgres/expect-out-files/schema.dbml +40 -0
- package/__test__/db2dbml/postgres/schema.sql +31 -0
- package/dbml-error.log +82 -0
- package/lib/cli/connector.js +2 -2
- package/lib/cli/index.js +20 -13
- package/lib/cli/utils.js +8 -3
- package/package.json +4 -4
- package/src/cli/connector.js +2 -2
- package/src/cli/index.js +19 -12
- package/src/cli/utils.js +10 -3
|
@@ -1,3 +1,33 @@
|
|
|
1
|
+
Enum "dbml_test"."enum_type1" {
|
|
2
|
+
"value1"
|
|
3
|
+
"value2"
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
Enum "dbml_test"."enum_type3" {
|
|
7
|
+
"value4"
|
|
8
|
+
"value5"
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
Table "dbml_test"."table1" {
|
|
12
|
+
"id" int4 [pk, not null, increment]
|
|
13
|
+
"status" dbml_test.enum_type1
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
Table "dbml_test"."table3" {
|
|
17
|
+
"id" int4 [pk, not null, increment]
|
|
18
|
+
"status" dbml_test.enum_type3
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
Enum "enum_type1" {
|
|
22
|
+
"value1"
|
|
23
|
+
"value2"
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
Enum "enum_type2" {
|
|
27
|
+
"value1"
|
|
28
|
+
"value3"
|
|
29
|
+
}
|
|
30
|
+
|
|
1
31
|
Enum "gender_type" {
|
|
2
32
|
"Male"
|
|
3
33
|
"Female"
|
|
@@ -94,6 +124,16 @@ Table "products" {
|
|
|
94
124
|
}
|
|
95
125
|
}
|
|
96
126
|
|
|
127
|
+
Table "table1" {
|
|
128
|
+
"id" int4 [pk, not null, increment]
|
|
129
|
+
"status" enum_type1
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
Table "table2" {
|
|
133
|
+
"id" int4 [pk, not null, increment]
|
|
134
|
+
"status" enum_type2
|
|
135
|
+
}
|
|
136
|
+
|
|
97
137
|
Table "table_with_comments" {
|
|
98
138
|
"id" int4 [pk, not null, increment, note: 'Unique identifier for each item.']
|
|
99
139
|
"name" varchar(100) [note: 'Name of the item.']
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
-- Create users table
|
|
2
|
+
CREATE SCHEMA dbml_test;
|
|
3
|
+
|
|
2
4
|
CREATE TABLE users (
|
|
3
5
|
user_id SERIAL PRIMARY KEY,
|
|
4
6
|
username VARCHAR(50) UNIQUE NOT NULL,
|
|
@@ -154,3 +156,32 @@ CREATE TABLE Books (
|
|
|
154
156
|
CONSTRAINT FK_AuthorNationality FOREIGN KEY (AuthorID, NationalityID)
|
|
155
157
|
REFERENCES Authors (AuthorID, NationalityID) ON DELETE CASCADE
|
|
156
158
|
);
|
|
159
|
+
|
|
160
|
+
-- Create enum types in the public schema
|
|
161
|
+
CREATE TYPE public.enum_type1 AS ENUM ('value1', 'value2');
|
|
162
|
+
CREATE TYPE public.enum_type2 AS ENUM ('value1', 'value3');
|
|
163
|
+
|
|
164
|
+
-- Create enum types in the dbml_test schema
|
|
165
|
+
CREATE TYPE dbml_test.enum_type1 AS ENUM ('value1', 'value2');
|
|
166
|
+
CREATE TYPE dbml_test.enum_type3 AS ENUM ('value4', 'value5');
|
|
167
|
+
|
|
168
|
+
-- Optionally, create tables to use these enum types
|
|
169
|
+
CREATE TABLE public.table1 (
|
|
170
|
+
id SERIAL PRIMARY KEY,
|
|
171
|
+
status public.enum_type1
|
|
172
|
+
);
|
|
173
|
+
|
|
174
|
+
CREATE TABLE public.table2 (
|
|
175
|
+
id SERIAL PRIMARY KEY,
|
|
176
|
+
status public.enum_type2
|
|
177
|
+
);
|
|
178
|
+
|
|
179
|
+
CREATE TABLE dbml_test.table1 (
|
|
180
|
+
id SERIAL PRIMARY KEY,
|
|
181
|
+
status dbml_test.enum_type1
|
|
182
|
+
);
|
|
183
|
+
|
|
184
|
+
CREATE TABLE dbml_test.table3 (
|
|
185
|
+
id SERIAL PRIMARY KEY,
|
|
186
|
+
status dbml_test.enum_type3
|
|
187
|
+
);
|
package/dbml-error.log
CHANGED
|
@@ -57,3 +57,85 @@ Error: Load credential error: ENOENT: no such file or directory, open 'bigquery'
|
|
|
57
57
|
at async fetchSchemaJson (/Users/huylm/code/dbx/dbml/packages/dbml-connector/dist/connectors/bigqueryConnector.js:256:27)
|
|
58
58
|
at async connectionHandler (/Users/huylm/code/dbx/dbml/packages/dbml-cli/lib/cli/connector.js:24:24)
|
|
59
59
|
|
|
60
|
+
2024-08-26T04:32:24.565Z
|
|
61
|
+
Error: Load credential error: ENOENT: no such file or directory, open 'bigquery'
|
|
62
|
+
at loadCredentialFromFile (/Users/huylm/code/dbx/dbml/packages/dbml-connector/dist/connectors/utils/credential-loader.js:13:19)
|
|
63
|
+
at async fetchSchemaJson (/Users/huylm/code/dbx/dbml/packages/dbml-connector/dist/connectors/bigqueryConnector.js:259:27)
|
|
64
|
+
at async connectionHandler (/Users/huylm/code/dbx/dbml/packages/dbml-cli/lib/cli/connector.js:24:24)
|
|
65
|
+
|
|
66
|
+
2024-08-26T09:05:40.128Z
|
|
67
|
+
Error: Load credential error: ENOENT: no such file or directory, open '/Users/huylm/code/dbx/dbml/packages/dbml-connector/keys/bq-test-key.json'
|
|
68
|
+
at loadCredentialFromFile (/Users/huylm/code/dbx/dbml/packages/dbml-connector/dist/connectors/utils/credential-loader.js:13:19)
|
|
69
|
+
at async fetchSchemaJson (/Users/huylm/code/dbx/dbml/packages/dbml-connector/dist/connectors/bigqueryConnector.js:259:27)
|
|
70
|
+
at async connectionHandler (/Users/huylm/code/dbx/dbml/packages/dbml-cli/lib/cli/connector.js:24:24)
|
|
71
|
+
|
|
72
|
+
2024-08-26T09:06:55.525Z
|
|
73
|
+
Error: Load credential error: ENOENT: no such file or directory, open '/Users/huylm/code/dbx/bq-test-key.json'
|
|
74
|
+
at loadCredentialFromFile (/Users/huylm/code/dbx/dbml/packages/dbml-connector/dist/connectors/utils/credential-loader.js:13:19)
|
|
75
|
+
at async fetchSchemaJson (/Users/huylm/code/dbx/dbml/packages/dbml-connector/dist/connectors/bigqueryConnector.js:259:27)
|
|
76
|
+
at async connectionHandler (/Users/huylm/code/dbx/dbml/packages/dbml-cli/lib/cli/connector.js:24:24)
|
|
77
|
+
|
|
78
|
+
2024-08-26T09:12:14.323Z
|
|
79
|
+
Error: Load credential error: ENOENT: no such file or directory, open '/Users/huylm/Users/huylm/code/dbx/bq-test-key.json'
|
|
80
|
+
at loadCredentialFromFile (/Users/huylm/code/dbx/dbml/packages/dbml-connector/dist/connectors/utils/credential-loader.js:13:19)
|
|
81
|
+
at async fetchSchemaJson (/Users/huylm/code/dbx/dbml/packages/dbml-connector/dist/connectors/bigqueryConnector.js:259:27)
|
|
82
|
+
at async connectionHandler (/Users/huylm/code/dbx/dbml/packages/dbml-cli/lib/cli/connector.js:24:24)
|
|
83
|
+
|
|
84
|
+
2024-08-26T09:12:39.045Z
|
|
85
|
+
Error: Load credential error: ENOENT: no such file or directory, open '/Users/huylm/code/dbx/dbml/packages/dbml-connector/keys/bq-test-key.json'
|
|
86
|
+
at loadCredentialFromFile (/Users/huylm/code/dbx/dbml/packages/dbml-connector/dist/connectors/utils/credential-loader.js:13:19)
|
|
87
|
+
at async fetchSchemaJson (/Users/huylm/code/dbx/dbml/packages/dbml-connector/dist/connectors/bigqueryConnector.js:259:27)
|
|
88
|
+
at async connectionHandler (/Users/huylm/code/dbx/dbml/packages/dbml-cli/lib/cli/connector.js:24:24)
|
|
89
|
+
|
|
90
|
+
2024-08-26T09:38:34.868Z
|
|
91
|
+
Error: Unsupported connection format: unknown
|
|
92
|
+
at Object.fetchSchemaJson (/Users/huylm/code/dbx/dbml/packages/dbml-connector/dist/connectors/connector.js:19:19)
|
|
93
|
+
at connectionHandler (/Users/huylm/code/dbx/dbml/packages/dbml-cli/lib/cli/connector.js:24:51)
|
|
94
|
+
at Object.db2dbml (/Users/huylm/code/dbx/dbml/packages/dbml-cli/lib/cli/index.js:66:26)
|
|
95
|
+
at Object.<anonymous> (/Users/huylm/code/dbx/dbml/packages/dbml-cli/bin/db2dbml.js:4:19)
|
|
96
|
+
at Module._compile (node:internal/modules/cjs/loader:1256:14)
|
|
97
|
+
at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
|
|
98
|
+
at Module.load (node:internal/modules/cjs/loader:1119:32)
|
|
99
|
+
at Module._load (node:internal/modules/cjs/loader:960:12)
|
|
100
|
+
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
|
|
101
|
+
at node:internal/main/run_main_module:23:47
|
|
102
|
+
|
|
103
|
+
2024-08-27T04:10:42.077Z
|
|
104
|
+
InvalidParameterError: Invalid account. The specified value must be a valid subdomain string.
|
|
105
|
+
at createError (/Users/huylm/code/dbx/dbml/node_modules/snowflake-sdk/lib/errors.js:536:17)
|
|
106
|
+
at exports.checkArgumentValid (/Users/huylm/code/dbx/dbml/node_modules/snowflake-sdk/lib/errors.js:270:11)
|
|
107
|
+
at consolidateHostAndAccount (/Users/huylm/code/dbx/dbml/node_modules/snowflake-sdk/lib/connection/connection_config.js:82:12)
|
|
108
|
+
at new ConnectionConfig (/Users/huylm/code/dbx/dbml/node_modules/snowflake-sdk/lib/connection/connection_config.js:192:5)
|
|
109
|
+
at createConnection (/Users/huylm/code/dbx/dbml/node_modules/snowflake-sdk/lib/core.js:79:7)
|
|
110
|
+
at Object.createConnection (/Users/huylm/code/dbx/dbml/node_modules/snowflake-sdk/lib/core.js:102:16)
|
|
111
|
+
at connectToSnowflake (/Users/huylm/code/dbx/dbml/packages/dbml-connector/dist/connectors/snowflakeConnector.js:69:48)
|
|
112
|
+
at fetchSchemaJson (/Users/huylm/code/dbx/dbml/packages/dbml-connector/dist/connectors/snowflakeConnector.js:260:24)
|
|
113
|
+
at Object.fetchSchemaJson (/Users/huylm/code/dbx/dbml/packages/dbml-connector/dist/connectors/connector.js:17:61)
|
|
114
|
+
at connectionHandler (/Users/huylm/code/dbx/dbml/packages/dbml-cli/lib/cli/connector.js:24:51)
|
|
115
|
+
|
|
116
|
+
2024-08-27T04:12:47.369Z
|
|
117
|
+
InvalidParameterError: Invalid account. The specified value must be a valid subdomain string.
|
|
118
|
+
at createError (/Users/huylm/code/dbx/dbml/node_modules/snowflake-sdk/lib/errors.js:536:17)
|
|
119
|
+
at exports.checkArgumentValid (/Users/huylm/code/dbx/dbml/node_modules/snowflake-sdk/lib/errors.js:270:11)
|
|
120
|
+
at consolidateHostAndAccount (/Users/huylm/code/dbx/dbml/node_modules/snowflake-sdk/lib/connection/connection_config.js:82:12)
|
|
121
|
+
at new ConnectionConfig (/Users/huylm/code/dbx/dbml/node_modules/snowflake-sdk/lib/connection/connection_config.js:192:5)
|
|
122
|
+
at createConnection (/Users/huylm/code/dbx/dbml/node_modules/snowflake-sdk/lib/core.js:79:7)
|
|
123
|
+
at Object.createConnection (/Users/huylm/code/dbx/dbml/node_modules/snowflake-sdk/lib/core.js:102:16)
|
|
124
|
+
at connectToSnowflake (/Users/huylm/code/dbx/dbml/packages/dbml-connector/dist/connectors/snowflakeConnector.js:69:48)
|
|
125
|
+
at fetchSchemaJson (/Users/huylm/code/dbx/dbml/packages/dbml-connector/dist/connectors/snowflakeConnector.js:261:24)
|
|
126
|
+
at Object.fetchSchemaJson (/Users/huylm/code/dbx/dbml/packages/dbml-connector/dist/connectors/connector.js:17:61)
|
|
127
|
+
at connectionHandler (/Users/huylm/code/dbx/dbml/packages/dbml-cli/lib/cli/connector.js:24:51)
|
|
128
|
+
|
|
129
|
+
2024-08-27T04:13:16.756Z
|
|
130
|
+
Error: Test throw
|
|
131
|
+
at connectToSnowflake (/Users/huylm/code/dbx/dbml/packages/dbml-connector/dist/connectors/snowflakeConnector.js:68:11)
|
|
132
|
+
at fetchSchemaJson (/Users/huylm/code/dbx/dbml/packages/dbml-connector/dist/connectors/snowflakeConnector.js:261:24)
|
|
133
|
+
at Object.fetchSchemaJson (/Users/huylm/code/dbx/dbml/packages/dbml-connector/dist/connectors/connector.js:17:61)
|
|
134
|
+
at connectionHandler (/Users/huylm/code/dbx/dbml/packages/dbml-cli/lib/cli/connector.js:24:51)
|
|
135
|
+
at Object.db2dbml (/Users/huylm/code/dbx/dbml/packages/dbml-cli/lib/cli/index.js:58:26)
|
|
136
|
+
at Object.<anonymous> (/Users/huylm/code/dbx/dbml/packages/dbml-cli/bin/db2dbml.js:4:19)
|
|
137
|
+
at Module._compile (node:internal/modules/cjs/loader:1256:14)
|
|
138
|
+
at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
|
|
139
|
+
at Module.load (node:internal/modules/cjs/loader:1119:32)
|
|
140
|
+
at Module._load (node:internal/modules/cjs/loader:960:12)
|
|
141
|
+
|
package/lib/cli/connector.js
CHANGED
|
@@ -18,10 +18,10 @@ async function connectionHandler(program) {
|
|
|
18
18
|
try {
|
|
19
19
|
const {
|
|
20
20
|
connection,
|
|
21
|
-
|
|
21
|
+
databaseType
|
|
22
22
|
} = (0, _utils.getConnectionOpt)(program.args);
|
|
23
23
|
const opts = program.opts();
|
|
24
|
-
const schemaJson = await _connector.connector.fetchSchemaJson(connection,
|
|
24
|
+
const schemaJson = await _connector.connector.fetchSchemaJson(connection, databaseType);
|
|
25
25
|
if (!opts.outFile && !opts.outDir) {
|
|
26
26
|
const res = _core.importer.generateDbml(schemaJson);
|
|
27
27
|
_outputConsolePlugin.default.write(res);
|
package/lib/cli/index.js
CHANGED
|
@@ -12,6 +12,8 @@ var _export = _interopRequireDefault(require("./export"));
|
|
|
12
12
|
var _connector = _interopRequireDefault(require("./connector"));
|
|
13
13
|
var _package = _interopRequireDefault(require("../../package.json"));
|
|
14
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
+
/* eslint-disable max-len */
|
|
16
|
+
|
|
15
17
|
function showHelp(args) {
|
|
16
18
|
if (args.length < 3) _commander.default.help();
|
|
17
19
|
}
|
|
@@ -35,21 +37,26 @@ function sql2dbml(args) {
|
|
|
35
37
|
}
|
|
36
38
|
function db2dbml(args) {
|
|
37
39
|
_commander.default.version(_package.default.version);
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
// A: The usage description is written in the following way:
|
|
41
|
-
// - <format> your database format (postgres, mysql, mssql)
|
|
42
|
-
// - <connection-string> your database connection string
|
|
43
|
-
// - postgres: postgresql://user:password@localhost:5432/dbname
|
|
44
|
-
// - mssql: 'Server=localhost,1433;Database=master;User Id=sa;Password=your_password;Encrypt=true;TrustServerCertificate
|
|
45
|
-
const description = `
|
|
46
|
-
<format> your database format (postgres, mysql, mssql)
|
|
40
|
+
const description = `Generate DBML directly from a database
|
|
41
|
+
<database-type> your database format (postgres, mysql, mssql, snowflake, bigquery)
|
|
47
42
|
<connection-string> your database connection string:
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
43
|
+
- postgres: 'postgresql://user:password@localhost:5432/dbname?schemas=schema1,schema2,schema3'
|
|
44
|
+
- mysql: 'mysql://user:password@localhost:3306/dbname'
|
|
45
|
+
- mssql: 'Server=localhost,1433;Database=master;User Id=sa;Password=your_password;Encrypt=true;TrustServerCertificate=true;Schemas=schema1,schema2,schema3;'
|
|
46
|
+
- snowflake: 'SERVER=<account_identifier>.<region>;UID=<your_username>;PWD=<your_password>;DATABASE=<your_database>;WAREHOUSE=<your_warehouse>;ROLE=<your_role>;SCHEMAS=schema1,schema2,schema3;'
|
|
47
|
+
- bigquery: /path_to_json_credential.json
|
|
48
|
+
|
|
49
|
+
For BigQuery, your JSON credential file must contain the following keys:
|
|
50
|
+
{
|
|
51
|
+
"project_id": "your-project-id",
|
|
52
|
+
"client_email": "your-client-email",
|
|
53
|
+
"private_key": "your-private-key",
|
|
54
|
+
"datasets": ["dataset_1", "dataset_2", ...]
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
Note: If the "datasets" key is not provided or is an empty array, it will fetch information from all datasets.
|
|
51
58
|
`;
|
|
52
|
-
_commander.default.usage('<
|
|
59
|
+
_commander.default.usage('<database-type> <connection-string> [options]').description(description).option('-o, --out-file <pathspec>', 'compile all input files into a single files');
|
|
53
60
|
showHelp(args);
|
|
54
61
|
_commander.default.parse(args);
|
|
55
62
|
(0, _connector.default)(_commander.default);
|
package/lib/cli/utils.js
CHANGED
|
@@ -38,13 +38,13 @@ function getFormatOpt(opts) {
|
|
|
38
38
|
return format;
|
|
39
39
|
}
|
|
40
40
|
function getConnectionOpt(args) {
|
|
41
|
-
const supportedDatabases = ['postgres', 'mysql', 'mssql'];
|
|
41
|
+
const supportedDatabases = ['postgres', 'mysql', 'mssql', 'snowflake', 'bigquery'];
|
|
42
42
|
const defaultConnectionOpt = {
|
|
43
43
|
connection: args[0],
|
|
44
|
-
|
|
44
|
+
databaseType: 'unknown'
|
|
45
45
|
};
|
|
46
46
|
return (0, _lodash.reduce)(args, (connectionOpt, arg) => {
|
|
47
|
-
if (supportedDatabases.includes(arg)) connectionOpt.
|
|
47
|
+
if (supportedDatabases.includes(arg)) connectionOpt.databaseType = arg;
|
|
48
48
|
// Check if the arg is a connection string using regex
|
|
49
49
|
const connectionStringRegex = /^.*[:;]/;
|
|
50
50
|
if (connectionStringRegex.test(arg)) {
|
|
@@ -52,6 +52,11 @@ function getConnectionOpt(args) {
|
|
|
52
52
|
// Example: odbc:Driver={SQL Server};Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;
|
|
53
53
|
connectionOpt.connection = arg;
|
|
54
54
|
}
|
|
55
|
+
const windowFilepathRegex = /^[a-zA-Z]:[\\/](?:[^<>:"/\\|?*\n\r]+[\\/])*[^<>:"/\\|?*\n\r]*$/;
|
|
56
|
+
const unixFilepathRegex = /^(\/|\.\/|~\/|\.\.\/)([^<>:"|?*\n\r]*\/?)*[^<>:"|?*\n\r]*$/;
|
|
57
|
+
if (windowFilepathRegex.test(arg) || unixFilepathRegex.test(arg)) {
|
|
58
|
+
connectionOpt.connection = arg;
|
|
59
|
+
}
|
|
55
60
|
return connectionOpt;
|
|
56
61
|
}, defaultConnectionOpt);
|
|
57
62
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dbml/cli",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.8.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -26,8 +26,8 @@
|
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@babel/cli": "^7.21.0",
|
|
29
|
-
"@dbml/connector": "^3.
|
|
30
|
-
"@dbml/core": "^3.
|
|
29
|
+
"@dbml/connector": "^3.8.1",
|
|
30
|
+
"@dbml/core": "^3.8.1",
|
|
31
31
|
"bluebird": "^3.5.5",
|
|
32
32
|
"chalk": "^2.4.2",
|
|
33
33
|
"commander": "^2.20.0",
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"^.+\\.js$": "babel-jest"
|
|
56
56
|
}
|
|
57
57
|
},
|
|
58
|
-
"gitHead": "
|
|
58
|
+
"gitHead": "40a25ded1488372f082739f6d43e45f2ad918e7e",
|
|
59
59
|
"engines": {
|
|
60
60
|
"node": ">=18"
|
|
61
61
|
}
|
package/src/cli/connector.js
CHANGED
|
@@ -13,9 +13,9 @@ import logger from '../helpers/logger';
|
|
|
13
13
|
|
|
14
14
|
export default async function connectionHandler (program) {
|
|
15
15
|
try {
|
|
16
|
-
const { connection,
|
|
16
|
+
const { connection, databaseType } = getConnectionOpt(program.args);
|
|
17
17
|
const opts = program.opts();
|
|
18
|
-
const schemaJson = await connector.fetchSchemaJson(connection,
|
|
18
|
+
const schemaJson = await connector.fetchSchemaJson(connection, databaseType);
|
|
19
19
|
|
|
20
20
|
if (!opts.outFile && !opts.outDir) {
|
|
21
21
|
const res = importer.generateDbml(schemaJson);
|
package/src/cli/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/* eslint-disable max-len */
|
|
1
2
|
import program from 'commander';
|
|
2
3
|
import importHandler from './import';
|
|
3
4
|
import exportHandler from './export';
|
|
@@ -49,21 +50,27 @@ function sql2dbml (args) {
|
|
|
49
50
|
function db2dbml (args) {
|
|
50
51
|
program.version(projectInfo.version);
|
|
51
52
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
// - <format> your database format (postgres, mysql, mssql)
|
|
55
|
-
// - <connection-string> your database connection string
|
|
56
|
-
// - postgres: postgresql://user:password@localhost:5432/dbname
|
|
57
|
-
// - mssql: 'Server=localhost,1433;Database=master;User Id=sa;Password=your_password;Encrypt=true;TrustServerCertificate
|
|
58
|
-
const description = `
|
|
59
|
-
<format> your database format (postgres, mysql, mssql)
|
|
53
|
+
const description = `Generate DBML directly from a database
|
|
54
|
+
<database-type> your database format (postgres, mysql, mssql, snowflake, bigquery)
|
|
60
55
|
<connection-string> your database connection string:
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
56
|
+
- postgres: 'postgresql://user:password@localhost:5432/dbname?schemas=schema1,schema2,schema3'
|
|
57
|
+
- mysql: 'mysql://user:password@localhost:3306/dbname'
|
|
58
|
+
- mssql: 'Server=localhost,1433;Database=master;User Id=sa;Password=your_password;Encrypt=true;TrustServerCertificate=true;Schemas=schema1,schema2,schema3;'
|
|
59
|
+
- snowflake: 'SERVER=<account_identifier>.<region>;UID=<your_username>;PWD=<your_password>;DATABASE=<your_database>;WAREHOUSE=<your_warehouse>;ROLE=<your_role>;SCHEMAS=schema1,schema2,schema3;'
|
|
60
|
+
- bigquery: /path_to_json_credential.json
|
|
61
|
+
|
|
62
|
+
For BigQuery, your JSON credential file must contain the following keys:
|
|
63
|
+
{
|
|
64
|
+
"project_id": "your-project-id",
|
|
65
|
+
"client_email": "your-client-email",
|
|
66
|
+
"private_key": "your-private-key",
|
|
67
|
+
"datasets": ["dataset_1", "dataset_2", ...]
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
Note: If the "datasets" key is not provided or is an empty array, it will fetch information from all datasets.
|
|
64
71
|
`;
|
|
65
72
|
program
|
|
66
|
-
.usage('<
|
|
73
|
+
.usage('<database-type> <connection-string> [options]')
|
|
67
74
|
.description(description)
|
|
68
75
|
.option('-o, --out-file <pathspec>', 'compile all input files into a single files');
|
|
69
76
|
|
package/src/cli/utils.js
CHANGED
|
@@ -34,14 +34,14 @@ function getFormatOpt (opts) {
|
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
function getConnectionOpt (args) {
|
|
37
|
-
const supportedDatabases = ['postgres', 'mysql', 'mssql'];
|
|
37
|
+
const supportedDatabases = ['postgres', 'mysql', 'mssql', 'snowflake', 'bigquery'];
|
|
38
38
|
const defaultConnectionOpt = {
|
|
39
39
|
connection: args[0],
|
|
40
|
-
|
|
40
|
+
databaseType: 'unknown',
|
|
41
41
|
};
|
|
42
42
|
|
|
43
43
|
return reduce(args, (connectionOpt, arg) => {
|
|
44
|
-
if (supportedDatabases.includes(arg)) connectionOpt.
|
|
44
|
+
if (supportedDatabases.includes(arg)) connectionOpt.databaseType = arg;
|
|
45
45
|
// Check if the arg is a connection string using regex
|
|
46
46
|
const connectionStringRegex = /^.*[:;]/;
|
|
47
47
|
if (connectionStringRegex.test(arg)) {
|
|
@@ -50,6 +50,13 @@ function getConnectionOpt (args) {
|
|
|
50
50
|
connectionOpt.connection = arg;
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
+
const windowFilepathRegex = /^[a-zA-Z]:[\\/](?:[^<>:"/\\|?*\n\r]+[\\/])*[^<>:"/\\|?*\n\r]*$/;
|
|
54
|
+
const unixFilepathRegex = /^(\/|\.\/|~\/|\.\.\/)([^<>:"|?*\n\r]*\/?)*[^<>:"|?*\n\r]*$/;
|
|
55
|
+
|
|
56
|
+
if (windowFilepathRegex.test(arg) || unixFilepathRegex.test(arg)) {
|
|
57
|
+
connectionOpt.connection = arg;
|
|
58
|
+
}
|
|
59
|
+
|
|
53
60
|
return connectionOpt;
|
|
54
61
|
}, defaultConnectionOpt);
|
|
55
62
|
}
|