🗄️ A simple and intuitive command-line SQLite database viewer built with Python.
- 🔌 Connect to SQLite databases
- 📋 List and explore table structures
- 👀 View table contents with beautiful formatting
- 🔍 Execute custom SQL queries
- 🎨 Interactive command-line interface
- 📊 Auto-formatted table outputs
- 🚀 No external dependencies required
- Clone the repository:
git clone https://github.com/sw3do/sql-viewer.git
cd sql-viewer
- Requirements: Python 3.6+ (no external dependencies needed)
# Start the application
python3 src/main.py
# Connect to a database directly
python3 src/main.py /path/to/your/database.db
# Try with the sample database
python3 create_sample_db.py # Creates sample.db
python3 src/main.py sample.db
Command | Shortcut | Description |
---|---|---|
connect <path> |
c |
Connect to SQLite database |
disconnect |
d |
Disconnect from current database |
tables |
t |
List all tables |
info |
i |
Show database information |
describe <table> |
desc |
Show table structure |
select <table> |
s |
Show table contents (first 50 rows) |
query <sql> |
q |
Execute custom SQL query |
help |
h |
Show help message |
exit/quit |
- | Exit the application |
🗄️ Welcome to SQL Viewer CLI!
Type 'help' for available commands or 'exit' to quit.
sql-viewer> connect sample.db
✓ Connected to database: sample.db
📊 Database Information:
Path: sample.db
Tables: 5
Table Details:
──────────────────────────────────────────────────
• categories 5 rows
• orders 50 rows
• products 25 rows
• users 15 rows
sql-viewer (sample.db)> describe users
📋 Table Structure: users
┌────────────┬─────────┬──────────┬─────────┬─────────────┐
│ Column │ Type │ Not Null │ Default │ Primary Key │
├────────────┼─────────┼──────────┼─────────┼─────────────┤
│ id │ INTEGER │ YES │ │ YES │
│ name │ TEXT │ YES │ │ NO │
│ email │ TEXT │ YES │ │ NO │
│ age │ INTEGER │ NO │ │ NO │
│ city │ TEXT │ NO │ │ NO │
│ created_at │ TEXT │ NO │ CURRENT │ NO │
└────────────┴─────────┴──────────┴─────────┴─────────────┘
(6 rows displayed)
sql-viewer (sample.db)> query SELECT name, email, city FROM users WHERE age > 30
📊 Query Results:
┌──────────────┬─────────────────────────┬──────────────┐
│ name │ email │ city │
├──────────────┼─────────────────────────┼──────────────┤
│ Jane Smith │ jane.smith@email.com │ Los Angeles │
│ Bob Johnson │ bob.johnson@email.com │ Chicago │
│ Charlie Wilson│ charlie.wilson@email.com│ Phoenix │
│ Diana Davis │ diana.davis@email.com │ Philadelphia │
└──────────────┴─────────────────────────┴──────────────┘
(4 rows displayed)
sql-viewer/
├── src/
│ ├── main.py # Application entry point
│ ├── cli.py # CLI interface and command handlers
│ ├── database.py # Database connection and operations
│ └── utils.py # Table formatting and utilities
├── create_sample_db.py # Sample database generator
├── sample.db # Sample SQLite database
├── requirements.txt # Project requirements
└── README.md # This file
- Read-only operations by default
- Dangerous SQL commands (DROP, DELETE, UPDATE, etc.) are restricted
- Limited to SQLite databases only
- No network connections or external data access
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the project
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
"Database file not found" error:
- Check the database file path
- Ensure the file exists and is readable
"Permission denied" error:
- Verify you have read permissions for the database file
Table display issues:
- Try increasing your terminal width
- Long text is automatically truncated for better display
- Python 3.6 or higher
- SQLite3 (included with Python)
- Terminal with Unicode support
This project is licensed under the MIT License - see the LICENSE file for details.
sw3do - GitHub Profile
⭐ If you found this project helpful, please give it a star!