github
DocsBlog
fontcolor_theme
package

API @deepkit/postgres

npm install @deepkit/postgres
import { PostgresDatabaseAdapter } from '@deepkit/mongo';
import { Database } from '@deepkit/orm';

const adapter = new PostgresDatabaseAdapter('postgres://user:password@localhost/mydatabase');
// const adapter = new PostgresDatabaseAdapter({ host: 'localhost', database: 'postgres', user: 'postgres' });

const database = new Database(adapter);

Classes

PostgresStatement [source]
export class PostgresStatement extends SQLStatement {
    constructor(protected logger: Logger, protected sql: string, protected client: PoolClient, protected stopwatch?: Stopwatch);
    async get(params: any[] = []);
    async all(params: any[] = []);
    release();
}
PostgresConnection [source]
export class PostgresConnection extends SQLConnection {
    lastReturningRows: any[];
    constructor(connectionPool: PostgresConnectionPool, public connection: PoolClient, logger: Logger, transaction?: DatabaseTransaction, stopwatch?: Stopwatch);
    async prepare(sql: string);
    async run(sql: string, params: any[] = []);
    async getChanges(): Promise<number>;
}
PostgresDatabaseTransaction [source]
export class PostgresDatabaseTransaction extends DatabaseTransaction {
    connection?: PostgresConnection;
    setTransaction?: TransactionTypes;
    /**
     * This is the default for mysql databases.
     */
    repeatableRead(): this;
    readCommitted(): this;
    serializable(): this;
    async begin();
    async commit();
    async rollback();
}
PostgresConnectionPool [source]
export class PostgresConnectionPool extends SQLConnectionPool {
    constructor(protected pool: Pool, protected logger: Logger, protected stopwatch?: Stopwatch);
    async getConnection(transaction?: PostgresDatabaseTransaction): Promise<PostgresConnection>;
    release(connection: PostgresConnection);
}
PostgresPersistence [source]
export class PostgresPersistence extends SQLPersistence {
    constructor(protected platform: DefaultPlatform, public connectionPool: PostgresConnectionPool, session: DatabaseSession<any>);
    override handleSpecificError(error: Error): Error;
    async batchUpdate<T extends OrmEntity>(entity: PreparedEntity, changeSets: DatabasePersistenceChangeSet<T>[]): Promise<void>;
}
PostgresSQLQueryResolver [source]
export class PostgresSQLQueryResolver<T extends OrmEntity> extends SQLQueryResolver<T> {
    async delete(model: SQLQueryModel<T>, deleteResult: DeleteResult<T>): Promise<void>;
    override handleSpecificError(error: Error): Error;
    async patch(model: SQLQueryModel<T>, changes: Changes<T>, patchResult: PatchResult<T>): Promise<void>;
}
PostgresSQLDatabaseQuery [source]
export class PostgresSQLDatabaseQuery<T extends OrmEntity> extends SQLDatabaseQuery<T> {
}
PostgresSQLDatabaseQueryFactory [source]
export class PostgresSQLDatabaseQueryFactory extends SQLDatabaseQueryFactory {
    createQuery<T extends OrmEntity>(type?: ReceiveType<T> | ClassType<T> | AbstractClassType<T> | ReflectionClass<T>): PostgresSQLDatabaseQuery<T>;
}
PostgresDatabaseAdapter [source]
export class PostgresDatabaseAdapter extends SQLDatabaseAdapter {
    connectionPool: PostgresConnectionPool;
    platform;
    closed;
    constructor(options: PoolConfig | string, additional: Partial<PoolConfig> = {});
    setLogger(logger: Logger);
    getName(): string;
    getSchemaName(): string;
    createPersistence(session: DatabaseSession<this>): SQLPersistence;
    createTransaction(session: DatabaseSession<this>): PostgresDatabaseTransaction;
    queryFactory(session: DatabaseSession<any>): SQLDatabaseQueryFactory;
    disconnect(force?: boolean): void;
}
PostgresPlaceholderStrategy [source]
export class PostgresPlaceholderStrategy extends SqlPlaceholderStrategy {
    override getPlaceholder();
}
PostgresPlatform [source]
export class PostgresPlatform extends DefaultPlatform {
    override annotationId;
    override readonly serializer: Serializer;
    override schemaParserType;
    override placeholderStrategy;
    constructor();
    override getSqlTypeCaster(type: Type): (placeholder: string) => string;
    override getAggregateSelect(tableName: string, property: ReflectionProperty, func: string);
    override createSqlFilterBuilder(adapter: PreparedAdapter, schema: ReflectionClass<any>, tableName: string): PostgreSQLFilterBuilder;
    override getDeepColumnAccessor(table: string, column: string, path: string);
    override quoteValue(value: any): string;
    override getColumnDDL(column: Column);
    getModifyColumnDDL(diff: ColumnDiff): string;
    getDefaultExpression(column: Column): string;
    getUniqueDDL(unique: IndexModel): string;
    getDropIndexDDL(index: IndexModel): string;
    supportsInlineForeignKey(): boolean;
    supportsAggregatedAlterTable(): boolean;
    supportsSelectFor(): boolean;
    getAutoIncrement();
    getDropTableDDL(table: Table): string;
    getUseSchemaDDL(table: Table);
    getResetSchemaDDL(table: Table): string;
}
PostgresSchemaParser [source]
export class PostgresSchemaParser extends SchemaParser {
    async parse(database: DatabaseModel, limitTableNames?: string[]);
}

Const

postgresSerializer [source]
PostgresSerializer

Functions

parseConnectionString [source]
(url: string): PoolConfig

Types

TransactionTypes [source]
type TransactionTypes = 'REPEATABLE READ' | 'READ COMMITTED' | 'SERIALIZABLE';