1
- import type { Operators } from '@payloadcms/drizzle'
2
1
import type {
3
- BuildQueryJoinAliases ,
4
- DrizzleAdapter ,
5
- TransactionPg ,
6
- } from '@payloadcms/drizzle/types'
7
- import type { DrizzleSnapshotJSON } from 'drizzle-kit/api'
8
- import type {
9
- ColumnBaseConfig ,
10
- ColumnDataType ,
11
- DrizzleConfig ,
12
- Relation ,
13
- Relations ,
14
- SQL ,
15
- } from 'drizzle-orm'
16
- import type { NodePgDatabase } from 'drizzle-orm/node-postgres'
17
- import type {
18
- PgColumn ,
19
- PgEnum ,
20
- PgInsertOnConflictDoUpdateConfig ,
21
- PgSchema ,
22
- PgTableWithColumns ,
23
- PgTransactionConfig ,
24
- pgEnum ,
25
- } from 'drizzle-orm/pg-core'
26
- import type { PgTableFn } from 'drizzle-orm/pg-core/table'
27
- import type { Payload , PayloadRequest } from 'payload'
28
- import type { Pool , PoolConfig , QueryResult } from 'pg'
2
+ BasePostgresAdapter ,
3
+ GenericEnum ,
4
+ MigrateDownArgs ,
5
+ MigrateUpArgs ,
6
+ PostgresDB ,
7
+ } from '@payloadcms/drizzle/postgres'
8
+ import type { DrizzleAdapter } from '@payloadcms/drizzle/types'
9
+ import type { DrizzleConfig } from 'drizzle-orm'
10
+ import type { PgSchema , PgTableFn , PgTransactionConfig } from 'drizzle-orm/pg-core'
11
+ import type { Pool , PoolConfig } from 'pg'
29
12
30
13
export type Args = {
31
14
idType ?: 'serial' | 'uuid'
@@ -49,125 +32,10 @@ export type Args = {
49
32
versionsSuffix ?: string
50
33
}
51
34
52
- export type GenericColumn = PgColumn <
53
- ColumnBaseConfig < ColumnDataType , string > ,
54
- Record < string , unknown >
55
- >
56
-
57
- export type GenericColumns = {
58
- [ x : string ] : GenericColumn
59
- }
60
-
61
- export type GenericTable = PgTableWithColumns < {
62
- columns : GenericColumns
63
- dialect : string
64
- name : string
65
- schema : string
66
- } >
67
-
68
- export type GenericEnum = PgEnum < [ string , ...string [ ] ] >
69
-
70
- export type GenericRelation = Relations < string , Record < string , Relation < string > > >
71
-
72
- export type PostgresDB = NodePgDatabase < Record < string , unknown > >
73
-
74
- export type CountDistinct = ( args : {
75
- db : PostgresDB | TransactionPg
76
- joins : BuildQueryJoinAliases
77
- tableName : string
78
- where : SQL
79
- } ) => Promise < number >
80
-
81
- export type DeleteWhere = ( args : {
82
- db : PostgresDB | TransactionPg
83
- tableName : string
84
- where : SQL
85
- } ) => Promise < void >
86
-
87
- export type DropDatabase = ( args : { adapter : PostgresAdapter } ) => Promise < void >
88
-
89
- export type Execute < T > = ( args : {
90
- db ?: PostgresDB | TransactionPg
91
- drizzle ?: PostgresDB
92
- raw ?: string
93
- sql ?: SQL < unknown >
94
- } ) => Promise < QueryResult < Record < string , T > > >
95
-
96
- export type Insert = ( args : {
97
- db : PostgresDB | TransactionPg
98
- onConflictDoUpdate ?: PgInsertOnConflictDoUpdateConfig < any >
99
- tableName : string
100
- values : Record < string , unknown > | Record < string , unknown > [ ]
101
- } ) => Promise < Record < string , unknown > [ ] >
102
-
103
- type PostgresDrizzleAdapter = Omit <
104
- DrizzleAdapter ,
105
- | 'countDistinct'
106
- | 'deleteWhere'
107
- | 'drizzle'
108
- | 'dropDatabase'
109
- | 'execute'
110
- | 'insert'
111
- | 'operators'
112
- | 'relations'
113
- >
114
-
115
- type Schema =
116
- | {
117
- enum : typeof pgEnum
118
- table : PgTableFn
119
- }
120
- | PgSchema
121
-
122
35
export type PostgresAdapter = {
123
- countDistinct : CountDistinct
124
- defaultDrizzleSnapshot : DrizzleSnapshotJSON
125
- deleteWhere : DeleteWhere
126
- drizzle : PostgresDB
127
- dropDatabase : DropDatabase
128
- enums : Record < string , GenericEnum >
129
- execute : Execute < unknown >
130
- /**
131
- * 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
132
- * Used for returning properly formed errors from unique fields
133
- */
134
- fieldConstraints : Record < string , Record < string , string > >
135
- idType : Args [ 'idType' ]
136
- initializing : Promise < void >
137
- insert : Insert
138
- localesSuffix ?: string
139
- logger : DrizzleConfig [ 'logger' ]
140
- operators : Operators
141
- pgSchema ?: Schema
142
36
pool : Pool
143
- poolOptions : Args [ 'pool' ]
144
- prodMigrations ?: {
145
- down : ( args : MigrateDownArgs ) => Promise < void >
146
- name : string
147
- up : ( args : MigrateUpArgs ) => Promise < void >
148
- } [ ]
149
- push : boolean
150
- rejectInitializing : ( ) => void
151
- relations : Record < string , GenericRelation >
152
- relationshipsSuffix ?: string
153
- resolveInitializing : ( ) => void
154
- schemaName ?: Args [ 'schemaName' ]
155
- sessions : {
156
- [ id : string ] : {
157
- db : PostgresDB | TransactionPg
158
- reject : ( ) => Promise < void >
159
- resolve : ( ) => Promise < void >
160
- }
161
- }
162
- tableNameMap : Map < string , string >
163
- tables : Record < string , GenericTable >
164
- versionsSuffix ?: string
165
- } & PostgresDrizzleAdapter
166
-
167
- export type IDType = 'integer' | 'numeric' | 'uuid' | 'varchar'
168
-
169
- export type MigrateUpArgs = { payload : Payload ; req ?: Partial < PayloadRequest > }
170
- export type MigrateDownArgs = { payload : Payload ; req ?: Partial < PayloadRequest > }
37
+ poolOptions : PoolConfig
38
+ } & BasePostgresAdapter
171
39
172
40
declare module 'payload' {
173
41
export interface DatabaseAdapter
0 commit comments