dbdocs 0.11.1 → 0.12.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/README.md +36 -20
- package/oclif.manifest.json +1 -1
- package/package.json +3 -3
- package/src/commands/db2dbml.js +37 -13
- package/src/utils/constants.js +20 -1
package/README.md
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
dbdocs
|
|
2
2
|
======
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
4
|
[](https://oclif.io)
|
|
7
5
|
[](https://npmjs.org/package/dbdocs)
|
|
8
6
|
[](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 [
|
|
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 [
|
|
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 [
|
|
64
|
+
$ dbdocs db2dbml [DATABASE-TYPE] [CONNECTION-STRING] [-o <value>]
|
|
66
65
|
|
|
67
66
|
ARGUMENTS
|
|
68
|
-
|
|
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,33 @@ 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
|
+
MySQL:
|
|
80
|
+
$ db2dbml mysql 'mysql://user:password@localhost:3306/dbname'
|
|
81
|
+
MSSQL:
|
|
82
|
+
$ db2dbml mssql 'Server=localhost,1433;Database=master;User Id=sa;Password=your_password;Encrypt=true;TrustServerCertificate=true;Schemas=schema1,schema2;'
|
|
83
|
+
Snowflake:
|
|
84
|
+
$ db2dbml snowflake 'SERVER=<account_identifier>.<region>;UID=<your_username>;PWD=<your_password>;DATABASE=<your_database>;WAREHOUSE=<your_warehouse>;ROLE=<your_role>;SCHEMAS=schema1,schema2;'
|
|
85
|
+
BigQuery:
|
|
86
|
+
$ db2dbml bigquery /path_to_json_credential.json
|
|
87
|
+
|
|
88
|
+
Note: Your JSON credential file must contain:
|
|
89
|
+
{
|
|
90
|
+
"project_id": "your-project-id",
|
|
91
|
+
"client_email": "your-client-email",
|
|
92
|
+
"private_key": "your-private-key",
|
|
93
|
+
"datasets": ["dataset_1", "dataset_2", ...]
|
|
94
|
+
}
|
|
95
|
+
If "datasets" key is not provided or is empty, it will fetch all datasets.
|
|
80
96
|
```
|
|
81
97
|
|
|
82
98
|
## `dbdocs help [COMMAND]`
|
|
83
99
|
|
|
84
100
|
display help for dbdocs
|
|
85
101
|
|
|
86
|
-
```
|
|
102
|
+
```bash
|
|
87
103
|
USAGE
|
|
88
104
|
$ dbdocs help [COMMAND]
|
|
89
105
|
|
|
@@ -98,7 +114,7 @@ OPTIONS
|
|
|
98
114
|
|
|
99
115
|
login to dbdocs
|
|
100
116
|
|
|
101
|
-
```
|
|
117
|
+
```bash
|
|
102
118
|
USAGE
|
|
103
119
|
$ dbdocs login
|
|
104
120
|
|
|
@@ -110,7 +126,7 @@ DESCRIPTION
|
|
|
110
126
|
|
|
111
127
|
logout
|
|
112
128
|
|
|
113
|
-
```
|
|
129
|
+
```bash
|
|
114
130
|
USAGE
|
|
115
131
|
$ dbdocs logout
|
|
116
132
|
|
|
@@ -122,7 +138,7 @@ DESCRIPTION
|
|
|
122
138
|
|
|
123
139
|
list projects
|
|
124
140
|
|
|
125
|
-
```
|
|
141
|
+
```bash
|
|
126
142
|
USAGE
|
|
127
143
|
$ dbdocs ls
|
|
128
144
|
|
|
@@ -134,7 +150,7 @@ DESCRIPTION
|
|
|
134
150
|
|
|
135
151
|
set password for your project or remove password
|
|
136
152
|
|
|
137
|
-
```
|
|
153
|
+
```bash
|
|
138
154
|
USAGE
|
|
139
155
|
$ dbdocs password
|
|
140
156
|
|
|
@@ -148,7 +164,7 @@ OPTIONS
|
|
|
148
164
|
|
|
149
165
|
remove project
|
|
150
166
|
|
|
151
|
-
```
|
|
167
|
+
```bash
|
|
152
168
|
USAGE
|
|
153
169
|
$ dbdocs remove [PROJECT_NAME]
|
|
154
170
|
|
|
@@ -160,7 +176,7 @@ ARGUMENTS
|
|
|
160
176
|
|
|
161
177
|
change your username
|
|
162
178
|
|
|
163
|
-
```
|
|
179
|
+
```bash
|
|
164
180
|
USAGE
|
|
165
181
|
$ dbdocs rename
|
|
166
182
|
|
|
@@ -172,7 +188,7 @@ DESCRIPTION
|
|
|
172
188
|
|
|
173
189
|
generate or revoke your authentication token
|
|
174
190
|
|
|
175
|
-
```
|
|
191
|
+
```bash
|
|
176
192
|
USAGE
|
|
177
193
|
$ dbdocs token
|
|
178
194
|
|
|
@@ -185,7 +201,7 @@ OPTIONS
|
|
|
185
201
|
|
|
186
202
|
validate docs content
|
|
187
203
|
|
|
188
|
-
```
|
|
204
|
+
```bash
|
|
189
205
|
USAGE
|
|
190
206
|
$ dbdocs validate [FILEPATH]
|
|
191
207
|
|
package/oclif.manifest.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":"0.
|
|
1
|
+
{"version":"0.12.1","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.
|
|
3
|
+
"version": "0.12.1",
|
|
4
4
|
"author": "@holistics",
|
|
5
5
|
"bin": {
|
|
6
6
|
"dbdocs": "./bin/run"
|
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
"oclif/**/ansi-regex": "^3.0.1"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@dbml/connector": "
|
|
13
|
-
"@dbml/core": "3.
|
|
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
16
|
"axios": "^1.7.4",
|
package/src/commands/db2dbml.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
/* eslint-disable
|
|
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 {
|
|
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,
|
|
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: '
|
|
54
|
-
description: 'your database
|
|
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:
|
|
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
|
-
|
|
82
|
-
|
|
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.
|
|
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
|
|
package/src/utils/constants.js
CHANGED
|
@@ -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 = /^(\/|\.\/|~\/|\.\.\/)([^<>:"|?*\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
|
};
|