python / python/cpython

Helper function for constructing URIs for `sqlite3.connect()`

Offen
#136,560 2 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

stdlib topic-sqlite3 type-feature
Vorherrschende Sprache
Python
Sterne
77.2k
Forks
35.9k
PR-Merge-Kennzahlen
PR-Kennzahlen ausstehend

Beschreibung

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

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Lies zunächst den sqlite3.connect()-Einstiegspunkt und das im Vorschlag beschriebene Verhalten von pathlib.Path, und prüfe anschließend die URI-Anforderungen von SQLite. Als abgeschlossen gilt, wenn ein Helper vereinbart und implementiert wurde, der aus einem Path die passende file: URI erstellt, einschließlich Windows-Laufwerksbuchstaben und POSIX-Trennzeichen, mit Tests für die genannten Fälle.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python, sqlite
Bereich
databases
Issue-Typ
Feature
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.