Skip to content

Backslash Commands Reference

DBCrust provides a comprehensive set of backslash commands (meta-commands) that help you navigate and manage your database sessions efficiently. These commands are inspired by PostgreSQLโ€™s psql but enhanced with modern features.

Navigation & Info

CommandDescriptionExample
\lList databases\l
\dtList tables\dt
\d [table]Describe table or list all tables\d users
\c <database>Connect to database\c production
\configShow current configuration\config

Display & Output

CommandDescriptionExample
\xToggle expanded display\x
\eToggle EXPLAIN mode\e
\ecopyCopy last EXPLAIN to clipboard\ecopy
\csToggle column selection mode\cs
\csthreshold <n>Set column selection threshold\csthreshold 15
\clrcsClear saved column selections\clrcs
\resetviewReset all view settings\resetview
\serverinfoToggle server info display\serverinfo

File Operations

CommandDescriptionExample
\w <file>Write last script to file\w query.sql
\i <file>Execute SQL file\i setup.sql
\edEdit query in external editor\ed

Named Queries

CommandDescriptionExample
\nList named queries\n
\ns [--scope] <name> <query> [--scope]Save named query with scope\ns --global users SELECT * FROM users
\nd <name>Delete named query\nd users

Sessions & History

CommandDescriptionExample
\s [name]List saved sessions or connect\s or \s prod
\ss <name>Save current connection as session\ss production
\sd <name>Delete saved session\sd oldprod
\rList recent connections\r
\rcClear recent connections\rc

Vault Management

CommandDescriptionExample
\vcShow vault credential cache status\vc
\vccClear all cached vault credentials\vcc
\vcr [role]Force refresh vault credentials\vcr or \vcr my-role
\vceShow expired vault credentials\vce

Password Management

CommandDescriptionExample
\savepassSave password to .dbcrust file (interactive)\savepass
\listpassList stored passwords (without showing passwords)\listpass
\deletepassDelete stored password (interactive selection)\deletepass
\encryptpassEncrypt all plaintext passwords in .dbcrust\encryptpass

MongoDB Operations

CommandDescriptionExample
\collectionsList collections in current database\collections
\dc <collection>Describe collection structure\dc users
\dmiList MongoDB indexes\dmi
\cmi <collection> <field> [type]Create MongoDB index\cmi users email
\ddmi <collection> <index>Drop MongoDB index\ddmi users email_1
\mstatsShow MongoDB database statistics\mstats
\find <collection> [filter] [projection] [limit]Execute MongoDB find query\find users {"active": true}
\aggregate <collection> <pipeline>Execute MongoDB aggregation\aggregate users [{"$match": {"active": true}}]
\search <collection> <term>MongoDB text search\search articles "mongodb tutorial"

Help & Control

CommandDescriptionExample
\hShow help\h
\qQuit DBCrust\q

Lists all databases on the current server.

\l

Output:

โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚ Name โ”‚ Owner โ”‚ Encoding โ”‚ Description โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ myapp_dev โ”‚ postgres โ”‚ UTF8 โ”‚ Development โ”‚
โ”‚ myapp_prod โ”‚ postgres โ”‚ UTF8 โ”‚ Production โ”‚
โ”‚ analytics โ”‚ analyst โ”‚ UTF8 โ”‚ Data warehouseโ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

Lists all tables in the current database.

\dt

Output:

โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚ Schema โ”‚ Name โ”‚ Type โ”‚ Owner โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ public โ”‚ users โ”‚ table โ”‚ postgres โ”‚
โ”‚ public โ”‚ orders โ”‚ table โ”‚ postgres โ”‚
โ”‚ public โ”‚ products โ”‚ table โ”‚ postgres โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

Without arguments, lists all tables. With a table name, shows detailed table structure.

-- List all tables
\d
-- Describe specific table
\d users

Output for \d users:

