存储
Sync Engine 在 Context 上提供两个数据库访问点:一个异步的 IndexedDB 数据库和一个同步的内存数据库。两者都由 Uni-KV 支持。
数据库
ts
// Async IndexedDB database
ctx.indexedDB: IndexedDBDatabase<General, General>;
// Synchronous in-memory database
ctx.memoryDB: MemoryDBDatabase<General, General>;现有的 store 包括 localContext20000、remoteContext10000、remoteContext20000(都存储 Stat 值)。Context 包装器内部用它们做状态缓存。
Uni-KV API
SDK 转发了 Uni-KV 的通用类型:
ts
type IndexedDBStore<T>; // asynchronous IndexedDB store
type IndexedDBDatabase<D, M>; // async database of stores and metadata
type MemoryDBStore<T>; // synchronous in-memory store
type MemoryDBDatabase<D, M>; // sync database of stores and metadata
type StoreSync<T>; // synchronous store interface
type StoreOperation<T> // IndexedDBStore.batch() payload typeStore 暴露 get、set、delete、has、clear、keys、values 和 entries;IndexedDBStore 另有 batch。数据库暴露 getStore、getStoreNames、deleteStore、clearStores、getMeta 和 setMeta;只有 IndexedDBDatabase 有 dispose。
RecordStore
ts
type RecordStore = StoreSync<RecordStat>;持久化同步记录条目。getRecordStore() 选择当前的本地 / 远端文件系统命名空间并解析出对应的 store;未设置后端时解析结果是一个 Error。
ts
const records = await ctx.getRecordStore();
records.set('note.md', { isDir: false, local: 'local-uid', remote: 'remote-uid' });
const record = records.get('note.md');Context 记录存储方法
| 方法 | 用途 |
|---|---|
getRecordStore | 解析当前或指定名称的 RecordStore。 |
deleteRecordStore | 删除当前或指定名称的记录存储。 |
clearRecordStores | 清空所有记录存储。 |
recordStoreExists | 测试当前或指定名称的记录存储是否存在。 |