@carllee1983/dbcli 1.46.0 → 1.47.1

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.
@@ -19,6 +19,28 @@ command-level option is only valid after the command that declares it.
19
19
  | `--config <path>` | Select the `.dbcli` configuration path. |
20
20
  | `--global` | Select the user-global registry at `~/.config/dbcli/config.json` instead of the current project's `.dbcli` config. Place it before the command path. |
21
21
  | `--use <connection>` | Select a named connection for this invocation; place it before the command path unless that command explicitly lists a command-level `--use`. |
22
+ | `--timeout <ms>` | Connection timeout in milliseconds (integer, 100–600000), overriding the connection config's `timeout` field for this invocation. Applies to every engine adapter. Without either the flag or the config field, adapters fall back to their built-in 5000ms default. |
23
+
24
+ `--timeout` is applied only when the adapter is constructed for this invocation — it is
25
+ never written back to `config.json`. Set the connection's `timeout` field instead for a
26
+ value that persists across runs. On PostgreSQL, the same value is also used as the
27
+ session's `statement_timeout` (not just the connection timeout), so a low value can cut
28
+ off a long-running query with an error that looks like a connection timeout; the 100ms
29
+ floor exists specifically to keep that failure mode from being too easy to trigger.
30
+ Elasticsearch applies its timeout per request rather than once for the whole connection.
31
+ The `timeout` field itself always takes a literal number — unlike other connection
32
+ fields, it does not accept an `{"$env": "..."}` reference.
33
+
34
+ ### Redirecting output
35
+
36
+ Results go to stdout; diagnostics (auto-limit notices, warnings, update hints) go to
37
+ stderr. That split is what keeps `--format json` machine-parseable, so do not collapse
38
+ it with `2>&1` — the diagnostic lines land in front of the JSON document and the parse
39
+ fails. Pipe stdout alone, or add `2>/dev/null` when the diagnostics are not wanted:
40
+
41
+ ```bash
42
+ dbcli query '{}' --collection events --format json 2>/dev/null | jq '.rows | length'
43
+ ```
22
44
 
23
45
  ## Commands
24
46
 
@@ -118,6 +140,10 @@ agent mode disabled. A host that needs protection from a same-user hostile
118
140
  process can set `DBCLI_CONFIG_INTEGRITY_ANCHOR_DIR` to a protected or read-only
119
141
  directory; trusted writes publish detached digests there.
120
142
 
143
+ When a connection's config fails schema validation, dbcli reports the specific field
144
+ path(s) that are wrong for that connection's declared `system` — not the raw Zod union
145
+ error tree — so a broken `.dbcli` can be fixed without guessing which branch applies.
146
+
121
147
  ### list
122
148
 
123
149
  List all tables (SQL), collections (MongoDB), keys (Redis), or indices (Elasticsearch).
@@ -197,6 +223,13 @@ dbcli query "SELECT * FROM orders" --format html > orders.html # pipe to stdou
197
223
  **Options:** `--format <table|json|csv|html>`, `--ui` (open the dashboard in the system browser; implies `--format html`), `--limit <number>`, `--no-limit`, `--collection <name>` (MongoDB / Elasticsearch), `--index <name>` (Elasticsearch alias for `--collection`), `--fields <list>`, `--truncate <number>` / `--no-truncate`, `-f, --query-file <path>`, `--use <name[,name]>`, `--recovery`
198
224
  **Permission:** query-only+ (Redis: per-command; Elasticsearch: per HTTP method/path)
199
225
 
226
+ Below `admin`, SQL holding more than one statement is rejected, because only the
227
+ first statement would decide the permission check while a driver on the simple
228
+ query protocol executes them all. Semicolons inside string literals, backtick
229
+ identifiers, and `#` comments are not separators. A MongoDB pipeline containing
230
+ `$out` or `$merge` requires `data-admin`, and is rejected outright on `export`,
231
+ in snippets, and in multi-connection fan-out.
232
+
200
233
  #### Field projection (`--fields`)
201
234
 
