chex-storage
Version:
A wrapper library for Chrome extension storage local - the standard storage in the chrome extension.
78 lines (77 loc) • 2.4 kB
TypeScript
import ChexStorageWebWhereMethods from "./_where";
import ChexStorageWorker from "./provider";
import type { Optional } from "../typing";
declare class ChexTableWeb<TData, TKeyPropName extends keyof TData> extends ChexStorageWorker {
#private;
constructor(database: string, name: string, extensionId: string);
/**
* Querying data with the specified key condition
*
* @param keyWhere
* @returns ChexStorageWhereMethods
*/
where(keyWhere: string): ChexStorageWebWhereMethods<TData>;
/**
* Adds new data to the table and returns the key of the added data.
*
* @param data
* @returns Key value
*/
add(data: Optional<TData, TKeyPropName>): Promise<TData[TKeyPropName]>;
/**
* Adds multiple data entries to the table
*
* @param data
*/
bulkAdd(data: Optional<TData, TKeyPropName>[]): Promise<any>;
/**
* Gets all data from the table or gets data by a specific key
*
* @param key
* @returns Data | undefined
*/
get(): Promise<TData[]>;
get(key: TData[TKeyPropName]): Promise<TData | undefined>;
/**
* Updates data in the table by key and returns the key of the updated data
*
* @param key
* @param change
*/
update(keyValue: TData[TKeyPropName], change: Partial<Omit<TData, TKeyPropName>>): Promise<TData[TKeyPropName]>;
/**
* Update data for create new record
*
* @param keyValue
* @param change
* @param defaultValue
* @returns
*/
updateOrCreate(keyValue: TData[TKeyPropName], change: Partial<Omit<TData, TKeyPropName>>, defaultValue: Omit<TData, TKeyPropName>): Promise<TData[TKeyPropName]>;
/**
* Updates all data in the table with the specified changes.
*
* @param change
*/
updateAll(change: Partial<Omit<TData, TKeyPropName>>): Promise<any>;
/**
* Deletes multiple data entries from the table by their keys
*
* @param keyValue
*/
delete(keyValue: TData[TKeyPropName]): Promise<any>;
/**
* Delete
*
* @param keyValues
*/
bulkDelete(keyValues: TData[TKeyPropName][]): Promise<any>;
/**
* Query data with the same of filter factory function
*
* @param callback
* @returns TData[]
*/
filter(callback: (row: TData) => boolean): Promise<void>;
}
export default ChexTableWeb;