---
title: "sqlite-utils 4.1 发布：新增代码行插入、严格模式转换等特性"
source: "Simon Willison 博客（Atom）"
source_tier: "t2"
url: "https://simonwillison.net/2026/Jul/11/sqlite-utils/#atom-everything"
permalink: "https://feed.astralor.com/items/itm_54d7e80f8d26711b1c7339fc"
published: "2026-07-11T23:50:20.000Z"
score: 74
channel: "tech"
tags: ["AI辅助编程","Python","SQLite","sqlite-utils"]
---

# sqlite-utils 4.1 发布：新增代码行插入、严格模式转换等特性

## AI 点评

> 这次更新虽小但很扎实，尤其是--code和strict模式两项功能，让sqlite-utils从数据浏览工具向轻量级数据管道又迈进了一步。如果你日常需要批量处理CSV或管理SQLite表结构，这些都值得试一试。另外，作者分享的AI辅助编程工作流程也很有启发——让模型自己测试自己的代码，是一种高效的验证方式。

## 速览

sqlite-utils 4.1 版本引入了多个新功能：insert 和 upsert 命令支持 --code 选项直接插入 Python 代码生成的行；支持 --type 指定列类型以保留前导零；新增 drop-index 命令和表方法；query 命令可从标准输入读取 SQL；upsert 可自动推断主键；transform 支持 strict 模式切换。这些功能大多源于社区需求和 Codex 辅助建议。

## 关键点

- 新增 --code 选项允许在 CLI 中直接嵌入 Python 代码生成行数据
- 新增 --type 参数可覆盖自动类型推断，适用于 ZIP 码等需保留前导零的列
- 新增 drop-index 命令和表方法，支持忽略不存在的索引
- transform 命令新增 --strict/--no-strict 选项，用于切换表的严格模式

## 全文

Release: sqlite-utils 4.1 The first dot-release since 4.0 a few days ago, introducing a number of minor new features. sqlite-utils insert and sqlite-utils upsert now accept a --code option for providing a block of Python code (or a path to a .py file) that defines a rows() function or rows iterable of rows to insert, as an alternative to importing from a file. (#684) sqlite-utils already had features that allow you to pass blocks of Python code as CLI arguments, for example this one for the sqlite-utils convert command: sqlite-utils convert content.db articles headline ' def convert(value): return value.upper()' Allowing blocks of code to generate new rows directly was on obvious extension of that pattern: sqlite-utils insert data.db creatures --code ' def rows(): yield {"id": 1, "name": "Cleo"} yield {"id": 2, "name": "Suna"} ' --pk id sqlite-utils insert and sqlite-utils upsert now accept --type column-name type to override the type automatically chosen when the table is created. This is useful for CSV or TSV columns such as ZIP codes that look like integers but should be stored as TEXT to preserve leading zeros. (#131) A long-standing feature request which turned out to be a simple implementation. New table.drop_index(name) method and sqlite-utils drop-index command for dropping an index by name. Both accept ignore=True/--ignore to ignore a missing index. (#626) sqlite-utils query can now read the SQL query from standard input by passing - in place of the query, for example echo "select * from dogs" | sqlite-utils query dogs.db -. (#765) Two more small features. I had Codex review all open issues and highlight the easiest ones! sqlite-utils upsert can now infer the primary key of an existing table, so --pk can be omitted when upserting into a table that already has a primary key. Another Codex suggestion, an obvious missing CLI feature from a Python library improvement that shipped in the 4.0 release. table.transform() and table.transform_sql() now accept strict=True or strict=False to change a table’s SQLite strict mode. Omitting the option preserves the existing mode. (#787) The sqlite-utils transform command now accepts --strict and --no-strict to change a table’s strict mode. (#787) These two were inspired by Prefer STRICT tables in SQLite by Evan Hahn, which did the rounds on Hacker News today. Evan pointed out that: Unfortunately, I don’t think there’s a way to ALTER a table to make it strict. I think you have to copy the data out of the non-strict table into the strict one. That's exactly what the sqlite-utils transform mechanism does, so I extended it to add the ability to switch tables from strict to non-strict and vice-versa. Here's the GPT-5.6 Sol xhigh Codex transcript I used to implement those new strict table features. One of the most useful prompts I ran was this one: use uv run python -c and manually exercise the new .transform(strict=) option, see if you can find any edge-cases or bugs Effectively telling the model to manually test its work, outside of the automated tests it had already written. This turned up two minor issues that we then fixed. Tags: projects, python, sqlite, sqlite-utils, annotated-release-notes, ai-assisted-programming

---

引用前请核对原文;本文由星际流动整理:https://feed.astralor.com/items/itm_54d7e80f8d26711b1c7339fc
