@naturalcycles/db-lib
Version:
Lowest Common Denominator API to supported Databases
70 lines (69 loc) • 2.25 kB
JavaScript
import { FakeDBTransaction } from '../transaction/dbTransaction.util.js';
import { CommonDBType } from './common.db.js';
/**
* No-op implementation of CommonDB interface.
* To be extended by actual implementations.
*/
export class BaseCommonDB {
dbType = CommonDBType.document;
support = {};
async ping() {
throw new Error('ping is not implemented');
}
async getTables() {
throw new Error('getTables is not implemented');
}
async getTableSchema(_table) {
throw new Error('getTableSchema is not implemented');
}
async createTable(_table, _schema) {
// no-op
}
async getByIds(_table, _ids) {
throw new Error('getByIds is not implemented');
}
async deleteByQuery(_q) {
throw new Error('deleteByQuery is not implemented');
}
async patchByQuery(_q, _patch, _opt) {
throw new Error('patchByQuery is not implemented');
}
async patchById(_table, _id, _patch, _opt) {
throw new Error('patchById is not implemented');
}
async runQuery(_q) {
throw new Error('runQuery is not implemented');
}
async runQueryCount(_q) {
throw new Error('runQueryCount is not implemented');
}
async saveBatch(_table, _rows, _opt) {
throw new Error('saveBatch is not implemented');
}
streamQuery(_q) {
throw new Error('streamQuery is not implemented');
}
async deleteByIds(_table, _ids, _opt) {
throw new Error('deleteByIds is not implemented');
}
async runInTransaction(fn, _opt) {
const tx = new FakeDBTransaction(this);
await fn(tx);
// there's no try/catch and rollback, as there's nothing to rollback
}
async createTransaction(_opt) {
return new FakeDBTransaction(this);
}
async incrementBatch(_table, _prop, _incrementMap, _opt) {
throw new Error('incrementBatch is not implemented');
}
async multiGet(_map, _opt) {
throw new Error('multiGetByIds is not implemented');
}
async multiSave(_map, _opt) {
throw new Error('multiSaveBatch is not implemented');
}
async multiDelete(_map, _opt) {
throw new Error('multiDeleteByIds is not implemented');
}
}