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
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();
}
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>;
}
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();
}
export class PostgresConnectionPool extends SQLConnectionPool {
constructor(protected pool: Pool, protected logger: Logger, protected stopwatch?: Stopwatch);
async getConnection(transaction?: PostgresDatabaseTransaction): Promise<PostgresConnection>;
release(connection: PostgresConnection);
}
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>;
}
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>;
}
export class PostgresSQLDatabaseQuery<T extends OrmEntity> extends SQLDatabaseQuery<T> {
}
export class PostgresSQLDatabaseQueryFactory extends SQLDatabaseQueryFactory {
createQuery<T extends OrmEntity>(type?: ReceiveType<T> | ClassType<T> | AbstractClassType<T> | ReflectionClass<T>): PostgresSQLDatabaseQuery<T>;
}
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;
}
export class PostgresPlaceholderStrategy extends SqlPlaceholderStrategy {
override getPlaceholder();
}
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;
}
export class PostgresSchemaParser extends SchemaParser {
async parse(database: DatabaseModel, limitTableNames?: string[]);
}
Const
PostgresSerializer
Functions
(url: string): PoolConfig
Types
type TransactionTypes = 'REPEATABLE READ' | 'READ COMMITTED' | 'SERIALIZABLE';