编程与软件工程sqlite.org
SQLite 作为应用文件格式(2014)
SQLite as an Application File Format (2014)
2018 — 2025,它一次次回到首页
黑点是上首页(≥ 50 分)的那次投稿,空心点是没冲上去的投稿,点越大分数越高。
导读
SQLite 官方文档的经典页面,主张用 SQLite 数据库作为应用程序的文件格式,替代自定义二进制或 XML 等格式。它列举了诸多优势:单文件便于复制移动、事务保证写入原子性、可增量更新、支持任意大小数据、可查询可扩展等,并给出实现建议。
为什么经久不衰:它把“应用文件格式”这一常见工程难题给出了一个经过数十年验证的标准答案,原子事务、单文件、可查询等特性让它在今天依然是值得推荐的方案。
HN 评论精选
开放格式让第三方工具和扩展变得轻而易举
用 SQLite 做应用文件格式的一大好处是:你可以写辅助小工具来扩展应用本身。比如 Adobe Lightroom 用 SQLite 存目录,写个外部程序帮它清理失效图片、生成播放列表就非常简单,只需一门带 SQLite 连接器的语言,再用 sqldiff 花几分钟摸清表结构即可。试试用同样方式逆向工程一个私有文件格式?
TheRealPomax查看英文原文
The great thing about applications that use sqlite as their application file format is that you can write secondary apps and utilities to supplement the applications themselves. For example, Adobe's Lightroom uses sqlite as their application file format, which means that it's almost trivial to write an application to help it do things it's either really bad/exceedingly slow at (like removing images from a catalogue that no longer exist on disk) or literally can't do (like generating a playlist of files-on-disk for a specific collection or tag), without being locked into whatever janky scripting solution exists in-app. If there even is one to begin with. All you need is a programming language with a sqlite connector, and you're in the driving seat. And sure, you'll need to figure out the table schemas you need to care about, but sqlite comes with sqldiff so it's really easy to figure out which operations hit which tables with only a few minutes of work. Good luck reverse engineering proprietary file formats in the same way!
SQLite 免费提供了自定义格式很难实现的原子写入保证
“原子事务”这一特性在自定义文件格式中远比人们意识到的更需要正式支持。以保证原子性的方式写文件比看起来难得多;当应用有百万用户时,每天都会有人遇到写入中途断电,应用读到损坏文件时该怎么办?我在移动应用中用 SQLite、在云端用 LMDB 解决过这个问题,也用 C 手写过原子写文件流程——不推荐后者。
corysama查看英文原文
“Atomic transactions” is a feature needs formal support in random file formats way more often than people realize. Simply writing to a file at all in an guaranteed-atomic way is much harder than it looks. That guarantee becomes important when your app gets widely distributed. If you have a million users of your free mobile app, 1 in a million events happen every day. For example: random hardware shutdown midway through a file write operation. How is your app going to react when it reads back that garbled file? I’ve used SQLite on mobile apps to mitigate this problem. I’ve used LMDB on a cloud app where the server was recording a lot of data, but also rebooting unexpectedly. Would recommend. I’ve also gone through the process of crafting an atomic file write routine in C. https://danluu.com/file-consistency/ It was “fun” if your idea of fun is responding to the error code of fclose(), but I would not recommend...
实战经验:迁移到 SQLite 后兼容性和维护性大幅改善
我在工作中曾把一个二进制文件格式迁移到基于 SQLite 的 ORM schema,效果非常好,几乎免费获得了(有限的)前向和后向兼容,省去了大量繁琐的 if-else 代码。SQLite 是许多场景下数据序列化/持久化/交换的最佳选择,尤其是存储 blob 或需要全精度保存的大浮点数组时。
romwell查看英文原文
I have migrated a binary file format to an SQLite-based ORM schema at one of my jobs. It worked out amazingly well, with (limited) forward and backward compatibility for nearly free. A lot of hairy if-else code was made unnecessary. SQLite is IMHO the best option for data serialization/persistence/interchange in many cases, especially when some data is a blob, or, say, a huge array of floating-point numbers that you need to store with full precision (which makes text-based formats clunky to deal with).
提醒:WAL 模式下“单文件”的说法需要附加条件
文中说“SQLite 数据库包含在单个文件中,文档隐喻得以保留”——在默认开启 WAL 和共享内存的情况下这还成立吗?此时只考虑数据库文件已不安全。虽然有 pragma 可以禁用这些特性,但人们应该了解它们并谨慎使用,文档应该更新以介绍这些概念。
LeoNatan25查看英文原文
> Single-File Documents. An SQLite database is contained in a single file, which is easily copied or moved or attached. The "document" metaphor is preserved. Is this still true by default? With write-ahead (wal) and shared memory (shm) enabled, it is no longer safe to consider only the database file. Pragmas exist to disable those, but people should be familiar of these features and use with care. The document should be updated to introduce these concepts.
历次讨论
同类还值得读
开源应用架构
The Architecture of Open Source Applications
《开源软件架构》(AOSA)是一本在线免费书,邀请知名开源项目的作者亲自剖析其内部设计,涵盖 SQLAlchemy、LLVM、Audacity、Apache、Bash 等系统。
编程与软件工程上首页 9 次 · 2011–2024aosabook.org编辑精选编程语言简史:简短、不完整且多半错误
A Brief, Incomplete, and Mostly Wrong History of Programming Languages
一篇以戏谑、故意不准确的方式回顾编程语言史的博客文章,用夸张轶事和讽刺定义串起 Lisp、C、C++、Java、JavaScript、PHP 等语言。
编程与软件工程上首页 8 次 · 2009–2021james-iry.blogspot.comSQLite 是如何测试的
How SQLite is tested
SQLite 官方文档页,系统介绍 SQLite 的测试体系:多种测试方法(TCL 测试、模糊测试、回归测试、静态分析等)和海量测试用例,展示了这个小型开源项目如何靠极致测试获得…
编程与软件工程上首页 8 次 · 2009–2025sqlite.org编辑精选高级编程语言(2009)
Advanced programming languages (2009)
Matt Might 的经典文章,按用途推荐“高级编程语言”:如果追求就业就选主流语言,如果追求表达力、学术研究或创业,则推荐 Haskell、OCaml、Scala 等函数式语…
编程与软件工程上首页 8 次 · 2009–2022matt.might.net我的 Forth 与栈机器经历
Yosefk - My history with Forth & stack machines
作者以亲身经历回顾了使用 Forth 语言和栈式机器的历程:既赞叹其简洁优雅、代码量小、可自举的优点,也坦率指出栈操作在实际编程中的痛苦,以及 Forth 社区文化中的问题。
编程与软件工程上首页 8 次 · 2010–2024yosefk.com编辑精选