4.2.12026-08-13
4.2 版本误带入一个依赖问题,启动时报 No module named 'typing_extensions' 直接崩溃。本次修复该缺陷,升级后无需手动安装额外依赖即可正常使用。若你此前因报错降级或绕行,现在可以放心升到这一版。
4.22026-08-13
- New table.checks, table.columnchecks and table.tablechecks introspection properties expose column-level and table-level CHECK constraints. (#834)
- New sqlite_utils.ANY marker type for creating and introspecting SQLite ANY columns. The Python API and CLI can create, add and transform these columns, and table.transform() and table.extract() now preserve ANY columns and their values in STRICT tables. (#790)
- table.default_values now unescapes doubled single quotes in string defaults, so a default such as 'O''Brien' is returned as "O'Brien". Thanks, ikatyal2110. (#811)
- table.default_values now decodes unquoted TRUE, FALSE and NULL default literals as True, False and None respectively. (#836)
- table.enable_fts(..., tokenize=...) and sqlite-utils enable-fts --tokenize now safely quote the tokenizer argument, preventing a crafted value from injecting additional SQL. Thanks, Bunlong Heng. (#828)
- rowswhere(), pksandrowswhere(), search() and search_sql() now support offset= without requiring limit=. The sqlite-utils rows --offset option now works without --limit too. Thanks, ethanhawkes-gif. (#816, #821)
- Empty or whitespace-only input passed to rowsfromfile() is now handled as an empty CSV file instead of raising csv.Error. Thanks, Rami Abdelrazzaq. (#808, #837)
- sqlite-utils convert --dry-run now works for table and column names containing closing square brackets. (#829)
- table.indexes and table.xindexes now work for table, index and column names containing double quotes. This also fixes table.transform() for tables with those identifiers. Thanks, nyxst4ck. (#824, #825)
- Improved type annotations throughout the package and added Pyright regression checks to CI. (#833)
- Changing a TEXT column to INTEGER, FLOAT or REAL using table.transform() or sqlite-utilstransform now converts exact empty strings to NULL. Previously they remained empty strings in the numeric column. Thanks, ikatyal2110. (#488, #805)
table.transform() can handle many more edge-cases:
- table.transform() now preserves column-level and composite UNIQUE constraints, including constraint names, collations, sort order and ON CONFLICT behavior. Renaming columns updates those constraints, while dropping any constituent column removes the entire constraint. (#762)
- table.transform() now preserves AUTOINCREMENT primary keys and their sequence high-water marks. Previously a transform removed AUTOINCREMENT and could reuse deleted row IDs. (#602)
- table.transform() now preserves CHECK constraints, including comments within their expressions. Renaming a column rewrites identifier references in checks without changing string literals or function names. Dropping a column drops a check owned by that column, and raises TransformError if a remaining check depends on it. (#762)
- table.transform() now preserves comments immediately before or after column definitions. These comments move with the column if it is renamed or reordered, and are removed if the column is dropped. (#762)
- table.transform(rename=...) now preserves explicit indexes on renamed columns by dropping and recreating those indexes against the new column names. Previously this raised a TransformError. (#822)
- table.transform() now works for tables that are referenced by views. Previously the ALTER TABLE... RENAME TO step raised no such table if a view referenced the table being transformed. View definitions are left unchanged - see Tables referenced by views. This also fixes a bug where transform(keep_table=...) silently rewrote dependent views to point at the frozen backup table instead of the live one. (#831)
3.39.12026-07-26
修复 table.delete_where() 的一个事务漏洞:调用后连接会一直停留在未提交的事务中,等连接关闭时删除被回滚,行数据悄无声息地恢复原状,而调用方完全察觉不到。现在该接口会正确结束事务,删除结果得以真正落盘。#815
4.1.12026-07-12
sqlite-utils 本次更新聚焦安全防护:当事务开启、PRAGMA foreign_keys 处于启用状态,且目标表被带有 CASCADE、SET NULL 或 SET DEFAULT 等破坏性 ON DELETE 动作的外键引用时,table.transform() 会抛出 TransactionError 拒绝执行。原因是外键开关无法在事务内修改,旧版照常删除旧表时可能触发这些动作,悄悄删改被引用的行。遇到这种情况需按文档中的规避办法处理。另外,CLI 与 Python API 文档现已互相链接,查阅一方能直接跳到另一方的对应功能,定位用法更省事。
4.12026-07-11
sqlite-utils 这次更新集中在导入方式与表结构控制上。insert、upsert 新增 --code 选项,可直接传入一段 Python 代码或 .py 文件路径,用其中定义的 rows() 函数或 rows 可迭代对象生成数据,省去先落地成文件的步骤;--type column-name type 允许逐列覆盖建表时自动推断的类型,邮编这类看似整数、实际应存 TEXT 以保住前导零的列终于有解。删索引有了专门出口:新增 table.dropindex(name) 方法和 sqlite-utils drop-index 命令,配合 ignore=True/--ignore 可对不存在的索引不报错。query 支持用 - 从标准输入读取 SQL,如 echo "select from dogs" | sqlite-utils query dogs.db -;upsert 能自动推断已有表的主键,--pk 可以省了。此外 table.transform()、table.transform_sql() 新增 strict 参数,sqlite-utils transform 命令相应支持 --strict/--no-strict,用于切换 SQLite strict 模式,不传则维持原状。
4.02026-07-07
sqlite-utils 4.0 正式版发布。主版本号升级源于几处不向后兼容的修正,同时带来三项大功能:数据库迁移机制(migrations),让项目 schema 能随时间结构化演进;db.atomic() 嵌套事务支持,并整体改进了库内的事务行为;复合外键支持,涵盖创建、transform 与 table.foreign_keys 内省。
其余改动:upsert 改用 INSERT ... ON CONFLICT ... DO UPDATE SET,自动识别表主键,拒绝缺失必填主键值的记录;db.query() 改为立即执行且只接受返回行的语句,写入和 DDL 请改用 db.execute();CSV/TSV 导入默认推断列类型,向已有表插入时保留其原列类型;transform 现在保留外键的 ON DELETE/ON UPDATE 动作;Python API 的列名匹配改为大小写不敏感;命令行默认输出 UTF-8 JSON,加 --ascii 恢复转义输出;table.extract() 与 extracts= 不再为全 null 值创建查找表记录。从 3.x 升级的不兼容细节见官方 Upgrading 文档。
4.0rc4预发布2026-07-07
sqlite-utils 本次有一处破坏性变更:table.extract() 与 sqlite-utils extract 不再提取所有列均为 null 的行,这些行的外键列保留 null,不再指向查找表里的全空记录;多列提取时只要有一列有值仍会提取。inserts= 中的 extracts= 选项也不再为 None 建重复查找记录,table.lookup() 改用 IS 比较,修复了每次调用都插重复行的问题。
命令行 JSON 输出不再转义非 ASCII 字符,日本語 可直接输出;新增 --ascii 选项供不支持 UTF-8 的目标恢复旧行为,覆盖 query、rows、search、tables 等命令。--no-headers 现在对 --fmt 和 --table 输出同样生效。
写入侧修复集中:insert_all(..., pk=...) 对不存在的主键列统一抛 InvalidColumns;pk=..., ignore=True 不再抛 IndexError;db.execute() 失败后遗留的隐式事务会在抛错前回滚,避免后续写入被静默丢弃;以 ; 或 BOM 开头的事务控制语句现在会被正确拒绝,不再误提交。另补充了 db.query() 对无返回行的 PRAGMA 的限制说明。
4.0rc3预发布2026-07-06
sqlite-utils 4.0 上线,对外键做了大改。table.foreignkeys 改用 dataclass 表示 ForeignKey,不再能按元组解包或索引,只能按字段名访问;复合外键也统一收成一个对象(iscompound=True,columns/othercolumns 填充,column 为 None),此前一列一个的做法容易被误读成多个独立外键。sqlean.py 替换标准库 sqlite3 的用法被移除,现在有 pysqlite3 就用它。上下文管理器 db.ensureautocommitoff() 更名为 db.ensureautocommit_on(),旧名字与实际行为相反。
新能力集中在复合外键:foreignkeys= 传入列名元组即可建表,transform()、addforeignkey()、indexforeignkeys() 都支持它,且 drop 列会连带删除整个约束。另外 ForeignKey 新增 ondelete/on_update,transform() 不再悄悄丢掉 ON DELETE CASCADE 这类子句。Python API 的列名匹配改为大小写不敏感,与 SQLite 本身一致,修复了此前不少「静默无效」的场景。
4.0rc2预发布2026-07-05
sqlite-utils 这版以几处破坏性变更为核心:db.execute() 的写入改为自动提交,若已在事务中则并入,修复了此前隐式事务在连接关闭时被静默回滚的隐患;需要手动控制回滚的代码要改用新的 db.begin() 开启显式事务。db.query() 由惰性执行改为调用即执行,SQL 错误在调用处抛出,不返回行的语句会提示改用 db.execute()。参数校验统一改抛 ValueError 而非 AssertionError,避免 Python 以 -O 运行时 assert 被跳过;upsert 遇到缺失主键值的记录时抛 PrimaryKeyRequired,不再静默插入重复行;事务未提交时调用 enablewal(),或传入 Python 3.12 的 autocommit 连接,都会抛 TransactionError。同时删掉 View.enablefts() 和已无实际作用的 -d/--detect-types 选项。另修复 deletewhere()、optimize()、rebuildfts() 不提交改动的 bug,drop-table 与 drop-view 现在会拒绝删除对象类型不符的名称。
4.0rc1预发布2026-06-21
- New database migrations system, incorporating functionality that was previously provided by the separate sqlite-migrate plugin. Define migration sets using the new sqlite_utils.Migrationsclass and apply them using the sqlite-utils migrate command or the migrations Python API. (#752)
- New db.atomic() context manager providing nested transaction support using SQLite transactions and savepoints. Internal multi-step operations such as table.transform() now use this mechanism to avoid unexpectedly committing an existing transaction. (#755)
- Database objects can now be used as context managers, automatically closing the connection when the with block exits. The CLI also now closes database and file handles more reliably, resolving a number of ResourceWarning warnings. (#692)
- The sqlite-utils convert command can now accept a direct callable reference such as r.parsedate or json.loads --import json as the conversion code, as an alternative to calling it explicitly with r.parsedate(value). (#686)
- Fixed a bug where CSV or TSV files with only a header row could crash sqlite-utils insert and sqlite-utils memory when type detection was enabled. Thanks, Rami Abdelrazzaq. (#702, #707)
- Fixed a bug where installed plugins could be loaded while running the test suite, despite the test-mode safeguard that disables plugin loading. Thanks, Rami Abdelrazzaq. (#713, #719)
- table.detectfts() now recognizes legacy FTS virtual tables that quote the content= table name using square brackets, allowing table.enablefts(..., replace=True) to replace them correctly. (#694)
- Now depends on Click 8.3.1 or later, removing compatibility workarounds for Click's Sentineldefault values. (#666)
- Improved type annotations throughout the package, with ty now run in CI. (#697)
- Development tooling now uses uv dependency groups, with separate dev and docs groups. (#691)
- The test suite now runs against Python 3.15-dev. (#738)