@bs-plugins/postgresql
Version:
Bamboo Shell plugin for PostgreSQL
63 lines (60 loc) • 2.19 kB
TypeScript
import { BSPlugin } from '@bs-core/shell';
import * as pg from 'pg';
type PostgreSqlConfig = {
database: string;
user: string;
password: string;
host?: string;
port?: number;
ssl?: boolean;
old?: boolean;
};
type PostgreSqlCreateOptions = {
client?: pg.PoolClient;
id?: string;
};
type PostgreSqlReadOptions = {
client?: pg.PoolClient;
fields?: string[];
criteria?: Record<string, any>;
orderBy?: string[];
descending?: boolean;
groupBy?: string[];
format?: "json" | "array";
distinct?: boolean;
};
type PostgreSqlUpdateOptions = {
client?: pg.PoolClient;
criteria?: Record<string, any>;
};
type PostgreSqlDeleteOptions = {
client?: pg.PoolClient;
criteria?: Record<string, any>;
};
declare class PostgresSqlError {
severity: string;
code: string;
detail: string;
message: string;
constructor(severity: string, code: string, detail: string, message: string);
}
declare class PostgreSql extends BSPlugin {
private _pool;
constructor(name: string, postgresqlConfig: PostgreSqlConfig);
protected stop(): Promise<void>;
private isServerReady;
start(): Promise<boolean>;
healthCheck(): Promise<boolean>;
create(collection: string, fields: Record<string, any>, options?: PostgreSqlCreateOptions): Promise<any[]>;
read(collection: string, readOptions?: PostgreSqlReadOptions): Promise<any[]>;
update(collection: string, fields: Record<string, any>, updateOptions?: PostgreSqlUpdateOptions): Promise<number>;
delete(collection: string, deleteOptions?: PostgreSqlDeleteOptions): Promise<number>;
query(query: string, client?: pg.PoolClient): Promise<any[]>;
exec(query: string, client?: pg.PoolClient): Promise<number>;
connect(): Promise<pg.PoolClient>;
release(client: pg.PoolClient): Promise<void>;
begin(client: pg.PoolClient): Promise<void>;
commit(client: pg.PoolClient): Promise<void>;
rollback(client: pg.PoolClient): Promise<void>;
}
export { PostgreSql, type PostgreSqlConfig, type PostgreSqlCreateOptions, type PostgreSqlDeleteOptions, type PostgreSqlReadOptions, type PostgreSqlUpdateOptions, PostgresSqlError };