pg-simple-wrapper
v0.0.13
Published
Simple wrapper around postgresql transactions using pg.
Downloads
14
Readme
pg-simple-wrapper
Simple wrapper around postgresql transactions using pg.
Install
Include with "npm install" or "yarn add":
yarn add pg-simple-wrapper --dev
Usage
Really simple query-forming wrapper around pg that cleans up (a bit) sql statement generation for common operations (select list, insert single, access single, etc.).
Used as a typescript module.
import { Xaxion } from 'pg-simple-wrapper';
class ModelRepository {
client: Xaxion;
async accessPooled(pooledCode: string): Promise<Pooled> {
return this.client.access<Pooled>(ModelPooled, 'pooledId', {
props: '* from "pooled" as p',
where: 'p."ucode" = $#',
param: [
pooledCode,
]
});
}
// ...
}
That's a trivial example, but should give you an idea of how it works. Keep in mind that in the above example, ModelPooled must have the following "construction":
export interface Pooled {
ucode: string;
// ...
}
import { Xaxion } from 'pg-simple-wrapper';
import { Pooled } from './Pooled';
export class ModelPooled implements Pooled {
constructor(private client: Xaxion, private id: number, that: {
ucode: string,
}) {
this.ucode = that.ucode;
}
ucode: string = '';
// ...
}
License
MIT © Kirk Bulis