python / python/cpython

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

未关闭
#136,560 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

stdlib topic-sqlite3 type-feature
主要语言
Python
星标
77.2k
派生
36k
PR 合并指标
PR 指标待抓取

描述

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

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

先阅读 sqlite3.connect() 入口点以及提案中描述的 pathlib.Path 行为,然后查看 SQLite 的 URI 要求。完成的标准是就实现一个从 Path 构造适当 file: URI 的 helper 达成一致并完成实现,其中包括 Windows 驱动器号和 POSIX 分隔符,并为所述情况添加测试。

由索引模型根据 Issue 内容生成。

评估

技术栈
python, sqlite
领域
databases
Issue 类型
功能
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。