69 lines
1.8 KiB
TypeScript
69 lines
1.8 KiB
TypeScript
// packages/core/db/poolSingleton.d.ts
|
|
// Declaraciones de tipos para @suitecoffee/db
|
|
// Refleja el módulo ESM que expone poolCore y poolTenants (ambos Singletons)
|
|
|
|
import type {
|
|
Pool,
|
|
PoolClient,
|
|
PoolConfig,
|
|
QueryResult,
|
|
QueryResultRow,
|
|
QueryConfig
|
|
} from 'pg';
|
|
|
|
export type { Pool, PoolClient, PoolConfig, QueryResult, QueryResultRow, QueryConfig };
|
|
|
|
// Clases modeladas según la implementación JS (no se exportan como valores en runtime,
|
|
// pero se exponen como tipos para el consumidor que quiera tipar sus variables).
|
|
export declare class DatabaseCore {
|
|
/** Instancia singleton interna (solo informativa para tipado). */
|
|
static instance?: DatabaseCore;
|
|
|
|
/** Pool real de `pg`. */
|
|
connection: Pool;
|
|
|
|
constructor();
|
|
|
|
/** Ejecuta una consulta utilizando el pool. */
|
|
query<T extends QueryResultRow = any>(
|
|
sql: string | QueryConfig<any[]>,
|
|
params?: any[]
|
|
): Promise<QueryResult<T>>;
|
|
|
|
/** Alias al `pool.connect()`; devuelve un `PoolClient`. */
|
|
connect(): Promise<PoolClient>;
|
|
|
|
/** Alias al `pool.connect()`; devuelve un `PoolClient`. */
|
|
getClient(): Promise<PoolClient>;
|
|
|
|
/** Cierra el pool subyacente. */
|
|
release(): Promise<void>;
|
|
}
|
|
|
|
export declare class DatabaseTenants {
|
|
static instance?: DatabaseTenants;
|
|
connection: Pool;
|
|
|
|
constructor();
|
|
|
|
query<T extends QueryResultRow = any>(
|
|
sql: string | QueryConfig<any[]>,
|
|
params?: any[]
|
|
): Promise<QueryResult<T>>;
|
|
|
|
connect(): Promise<PoolClient>;
|
|
getClient(): Promise<PoolClient>;
|
|
release(): Promise<void>;
|
|
}
|
|
|
|
/** Singletons creados por el módulo. */
|
|
export declare const poolCore: DatabaseCore;
|
|
export declare const poolTenants: DatabaseTenants;
|
|
|
|
/** Export por defecto del módulo: objeto con ambos pools. */
|
|
declare const _default: {
|
|
poolCore: DatabaseCore;
|
|
poolTenants: DatabaseTenants;
|
|
};
|
|
export default _default;
|