python / python/cpython

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

Aperta
#136,560 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

stdlib topic-sqlite3 type-feature
Lingua principale
Python
Stelle
77.2k
Fork
35.9k
Metriche di merge delle PR
Metriche PR in attesa

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia leggendo l’entry point sqlite3.connect() e il comportamento di pathlib.Path descritto nella proposta, quindi esamina i requisiti URI di SQLite. Il lavoro è completato quando è stato concordato e implementato un helper che costruisca l’URI file: appropriata a partire da un Path, incluse le lettere delle unità Windows e i separatori POSIX, con test per i casi indicati.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python, sqlite
Ambito
databases
Tipo di issue
Funzionalità
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.