A terminal-native database learning playground
Project description
TermiBase ๐
A terminal-native database learning playground that lets you run SQL queries and observe how they're parsed, planned, and executedโall from your command line.
Install in one command: brew install tejgokani/termibase/termibase or pip install termibase
Use immediately: Just type termibase and start querying!
๐ฏ What is TermiBase?
TermiBase is an educational tool designed to help developers understand database internals by providing:
- Interactive SQL REPL with real-time query analysis
- Multi-line query support (SQL*Plus style) - write queries across multiple lines
- Command history with arrow key navigation (โโ)
- Execution plan visualization showing how queries are processed step-by-step
- Query optimization suggestions to learn best practices
- Interactive learning mode (
.learn) with guided SQL lessons - Commit/rollback tracking to manage database changes
- Beautiful terminal UI using Rich for a modern CLI experience
- No browser required - everything runs in your terminal
๐ Quick Start
Installation
Option 1: Homebrew (Recommended for macOS)
brew install termibase
Option 2: pip
pip install termibase
Option 3: pip3
pip3 install termibase
Option 4: pipx (Recommended for CLI tools)
pipx install termibase
First Use
Simply run:
termibase
The database will be automatically initialized on first run. You'll see:
โจ TermiBase - Your Database Learning Playground
๐ก Tip: Type SQL queries to see how they're executed step-by-step
Use .help for commands, .exit to quit
Write multi-line queries (end with ';') or use arrow keys for history
termibase>
๐ Features
1. Multi-Line Query Input
Write SQL queries across multiple lines, just like SQL*Plus:
termibase> SELECT DISTINCT
-> c.customer_id,
-> c.first_name,
-> c.last_name
-> FROM rental r
-> INNER JOIN customer c ON r.customer_id = c.customer_id
-> WHERE c.city = 'Lethbridge';
End your query with ; to execute. Use \ on an empty line to cancel.
2. Command History
Navigate your query history using arrow keys:
- โ - Previous query
- โ - Next query
- History is saved to
.termibase_historyand persists across sessions
3. Interactive Learning Mode
Learn SQL interactively with guided lessons:
termibase> .learn
Available Topics:
- SELECT Basics
- WHERE Clause
- JOINs
- GROUP BY & Aggregation
- ORDER BY
- Subqueries
- Indexes & Performance
Each lesson includes:
- Detailed explanations
- Example queries
- Practice queries you can run
- Option to write your own queries
4. Commit/Rollback Tracking
TermiBase tracks uncommitted changes and prompts you to save before exiting:
termibase> INSERT INTO users (name, age, city) VALUES ('Alice', 25, 'NYC');
โ Query executed successfully.
๐ก Use .commit to save changes or .rollback to discard
termibase> .commit
โ Changes committed successfully
Commands:
.commit- Save pending changes.rollback- Discard pending changes
If you try to exit with uncommitted changes, you'll be prompted to commit.
5. Query Analysis & Visualization
Every query is automatically analyzed and visualized:
termibase> SELECT * FROM users WHERE age > 28;
Shows:
- Query structure (tables, columns, WHERE conditions)
- Execution plan (step-by-step processing)
- Query results (beautifully formatted tables)
- Optimization suggestions
6. Execution Plan Visualization
See how your query is executed internally:
Execution Plan
Query Execution
โโโ [1] TABLE_SCAN - Scanning table users (cost: 1.00, rows: 8)
โโโ [2] FILTER - Applying WHERE filter: age > 28 (cost: 0.30, rows: 4)
โโโ [3] PROJECT - Projecting all columns (cost: 0.20, rows: 4)
๐ REPL Commands
Inside the TermiBase REPL, use these commands:
| Command | Description |
|---|---|
.help |
Show all available commands |
.learn |
Interactive SQL learning mode |
.explain |
Toggle execution plan display on/off |
.commit |
Commit pending database changes |
.rollback |
Rollback pending database changes |
.tables |
List all tables in the database |
.schema |
Show table schemas |
.examples |
Show example queries |
.exit or .quit |
Exit REPL |
๐ฎ Usage Examples
Basic Queries
-- Simple select
SELECT * FROM users LIMIT 5;
-- Filtering
SELECT name, age FROM users WHERE age > 28;
-- Grouping
SELECT city, COUNT(*) as count FROM users GROUP BY city;
-- Joins
SELECT u.name, o.amount
FROM users u
JOIN orders o ON u.id = o.user_id;
Multi-Line Complex Query
termibase> SELECT DISTINCT
-> c.customer_id,
-> c.first_name,
-> c.last_name,
-> c.email,
-> s.store_id
-> FROM rental r
-> INNER JOIN staff st ON st.staff_id = r.staff_id
-> INNER JOIN store s ON s.manager_staff_id = st.staff_id
-> AND s.store_id = st.store_id
-> INNER JOIN customer c ON r.customer_id = c.customer_id
-> AND s.store_id = c.store_id
-> INNER JOIN address a ON s.address_id = a.address_id
-> INNER JOIN city ci ON ci.city_id = a.city_id
-> WHERE ci.city = 'Lethbridge';
Using Learning Mode
termibase> .learn
๐ SQL Learning Topics
# Topic Description
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
1 SELECT Basics Learn the fundamentals of SELECT queries
2 WHERE Clause Filter data using WHERE conditions
3 JOINs Combine data from multiple tables
4 GROUP BY & Aggregation Group data and use aggregate functions
5 ORDER BY Sort query results
6 Subqueries Nested queries and subqueries
7 Indexes & Performance Understand indexes and query optimization
Select a topic (1-7) or 'q' to quit: 3
๐ JOINs
Explanation:
JOINs combine rows from two or more tables.
Types:
โข INNER JOIN - Returns matching rows from both tables
โข LEFT JOIN - Returns all rows from left table + matching from right
...
Options:
1 - Run practice query
2 - Write your own query
3 - See execution plan
4 - Back to topics
๐ ๏ธ Command-Line Commands
termibase (No Arguments)
Launches interactive REPL - the main way to use TermiBase.
termibase
termibase init
Initialize or reset the sandbox database with demo data.
termibase init
termibase init --db-path ./my-db.db
termibase repl
Explicitly launch REPL (same as termibase).
termibase repl
termibase repl --explain # Always show execution plans
termibase run
Execute a single query with full visualization.
termibase run "SELECT * FROM users WHERE age > 25"
termibase run "SELECT * FROM users" --no-explain # Skip execution plan
termibase explain
Show execution plan for a query without running it.
termibase explain "SELECT * FROM users JOIN orders ON users.id = orders.user_id"
termibase demo
Run educational demo queries.
termibase demo # Run all demos
termibase demo basics # Run specific demo
๐ Demo Data
TermiBase comes with pre-loaded demo data:
Users Table:
id(INTEGER PRIMARY KEY)name(TEXT)age(INTEGER)city(TEXT)
Orders Table:
id(INTEGER PRIMARY KEY)user_id(INTEGER, FOREIGN KEY)amount(REAL)date(TEXT)
Indexes:
idx_users_cityonusers(city)idx_orders_user_idonorders(user_id)
๐๏ธ Architecture
TermiBase is built with a modular architecture:
termibase/
โโโ cli/ # Command-line interface (Typer)
โ โโโ main.py # Main CLI commands
โ โโโ input_handler.py # Multi-line input & history
โโโ parser/ # SQL parsing and analysis
โโโ engine/ # Query execution simulation
โโโ visualizer/ # Rich-based terminal rendering
โโโ storage/ # SQLite wrapper
โโโ learn/ # Interactive learning module
โโโ demos/ # Educational examples
Key Components
- CLI Interface: Handles commands, flags, and REPL loop
- Input Handler: Multi-line query input with readline history support
- SQL Parser: Parses SQL into tokens and AST using
sqlparse - Query Analyzer: Identifies query type, tables, indexes, joins
- Execution Simulator: Simulates logical execution steps
- Storage Engine: SQLite wrapper for actual query execution
- Visualizer: Renders execution plans and results using Rich
- Learning Module: Interactive SQL lessons and practice
๐ Educational Features
Query Analysis
Every query is analyzed to show:
- Query type (SELECT, INSERT, UPDATE, DELETE)
- Tables involved
- Columns selected
- WHERE conditions
- JOIN operations
- GROUP BY and ORDER BY clauses
- LIMIT values
Execution Visualization
See how your query is executed:
- Table scans vs index scans
- Filter operations for WHERE clauses
- Join strategies (INNER, LEFT, etc.)
- Sorting for ORDER BY
- Grouping for GROUP BY
- Cost estimates for each step
Optimization Suggestions
Get tips on improving your queries:
- Index recommendations
- Full table scan warnings
- Large result set alerts
- Join optimization hints
๐ง Development
Setup Development Environment
# Clone repository
git clone https://github.com/tejgokani/TermiBase.git
cd TermiBase
# Create virtual environment
python3 -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install in editable mode
pip install -e .
Running Tests
pytest termibase/tests/
๐จ Design Philosophy
- Terminal-first: Everything works in the terminal, no browser needed
- Educational: Transparent about how queries are processed
- Fast feedback: Immediate visualization of query execution
- Developer-centric: Built for developers learning databases
- Interactive: Multi-line queries, history, and guided learning
- Safe: Commit/rollback tracking prevents accidental data loss
๐ Requirements
- Python 3.8 or higher
- SQLite (included with Python)
๐ Platform Support
- โ macOS
- โ Linux
- โ Windows (with WSL recommended)
๐ Update TermiBase
Homebrew:
brew upgrade termibase
pip:
pip install --upgrade termibase
๐๏ธ Uninstall
Homebrew:
brew uninstall termibase
pip:
pip uninstall termibase
License
TermiBase is source-available. You are free to use and study the code, but modification and redistribution are not permitted without explicit permission.
๐ Acknowledgments
Built with:
- Typer - Modern CLI framework
- Rich - Beautiful terminal output
- sqlparse - SQL parsing
- SQLite - Embedded database
๐ Support
- Issues: GitHub Issues
- Documentation: This README
Happy Learning! ๐
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file termibase-0.1.0.tar.gz.
File metadata
- Download URL: termibase-0.1.0.tar.gz
- Upload date:
- Size: 31.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d2bb1570ff25422acf9bd91f2e2fb32d8f76fc32b21b293f38053dce443c9268
|
|
| MD5 |
c362cda3f0580a7bb35f327591cf1bdf
|
|
| BLAKE2b-256 |
dab8105f6cbb01c5027cc0b44b90d9ec5983a94dc0adbdd0ede95e50fbf72439
|
File details
Details for the file termibase-0.1.0-py3-none-any.whl.
File metadata
- Download URL: termibase-0.1.0-py3-none-any.whl
- Upload date:
- Size: 31.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
821f1ea5aa95b9d27b8bfefd04048746beba283e8941adc70d6b0614ae30ce66
|
|
| MD5 |
b52b89e99ecbf1aeb4d62e305961ea0e
|
|
| BLAKE2b-256 |
6111d4e1bcc6dc9546c803588f87ebf00c998810cb5970c583eb4dce95993329
|