Build Python SQLite3 Command Line Tool#1
Open
dhoe wants to merge 3 commits into
Open
Conversation
Implemented a fully-featured SQLite3 command-line interface in pure Python with only standard library dependencies. This provides a portable, compatible alternative to the C-based sqlite3 CLI. Features: - Interactive REPL mode with sqlite> prompt - All major output modes (list, csv, column, line, html, insert, quote, tabs, tcl) - Comprehensive meta-commands (.tables, .schema, .dump, .mode, .headers, etc.) - Command-line argument support (-csv, -column, -header, etc.) - SQL execution from files, stdin, and command line - Compatible with standard sqlite3 CLI workflows The implementation uses only Python standard library modules (sqlite3, sys, os, csv, re, io) making it highly portable and easy to deploy anywhere Python is available.
Added proper transaction tracking to prevent auto-commit when in an explicit transaction (BEGIN/COMMIT/ROLLBACK). This fixes compatibility with .dump output and allows proper transaction control. The CLI now: - Tracks when BEGIN TRANSACTION is executed - Disables auto-commit during explicit transactions - Re-enables auto-commit after COMMIT, END, or ROLLBACK - Properly handles dump file restoration with BEGIN/COMMIT blocks This matches the behavior of the standard sqlite3 CLI tool.
Created a generalized database CLI that works with both SQLite and DuckDB through a backend abstraction layer. This provides a unified interface for both databases while maintaining compatibility with the sqlite3 CLI tool. Key features: - Backend abstraction layer with DatabaseBackend base class - SQLite and DuckDB backend implementations - Auto-detection of database type from file extension (.db → SQLite, .duckdb → DuckDB) - Manual override with -db flag for explicit backend selection - All output modes work with both databases (csv, column, line, list, etc.) - Transaction support for both backends - Meta-commands adapted for both databases (.tables, .schema, .dump, etc.) - Handles differences in system catalogs (sqlite_master vs information_schema) - Suppresses DuckDB INSERT/UPDATE/DELETE count output for CLI compatibility The implementation maintains the same command-line interface and meta-commands as the SQLite-only version, making it a drop-in replacement that extends functionality to DuckDB. Auto-detection rules: - .db, .sqlite, .sqlite3 files → SQLite backend - .duckdb, .ddb files → DuckDB backend - :memory: → SQLite backend (default) - Can be overridden with -db sqlite or -db duckdb Dependencies: - sqlite3 (Python standard library) - duckdb (optional, only needed for DuckDB support)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.