UNPKG

@naturalcycles/db-lib

Version:

Lowest Common Denominator API to supported Databases

39 lines (38 loc) 2.39 kB
import { JsonSchemaRootObject, ObjectWithId } from '@naturalcycles/js-lib'; import { ReadableTyped } from '@naturalcycles/nodejs-lib'; import { BaseCommonDB, CommonDBSupport, DBSaveBatchOperation } from '../..'; import { CommonDB } from '../../common.db'; import { CommonDBOptions, CommonDBSaveOptions, CommonDBStreamOptions, RunQueryResult } from '../../db.model'; import { DBQuery } from '../../query/dbQuery'; import { FileDBCfg } from './file.db.model'; /** * Provides barebone implementation for "whole file" based CommonDB. * "whole file" means that the persistence layer doesn't allow any querying, * but allows to read the whole file or save the whole file. * For example, Google Cloud Storage / S3 that store ndjson files will be such persistence. * * In contrast with InMemoryDB, FileDB stores *nothing* in memory. * Each load/query operation loads *whole* file from the persitence layer. * Each save operation saves *whole* file to the persistence layer. */ export declare class FileDB extends BaseCommonDB implements CommonDB { support: CommonDBSupport; constructor(cfg: FileDBCfg); cfg: FileDBCfg; ping(): Promise<void>; getTables(): Promise<string[]>; getByIds<ROW extends ObjectWithId>(table: string, ids: string[], _opt?: CommonDBOptions): Promise<ROW[]>; saveBatch<ROW extends ObjectWithId>(table: string, rows: ROW[], _opt?: CommonDBSaveOptions<ROW>): Promise<void>; runQuery<ROW extends ObjectWithId>(q: DBQuery<ROW>, _opt?: CommonDBOptions): Promise<RunQueryResult<ROW>>; runQueryCount<ROW extends ObjectWithId>(q: DBQuery<ROW>, _opt?: CommonDBOptions): Promise<number>; streamQuery<ROW extends ObjectWithId>(q: DBQuery<ROW>, opt?: CommonDBStreamOptions): ReadableTyped<ROW>; deleteByQuery<ROW extends ObjectWithId>(q: DBQuery<ROW>, _opt?: CommonDBOptions): Promise<number>; deleteByIds(table: string, ids: string[], _opt?: CommonDBOptions): Promise<number>; getTableSchema<ROW extends ObjectWithId>(table: string): Promise<JsonSchemaRootObject<ROW>>; loadFile<ROW extends ObjectWithId>(table: string): Promise<ROW[]>; saveFile<ROW extends ObjectWithId>(table: string, _rows: ROW[]): Promise<void>; saveFiles<ROW extends ObjectWithId>(ops: DBSaveBatchOperation<ROW>[]): Promise<void>; sortRows<ROW extends ObjectWithId>(rows: ROW[]): ROW[]; private logStarted; private logFinished; }