Helper function for constructing URIs for `sqlite3.connect()`
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 77.2k
- Forks
- 35.9k
- PR merge metrics
- PR metrics pending
Description
Feature or enhancement
Proposal:
When working with SQLite3 URIs, one very subtle thing about them is if you are on Windows and the database path starts with a drive letter, you need to make sure there's a leading /. You must also use POSIX file path separators.
A non-optimized solution is:
db_path = path.resolve(strict=True).as_posix()
if not db_path.startswith("/"):
# Starts with a Windows drive letter, so add leading slash.
db_path = "/" + db_path
This seems subtle enough to potentially warrant a function to take a pathlib.Path object and construct the resulting file: URI appropriately. I'm sure something nicer that doesn't force the absolute path could be used to save on any extra stat calls (if people are even that concerned for a single call that opens a database).
Has this already been discussed elsewhere?
No response given
Links to previous discussion of this feature:
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the sqlite3.connect() entry point and the pathlib.Path behavior described in the proposal, then review SQLite's URI requirements. Done means agreeing on and implementing a helper that constructs the appropriate file: URI from a Path, including Windows drive letters and POSIX separators, with tests for the stated cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, sqlite
- Domain
- databases
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100