UNPKG

brackets-json-db

Version:

An in-memory database for brackets-manager.js

109 lines (108 loc) 3.07 kB
import { CrudInterface, Table } from 'brackets-manager'; export declare class JsonDatabase implements CrudInterface { private internal; /** * Creates an instance of JsonDatabase, an implementation of CrudInterface for a json file. * * @param filename An optional filename for the database. */ constructor(filename?: string); /** * Creates the array if it doesn't exist. * * @param table The table to check. */ private ensureArrayExists; /** * Initiates the storage. */ private init; /** * Creates the path of a table. * * @param table Name of the table. */ private static makePath; /** * Creates the path of an array. * * @param table Name of the table. */ private static makeArrayPath; /** * Creates the path of an element at a given index in an array. * * @param table Name of the table. * @param index Index of the element. */ private static makeArrayIndexPath; /** * Makes the filter function associated to the partial object. * * @param partial A partial object with given values as query. */ private makeFilter; /** * Empties the database and `init()` it back. */ reset(): void; /** * Inserts a value in a table and returns its id. * * @param table Where to insert. * @param value What to insert. */ insert<T>(table: Table, value: T): Promise<number>; /** * Inserts multiple values in a table. * * @param table Where to insert. * @param values What to insert. */ insert<T>(table: Table, values: T[]): Promise<boolean>; /** * Gets all data from a table. * * @param table Where to get from. */ select<T>(table: Table): Promise<T[] | null>; /** * Gets specific data from a table. * * @param table Where to get from. * @param key What to get. */ select<T>(table: Table, key: number): Promise<T | null>; /** * Gets data from a table with a filter. * * @param table Where to get from. * @param filter An object to filter data. */ select<T>(table: Table, filter: Partial<T>): Promise<T[] | null>; /** * Updates data in a table. * * @param table Where to update. * @param key What to update. * @param value How to update. */ update<T>(table: Table, key: number, value: T): Promise<boolean>; /** * Updates data in a table. * * @param table Where to update. * @param filter An object to filter data. * @param value How to update. */ update<T>(table: Table, filter: Partial<T>, value: Partial<T>): Promise<boolean>; /** * Delete data in a table, based on a filter. * * @param table Where to delete in. * @param filter An object to filter data or undefined to empty the table. */ delete<T extends { [key: string]: unknown; }>(table: Table, filter?: Partial<T>): Promise<boolean>; }