dbdocs 0.11.0 → 0.12.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/README.md CHANGED
@@ -1,8 +1,6 @@
1
1
  dbdocs
2
2
  ======
3
3
 
4
-
5
-
6
4
  [![oclif](https://img.shields.io/badge/cli-oclif-brightgreen.svg)](https://oclif.io)
7
5
  [![Version](https://img.shields.io/npm/v/dbdocs.svg)](https://npmjs.org/package/dbdocs)
8
6
  [![Downloads/week](https://img.shields.io/npm/dw/dbdocs.svg)](https://npmjs.org/package/dbdocs)
@@ -12,6 +10,7 @@ dbdocs
12
10
  * [Usage](#usage)
13
11
  * [Commands](#commands)
14
12
  <!-- tocstop -->
13
+
15
14
  # Usage
16
15
  <!-- usage -->
17
16
  ```sh-session
@@ -29,7 +28,7 @@ USAGE
29
28
  # Commands
30
29
  <!-- commands -->
31
30
  * [`dbdocs build [FILEPATH]`](#dbdocs-build-filepath)
32
- * [`dbdocs db2dbml [FORMAT] [CONNECTION-STRING`](#dbdocs-db2dbml-format-connection-string)
31
+ * [`dbdocs db2dbml [DATABASE-TYPE] [CONNECTION-STRING`](#dbdocs-db2dbml-database-type-connection-string)
33
32
  * [`dbdocs help [COMMAND]`](#dbdocs-help-command)
34
33
  * [`dbdocs login`](#dbdocs-login)
35
34
  * [`dbdocs logout`](#dbdocs-logout)
@@ -44,7 +43,7 @@ USAGE
44
43
 
45
44
  build docs
46
45
 
47
- ```
46
+ ```bash
48
47
  USAGE
49
48
  $ dbdocs build [FILEPATH]
50
49
 
@@ -56,20 +55,17 @@ OPTIONS
56
55
  --project=project project name
57
56
  ```
58
57
 
59
- ## `dbdocs db2dbml [FORMAT] [CONNECTION-STRING]`
58
+ ## `dbdocs db2dbml [DATABASE-TYPE] [CONNECTION-STRING]`
60
59
 
61
60
  Generate DBML directly from a database
62
61
 
63
62
  ```bash
64
63
  USAGE
65
- $ dbdocs db2dbml [FORMAT] [CONNECTION-STRING] [-o <value>]
64
+ $ dbdocs db2dbml [DATABASE-TYPE] [CONNECTION-STRING] [-o <value>]
66
65
 
67
66
  ARGUMENTS
68
- FORMAT your database format (postgres, mysql, mssql)
69
- CONNECTION-STRING your database connection string:
70
- - postgres: postgresql://user:password@localhost:5432/dbname
71
- - mysql: mysql://user:password@localhost:3306/dbname
72
- - mssql: 'Server=localhost,1433;Database=master;User Id=sa;Password=your_password;Encrypt=true;TrustServerCertificate=true;'
67
+ DATABASE-TYPE your database type (postgres, mysql, mssql, snowflake, bigquery)
68
+ CONNECTION-STRING your database connection string (See below examples for more details)
73
69
 
74
70
  FLAGS
75
71
  -o, --outFile=/path-to-your-file output file path
@@ -77,13 +73,37 @@ FLAGS
77
73
  DESCRIPTION
78
74
  Generate DBML directly from a database
79
75
 
76
+ EXAMPLES
77
+ Postgres:
78
+ $ db2dbml postgres 'postgresql://user:password@localhost:5432/dbname?schemas=schema1,schema2'
79
+
80
+ MySQL:
81
+ $ db2dbml mysql 'mysql://user:password@localhost:3306/dbname'
82
+
83
+ MSSQL:
84
+ $ db2dbml mssql 'Server=localhost,1433;Database=master;User Id=sa;Password=your_password;Encrypt=true;TrustServerCertificate=true;Schemas=schema1,schema2;'
85
+
86
+ Snowflake:
87
+ $ db2dbml snowflake 'SERVER=<account_identifier>.<region>;UID=<your_username>;PWD=<your_password>;DATABASE=<your_database>;WAREHOUSE=<your_warehouse>;ROLE=<your_role>;SCHEMAS=schema1,schema2;'
88
+
89
+ BigQuery:
90
+ $ db2dbml bigquery /path_to_json_credential.json
91
+
92
+ Note: Your JSON credential file must contain:
93
+ {
94
+ "project_id": "your-project-id",
95
+ "client_email": "your-client-email",
96
+ "private_key": "your-private-key",
97
+ "datasets": ["dataset_1", "dataset_2", ...]
98
+ }
99
+ If "datasets" key is not provided or is empty, it will fetch all datasets.
80
100
  ```
81
101
 
82
102
  ## `dbdocs help [COMMAND]`
83
103
 
84
104
  display help for dbdocs
85
105
 
86
- ```
106
+ ```bash
87
107
  USAGE
88
108
  $ dbdocs help [COMMAND]
89
109
 
@@ -98,7 +118,7 @@ OPTIONS
98
118
 
99
119
  login to dbdocs
100
120
 
101
- ```
121
+ ```bash
102
122
  USAGE
103
123
  $ dbdocs login
104
124
 
@@ -110,7 +130,7 @@ DESCRIPTION
110
130
 
111
131
  logout
112
132
 
113
- ```
133
+ ```bash
114
134
  USAGE
115
135
  $ dbdocs logout
116
136
 
@@ -122,7 +142,7 @@ DESCRIPTION
122
142
 
123
143
  list projects
124
144
 
125
- ```
145
+ ```bash
126
146
  USAGE
127
147
  $ dbdocs ls
128
148
 
@@ -134,7 +154,7 @@ DESCRIPTION
134
154
 
135
155
  set password for your project or remove password
136
156
 
137
- ```
157
+ ```bash
138
158
  USAGE
139
159
  $ dbdocs password
140
160
 
@@ -148,7 +168,7 @@ OPTIONS
148
168
 
149
169
  remove project
150
170
 
151
- ```
171
+ ```bash
152
172
  USAGE
153
173
  $ dbdocs remove [PROJECT_NAME]
154
174
 
@@ -160,7 +180,7 @@ ARGUMENTS
160
180
 
161
181
  change your username
162
182
 
163
- ```
183
+ ```bash
164
184
  USAGE
165
185
  $ dbdocs rename
166
186
 
@@ -172,7 +192,7 @@ DESCRIPTION
172
192
 
173
193
  generate or revoke your authentication token
174
194
 
175
- ```
195
+ ```bash
176
196
  USAGE
177
197
  $ dbdocs token
178
198
 
@@ -185,7 +205,7 @@ OPTIONS
185
205
 
186
206
  validate docs content
187
207
 
188
- ```
208
+ ```bash
189
209
  USAGE
190
210
  $ dbdocs validate [FILEPATH]
191
211
 
@@ -1 +1 @@
1
- {"version":"0.11.0","commands":{"build":{"id":"build","description":"build docs","strict":true,"pluginName":"dbdocs","pluginAlias":"dbdocs","pluginType":"core","aliases":[],"flags":{"project":{"name":"project","type":"option","description":"project name","multiple":false},"public":{"name":"public","type":"boolean","description":"anyone with the URL can access","helpGroup":"sharing","allowNo":false,"exclusive":["private","password"]},"private":{"name":"private","type":"boolean","description":"only invited people can access","helpGroup":"sharing","allowNo":false,"exclusive":["public","password"]},"password":{"name":"password","type":"option","char":"p","description":"anyone with the URL + password can access","helpGroup":"sharing","multiple":false,"exclusive":["public","private"]}},"args":[{"name":"filepath","description":"dbml file path"}]},"db2dbml":{"id":"db2dbml","description":"Generate DBML directly from a database","strict":true,"pluginName":"dbdocs","pluginAlias":"dbdocs","pluginType":"core","aliases":[],"flags":{"outFile":{"name":"outFile","type":"option","char":"o","description":"output file path","helpValue":"/path-to-your-file","multiple":false}},"args":[{"name":"format","description":"your database format (postgres, mysql, mssql)","required":true},{"name":"connection-string","description":"your database connection string:\n - postgres: postgresql://user:password@localhost:5432/dbname\n - mysql: mysql://user:password@localhost:3306/dbname\n - mssql: 'Server=localhost,1433;Database=master;User Id=sa;Password=your_password;Encrypt=true;TrustServerCertificate=true;'","required":true}]},"login":{"id":"login","description":"login to dbdocs\nlogin with your dbdocs credentials\n","strict":true,"pluginName":"dbdocs","pluginAlias":"dbdocs","pluginType":"core","aliases":[],"flags":{},"args":[]},"logout":{"id":"logout","description":"logout\nclears local login credentials\n","strict":true,"pluginName":"dbdocs","pluginAlias":"dbdocs","pluginType":"core","aliases":[],"flags":{},"args":[]},"ls":{"id":"ls","description":"list projects","strict":true,"pluginName":"dbdocs","pluginAlias":"dbdocs","pluginType":"core","aliases":[],"flags":{},"args":[]},"password":{"id":"password","description":"set password for your project or remove password","strict":true,"pluginName":"dbdocs","pluginAlias":"dbdocs","pluginType":"core","aliases":[],"flags":{"project":{"name":"project","type":"option","char":"p","description":"project name","helpValue":"project name","multiple":false},"set":{"name":"set","type":"option","char":"s","description":"password for your project","helpValue":"password","multiple":false},"remove":{"name":"remove","type":"boolean","char":"r","description":"remove password from your project","allowNo":false}},"args":[]},"remove":{"id":"remove","description":"remove project","strict":true,"pluginName":"dbdocs","pluginAlias":"dbdocs","pluginType":"core","aliases":[],"flags":{},"args":[{"name":"project_name","description":"name of the project which you want to remove"}]},"rename":{"id":"rename","description":"change your username","strict":true,"pluginName":"dbdocs","pluginAlias":"dbdocs","pluginType":"core","aliases":[],"flags":{},"args":[]},"token":{"id":"token","description":"generate or revoke your authentication token","strict":true,"pluginName":"dbdocs","pluginAlias":"dbdocs","pluginType":"core","aliases":[],"flags":{"generate":{"name":"generate","type":"boolean","char":"g","description":"generate authentication token","allowNo":false},"revoke":{"name":"revoke","type":"boolean","char":"r","description":"revoke authentication token","allowNo":false}},"args":[]},"validate":{"id":"validate","description":"validate docs content","strict":true,"pluginName":"dbdocs","pluginAlias":"dbdocs","pluginType":"core","aliases":[],"flags":{},"args":[{"name":"filepath","description":"dbml file path"}]}}}
1
+ {"version":"0.12.0","commands":{"build":{"id":"build","description":"build docs","strict":true,"pluginName":"dbdocs","pluginAlias":"dbdocs","pluginType":"core","aliases":[],"flags":{"project":{"name":"project","type":"option","description":"project name","multiple":false},"public":{"name":"public","type":"boolean","description":"anyone with the URL can access","helpGroup":"sharing","allowNo":false,"exclusive":["private","password"]},"private":{"name":"private","type":"boolean","description":"only invited people can access","helpGroup":"sharing","allowNo":false,"exclusive":["public","password"]},"password":{"name":"password","type":"option","char":"p","description":"anyone with the URL + password can access","helpGroup":"sharing","multiple":false,"exclusive":["public","private"]}},"args":[{"name":"filepath","description":"dbml file path"}]},"db2dbml":{"id":"db2dbml","description":"Generate DBML directly from a database","strict":true,"pluginName":"dbdocs","pluginAlias":"dbdocs","pluginType":"core","aliases":[],"examples":"Postgres:\n $ db2dbml postgres 'postgresql://user:password@localhost:5432/dbname?schemas=schema1,schema2'\nMySQL:\n $ db2dbml mysql 'mysql://user:password@localhost:3306/dbname'\nMSSQL:\n $ db2dbml mssql 'Server=localhost,1433;Database=master;User Id=sa;Password=your_password;Encrypt=true;TrustServerCertificate=true;Schemas=schema1,schema2;'\nSnowflake:\n $ db2dbml snowflake 'SERVER=<account_identifier>.<region>;UID=<your_username>;PWD=<your_password>;DATABASE=<your_database>;WAREHOUSE=<your_warehouse>;ROLE=<your_role>;SCHEMAS=schema1,schema2;'\nBigQuery:\n $ db2dbml bigquery /path_to_json_credential.json\n \n Note: Your JSON credential file must contain:\n {\n \"project_id\": \"your-project-id\",\n \"client_email\": \"your-client-email\",\n \"private_key\": \"your-private-key\",\n \"datasets\": [\"dataset_1\", \"dataset_2\", ...]\n }\n If \"datasets\" key is not provided or is empty, it will fetch all datasets.","flags":{"outFile":{"name":"outFile","type":"option","char":"o","description":"output file path","helpValue":"/path-to-your-file","multiple":false}},"args":[{"name":"database-type","description":"your database type (postgres, mysql, mssql, snowflake, bigquery)","required":true},{"name":"connection-string","description":"your database connection string (See below examples for more details)","required":true}]},"login":{"id":"login","description":"login to dbdocs\nlogin with your dbdocs credentials\n","strict":true,"pluginName":"dbdocs","pluginAlias":"dbdocs","pluginType":"core","aliases":[],"flags":{},"args":[]},"logout":{"id":"logout","description":"logout\nclears local login credentials\n","strict":true,"pluginName":"dbdocs","pluginAlias":"dbdocs","pluginType":"core","aliases":[],"flags":{},"args":[]},"ls":{"id":"ls","description":"list projects","strict":true,"pluginName":"dbdocs","pluginAlias":"dbdocs","pluginType":"core","aliases":[],"flags":{},"args":[]},"password":{"id":"password","description":"set password for your project or remove password","strict":true,"pluginName":"dbdocs","pluginAlias":"dbdocs","pluginType":"core","aliases":[],"flags":{"project":{"name":"project","type":"option","char":"p","description":"project name","helpValue":"project name","multiple":false},"set":{"name":"set","type":"option","char":"s","description":"password for your project","helpValue":"password","multiple":false},"remove":{"name":"remove","type":"boolean","char":"r","description":"remove password from your project","allowNo":false}},"args":[]},"remove":{"id":"remove","description":"remove project","strict":true,"pluginName":"dbdocs","pluginAlias":"dbdocs","pluginType":"core","aliases":[],"flags":{},"args":[{"name":"project_name","description":"name of the project which you want to remove"}]},"rename":{"id":"rename","description":"change your username","strict":true,"pluginName":"dbdocs","pluginAlias":"dbdocs","pluginType":"core","aliases":[],"flags":{},"args":[]},"token":{"id":"token","description":"generate or revoke your authentication token","strict":true,"pluginName":"dbdocs","pluginAlias":"dbdocs","pluginType":"core","aliases":[],"flags":{"generate":{"name":"generate","type":"boolean","char":"g","description":"generate authentication token","allowNo":false},"revoke":{"name":"revoke","type":"boolean","char":"r","description":"revoke authentication token","allowNo":false}},"args":[]},"validate":{"id":"validate","description":"validate docs content","strict":true,"pluginName":"dbdocs","pluginAlias":"dbdocs","pluginType":"core","aliases":[],"flags":{},"args":[{"name":"filepath","description":"dbml file path"}]}}}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dbdocs",
3
- "version": "0.11.0",
3
+ "version": "0.12.0",
4
4
  "author": "@holistics",
5
5
  "bin": {
6
6
  "dbdocs": "./bin/run"
@@ -9,11 +9,11 @@
9
9
  "oclif/**/ansi-regex": "^3.0.1"
10
10
  },
11
11
  "dependencies": {
12
- "@dbml/connector": "^3.7.2",
13
- "@dbml/core": "3.7.2",
12
+ "@dbml/connector": "3.8.0",
13
+ "@dbml/core": "3.8.0",
14
14
  "@oclif/core": "1.12.1",
15
15
  "@oclif/plugin-help": "5.1.12",
16
- "axios": "1.6.0",
16
+ "axios": "^1.7.4",
17
17
  "chalk": "^3.0.0",
18
18
  "dotenv": "^8.2.0",
19
19
  "inquirer": "^7.0.1",
@@ -1,11 +1,11 @@
1
- /* eslint-disable import/no-extraneous-dependencies */
1
+ /* eslint-disable max-len */
2
2
  /* eslint-disable no-use-before-define */
3
3
  /* eslint-disable no-param-reassign */
4
4
  const { Command, Flags } = require('@oclif/core');
5
5
  const { importer } = require('@dbml/core');
6
6
  const { connector } = require('@dbml/connector');
7
7
  const ora = require('ora');
8
- const { SUPPORTED_DATABASE_CONNECTORS } = require('../utils/constants');
8
+ const { SUPPORTED_DATABASE_CONNECTORS, WINDOW_FILE_PATH_REGEX, UNIX_FILE_PATH_REGEX } = require('../utils/constants');
9
9
  const { writeToConsole, writeToFileAsync } = require('../utils/output-writer');
10
10
 
11
11
  class Db2dbmlCommand extends Command {
@@ -14,12 +14,12 @@ class Db2dbmlCommand extends Command {
14
14
 
15
15
  try {
16
16
  const { flags, argv } = await this.parse(Db2dbmlCommand);
17
- const { format, connection } = getConnectionOpt(argv);
17
+ const { databaseType, connection } = getConnectionOpt(argv);
18
18
 
19
19
  spinner.text = 'Connecting to database...';
20
20
  spinner.start();
21
21
 
22
- const schemaJson = await connector.fetchSchemaJson(connection, format);
22
+ const schemaJson = await connector.fetchSchemaJson(connection, databaseType);
23
23
  spinner.succeed('Connecting to database... done.');
24
24
 
25
25
  spinner.start('Generating DBML ...');
@@ -50,16 +50,13 @@ Db2dbmlCommand.description = 'Generate DBML directly from a database';
50
50
 
51
51
  Db2dbmlCommand.args = [
52
52
  {
53
- name: 'format',
54
- description: 'your database format (postgres, mysql, mssql)',
53
+ name: 'database-type',
54
+ description: 'your database type (postgres, mysql, mssql, snowflake, bigquery)',
55
55
  required: true,
56
56
  },
57
57
  {
58
58
  name: 'connection-string',
59
- description: `your database connection string:
60
- - postgres: postgresql://user:password@localhost:5432/dbname
61
- - mysql: mysql://user:password@localhost:3306/dbname
62
- - mssql: 'Server=localhost,1433;Database=master;User Id=sa;Password=your_password;Encrypt=true;TrustServerCertificate=true;'`,
59
+ description: 'your database connection string (See below examples for more details)',
63
60
  required: true,
64
61
  },
65
62
  ];
@@ -72,19 +69,41 @@ Db2dbmlCommand.flags = {
72
69
  }),
73
70
  };
74
71
 
72
+ Db2dbmlCommand.examples = [
73
+ 'Postgres:',
74
+ " $ db2dbml postgres 'postgresql://user:password@localhost:5432/dbname?schemas=schema1,schema2'",
75
+ 'MySQL:',
76
+ " $ db2dbml mysql 'mysql://user:password@localhost:3306/dbname'",
77
+ 'MSSQL:',
78
+ " $ db2dbml mssql 'Server=localhost,1433;Database=master;User Id=sa;Password=your_password;Encrypt=true;TrustServerCertificate=true;Schemas=schema1,schema2;'",
79
+ 'Snowflake:',
80
+ " $ db2dbml snowflake 'SERVER=<account_identifier>.<region>;UID=<your_username>;PWD=<your_password>;DATABASE=<your_database>;WAREHOUSE=<your_warehouse>;ROLE=<your_role>;SCHEMAS=schema1,schema2;'",
81
+ 'BigQuery:',
82
+ ' $ db2dbml bigquery /path_to_json_credential.json',
83
+ ' ',
84
+ ' Note: Your JSON credential file must contain:',
85
+ ' {',
86
+ ' "project_id": "your-project-id",',
87
+ ' "client_email": "your-client-email",',
88
+ ' "private_key": "your-private-key",',
89
+ ' "datasets": ["dataset_1", "dataset_2", ...]',
90
+ ' }',
91
+ ' If "datasets" key is not provided or is empty, it will fetch all datasets.',
92
+ ].join('\n');
93
+
75
94
  /**
76
95
  * @param {string[]} argv
77
96
  * @returns {{ format: string, connection: string}}
78
97
  */
79
98
  function getConnectionOpt (argv) {
80
99
  const defaultConnectionOpt = {
81
- format: 'unknown',
82
- connection: argv[1],
100
+ connection: argv[0],
101
+ databaseType: 'unknown',
83
102
  };
84
103
 
85
104
  const options = argv.reduce((connectionOpt, arg) => {
86
105
  if (SUPPORTED_DATABASE_CONNECTORS.includes(arg)) {
87
- connectionOpt.format = arg;
106
+ connectionOpt.databaseType = arg;
88
107
  }
89
108
 
90
109
  // Check if the arg is a connection string using regex
@@ -95,6 +114,11 @@ function getConnectionOpt (argv) {
95
114
  connectionOpt.connection = arg;
96
115
  }
97
116
 
117
+ // check if the arg is a valid path to credential json file
118
+ if (WINDOW_FILE_PATH_REGEX.test(arg) || UNIX_FILE_PATH_REGEX.test(arg)) {
119
+ connectionOpt.connection = arg;
120
+ }
121
+
98
122
  return connectionOpt;
99
123
  }, defaultConnectionOpt);
100
124
 
@@ -19,7 +19,24 @@ const LOGIN_METHODS = {
19
19
  GITHUB_GOOGLE: 'GitHub/Google',
20
20
  };
21
21
 
22
- const SUPPORTED_DATABASE_CONNECTORS = ['postgres', 'mysql', 'mssql'];
22
+ const SUPPORTED_DATABASE_CONNECTORS = ['postgres', 'mysql', 'mssql', 'snowflake', 'bigquery'];
23
+
24
+ /**
25
+ * Match window path
26
+ * Eg:
27
+ * - C:\Documents\code\credential.json
28
+ * - C:/Documents/code/credential.json
29
+ */
30
+ const WINDOW_FILE_PATH_REGEX = /^[a-zA-Z]:[\\/](?:[^<>:"/\\|?*\n\r]+[\\/])*[^<>:"/\\|?*\n\r]*$/;
31
+
32
+ /**
33
+ * Match unix system path
34
+ * Eg:
35
+ * - /Users/dev/code/credential.json
36
+ * - ~/code/credential.json
37
+ * - ./code/credential.json
38
+ */
39
+ const UNIX_FILE_PATH_REGEX = /^[a-zA-Z]:[\\/](?:[^<>:"/\\|?*\n\r]+[\\/])*[^<>:"/\\|?*\n\r]*$/;
23
40
 
24
41
  module.exports = {
25
42
  PROJECT_GENERAL_ACCESS_TYPE,
@@ -27,4 +44,6 @@ module.exports = {
27
44
  FLAG_HELP_GROUP,
28
45
  LOGIN_METHODS,
29
46
  SUPPORTED_DATABASE_CONNECTORS,
47
+ WINDOW_FILE_PATH_REGEX,
48
+ UNIX_FILE_PATH_REGEX,
30
49
  };