3 releases
| 0.1.3 | Dec 9, 2025 |
|---|---|
| 0.1.2 | Dec 5, 2025 |
| 0.1.1 | Dec 4, 2025 |
#2573 in Database interfaces
14MB
259K
SLoC
VibeSQL CLI
Command-line interface for VibeSQL, providing interactive SQL querying and database management.
Features
Phase 1: Basic REPL
- Interactive SQL prompt with line editing and history
- Execute SQL statements and display results
- Basic table formatting for query results
- Command history and error handling
- Meta-commands:
\help,\q,\d,\dt,\timing
Phase 2: Script Execution & File I/O (Current)
- Execute SQL from files:
vibesql -f script.sql - Execute SQL from stdin:
cat queries.sql | vibesqlorvibesql --stdin - Execute single commands:
vibesql -c "SELECT * FROM users" - Support multiple statements in scripts
- Auto-detection of piped input
- Verbose output mode:
vibesql -f script.sql -v - Execution summary with success/failure counts
- Data import/export utilities (CSV, JSON)
Phase 3: Advanced Features (Current)
- More meta-commands:
\ds(schemas),\di(indexes),\du(roles/users) - Output format control:
\f <format>or--formatflag - Output format options (table, CSV, JSON)
- Query timing and performance statistics
- Automatic output format switching in REPL
Phase 4: Database Management (Future)
- Connection to persistent database files
- Schema introspection enhancements
- Database backup/restore
- Query profiling
- Configuration file support (.vibesqlrc)
- Syntax highlighting
- Multi-line statement editing
Usage
Interactive REPL
# Start interactive session
cargo run --bin vibesql
# Start with specific database
cargo run --bin vibesql -- --database mydb.vsql
Command Execution
# Execute single SQL command
cargo run --bin vibesql -- -c "SELECT 1"
# Execute single SQL command with verbose output
cargo run --bin vibesql -- -c "SELECT 1" -v
File Execution
# Execute SQL from file
cargo run --bin vibesql -- -f script.sql
# Execute SQL from file with verbose output and summary
cargo run --bin vibesql -- -f script.sql --verbose
# Execute with specific output format
cargo run --bin vibesql -- -f script.sql --format json
cargo run --bin vibesql -- -f script.sql --format csv
Stdin Execution
# Execute from stdin (auto-detected when piped)
cat queries.sql | cargo run --bin vibesql
# Or explicitly request stdin
cargo run --bin vibesql -- --stdin < queries.sql
# Pipe from other commands with specific format
echo "SELECT 1; SELECT 2;" | cargo run --bin vibesql -- --format json
Output Formats
# Table format (default, ASCII tables)
cargo run --bin vibesql -- -c "SELECT * FROM users" --format table
# JSON format (array of objects)
cargo run --bin vibesql -- -c "SELECT * FROM users" --format json
# CSV format (comma-separated values)
cargo run --bin vibesql -- -c "SELECT * FROM users" --format csv
Meta-Commands
\d [table] - Describe table or list all tables
\dt - List tables
\ds - List schemas
\di - List indexes
\du - List roles/users
\f <format> - Set output format (table, json, csv)
\timing - Toggle query timing
\h, \help - Show help
\q, \quit - Exit
Format Command Examples
vibesql> \f json
Output format set to: json
vibesql> SELECT * FROM users;
[
{"id": "1", "name": "Alice"},
{"id": "2", "name": "Bob"}
]
vibesql> \f csv
Output format set to: csv
vibesql> SELECT * FROM users;
id,name
1,Alice
2,Bob
vibesql> \f table
Output format set to: table
Example Session
$ vibesql
VibeSQL v0.1.0 - SQL:1999 FULL Compliance Database
Type \help for help, \quit to exit
vibesql> CREATE TABLE users (id INT PRIMARY KEY, name VARCHAR(100));
Table created successfully
vibesql> INSERT INTO users VALUES (1, 'Alice'), (2, 'Bob');
2 rows inserted
vibesql> SELECT * FROM users;
+----+-------+
| id | name |
+----+-------+
| 1 | Alice |
| 2 | Bob |
+----+-------+
2 rows
vibesql> \d users
Table: users
Columns:
id INT PRIMARY KEY
name VARCHAR(100)
vibesql> \quit
Goodbye!
Architecture
The CLI is organized into modules:
main.rs- Entry point, CLI argument parsing, and mode selectionrepl.rs- Interactive REPL implementationexecutor.rs- SQL execution wrapper (SELECT, CREATE, INSERT, UPDATE, DELETE)formatter.rs- Result formatting (table, CSV, JSON)commands.rs- Meta-command parsing and handlingscript.rs- Batch SQL execution from files and stdindata_io.rs- Data import/export utilities (CSV, JSON)error.rs- CLI-specific error types
Dependencies
clap 4- Command-line argument parsingrustyline 13- Line editing and historyprettytable-rs 0.10- Table formattingserde_json 1.0- JSON formattingcsv 1.3- CSV parsing and formattinganyhow 1.0- Error handlingatty 0.2- Terminal detection for stdin piping
Dependencies
~27–45MB
~628K SLoC