@naturalcycles/db-lib
Version:
Lowest Common Denominator API to supported Databases
34 lines (33 loc) • 2.08 kB
TypeScript
import type { JsonSchemaObject, JsonSchemaRootObject } from '@naturalcycles/js-lib/json-schema';
import type { ObjectWithId } from '@naturalcycles/js-lib/types';
import type { ReadableTyped } from '@naturalcycles/nodejs-lib/stream';
import { BaseCommonDB } from '../../commondb/base.common.db.js';
import type { CommonDB, CommonDBSupport } from '../../commondb/common.db.js';
import type { RunQueryResult } from '../../db.model.js';
import type { DBQuery } from '../../query/dbQuery.js';
import type { CacheDBCfg, CacheDBCreateOptions, CacheDBOptions, CacheDBSaveOptions, CacheDBStreamOptions } from './cache.db.model.js';
/**
* CommonDB implementation that proxies requests to downstream CommonDB
* and does in-memory caching.
*
* Queries always hit downstream (unless `onlyCache` is passed)
*/
export declare class CacheDB extends BaseCommonDB implements CommonDB {
support: CommonDBSupport;
constructor(cfg: CacheDBCfg);
cfg: CacheDBCfg;
ping(): Promise<void>;
/**
* Resets InMemory DB data
*/
getTables(): Promise<string[]>;
getTableSchema<ROW extends ObjectWithId>(table: string): Promise<JsonSchemaRootObject<ROW>>;
createTable<ROW extends ObjectWithId>(table: string, schema: JsonSchemaObject<ROW>, opt?: CacheDBCreateOptions): Promise<void>;
getByIds<ROW extends ObjectWithId>(table: string, ids: string[], opt?: CacheDBSaveOptions<ROW>): Promise<ROW[]>;
saveBatch<ROW extends ObjectWithId>(table: string, rows: ROW[], opt?: CacheDBSaveOptions<ROW>): Promise<void>;
runQuery<ROW extends ObjectWithId>(q: DBQuery<ROW>, opt?: CacheDBSaveOptions<ROW>): Promise<RunQueryResult<ROW>>;
runQueryCount<ROW extends ObjectWithId>(q: DBQuery<ROW>, opt?: CacheDBOptions): Promise<number>;
streamQuery<ROW extends ObjectWithId>(q: DBQuery<ROW>, opt?: CacheDBStreamOptions): ReadableTyped<ROW>;
deleteByQuery<ROW extends ObjectWithId>(q: DBQuery<ROW>, opt?: CacheDBOptions): Promise<number>;
patchByQuery<ROW extends ObjectWithId>(q: DBQuery<ROW>, patch: Partial<ROW>, opt?: CacheDBOptions): Promise<number>;
}