@dbml/cli 3.7.3 → 3.8.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/dbml-error.log CHANGED
@@ -51,3 +51,91 @@ TypeError [ERR_INVALID_URL]: Invalid URL
51
51
  at tryCatch (/Users/huylm/code/dbx/dbml/packages/dbml-core/lib/connectors/mysqlConnector.js:14:1357)
52
52
  at Generator.<anonymous> (/Users/huylm/code/dbx/dbml/packages/dbml-core/lib/connectors/mysqlConnector.js:14:4174)
53
53
 
54
+ 2024-08-25T16:18:11.612Z
55
+ Error: Load credential error: ENOENT: no such file or directory, open 'bigquery'
56
+ at loadCredentialFromFile (/Users/huylm/code/dbx/dbml/packages/dbml-connector/dist/connectors/utils/credential-loader.js:13:19)
57
+ at async fetchSchemaJson (/Users/huylm/code/dbx/dbml/packages/dbml-connector/dist/connectors/bigqueryConnector.js:256:27)
58
+ at async connectionHandler (/Users/huylm/code/dbx/dbml/packages/dbml-cli/lib/cli/connector.js:24:24)
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
+
@@ -18,10 +18,10 @@ async function connectionHandler(program) {
18
18
  try {
19
19
  const {
20
20
  connection,
21
- format
21
+ databaseType
22
22
  } = (0, _utils.getConnectionOpt)(program.args);
23
23
  const opts = program.opts();
24
- const schemaJson = await _connector.connector.fetchSchemaJson(connection, format);
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
- // Q: How to write the arguments description for the below usage?
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
- - postgres: postgresql://user:password@localhost:5432/dbname
49
- - mysql: mysql://user:password@localhost:3306/dbname
50
- - mssql: 'Server=localhost,1433;Database=master;User Id=sa;Password=your_password;Encrypt=true;TrustServerCertificate=true;'
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('<format> <connection-string> [options]').description(description).option('-o, --out-file <pathspec>', 'compile all input files into a single files');
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
- format: 'unknown'
44
+ databaseType: 'unknown'
45
45
  };
46
46
  return (0, _lodash.reduce)(args, (connectionOpt, arg) => {
47
- if (supportedDatabases.includes(arg)) connectionOpt.format = arg;
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.7.3",
3
+ "version": "3.8.0",
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.7.3",
30
- "@dbml/core": "^3.7.3",
29
+ "@dbml/connector": "^3.8.0",
30
+ "@dbml/core": "^3.8.0",
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": "b9e7ed2421f83872b3319510155225a228d3e75e",
58
+ "gitHead": "f106540bc455695c8a4c91ed63aa8fabc8ce645a",
59
59
  "engines": {
60
60
  "node": ">=18"
61
61
  }
@@ -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, format } = getConnectionOpt(program.args);
16
+ const { connection, databaseType } = getConnectionOpt(program.args);
17
17
  const opts = program.opts();
18
- const schemaJson = await connector.fetchSchemaJson(connection, format);
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
- // Q: How to write the arguments description for the below usage?
53
- // A: The usage description is written in the following way:
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
- - postgres: postgresql://user:password@localhost:5432/dbname
62
- - mysql: mysql://user:password@localhost:3306/dbname
63
- - mssql: 'Server=localhost,1433;Database=master;User Id=sa;Password=your_password;Encrypt=true;TrustServerCertificate=true;'
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('<format> <connection-string> [options]')
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
- format: 'unknown',
40
+ databaseType: 'unknown',
41
41
  };
42
42
 
43
43
  return reduce(args, (connectionOpt, arg) => {
44
- if (supportedDatabases.includes(arg)) connectionOpt.format = arg;
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
  }