sqlite-utils icon indicating copy to clipboard operation
sqlite-utils copied to clipboard

feat: add URI filename support

Open fry69 opened this issue 2 months ago • 0 comments

fix #650

This code was generated with VS Code Copilot agent and Sonnet-4.5.

I think it did its job quite well.

Generated PR message below


Add SQLite URI filename support

Implements support for SQLite URI filenames across CLI and Python API (fixes #650).

Changes

sqlite_utils/db.py:

  • Modified Database.__init__() to detect URI filenames (strings starting with ) and pass uri=True parameter to sqlite3.connect()

sqlite_utils/cli.py:

  • Added DatabasePath class extending click.Path to handle URI filenames
  • URIs bypass file existence validation while maintaining normal validation for regular paths
  • Replaced all database path parameters throughout CLI with DatabasePath

tests/test_uri.py:

  • Added comprehensive test coverage for URI functionality
  • Tests include: read-only mode, immutable flag, multiple parameters, CLI commands, path validation

Documentation:

  • Added URI filenames section to CLI documentation
  • Added URI examples to Python API documentation

Usage

CLI:

sqlite-utils tables 'file:data.db?mode=ro&immutable=1'
sqlite-utils query 'file:data.db?mode=ro' "SELECT * FROM items"

Python API:

from sqlite_utils import Database
db = Database("file:data.db?mode=ro&immutable=1")

Testing

All existing tests pass. Added 13 new tests covering URI functionality. Type checking passes with mypy.


📚 Documentation preview 📚: https://sqlite-utils--670.org.readthedocs.build/en/670/

fry69 avatar Oct 10 '25 13:10 fry69