@naturalcycles/db-lib
Version:
Lowest Common Denominator API to supported Databases
31 lines (30 loc) • 2.1 kB
TypeScript
import type { JsonSchemaObject, JsonSchemaRootObject } from '@naturalcycles/js-lib/json-schema';
import type { ObjectWithId, StringMap } from '@naturalcycles/js-lib/types';
import type { ReadableTyped } from '@naturalcycles/nodejs-lib/stream';
import type { CommonDBOptions, CommonDBSaveOptions, CommonDBTransactionOptions, DBTransaction, DBTransactionFn, RunQueryResult } from '../db.model.js';
import type { DBQuery } from '../query/dbQuery.js';
import type { CommonDB, CommonDBSupport } from './common.db.js';
import { CommonDBType } from './common.db.js';
/**
* No-op implementation of CommonDB interface.
* To be extended by actual implementations.
*/
export declare class BaseCommonDB implements CommonDB {
dbType: CommonDBType;
support: CommonDBSupport;
ping(): Promise<void>;
getTables(): Promise<string[]>;
getTableSchema<ROW extends ObjectWithId>(_table: string): Promise<JsonSchemaRootObject<ROW>>;
createTable<ROW extends ObjectWithId>(_table: string, _schema: JsonSchemaObject<ROW>): Promise<void>;
getByIds<ROW extends ObjectWithId>(_table: string, _ids: string[]): Promise<ROW[]>;
deleteByQuery<ROW extends ObjectWithId>(_q: DBQuery<ROW>): Promise<number>;
patchByQuery<ROW extends ObjectWithId>(_q: DBQuery<ROW>, _patch: Partial<ROW>, _opt?: CommonDBOptions): Promise<number>;
runQuery<ROW extends ObjectWithId>(_q: DBQuery<ROW>): Promise<RunQueryResult<ROW>>;
runQueryCount<ROW extends ObjectWithId>(_q: DBQuery<ROW>): Promise<number>;
saveBatch<ROW extends ObjectWithId>(_table: string, _rows: ROW[], _opt?: CommonDBSaveOptions<ROW>): Promise<void>;
streamQuery<ROW extends ObjectWithId>(_q: DBQuery<ROW>): ReadableTyped<ROW>;
deleteByIds(_table: string, _ids: string[], _opt?: CommonDBOptions): Promise<number>;
runInTransaction(fn: DBTransactionFn, _opt?: CommonDBTransactionOptions): Promise<void>;
createTransaction(_opt?: CommonDBTransactionOptions): Promise<DBTransaction>;
incrementBatch(_table: string, _prop: string, _incrementMap: StringMap<number>, _opt?: CommonDBOptions): Promise<StringMap<number>>;
}