rxdb-adapter-sqlite
@aiao/rxdb 的官方 SQLite 适配器,基于 SQLite 官方 WASM 构建,为核心引擎提供 SQLite 存储后端。
安装
pnpm add @aiao/rxdb @aiao/rxdb-adapter-sqlite rxjs
用法
import { createSqliteClient, RxDBAdapterSqlite } from '@aiao/rxdb-adapter-sqlite';
createSqliteClient:创建 SQLite 客户端RxDBAdapterSqlite:接入@aiao/rxdb的适配器实现sqliteLoad/resetSqliteLoadCache:WASM 加载与缓存控制- 类型:
SqliteOptions、SqliteLoadOptions、SqliteRepositoryConstructor等
适配器共享内核(表名解析、规则编译、基础 Repository)来自 @aiao/rxdb-adapter-sqlite-core。
备份与恢复
backup() / restore() / cleanupIncompleteRestore() 由 @aiao/rxdb-adapter-sqlite-core 提供,语义与错误码见那里。
| 配置 | 备份 / 恢复 |
|---|---|
不开 opfs | ✅ 内存库 |
opfs: true | ✅ OPFS,持久化 journal_mode 为 delete |
opfs: true, opfsFallback: 'memory' | ❌ unsupported_combination(opfsFallback):OPFS 打不开时静默落到内存,恢复目标不确定 |
在 Worker 里跑时,每次连接租用 Worker 的一条独立子端口:恢复用一条连接写库,之后的 connect() 在同一个 Worker 上再开一条。
同一个 workerInstance 同一时间只借给一条连接:第二条并发连接会抛 Worker transport already has an active SQLite client。
直接调用 createSqliteClient 时,先 await client.disconnect(),再调用 @aiao/rxdb-adapter-sqlite-core 导出的
releaseComlinkProxy(client) 归还子端口,之后才能在同一个 Worker 上重连;适配器已在 disconnect() 内自动完成这一步。
文档
- 仓库主页:https://github.com/aiao-io/rxdb
- 适配器与存储后端指南见项目文档站
License
Classes
| Class | Description |
|---|---|
| RxDBAdapterSqlite | 基于官方 @sqlite.org/sqlite-wasm 的 RxDB 本地存储适配器。 |
| RxDBAdapterSqliteError | RxDB SQLite 适配器错误类 |
| SqliteClient | 官方 sqlite-wasm 的 oo1 客户端。 |
| SqliteRepository | 操作实体仓库 |
Interfaces
| Interface | Description |
|---|---|
| GenerateSqlResult | SQL 生成结果:完整的 SQL 语句与可选的参数绑定。 |
| RxDBAdapterSqliteBase | 与后端无关的 SQLite adapter 基类。 |
| SqliteOfficialOptions | 官方 sqlite-wasm 适配器的完整选项。 |
Type Aliases
| Type Alias | Description |
|---|---|
| SqliteLoadOptions | sqliteLoad 接受的运行时选项,不包含 worker 与 repository 配置。 |
| SqliteOfficialRepositoryConstructor | 自定义 Repository 类的构造器签名。 |
Variables
| Variable | Description |
|---|---|
| BATCH_TIMEOUT | 变更事件批处理超时档位(毫秒)。 越短延迟越低但 CPU 唤醒越频繁;越长越省电但 UI 响应延后。 - IMMEDIATE (0): 同步派发,仅在测试场景使用 - FAST (4): 约一帧内合并 - BALANCED (16): 默认值,约一帧(60fps) - POWER_SAVE (50): 移动端 / 后台场景 |
| buildRuleGroup | 生成 ruleGroup sql 查询条件 |
| ROWID | sqlite 行 id 列名 |
| sqliteGetTableName | 获取表名 |
| sqliteGetTableNameByMetadata | 通过元数据获取表名 |
Functions
| Function | Description |
|---|---|
| createSqliteClient | 创建并初始化官方 sqlite-wasm 客户端。 |
| resetSqliteLoadCache | 清除官方 sqlite-wasm 模块缓存;仅供需要隔离模块状态的测试调用。 |
| sqliteLoad | 加载并缓存官方 sqlite-wasm 的 oo1 模块。 |
References
resetSqliteOfficialLoadCache
Renames and re-exports resetSqliteLoadCache
RxDBAdapterSqliteOfficial
Renames and re-exports RxDBAdapterSqlite
SqliteOfficialClient
Renames and re-exports SqliteClient
sqliteOfficialLoad
Renames and re-exports sqliteLoad
SqliteOfficialLoadOptions
Renames and re-exports SqliteLoadOptions
SqliteOptions
Renames and re-exports SqliteOfficialOptions
SqliteRepositoryConstructor
Renames and re-exports SqliteOfficialRepositoryConstructor