@stexcore/indexed-db
Version:
Manage the IndexedDB Web API, through a simple and easy interface.
84 lines (83 loc) • 2.66 kB
TypeScript
/***************************************************************
Authors : Steven Aray - Sunday, December 12, 2024
Website : https://stexcore.com
Lib: indexed-db
Copyright 2024
***************************************************************/
import { IFieldType } from "./types/field.type";
import { IFieldTypeToValueType } from "./types/field.type.value.type";
import { IStructField } from "./types/struct.field";
import { IStructTable } from "./types/struct.table";
import { ITable } from "./types/table";
/**
* Make a structure of tables database to manage indexeddb
* @param struct Structure table
* @returns Structure table
*/
export declare function createStructTables<T extends {
[key: string]: IStructTable<{
[key: string]: IStructField<IFieldType, boolean | undefined, boolean | undefined>;
}>;
}>(struct: T): T;
/**
* Database to manage tables based in IndexedDB
*/
export declare class IndexedDB<T extends {
[key: string]: IStructTable<{
[key: string]: IStructField<IFieldType, boolean | undefined, boolean | undefined>;
}>;
}> {
/**
* database name
*/
readonly db_name: string;
readonly table_structs: T;
/**
* Structure of all tables
*/
readonly structs: {
[key in keyof T]: {
/**
* Name field key with primary key
*/
primaryKey: keyof T[key];
/**
* Fields of table
*/
fields: T[key];
};
};
/**
* Promise async getting database
*/
private gettingDatabase;
/**
* Database instance memory
*/
private db;
/**
* Inicialize the structure of database
* @param database Database name
* @param table_structs Structure of tables
*/
constructor(
/**
* database name
*/
db_name: string, table_structs: T);
/**
* asynchronously obtains the database
* @returns Indexed Database
*/
private GetDataBase;
/**
* Get a interface to manage a table of indexedDB
* @param name Name of table
* @returns Inteface to manage the table
*/
getTable<T2 extends (keyof T & string)>(name: T2): Promise<ITable<{
[key in keyof T[T2]]: (T[T2][key]["allow_null"] extends true ? (IFieldTypeToValueType<T[T2][key]["type"]> | null) : (IFieldTypeToValueType<T[T2][key]["type"]>));
}, {
[key in keyof T[T2] as T[T2][key]["autoincrement"] extends true ? never : key]: (T[T2][key]["allow_null"] extends true ? (IFieldTypeToValueType<T[T2][key]["type"]> | null) : (IFieldTypeToValueType<T[T2][key]["type"]>));
}>>;
}