202
235
  ```bash
@@ -253,7 +286,7 @@ instead of silently running its only connection.
253
286
  An explicit comma-separated `--use primary,staging` fans one query out to several named
254
287
  connections. `DBCLI_CONNECTION` always names one literal connection and never enables
255
288
  fan-out. SQL permits `SELECT`, `SHOW`, `DESCRIBE`, and `EXPLAIN`; MongoDB permits filters and
256
- read-only pipelines without top-level `$out` / `$merge`; Elasticsearch permits searches.
289
+ read-only pipelines without `$out` / `$merge`; Elasticsearch permits searches.
257
290
  Redis, writes, `--recovery`, `--ui`, CSV, and HTML are rejected before execution. Each
258
291
  connection keeps its own blacklist, limit metadata, audit entry, and error. Aggregate exit
259
292
  codes are `0` when all succeed, `2` for mixed outcomes, and `1` when all fail or preflight
@@ -505,6 +538,13 @@ dbcli q @analytics/revenue --param days=30 --format html > report.html
505
538
 
506
539
  Each `.sql` file is plain SQL with optional YAML frontmatter inside a leading `-- ---` block. Lines outside frontmatter form the SQL body.
507
540
 
541
+ Snippets are read-only by contract, at every permission level including `admin`.
542
+ A body must be a single statement opening with `SELECT` or `WITH` **and** free of
543
+ write or DDL keywords, so a data-modifying CTE (`WITH x AS (DELETE … RETURNING *)
544
+ SELECT * FROM x`) and `SELECT … INTO` are rejected at parse time rather than at
545
+ execution. A MongoDB body may not contain `$out` or `$merge`. The same rule
546
+ applies to `verify.query` in frontmatter, which `q --verify` executes verbatim.
547
+
508
548
  ```sql
509
549
  -- ---
510
550
  -- name: DAU
@@ -2605,6 +2645,8 @@ MongoDB connections use a JSON-based query model instead of SQL. Treat MongoDB s
2605
2645
 
2606
2646
  `init --system mongodb` defaults to a field-by-field wizard (`host`, `srv`, `port`, `user`, `password` + `authSource`, then optional `replicaSet` / `tls`); a full `uri` is an explicit advanced choice in the interactive flow and the unchanged non-interactive path via `--uri`. Optional fields `authSource`, `replicaSet`, `tls`, and `srv` express what previously required embedding options in the `uri` query string. Atlas-style `mongodb+srv://` URIs are supported both as a full `uri` and via the per-field `srv: true` option. `list` and `query` run against the database configured for the connection, and `query` always requires `--collection <name>`.
2607
2647
 
2648
+ The 5000ms default server-selection timeout is often too tight for a connection over a VPN or to Atlas. Set a `timeout` field (ms) in the connection config, or override it per invocation with root-level `--timeout`, e.g. `dbcli --timeout 20000 --use <conn> list`.
2649
+
2608
2650
  **Supported commands:** `init`, `use`, `list`, `schema`, `query`, `q`, `insert`, `update`, `delete`, `export`, `status`, `shell`, `doctor`, `upgrade`, `completion`
2609
2651
 
2610
2652
  **Limited support:**
@@ -2669,7 +2711,7 @@ Redis connections speak Redis commands rather than SQL. The adapter uses Bun's n
2669
2711
 
2670
2712
  - Required fields: `system: redis`, `host`, `port`. `password` and `database` are optional.
2671
2713
  - `database` is the **logical DB index** (`"0"` … `"15"`), kept as a string to play nicely with env-ref bindings. `list` and the connection metadata both label it as the active DB.
2672
- - `connection.timeout` (ms, default 5000) maps to the client's `connectionTimeout`.
2714
+ - `connection.timeout` (ms, default 5000) maps to the client's `connectionTimeout`; root-level `--timeout <ms>` overrides it for a single invocation.
2673
2715
 
2674
2716
  ### Permission classification
2675
2717
 
@@ -2799,7 +2841,7 @@ Elasticsearch connections speak the REST API. The adapter is fetch-based (no SDK
2799
2841
  - Either `host` + `port` (default `https://localhost:9200`) or `nodes: [...]` (first node is used) or `cloudId`.
2800
2842
  - Auth precedence: `apiKey` → `user`/`password` (HTTP Basic). Leave both unset for an open cluster.
2801
2843
  - `protocol` defaults to `https`. For TLS quirks: `caPath` (path to a PEM bundle) and `rejectUnauthorized: false` (last resort).
2802
- - `connection.timeout` (ms, default 5000) is wired to `AbortController` on every request.
2844
+ - `connection.timeout` (ms, default 5000) is wired to `AbortController` on every request; root-level `--timeout <ms>` overrides it for a single invocation.
2803
2845
 
2804
2846
  ### Permission classification
2805
2847