node-dbal-pg
An entity oriented Database Abstraction Layer (DBAL) for NodeJS to PostgreSQL. This means that you communicate with the database using whole entities as the primitives, instead of data in records.
How it works
The library's exposes a single class that allows access to the data using the repository pattern. This class assumes that all tables store data in columns that directly align with the key value value pairs of data objects, so one row in a table directly corresponds to one entity and the columns represent the key for the values in the row.
How to install
npm install node-dbal-pg
How to use
import EntityRepository from 'node-dbal-pg';
var repository = new EntityRepository({
username, password, host, port, database
}:{
username:string,
password:string,
host:string,
port:string|number,
database:string
}, {
dbms, table, pk, converters}: {
dbms:string;
table:string;
pk:string;
converters:any;
});
Repository functions
findByPk(pk: number | string, txn: any, cb: (err: Error, record: any) => void): void;
findAll(orderBy: string, offset: number, limit: number, txn: any, cb: (err: Error, records: any[]) => void): void;
find(criteria: any, orderBy: string, offset: number, limit: number, txn: any, cb: (err: Error, records: any[]) => void): void;
insert(values: any, txn: any, cb: (err: Error, records: any[], ctx: {
lastPk: number;
}) => void): void;
updateAll(values: any, txn: any, cb: (err: Error, records: any[], ctx: any) => void): void;
updateByPk(pk: number | string, values: any, txn: any, cb: (err: Error, records: any[], ctx: any) => void): void;
update(criteria: any, values: any, txn: any, cb: (err: Error, records: any[], ctx: any) => void): void;
removeAll(txn: any, cb: (err: Error, records: any[], ctx: any) => void): void;
removeByPk(pk: string | number, txn: any, cb: (err: Error, records: any[], ctx: any) => void): void;
remove(criteria: any, txn: any, cb: (err: Error, records: any[], ctx: any) => void): void;
countAll(txn: any, cb: (err: Error, value: number) => void): void;
count(criteria: any, txn: any, cb: (err: Error, value: number) => void): void;
beginTransaction(cb: (err: Error, txn: any) => void): void;
commitTransaction(txn: any, cb: (err: Error) => void): void;
rollbackTransaction(txn: any, cb: (err: Error) => void): void;
client: {
beginTransaction(cb: (err: Error, txn: any) => void): void;
rollbackTransaction(txn: any, cb: (err: Error) => void): void;
commitTransaction(txn: any, cb: (err: Error) => void): void;
exec(queryType: string, sql: string, parameters: any[], txn: any, cb: (err: Error, rows: any[], ctx: any) => void): void;
};
License
LGPL