26 lines
625 B
TypeScript
26 lines
625 B
TypeScript
import { Pool, QueryResult, QueryResultRow } from "pg";
|
|
|
|
export class postgreClient {
|
|
private pgPool: Pool;
|
|
|
|
constructor(args: {
|
|
pool: Pool
|
|
}) {
|
|
this.pgPool = args.pool
|
|
}
|
|
|
|
/**
|
|
* Wrapper para ejecutar consultas con tipado fuerte.
|
|
* T es el formato de la respusta.
|
|
* @param text - La consulta SQL (ej. 'SELECT * FROM users WHERE id = $1')
|
|
* @param params - Los valores para los placeholders $1, $2, etc.
|
|
*/
|
|
public async postgreQuery<T extends QueryResultRow = any>(
|
|
text: string,
|
|
params?: any[]
|
|
): Promise<QueryResult<T>> {
|
|
return await this.pgPool.query(text, params);
|
|
};
|
|
|
|
}
|