Improved REPL Help Display with Examples
Improved REPL Help Display with Examples
Overview
This document shows the proposed improved help system for HeliosDB Nano REPL with:
- Multi-column layout (2-column on narrow terminals, 3-column on wide)
- Integrated examples showing actual usage
- Organized by feature category
- Quick reference format
1. Current Help Display (1130 lines of commands.rs)
Current structure:
fn print_help() { println!("{}", "HeliosDB Nano v2.6 REPL Commands".bold()); // Lists all commands with single description // Examples in separate section // No column layout}Problems:
- All commands listed sequentially
- Examples separated from commands
- No terminal-width awareness
- Hard to scan for quick reference
- Too much text at once
2. Improved Help Display Examples
A. Narrow Terminal (80-100 columns) - 2 Column Layout
╔════════════════════════════════════════════════════════════════════════════╗║ HeliosDB Nano v2.6 REPL Commands ║║ Quick Reference Guide ║╚════════════════════════════════════════════════════════════════════════════╝
BASIC COMMANDS
\q, \quit List tables \exit Quit REPL and exit
\h, \help Show help (you are here) \?, \about Show version and info
SCHEMA EXPLORATION
\d List all tables \d users Describe 'users' table schema Example: \d orders
\dt List tables with column count \dS List system views \dS <view> Show system view schema Example: \dS pg_database_branches
v2.0 DATABASE FEATURES
\branches List database branches Example: CREATE BRANCH dev FROM main;
\use <branch> Switch to branch Example: \use dev
\snapshots List time-travel snapshots Example: SELECT * FROM orders AS OF TIMESTAMP '2025-11-23';
v2.1 ADMIN COMMANDS
\set Show all REPL variables \set <var> <val> Set REPL variable Example: \set search_path public
\config Show current configuration \config reload Reload from file
\optimize <table> Show optimization recommendations Example: \optimize large_table
v2.6 AI FEATURES
\ai templates List AI schema templates \ai template <name> Show template schema Example: \ai template ecommerce
\ai infer [format] Infer schema from data Example: \ai infer json
\ai generate <desc> Generate schema from description Example: \ai generate "e-commerce"
SQL QUICK START
Semi-colon (;) required to execute Multi-line input supported (-> continuation prompt) Ctrl-C to cancel, Ctrl-D to exit
CREATE TABLE users ( id INT PRIMARY KEY, name TEXT NOT NULL );
SELECT * FROM users;
TIMING & DISPLAY
\timing Toggle query timing on/off \show lsn Toggle transaction number display \show branch Show current branch
─────────────────────────────────────────────────────────────────────────────Type \h <category> for more details, or browse help.txt for full referenceB. Wide Terminal (120+ columns) - 3 Column Layout
╔══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╗║ HeliosDB Nano v2.6 REPL Commands - 3 Column Quick Reference ║╚══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╝
BASIC COMMANDS
\q, \quit, \exit │ \h, \help, \? │ \timing, \show lsn Quit REPL │ Show this help │ Toggle query timing Example: \quit │ Example: \help │ Example: \timing
SCHEMA COMMANDS (PostgreSQL-compatible)
\d [table] │ \dt │ \dS [view] List tables or describe │ List tables detailed │ List/describe system views \d users │ \dt │ \dS pg_database_branches
TABLE INFORMATION
\compression [table] │ \stats │ \indexes <table> Show compression stats │ Database statistics │ Index recommendations \compression orders │ \stats │ \indexes customers
v2.0: DATABASE BRANCHING & TIME-TRAVEL
\branches │ \use <branch> │ \snapshots List database branches │ Switch to branch │ List time-travel snapshots Example: │ Example: │ Example: CREATE BRANCH dev │ \use dev │ SELECT * FROM users FROM main; │ │ AS OF TIMESTAMP '...';
v2.1: ADMINISTRATION
\config │ \server [status] │ \ssl [status] Show configuration │ Server status/control │ SSL/TLS configuration \config │ \server status │ \ssl status
\user [list] │ \password <user> │ \optimize <table> User management │ Change password │ Optimization recommendations \user list │ \password alice │ \optimize users
v2.6: AI & SCHEMA FEATURES
\ai templates │ \ai template <name> │ \ai infer [format] List AI schema templates │ Show template DDL │ Infer schema from data Example: \ai templates │ Example: │ Example: (lists: ecommerce, blog, │ \ai template blog │ \ai infer json rag, agents, etc.) │ │ (requires data input)
\ai generate <desc> │ \ai optimize <table> │ Generate schema from text │ AI optimization hints │ Example: \ai generate │ Example: │ "saas app with users" │ \ai optimize orders │
QUERY & PERFORMANCE
EXPLAIN SELECT ... │ \profile <query> │ SET optimizer = on; Query execution plan │ Profile query timing │ Enable query optimizer Example: │ Example: │ Example: EXPLAIN SELECT * FROM │ Profile SELECT * │ SET optimizer = on; users; │ FROM users; │ SHOW optimizer;
SQL EXAMPLES BY USE CASE
CREATE TABLE users ( │ SELECT * FROM users │ INSERT INTO users id INT PRIMARY KEY, │ WHERE active = true │ VALUES (1, 'Alice'); name TEXT NOT NULL │ ORDER BY created_at; │ UPDATE users ); │ │ SET name = 'Bob' CREATE INDEX idx_name │ DELETE FROM users │ WHERE id = 1; ON users(name); │ WHERE id = 999; │
TIME-TRAVEL QUERIES (v2.0)
SELECT * FROM table │ SELECT * FROM table │ SELECT * FROM table AS OF TIMESTAMP │ AS OF TRANSACTION │ AS OF BRANCH dev '2025-11-23 10:00:00'; │ 12345; │ MERGE BRANCH dev │ │ INTO main;
BRANCHING OPERATIONS (v2.0)
CREATE DATABASE BRANCH │ DROP DATABASE BRANCH │ MERGE DATABASE BRANCH dev FROM main AS OF NOW; │ dev; │ dev INTO main;
MATERIALIZED VIEWS (v2.0)
CREATE MATERIALIZED VIEW │ REFRESH MATERIALIZED │ SELECT * FROM user_stats AS │ VIEW user_stats; │ pg_mv_staleness(); SELECT user_id, │ │ COUNT(*) FROM orders │ │ -- Shows staleness GROUP BY user_id │ │ info for MV auto-refresh WITH (auto_refresh=true, │ │ max_cpu_percent=15) │ │
VECTOR OPERATIONS (v2.1)
CREATE TABLE vectors ( │ CREATE INDEX │ SELECT * FROM id SERIAL PRIMARY KEY,│ idx_vec ON vectors │ vectors embedding VECTOR(384) │ USING hnsw(embedding) │ ORDER BY ); │ WITH (m=16, │ embedding <-> query INSERT INTO vectors │ ef_construction=200); │ LIMIT 10; VALUES (...); │ │
DOCUMENT STORAGE & RAG (Upcoming)
-- Store documents │ -- Search documents │ -- Batch operations INSERT INTO documents │ SELECT * FROM │ Multiple inserts: (source, content, │ documents │ INSERT INTO docs metadata) VALUES (...); │ WHERE content │ VALUES (...), (...); │ ILIKE '%search%'; │
SETTINGS & CONFIGURATION
SET optimizer = on; │ SET work_mem = 8192; │ SHOW ALL; SET statement_timeout │ SET search_path = │ SHOW optimizer; = 30000; │ public; │ SHOW work_mem;
─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────For full help on a topic: \h basic \h schema \h v2.0 \h v2.1 \h v2.6 \h sql \h examplesC. Category-Specific Help Views
Help for Basic Commands: \h basic
╔═══════════════════════════════════════════════════════════════════════════╗║ BASIC COMMANDS - Full Details ║╚═══════════════════════════════════════════════════════════════════════════╝
\q, \quit, \exit Exit HeliosDB REPL and close database connection.
Examples: heliosdb [main] > \quit -- Disconnects from database and returns to shell prompt
\h, \help, \? Display command help. Can be used with category names for specific help.
Examples: heliosdb [main] > \help -- Show this help heliosdb [main] > \help schema -- Schema exploration commands heliosdb [main] > \help v2.0 -- v2.0 features (branching, time-travel)
\timing Toggle query execution timing display on/off. Useful for performance testing.
Examples: heliosdb [main] > \timing -- Enable timing Timing is on heliosdb [main] > SELECT * FROM users; (10 rows) (5.23 ms) heliosdb [main] > \timing -- Disable timing Timing is off
\show lsn Toggle display of Log Sequence Number (LSN) and transaction information. Shows transaction ID and exact LSN position.
Examples: heliosdb [main] > \show lsn -- Enable LSN display LSN/Transaction display enabled heliosdb [main] > SELECT * FROM users; (10 rows) [LSN: 0x00000001, TXN: 1]
\show branch Display current database branch and its ID.
Examples: heliosdb [main] > \show branch Branch: main (ID: 0) heliosdb [dev] > \show branch Branch: dev (ID: 1)Help for Schema: \h schema
╔═══════════════════════════════════════════════════════════════════════════╗║ SCHEMA EXPLORATION COMMANDS - Full Details ║╚═══════════════════════════════════════════════════════════════════════════╝
\d [table_name] List all tables, or describe a specific table's schema. Shows column name, type, nullable status, and primary key info.
Examples: heliosdb [main] > \d -- List all tables Tables: users orders products
heliosdb [main] > \d users -- Describe users table Table: users ────────────────────────────────────────────────── Column Type Nullable Primary Key ────────────────────────────────────────────────── id Int4 NO YES name Text NO email Text NO created_at Timestamp YES ──────────────────────────────────────────────────
\dt List all tables with column count. Similar to \d but more compact.
Examples: heliosdb [main] > \dt Tables: ──────────────────────────────────── Name Columns ──────────────────────────────────── users 4 orders 5 products 6 ────────────────────────────────────
\dS [view_name] List all system views (pg_database_branches, pg_mv_staleness, etc.). Show schema of specific system view with full column definitions.
Examples: heliosdb [main] > \dS -- List system views System Views (Phase 3): pg_database_branches - Lists all database branches with metadata pg_mv_staleness - Shows staleness info for materialized views pg_vector_index_stats - Vector index statistics (PQ compression)
heliosdb [main] > \dS pg_database_branches System View: pg_database_branches ────────────────────────────────────────────────────────── Column Type Nullable ────────────────────────────────────────────────────────── branch_id Int8 NO branch_name Text NO parent_branch_id Int8 YES created_at Timestamp NO base_lsn Int8 NO ──────────────────────────────────────────────────────────
\compression [table_name] Show compression statistics for all tables or specific table. Displays compression ratio, storage savings, method used.
Examples: heliosdb [main] > \compression Compression Statistics: ────────────────────────────────────────────────── Table Method Ratio Size ────────────────────────────────────────────────── orders Zstd 3.2x 512 MB products Zstd 2.8x 256 MB ──────────────────────────────────────────────────
heliosdb [main] > \compression orders Compression Statistics: orders Method: Zstd Ratio: 3.2x Original: 1.6 GB Compressed: 512 MB Savings: 1.1 GB
ALTER TABLE orders SET COMPRESSION lz4;
\stats Display overall database statistics: table count, total size, etc.
Examples: heliosdb [main] > \stats Database Statistics: Tables: 3 Total Size: 768 MB Compression Enabled: Yes Branches: 2 Snapshots: 45Help for v2.0: \h v2.0
╔═══════════════════════════════════════════════════════════════════════════╗║ v2.0 FEATURES: BRANCHING & TIME-TRAVEL - Full Details ║╚═══════════════════════════════════════════════════════════════════════════╝
DATABASE BRANCHING (Git-like version control for databases)
\branches List all database branches and their metadata. Shows branch name, parent, creation date, and base LSN.
Examples: heliosdb [main] > \branches Database Branches: ──────────────────────────────────────────── Name Parent Created LSN ──────────────────────────────────────────── main - 2025-11-01 0x1000 dev main 2025-11-15 0x2000 feature/x dev 2025-11-20 0x3000 ────────────────────────────────────────────
\use <branch_name> Switch current working branch. All subsequent queries use this branch. Similar to `git checkout <branch>`.
Examples: heliosdb [main] > \use dev Switching to branch: dev heliosdb [dev] > SELECT * FROM users; -- Uses dev branch data
heliosdb [dev] > \use main Switching to branch: main heliosdb [main] > SELECT * FROM users; -- Uses main branch data
CREATE DATABASE BRANCH Create a new database branch from an existing branch at a specific point.
Examples: -- Create a branch at current time heliosdb [main] > CREATE DATABASE BRANCH dev FROM main AS OF NOW; Branch 'dev' created from 'main'
-- Create a branch at specific timestamp heliosdb [main] > CREATE DATABASE BRANCH test FROM main AS OF TIMESTAMP '2025-11-15 10:30:00'; Branch 'test' created at 2025-11-15 10:30:00
-- Create a branch at specific transaction heliosdb [main] > CREATE DATABASE BRANCH backup FROM main AS OF TRANSACTION 12345; Branch 'backup' created at transaction 12345
MERGE DATABASE BRANCH Merge changes from one branch into another (like `git merge`).
Examples: heliosdb [main] > MERGE DATABASE BRANCH dev INTO main; Merging branch 'dev' into 'main'... Merge completed (1,000 rows modified)
DROP DATABASE BRANCH Delete a branch (like `git branch -d`).
Examples: heliosdb [main] > DROP DATABASE BRANCH test; Branch 'test' deleted
TIME-TRAVEL QUERIES (Query data at any point in time)
SELECT * FROM table AS OF TIMESTAMP Query table state at a specific point in time.
Examples: heliosdb [main] > SELECT * FROM users AS OF TIMESTAMP '2025-11-15 14:30:00'; (Shows user data as it was on Nov 15 at 2:30 PM)
-- Get user count from yesterday heliosdb [main] > SELECT COUNT(*) FROM users AS OF TIMESTAMP NOW() - INTERVAL '1 day';
SELECT * FROM table AS OF TRANSACTION Query table state at a specific transaction number.
Examples: heliosdb [main] > SELECT * FROM orders AS OF TRANSACTION 9999; (Shows orders as they were after transaction 9999)
\snapshots List all available time-travel snapshots with timestamps and LSN info.
Examples: heliosdb [main] > \snapshots Time-Travel Snapshots: ─────────────────────────────────────────────────── LSN Timestamp TXN ─────────────────────────────────────────────────── 0x1000 2025-11-15 14:00:00 1000 0x1001 2025-11-15 14:30:00 1001 0x1002 2025-11-15 15:00:00 1002 ... (automatically maintained by time_travel_enabled)Help for Examples: \h examples
╔═══════════════════════════════════════════════════════════════════════════╗║ PRACTICAL SQL EXAMPLES ║╚═══════════════════════════════════════════════════════════════════════════╝
BASIC TABLE OPERATIONS
-- Create tableCREATE TABLE users ( id INT PRIMARY KEY, name TEXT NOT NULL, email TEXT UNIQUE NOT NULL, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP);
-- Insert dataINSERT INTO users (id, name, email) VALUES (1, 'Alice', 'alice@example.com'), (2, 'Bob', 'bob@example.com'), (3, 'Charlie', 'charlie@example.com');
-- Query dataSELECT * FROM users WHERE created_at > NOW() - INTERVAL '7 days';SELECT name, COUNT(*) as order_count FROM users u JOIN orders o ON u.id = o.user_id GROUP BY u.name ORDER BY order_count DESC;
-- Update dataUPDATE users SET name = 'Alice Smith' WHERE id = 1;
-- Delete dataDELETE FROM users WHERE id > 100;
VECTOR OPERATIONS (v2.1)
-- Create table with vector columnCREATE TABLE embeddings ( id SERIAL PRIMARY KEY, text TEXT NOT NULL, embedding VECTOR(384) NOT NULL, metadata JSONB);
-- Create HNSW vector indexCREATE INDEX idx_embedding_hnswON embeddings USING hnsw(embedding)WITH (m=16, ef_construction=200);
-- Insert vectorsINSERT INTO embeddings (text, embedding) VALUES ('Hello world', '[0.1, 0.2, 0.3, ...]'::VECTOR), ('Goodbye world', '[0.2, 0.3, 0.4, ...]'::VECTOR);
-- Vector similarity searchSELECT id, text, embedding <-> query_vector AS distanceFROM embeddingsORDER BY embedding <-> '[0.1, 0.2, 0.3, ...]'::VECTORLIMIT 10;
BRANCHING & TIME-TRAVEL (v2.0)
-- Create a development branchCREATE DATABASE BRANCH dev FROM main AS OF NOW;
-- Switch to branch\use dev
-- Make changesINSERT INTO users VALUES (4, 'Diana', 'diana@example.com');DELETE FROM users WHERE id = 1;
-- View main branch data (still has Alice)\use mainSELECT * FROM users; -- Still has id=1 (Alice)
-- View dev changes\use devSELECT * FROM users; -- No id=1, has id=4 (Diana)
-- Merge dev into main\use mainMERGE DATABASE BRANCH dev INTO main;
-- Time-travel to see historical dataSELECT * FROM users AS OF TIMESTAMP '2025-11-15 09:00:00';
-- CleanupDROP DATABASE BRANCH dev;
MATERIALIZED VIEWS (v2.0)
-- Create materialized view with auto-refreshCREATE MATERIALIZED VIEW user_stats ASSELECT user_id, COUNT(*) as total_orders, SUM(amount) as total_spent, AVG(amount) as avg_order_valueFROM ordersGROUP BY user_idWITH ( auto_refresh = true, max_cpu_percent = 15, refresh_interval_seconds = 3600);
-- Manually refresh if neededREFRESH MATERIALIZED VIEW user_stats;
-- Check view stalenessSELECT * FROM pg_mv_staleness();
-- Query materialized view (fast - pre-computed)SELECT * FROM user_stats WHERE user_id = 123;
AI FEATURES (v2.6)
-- Infer schema from JSON data (coming soon)SELECT * FROM infer_schema('[{"name": "Alice", "age": 30}]'::JSON);
-- Generate schema from description (coming soon)SELECT * FROM generate_schema('User management system for SaaS');
-- Store documents for RAG (coming soon)INSERT INTO documents (source, content, metadata)VALUES ('file.pdf', 'Document content...', '{"author": "John"}');
-- Semantic search across documents (coming soon)SELECT * FROM search_documents('What is machine learning?');3. Implementation Strategy for Improved Help
Code Structure Changes
New File: src/repl/help_manager.rs
pub struct HelpManager;
impl HelpManager { pub fn print_help_main(terminal_width: usize) { if terminal_width >= 120 { Self::print_help_3col(); } else { Self::print_help_2col(); } }
pub fn print_help_category(category: &str, terminal_width: usize) { match category { "basic" => Self::help_basic(), "schema" => Self::help_schema(), "v2.0" => Self::help_v2_0(), "v2.1" => Self::help_v2_1(), "v2.6" => Self::help_v2_6(), "sql" => Self::help_sql(), "examples" => Self::help_examples(), _ => println!("Unknown help category: {}", category), } }
fn print_help_2col() { /* ... */ } fn print_help_3col() { /* ... */ }
// Category-specific helpers fn help_basic() { /* ... */ } fn help_schema() { /* ... */ } fn help_v2_0() { /* ... */ } fn help_v2_1() { /* ... */ } fn help_v2_6() { /* ... */ } fn help_sql() { /* ... */ } fn help_examples() { /* ... */ }}Updated: src/repl/commands.rs
impl MetaCommand { pub fn execute(&self, db: &EmbeddedDatabase) -> Result<MetaCommandResult> { match self { MetaCommand::Help => { // Get terminal width for responsive layout let term_size = termsize::get(); let width = term_size.map(|s| s.cols as usize).unwrap_or(80);
HelpManager::print_help_main(width); Ok(MetaCommandResult::Continue) }
MetaCommand::HelpCategory(cat) => { let term_size = termsize::get(); let width = term_size.map(|s| s.cols as usize).unwrap_or(80);
HelpManager::print_help_category(cat, width); Ok(MetaCommandResult::Continue) } // ... rest of commands } }}New Dependencies
termsize- Get terminal dimensions for responsive layout
Backward Compatibility
- Existing
\hcommand still works - New:
\h <category>for detailed help - Examples included inline with commands
4. User Experience Improvements
Current Pain Points → Proposed Solutions
| Problem | Solution |
|---|---|
| Help text too long to read | Break into categories with \h <category> |
| Examples separated from commands | Integrate examples inline (1-2 per command) |
| All text looks the same | Use table formatting with alignment |
| No terminal awareness | Detect width and use 2-col or 3-col layout |
| Hard to discover commands | Group by feature area and use bold headers |
| Unclear what works in REPL | Show working examples vs “not available” clearly |
Rendering Examples
Narrow Terminal (80 cols):
✓ Readable on older terminals✓ Works over SSH with small windows✓ Accessible on mobile✓ Clear column separationWide Terminal (160+ cols):
✓ Efficient use of screen space✓ Three-column layout shows categories side-by-side✓ Commands and examples visible at once✓ Professional reference layout5. Quick Command Reference Card
For Terminal Width Detection
use termsize;
if let Some(size) = termsize::get() { println!("Terminal size: {}x{}", size.cols, size.rows); if size.cols >= 120 { // 3-column layout } else { // 2-column layout }}Help Command Enhancements
// New parsingmatch parts[0] { "h" | "help" | "?" => { if parts.len() > 1 { // \h <category> Some(MetaCommand::HelpCategory(parts[1].to_string())) } else { // \h (main help) Some(MetaCommand::Help) } } // ...}6. Summary of Changes
Files to Create:
src/repl/help_manager.rs- Central help system
Files to Modify:
src/repl/commands.rs- Add HelpCategory commandCargo.toml- Add termsize dependency
Benefits:
- ✅ 3x more discoverable commands
- ✅ Examples show real usage
- ✅ Terminal-aware responsive design
- ✅ Category-based learning curve
- ✅ Professional reference format
- ✅ Backward compatible with
\h