dbdocs 0.10.0 → 0.11.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 +24 -0
- package/oclif.manifest.json +1 -1
- package/package.json +4 -3
- package/src/commands/db2dbml.js +104 -0
- package/src/commands/validate.js +1 -1
- package/src/utils/constants.js +3 -0
- package/src/utils/output-writer.js +25 -0
package/README.md
CHANGED
|
@@ -29,6 +29,7 @@ USAGE
|
|
|
29
29
|
# Commands
|
|
30
30
|
<!-- commands -->
|
|
31
31
|
* [`dbdocs build [FILEPATH]`](#dbdocs-build-filepath)
|
|
32
|
+
* [`dbdocs db2dbml [FORMAT] [CONNECTION-STRING`](#dbdocs-db2dbml-format-connection-string)
|
|
32
33
|
* [`dbdocs help [COMMAND]`](#dbdocs-help-command)
|
|
33
34
|
* [`dbdocs login`](#dbdocs-login)
|
|
34
35
|
* [`dbdocs logout`](#dbdocs-logout)
|
|
@@ -55,6 +56,29 @@ OPTIONS
|
|
|
55
56
|
--project=project project name
|
|
56
57
|
```
|
|
57
58
|
|
|
59
|
+
## `dbdocs db2dbml [FORMAT] [CONNECTION-STRING]`
|
|
60
|
+
|
|
61
|
+
Generate DBML directly from a database
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
USAGE
|
|
65
|
+
$ dbdocs db2dbml [FORMAT] [CONNECTION-STRING] [-o <value>]
|
|
66
|
+
|
|
67
|
+
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;'
|
|
73
|
+
|
|
74
|
+
FLAGS
|
|
75
|
+
-o, --outFile=/path-to-your-file output file path
|
|
76
|
+
|
|
77
|
+
DESCRIPTION
|
|
78
|
+
Generate DBML directly from a database
|
|
79
|
+
|
|
80
|
+
```
|
|
81
|
+
|
|
58
82
|
## `dbdocs help [COMMAND]`
|
|
59
83
|
|
|
60
84
|
display help for dbdocs
|
package/oclif.manifest.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":"0.
|
|
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"}]}}}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dbdocs",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"author": "@holistics",
|
|
5
5
|
"bin": {
|
|
6
6
|
"dbdocs": "./bin/run"
|
|
@@ -9,7 +9,8 @@
|
|
|
9
9
|
"oclif/**/ansi-regex": "^3.0.1"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@dbml/
|
|
12
|
+
"@dbml/connector": "^3.7.2",
|
|
13
|
+
"@dbml/core": "3.7.2",
|
|
13
14
|
"@oclif/core": "1.12.1",
|
|
14
15
|
"@oclif/plugin-help": "5.1.12",
|
|
15
16
|
"axios": "1.6.0",
|
|
@@ -31,7 +32,7 @@
|
|
|
31
32
|
"oclif": "^3.2.0"
|
|
32
33
|
},
|
|
33
34
|
"engines": {
|
|
34
|
-
"node": ">=
|
|
35
|
+
"node": ">=18.0.0"
|
|
35
36
|
},
|
|
36
37
|
"files": [
|
|
37
38
|
"/bin",
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/* eslint-disable import/no-extraneous-dependencies */
|
|
2
|
+
/* eslint-disable no-use-before-define */
|
|
3
|
+
/* eslint-disable no-param-reassign */
|
|
4
|
+
const { Command, Flags } = require('@oclif/core');
|
|
5
|
+
const { importer } = require('@dbml/core');
|
|
6
|
+
const { connector } = require('@dbml/connector');
|
|
7
|
+
const ora = require('ora');
|
|
8
|
+
const { SUPPORTED_DATABASE_CONNECTORS } = require('../utils/constants');
|
|
9
|
+
const { writeToConsole, writeToFileAsync } = require('../utils/output-writer');
|
|
10
|
+
|
|
11
|
+
class Db2dbmlCommand extends Command {
|
|
12
|
+
async run () {
|
|
13
|
+
const spinner = ora({});
|
|
14
|
+
|
|
15
|
+
try {
|
|
16
|
+
const { flags, argv } = await this.parse(Db2dbmlCommand);
|
|
17
|
+
const { format, connection } = getConnectionOpt(argv);
|
|
18
|
+
|
|
19
|
+
spinner.text = 'Connecting to database...';
|
|
20
|
+
spinner.start();
|
|
21
|
+
|
|
22
|
+
const schemaJson = await connector.fetchSchemaJson(connection, format);
|
|
23
|
+
spinner.succeed('Connecting to database... done.');
|
|
24
|
+
|
|
25
|
+
spinner.start('Generating DBML ...');
|
|
26
|
+
const dbml = importer.generateDbml(schemaJson);
|
|
27
|
+
spinner.succeed('Generating DBML... done');
|
|
28
|
+
|
|
29
|
+
const { outFile } = flags;
|
|
30
|
+
|
|
31
|
+
if (!outFile || !outFile.trim()) {
|
|
32
|
+
writeToConsole(dbml);
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
spinner.start(`Wrote to ${outFile}`);
|
|
37
|
+
await writeToFileAsync(outFile, dbml);
|
|
38
|
+
spinner.succeed();
|
|
39
|
+
} catch (error) {
|
|
40
|
+
if (spinner.isSpinning) {
|
|
41
|
+
spinner.fail();
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
this.error(error.message);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
Db2dbmlCommand.description = 'Generate DBML directly from a database';
|
|
50
|
+
|
|
51
|
+
Db2dbmlCommand.args = [
|
|
52
|
+
{
|
|
53
|
+
name: 'format',
|
|
54
|
+
description: 'your database format (postgres, mysql, mssql)',
|
|
55
|
+
required: true,
|
|
56
|
+
},
|
|
57
|
+
{
|
|
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;'`,
|
|
63
|
+
required: true,
|
|
64
|
+
},
|
|
65
|
+
];
|
|
66
|
+
|
|
67
|
+
Db2dbmlCommand.flags = {
|
|
68
|
+
outFile: Flags.string({
|
|
69
|
+
description: 'output file path',
|
|
70
|
+
char: 'o',
|
|
71
|
+
helpValue: '/path-to-your-file',
|
|
72
|
+
}),
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* @param {string[]} argv
|
|
77
|
+
* @returns {{ format: string, connection: string}}
|
|
78
|
+
*/
|
|
79
|
+
function getConnectionOpt (argv) {
|
|
80
|
+
const defaultConnectionOpt = {
|
|
81
|
+
format: 'unknown',
|
|
82
|
+
connection: argv[1],
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const options = argv.reduce((connectionOpt, arg) => {
|
|
86
|
+
if (SUPPORTED_DATABASE_CONNECTORS.includes(arg)) {
|
|
87
|
+
connectionOpt.format = arg;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Check if the arg is a connection string using regex
|
|
91
|
+
const connectionStringRegex = /^.*[:;]/;
|
|
92
|
+
if (connectionStringRegex.test(arg)) {
|
|
93
|
+
// Example: jdbc:mysql://localhost:3306/mydatabase
|
|
94
|
+
// Example: odbc:Driver={SQL Server};Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;
|
|
95
|
+
connectionOpt.connection = arg;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return connectionOpt;
|
|
99
|
+
}, defaultConnectionOpt);
|
|
100
|
+
|
|
101
|
+
return options;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
module.exports = Db2dbmlCommand;
|
package/src/commands/validate.js
CHANGED
|
@@ -23,7 +23,7 @@ class ValidateCommand extends Command {
|
|
|
23
23
|
spinner.succeed('Done. Parse succeeded without errors.');
|
|
24
24
|
} catch (error) {
|
|
25
25
|
const rawMessage = formatParserV2ErrorMessage(error);
|
|
26
|
-
const message = rawMessage ? `You have syntax error(s) in ${path.basename(filepath)}\n${rawMessage}` :
|
|
26
|
+
const message = rawMessage ? `You have syntax error(s) in ${path.basename(filepath)}\n${rawMessage}` : error.message;
|
|
27
27
|
|
|
28
28
|
if (spinner.isSpinning) {
|
|
29
29
|
spinner.fail(`Failed: ${message}`);
|
package/src/utils/constants.js
CHANGED
|
@@ -19,9 +19,12 @@ const LOGIN_METHODS = {
|
|
|
19
19
|
GITHUB_GOOGLE: 'GitHub/Google',
|
|
20
20
|
};
|
|
21
21
|
|
|
22
|
+
const SUPPORTED_DATABASE_CONNECTORS = ['postgres', 'mysql', 'mssql'];
|
|
23
|
+
|
|
22
24
|
module.exports = {
|
|
23
25
|
PROJECT_GENERAL_ACCESS_TYPE,
|
|
24
26
|
PROJECT_SHARING_TEXT,
|
|
25
27
|
FLAG_HELP_GROUP,
|
|
26
28
|
LOGIN_METHODS,
|
|
29
|
+
SUPPORTED_DATABASE_CONNECTORS,
|
|
27
30
|
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
const { writeFile } = require('fs/promises');
|
|
2
|
+
|
|
3
|
+
/* eslint-disable no-console */
|
|
4
|
+
function writeToConsole (output) {
|
|
5
|
+
console.log(output);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
async function writeToFileAsync (filePath, output) {
|
|
9
|
+
if (typeof filePath !== 'string' || !filePath || !filePath.trim()) {
|
|
10
|
+
throw new Error('File path must be a non-empty string.');
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
try {
|
|
14
|
+
await writeFile(filePath, output);
|
|
15
|
+
} catch (error) {
|
|
16
|
+
const message = error.message ? error.message : `Unknown error when writing to ${filePath}`;
|
|
17
|
+
|
|
18
|
+
throw new Error(message);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
module.exports = {
|
|
23
|
+
writeToConsole,
|
|
24
|
+
writeToFileAsync,
|
|
25
|
+
};
|