存储

存储 ​

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 type

Store 暴露 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测试当前或指定名称的记录存储是否存在。

所有内容均以 CC BY 4.0 协议授权。