本文整理汇总了TypeScript中idb.DB类的典型用法代码示例。如果您正苦于以下问题:TypeScript DB类的具体用法?TypeScript DB怎么用?TypeScript DB使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DB类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: saveMetadata
async saveMetadata(name: string, value: Uint8Array | undefined): Promise<void> {
const trans = this.db.transaction(["metadata"], "readwrite");
const store = trans.objectStore("metadata");
if(value){
await store.put({name, value});
}else{
await store.delete(name);
}
}
示例2: setRef
async setRef(ref : string, hash : Hash | undefined) : Promise<void> {
const trans = this.db.transaction(["refs"], "readwrite");
const store = trans.objectStore("refs");
if(hash === undefined){
await store.delete(ref);
}else{
const entry = { path: ref, hash: hash };
await store.put(entry);
}
}
示例3: loadMetadata
async loadMetadata(name: string): Promise<Uint8Array | undefined> {
const trans = this.db.transaction(["metadata"], "readonly");
const store = trans.objectStore("metadata");
const result = await store.get(name).catch(N => undefined);
return result ? result.value as Uint8Array : undefined;
}
示例4: hasObject
async hasObject(hash: string): Promise<boolean> {
const trans = this.db.transaction(["objects"], "readonly");
const store = trans.objectStore("objects");
return await store.getKey(hash).then(key => key !== undefined, N => false);
}
示例5: getRef
async getRef(ref : string) : Promise<Hash | undefined> {
const trans = this.db.transaction(["refs"], "readonly");
const store = trans.objectStore("refs");
const result = await store.get(ref).catch(N => undefined);
return result ? result.hash as Hash : undefined;
}
示例6: listRefs
async listRefs() : Promise<Hash[]> {
const trans = this.db.transaction(["refs"], "readonly");
const store = trans.objectStore("refs");
return await store.getAllKeys() as Hash[];
}
示例7: loadRaw
async loadRaw(hash : Hash) : Promise<Uint8Array | undefined> {
const trans = this.db.transaction(["objects"], "readonly");
const store = trans.objectStore("objects");
const result = await store.get(hash).catch(N => undefined);
return result ? result.raw as Uint8Array : undefined;
}
示例8: saveRaw
async saveRaw(hash : Hash, raw : Uint8Array) : Promise<void> {
const trans = this.db.transaction(["objects"], "readwrite");
const store = trans.objectStore("objects");
await store.put({hash, raw});
}