@huihoo: 这次 SQLite 讨论,大家也可就此深入学习一下 SQLite 微信基于 SQLite 和 SQLCipher 构建的移动数据库框架 WCDB https://github.com/Tencent/wcdb DB Browser for…
摘要
介绍微信基于 SQLite 和 SQLCipher 构建的移动数据库框架 WCDB,并推荐相关学习资源。
查看缓存全文
缓存时间: 2026/07/02 18:25
这次 SQLite 讨论,大家也可就此深入学习一下 SQLite
微信基于 SQLite 和 SQLCipher 构建的移动数据库框架 WCDB https://github.com/Tencent/wcdb
DB Browser for SQLite (DB4S) https://github.com/sqlitebrowser/sqlitebrowser…
SQLCipher 是 SQLite 的一个分支 增加了对数据库文件的 256 位 AES 加密和其他安全功能 https://github.com/sqlcipher/sqlcipher…
SQLite 文档很丰富 比如:SQLite 读取和写入小数据块(例如缩略图)的速度比使用 fread() 或 fwrite() 从磁盘上的单个文件中读取或写入相同数据块的速度快 35% 单个 SQLite 数据库存储 10 KB 的数据块比将这些数据块存储在单个文件中节省约 20% 的磁盘空间 https://sqlite.org/fasterthanfs.html…
SQLite Internals: How The World’s Most Used Database Works https://compileralchemy.com/assets/books/foss_sqlite_internals.pdf…
Tencent/wcdb
Source: https://github.com/Tencent/wcdb
WCDB
中文版本请参看这里
WCDB is an efficient, complete, easy-to-use mobile database framework used in the WeChat application. It’s based on SQLite and SQLCipher, and supports five languages: C++, Java, Kotlin, Swift and Objective-C.
Feature
Easy-to-use
- ORM (Object Relational Mapping): WCDB provides a flexible, easy-to-use ORM for creating tables, indices and constraints, as well as CRUD through C++/Java/Kotlin/Swift/Objc objects.
- WINQ (WCDB language integrated query): WINQ is a native data querying capability which frees developers from writing glue code to concatenate SQL query strings.
With ORM and WINQ, you can insert, update, query and delete objects from database in one line code:
// C++
database.insertObjects<Sample>(Sample(1, "text"), myTable);
database.updateRow("text2", WCDB_FIELD(Sample::content), myTable, WCDB_FIELD(Sample::id) == 1);
auto objects = database.getAllObjects<Sample>(myTable, WCDB_FIELD(Sample::id) > 0);
database.deleteObjects(myTable, WCDB_FIELD(Sample::id) == 1);
// Java
database.insertObject(new Sample(1, "text"), DBSample.allFields(), myTable);
database.updateValue("text2", DBSample.content, myTable, DBSample.id.eq(1));
List<Sample> objects = database.getAllObjects(DBSample.allFields(), myTable, DBSample.id.gt(0));
database.deleteObjects(myTable, DBSample.id.eq(1));
// Kotlin
database.insertObject<Sample>(Sample(1, "text"), DBSample.allFields(), myTable)
database.updateValue("text2", DBSample.content, myTable, DBSample.id.eq(1))
val objects = database.getAllObjects<Sample>(DBSample.allFields(), myTable, DBSample.id.gt(0))
database.deleteObjects(myTable, DBSample.id.eq(1))
// Swift
try database.insert(Sample(id:1, content:"text"), intoTable: myTable)
try database.update(table: myTable,
on: Sample.Properties.content,
with: "text2"
where:Sample.Properties.id == 1)
let objects: [Sample] = try database.getObjects(fromTable: myTable,
where: Sample.Properties.id > 0)
try database.delete(fromTable: myTable where: Sample.Properties.id == 1)
// Objc
[database insertObject:sample intoTable:myTable];
[database updateTable:myTable
setProperty:Sample.content
toValue:@"text2"
where:Sample.id == 1];
NSArray* objects = [database getObjectsOfClass:Sample.class
fromTable:myTable
where:Sample.id > 0];
[database deleteFromTable:myTable where:Sample.id == 1];
Efficient
Through the framework layer and sqlcipher source optimization, WCDB have more efficient performance.
- Multi-threaded concurrency: WCDB supports concurrent read-read and read-write access via connection pooling.
- Deeply optimized: WCDB has deeply optimized the source code and configuration of SQLite to adapt to the development scenarios of mobile terminals. At the same time, WCDB has also been optimized for common time-consuming scenarios, such as writing data in batches.
Complete
WCDB summarizes common problems in practice to provide a more complete development experience for database development:
- Encryption Support: WCDB supports database encryption via SQLCipher.
- Corruption recovery: WCDB provides a built-in repair kit for database corruption recovery.
- Anti-injection: WCDB provides a built-in protection from SQL injection.
- Database model upgrade: The database model is bound to the class definition, so that the addition, deletion and modification of database fields are consistent with the definition of class variables.
- Full-text search: WCDB provides an easy-to-use full-text search interface and includes tokenizers for multiple languages.
- Data Migration: WCDB supports to migrate data from one databasse to another with simple configuration. And developers don’t need to care about the intermediate status and progress of the migration.
- Data Compression: WCDB supports to compress content via Zstd within specific fields of a database table through a simple configuration. Once configured, the details of data compression and decompression become transparent to developers, and WCDB can automatically compress existing data.
Compatibility
WCDB has interfaces in five languages: C++, Java, Kotlin, Swift, and Objc. Interfaces in different languages share the same underlying logic. The code structure of WCDB is shown in the figure below:

Under such architecture, WCDB in different languages can have the same interface structure and interface capabilities. In one project, you can write database code in different languages with one WCDB. Database logic in different languages will not conflict. Some global interfaces such as error monitoring can work on database logic in different languages at the same time.
Build and Install
Following wikies contain the detailed instructions about building and installing of WCDB.
- Building and Installing of WCDB C++
- Building and Installing of WCDB Java/Kotlin
- Building and Installing of WCDB Swift
- Building and Installing of WCDB Objc
Tutorials
Tutorials of different languages can be found below:
- Tutorials for WCDB C++
- Tutorials for WCDB Java/Kotlin
- Tutorials for WCDB Swift
- Tutorials for WCDB Objc
Contributing
If you are interested in contributing, check out the [CONTRIBUTING.md], also join our Tencent OpenSource Plan.
WCDB 正式加入TDS 腾讯端服务产品联盟,携手联盟其他成员,共同致力于构建开放共赢的大前端技术产品生态。
信息公示
-
开发者: 深圳市腾讯计算机系统有限公司
相似文章
@Huahuazo: 搞数据库的兄弟们,注意了——以后真不用再装一桌面的客户端了。 挖到一个宝藏工具 DBX,一个客户端直接打通所有主流数据库: ① MySQL、PostgreSQL、SQLite ② Redis、MongoDB、ClickHouse ③ 连国…
DBX 是一款轻量级多数据库客户端,支持 MySQL、PostgreSQL、Redis、MongoDB 等 60+ 数据库,安装包仅 15MB,内置 AI 助手可自然语言生成 SQL。
@Crypto_QianXun: Codex 这两个 GitHub 项目一接上,资料归档直接起飞。 一个管微信,一个管飞书: 微信本地资料库: https://github.com/mcncarl/yichen-skills/tree/main/wechat-local-…
介绍了一个名为 yichen-skills 的 GitHub 仓库,包含多个技能工具,能连接 Codex 与微信、飞书等平台,实现资料归档和工作流自动化。
@jinchenma_ai: 卧槽!刚发现一个能读取微信聊天记录的工具,私域运营神器啊! wx-cli,让 AI 可以自由读取微信消息。 1. 消息随便翻:不用点开微信那个难用的搜索框,直接输入关键词就能搜全库聊天记录,速度快到飞起。 2. 朋友圈挖掘机:能直接看朋友…
wx-cli is a local tool for extracting and analyzing WeChat chat history and moments, enabling AI integration without cloud data transmission.
@hank_aibtc: 兄弟们,挖到个神级项目! 用闲置安卓手机直接变 SMS 网关,HTTP API 随便调用发收短信,再也不用给 Twilio 或短信平台交冤枉钱了! 项目叫 httpSMS,GitHub:NdoleStudio/httpsms 简单说就是装…
介绍开源项目 httpSMS,可将闲置安卓手机变为 SMS 网关,通过 HTTP API 收发短信,支持自托管 Docker 和端到端加密,省钱且稳定。
@jaywcjlove: Tabularis — 一款开源、跨平台的现代数据库客户端。 支持 PostgreSQL、MySQL/MariaDB 和 SQLite,内置 AI、MCP 与 Notebook,并支持插件扩展。轻量、原生、高颜值,专为开发者打造。 支持 …
Tabularis 是一款开源、跨平台的现代数据库客户端,支持 PostgreSQL、MySQL/MariaDB 和 SQLite,内置 AI、MCP 与 Notebook,并支持插件扩展,专为开发者打造。