@dtinsight/dt-utils
Version:
58 lines (57 loc) • 1.92 kB
TypeScript
/**
* Usage: https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API/Using_IndexedDB
* Compatibility: https://caniuse.com/#feat=indexeddb
*/
declare class LocalIndexedDB {
private _db;
private _version;
private _database;
private _storeName;
private _openLog;
/**
* Constructor a new indexedDB object
* @param database database name
* @param version database version
* @param storeName store object name
* @param openLog - 是否打印 indexedDB 变化
*/
constructor(database: string, version: number, storeName: string, openLog?: boolean);
/**
* Open the database indicated in constructor function.
* This method return a Promise object which success will resolve db instance.
*/
open(): Promise<IDBDatabase>;
private getObjectStore;
add(value: any, key?: string): Promise<IDBRequest<any>>;
/**
* Set a value to store object by key
* @param key the key of store object
* @param value the value of store object
*/
set(key: string, value: any): Promise<IDBRequest<any>>;
/**
* Get the value with the given key
* @param key the key of store object
*/
get(key: string): Promise<IDBRequest<any>>;
/**
* Delete records in store with the given key
* @param key the key of store object
*/
delete(key: string): Promise<IDBRequest<any>>;
/**
* Delete all data in store object
*/
clear(): Promise<IDBRequest<any>>;
/**
* Get the store object
*/
getStore(): IDBObjectStore | null;
/**
* Wrap the database request result as promise object
* @param operate A function which operate store
*/
wrapStoreOperationPromise<T = IDBRequest>(operate: (store: IDBObjectStore) => IDBRequest): Promise<T>;
private log;
}
export default LocalIndexedDB;