Table "public.users"
โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚ Column โ”‚ Type โ”‚ Nullable โ”‚ Default โ”‚ Description โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ id โ”‚ integer โ”‚ not null โ”‚ nextval โ”‚ Primary key โ”‚
โ”‚ name โ”‚ character varying โ”‚ not null โ”‚ โ”‚ Full name โ”‚
โ”‚ email โ”‚ character varying โ”‚ not null โ”‚ โ”‚ Email addr โ”‚
โ”‚ created_at โ”‚ timestamp โ”‚ not null โ”‚ now() โ”‚ Created โ”‚
โ”‚ status โ”‚ character varying โ”‚ โ”‚ active โ”‚ User status โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ
Indexes:
"users_pkey" PRIMARY KEY, btree (id)
"users_email_key" UNIQUE CONSTRAINT, btree (email)
"idx_users_status" btree (status)

Switches to a different database on the same server.

\c production_db

Output:

You are now connected to database "production_db" as user "postgres".

Switches between table and expanded (vertical) display formats.

\x

Before (table format):

โ•ญโ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚ id โ”‚ name โ”‚ email โ”‚
โ”œโ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ 1 โ”‚ John Doe โ”‚ john@example.com โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

After (expanded format):

-[ RECORD 1 ]----------
id | 1
name | John Doe
email | john@example.com

Enables or disables automatic EXPLAIN for all queries.

\e -- Enable EXPLAIN mode
SELECT * FROM users WHERE email = 'john@example.com';

Output with EXPLAIN enabled:

โ—‹ Execution Time: 0.89 ms
โ—‹ Planning Time: 0.12 ms
Index Scan using email_idx on users
โ”‚ Index Cond: (email = 'john@example.com'::text)
โ”‚ โ—‹ Cost: 0.29..8.31 โ—‹ Rows: 1 โ—‹ Width: 156
โ””โ”€ Returns: id, name, email, created_at, status
โ•ญโ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚ id โ”‚ name โ”‚ email โ”‚
โ”œโ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ 1 โ”‚ John Doe โ”‚ john@example.com โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

EXPLAIN modes:

\e on -- Basic EXPLAIN
\e analyze -- EXPLAIN ANALYZE
\e verbose -- EXPLAIN VERBOSE
\e buffers -- EXPLAIN (ANALYZE, BUFFERS)
\e off -- Disable EXPLAIN

Copies the last EXPLAIN plan in JSON format to your clipboard.

\ecopy

Output:

EXPLAIN plan copied to clipboard (JSON format)

Enables or disables interactive column selection for all queries. When enabled, all queries will prompt for column selection regardless of the number of columns.

\cs -- Toggle column selection mode on/off

Output:

Column selection is now enabled.

Configures the number of columns that triggers automatic column selection. This setting is saved to your configuration file.

-- Set threshold to 15 columns
\csthreshold 15
-- Set threshold to 5 columns for detailed work
\csthreshold 5

Output:

Column selection threshold set to: 15

Default threshold: 10 columns

When column selection is triggered (either automatically or via \cs mode), an interactive interface appears:

Features:

  • Visual Selection: Checkbox-style interface with arrow key navigation
  • Multi-Select: Use spacebar to select/deselect multiple columns
  • Keyboard Controls:
    • โ†‘/โ†“ Arrow keys: Navigate between columns
    • Space: Toggle column selection
    • Enter: Confirm selection and show results
    • Ctrl+C: Abort query and return to prompt (doesnโ€™t exit DBCrust)

Example Usage:

-- This query has 11 columns, exceeds default threshold of 10
SELECT * FROM users_detailed;

Interactive Interface:

? Select columns to display:
โฏ โ—ฏ id
โ—ฏ username
โ—ฏ email
โ—ฏ first_name
โ—ฏ last_name
โ—ฏ created_at
โ—ฏ updated_at
โ—ฏ last_login
โ—ฏ is_active
โ—ฏ phone
โ—ฏ address
[โ†‘โ†“ to move, space to select, enter to confirm, ctrl+c to abort]

After selection (e.g., selecting id, username, email):

Showing 3 of 11 columns
โ•ญโ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚ id โ”‚ username โ”‚ email โ”‚
โ”œโ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ 1 โ”‚ john_doe โ”‚ john@example.com โ”‚
โ”‚ 2 โ”‚ jane_doe โ”‚ jane@example.com โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

Column selections are automatically remembered during your session:

Behavior:

  • Selections saved per table structure (based on column names)
  • Subsequent queries on same table use saved selection automatically
  • Persists until you clear selections or reset views

