跳到主要内容

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() 内自动完成这一步。

文档​

License​

MIT

Classes​

ClassDescription
RxDBAdapterSqlite基于官方 @sqlite.org/sqlite-wasm 的 RxDB 本地存储适配器。
RxDBAdapterSqliteErrorRxDB SQLite 适配器错误类
SqliteClient官方 sqlite-wasm 的 oo1 客户端。
SqliteRepository操作实体仓库

Interfaces​

InterfaceDescription
GenerateSqlResultSQL 生成结果:完整的 SQL 语句与可选的参数绑定。
RxDBAdapterSqliteBase与后端无关的 SQLite adapter 基类。
SqliteOfficialOptions官方 sqlite-wasm 适配器的完整选项。

Type Aliases​

Type AliasDescription
SqliteLoadOptionssqliteLoad 接受的运行时选项,不包含 worker 与 repository 配置。
SqliteOfficialRepositoryConstructor自定义 Repository 类的构造器签名。

Variables​

VariableDescription
BATCH_TIMEOUT变更事件批处理超时档位(毫秒)。 越短延迟越低但 CPU 唤醒越频繁;越长越省电但 UI 响应延后。 - IMMEDIATE (0): 同步派发,仅在测试场景使用 - FAST (4): 约一帧内合并 - BALANCED (16): 默认值,约一帧(60fps) - POWER_SAVE (50): 移动端 / 后台场景
buildRuleGroup生成 ruleGroup sql 查询条件
ROWIDsqlite 行 id 列名
sqliteGetTableName获取表名
sqliteGetTableNameByMetadata通过元数据获取表名

Functions​

FunctionDescription
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