UNPKG

@lordfokas/magic-orm

Version:

A class-based ORM in TypeScript. Unorthodox and extremely opinionated, made to fit my specific use cases.

46 lines (45 loc) 1.82 kB
import Pool from 'pg-pool'; import { QueryArrayResult, type Client, type PoolClient } from 'pg'; import { Logger, type Options } from '@lordfokas/loggamus'; /** Define a new logger to send output to */ export declare function useLogger(logger: Logger, options?: Options): void; type PGClient = Client & PoolClient; /** The database connection manager */ export declare class DB { /** Initiate the connection pool to the database server. Necessary before acquiring any connections. */ static init(config: Pool.Config<Client>): void; /** Acquire a connection to execute queries on. */ static acquire(): Promise<Connection>; } /** A database connection to execute queries on. */ export declare class Connection { #private; constructor(conn: PGClient); /** * Execute a PreparedStatement query * @param sql string or string[] with the query to execute * @param values parameters to replace in the prepared statement * @returns query results */ execute(sql: string | string[], values?: any[]): Promise<QueryArrayResult>; /** * Executes raw unprepared queries. Should be used solely to run commands unsupported by prepared statements, such as LOCKs * @param sql the raw SQL query to execute * @returns query results * @deprecated */ DANGEROUSLY(sql: string): Promise<QueryArrayResult>; /** * Runs an async function inside a new transaction. * Automatically commits at the end, and rollbacks on error. */ atomic<T>(fn: () => Promise<T>): Promise<T>; /** * Sets the current path to a given list of schemas. * @param schemas varargs list of schemas to use. */ schema(...schemas: string[]): Promise<void>; /** Release this connection back into the Pool. */ release(): void; } export {};