Example:

-- First time: interactive selection appears
SELECT * FROM users_detailed;
-- [Select id, username, email]
-- Second time: uses saved selection automatically
SELECT * FROM users_detailed WHERE created_at > '2024-01-01';
-- Shows only id, username, email columns

Removes all saved column selections, returning to fresh selection state for all tables.

\clrcs

Output:

Column views cleared.

After clearing, the next query on any table will prompt for column selection again.

Resets all display settings to defaults, including:

  • Column selections (clears all saved selections)
  • Expanded display mode (\x)
  • EXPLAIN mode (\e)
\resetview

Output:

View settings reset to defaults.

Saves the last executed query or script to a file.

-- Execute a query
SELECT * FROM users WHERE created_at > '2024-01-01';
-- Save it to file
\w recent_users.sql

Output:

Script written to 'recent_users.sql' (156 bytes)

Loads and executes SQL commands from a file.

\i setup_tables.sql

File contents (setup_tables.sql):

CREATE TABLE IF NOT EXISTS users (
id SERIAL PRIMARY KEY,
name VARCHAR(255) NOT NULL,
email VARCHAR(255) UNIQUE NOT NULL,
created_at TIMESTAMP DEFAULT NOW()
);
INSERT INTO users (name, email) VALUES
('Alice Johnson', 'alice@example.com'),
('Bob Smith', 'bob@example.com');

Output:

Executing setup_tables.sql...
CREATE TABLE
INSERT 0 2
Script execution completed successfully.

Opens your default editor to write or edit a query.

\ed

Process:

  1. Opens $EDITOR (vim, nano, code, etc.)
  2. Edit your query
  3. Save and close
  4. Script is loaded and ready - press Enter to execute

Editor integration:

Terminal window
# Set preferred editor
export EDITOR="code --wait" # VS Code
export EDITOR="vim" # Vim
export EDITOR="nano" # Nano

Workflow tip: After using \ed or \i, press Enter on an empty line to re-execute the last loaded script.

DBCrust provides a powerful scoped named query system that allows you to organize queries by visibility scope: global, database-type specific, or session-local.

Global Scope - Available across all database connections and sessions Database-Type Scope - Available only for specific database types (PostgreSQL, MySQL, SQLite) Session-Local Scope - Available only for the current database session (host+port+database+user)

Shows all named queries available in the current context, with scope indicators.

\n

Output:

Named queries:
active_users [global] - SELECT * FROM users WHERE status = 'active'
pg_stats [postgres] - SELECT * FROM pg_stat_activity
daily_summary [session] - SELECT DATE(created_at), COUNT(*) FROM orders
user_report [global] - SELECT u.*, COUNT(o.id) FROM users u LEFT JOIN orders o ON u.id = o.user_id

Scope Priority: Session-local queries take precedence over database-type queries, which take precedence over global queries when names conflict.

\ns [--scope] <name> <query> [--scope] - Save Named Query with Scope

Section titled โ€œ\ns [--scope] <name> <query> [--scope] - Save Named Query with Scopeโ€

Saves a query with a name and optional scope specification. Supports parameter substitution.

Scope Options:

  • -g / --global - Available for all database connections
  • --postgres - Available only for PostgreSQL connections
  • --mysql - Available only for MySQL connections
  • --sqlite - Available only for SQLite connections
  • No flag (default) - Session-local scope (current database session only)

Scope flags can be placed before the name, between the name and query, or after the query.

Basic Examples:

-- Session-local query (default)
\ns active_users SELECT * FROM users WHERE status = 'active'
-- Global query - flag before name (recommended)
\ns --global count_all SELECT COUNT(*) FROM $1
-- Global query - flag after query (also works)
\ns count_all SELECT COUNT(*) FROM $1 --global
-- PostgreSQL-specific query
\ns --postgres pg_activity SELECT * FROM pg_stat_activity
-- MySQL-specific query
\ns --mysql mysql_status SHOW GLOBAL STATUS LIKE 'Connections'
-- SQLite-specific query
\ns --sqlite sqlite_tables SELECT name FROM sqlite_master WHERE type='table'

Parameter Substitution:

