@dbx-app/cli 0.4.7 → 0.4.9
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 +29 -20
- package/dist/cli.js +9 -24
- package/package.json +18 -18
package/README.md
CHANGED
|
@@ -4,10 +4,19 @@ Command line interface for DBX database connections, schema inspection, safe que
|
|
|
4
4
|
|
|
5
5
|
## Install
|
|
6
6
|
|
|
7
|
+
### npm
|
|
8
|
+
|
|
7
9
|
```bash
|
|
8
10
|
npm install -g @dbx-app/cli
|
|
9
11
|
```
|
|
10
12
|
|
|
13
|
+
### Homebrew
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
brew tap t8y2/dbx
|
|
17
|
+
brew install dbx-cli
|
|
18
|
+
```
|
|
19
|
+
|
|
11
20
|
Requires Node.js 22.13.0 or newer.
|
|
12
21
|
|
|
13
22
|
## Usage
|
|
@@ -29,17 +38,17 @@ dbx open local users
|
|
|
29
38
|
|
|
30
39
|
## Commands
|
|
31
40
|
|
|
32
|
-
| Command
|
|
33
|
-
|
|
34
|
-
| `dbx doctor`
|
|
35
|
-
| `dbx capabilities`
|
|
36
|
-
| `dbx connections list`
|
|
37
|
-
| `dbx schema list <connection>`
|
|
38
|
-
| `dbx schema describe <connection> <table>`
|
|
39
|
-
| `dbx query <connection> <sql>`
|
|
40
|
-
| `dbx query <connection> --file ./query.sql` | Execute SQL from a file
|
|
41
|
-
| `dbx context <connection>`
|
|
42
|
-
| `dbx open <connection> <table>`
|
|
41
|
+
| Command | Description |
|
|
42
|
+
| ------------------------------------------- | ----------------------------------------------------- |
|
|
43
|
+
| `dbx doctor` | Show local DBX config and desktop bridge diagnostics |
|
|
44
|
+
| `dbx capabilities` | Show direct-query and desktop-bridge database support |
|
|
45
|
+
| `dbx connections list` | List DBX connections without printing secrets |
|
|
46
|
+
| `dbx schema list <connection>` | List tables and views |
|
|
47
|
+
| `dbx schema describe <connection> <table>` | Show table columns |
|
|
48
|
+
| `dbx query <connection> <sql>` | Execute one SQL statement |
|
|
49
|
+
| `dbx query <connection> --file ./query.sql` | Execute SQL from a file |
|
|
50
|
+
| `dbx context <connection>` | Print compact schema context for prompts |
|
|
51
|
+
| `dbx open <connection> <table>` | Open a table in DBX Desktop |
|
|
43
52
|
|
|
44
53
|
## Output
|
|
45
54
|
|
|
@@ -102,16 +111,16 @@ npm install -g @dbx-app/cli
|
|
|
102
111
|
|
|
103
112
|
CLI JSON errors use stable codes:
|
|
104
113
|
|
|
105
|
-
| Code
|
|
106
|
-
|
|
107
|
-
| `UNKNOWN_OPTION`
|
|
108
|
-
| `INVALID_OPTION`
|
|
109
|
-
| `INVALID_ARGUMENT`
|
|
114
|
+
| Code | Meaning |
|
|
115
|
+
| ------------------------ | --------------------------------------------------- |
|
|
116
|
+
| `UNKNOWN_OPTION` | An unsupported flag was provided |
|
|
117
|
+
| `INVALID_OPTION` | A flag is missing a value or has an invalid value |
|
|
118
|
+
| `INVALID_ARGUMENT` | Positional arguments are missing or conflicting |
|
|
110
119
|
| `CONNECTION_STORE_ERROR` | DBX connection storage exists but could not be read |
|
|
111
|
-
| `CONNECTION_NOT_FOUND`
|
|
112
|
-
| `SQL_BLOCKED`
|
|
113
|
-
| `DBX_NOT_RUNNING`
|
|
114
|
-
| `ERROR`
|
|
120
|
+
| `CONNECTION_NOT_FOUND` | No DBX connection matched the requested name |
|
|
121
|
+
| `SQL_BLOCKED` | SQL safety rules blocked execution |
|
|
122
|
+
| `DBX_NOT_RUNNING` | DBX Desktop bridge is unavailable |
|
|
123
|
+
| `ERROR` | Unexpected runtime failure |
|
|
115
124
|
|
|
116
125
|
## Codex
|
|
117
126
|
|
package/dist/cli.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { readFile } from "node:fs/promises";
|
|
3
|
-
import { buildSchemaContext, createBackend, DIRECT_QUERY_TYPES, BRIDGE_REQUIRED_TYPES, evaluateSqlSafety, formatSchemaContext, getDbxDiagnostics, isMainModule, postBridge
|
|
3
|
+
import { buildSchemaContext, createBackend, DIRECT_QUERY_TYPES, BRIDGE_REQUIRED_TYPES, evaluateSqlSafety, formatSchemaContext, getDbxDiagnostics, isMainModule, postBridge } from "@dbx-app/node-core";
|
|
4
4
|
import { connectionSummary, csvTable, errorPayload, formatCell, formatErrorMessage, mdTable } from "./cli-format.js";
|
|
5
5
|
class CliError extends Error {
|
|
6
6
|
code;
|
|
@@ -55,12 +55,12 @@ export async function runCli(argv, options = {}) {
|
|
|
55
55
|
if (flags.format === "json")
|
|
56
56
|
return okJson(payload);
|
|
57
57
|
if (flags.format === "csv") {
|
|
58
|
-
return ok(csvTable(["mode", "type"], [
|
|
59
|
-
...payload.directQueryTypes.map((type) => ({ mode: "direct", type })),
|
|
60
|
-
...payload.bridgeRequiredTypes.map((type) => ({ mode: "bridge", type })),
|
|
61
|
-
]));
|
|
58
|
+
return ok(csvTable(["mode", "type"], [...payload.directQueryTypes.map((type) => ({ mode: "direct", type })), ...payload.bridgeRequiredTypes.map((type) => ({ mode: "bridge", type }))]));
|
|
62
59
|
}
|
|
63
|
-
return ok(`${mdTable(["Mode", "Types"], [
|
|
60
|
+
return ok(`${mdTable(["Mode", "Types"], [
|
|
61
|
+
["Direct", payload.directQueryTypes.join(", ")],
|
|
62
|
+
["Requires DBX Desktop", payload.bridgeRequiredTypes.join(", ")],
|
|
63
|
+
])}\n`);
|
|
64
64
|
}
|
|
65
65
|
if (args[0] === "connections" && args[1] === "list") {
|
|
66
66
|
ensureArgCount(args, 2, "dbx connections list");
|
|
@@ -93,13 +93,7 @@ export async function runCli(argv, options = {}) {
|
|
|
93
93
|
if (flags.format === "csv") {
|
|
94
94
|
return ok(csvTable(["name", "data_type", "is_nullable", "is_primary_key", "column_default", "comment"], columns));
|
|
95
95
|
}
|
|
96
|
-
return ok(`${mdTable(["Column", "Type", "Nullable", "Default", "Comment"], columns.map((c) => [
|
|
97
|
-
c.is_primary_key ? `${c.name} (PK)` : c.name,
|
|
98
|
-
c.data_type,
|
|
99
|
-
c.is_nullable ? "YES" : "NO",
|
|
100
|
-
c.column_default ?? "",
|
|
101
|
-
c.comment ?? "",
|
|
102
|
-
]))}\n`);
|
|
96
|
+
return ok(`${mdTable(["Column", "Type", "Nullable", "Default", "Comment"], columns.map((c) => [c.is_primary_key ? `${c.name} (PK)` : c.name, c.data_type, c.is_nullable ? "YES" : "NO", c.column_default ?? "", c.comment ?? ""]))}\n`);
|
|
103
97
|
}
|
|
104
98
|
if (args[0] === "query") {
|
|
105
99
|
const usesDefaultConnection = !!env.DBX_CONNECTION && args.length === (flags.file ? 1 : 2);
|
|
@@ -171,11 +165,7 @@ export async function runCli(argv, options = {}) {
|
|
|
171
165
|
}
|
|
172
166
|
catch (error) {
|
|
173
167
|
const message = error instanceof Error ? error.message : String(error);
|
|
174
|
-
const code = error instanceof CliError
|
|
175
|
-
? error.code
|
|
176
|
-
: typeof error === "object" && error !== null && "code" in error && typeof error.code === "string"
|
|
177
|
-
? error.code
|
|
178
|
-
: "ERROR";
|
|
168
|
+
const code = error instanceof CliError ? error.code : typeof error === "object" && error !== null && "code" in error && typeof error.code === "string" ? error.code : "ERROR";
|
|
179
169
|
const wantsJson = argv.includes("--json");
|
|
180
170
|
return fail(code, message, wantsJson);
|
|
181
171
|
}
|
|
@@ -332,12 +322,7 @@ function formatDoctor(diagnostics) {
|
|
|
332
322
|
["App data directory", diagnostics.appDataDir],
|
|
333
323
|
["DBX database", diagnostics.dbPathExists ? `found (${diagnostics.dbPath})` : `missing (${diagnostics.dbPath})`],
|
|
334
324
|
["Connections table", diagnostics.connectionsTableExists ? `${diagnostics.connectionRowCount} row(s)` : "missing"],
|
|
335
|
-
[
|
|
336
|
-
"Connection loading",
|
|
337
|
-
diagnostics.loadConnectionsOk
|
|
338
|
-
? `ok (${diagnostics.loadedConnectionCount} loaded)`
|
|
339
|
-
: `failed (${diagnostics.loadConnectionsError ?? "unknown error"})`,
|
|
340
|
-
],
|
|
325
|
+
["Connection loading", diagnostics.loadConnectionsOk ? `ok (${diagnostics.loadedConnectionCount} loaded)` : `failed (${diagnostics.loadConnectionsError ?? "unknown error"})`],
|
|
341
326
|
...(diagnostics.loadConnectionsHint ? [["Connection fix", diagnostics.loadConnectionsHint]] : []),
|
|
342
327
|
["Desktop bridge", diagnostics.bridgePortFileExists ? `available (${diagnostics.bridgeUrl ?? diagnostics.bridgePortFile})` : "not running"],
|
|
343
328
|
["Direct query types", diagnostics.directQueryTypes.join(", ")],
|
package/package.json
CHANGED
|
@@ -1,43 +1,43 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dbx-app/cli",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.9",
|
|
4
4
|
"description": "Command line interface for DBX database connections, schema, and safe queries",
|
|
5
|
-
"type": "module",
|
|
6
|
-
"engines": {
|
|
7
|
-
"node": ">=22.13.0"
|
|
8
|
-
},
|
|
9
|
-
"bin": {
|
|
10
|
-
"dbx": "dist/cli.js"
|
|
11
|
-
},
|
|
12
|
-
"files": [
|
|
13
|
-
"dist"
|
|
14
|
-
],
|
|
15
5
|
"keywords": [
|
|
6
|
+
"ai-agent",
|
|
7
|
+
"automation",
|
|
16
8
|
"cli",
|
|
9
|
+
"codex",
|
|
17
10
|
"database",
|
|
18
11
|
"dbx",
|
|
19
|
-
"codex",
|
|
20
|
-
"terminal",
|
|
21
|
-
"automation",
|
|
22
|
-
"postgresql",
|
|
23
12
|
"mysql",
|
|
24
|
-
"
|
|
13
|
+
"postgresql",
|
|
14
|
+
"terminal"
|
|
25
15
|
],
|
|
16
|
+
"homepage": "https://github.com/t8y2/dbx/tree/main/packages/cli",
|
|
26
17
|
"license": "Apache-2.0",
|
|
27
18
|
"repository": {
|
|
28
19
|
"type": "git",
|
|
29
20
|
"url": "https://github.com/t8y2/dbx",
|
|
30
21
|
"directory": "packages/cli"
|
|
31
22
|
},
|
|
32
|
-
"
|
|
23
|
+
"bin": {
|
|
24
|
+
"dbx": "dist/cli.js"
|
|
25
|
+
},
|
|
26
|
+
"files": [
|
|
27
|
+
"dist"
|
|
28
|
+
],
|
|
29
|
+
"type": "module",
|
|
33
30
|
"dependencies": {
|
|
34
|
-
"@dbx-app/node-core": "^0.4.
|
|
31
|
+
"@dbx-app/node-core": "^0.4.9"
|
|
35
32
|
},
|
|
36
33
|
"devDependencies": {
|
|
37
34
|
"@types/node": "^22.15.21",
|
|
38
35
|
"tsx": "^4.19.4",
|
|
39
36
|
"typescript": "^5.8.3"
|
|
40
37
|
},
|
|
38
|
+
"engines": {
|
|
39
|
+
"node": ">=22.13.0"
|
|
40
|
+
},
|
|
41
41
|
"scripts": {
|
|
42
42
|
"start": "tsx src/cli.ts",
|
|
43
43
|
"test": "pnpm --filter @dbx-app/node-core build && vitest run --config vitest.config.ts",
|