CLI & Desktop Studio

Run interactive queries, administer Raft clusters, manage keys and backups with spyd CLI and SpydStudio.

9 min read Getting Started

In addition to the Embedded Web Studio built directly into spyd-server at /studio, SpydDB provides two standalone client tools: spyd (an interactive terminal shell and multi-database CLI) and spyd-studio (a native desktop workbench).


1. Installing spyd Globally#

Install spyd (and the spyd-cli alias) via any of four public channels:

bash
# 1. One-line curl installer (Linux & macOS, verifies SHA-256 checksum)
curl -fsSL https://spyddb-docs.netlify.app/install.sh | sh

# 2. Cargo (crates.io or from repository)
cargo install spyd-cli --locked

# 3. Homebrew (macOS & Linux)
brew install spydotech/tap/spyd

# 4. npm (downloads the verified native binary for your platform)
npm install -g @spyddb/cli

Enable shell tab-completion (Bash, Zsh, Fish, PowerShell, Elvish):

bash
spyd completions bash > ~/.local/share/bash-completion/completions/spyd
spyd completions zsh  > ~/.zfunc/_spyd

2. Full-Screen Interactive Terminal UI (spyd)#

Run spyd with no arguments in an interactive terminal to launch the full-screen workbench (ratatui + crossterm). If no saved credentials exist for the active target, spyd opens the centered Connections & Encrypted Vault modal so you can pick a saved profile, paste a token/password (masked and encrypted into vault.enc), connect to any external database URL, or open an in-memory SQLite scratchpad. Set SPYD_PLAIN=1 (or pipe stdin/stdout) to use the plain line mode instead.

Key workspace features:

  • Top status bar & welcome canvas: displays the active engine badge (spyddb, postgres, mongodb, mysql, sqlite), target host, active profile, database, ๐Ÿ”’ vault indicator, and TX transaction badge.
  • Collapsible Connections & Schema sidebar (Ctrl+B): lists saved multi-DB profiles and live tables/collections with right-aligned column counts (17 cols). Press Tab to focus the sidebar, โ†‘/โ†“ to select an item, Enter to switch profiles or preview rows (/rows <name> 20), and d to describe a table (/describe <name>).
  • Floating / slash command palette: typing / opens a filterable command popup above the composer (โ†‘/โ†“ navigate, Tab complete, Enter run).
  • Floating Connections & Vault modal (Ctrl+P or /profile): switch between saved SpydDB, PostgreSQL, MongoDB, MySQL, and SQLite profiles (Enter), delete profiles and purge their vault secrets (d), or create new connections with masked secret storage (n).
  • Wide table panning & Record Card view (Ctrl+E): tables wider than the terminal show a live horizontal scrollbar (cols 1โ€“96/194). Pan with โ†/โ†’ (when the input box is empty), Shift+โ†/โ†’, Ctrl+โ†/โ†’, Alt+โ†/โ†’, trackpad horizontal scroll, or Shift + Mouse Wheel โ€” or press Ctrl+E (/expanded) to switch immediately to vertical Record Cards with zero horizontal cutoff.
  • Zero-truncation JSON trees & enriched /stats: nested JSON objects (/cluster, /format json, JSON query columns, and nested /stats sections such as pool) render as syntax-highlighted indented trees with automatic byte, microsecond, UTC timestamp, and duration annotations. /stats adds metric descriptions and a latency distribution histogram.
  • Inline ML explanations: results containing ml_explain(...) JSON automatically render a TreeSHAP feature attribution waterfall below the result table.
  • Resilient idle connections: both SpydWire TLS and PostgreSQL/PGWire sessions transparently reconnect if the server closes an idle socket.
Slash CommandAliasPurpose
/help\?, F1Open the floating command & keyboard shortcut reference
/connect <url|db>\cSwitch database or connect live to SpydDB, Postgres, MongoDB, MySQL, or SQLite
/profile [name]Ctrl+POpen the Connections & Vault modal or switch live to [name]
/save <name>โ€”Save the active connection to config.toml and encrypt its secret in vault.enc
/delete-profile <name>โ€”Remove a saved profile and purge its encrypted vault secret
/conninfo\conninfoShow active engine, target, database, profile, vault status, and format
/dbs, /tables, /views, /indexes, /roles, /streams\l, \dt, \dv, \di, \du, \dsIntrospect databases, collections/tables, views, indexes, roles, and streams
/describe <name>\dShow fields, types, and indexes for a collection, view, or role
/rows <name> [limit]/peekPreview rows using the active engine's native syntax (`
/explain <stmt> / /analyze <stmt>โ€”Show execution plan or run explain analyze
/events <coll> [limit]โ€”Stream live committed SSE row changes into the viewport (Esc or Ctrl+C stops cleanly)
/cluster, /extensions, /health, /statsโ€”Inspect cluster topology/HLC/leases/locks/fleet, WASM extensions, health, and telemetry
/format <fmt>, /expanded, /timing, /output [file], /run <file>\format, \x, Ctrl+E, \timing, \o, \iOutput formatting (table, expanded, json, ndjson, csv, tsv, yaml), timing, and script execution
/begin, /commit, /rollback\begin, \commit, \rollbackExplicit multi-statement transaction control (shows TX badge in the header)
/refresh, /clear, /history, /quit\refresh, Ctrl+L, \history, Ctrl+Q, \qReload schema completions, clear viewport, show history path, or exit