-- Single parameter
\ns --global user_by_id SELECT * FROM users WHERE id = $1
-- Multiple parameters
\ns user_orders SELECT * FROM orders WHERE user_id = $1 AND status = '$2'
-- All remaining parameters (space-separated)
\ns --global search_users SELECT * FROM users WHERE name ILIKE '%$*%'
-- All remaining parameters (single string)
\ns full_search SELECT * FROM users WHERE CONCAT(first_name, ' ', last_name) ILIKE '%$@%'

Advanced Scope Examples:

-- Database-type specific reporting queries
\ns --postgres pg_table_sizes SELECT schemaname, tablename, pg_size_pretty(pg_total_relation_size(schemaname||'.'||tablename)) as size FROM pg_tables
\ns --mysql mysql_table_info SELECT table_name, table_rows, data_length FROM information_schema.tables WHERE table_schema = DATABASE()
-- Global utility queries
\ns --global today_records SELECT * FROM $1 WHERE DATE(created_at) = CURRENT_DATE
-- Session-specific queries (no flag needed)
\ns my_analysis SELECT customer_id, SUM(amount) FROM local_sales_data GROUP BY customer_id

Query Execution:

-- Execute named queries with parameters
active_users
user_by_id 123
user_orders 123 completed
search_users John Doe
pg_table_sizes

Save Confirmation:

Named query 'active_users' saved successfully (scope: session-local).
Named query 'pg_activity' saved successfully (scope: postgres).
Named query 'count_all' saved successfully (scope: global).

Removes a named query from the current context. Automatically detects the scope of the query to delete.

\nd active_users

Output:

Named query 'active_users' deleted successfully (scope: session-local).

Scope Resolution: When deleting, DBCrust follows the same priority order as execution - it will delete the session-local query first, then database-type, then global if multiple queries exist with the same name.

Development Workflow:

-- Create session-specific analysis queries during development
\ns debug_orders SELECT * FROM orders WHERE created_at > '2024-01-01' AND status = 'pending'
-- Create global utilities for reuse across projects
\ns --global table_info SELECT table_name, table_rows FROM information_schema.tables WHERE table_schema = '$1'
-- Create database-specific maintenance queries
\ns --postgres pg_vacuum_analyze VACUUM ANALYZE $1

Team Collaboration:

-- Global queries shared across team
\ns --global daily_metrics SELECT DATE(created_at), COUNT(*), AVG(amount) FROM orders WHERE created_at >= CURRENT_DATE - INTERVAL '7 days' GROUP BY DATE(created_at)
-- Database-specific performance queries
\ns --postgres pg_slow_queries SELECT query, calls, total_time, mean_time FROM pg_stat_statements ORDER BY mean_time DESC LIMIT 10

Multi-Database Projects:

-- PostgreSQL analytics
\ns --postgres user_engagement SELECT user_id, COUNT(*) as actions FROM user_events WHERE created_at > $1 GROUP BY user_id
-- MySQL equivalent
\ns --mysql user_engagement SELECT user_id, COUNT(*) as actions FROM user_events WHERE created_at > '$1' GROUP BY user_id
-- Global fallback
\ns --global simple_count SELECT COUNT(*) FROM $1

The named query system provides intelligent autocomplete:

Query Name Completion:

\n act[TAB] -- Shows: active_users
\ns my_qu[TAB] -- Shows existing query names for overwriting
\nd debug[TAB] -- Shows: debug_orders

Scope Flag Completion:

\ns --glo[TAB] -- Shows: --global (at start)
\ns myquery SELECT 1 --post[TAB] -- Shows: --postgres (at end)

SQL Completion:

\ns myquery SELE[TAB] -- Shows: SELECT, SELECT *, etc.
\ns myquery SELECT * FROM use[TAB] -- Shows: users table

Named queries are stored separately by scope:

  • Global: Available across all sessions and database types
  • Database-type: Available for all sessions of that database type
  • Session-local: Available only for the specific database session

Storage Location: ~/.config/dbcrust/named_queries.toml

Migration: Existing named queries from older versions are automatically migrated to the new scoped system as global queries during the first run.

Without arguments, lists all saved sessions. With a session name, connects to that session.

-- List all saved sessions
\s

Output:

Saved Sessions:
production - PostgreSQL postgres@prod.db.com:5432/myapp
staging - PostgreSQL postgres@staging.db.com:5432/myapp_staging
local_mysql - MySQL root@localhost:3306/testdb
analytics - SQLite /data/analytics.db
Use 'session://<name>' to connect via command line
-- Connect to a saved session
\s production

Output:

Connecting to saved session 'production'...
โœ“ Successfully connected to database

Saves the current connection as a named session for quick reconnection.

\ss production

Output:

Session 'production' saved successfully

Removes a saved session.

\sd old_staging

Output:

Deleted session 'old_staging'

Shows your recent connection history with full URLs (excluding passwords).

\r

Output:

Recent Connections:
[1] โœ“ docker://postgres@myapp-postgres/myapp_dev - 2024-01-15 14:22 (PostgreSQL)
[2] โœ“ postgres://user@localhost:5432/testdb - 2024-01-15 14:15 (PostgreSQL)
[3] โœ— mysql://root@badhost:3306/db - 2024-01-15 14:10 (MySQL)
[4] โœ“ sqlite:///home/user/data.db - 2024-01-15 13:55 (SQLite)
Use 'recent://' to interactively select and connect to a recent connection

Clears all connection history.

\rc

Output:

Cleared all recent connections
Configuration saved

DBCrust provides intelligent caching for HashiCorp Vault dynamic credentials to improve performance and reduce Vault API calls.

Displays all cached Vault credentials with their expiration status and remaining TTL.

\vc

Output:

Vault credential cache status (showing 2 entries):
database/myapp-prod/readonly (v-user-prod--ABC123-1234567890) - 0h58m remaining - VALID
database/myapp-dev/admin (v-user-dev--XYZ789-9876543210) - 0h02m remaining - EXPIRES SOON

Status indicators:

  • VALID: Credentials have sufficient TTL remaining
  • EXPIRES SOON: Credentials below renewal threshold (default: 25% of original TTL)
  • EXPIRED: Credentials past expiration time (automatically cleaned up)

Removes all cached vault credentials, forcing fresh authentication on next vault:// connection.

\vcc

Output:

Cleared all cached vault credentials (2 entries removed)

Forces refresh of Vault credentials, either for all cached entries or a specific role.

-- Refresh all cached credentials
\vcr
-- Refresh specific role
\vcr readonly

Output:

Refreshed vault credentials for role 'readonly'
New credentials valid for 1h0m

Use cases:

  • Force credential renewal before long-running operations
  • Refresh credentials that are near expiration
  • Update credentials after Vault policy changes

Lists vault credentials that have expired but havenโ€™t been cleaned up yet.

\vce

Output:

Expired vault credentials (1 entry):
database/myapp-staging/readonly - expired 0h15m ago

Automatic Caching:

  • Credentials are automatically cached when using vault:// URLs
  • Cache persists between DBCrust sessions
  • Stored in encrypted file: ~/.config/dbcrust/vault_credentials.enc

Cache Validation:

  • Credentials are checked for expiration before use
  • TTL threshold prevents using credentials that expire soon (default: 5 minutes minimum)
  • Automatic cleanup removes expired credentials

Security Features:

  • All cached credentials are encrypted using AES-256-GCM
  • Encryption key derived from your Vault token
  • Cache automatically invalidated if Vault token changes

Configuration:

~/.config/dbcrust/config.toml
vault_credential_cache_enabled = true # Enable/disable caching
vault_cache_renewal_threshold = 0.25 # Renew when 25% TTL remaining
vault_cache_min_ttl_seconds = 300 # Minimum 5 minutes required
-- First connection: fetches and caches credentials
dbcrust vault://readonly@database/myapp-prod
-- Check cache status
\vc
-- Output: database/myapp-prod/readonly (v-user--ABC123-1234567890) - 0h59m remaining - VALID
-- Reconnect quickly using cached credentials
dbcrust vault://readonly@database/myapp-prod
-- Uses cached credentials, no Vault API call
-- Force refresh if needed
\vcr readonly
-- Clear cache when done
\vcc

DBCrust provides comprehensive MongoDB support with both native MongoDB commands and familiar SQL-like syntax for database and collection management.

MongoDB database and collection operations can be performed using familiar SQL syntax:

