CARVIEW |
Select Language
HTTP/2 200
date: Wed, 30 Jul 2025 05:03:28 GMT
content-type: text/html; charset=utf-8
vary: X-PJAX, X-PJAX-Container, Turbo-Visit, Turbo-Frame, X-Requested-With,Accept-Encoding, Accept, X-Requested-With
etag: W/"9e1bcd79b69a45a315dac1003005e848"
cache-control: max-age=0, private, must-revalidate
strict-transport-security: max-age=31536000; includeSubdomains; preload
x-frame-options: deny
x-content-type-options: nosniff
x-xss-protection: 0
referrer-policy: no-referrer-when-downgrade
content-security-policy: default-src 'none'; base-uri 'self'; child-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/; connect-src 'self' uploads.github.com www.githubstatus.com collector.github.com raw.githubusercontent.com api.github.com github-cloud.s3.amazonaws.com github-production-repository-file-5c1aeb.s3.amazonaws.com github-production-upload-manifest-file-7fdce7.s3.amazonaws.com github-production-user-asset-6210df.s3.amazonaws.com *.rel.tunnels.api.visualstudio.com wss://*.rel.tunnels.api.visualstudio.com objects-origin.githubusercontent.com copilot-proxy.githubusercontent.com proxy.individual.githubcopilot.com proxy.business.githubcopilot.com proxy.enterprise.githubcopilot.com *.actions.githubusercontent.com wss://*.actions.githubusercontent.com productionresultssa0.blob.core.windows.net/ productionresultssa1.blob.core.windows.net/ productionresultssa2.blob.core.windows.net/ productionresultssa3.blob.core.windows.net/ productionresultssa4.blob.core.windows.net/ productionresultssa5.blob.core.windows.net/ productionresultssa6.blob.core.windows.net/ productionresultssa7.blob.core.windows.net/ productionresultssa8.blob.core.windows.net/ productionresultssa9.blob.core.windows.net/ productionresultssa10.blob.core.windows.net/ productionresultssa11.blob.core.windows.net/ productionresultssa12.blob.core.windows.net/ productionresultssa13.blob.core.windows.net/ productionresultssa14.blob.core.windows.net/ productionresultssa15.blob.core.windows.net/ productionresultssa16.blob.core.windows.net/ productionresultssa17.blob.core.windows.net/ productionresultssa18.blob.core.windows.net/ productionresultssa19.blob.core.windows.net/ github-production-repository-image-32fea6.s3.amazonaws.com github-production-release-asset-2e65be.s3.amazonaws.com insights.github.com wss://alive.github.com api.githubcopilot.com api.individual.githubcopilot.com api.business.githubcopilot.com api.enterprise.githubcopilot.com; font-src github.githubassets.com; form-action 'self' github.com gist.github.com copilot-workspace.githubnext.com objects-origin.githubusercontent.com; frame-ancestors 'none'; frame-src viewscreen.githubusercontent.com notebooks.githubusercontent.com; img-src 'self' data: blob: github.githubassets.com media.githubusercontent.com camo.githubusercontent.com identicons.github.com avatars.githubusercontent.com private-avatars.githubusercontent.com github-cloud.s3.amazonaws.com objects.githubusercontent.com release-assets.githubusercontent.com secured-user-images.githubusercontent.com/ user-images.githubusercontent.com/ private-user-images.githubusercontent.com opengraph.githubassets.com copilotprodattachments.blob.core.windows.net/github-production-copilot-attachments/ github-production-user-asset-6210df.s3.amazonaws.com customer-stories-feed.github.com spotlights-feed.github.com objects-origin.githubusercontent.com *.githubusercontent.com; manifest-src 'self'; media-src github.com user-images.githubusercontent.com/ secured-user-images.githubusercontent.com/ private-user-images.githubusercontent.com github-production-user-asset-6210df.s3.amazonaws.com gist.github.com; script-src github.githubassets.com; style-src 'unsafe-inline' github.githubassets.com; upgrade-insecure-requests; worker-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/
server: github.com
content-encoding: gzip
accept-ranges: bytes
set-cookie: _gh_sess=HDCq1NHKi3ibofz%2FGiE%2BSqwfQurYb%2BTIyfLckp4LU3XB5kLF2rff0Sm5K8NEh6K8rQvYE8nCfHsomfKvIWEaPLfJJp4Xa2sP5Gzf7Icpr8EFBrC8fmplkvMM%2BaQ548tVB8huBOxTae4ADYxaXFNYrn0Y6VmMkzpxT5uHu80FHtF1FpsWxjukZgDR0aCCocaysowOlJNYVayJ%2BLMTzAAFzCxrVKHCUjTfm3MVd0ay5556zze15Rga9IkEq%2FvtyTVx%2FDTvvPhxrtYfN46rBCPHSA%3D%3D--zLktkepn10DQoN0%2B--A2%2FbQoPhxeFQWiMBuPfzlA%3D%3D; Path=/; HttpOnly; Secure; SameSite=Lax
set-cookie: _octo=GH1.1.1832383948.1753851808; Path=/; Domain=github.com; Expires=Thu, 30 Jul 2026 05:03:28 GMT; Secure; SameSite=Lax
set-cookie: logged_in=no; Path=/; Domain=github.com; Expires=Thu, 30 Jul 2026 05:03:28 GMT; HttpOnly; Secure; SameSite=Lax
x-github-request-id: B90C:1CFCAC:1279EA7:167E850:6889A7A0
Home · Tencent/wcdb Wiki · GitHub
Skip to content
Navigation Menu
{{ message }}
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Home
qiuwenchen edited this page Mar 9, 2024
·
47 revisions
WCDB 是一个易用、高效、完整的移动数据库框架,它基于 SQLite 和 SQLCipher 开发,在微信中应用广泛,且支持在 C++、Java、Kotlin、Swift、Objc 五种语言环境中使用。
One line of code 是 WCDB 设计的基本原则之一。通过更现代的数据库开发模式,减少开发者所需使用的代码量,绝大部分增删查改都只需一行代码即可完成:
// 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];
- 模型绑定。基于C++、Java、Kotlin、Swift、Objc 的语法特性,使用声明式语句建立原生语言类型与数据库表之间的映射关系,从而使得开发者可以通过类对象直接操作数据库。
- 范型与类型推导。WCDB 的接口与 C++、Java、Kotlin、Swift、Objc 的语法相结合,使复杂的数据库操作可以以简明的方式表达出来。因此,代码不仅易于编写,而且更易于阅读和维护。
- 语言集成查询。深度结合 C++、Java、Kotlin、Swift、Objc 和 SQL 的语法,使得纯字符串的 SQL 可以以原生代码的形式表达出来。结合代码提示及纠错,极大地提高了开发效率。
WCDB 基于 SQLite,并深入其源码进行了性能优化,以适配移动终端的场景。同时,对于常用且性能消耗较大的场景,如批量插入等,也做了针对性的优化。 在多线程方面,WCDB 不仅可以安全地在任意线程进行数据库操作,且其内部会智能地根据操作类型调配资源,使其能够并发执行,进一步提升效率。
WCDB 总结实践中常见的问题,为数据库开发提供更完整、全面的使用体验:
- 加密。基于 SQLCipher 的加密机制,为数据安全提供保障。
- 全文搜索。WCDB 提供简单易用的全文搜索接口,并包含适配多种语言的分词器,使得数据搜索更精准。
- 反注入。内建在语言集成查询中的反注入机制,可以避免第三方从输入框注入 SQL,进行预期之外的恶意操作。
- 字段升级。数据库模型与类定义绑定,使得字段的增加、删除、修改都与类变量的定义保持一致,不需要开发者额外地管理字段的版本。
- 损坏修复。修复工具可以在系统错误、磁盘故障等情况下,尽最大限度地将损坏的数据找回并导出。
- 数据迁移。WCDB 支持通过简单的配置将数据表迁移到其他数据库,而且让开发者可以以迁移已经完成为假定前提 进行开发,无需关心迁移的中间状态和进度。
- 数据压缩。WCDB 支持通过简单的配置来使用 Zstd 压缩数据表中的部分字段的内容。配置后,开发者不会感知到数据加解压的细节,而且 WCDB 会自动压缩存量数据。
WCDB 支持 C++、Java、Kotlin、Swift、Objc 五种语言进行开发,但是这五种语言在底层是共享同一套逻辑的,整体架构如下图所示:

在这个架构下,不同语言版本的WCDB可以拥有同样的接口结构和接口能力,开发者在一个项目中只要用一个WCDB就可以满足不同语言的开发需求,不同语言的数据库逻辑不会产生冲突。一些如错误监听之类的全局接口,可以做到一处配置,同时作用于不同语言的数据库,可以节省代码,统一数据库管理逻辑。
WCDB 的安装和使用教程请看右侧导航栏,查看你需要使用的开发语言的文档。
- 欢迎使用 WCDB
- 基础教程
- 进阶教程
- 欢迎使用 WCDB
- 基础教程
- 进阶教程
- 欢迎使用 WCDB
- 基础教程
- 进阶教程
- 欢迎使用 WCDB
- 基础教程
- 进阶教程
Clone this wiki locally
You can’t perform that action at this time.