support idb store/index.count

This commit is contained in:
Bruno Windels 2022-01-26 15:12:11 +01:00
parent a791641b34
commit 524090e27d
2 changed files with 13 additions and 0 deletions

View file

@ -37,6 +37,7 @@ interface QueryTargetInterface<T> {
openKeyCursor(range?: IDBQuery, direction?: IDBCursorDirection | undefined): IDBRequest<IDBCursor | null>;
supports(method: string): boolean;
keyPath: string | string[];
count(keyRange?: IDBKeyRange): IDBRequest<number>;
get(key: IDBValidKey | IDBKeyRange): IDBRequest<T | undefined>;
getKey(key: IDBValidKey | IDBKeyRange): IDBRequest<IDBValidKey | undefined>;
}
@ -78,6 +79,10 @@ export class QueryTarget<T> {
return this._target.supports(methodName);
}
count(keyRange?: IDBKeyRange): Promise<number> {
return reqAsPromise(this._target.count(keyRange));
}
get(key: IDBValidKey | IDBKeyRange): Promise<T | undefined> {
return reqAsPromise(this._target.get(key));
}

View file

@ -118,6 +118,14 @@ export class QueryTargetWrapper<T> {
}
}
count(keyRange?: IDBKeyRange): IDBRequest<number> {
try {
return this._qtStore.count(keyRange);
} catch(err) {
throw new IDBRequestAttemptError("count", this._qt, err, [keyRange]);
}
}
index(name: string): IDBIndex {
try {
return this._qtStore.index(name);