Keyboard Shortcuts#

ShortcutActionShortcutAction
/Open floating slash command paletteCtrl+POpen Connections & Encrypted Vault modal
Ctrl+BToggle Connections & Schema sidebarCtrl+EToggle vertical Record Card view
Tab / โ†’Accept hint, complete command, or focus sidebarShift+Enter / Alt+EnterInsert newline in multi-line query
PgUp / PgDn / WheelScroll output verticallyโ†/โ†’, Shift+โ†/โ†’, Ctrl+โ†/โ†’Pan wide tables horizontally
F1Open Help modalCtrl+L / Ctrl+QClear viewport / Quit spyd

3. Encrypted Multi-Database Profiles & Secret Vault#

spyd stores unlimited named connections across SpydDB, PostgreSQL, MongoDB, MySQL, and SQLite with strict separation between metadata and credentials:

  • Metadata (~/.config/spyddb/config.toml, mode 0600): stores target URLs, TLS CA/mTLS paths, usernames, and default databases. Any password embedded in a connection URL (postgres://user:pass@host/db) is automatically stripped and percent-decoded before saving so raw secrets never touch config.toml.
  • Encrypted Vault (~/.local/state/spyddb/vault.enc, mode 0600): stores SpydDB tokens and external database passwords encrypted with AES-256-GCM-SIV, a fresh CSPRNG 96-bit nonce per write, and associated data spyd-cli-vault-v1. Key material and decrypted buffers are zeroized on drop.
  • Fail-closed permissions & optional passphrase: before reading vault.enc or vault.key, spyd checks file permissions (OpenSSH-style) and refuses to open files accessible by group or others (chmod 600 required). Set SPYD_VAULT_PASSPHRASE to mix a user passphrase into the derived vault key via SHA-256.
bash
# Save a SpydDB profile (token encrypted in vault.enc; omitted from config.toml)
spyd --url spydwires://127.0.0.1:5433 --http https://127.0.0.1:8080 \
  --ca tls/ca.crt --server-name localhost --token "$SPYD_TOKEN" config set local

# Save PostgreSQL and MongoDB profiles (URL passwords automatically moved to vault.enc)
spyd --url "postgres://alice:secret@db.internal:5432/orders?sslmode=require" config set prod-pg
spyd --url "mongodb+srv://app:secret@cluster.example.net/catalog" config set prod-mongo

# List profiles with engine and vault badges, switch default, or delete (purges vault secret)
spyd config list
spyd config use local
spyd config delete prod-mongo

4. Universal Database Connectivity (SpydDB Native + Postgres, MongoDB, MySQL, SQLite)#

spyd is native to SpydDB โ€” covering SpydQL, SQL, live SSE event tailing, cluster administration, backups, security, and observability โ€” and also connects directly to external databases using the exact same shell, profiles, /tables//describe//dbs introspection, /connect hot-swapping, and output formats (table, expanded, json, ndjson, csv, tsv, yaml).

EngineTarget URL SchemesCapabilities
SpydDB (Native)spydwire://, spydwires://, http(s)://, grpc(s)://, embedded:<dir>Full SpydQL/SQL, SCRAM/token/mTLS, SSE events, cluster, backup, audit, keys, extensions, apm, alerts, slo
PostgreSQLpostgres://, postgresql://Native tokio-postgres + rustls TLS, parameterized SQL, transactions, Ctrl-C cancel, /tables//views//indexes//describe//dbs
MongoDBmongodb://, mongodb+srv://Native Rust driver + rustls, db.<coll>.find/findOne/insertOne/insertMany/updateOne/deleteOne/aggregate/countDocuments, show dbs, show collections, raw JSON commands
MySQL / MariaDBmysql://, mysqls://Pure Rust + rustls TLS, parameterized SQL, transactions, /tables//views//describe//dbs
SQLitesqlite://path/to.db, sqlite::memory:Bundled SQLite (zero external libs), transactions, /tables//views//indexes//describe//dbs
bash
# Query PostgreSQL, MongoDB, MySQL, or SQLite directly with the same CLI
spyd --url postgres://alice@127.0.0.1:5432/orders sql "SELECT id, total FROM orders LIMIT 10" -o json
spyd --url mongodb://127.0.0.1:27017/shop sql 'db.orders.find({"status": "paid"}).limit(10)'
spyd --url mysql://root@127.0.0.1:3306/shop sql "SHOW TABLES"
spyd --url sqlite://local.db sql "SELECT * FROM products ORDER BY id"

Cross-Database Copy & Migration (spyd copy)#

Stream rows from PostgreSQL, MongoDB, MySQL, SQLite, or another SpydDB instance directly into a SpydDB collection with optional schema inference (--create-collection) and idempotent conflict upserts (--upsert-on):

bash
spyd copy postgres://alice@127.0.0.1:5432/shop spydwires://127.0.0.1:5433 \
  --query "SELECT id, email, total FROM orders ORDER BY id" \
  --into orders \
  --create-collection \
  --upsert-on id \
  --batch-size 500

5. Global Flags, Scripting & Subcommands#

Flag / Env VarPurpose
-P, --profile / SPYD_PROFILESelect saved connection profile (spyd config list/set/use/delete)
--url / SPYD_URLTarget endpoint (SpydDB, Postgres, MongoDB, MySQL, or SQLite)
--http / SPYD_HTTP_URLSpydDB HTTP API endpoint for admin, search, events, extensions, backup, and APM subcommands
-d, --database / SPYD_DATABASETarget database name
--cluster / SPYD_CLUSTERLinked remote cluster to proxy requests to (X-Spyd-Cluster)
--token / SPYD_TOKEN, -U/--user, --authBearer token, SCRAM-SHA-256, password, or cached session (spyd login / spyd logout)
--ca, --server-name, --cert, --keyTLS CA verification and mutual TLS client credentials (SPYD_CA, SPYD_CERT, SPYD_KEY)
-o, --output / SPYD_OUTPUTOutput format: table (default on TTY), expanded, json, ndjson, csv, tsv, yaml (--no-header)

Scripting, Consistency Headers, Live SSE & Operational Subcommands#

spyd sql supports inline statements, -p <JSON> parameters ($1, $2, ...), --file, --continue-on-error, --single-transaction, --timing, and HTTP consistency headers (--idempotency-key, --if-match, --read-hlc):

bash
# Parameterized query from file with timing & idempotency key
spyd sql -f report.spydql -p '"acme"' -p '100' --timing --idempotency-key req-001

# Tail live committed row changes over SSE (with optional Last-Event-ID cursor resume)
spyd events -c orders -e insert -e update --include-before

# Stream query results to gzipped NDJSON
spyd export "events | where created_at >= now() - 7d" --to weekly.ndjson.gz --gzip --overwrite
Subcommand GroupCapabilities Covered
spyd health / whoami / stats / catalog [name]Health check (works on SpydDB and external DBs), identity, engine stats, schema catalog browser
spyd eventsLive SSE row-change subscription (/v1/events/subscribe) with --collection, --event, --where, --from cursor resume
spyd copyCross-DB streaming copy from Postgres, MongoDB, MySQL, SQLite, or SpydDB into SpydDB
spyd extensions list | install | dropManage signed .spydext WebAssembly extensions
spyd query active / cancel <query_id>List running queries and cancel a query ID online
spyd search / suggestCross-collection BM25 search and prefix autocomplete
spyd db list | create | dropLogical database lifecycle management
spyd backup list | create | verify | archive-wal | restoreOnline base backups, verification, WAL archiving, and PITR restore (--into <db>)
spyd keys rotate-column | retire-column | rotate-storage | retire-storageOnline encryption key rotation
spyd audit verifyVerify SHA-256 hash-chain integrity of the audit log
spyd cluster ...topology, node, shard, insert, query, raft, tx, link, ccr, dr, catalog, leases, locks, hlc, fleet, security-sync
spyd replication ...Primary/standby streaming status, follow, lease renewal, fencing, and promote
spyd alerts ... & spyd slo ...Notification channels (webhook, Slack, PagerDuty), threshold/burn-rate rules, evaluate/events, SLO management
spyd apm ... & spyd otlp ...Inspect APM services/traces, configure sampling/synthetics, or push OTLP JSON/protobuf payloads
spyd config ... & spyd completions <shell>Multi-DB connection profile manager (config.toml metadata + AES-256-GCM-SIV vault.enc secrets) and shell completions

CLI Exit Codes#

CodeMeaningCodeMeaning
0Success4Resource or profile not found
1Server or query execution error5Connection or TLS failure
2CLI usage / invalid flag syntax130Interrupted (SIGINT)
3Authentication failure

6. Native Desktop Workbench (spyd-studio)#

For local development and air-gapped administration without a browser, spyd-studio delivers a native GUI desktop client connecting both to remote spyd-server instances and local embedded sandbox directories.

bash
spyd-studio                         # standard launch
spyd-studio --demo                  # launch with a seeded local sandbox
spyd-studio --telemetry             # open straight to live engine telemetry