Skip to main content

Simple SQLite database utility with CRUD operations via CLI

Project description

DBBox

Simple SQLite database utility with CRUD operations via CLI

Part of the Box Suite - a modular Python CLI application framework.

Features

  • Simple CRUD operations via command-line flags (-c, -r, -u, -d)
  • Schema management with type-safe column definitions
  • Cross-platform storage using ConfBox for OS-specific directories
  • Pretty-printed output for SELECT queries
  • Auto-increment IDs by default
  • Zero configuration - just install and use

Installation

pip install dbbox

Or install from source:

git clone https://github.com/jmmirabile/dbbox.git
cd dbbox
pip install -e .

Storage Location

DBBox uses ConfBox to store databases in OS-specific data directories:

OS Storage Location
Linux ~/.local/share/dbbox/
macOS ~/Library/Application Support/dbbox/
Windows %APPDATA%\dbbox\

Quick Start

# Create a table with schema
dbbox mydb users --schema name:TEXT age:INTEGER email:TEXT

# Insert data
dbbox mydb users -c 'John Doe' 30 'john@example.com'
dbbox mydb users -c 'Jane Smith' 25 'jane@example.com'

# Read all rows
dbbox mydb users -r

# Read specific row by ID
dbbox mydb users -r 1

# Update a row
dbbox mydb users -u 1 'John Updated' 31 'john.new@example.com'

# Delete a row
dbbox mydb users -d 2

# Show table info
dbbox mydb users --info

# List all tables
dbbox mydb --list

# Show database path
dbbox mydb --path

Listing Databases and Tables

DBBox provides multiple ways to list databases and tables for flexibility:

List All Databases

# Four equivalent ways:
dbbox databases         # Positional command (recommended)
dbbox -l                # Short flag
dbbox --databases       # Explicit flag
dbbox --list            # Long flag alias

List Tables in a Database

# Four equivalent ways:
dbbox mydb tables       # Positional command (recommended)
dbbox mydb -l           # Short flag
dbbox mydb --tables     # Explicit flag
dbbox mydb --list       # Long flag alias

The -l/--list flag is context-aware:

  • Without database name: lists databases
  • With database name: lists tables

Usage

Create Table

dbbox <dbname> <table> --schema <col:type> <col:type> ...

Example:

dbbox mydb products --schema name:TEXT price:REAL stock:INTEGER

Note: An id INTEGER PRIMARY KEY AUTOINCREMENT column is added automatically.

Supported SQLite types: TEXT, INTEGER, REAL, BLOB, NUMERIC

Insert (Create)

dbbox <dbname> <table> -c <value1> <value2> ...

Example:

dbbox mydb products -c 'Widget' 19.99 100

Select (Read)

# Read all rows
dbbox <dbname> <table> -r

# Read specific row by ID
dbbox <dbname> <table> -r <id>

Examples:

dbbox mydb products -r           # All rows
dbbox mydb products -r 5         # Row with id=5

Update

dbbox <dbname> <table> -u <id> <value1> <value2> ...

Example:

dbbox mydb products -u 5 'Super Widget' 24.99 150

Delete

dbbox <dbname> <table> -d <id>

Example:

dbbox mydb products -d 5

Drop Table

dbbox <dbname> <table> --drop-table

Example:

dbbox mydb products --drop-table
# Prompts for confirmation before dropping

Warning: This permanently deletes the table and all its data. Cannot be undone.

Drop Database

dbbox <dbname> --drop-database

Example:

dbbox mydb --drop-database
# Prompts for confirmation before dropping

Warning: This permanently deletes the entire database file. Cannot be undone.

Database Management

# List all tables in a database
dbbox <dbname> --list

# Show table schema/info
dbbox <dbname> <table> --info

# Show database file path
dbbox <dbname> --path

# Drop a table (with confirmation)
dbbox <dbname> <table> --drop-table

# Drop entire database (with confirmation)
dbbox <dbname> --drop-database

Complete Example

# Create a contacts database
dbbox contacts people --schema name:TEXT phone:TEXT email:TEXT

# Add some contacts
dbbox contacts people -c 'Alice Smith' '555-1234' 'alice@example.com'
dbbox contacts people -c 'Bob Jones' '555-5678' 'bob@example.com'

# View all contacts
dbbox contacts people -r

# Output:
# id              | name            | phone           | email
# --------------------------------------------------------------------------
# 1               | Alice Smith     | 555-1234        | alice@example.com
# 2               | Bob Jones       | 555-5678        | bob@example.com
#
# 2 row(s) returned

# Update a contact
dbbox contacts people -u 2 'Robert Jones' '555-5678' 'robert@example.com'

# Delete a contact
dbbox contacts people -d 1

# Show table structure
dbbox contacts people --info

# List all tables
dbbox contacts --list

# Drop a table (with confirmation prompt)
dbbox contacts people --drop-table

# Drop entire database (with confirmation prompt)
dbbox contacts --drop-database

Use Cases

  • Quick data storage for scripts and automation
  • Prototyping database schemas
  • Data tracking for personal projects
  • Testing SQL queries and table designs
  • Simple CRUD apps without writing database code
  • Local caching of data

The Box Suite

DBBox is part of the Box Suite - a collection of modular Python packages for building CLI applications:

  • ConfBox ✅ - Cross-platform configuration management
  • DBBox ✅ - SQLite database utility (this package)
  • PlugBox 🔨 - Plugin system (planned)
  • CLIBox 🔨 - Complete CLI framework (planned)
  • RestBox 🔨 - REST API testing tool (planned)

Each package can be used independently or together for maximum flexibility.

Python API

DBBox can also be used as a Python library:

from dbbox import DBManager

# Create database manager
with DBManager("mydb") as db:
    # Create table
    db.create_table("users", ["name:TEXT", "age:INTEGER"])

    # Insert data
    user_id = db.insert("users", ["John Doe", 30])

    # Select data
    rows = db.select("users")
    for row in rows:
        print(dict(row))

    # Update data
    db.update("users", user_id, ["Jane Doe", 31])

    # Delete data
    db.delete("users", user_id)

Development

Install development dependencies:

pip install -e ".[dev]"

Run tests:

pytest

Requirements

License

MIT License - see LICENSE file for details.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Links

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dbbox-0.1.1.tar.gz (12.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dbbox-0.1.1-py3-none-any.whl (11.4 kB view details)

Uploaded Python 3

File details

Details for the file dbbox-0.1.1.tar.gz.

File metadata

  • Download URL: dbbox-0.1.1.tar.gz
  • Upload date:
  • Size: 12.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for dbbox-0.1.1.tar.gz
Algorithm Hash digest
SHA256 236a178159b426e1f199c7b64d7f8af918bfb5e9450e641f24f0a44c8853469d
MD5 1e4eebb75188fd7ff6d01407dba3631f
BLAKE2b-256 28a37fe9255dad3282655d7356aec3de896d4a3cdbf0b5148b659a93eaf852b6

See more details on using hashes here.

File details

Details for the file dbbox-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: dbbox-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 11.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for dbbox-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 18364684d6e9e6e46e49c76868be7767345241ea46a5b35e993eef385aa592c5
MD5 3ada6cfc0f7af9acaed65a06f5521683
BLAKE2b-256 c16c335f1f3f6e8637de17a2bb927e3fed8588c259d61ca4bc807cb720d651d4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page