@carllee1983/dbcli 0.5.2-beta → 1.2.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 +131 -5
- package/README.md +313 -54
- package/README.zh-TW.md +951 -338
- package/assets/SKILL.md +105 -7
- package/dist/cli.mjs +46569 -44311
- package/package.json +7 -4
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. Trigger when working with databases, running SQL, exploring table structures, 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 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.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# dbcli
|
|
@@ -22,16 +22,43 @@ dbcli query "SELECT * FROM users" # Execute SQL
|
|
|
22
22
|
Initialize `.dbcli` configuration file. Typically run manually by the developer — avoid running on behalf of the user unless explicitly requested.
|
|
23
23
|
|
|
24
24
|
```bash
|
|
25
|
-
dbcli init
|
|
25
|
+
dbcli init # Single connection (v1 format)
|
|
26
26
|
dbcli init --system mysql --host localhost --port 3306 --user root --name mydb
|
|
27
|
-
dbcli init --use-env-refs
|
|
28
|
-
dbcli init --no-interactive --force
|
|
27
|
+
dbcli init --use-env-refs # Store env var references
|
|
28
|
+
dbcli init --no-interactive --force # Non-interactive mode
|
|
29
|
+
|
|
30
|
+
# Multi-connection (v2 format)
|
|
31
|
+
dbcli init --conn-name staging --env-file .env.staging # Named connection with custom env file
|
|
32
|
+
dbcli init --conn-name prod --env-file .env.production --use-env-refs --skip-test
|
|
33
|
+
dbcli init --remove staging # Remove a named connection
|
|
34
|
+
dbcli init --rename staging:production # Rename a connection
|
|
29
35
|
```
|
|
30
36
|
|
|
31
|
-
**Key options:** `--system
|
|
37
|
+
**Key options:** `--system`, `--permission`, `--use-env-refs`, `--skip-test`, `--no-interactive`, `--force`, `--conn-name <name>`, `--env-file <path>`, `--remove <name>`, `--rename <old:new>`
|
|
38
|
+
|
|
39
|
+
**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.
|
|
32
40
|
|
|
33
41
|
> **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.
|
|
34
42
|
|
|
43
|
+
### use
|
|
44
|
+
|
|
45
|
+
Switch or display the default database connection (v2 multi-connection config).
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
dbcli use # Show current default connection
|
|
49
|
+
dbcli use staging # Switch default to 'staging'
|
|
50
|
+
dbcli use --list # List all connections (* marks default)
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Any command can also use `--use <name>` to temporarily select a connection without changing the default:
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
dbcli query --use staging "SELECT * FROM users LIMIT 10"
|
|
57
|
+
dbcli list --use prod
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
**Requires v2 config** (created with `dbcli init --conn-name`).
|
|
61
|
+
|
|
35
62
|
### list
|
|
36
63
|
|
|
37
64
|
List all tables.
|
|
@@ -116,10 +143,11 @@ Export query results to file or stdout.
|
|
|
116
143
|
|
|
117
144
|
```bash
|
|
118
145
|
dbcli export "SELECT * FROM users" --format csv --output users.csv
|
|
146
|
+
dbcli export "SELECT * FROM users" --format csv --output users.csv --force # Skip overwrite confirmation
|
|
119
147
|
dbcli export "SELECT * FROM users" --format json | jq '.[]'
|
|
120
148
|
```
|
|
121
149
|
|
|
122
|
-
**Options:** `--format <json|csv>` (required), `--output <path
|
|
150
|
+
**Options:** `--format <json|csv>` (required), `--output <path>`, `--force`
|
|
123
151
|
**Permission:** query-only+
|
|
124
152
|
|
|
125
153
|
### blacklist
|
|
@@ -222,6 +250,75 @@ dbcli upgrade --check # Only check, do not upgrade
|
|
|
222
250
|
|
|
223
251
|
**Background check:** Every command silently checks the npm registry for a newer version (at most once per 24 hours, cached in `.dbcli/version-check.json`). If a newer version is found, a one-line hint is printed to stderr after the command completes. Pass `-q` / `--quiet` to suppress the hint.
|
|
224
252
|
|
|
253
|
+
### `dbcli shell`
|
|
254
|
+
|
|
255
|
+
Start an interactive database shell.
|
|
256
|
+
|
|
257
|
+
```bash
|
|
258
|
+
dbcli shell # Interactive mode with SQL + dbcli commands
|
|
259
|
+
dbcli shell --sql # SQL-only mode
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
Inside the shell:
|
|
263
|
+
- Type SQL statements ending with `;` to execute
|
|
264
|
+
- Type dbcli commands without the `dbcli` prefix (e.g., `schema users`)
|
|
265
|
+
- Use Tab for auto-completion (SQL keywords, table names, column names)
|
|
266
|
+
- Type `.help` for meta commands (.quit, .clear, .format, .history, .timing)
|
|
267
|
+
- Multi-line SQL: keeps accumulating until `;` is found
|
|
268
|
+
- History persists across sessions (~/.dbcli_history)
|
|
269
|
+
|
|
270
|
+
### migrate
|
|
271
|
+
|
|
272
|
+
Schema DDL operations. **All commands default to dry-run** — use `--execute` to actually run the SQL. Destructive operations (DROP) also require `--force`.
|
|
273
|
+
|
|
274
|
+
```bash
|
|
275
|
+
# Create table
|
|
276
|
+
dbcli migrate create posts \
|
|
277
|
+
--column "id:serial:pk" \
|
|
278
|
+
--column "title:varchar(200):not-null" \
|
|
279
|
+
--column "body:text" \
|
|
280
|
+
--column "created_at:timestamp:default=now()"
|
|
281
|
+
|
|
282
|
+
# Drop table (dry-run by default)
|
|
283
|
+
dbcli migrate drop posts
|
|
284
|
+
dbcli migrate drop posts --execute --force # Actually drop
|
|
285
|
+
|
|
286
|
+
# Add/drop/alter column
|
|
287
|
+
dbcli migrate add-column users bio text --nullable
|
|
288
|
+
dbcli migrate drop-column users temp_field --execute --force
|
|
289
|
+
dbcli migrate alter-column users name --type "varchar(200)"
|
|
290
|
+
dbcli migrate alter-column users email --rename user_email
|
|
291
|
+
dbcli migrate alter-column users status --set-default "'active'"
|
|
292
|
+
dbcli migrate alter-column users bio --drop-default
|
|
293
|
+
dbcli migrate alter-column users bio --set-nullable
|
|
294
|
+
dbcli migrate alter-column users email --drop-nullable
|
|
295
|
+
|
|
296
|
+
# Index management
|
|
297
|
+
dbcli migrate add-index users --columns email --unique
|
|
298
|
+
dbcli migrate add-index users --columns "last_name,first_name" --name idx_fullname
|
|
299
|
+
dbcli migrate drop-index idx_fullname --execute --force
|
|
300
|
+
|
|
301
|
+
# Constraint management
|
|
302
|
+
dbcli migrate add-constraint orders --fk user_id --references users.id --on-delete cascade
|
|
303
|
+
dbcli migrate add-constraint users --unique email
|
|
304
|
+
dbcli migrate add-constraint users --check "age >= 0"
|
|
305
|
+
dbcli migrate drop-constraint orders fk_orders_user_id --execute --force
|
|
306
|
+
|
|
307
|
+
# Enum (PostgreSQL only — MySQL uses inline ENUM in column type)
|
|
308
|
+
dbcli migrate add-enum status active inactive suspended
|
|
309
|
+
dbcli migrate alter-enum status --add-value archived
|
|
310
|
+
dbcli migrate drop-enum status --execute --force
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
**Column spec format:** `name:type[:modifier[:modifier...]]`
|
|
314
|
+
- Modifiers: `pk`, `not-null`, `unique`, `auto-increment`, `default=<value>`, `references=<table>.<column>`
|
|
315
|
+
- Serial types: `serial`, `bigserial`, `smallserial` (auto-expand per DB dialect)
|
|
316
|
+
|
|
317
|
+
**Options (all subcommands):** `--execute`, `--force`, `--config <path>`
|
|
318
|
+
**Permission:** admin
|
|
319
|
+
|
|
320
|
+
**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.
|
|
321
|
+
|
|
225
322
|
## Permission Levels
|
|
226
323
|
|
|
227
324
|
| Level | Allowed Operations |
|
|
@@ -229,7 +326,7 @@ dbcli upgrade --check # Only check, do not upgrade
|
|
|
229
326
|
| query-only | SELECT, list, schema, export |
|
|
230
327
|
| read-write | query-only + INSERT, UPDATE |
|
|
231
328
|
| data-admin | read-write + DELETE (full DML, no DDL) |
|
|
232
|
-
| admin | data-admin + DROP, ALTER, CREATE, TRUNCATE |
|
|
329
|
+
| admin | data-admin + DDL (migrate create/drop/alter, DROP, ALTER, CREATE, TRUNCATE) |
|
|
233
330
|
|
|
234
331
|
Set via `dbcli init --permission <level>` or in `.dbcli` config.
|
|
235
332
|
|
|
@@ -238,6 +335,7 @@ Set via `dbcli init --permission <level>` or in `.dbcli` config.
|
|
|
238
335
|
| Flag | Description |
|
|
239
336
|
|------|-------------|
|
|
240
337
|
| `--config <path>` | Path to .dbcli config file (default: `.dbcli`) |
|
|
338
|
+
| `--use <connection>` | Use a specific named connection (v2 config) |
|
|
241
339
|
| `-v, --verbose` | Increase verbosity (`-v` verbose, `-vv` debug) |
|
|
242
340
|
| `-q, --quiet` | Suppress non-essential output |
|
|
243
341
|
| `--no-color` | Disable colored output (also respects `NO_COLOR` env var) |
|