SQLite for Everything
SQLite for Everything
JoeCode | Aug 19, 2026
Dr. Raphael Bauer penned an excellent article (PostgreSQL for Everything) on the value of using PostgreSQL to power your enterprise. I’ve taken the liberty of correcting a couple of errors, mainly he should of chosen SQLite 😊 (this is mostly a joke, I ❤️ PostgreSQL, its great tech.) Raphael Bauer 博士写了一篇非常棒的文章(《PostgreSQL for Everything》),探讨了使用 PostgreSQL 驱动企业级应用的价值。我冒昧地纠正了其中的几个“错误”,主要是他本应该选择 SQLite 😊(这主要是个玩笑,我 ❤️ PostgreSQL,它是一项伟大的技术。)
Contrary to popular belief, the answer to everything is NOT 42. It’s SQLite. (Fine. It might also be sqlite3.) 与普遍的看法相反,万物的答案并不是 42,而是 SQLite。(好吧,可能也是 sqlite3。)
Intro
引言
SQLite will outlive most of what you are running right now. SQLite 的寿命将超过你目前运行的大多数系统。
Back then the accepted wisdom was that SQLite was a toy. A file. Something you shipped inside a phone app so you didn’t have to write a config parser. Real applications got a real database with a real port number and a real daemon and a real 3am page. 过去,人们普遍认为 SQLite 只是一个玩具。一个文件。一种你塞进手机应用里,这样就不必编写配置解析器的东西。真正的应用程序需要一个真正的数据库,配有真正的端口号、真正的守护进程,以及真正的凌晨 3 点寻呼报警。
In my humble opinion, the power of SQLite comes from three sources: 在我看来,SQLite 的强大之处源于三个方面:
- It is rock-solid and stable.
- 它坚如磐石且极其稳定。
- It is easy to run, install and scale. Mostly because there is nothing to run.
- 它易于运行、安装和扩展。主要是因为它根本不需要“运行”什么(后台服务)。
- It massively simplifies your IT setup by being not only an RDBMS, but also a full-text search engine, a document store, a cache, a vector index, and a file format.
- 它极大地简化了你的 IT 设置,因为它不仅是一个关系型数据库管理系统(RDBMS),还是全文搜索引擎、文档存储、缓存、向量索引和文件格式。
Let’s have a closer look. 让我们深入了解一下。
Rock Solid and Stable
坚如磐石且极其稳定
SQLite is boring old technology. First release: 2000. It is also, by a margin that isn’t close, the most widely deployed database engine on the planet. It’s in your phone. It’s in your browser. It’s in your car. It’s in the plane you flew here on. There are more running copies of SQLite than there are running copies of everything else combined, and it isn’t a contest. SQLite 是一项枯燥的旧技术。首次发布于 2000 年。同时,它是地球上部署最广泛的数据库引擎,其领先优势遥遥领先。它在你的手机里,在你的浏览器里,在你的车里,在你乘坐的飞机里。运行中的 SQLite 实例数量比其他所有数据库的总和还要多,这根本不是一个量级的竞争。
Ironing out bugs in database systems takes time. SQLite had that time, and then kept going. The test suite has 100% branch coverage under MC/DC, the same standard used for avionics software. There is roughly 500 times more test code than library code. The project has a stated support commitment through the year 2050, which is a longer planning horizon than your company’s mission statement. 修复数据库系统中的 Bug 需要时间。SQLite 拥有充足的时间,并且一直在持续改进。其测试套件在 MC/DC 标准下实现了 100% 的分支覆盖率,这与航空电子软件使用的标准相同。测试代码的数量大约是库代码的 500 倍。该项目承诺支持到 2050 年,这比你公司的使命宣言规划得还要长远。
It’s also in the public domain. Not open source. Public domain. No license, no CLA, no attribution clause, no vendor with a Series C and a change of heart. 它还属于公共领域(Public Domain)。不是开源,而是公共领域。没有许可证,没有贡献者许可协议(CLA),没有署名条款,也没有那种拿了 C 轮融资后突然变卦的供应商。
True, SQLite is old. But it keeps quietly shipping modern features: window functions, RETURNING, strict tables, generated columns, jsonb. Every release is a small, well-tested, backwards-compatible improvement, which is the least exciting and most valuable thing a database can be. 诚然,SQLite 很老。但它一直在悄悄地推出现代特性:窗口函数、RETURNING 子句、严格表(Strict Tables)、生成列、jsonb 等。每一次发布都是一次小规模、经过充分测试且向后兼容的改进,这对于数据库而言,是最不令人兴奋但却最有价值的特质。
Easy to Run, Install and Scale
易于运行、安装和扩展
Installing SQLite locally is easy in the sense that you have already done it. It is bundled with every major Linux distribution, ships inside Python, Ruby, PHP, Go, Rust, .NET, Android and iOS, and is sitting on your Mac right now whether you asked for it or not. 在本地安装 SQLite 很简单,因为你其实已经安装过了。它捆绑在每一个主流 Linux 发行版中,内置于 Python、Ruby、PHP、Go、Rust、.NET、Android 和 iOS 中,无论你是否需要,它现在就躺在你的 Mac 里。
Running tests against a database identical to production is not a Test containers problem here. It is :memory:. Your test suite spins up a fresh database in microseconds, per test, in parallel, with no Docker daemon and no port collisions. The thing you test against is the thing you ship, because it’s the same library compiled into the same binary.
针对与生产环境完全一致的数据库运行测试,在这里根本不需要 Testcontainers。直接使用 :memory: 即可。你的测试套件可以在微秒级时间内为每个测试用例并行启动一个全新的数据库,无需 Docker 守护进程,也不会有端口冲突。你测试的对象就是你发布的对象,因为它们是编译进同一个二进制文件中的同一个库。
If you want to run SQLite on a server: you already are. It came with the OS. 如果你想在服务器上运行 SQLite:你其实已经在运行了。它随操作系统自带。
Scaling is the part where people expect the article to get quiet, so let’s not: 扩展性是人们认为这篇文章会“沉默”的部分,所以我们偏不:
- Vertical: a modern NVMe drive and a machine with 128GB of RAM will serve a shocking amount of traffic when your database round trip is a function call instead of a network hop. No connection pool. No TLS handshake. No pgbouncer. Nanoseconds instead of milliseconds.
- 垂直扩展: 当你的数据库往返调用只是函数调用而不是网络跳转时,现代 NVMe 硬盘和 128GB 内存的机器可以处理惊人的流量。没有连接池,没有 TLS 握手,没有 pgbouncer。延迟是纳秒级而非毫秒级。
- Replication and backup: Litestream streams your WAL to S3 continuously. LiteFS gives you distributed reads. Both are small, single-binary, and boring.
- 复制与备份: Litestream 可以将你的 WAL(预写日志)持续流式传输到 S3。LiteFS 为你提供分布式读取。两者都是小巧、单一二进制文件且“枯燥”的工具。
- Hosted: Turso, Cloudflare D1, rqlite, and friends will happily sell you SQLite with a control panel if you miss having a control panel.
- 托管服务: 如果你怀念控制面板,Turso、Cloudflare D1、rqlite 等服务商很乐意为你提供带有控制面板的 SQLite。
That makes SQLite one of the most widely supported pieces of software in existence. For you this means less maintenance and more time building features for clients. 这使得 SQLite 成为现存支持最广泛的软件之一。对你而言,这意味着更少的维护工作,以及更多为客户构建功能的时间。
Simplifies Your IT Setup
简化你的 IT 设置
Running SQLite in the cloud is zero clicks, because it’s a file next to your application. But it gets better. SQLite can replace a whole shelf of systems you’d otherwise be running. 在云端运行 SQLite 无需任何点击操作,因为它只是你应用程序旁边的一个文件。但不仅如此,SQLite 可以替代你原本需要运行的一整套系统。
SQLite Replaces Solr and Elastic: Full-Text Search
SQLite 替代 Solr 和 Elastic:全文搜索
SQLite ships with FTS5, a full-text search engine built into the library you already have linked. Tokenizers, prefix queries, phrase queries, NEAR, boolean operators, custom ranking with BM25, and snippet/highlight functions for rendering results. SQLite 自带 FTS5,这是一个内置在你已经链接的库中的全文搜索引擎。它支持分词器、前缀查询、短语查询、NEAR 运算符、布尔运算符、基于 BM25 的自定义排序,以及用于渲染结果的片段/高亮函数。
Two things worth appreciating here. First, there is no sync problem, because there is no second system. Your search index is updated in the same transaction as your data, by definition, forever. Every “why is the search index stale” incident you have ever had was caused by architecture you didn’t need. 这里有两点值得称赞。首先,没有同步问题,因为根本没有第二个系统。根据定义,你的搜索索引与数据在同一个事务中更新,永远如此。你曾经遇到的每一个“为什么搜索索引过期了”的事故,都是由你本不需要的架构引起的。
Second, it’s fast in a way that surprises people. Simon Willison’s Datasette runs faceted full-text search over multi-gigabyte SQLite files and returns in milliseconds, on a small VM, for free. 其次,它的速度快得令人惊讶。Simon Willison 的 Datasette 在多 GB 的 SQLite 文件上运行分面全文搜索,在小型虚拟机上即可在毫秒级返回结果,而且是免费的。
Is FTS5 going to do multilingual analysis chains and distributed sharding across 40 nodes? No. Do you have 40 nodes? Also no. FTS5 能做多语言分析链和跨 40 个节点的分布式分片吗?不能。你有 40 个节点吗?也没有。
SQLite Replaces MongoDB: Excellent JSON Support
SQLite 替代 MongoDB:出色的 JSON 支持
SQLite has excellent support for storing and querying JSON. The JSON functions are built in, -> and ->> operators work the way you’d hope, and since 3.45 there’s jsonb, a binary representation that skips the reparse on every access.
SQLite 对存储和查询 JSON 有着极好的支持。JSON 函数是内置的,-> 和 ->> 运算符的工作方式正如你所期望的那样。自 3.45 版本以来,还引入了 jsonb,这是一种二进制表示形式,避免了每次访问时重新解析。
The part people miss: you can index into JSON. Create a generated column from a JSON path, index the generated column, and you have a fast lookup. 人们容易忽略的一点是:你可以对 JSON 进行索引。通过 JSON 路径创建一个生成列,对该生成列建立索引,你就拥有了快速查找能力。