pg-test-util
Version:
PostgreSQL administrative utilities such as creating and dropping tables, users etc.
71 lines • 3.19 kB
TypeScript
import { Client, ClientConfig } from "pg";
import { SequenceInfo, EntityInfo } from "./types";
export type Oid = string;
/** @ignore */
export type DatabaseConstructorArgs = {
clientConfig: ClientConfig;
schemas?: string[];
cleanup: () => Promise<void>;
drop: () => Promise<void>;
};
/** Execute tasks related to individual database such as connecting, querying, getting tables, getting sequences etc. */
export default class Database {
#private;
/** [node-postgres client](https://node-postgres.com/api/client) */
readonly client: Client;
/** Drops the database. */
readonly drop: () => Promise<void>;
/** @ignore */
private constructor();
/** @ignore */
static new(args: DatabaseConstructorArgs): Promise<Database>;
/** Name of the database */
get name(): string;
/** Connects to database. */
connect(): Promise<void>;
/** Disconnects from database. */
disconnect(): Promise<void>;
/** Fetches database objects (i.e. tables, sequences) from database and refreshes the cache of the object. If you create new tables etc., you should refresh. */
refresh(): Promise<void>;
/** Returns tables from database. Uses cache for fast results. Use `refresh()` method to refresh the cache. */
getTables(): Promise<EntityInfo[]>;
/** Returns views from database. Uses cache for fast results. Use `refresh()` method to refresh the cache. */
getViews(): Promise<EntityInfo[]>;
/** Returns materialized views from database. Uses cache for fast results. Use `refresh()` method to refresh the cache. */
getMaterializedViews(): Promise<EntityInfo[]>;
/** Returns partitioned tables from database. Uses cache for fast results. Use `refresh()` method to refresh the cache. */
getPartitionedTables(): Promise<EntityInfo[]>;
/** Returns sequences from database. Uses cache for fast results. Use `refresh()` method to refresh the cache. */
getSequences(): Promise<SequenceInfo[]>;
/** Set current value of sequence for each column of all tables based on record with maximum number. If there are no record in the table, the value will be set to 1. */
syncSequences(): Promise<void>;
/**
* Truncates all tables and resets their sequences in the database.
*
* @param ignore are the list of the tables to ignore.
*/
truncate({ ignore }?: {
ignore?: string[];
}): Promise<void>;
/**
* Executes given SQL and returns result rows.
*
* @typeparam T is type for single row returned by SQL query.
*
* @param sql is sql query.
* @param params are array of parameters to pass query.
* @returns result rows of the SQL query.
*/
query<T = any>(sql: string, params?: any[]): Promise<T[]>;
/**
* Reads and executes SQL in given file and returns results.
*
* @typeparam T is type for single row returned by SQL query.
*
* @param file is file to read SQL from.
* @param params are array of parameters to pass query.
* @returns result rows of the SQL query.
*/
queryFile<T = any>(file: string, params?: any[]): Promise<T[]>;
}
//# sourceMappingURL=database.d.ts.map