Skip to main content

Interface: IDatabasePool

Defined in: src/types/interfaces/database.interface.ts:36

Database pool interface for PostgreSQL operations.

Remarks

Abstracts the pg.Pool interface to allow for:

  • Unit testing with mock implementations
  • Dependency injection without tsyringe decorators
  • Consistent type safety across services

Example

class MyService {
constructor(private readonly db: IDatabasePool) {}

async getData(): Promise<MyData[]> {
const result = await this.db.query<MyData>('SELECT * FROM my_table');
return result.rows;
}
}

Methods

query()

query<T>(text, values?): Promise<{ rows: T[]; }>

Defined in: src/types/interfaces/database.interface.ts:45

Executes a SQL query against the database.

Type Parameters

T

The expected row type

Parameters

text

string

SQL query string with optional $1, $2, ... placeholders

values?

unknown[]

Parameter values to bind to placeholders

Returns

Promise<{ rows: T[]; }>

Query result with typed rows