@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/README.md
CHANGED
|
@@ -37,6 +37,7 @@ All messages, help text, error messages, and command output respond to the langu
|
|
|
37
37
|
|
|
38
38
|
```bash
|
|
39
39
|
npm install -g @carllee1983/dbcli
|
|
40
|
+
# or: bun install -g @carllee1983/dbcli
|
|
40
41
|
```
|
|
41
42
|
|
|
42
43
|
#### Zero-Install (No Installation Needed)
|
|
@@ -44,6 +45,7 @@ npm install -g @carllee1983/dbcli
|
|
|
44
45
|
```bash
|
|
45
46
|
npx @carllee1983/dbcli init
|
|
46
47
|
npx @carllee1983/dbcli query "SELECT * FROM users"
|
|
48
|
+
# or with Bun: bunx @carllee1983/dbcli init
|
|
47
49
|
```
|
|
48
50
|
|
|
49
51
|
#### Update
|
|
@@ -59,12 +61,15 @@ npm update -g @carllee1983/dbcli
|
|
|
59
61
|
#### Development Installation
|
|
60
62
|
|
|
61
63
|
```bash
|
|
62
|
-
git clone
|
|
64
|
+
git clone https://github.com/CarlLee1983/dbcli.git
|
|
63
65
|
cd dbcli
|
|
64
66
|
bun install
|
|
65
|
-
bun run
|
|
67
|
+
bun run src/cli.ts -- --help
|
|
68
|
+
# or: bun run dev -- --help
|
|
66
69
|
```
|
|
67
70
|
|
|
71
|
+
When `dbcli` is not on your `PATH`, use `bun run src/cli.ts <subcommand> ...` (same as `bun run dev -- <subcommand> ...`).
|
|
72
|
+
|
|
68
73
|
### First Steps
|
|
69
74
|
|
|
70
75
|
```bash
|
|
@@ -86,9 +91,57 @@ dbcli skill --install claude
|
|
|
86
91
|
|
|
87
92
|
---
|
|
88
93
|
|
|
89
|
-
##
|
|
94
|
+
## Multi-connection Support (v2)
|
|
95
|
+
|
|
96
|
+
dbcli supports multiple named database connections within a single project. This is useful for managing different environments (development, staging, production) or multiple databases.
|
|
97
|
+
|
|
98
|
+
### Initializing Named Connections
|
|
99
|
+
|
|
100
|
+
To create a named connection, use the `--conn-name` option during `init`. You can also specify a custom `.env` file for that connection.
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
# Add a staging connection using .env.staging
|
|
104
|
+
dbcli init --conn-name staging --env-file .env.staging
|
|
105
|
+
|
|
106
|
+
# Add a production connection with environment variable references
|
|
107
|
+
dbcli init --conn-name prod --env-file .env.production --use-env-refs
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### Managing Connections
|
|
111
|
+
|
|
112
|
+
Use the `dbcli use` command to switch between connections or list them.
|
|
113
|
+
|
|
114
|
+
```bash
|
|
115
|
+
# List all connections (* marks the current default)
|
|
116
|
+
dbcli use --list
|
|
117
|
+
|
|
118
|
+
# Switch the default connection to 'staging'
|
|
119
|
+
dbcli use staging
|
|
120
|
+
|
|
121
|
+
# Show the current default connection
|
|
122
|
+
dbcli use
|
|
123
|
+
|
|
124
|
+
# Remove a connection
|
|
125
|
+
dbcli init --remove staging
|
|
126
|
+
|
|
127
|
+
# Rename a connection
|
|
128
|
+
dbcli init --rename staging:production
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### Using a Specific Connection Temporarily
|
|
132
|
+
|
|
133
|
+
You can use the `--use <name>` global flag to execute any command against a specific connection without changing the default.
|
|
134
|
+
|
|
135
|
+
```bash
|
|
136
|
+
# Query the production database once
|
|
137
|
+
dbcli query "SELECT count(*) FROM users" --use prod
|
|
138
|
+
|
|
139
|
+
# Check staging table health
|
|
140
|
+
dbcli check users --use staging
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
---
|
|
90
144
|
|
|
91
|
-
### Commands
|
|
92
145
|
|
|
93
146
|
#### `dbcli init`
|
|
94
147
|
|
|
@@ -99,7 +152,7 @@ Initialize a new dbcli project with database connection configuration.
|
|
|
99
152
|
dbcli init [OPTIONS]
|
|
100
153
|
```
|
|
101
154
|
|
|
102
|
-
**Options:**
|
|
155
|
+
**Options (Basic):**
|
|
103
156
|
- `--system <type>` — Database system: `postgresql`, `mysql`, `mariadb`
|
|
104
157
|
- `--host <host>` — Database host
|
|
105
158
|
- `--port <port>` — Database port
|
|
@@ -108,15 +161,16 @@ dbcli init [OPTIONS]
|
|
|
108
161
|
- `--name <db>` — Database name
|
|
109
162
|
- `--permission <level>` — Permission level: `query-only`, `read-write`, `data-admin`, `admin`
|
|
110
163
|
- `--use-env-refs` — Store environment variable references instead of actual values in config
|
|
111
|
-
- `--env-host <var>` — Env var name for host (with `--use-env-refs`)
|
|
112
|
-
- `--env-port <var>` — Env var name for port (with `--use-env-refs`)
|
|
113
|
-
- `--env-user <var>` — Env var name for user (with `--use-env-refs`)
|
|
114
|
-
- `--env-password <var>` — Env var name for password (with `--use-env-refs`)
|
|
115
|
-
- `--env-database <var>` — Env var name for database (with `--use-env-refs`)
|
|
116
164
|
- `--skip-test` — Skip connection test
|
|
117
165
|
- `--no-interactive` — Non-interactive mode (requires all options)
|
|
118
166
|
- `--force` — Overwrite existing config without confirmation
|
|
119
167
|
|
|
168
|
+
**Options (Multi-connection v2):**
|
|
169
|
+
- `--conn-name <name>` — Create a named connection (e.g., `staging`, `prod`)
|
|
170
|
+
- `--env-file <path>` — Load credentials from a specific `.env` file for this connection
|
|
171
|
+
- `--remove <name>` — Remove a named connection from the config
|
|
172
|
+
- `--rename <old:new>` — Rename an existing connection (format: `old:new`)
|
|
173
|
+
|
|
120
174
|
**Behavior:**
|
|
121
175
|
- Reads `.env` file if present (auto-fills DATABASE_URL, DB_* variables)
|
|
122
176
|
- Prompts for missing values (host, port, user, password, database name, permission level)
|
|
@@ -128,15 +182,9 @@ dbcli init [OPTIONS]
|
|
|
128
182
|
# Interactive initialization
|
|
129
183
|
dbcli init
|
|
130
184
|
|
|
131
|
-
#
|
|
132
|
-
|
|
133
|
-
dbcli init
|
|
134
|
-
|
|
135
|
-
# Specify permission level
|
|
136
|
-
echo "PERMISSION_LEVEL=admin" >> .env && dbcli init
|
|
137
|
-
|
|
138
|
-
# Store env var references instead of values (interactive)
|
|
139
|
-
dbcli init --use-env-refs
|
|
185
|
+
# Multi-connection setup
|
|
186
|
+
dbcli init --conn-name staging --env-file .env.staging
|
|
187
|
+
dbcli init --conn-name prod --env-file .env.production --use-env-refs
|
|
140
188
|
|
|
141
189
|
# Store env var references (non-interactive)
|
|
142
190
|
dbcli init --use-env-refs --system mysql \
|
|
@@ -146,6 +194,34 @@ dbcli init --use-env-refs --system mysql \
|
|
|
146
194
|
--no-interactive
|
|
147
195
|
```
|
|
148
196
|
|
|
197
|
+
---
|
|
198
|
+
|
|
199
|
+
#### `dbcli use` (Requires v2 config)
|
|
200
|
+
|
|
201
|
+
Manage or switch the default database connection in multi-connection projects.
|
|
202
|
+
|
|
203
|
+
**Usage:**
|
|
204
|
+
```bash
|
|
205
|
+
dbcli use [connection-name] [OPTIONS]
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
**Options:**
|
|
209
|
+
- `--list` — List all connections and show the current default
|
|
210
|
+
|
|
211
|
+
**Examples:**
|
|
212
|
+
```bash
|
|
213
|
+
# Show current default connection
|
|
214
|
+
dbcli use
|
|
215
|
+
|
|
216
|
+
# Switch default connection to 'prod'
|
|
217
|
+
dbcli use prod
|
|
218
|
+
|
|
219
|
+
# List all connections
|
|
220
|
+
dbcli use --list
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
---
|
|
224
|
+
|
|
149
225
|
> **`--use-env-refs`:** When enabled, the config stores environment variable names (e.g., `{"$env": "DB_HOST"}`) instead of actual values. This avoids writing sensitive credentials into the config file, making it suitable for multi-environment deployments and CI/CD pipelines. At connection time, dbcli automatically reads the actual values from the referenced environment variables.
|
|
150
226
|
|
|
151
227
|
---
|
|
@@ -224,12 +300,14 @@ dbcli query "SELECT * FROM users"
|
|
|
224
300
|
|
|
225
301
|
**Options:**
|
|
226
302
|
- `--format json|table|csv` — Output format (default: table)
|
|
227
|
-
- `--
|
|
303
|
+
- `--limit <number>` — Cap rows (overrides the automatic limit in query-only mode)
|
|
304
|
+
- `--no-limit` — Disable the automatic 1000-row cap in query-only mode
|
|
228
305
|
|
|
229
306
|
**Behavior:**
|
|
230
307
|
- Enforces permission-based restrictions (Query-only mode blocks INSERT/UPDATE/DELETE)
|
|
231
|
-
- Auto-limits results to 1000 rows in Query-only mode (notification shown)
|
|
308
|
+
- Auto-limits results to 1000 rows in Query-only mode (notification shown), unless `--no-limit` or `--limit` applies
|
|
232
309
|
- Returns structured results with metadata (row count, execution time)
|
|
310
|
+
- To write CSV/JSON to a file, use shell redirection or the `export` command
|
|
233
311
|
|
|
234
312
|
**Examples:**
|
|
235
313
|
```bash
|
|
@@ -239,8 +317,8 @@ dbcli query "SELECT * FROM users"
|
|
|
239
317
|
# JSON (for AI/programmatic parsing)
|
|
240
318
|
dbcli query "SELECT * FROM users" --format json
|
|
241
319
|
|
|
242
|
-
# CSV
|
|
243
|
-
dbcli query "SELECT * FROM users" --format csv
|
|
320
|
+
# CSV to stdout (redirect to a file)
|
|
321
|
+
dbcli query "SELECT * FROM users" --format csv > users.csv
|
|
244
322
|
|
|
245
323
|
# Pipe to other tools
|
|
246
324
|
dbcli query "SELECT * FROM products" --format json | jq '.data[] | .name'
|
|
@@ -316,9 +394,9 @@ dbcli update users --where "id=2" --set '{"email": "new@example.com"}' --force
|
|
|
316
394
|
|
|
317
395
|
---
|
|
318
396
|
|
|
319
|
-
#### `dbcli delete [table]` (Requires Admin permission
|
|
397
|
+
#### `dbcli delete [table]` (Requires Data-Admin or Admin permission)
|
|
320
398
|
|
|
321
|
-
Delete rows (
|
|
399
|
+
Delete rows (blocked for query-only and read-write; requires elevated DML permission).
|
|
322
400
|
|
|
323
401
|
**Usage:**
|
|
324
402
|
```bash
|
|
@@ -472,6 +550,80 @@ DBCLI_OVERRIDE_BLACKLIST=true dbcli query "SELECT * FROM secrets_vault"
|
|
|
472
550
|
|
|
473
551
|
---
|
|
474
552
|
|
|
553
|
+
#### `dbcli check`
|
|
554
|
+
|
|
555
|
+
Run data-quality and health checks on tables.
|
|
556
|
+
|
|
557
|
+
**Usage:**
|
|
558
|
+
```bash
|
|
559
|
+
dbcli check [table] [OPTIONS]
|
|
560
|
+
```
|
|
561
|
+
|
|
562
|
+
**Options:**
|
|
563
|
+
- `--all` — Check every table (skips huge tables unless `--include-large`)
|
|
564
|
+
- `--include-large` — Include huge tables in `--all` scan
|
|
565
|
+
- `--checks <types>` — Comma-separated checks: `nulls`, `duplicates`, `orphans`, `emptyStrings`, `rowCount`, `size`
|
|
566
|
+
- `--sample <number>` — Sample size for large tables (default: 10000)
|
|
567
|
+
- `--format json|table` — Output format (default: json)
|
|
568
|
+
|
|
569
|
+
**Examples:**
|
|
570
|
+
```bash
|
|
571
|
+
# Check users table
|
|
572
|
+
dbcli check users
|
|
573
|
+
|
|
574
|
+
# Run specific checks only
|
|
575
|
+
dbcli check orders --checks nulls,orphans --format table
|
|
576
|
+
# Scan all tables
|
|
577
|
+
dbcli check --all
|
|
578
|
+
```
|
|
579
|
+
|
|
580
|
+
---
|
|
581
|
+
|
|
582
|
+
**Examples:**
|
|
583
|
+
```bash
|
|
584
|
+
dbcli check orders --format table
|
|
585
|
+
dbcli check --all --checks nulls,duplicates --format json
|
|
586
|
+
```
|
|
587
|
+
|
|
588
|
+
---
|
|
589
|
+
|
|
590
|
+
#### `dbcli diff`
|
|
591
|
+
|
|
592
|
+
Save a schema snapshot or compare the live database to a previous snapshot (tables, columns, indexes).
|
|
593
|
+
|
|
594
|
+
**Usage:**
|
|
595
|
+
```bash
|
|
596
|
+
dbcli diff --snapshot ./schema-before.json
|
|
597
|
+
dbcli diff --against ./schema-before.json
|
|
598
|
+
dbcli diff --against ./schema-before.json --format table
|
|
599
|
+
```
|
|
600
|
+
|
|
601
|
+
**Options:**
|
|
602
|
+
- `--snapshot <path>` — Write the current schema to a JSON file
|
|
603
|
+
- `--against <path>` — Diff live schema vs. the saved snapshot
|
|
604
|
+
- `--format json|table` — Output format (default: `json`)
|
|
605
|
+
- `--config <path>` — Config path (default: `.dbcli`)
|
|
606
|
+
|
|
607
|
+
---
|
|
608
|
+
|
|
609
|
+
#### `dbcli status`
|
|
610
|
+
|
|
611
|
+
Show non-sensitive configuration summary (permission level, DB system, blacklist counts, config metadata version). Does not print connection credentials — intended for AI agents.
|
|
612
|
+
|
|
613
|
+
**Usage:**
|
|
614
|
+
```bash
|
|
615
|
+
dbcli status
|
|
616
|
+
dbcli status --format text
|
|
617
|
+
dbcli status --format json
|
|
618
|
+
```
|
|
619
|
+
|
|
620
|
+
**Options:**
|
|
621
|
+
- `--format text|json` — Output format (default: `json`)
|
|
622
|
+
|
|
623
|
+
**Note:** This command reads the default project config path `.dbcli` (not the global `--config` flag).
|
|
624
|
+
|
|
625
|
+
---
|
|
626
|
+
|
|
475
627
|
#### `dbcli doctor`
|
|
476
628
|
|
|
477
629
|
Run diagnostic checks on environment, configuration, connection, and data.
|
|
@@ -519,6 +671,72 @@ dbcli upgrade --check # Only check, do not upgrade
|
|
|
519
671
|
**Options:** `--check` — check only, don't install
|
|
520
672
|
**Background check:** dbcli silently checks npm registry once per 24 hours. If a newer version is found, a hint is shown after command output.
|
|
521
673
|
|
|
674
|
+
#### `dbcli shell`
|
|
675
|
+
|
|
676
|
+
Interactive database shell with SQL execution, auto-completion, and syntax highlighting.
|
|
677
|
+
|
|
678
|
+
**Usage:**
|
|
679
|
+
```bash
|
|
680
|
+
dbcli shell # Interactive mode (SQL + dbcli commands)
|
|
681
|
+
dbcli shell --sql # SQL-only mode
|
|
682
|
+
```
|
|
683
|
+
|
|
684
|
+
**Inside the shell:**
|
|
685
|
+
- Type SQL statements ending with `;` to execute queries
|
|
686
|
+
- Type dbcli commands without the `dbcli` prefix (e.g., `schema users`, `list`)
|
|
687
|
+
- Press Tab for context-aware auto-completion (SQL keywords, table/column names)
|
|
688
|
+
- Use `.help` for meta commands (`.quit`, `.clear`, `.format`, `.history`, `.timing`)
|
|
689
|
+
- Multi-line SQL: input accumulates until `;` is found
|
|
690
|
+
- History persists across sessions in `~/.dbcli_history`
|
|
691
|
+
|
|
692
|
+
**Permission:** Inherits from config. SQL and commands are fully permission/blacklist enforced.
|
|
693
|
+
|
|
694
|
+
#### `dbcli migrate`
|
|
695
|
+
|
|
696
|
+
Schema DDL operations. **All commands default to dry-run** — use `--execute` to actually run the SQL.
|
|
697
|
+
|
|
698
|
+
**Usage:**
|
|
699
|
+
```bash
|
|
700
|
+
# Create table
|
|
701
|
+
dbcli migrate create posts \
|
|
702
|
+
--column "id:serial:pk" \
|
|
703
|
+
--column "title:varchar(200):not-null" \
|
|
704
|
+
--column "body:text" \
|
|
705
|
+
--column "created_at:timestamp:default=now()"
|
|
706
|
+
|
|
707
|
+
# Execute (actually run the SQL)
|
|
708
|
+
dbcli migrate create posts --column "id:serial:pk" --execute
|
|
709
|
+
|
|
710
|
+
# Drop table (destructive — requires --execute --force)
|
|
711
|
+
dbcli migrate drop posts --execute --force
|
|
712
|
+
|
|
713
|
+
# Column operations
|
|
714
|
+
dbcli migrate add-column users bio text --nullable --execute
|
|
715
|
+
dbcli migrate alter-column users name --type "varchar(200)" --execute
|
|
716
|
+
dbcli migrate alter-column users email --rename user_email --execute
|
|
717
|
+
dbcli migrate drop-column users temp_field --execute --force
|
|
718
|
+
|
|
719
|
+
# Index operations
|
|
720
|
+
dbcli migrate add-index users --columns email --unique --execute
|
|
721
|
+
dbcli migrate drop-index idx_users_email --table users --execute --force
|
|
722
|
+
|
|
723
|
+
# Constraint operations
|
|
724
|
+
dbcli migrate add-constraint orders --fk user_id --references users.id --on-delete cascade --execute
|
|
725
|
+
dbcli migrate add-constraint users --unique email --execute
|
|
726
|
+
dbcli migrate add-constraint users --check "age >= 0" --execute
|
|
727
|
+
dbcli migrate drop-constraint orders fk_orders_user_id --execute --force
|
|
728
|
+
|
|
729
|
+
# Enum (PostgreSQL only)
|
|
730
|
+
dbcli migrate add-enum status active inactive suspended --execute
|
|
731
|
+
dbcli migrate alter-enum status --add-value archived --execute
|
|
732
|
+
dbcli migrate drop-enum status --execute --force
|
|
733
|
+
```
|
|
734
|
+
|
|
735
|
+
**Column spec format:** `name:type[:modifier...]` — Modifiers: `pk`, `not-null`, `unique`, `auto-increment`, `default=<value>`, `references=<table>.<column>`
|
|
736
|
+
|
|
737
|
+
**Options (all subcommands):** `--execute` (run SQL), `--force` (skip confirmation for DROP), `--config <path>`
|
|
738
|
+
**Permission:** admin only
|
|
739
|
+
|
|
522
740
|
---
|
|
523
741
|
|
|
524
742
|
## Global Options
|
|
@@ -534,6 +752,40 @@ All commands support these global options:
|
|
|
534
752
|
|
|
535
753
|
---
|
|
536
754
|
|
|
755
|
+
## Internals & Strategy
|
|
756
|
+
|
|
757
|
+
### Schema Update Strategy
|
|
758
|
+
|
|
759
|
+
dbcli maintains a schema snapshot in your `.dbcli` config file. This allows AI agents to understand the database structure without constant network overhead. Understanding when this cache updates is key:
|
|
760
|
+
|
|
761
|
+
1. **Manual Updates:**
|
|
762
|
+
* `dbcli schema`: Performs a full scan of the database.
|
|
763
|
+
* `dbcli schema --refresh`: Incremental update. Detects changes and updates only the affected tables.
|
|
764
|
+
* `dbcli schema --reset`: Clears the cache and re-fetches everything.
|
|
765
|
+
2. **Automatic Updates (DDL):**
|
|
766
|
+
* When you execute DDL through `dbcli migrate` (e.g., `add-column`), the CLI automatically re-scans the affected table and updates the `.dbcli` snapshot after successful execution.
|
|
767
|
+
3. **Real-time Validation (Non-cached):**
|
|
768
|
+
* Commands like `insert`, `update`, `delete`, and `check` fetch the latest schema from the database immediately before execution to ensure data integrity, but they **do not** update the long-term snapshot in `.dbcli`.
|
|
769
|
+
|
|
770
|
+
> **Note:** If you change the database schema using external tools (like DBeaver or migration scripts), you **must** run `dbcli schema --refresh` to sync the snapshot so AI agents can see the changes.
|
|
771
|
+
|
|
772
|
+
### How `dbcli migrate` Works
|
|
773
|
+
|
|
774
|
+
The `migrate` command follows a strict safety pipeline to prevent accidental database corruption:
|
|
775
|
+
|
|
776
|
+
1. **Permission Check:** Verifies the user has `admin` privileges. DDL is blocked for all other levels.
|
|
777
|
+
2. **Blacklist Check:** Ensures the operation isn't targeting a table restricted in the security blacklist.
|
|
778
|
+
3. **Dialect-Specific Generation:** The `DDLGenerator` translates your request into the correct SQL for your system:
|
|
779
|
+
* **PostgreSQL:** Uses `SERIAL`, native `ENUM` types, and double-quoted identifiers.
|
|
780
|
+
* **MySQL/MariaDB:** Uses `AUTO_INCREMENT`, inline `ENUM` definitions, and backticked identifiers.
|
|
781
|
+
4. **Dry-run (Default):** All commands output the generated SQL for review without executing it.
|
|
782
|
+
5. **Execution & Confirmation:**
|
|
783
|
+
* Requires the `--execute` flag to run.
|
|
784
|
+
* Destructive operations (like `drop`) require both `--execute` and `--force`.
|
|
785
|
+
6. **Snapshot Sync:** After successful execution, it automatically triggers a schema refresh for the modified table to keep your `.dbcli` file up to date.
|
|
786
|
+
|
|
787
|
+
---
|
|
788
|
+
|
|
537
789
|
## Permission Model
|
|
538
790
|
|
|
539
791
|
dbcli implements a coarse-grained permission system with three levels. Permission level is set during `dbcli init` and stored in `.dbcli` config file. The blacklist system works alongside permissions to provide fine-grained protection for sensitive tables and columns (see [Data Access Control](#data-access-control)).
|
|
@@ -542,9 +794,10 @@ dbcli implements a coarse-grained permission system with three levels. Permissio
|
|
|
542
794
|
|
|
543
795
|
| Level | Allowed Commands | Blocked Commands | Use Case |
|
|
544
796
|
|-------|------------------|------------------|----------|
|
|
545
|
-
| **Query-only** | `init`, `list`, `schema`, `query`, `export` (limited to 1000 rows) | `insert`, `update`, `delete` | Read-only AI agents, data analysts, reporting |
|
|
546
|
-
| **Read-Write** | + `insert`, `update` | `delete` | Application developers, content managers |
|
|
547
|
-
| **Admin** |
|
|
797
|
+
| **Query-only** | `init`, `list`, `schema`, `query`, `export` (limited to 1000 rows) | `insert`, `update`, `delete`, `migrate` | Read-only AI agents, data analysts, reporting |
|
|
798
|
+
| **Read-Write** | + `insert`, `update` | `delete`, `migrate` | Application developers, content managers |
|
|
799
|
+
| **Data-Admin** | + `delete` | `migrate` | Full DML access, no DDL |
|
|
800
|
+
| **Admin** | All commands including `migrate` (DDL) | — | Database administrators, schema modifications |
|
|
548
801
|
|
|
549
802
|
### Configuration
|
|
550
803
|
|
|
@@ -552,8 +805,8 @@ Permission level is set during initialization:
|
|
|
552
805
|
|
|
553
806
|
```bash
|
|
554
807
|
dbcli init
|
|
555
|
-
# Prompts:
|
|
556
|
-
# Stored in
|
|
808
|
+
# Prompts: permission level (query-only / read-write / data-admin / admin)
|
|
809
|
+
# Stored in project .dbcli/config.json as: "permission": "query-only"
|
|
557
810
|
```
|
|
558
811
|
|
|
559
812
|
### Permission-Based Examples
|
|
@@ -577,17 +830,18 @@ dbcli query "SELECT * FROM users"
|
|
|
577
830
|
dbcli insert users --data '{"name": "Alice"}'
|
|
578
831
|
dbcli update users --where "id=1" --set '{"name": "Bob"}'
|
|
579
832
|
|
|
580
|
-
# Blocked: Delete (
|
|
581
|
-
dbcli delete users --where "id=1" # ERROR:
|
|
833
|
+
# Blocked: Delete (requires data-admin or admin)
|
|
834
|
+
dbcli delete users --where "id=1" # ERROR: Permission denied (read-write cannot DELETE)
|
|
582
835
|
```
|
|
583
836
|
|
|
584
837
|
#### Admin Mode (Database Administrator)
|
|
585
838
|
```bash
|
|
586
|
-
# Allowed: Everything
|
|
839
|
+
# Allowed: Everything including DDL
|
|
587
840
|
dbcli query "SELECT * FROM users"
|
|
588
841
|
dbcli insert users --data '{"name": "Eve"}'
|
|
589
842
|
dbcli update users --where "id=1" --set '{"status": "active"}'
|
|
590
|
-
dbcli delete users --where "id=1" --force #
|
|
843
|
+
dbcli delete users --where "id=1" --force # Data-Admin+ can delete
|
|
844
|
+
dbcli migrate create posts --column "id:serial:pk" --execute # Admin only
|
|
591
845
|
```
|
|
592
846
|
|
|
593
847
|
### Best Practices
|
|
@@ -700,7 +954,7 @@ After installation, the AI agent will have access to dbcli commands and can use
|
|
|
700
954
|
|
|
701
955
|
#### Claude Code (Anthropic)
|
|
702
956
|
|
|
703
|
-
1. Install dbcli globally: `npm install -g dbcli`
|
|
957
|
+
1. Install dbcli globally: `npm install -g @carllee1983/dbcli`
|
|
704
958
|
2. Initialize: `dbcli init` (choose permission level)
|
|
705
959
|
3. Install skill: `dbcli skill --install claude`
|
|
706
960
|
4. Restart Claude Code extension
|
|
@@ -712,7 +966,7 @@ After installation, the AI agent will have access to dbcli commands and can use
|
|
|
712
966
|
|
|
713
967
|
#### Gemini CLI (Google)
|
|
714
968
|
|
|
715
|
-
1. Install dbcli globally: `npm install -g dbcli`
|
|
969
|
+
1. Install dbcli globally: `npm install -g @carllee1983/dbcli`
|
|
716
970
|
2. Initialize: `dbcli init`
|
|
717
971
|
3. Install skill: `dbcli skill --install gemini`
|
|
718
972
|
4. Start Gemini: `gemini start`
|
|
@@ -724,7 +978,7 @@ After installation, the AI agent will have access to dbcli commands and can use
|
|
|
724
978
|
|
|
725
979
|
#### GitHub Copilot CLI
|
|
726
980
|
|
|
727
|
-
1. Install dbcli globally: `npm install -g dbcli`
|
|
981
|
+
1. Install dbcli globally: `npm install -g @carllee1983/dbcli`
|
|
728
982
|
2. Initialize: `dbcli init`
|
|
729
983
|
3. Install skill: `dbcli skill --install copilot`
|
|
730
984
|
4. Install Copilot CLI: `npm install -g @github-next/github-copilot-cli`
|
|
@@ -736,7 +990,7 @@ After installation, the AI agent will have access to dbcli commands and can use
|
|
|
736
990
|
|
|
737
991
|
#### Cursor IDE
|
|
738
992
|
|
|
739
|
-
1. Install dbcli globally: `npm install -g dbcli`
|
|
993
|
+
1. Install dbcli globally: `npm install -g @carllee1983/dbcli`
|
|
740
994
|
2. Initialize: `dbcli init`
|
|
741
995
|
3. Install skill: `dbcli skill --install cursor`
|
|
742
996
|
4. Open Cursor editor
|
|
@@ -752,7 +1006,7 @@ After installation, the AI agent will have access to dbcli commands and can use
|
|
|
752
1006
|
|
|
753
1007
|
```bash
|
|
754
1008
|
# 1. Install and initialize
|
|
755
|
-
npm install -g dbcli
|
|
1009
|
+
npm install -g @carllee1983/dbcli
|
|
756
1010
|
dbcli init # Choose "query-only" for safety
|
|
757
1011
|
|
|
758
1012
|
# 2. Install skill to Claude Code
|
|
@@ -773,7 +1027,7 @@ dbcli dynamically generates skills based on your current configuration:
|
|
|
773
1027
|
|
|
774
1028
|
```bash
|
|
775
1029
|
# When permission level changes, skill updates automatically
|
|
776
|
-
# Edit
|
|
1030
|
+
# Edit .dbcli/config.json and set "permission" to "admin" (or re-run dbcli init)
|
|
777
1031
|
dbcli skill # Now shows delete and admin commands
|
|
778
1032
|
|
|
779
1033
|
# Re-install to push changes to AI platform
|
|
@@ -812,8 +1066,8 @@ Hostname resolution failed (typo or DNS issue).
|
|
|
812
1066
|
**Solutions:**
|
|
813
1067
|
|
|
814
1068
|
```bash
|
|
815
|
-
# Verify hostname in .dbcli
|
|
816
|
-
|
|
1069
|
+
# Verify hostname in project config (directory layout: .dbcli/config.json)
|
|
1070
|
+
grep host .dbcli/config.json
|
|
817
1071
|
|
|
818
1072
|
# Test DNS resolution
|
|
819
1073
|
ping your-hostname.com
|
|
@@ -833,18 +1087,18 @@ Trying to write with Query-only permission level.
|
|
|
833
1087
|
**Solution:** Re-initialize with higher permission level:
|
|
834
1088
|
|
|
835
1089
|
```bash
|
|
836
|
-
rm
|
|
837
|
-
dbcli init
|
|
1090
|
+
rm -rf .dbcli # Remove project config (destructive — backup if needed)
|
|
1091
|
+
dbcli init # Re-run, choose "read-write", "data-admin", or "admin"
|
|
838
1092
|
```
|
|
839
1093
|
|
|
840
|
-
#### "Permission denied: DELETE requires Admin"
|
|
1094
|
+
#### "Permission denied: DELETE operation requires Data-Admin or Admin"
|
|
841
1095
|
|
|
842
|
-
|
|
1096
|
+
DELETE is not allowed in query-only or read-write mode.
|
|
843
1097
|
|
|
844
|
-
**Solution:**
|
|
1098
|
+
**Solution:** Use `data-admin` or `admin` permission (re-run `dbcli init`, or edit `.dbcli/config.json`), or ask an administrator.
|
|
845
1099
|
|
|
846
1100
|
```bash
|
|
847
|
-
dbcli init # Choose "admin"
|
|
1101
|
+
dbcli init # Choose "data-admin" or "admin"
|
|
848
1102
|
dbcli delete users --where "id=1" --force
|
|
849
1103
|
```
|
|
850
1104
|
|
|
@@ -907,11 +1161,11 @@ npx is downloading and caching package.
|
|
|
907
1161
|
**Solution:** This is normal on first run. Subsequent runs are instant:
|
|
908
1162
|
|
|
909
1163
|
```bash
|
|
910
|
-
npx dbcli init # First run: 30s (downloads)
|
|
911
|
-
npx dbcli init # Second run: <1s (cached)
|
|
1164
|
+
npx @carllee1983/dbcli init # First run: 30s (downloads)
|
|
1165
|
+
npx @carllee1983/dbcli init # Second run: <1s (cached)
|
|
912
1166
|
|
|
913
1167
|
# Or install globally for faster startup
|
|
914
|
-
npm install -g dbcli
|
|
1168
|
+
npm install -g @carllee1983/dbcli
|
|
915
1169
|
dbcli init # All future runs: <1s
|
|
916
1170
|
```
|
|
917
1171
|
|
|
@@ -928,8 +1182,8 @@ npm .cmd wrapper not created or PATH not updated.
|
|
|
928
1182
|
```bash
|
|
929
1183
|
# Restart terminal to refresh PATH
|
|
930
1184
|
# OR reinstall globally
|
|
931
|
-
npm uninstall -g dbcli
|
|
932
|
-
npm install -g dbcli
|
|
1185
|
+
npm uninstall -g @carllee1983/dbcli
|
|
1186
|
+
npm install -g @carllee1983/dbcli
|
|
933
1187
|
|
|
934
1188
|
# Verify installation
|
|
935
1189
|
where dbcli # Windows command to find executable
|
|
@@ -971,7 +1225,12 @@ chmod +x dist/cli.mjs
|
|
|
971
1225
|
|
|
972
1226
|
## Development
|
|
973
1227
|
|
|
974
|
-
|
|
1228
|
+
```bash
|
|
1229
|
+
bun test # run test suite
|
|
1230
|
+
bun run build # bundle CLI to dist/ (used before publish)
|
|
1231
|
+
```
|
|
1232
|
+
|
|
1233
|
+
See [CONTRIBUTING.md](./CONTRIBUTING.md) for full setup, testing, and release process.
|
|
975
1234
|
|
|
976
1235
|
---
|
|
977
1236
|
|