import type { DrizzleSnapshotJSON } from 'drizzle-kit/api'; import type { ColumnBaseConfig, ColumnDataType, DrizzleConfig, Relation, Relations, SQL } from 'drizzle-orm'; import type { NodePgDatabase } from 'drizzle-orm/node-postgres'; import type { ForeignKeyBuilder, IndexBuilder, PgColumn, PgEnum, pgEnum, PgInsertOnConflictDoUpdateConfig, PgSchema, PgTableWithColumns, UniqueConstraintBuilder } from 'drizzle-orm/pg-core'; import type { PgTableFn } from 'drizzle-orm/pg-core/table'; import type { SQLiteColumn } from 'drizzle-orm/sqlite-core'; import type { Payload, PayloadRequest } from 'payload'; import type { ClientConfig, QueryResult } from 'pg'; import type { extendDrizzleTable, Operators } from '../index.js'; import type { BuildQueryJoinAliases, DrizzleAdapter, TransactionPg } from '../types.js'; export type BaseExtraConfig = Record ForeignKeyBuilder | IndexBuilder | UniqueConstraintBuilder>; export type RelationMap = Map; export type GenericColumn = PgColumn, Record>; export type GenericColumns = { [x: string]: GenericColumn; }; export type GenericTable = PgTableWithColumns<{ columns: GenericColumns; dialect: string; name: string; schema: string; }>; export type GenericEnum = PgEnum<[string, ...string[]]>; export type GenericRelation = Relations>>; export type PostgresDB = NodePgDatabase>; export type CountDistinct = (args: { column?: PgColumn | SQLiteColumn; db: PostgresDB | TransactionPg; joins: BuildQueryJoinAliases; tableName: string; where: SQL; }) => Promise; export type DeleteWhere = (args: { db: PostgresDB | TransactionPg; tableName: string; where: SQL; }) => Promise; export type DropDatabase = (args: { adapter: BasePostgresAdapter; }) => Promise; export type Execute = (args: { db?: PostgresDB | TransactionPg; drizzle?: PostgresDB; raw?: string; sql?: SQL; }) => Promise>>; export type Insert = (args: { db: PostgresDB | TransactionPg; onConflictDoUpdate?: PgInsertOnConflictDoUpdateConfig; tableName: string; values: Record | Record[]; }) => Promise[]>; export type CreateDatabase = (args?: { /** * Name of a database, defaults to the current one */ name?: string; /** * Schema to create in addition to 'public'. Defaults from adapter.schemaName if exists. */ schemaName?: string; }) => Promise; type Schema = { enum: typeof pgEnum; table: PgTableFn; } | PgSchema; type PostgresSchema = { enums: Record; relations: Record; tables: Record>; }; type PostgresSchemaHookArgs = { adapter: PostgresDrizzleAdapter; extendTable: typeof extendDrizzleTable; schema: PostgresSchema; }; export type PostgresSchemaHook = (args: PostgresSchemaHookArgs) => PostgresSchema | Promise; export type BasePostgresAdapter = { afterSchemaInit: PostgresSchemaHook[]; beforeSchemaInit: PostgresSchemaHook[]; countDistinct: CountDistinct; createDatabase: CreateDatabase; createExtensions: () => Promise; defaultDrizzleSnapshot: DrizzleSnapshotJSON; deleteWhere: DeleteWhere; disableCreateDatabase: boolean; drizzle: PostgresDB; dropDatabase: DropDatabase; enums: Record; execute: Execute; extensions: Record; /** * An object keyed on each table, with a key value pair where the constraint name is the key, followed by the dot-notation field name * Used for returning properly formed errors from unique fields */ fieldConstraints: Record>; idType: 'serial' | 'uuid'; initializing: Promise; insert: Insert; localesSuffix?: string; logger: DrizzleConfig['logger']; operators: Operators; pgSchema: Schema; poolOptions?: ClientConfig; prodMigrations?: { down: (args: MigrateDownArgs) => Promise; name: string; up: (args: MigrateUpArgs) => Promise; }[]; push: boolean; readReplicaOptions?: string[]; rejectInitializing: () => void; relations: Record; relationshipsSuffix?: string; resolveInitializing: () => void; schemaName?: string; sessions: { [id: string]: { db: PostgresDB | TransactionPg; reject: () => Promise; resolve: () => Promise; }; }; tableNameMap: Map; tables: Record; tablesFilter?: string[]; versionsSuffix?: string; } & PostgresDrizzleAdapter; export type PostgresDrizzleAdapter = Omit; export type IDType = 'integer' | 'numeric' | 'uuid' | 'varchar'; export type MigrateUpArgs = { /** * The Postgres Drizzle instance that you can use to execute SQL directly within the current transaction. * @example * ```ts * import { type MigrateUpArgs, sql } from '@payloadcms/db-postgres' * * export async function up({ db, payload, req }: MigrateUpArgs): Promise { * const { rows: posts } = await db.execute(sql`SELECT * FROM posts`) * } * ``` */ db: PostgresDB; /** * The Payload instance that you can use to execute Local API methods * To use the current transaction you must pass `req` to arguments * @example * ```ts * import { type MigrateUpArgs, sql } from '@payloadcms/db-postgres' * * export async function up({ db, payload, req }: MigrateUpArgs): Promise { * const posts = await payload.find({ collection: 'posts', req }) * } * ``` */ payload: Payload; /** * The `PayloadRequest` object that contains the current transaction */ req: PayloadRequest; }; export type MigrateDownArgs = { /** * The Postgres Drizzle instance that you can use to execute SQL directly within the current transaction. * @example * ```ts * import { type MigrateDownArgs, sql } from '@payloadcms/db-postgres' * * export async function down({ db, payload, req }: MigrateDownArgs): Promise { * const { rows: posts } = await db.execute(sql`SELECT * FROM posts`) * } * ``` */ db: PostgresDB; /** * The Payload instance that you can use to execute Local API methods * To use the current transaction you must pass `req` to arguments * @example * ```ts * import { type MigrateDownArgs } from '@payloadcms/db-postgres' * * export async function down({ db, payload, req }: MigrateDownArgs): Promise { * const posts = await payload.find({ collection: 'posts', req }) * } * ``` */ payload: Payload; /** * The `PayloadRequest` object that contains the current transaction */ req: PayloadRequest; }; export {}; //# sourceMappingURL=types.d.ts.map