Database Operations:

-- Create a new database
CREATE DATABASE analytics;
-- Drop an existing database
DROP DATABASE old_analytics;

Collection Operations:

-- Create a new collection
CREATE COLLECTION user_profiles;
-- Drop an existing collection
DROP COLLECTION temp_data;

Lists all collections in the current MongoDB database.

\collections

Output:

โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚ Collection โ”‚ Type โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ users โ”‚ collection โ”‚
โ”‚ orders โ”‚ collection โ”‚
โ”‚ products โ”‚ collection โ”‚
โ”‚ sessions โ”‚ collection โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

Shows the structure and sample documents from a MongoDB collection.

\dc users

Output:

Collection: users
Sample Documents: 3
Field Structure:
โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚ Field โ”‚ Type โ”‚ Sample Value โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ _id โ”‚ ObjectId โ”‚ 507f1f77... โ”‚
โ”‚ email โ”‚ String โ”‚ user@email.com โ”‚
โ”‚ name โ”‚ String โ”‚ John Doe โ”‚
โ”‚ active โ”‚ Boolean โ”‚ true โ”‚
โ”‚ created_at โ”‚ DateTime โ”‚ 2024-01-15 โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

\dmi - List MongoDB Indexes:

\dmi

Shows all indexes across collections in the current database.

\cmi <collection> <field> [type] - Create Index:

-- Create standard index
\cmi users email
-- Create text index for search
\cmi articles content text

\search <collection> <term> - Text Search:

-- Search for documents containing specific terms
\search articles "mongodb tutorial"
-- Search with multiple terms
\search products "wireless bluetooth"

DBCrust supports advanced SQL-to-MongoDB translation with sophisticated filtering:

LIKE Pattern Matching:

-- SQL LIKE translates to MongoDB $regex
SELECT * FROM users WHERE name LIKE 'John%';
-- โ†’ MongoDB: {"name": {"$regex": "John.*", "$options": "i"}}

IN Operator:

-- SQL IN translates to MongoDB $in
SELECT * FROM orders WHERE status IN ('pending', 'processing');
-- โ†’ MongoDB: {"status": {"$in": ["pending", "processing"]}}

OR Conditions:

-- SQL OR translates to MongoDB $or
SELECT * FROM users WHERE age > 18 OR verified = true;
-- โ†’ MongoDB: {"$or": [{"age": {"$gt": 18}}, {"verified": true}]}

BETWEEN Ranges:

-- SQL BETWEEN translates to MongoDB $gte + $lte
SELECT * FROM products WHERE price BETWEEN 10 AND 100;
-- โ†’ MongoDB: {"price": {"$gte": 10, "$lte": 100}}

NULL Handling:

-- SQL IS NULL/IS NOT NULL translates to MongoDB $exists
SELECT * FROM users WHERE email IS NOT NULL;
-- โ†’ MongoDB: {"email": {"$exists": true, "$ne": null}}
-- Connect to MongoDB
dbcrust mongodb://localhost:27017/myapp
-- List collections
\collections
-- Examine a collection structure
\dc users
-- Query with advanced filtering
SELECT * FROM users
WHERE name LIKE 'John%'
AND age BETWEEN 18 AND 65
AND status IN ('active', 'verified');
-- Create collection with SQL syntax
CREATE COLLECTION user_sessions;
-- Drop collection when no longer needed
DROP COLLECTION temp_analytics;
-- Create index for better performance
\cmi users email
-- Perform text search
\search users "john developer"
-- Switch database and list tables
\c analytics
\dt
-- Enable EXPLAIN and run query
\e on
SELECT COUNT(*) FROM large_table;
-- Save result and write to file
\w large_table_count.sql
-- Create a setup script
\ed
-- In editor, write:
-- \c development
-- \i create_tables.sql
-- \i seed_data.sql
-- \dt
-- Save and execute automatically
-- Start with simple query
SELECT * FROM users LIMIT 5;
-- Refine in editor
\ed
-- Save final version
\w final_user_report.sql
-- Create named query for reuse
\ns user_report SELECT u.*, COUNT(o.id) as order_count FROM users u LEFT JOIN orders o ON u.id = o.user_id GROUP BY u.id