@omnia/fx
Version:
Provide Omnia Fx typings and tooling for clientside Omnia development.
70 lines (69 loc) • 2 kB
TypeScript
import { Future } from "@omnia/fx-models";
import { Ref } from "vue";
/**
* Async api for working with indexedDB. Remember to await the useIndexedDb since its async
* @export
* @param {string} name
* @param {string} table
* @return {*} {Future<IndexedDbApi>}
*/
export declare function useIndexedDb(name: string, table: string): Future<IndexedDbApi>;
/**
*
*
* @export
* @interface IndexedDbApi
*/
export interface IndexedDbApi {
/**
* Current database instance
* @type {(IDBDatabase | null)}
* @memberof IndexedDbApi
*/
currentDb: IDBDatabase | null;
/**
* Current database name
* @type {Ref<string>}
* @memberof IndexedDbApi
*/
currentDbName: Ref<string>;
/**
* Current database version
* @type {Ref<number>}
* @memberof IndexedDbApi
*/
currentDbVersion: Ref<number>;
/**
* Gets the data by key from the database
* @memberof IndexedDbApi
*/
get: <T>(key: IDBValidKey) => Promise<T>;
/**
* Gets all the data from the database
* @memberof IndexedDbApi
*/
getAll: <T>() => Promise<Map<IDBValidKey, T>>;
/**
* Adds the key to the database if the key exists it will throw exception
* use upsert for add or update operations
* @memberof IndexedDbApi
*/
add: <T>(key: IDBValidKey, data: T) => Promise<unknown>;
/**
* Does an add or update depending on if the key exists
* @memberof IndexedDbApi
*/
upsert: <T>(key: IDBValidKey, data: T) => Promise<unknown>;
/**
* Removes the key from the database
* @memberof IndexedDbApi
*/
remove: (key: IDBValidKey) => Promise<unknown>;
/**
* Closes the database connection and dispsoses the instance from the cache
* Note if you have multiple tables opened on the same database it will close all instances
* this means you have to call useIndexedDb again after this
* @memberof IndexedDbApi
*/
close: () => void;
}