Skip to content

Conversation

lonetwin
Copy link
Contributor

@lonetwin lonetwin commented Aug 20, 2025

Description

SQLite accepts URI style db names:

This is particularly useful for opening databases in read-only mode (also with multiple connections, when using cache=shared). Although, this might be a corner case for litecli it'll help my use-case of embedding litecli in a personal app.

Checklist

  • I've added this contribution to the CHANGELOG.md file.

SQLite accepts URI style db names:
* https://docs.python.org/3/library/sqlite3.html#sqlite3-uri-tricks
* https://www.sqlite.org/c3ref/open.html#urifilenameexamples

This is particularly useful for opening databases in read-only mode (also with
multiple connections, when using `cache=shared`). Although, this might be a
corner case for `litecli` it'll help my use-case of embedding litecli in a
personal app.
Copy link
Member

@amjith amjith left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lonetwin Thank you for the contribution. I appreciate the tests. 💯

I have a small suggestion to use urlparse. Thoughts?

if db.startswith("file:"):
uri = True
db_name = db
db_filename, *_ = db_name[5:].split("?", 1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks a little brittle. How about using the urlparse() from the urllib.parse module?

We can do

parsed = urlparse(db)
db_filename = parsed.path

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@amjith Thanks for your time!

Sure yeah. tbh, I just wanted to keep the change minimal and stay consistent with the use of string functions elsewhere in the code. I've updated the code. Is this what you had in mind ?

This is a small enough change and I'm happy for you to adapt it in whatever way you think seems best.

@lonetwin lonetwin requested a review from amjith August 25, 2025 21:57
@amjith amjith merged commit c1f7911 into dbcli:main Aug 25, 2025
7 checks passed
@lonetwin lonetwin deleted the uri-arg branch August 27, 2025 14:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants