Reference Recipes · Copy & Run

SQL Cookbook & REPL Commands. What works and common errors.

Quick copyable examples for users(id INT, name TEXT), REPL dot commands, TCP server mode, and why certain queries error out.

REPL Tour

Dot commands built into src/main.rs

Single-line input · .exit flushes & clears WAL
Inspect Tables & Schema

.tables lists table names and row counts. .schema users displays column types (INT, TEXT, FLOAT, BOOLEAN).

Indexes & Live Stats

.indexes lists secondary indexes stored on Page 0. .stats shows .db bytes, .wal bytes, and primary B-Tree depth.

Dump, Export & Exit

.dump prints SQL to stdout; .export backup.sql writes a file. Always quit with .exit so dirty pages flush cleanly.

SQL Patterns

Copyable SQL & Server Snippets

Full SQL status matrix

1. Create, Insert & Filter

Works
CRUD + WHERE + ORDER BY + LIMIT
CREATE TABLE users (id INT, name TEXT);
INSERT INTO users VALUES (1, 'alice');
SELECT * FROM users WHERE id = 1 ORDER BY id DESC LIMIT 10;

Supports =, >, < with AND/OR. No JOINs, !=, >=, NULL, or (...).

2. Secondary Indexes & EXPLAIN

Partial
Index + Planner
CREATE INDEX idx_id ON users (id);
EXPLAIN SELECT * FROM users WHERE id = 1;
DROP INDEX idx_id;

SELECT uses indexes for single predicates (except >/< on hashed TEXT). UPDATE/DELETE still scan the heap.

3. TCP Server & Client

Partial
Two terminal tabs
cargo run --bin rustdb-server -- mydb.db 7878
cargo run --bin rustdb-client -- localhost 7878

Never open one .db file in two standalone rustdb processes. Use rustdb-server for shared clients.

4. Common Errors & Fixes

Reference
  • UnsupportedOp(>=) — Only =, >, < exist in src/lexer.rs.
  • Column count mismatch — INSERT expects every column in schema order.
  • Page Full / exceeds 4KB — One row or Page 0 catalog exceeded 4096 bytes.

Curious what happens inside when you run those queries?

Inspect Engine Architecture Play with 4KB Storage Lab