MCPcopy Index your code
hub / github.com/Tencent/wcdb

github.com/Tencent/wcdb @v2.1.16

Chat with this repo
repository ↗ · DeepWiki ↗ · release v2.1.16 ↗ · + Follow
11,649 symbols 28,594 edges 2,174 files 1,165 documented · 10%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

WCDB

PRs Welcome Release Version LanguagePlatform

中文版本请参看这里

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.

Tutorials

Tutorials of different languages can be found below:

Contributing

If you are interested in contributing, check out the [CONTRIBUTING.md], also join our Tencent OpenSource Plan.

WCDB 正式加入TDS 腾讯端服务产品联盟,携手联盟其他成员,共同致力于构建开放共赢的大前端技术产品生态。

信息公示

Extension points exported contracts — how you extend this code

DatabaseErrorHandler (Interface)
An interface to let the apps define the actions to take when the following errors are detected database corruption [6 …
deprecated/android/wcdb/src/com/tencent/wcdb/DatabaseErrorHandler.java
DatabaseErrorHandler (Interface)
An interface to let apps define an action to take when database corruption is detected. [5 implementers]
src/java/compat/src/main/java/com/tencent/wcdb/compat/DatabaseErrorHandler.java
OnCancelListener (Interface)
Listens for cancellation. [8 implementers]
deprecated/android/wcdb/src/com/tencent/wcdb/support/CancellationSignal.java
TestOperation (Interface)
(no doc) [37 implementers]
src/java/test/src/androidTest/java/com/tencent/wcdbtest/base/DatabaseTestCase.java
IBulkCursor (Interface)
This interface provides a low-level way to pass bulk cursor data across both process and language boundaries. Applicatio [5 …
deprecated/android/wcdb/src/com/tencent/wcdb/IBulkCursor.java
SelectingObjectOperation (Interface)
(no doc) [37 implementers]
src/java/test/src/androidTest/java/com/tencent/wcdbtest/base/TableTestCase.java
CrossProcessCursor (Interface)
A cross process cursor is an extension of a Cursor that also supports usage from remote processes. The conte [4 implementers]
deprecated/android/wcdb/src/com/tencent/wcdb/CrossProcessCursor.java
IndexedColumnConvertible (Interface)
(no doc) [7 implementers]
src/java/main/src/main/java/com/tencent/wcdb/winq/IndexedColumnConvertible.java

Core symbols most depended-on inside this repo

size
called by 509
src/common/base/UnsafeData.cpp
order
called by 427
src/java/main/src/main/java/com/tencent/wcdb/winq/Column.java
select
called by 382
src/java/main/src/main/java/com/tencent/wcdb/chaincall/Select.java
get
called by 313
src/java/main/src/main/java/com/tencent/wcdb/base/CppObject.java
from
called by 307
src/java/main/src/main/java/com/tencent/wcdb/chaincall/Select.java
eq
called by 259
src/java/main/src/main/java/com/tencent/wcdb/winq/ExpressionOperable.java
value
called by 238
src/common/core/Tag.cpp
orderBy
called by 237
src/java/main/src/main/java/com/tencent/wcdb/chaincall/Update.java

Shape

Method 6,591
Class 3,224
Function 1,489
Enum 300
Interface 45

Languages

C++61%
Java32%
C3%
Kotlin3%
Python1%

Modules by API surface

src/java/main/src/main/java/com/tencent/wcdb/core/Database.java140 symbols
deprecated/android/wcdb/src/com/tencent/wcdb/database/SQLiteConnection.java124 symbols
deprecated/android/wcdb/src/com/tencent/wcdb/database/SQLiteDatabase.java103 symbols
src/java/test/src/androidTest/java/com/tencent/wcdbtest/crud/ObjectSelectTest.java101 symbols
src/java/kotlin-test/src/androidTest/java/com/tencent/wcdbtest/crud/ObjectSelectTest.kt100 symbols
src/common/core/sqlite/AbstractHandle.cpp98 symbols
src/cpp/core/Database.cpp84 symbols
src/common/winq/identifier/Pragma.cpp81 symbols
tools/prebuild/openssl/include/openssl/ossl_typ.h80 symbols
src/bridge/cppbridge/DatabaseBridge.cpp69 symbols
deprecated/android/wcdb/src/com/tencent/wcdb/repair/RepairKit.java68 symbols
src/java/main/src/main/java/com/tencent/wcdb/winq/ExpressionOperable.java66 symbols

For agents

$ claude mcp add wcdb \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact