UNPKG

@naturalcycles/db-lib

Version:

Lowest Common Denominator API to supported Databases

30 lines (29 loc) 1.46 kB
import type { ObjectWithId } from '@naturalcycles/js-lib/types'; import type { CommonDB } from '../commondb/common.db.js'; import type { CommonDBOptions, CommonDBSaveOptions, DBTransaction } from '../db.model.js'; /** * Optimizes the Transaction (list of DBOperations) to do less operations. * E.g if you save id1 first and then delete it - this function will turn it into a no-op (self-eliminate). * UPD: actually, it will only keep delete, but remove previous ops. * * Currently only takes into account SaveBatch and DeleteByIds ops. * Output ops are maximum 1 per entity - save or delete. */ /** * Naive implementation of "Transaction" which just executes all operations one-by-one. * Does NOT actually implement a Transaction, cause partial ops application will happen * in case of an error in the middle. */ /** * Fake implementation of DBTransactionContext, * which executes all operations instantly, without any Transaction involved. */ export declare class FakeDBTransaction implements DBTransaction { protected db: CommonDB; constructor(db: CommonDB); commit(): Promise<void>; rollback(): Promise<void>; 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>; deleteByIds(table: string, ids: string[], opt?: CommonDBOptions): Promise<number>; }