跳到主内容
@wquguru
精选70Simon Willison 博客(RSS)产品发布/更新

alchemy-utils 0.1a0:数据库无关的 sqlite-utils

alchemy-utils 0.1a0

原文
发到 X

Release: alchemy-utils 0.1a0

发布:alchemy-utils 0.1a0

I've long pondered what a database agnostic version of my sqlite-utils Python library and CLI utility might look like. This morning (literally a shower project) I tasked Codex and GPT-5.6 Sol Ultra with building a prototype:

我一直在思考,我的 sqlite-utils Python 库和 CLI 工具如果做成一个不依赖特定数据库的版本会是什么样子。今天早上(真的是在淋浴时想到的项目),我让 Codex 和 GPT-5.6 Sol Ultra 构建一个原型:

Do a research spike to see what it would take to build a library with the same core API as SQLite-utils - in particular the insert and upsert and insert_all and upsert_all and create and update methods, and the table introspection stuff - but backed by SQLalchemy so it works for multiple database engines

进行一次研究性探索,看看构建一个与 SQLite-utils 核心 API 相同的库需要什么——特别是 insert、upsert、insert_all、upsert_all、create 和 update 方法,以及表内省功能——但底层使用 SQLAlchemy,以便支持多种数据库引擎。

Test against PostgreSQL and SQLite and duckdb

针对 PostgreSQL、SQLite 和 DuckDB 进行测试。

Use ~/dev/sqlite-utils for reference

使用 ~/dev/sqlite-utils 作为参考。

Create a git repo for this and commit and early and often - use uv init to start the project - use red/green TDD and pytest, see ~/dev/django-sql-dashboard for one idea as to how the PostgreSQL tests could work

为此创建一个 git 仓库,并尽早且频繁地提交——使用 uv init 启动项目——使用红/绿 TDD 和 pytest,参见 ~/dev/django-sql-dashboard 了解 PostgreSQL 测试的一种思路。

It took very few follow-up prompts to produce this project in a state good enough to release as an alpha.

只用了很少的后续提示,就把这个项目做到了可以发布为 alpha 版本的状态。

Here's a one-liner I can use to list the rows in a table in my local PostgreSQL copy of my blog's database:

这里有一个一行命令,可以用来列出我本地 PostgreSQL 中博客数据库副本的表中的行:

uvx --with 'alchemy-utils[postgresql]' alchemy-utils rows 'postgresql+psycopg://simon@localhost:5432/simonwillisonblog' redirects_redirect

uvx --with 'alchemy-utils[postgresql]' alchemy-utils rows 'postgresql+psycopg://simon@localhost:5432/simonwillisonblog' redirects_redirect

The output from that starts like this:

该命令的输出开头如下:

代码 · 15
[
  {
    "id": 2328,
    "domain": "simonwillison.net",
    "path": "2020/May/21/apple-photos-sqlite/",
    "target": "/2020/May/21/dogsheep-photos/",
    "created": "2020-05-21T13:03:46.591692-07:00"
  },
  {
    "id": 3,
    "domain": "feeds.simonwillison.net",
    "path": "swn-links",
    "target": "https://simonwillison.net/atom/links/",
    "created": "2017-10-01T14:12:54.820729-07:00"
  }
代码 · 15
[
  {
    "id": 2328,
    "domain": "simonwillison.net",
    "path": "2020/May/21/apple-photos-sqlite/",
    "target": "/2020/May/21/dogsheep-photos/",
    "created": "2020-05-21T13:03:46.591692-07:00"
  },
  {
    "id": 3,
    "domain": "feeds.simonwillison.net",
    "path": "swn-links",
    "target": "https://simonwillison.net/atom/links/",
    "created": "2017-10-01T14:12:54.820729-07:00"
  }

Or if you'd like a DuckDB database with every tree in San Francisco, schema created automatically to match the file:

或者,如果你想要一个包含旧金山所有树木的 DuckDB 数据库,模式会根据文件自动创建:

curl 'https://raw.githubusercontent.com/simonw/sf-tree-history/refs/heads/main/Street_Tree_List.csv' | uvx --with 'alchemy-utils[duckdb]' alchemy-utils insert 'duckdb:////tmp/trees.db' trees - --csv

curl 'https://raw.githubusercontent.com/simonw/sf-tree-history/refs/heads/main/Street_Tree_List.csv' | uvx --with 'alchemy-utils[duckdb]' alchemy-utils insert 'duckdb:////tmp/trees.db' trees - --csv

(That one took nearly an hour the first time I ran it, so I had Codex optimize it and got it down to around 35 seconds.)

(第一次运行这个命令花了将近一个小时,所以我让 Codex 优化了一下,把它降到了大约 35 秒。)

Tags: databases, postgresql, projects, python, sql, sqlalchemy, sqlite, sqlite-utils, duckdb, coding-agents, codex

标签:databases, postgresql, projects, python, sql, sqlalchemy, sqlite, sqlite-utils, duckdb, coding-agents, codex

更进一步:量化金融体系

看懂新闻只是起点——沿量化金融路径,把它变成能交付的工程能力

进入量化体系 →

相似阅读

另一事件,读法相近