@carllee1983/dbcli 1.45.1 → 1.47.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.
@@ -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
 
@@ -32,10 +54,11 @@ dbcli init --system mysql --host localhost --port 3306 --user root --name mydb
32
54
  dbcli init --use-env-refs # Store env var references
33
55
  dbcli init --no-interactive --force # Non-interactive mode
34
56
 
35
- # MongoDB
36
- dbcli init --system mongodb --uri "mongodb://user:pass@host:27017/mydb?authSource=admin"
37
- dbcli init --system mongodb --host localhost --port 27017 --user admin --password secret --name mydb
57
+ # MongoDB — field-by-field (primary path, same shape as SQL)
58
+ dbcli init --system mongodb --host localhost --port 27017 --user admin --password secret --auth-source admin --name mydb
38
59
  dbcli init --system mongodb --host localhost --port 27017 --name mydb # No auth
60
+ # MongoDB — full URI (advanced fallback: multi-host, non-standard driver options)
61
+ dbcli init --system mongodb --uri "mongodb://user:pass@host:27017/mydb?authSource=admin"
39
62
 
40
63
  # Redis (database = logical DB index)
41
64
  dbcli init --system redis --host localhost --port 6379
@@ -62,7 +85,7 @@ dbcli --global use --list
62
85
 
63
86
  **Environment-reference options:** `--env-host <var>`, `--env-port <var>`, `--env-user <var>`, `--env-password <var>`, `--env-database <var>`
64
87
 
65
- **MongoDB-specific options:** `--uri <uri>` (full connection URI), `--auth-source <db>` (auth database, default: `admin` when user/password set)
88
+ **MongoDB-specific options:** `--uri <uri>` (full connection URI — advanced fallback), `--auth-source <db>` (auth database, default: `admin` when user/password set). Interactive `init` also asks for `replicaSet` and `tls` under an "advanced options?" prompt; there is no dedicated non-interactive flag for either yet — set them interactively or edit `.dbcli` afterward. `srv` (boolean, builds `mongodb+srv://` and resolves hosts via DNS SRV, ignoring `port`) is asked right after `host`, before `port`, since it decides whether `port` is even relevant.
66
89
 
67
90
  **Elasticsearch-specific options:** `--cloud-id <id>` (Elastic Cloud), `--api-key <key>` (ApiKey auth). Other ES fields (`nodes[]`, `protocol`, `caPath`, `rejectUnauthorized`) can be edited directly in `.dbcli`.
68
91
 
@@ -117,6 +140,10 @@ agent mode disabled. A host that needs protection from a same-user hostile
117
140
  process can set `DBCLI_CONFIG_INTEGRITY_ANCHOR_DIR` to a protected or read-only
118
141
  directory; trusted writes publish detached digests there.
119
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
+
120
147
  ### list
121
148
 
122
149
  List all tables (SQL), collections (MongoDB), keys (Redis), or indices (Elasticsearch).
@@ -2025,7 +2052,9 @@ dbcli doctor --format json # JSON output for AI agents
2025
2052
  - Configuration: config file exists/valid, permission level, blacklist completeness (detects unprotected sensitive columns)
2026
2053
  - Connection & Data: database connectivity, schema cache freshness (warns if > 7 days), large table warnings (> 1M rows)
2027
2054
 
2028
- > **MongoDB SRV diagnostics:** When the active connection uses `mongodb+srv://`, `doctor` reports whether the current runtime can resolve SRV records directly or only through the DNS-over-HTTPS fallback used by dbcli. This helps spot execution-environment DNS restrictions even when Compass can connect.
2055
+ > **MongoDB SRV diagnostics:** When the active connection uses `mongodb+srv://` (via a full `uri` or the per-field `srv: true`), `doctor` reports whether the current runtime can resolve SRV records directly or only through the DNS-over-HTTPS fallback used by dbcli. This helps spot execution-environment DNS restrictions even when Compass can connect.
2056
+
2057
+ > **MongoDB connection-field warnings:** `doctor` also warns when a config has both `uri` and per-field values (`host` / `user`) present — `uri` silently wins and the per-field values are ignored — and when `srv: true` is combined with a non-default `port`, since SRV records carry their own ports.
2029
2058
 
2030
2059
  **Exit code:** 0 if all pass or warnings only, 1 if any error
2031
2060
  **Options:** `--format <text|json>`, `--remediation`
@@ -2600,7 +2629,9 @@ Parser behaviour (`src/core/saved-queries/parser.ts::normaliseVisual`):
2600
2629
 
2601
2630
  MongoDB connections use a JSON-based query model instead of SQL. Treat MongoDB support as a narrower document-database path, not as a full SQL feature equivalent.
2602
2631
 
2603
- Atlas-style `mongodb+srv://` URIs are supported. `list` and `query` run against the database configured for the connection, and `query` always requires `--collection <name>`.
2632
+ `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>`.
2633
+
2634
+ 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`.
2604
2635
 
2605
2636
  **Supported commands:** `init`, `use`, `list`, `schema`, `query`, `q`, `insert`, `update`, `delete`, `export`, `status`, `shell`, `doctor`, `upgrade`, `completion`
2606
2637
 
@@ -2623,7 +2654,10 @@ Atlas-style `mongodb+srv://` URIs are supported. `list` and `query` run against
2623
2654
  ### MongoDB-specific workflow
2624
2655
 
2625
2656
  ```bash
2626
- # 1. Initialize (URI or individual params)
2657
+ # 1. Initialize field-by-field (primary path)
2658
+ dbcli init --system mongodb --host localhost --port 27017 \
2659
+ --user admin --password '<secret>' --auth-source admin --name mydb
2660
+ # ...or a full URI (advanced fallback, e.g. Atlas SRV clusters)
2627
2661
  dbcli init --system mongodb --uri "mongodb+srv://user:pass@cluster.example.mongodb.net/mydb"
2628
2662
 
2629
2663
  # 2. List collections
@@ -2663,7 +2697,7 @@ Redis connections speak Redis commands rather than SQL. The adapter uses Bun's n
2663
2697
 
2664
2698
  - Required fields: `system: redis`, `host`, `port`. `password` and `database` are optional.
2665
2699
  - `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.
2666
- - `connection.timeout` (ms, default 5000) maps to the client's `connectionTimeout`.
2700
+ - `connection.timeout` (ms, default 5000) maps to the client's `connectionTimeout`; root-level `--timeout <ms>` overrides it for a single invocation.
2667
2701
 
2668
2702
  ### Permission classification
2669
2703
 
@@ -2793,7 +2827,7 @@ Elasticsearch connections speak the REST API. The adapter is fetch-based (no SDK
2793
2827
  - Either `host` + `port` (default `https://localhost:9200`) or `nodes: [...]` (first node is used) or `cloudId`.
2794
2828
  - Auth precedence: `apiKey` → `user`/`password` (HTTP Basic). Leave both unset for an open cluster.
2795
2829
  - `protocol` defaults to `https`. For TLS quirks: `caPath` (path to a PEM bundle) and `rejectUnauthorized: false` (last resort).
2796
- - `connection.timeout` (ms, default 5000) is wired to `AbortController` on every request.
2830
+ - `connection.timeout` (ms, default 5000) is wired to `AbortController` on every request; root-level `--timeout <ms>` overrides it for a single invocation.
2797
2831
 
2798
2832
  ### Permission classification
2799
2833