@carllee1983/dbcli 1.4.1 → 1.5.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/CHANGELOG.md +6 -9
- package/README.dev.md +11 -0
- package/README.md +11 -0
- package/README.zh-TW.md +11 -0
- package/assets/SKILL.md +58 -4
- package/dist/cli.mjs +29674 -404
- package/package.json +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,15 +5,7 @@ All notable changes to dbcli are documented here.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
-
## [1.
|
|
9
|
-
|
|
10
|
-
### Added
|
|
11
|
-
|
|
12
|
-
- **Documentation Update**: Added per-connection schema isolation details to `SKILL.md` for AI agents.
|
|
13
|
-
- Clarified schema storage layout in `.dbcli/schemas/`.
|
|
14
|
-
- Added usage examples for `--use <connection>` with schema commands.
|
|
15
|
-
|
|
16
|
-
## [1.4.0] - 2026-04-21
|
|
8
|
+
## [1.5.0] - 2026-04-21
|
|
17
9
|
|
|
18
10
|
### Added
|
|
19
11
|
|
|
@@ -22,6 +14,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
22
14
|
- Layered schema loading (Hot/Cold) integrated into `configModule`.
|
|
23
15
|
- Per-connection isolation: Each connection now has its own schema directory (`.dbcli/schemas/<connection>/`).
|
|
24
16
|
- **Improved Migration UX**: Added proactive hints during schema migration to ensure data consistency.
|
|
17
|
+
- **Documentation Update**: Added per-connection schema isolation details to `SKILL.md` for AI agents.
|
|
18
|
+
- Clarified schema storage layout in `.dbcli/schemas/`.
|
|
19
|
+
- Added usage examples for `--use <connection>` with schema commands.
|
|
20
|
+
|
|
21
|
+
## [1.4.1] - 2026-04-21
|
|
25
22
|
|
|
26
23
|
## [1.3.0] - 2026-04-02
|
|
27
24
|
|
package/README.dev.md
CHANGED
|
@@ -17,6 +17,14 @@ Before running `npm publish`:
|
|
|
17
17
|
bun test --run unit/
|
|
18
18
|
```
|
|
19
19
|
|
|
20
|
+
For live database integration tests, use an explicit config path if needed:
|
|
21
|
+
```bash
|
|
22
|
+
LIVE_DB_CONFIG_PATH=/path/to/.dbcli bun test tests/integration/live-db.test.ts
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
If no live config is available, `tests/integration/live-db.test.ts` skips
|
|
26
|
+
instead of falling back to the default PostgreSQL configuration.
|
|
27
|
+
|
|
20
28
|
3. **Update version in package.json:**
|
|
21
29
|
```bash
|
|
22
30
|
npm version minor # Updates package.json version + creates git tag
|
|
@@ -101,6 +109,9 @@ Then publish a patch fix.
|
|
|
101
109
|
- **Cross-platform support:** Shebang `#!/usr/bin/env bun` works on all platforms
|
|
102
110
|
- macOS/Linux: Direct shebang execution
|
|
103
111
|
- Windows: npm creates .cmd wrapper automatically (no manual creation needed)
|
|
112
|
+
- **Live integration tests:** `tests/integration/live-db.test.ts` reads `.dbcli/config.json`
|
|
113
|
+
by default or `LIVE_DB_CONFIG_PATH` when you need to point at another config
|
|
114
|
+
directory. Set `SKIP_INTEGRATION_TESTS=true` to skip all integration tests.
|
|
104
115
|
|
|
105
116
|
### Troubleshooting
|
|
106
117
|
|
package/README.md
CHANGED
|
@@ -1236,6 +1236,17 @@ bun run test:docker # integration tests with docker-compose.test.yml (MySQ
|
|
|
1236
1236
|
bun run build # bundle CLI to dist/ (used before publish)
|
|
1237
1237
|
```
|
|
1238
1238
|
|
|
1239
|
+
Live database integration tests use `.dbcli/config.json` by default. If your live
|
|
1240
|
+
config lives elsewhere, set `LIVE_DB_CONFIG_PATH=/path/to/.dbcli` before running:
|
|
1241
|
+
|
|
1242
|
+
```bash
|
|
1243
|
+
LIVE_DB_CONFIG_PATH=/path/to/.dbcli bun test tests/integration/live-db.test.ts
|
|
1244
|
+
```
|
|
1245
|
+
|
|
1246
|
+
If no live config is available, `tests/integration/live-db.test.ts` skips instead
|
|
1247
|
+
of falling back to the default PostgreSQL configuration. Set
|
|
1248
|
+
`SKIP_INTEGRATION_TESTS=true` to skip all integration tests.
|
|
1249
|
+
|
|
1239
1250
|
See [CONTRIBUTING.md](./CONTRIBUTING.md) for full setup, testing, and release process.
|
|
1240
1251
|
|
|
1241
1252
|
---
|
package/README.zh-TW.md
CHANGED
|
@@ -1236,6 +1236,17 @@ bun run test:docker # 搭配 docker-compose.test.yml(MySQL + PostgreSQL
|
|
|
1236
1236
|
bun run build # 建置 CLI 至 dist/(發布前使用)
|
|
1237
1237
|
```
|
|
1238
1238
|
|
|
1239
|
+
live DB 整合測試預設讀取 `.dbcli/config.json`。如果你的 live 設定放在其他位置,
|
|
1240
|
+
可先指定 `LIVE_DB_CONFIG_PATH=/path/to/.dbcli` 再執行:
|
|
1241
|
+
|
|
1242
|
+
```bash
|
|
1243
|
+
LIVE_DB_CONFIG_PATH=/path/to/.dbcli bun test tests/integration/live-db.test.ts
|
|
1244
|
+
```
|
|
1245
|
+
|
|
1246
|
+
如果沒有可用的 live config,`tests/integration/live-db.test.ts` 會直接 skip,
|
|
1247
|
+
不再回退到預設 PostgreSQL 設定。若要跳過所有整合測試,可設定
|
|
1248
|
+
`SKIP_INTEGRATION_TESTS=true`。
|
|
1249
|
+
|
|
1239
1250
|
完整環境、測試與發布流程見 [CONTRIBUTING.md](./CONTRIBUTING.md)。
|
|
1240
1251
|
|
|
1241
1252
|
---
|
package/assets/SKILL.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: dbcli
|
|
3
|
-
description: Database CLI for AI agents with permission-based access control. Use to query, inspect schemas, insert/update/delete data, export results, and manage sensitive data blacklists. Supports MySQL, PostgreSQL, MariaDB with multiple named connections per project and custom env files. Trigger when working with databases, running SQL, exploring table structures, switching between database environments, or protecting sensitive columns/tables from AI access.
|
|
3
|
+
description: Database CLI for AI agents with permission-based access control. Use to query, inspect schemas, insert/update/delete data, export results, and manage sensitive data blacklists. Supports MySQL, PostgreSQL, MariaDB, and MongoDB with multiple named connections per project and custom env files. Trigger when working with databases, running SQL or MongoDB JSON queries, exploring table/collection structures, switching between database environments, or protecting sensitive columns/tables from AI access.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# dbcli
|
|
@@ -27,6 +27,11 @@ dbcli init --system mysql --host localhost --port 3306 --user root --name mydb
|
|
|
27
27
|
dbcli init --use-env-refs # Store env var references
|
|
28
28
|
dbcli init --no-interactive --force # Non-interactive mode
|
|
29
29
|
|
|
30
|
+
# MongoDB
|
|
31
|
+
dbcli init --system mongodb --uri "mongodb://user:pass@host:27017/mydb?authSource=admin"
|
|
32
|
+
dbcli init --system mongodb --host localhost --port 27017 --user admin --password secret --name mydb
|
|
33
|
+
dbcli init --system mongodb --host localhost --port 27017 --name mydb # No auth
|
|
34
|
+
|
|
30
35
|
# Multi-connection (v2 format)
|
|
31
36
|
dbcli init --conn-name staging --env-file .env.staging # Named connection with custom env file
|
|
32
37
|
dbcli init --conn-name prod --env-file .env.production --use-env-refs --skip-test
|
|
@@ -36,6 +41,8 @@ dbcli init --rename staging:production # Rename a connection
|
|
|
36
41
|
|
|
37
42
|
**Key options:** `--system`, `--permission`, `--use-env-refs`, `--skip-test`, `--no-interactive`, `--force`, `--conn-name <name>`, `--env-file <path>`, `--remove <name>`, `--rename <old:new>`
|
|
38
43
|
|
|
44
|
+
**MongoDB-specific options:** `--uri <uri>` (full connection URI), `--auth-source <db>` (auth database, default: `admin` when user/password set)
|
|
45
|
+
|
|
39
46
|
**Multi-connection:** Using `--conn-name` or `--env-file` creates a v2 config with named connections. Each connection can have its own env file and permission level. Existing v1 configs are automatically imported as the `default` connection when upgrading.
|
|
40
47
|
|
|
41
48
|
> **AI agent note on `--use-env-refs`:** If an existing `.dbcli` config contains `{"$env": "DB_HOST"}` style references, the connection values are read from environment variables at runtime. Do NOT re-run `init` to replace these references with actual values — the env-ref format is intentional for CI/CD and multi-environment setups.
|
|
@@ -61,7 +68,7 @@ dbcli list --use prod
|
|
|
61
68
|
|
|
62
69
|
### list
|
|
63
70
|
|
|
64
|
-
List all tables.
|
|
71
|
+
List all tables (SQL) or collections (MongoDB).
|
|
65
72
|
|
|
66
73
|
```bash
|
|
67
74
|
dbcli list
|
|
@@ -70,6 +77,8 @@ dbcli list --format json
|
|
|
70
77
|
|
|
71
78
|
**Permission:** query-only+
|
|
72
79
|
|
|
80
|
+
> **MongoDB:** Lists collections with estimated document count instead of tables.
|
|
81
|
+
|
|
73
82
|
### schema
|
|
74
83
|
|
|
75
84
|
Display table schema or scan entire database.
|
|
@@ -94,17 +103,30 @@ dbcli schema --use prod # Scan prod DB; saves to .dbcli/schemas/prod
|
|
|
94
103
|
|
|
95
104
|
### query
|
|
96
105
|
|
|
97
|
-
Execute SQL query.
|
|
106
|
+
Execute SQL query (MySQL/PostgreSQL/MariaDB) or JSON filter/pipeline (MongoDB).
|
|
98
107
|
|
|
99
108
|
```bash
|
|
109
|
+
# SQL databases
|
|
100
110
|
dbcli query "SELECT * FROM users LIMIT 10"
|
|
101
111
|
dbcli query "SELECT id, email FROM users" --format json
|
|
102
112
|
dbcli query "SELECT * FROM logs" --no-limit
|
|
113
|
+
|
|
114
|
+
# MongoDB: JSON filter (find)
|
|
115
|
+
dbcli query '{"status": "active"}' --collection users
|
|
116
|
+
dbcli query '{"age": {"$gt": 18}}' --collection users --format json
|
|
117
|
+
|
|
118
|
+
# MongoDB: aggregation pipeline
|
|
119
|
+
dbcli query '[{"$match": {"status": "active"}}, {"$group": {"_id": "$role", "count": {"$sum": 1}}}]' --collection users
|
|
103
120
|
```
|
|
104
121
|
|
|
105
|
-
**Options:** `--format <table|json|csv>`, `--limit <number>`, `--no-limit
|
|
122
|
+
**Options:** `--format <table|json|csv>`, `--limit <number>`, `--no-limit`, `--collection <name>` (MongoDB only)
|
|
106
123
|
**Permission:** query-only+
|
|
107
124
|
|
|
125
|
+
> **MongoDB notes:**
|
|
126
|
+
> - SQL syntax is rejected — use JSON object (filter) or JSON array (pipeline)
|
|
127
|
+
> - `--collection <name>` is required
|
|
128
|
+
> - Auto-limit does not apply; use `$limit` in your pipeline if needed
|
|
129
|
+
|
|
108
130
|
### insert
|
|
109
131
|
|
|
110
132
|
Insert data into a table.
|
|
@@ -325,6 +347,38 @@ dbcli migrate drop-enum status --execute --force
|
|
|
325
347
|
|
|
326
348
|
**AI agent note:** Always use dry-run first (no `--execute`) to preview generated SQL. Only add `--execute` after confirming the SQL is correct. For DROP operations, both `--execute` and `--force` are required.
|
|
327
349
|
|
|
350
|
+
## MongoDB Support
|
|
351
|
+
|
|
352
|
+
MongoDB connections use a JSON-based query model instead of SQL.
|
|
353
|
+
|
|
354
|
+
**Supported commands:** `init`, `list`, `query`, `status`, `use`, `shell`, `doctor`, `upgrade`, `completion`
|
|
355
|
+
|
|
356
|
+
**Not supported (exit with error):** `schema`, `insert`, `update`, `delete`, `export`, `diff`, `migrate`, `check`
|
|
357
|
+
|
|
358
|
+
### MongoDB-specific workflow
|
|
359
|
+
|
|
360
|
+
```bash
|
|
361
|
+
# 1. Initialize (URI or individual params)
|
|
362
|
+
dbcli init --system mongodb --uri "mongodb://localhost:27017/mydb"
|
|
363
|
+
|
|
364
|
+
# 2. List collections
|
|
365
|
+
dbcli list --format json
|
|
366
|
+
|
|
367
|
+
# 3. Query with JSON filter (find) or pipeline (aggregate)
|
|
368
|
+
dbcli query '{}' --collection orders --format json # All documents
|
|
369
|
+
dbcli query '{"status": "paid"}' --collection orders # Filter
|
|
370
|
+
dbcli query '[{"$match": {"status":"paid"}}, {"$count":"total"}]' --collection orders # Pipeline
|
|
371
|
+
```
|
|
372
|
+
|
|
373
|
+
### Query syntax
|
|
374
|
+
|
|
375
|
+
| Intent | Syntax |
|
|
376
|
+
|--------|--------|
|
|
377
|
+
| All documents | `'{}'` |
|
|
378
|
+
| Field filter | `'{"field": "value"}'` |
|
|
379
|
+
| Comparison | `'{"age": {"$gt": 18}}'` |
|
|
380
|
+
| Aggregation | `'[{"$match": {...}}, {"$group": {...}}]'` |
|
|
381
|
+
|
|
328
382
|
## Permission Levels
|
|
329
383
|
|
|
330
384
|
| Level | Allowed Operations |
|