Shell¶
A fast, lightweight command-line shell for exploring, scripting, and debugging Velr databases.
The shell is designed to:
- Start instantly — perfect for one-off commands, scripts, and automation.
- Provide a clean interactive REPL for Cypher exploration.
- Integrate smoothly with Bash, pipes, cron, Makefiles, and CI.
- Support multiple output formats (
plain,styled,csv,tsv,ndjson). - Offer query introspection via
EXPLAINto show the generated SQL.
Overview¶
The shell operates in three modes:
- Interactive mode — the default REPL experience
- Execute mode (
-e/--execute) — run a single query and exit - Stdin mode — read an entire query from pipes or here-docs
You can work on either:
- An in-memory database (default), or
- A persistent file-backed database (pass a path)
All queries, including EXPLAIN, run through the same embedded engine as the Rust and Python drivers.
Basic Usage¶
Run Cypher directly in the REPL:
Every query prints results and a timing line:
Startup is essentially instantaneous — there is no server process or daemon. This makes the shell ideal for Bash scripting.
EXPLAIN — Inspect the Generated SQL Plan¶
Velr lets you inspect how a Cypher query is lowered into SQLite by prefixing any query with:
Example:
The shell prints the SQL plan Velr produces internally. This is extremely useful for:
- Understanding join structure
- Debugging variable-length paths
- Checking index usage
- Optimizing complex graph queries
- Learning how Velr maps Cypher → SQL
You can pipe EXPLAIN output into other tools for analysis:
Modes¶
1. Interactive Mode (REPL)¶
Inside the REPL:
- Enter Cypher queries
- Use
EXPLAIN ...to inspect plans - Use commands starting with
:(see below) - Exit with Ctrl+C, Ctrl+D, or an empty line
2. Execute Mode (-e/--execute)¶
This mode:
- Runs exactly one query
- Prints results
- Exits immediately
Great for scripts:
3. Stdin Mode¶
When stdin is non-empty, Velr reads all of it as a query:
Or with a here-doc:
If stdin is empty, the shell falls back to the REPL.
Output Formats (-f/--format)¶
| Format | Best for |
|---|---|
plain |
Default, simple tables |
styled |
Human-friendly borders/colors |
csv |
Export, analytics pipelines |
tsv |
Unix tools (cut, awk, etc.) |
ndjson |
Machine parsing, jq pipelines |
Examples:
velr my.db -f csv -e "MATCH (u) RETURN u.name, u.age"
velr my.db -f ndjson -e "EXPLAIN MATCH (n) RETURN n"
Strip the timing line for scripts:
Shell Commands (REPL-only)¶
Commands must begin with :.
:source <file>¶
Executes a file containing Cypher:
:help / :h¶
Shows available commands:
Using the Shell in Scripts¶
Because it starts instantly, velr is very comfortable for automation.
Setup / migrations¶
#!/usr/bin/env bash
set -euo pipefail
DB="app.db"
velr "$DB" -e "
CREATE (:User {name:'Root'});
"
velr "$DB" << 'EOF'
UNWIND [
{name:'Alice', age:30},
{name:'Bob', age:25}
] AS r
CREATE (:User {name:r.name, age:r.age});
EOF
Export to CSV¶
velr my.db -f csv -e "
MATCH (u:User)
RETURN u.name AS name, u.age AS age
" \
| grep -v '^Query executed' \
> users.csv
Inspect the SQL plan of a query¶
Summary¶
- Instant startup — great for automation and short-lived commands
- 3 modes: interactive, execute, stdin
- Multiple output formats for humans and machines
:sourcefor loading scriptsEXPLAINto inspect the SQL plan behind any query- Built for scripting, piping, cron jobs, and ad-hoc analysis
- Works with both in-memory and file-backed databases
If you want, I can also generate:
- A “Shell Quickstart” page
- A “Performance Tuning with EXPLAIN” page
- A cookbook of shell examples for migrations, exports, and debugging
Just say the word.