1
1
import PostgrestBuilder from './PostgrestBuilder'
2
2
import PostgrestFilterBuilder from './PostgrestFilterBuilder'
3
3
import { GetResult } from './select-query-parser/result'
4
- import { Fetch , GenericSchema , GenericTable , GenericView } from './types'
4
+ import { ClientServerOptions , Fetch , GenericSchema , GenericTable , GenericView } from './types'
5
5
6
6
export default class PostgrestQueryBuilder <
7
+ ClientOptions extends ClientServerOptions ,
7
8
Schema extends GenericSchema ,
8
9
Relation extends GenericTable | GenericView ,
9
10
RelationName = unknown ,
@@ -56,7 +57,14 @@ export default class PostgrestQueryBuilder<
56
57
*/
57
58
select <
58
59
Query extends string = '*' ,
59
- ResultOne = GetResult < Schema , Relation [ 'Row' ] , RelationName , Relationships , Query >
60
+ ResultOne = GetResult <
61
+ Schema ,
62
+ Relation [ 'Row' ] ,
63
+ RelationName ,
64
+ Relationships ,
65
+ Query ,
66
+ ClientOptions
67
+ >
60
68
> (
61
69
columns ?: Query ,
62
70
{
@@ -67,6 +75,7 @@ export default class PostgrestQueryBuilder<
67
75
count ?: 'exact' | 'planned' | 'estimated'
68
76
} = { }
69
77
) : PostgrestFilterBuilder <
78
+ ClientOptions ,
70
79
Schema ,
71
80
Relation [ 'Row' ] ,
72
81
ResultOne [ ] ,
@@ -101,7 +110,7 @@ export default class PostgrestQueryBuilder<
101
110
schema : this . schema ,
102
111
fetch : this . fetch ,
103
112
allowEmpty : false ,
104
- } as unknown as PostgrestBuilder < ResultOne [ ] > )
113
+ } as unknown as PostgrestBuilder < ClientOptions , ResultOne [ ] > )
105
114
}
106
115
107
116
// TODO(v3): Make `defaultToNull` consistent for both single & bulk inserts.
@@ -110,14 +119,30 @@ export default class PostgrestQueryBuilder<
110
119
options ?: {
111
120
count ?: 'exact' | 'planned' | 'estimated'
112
121
}
113
- ) : PostgrestFilterBuilder < Schema , Relation [ 'Row' ] , null , RelationName , Relationships , 'POST' >
122
+ ) : PostgrestFilterBuilder <
123
+ ClientOptions ,
124
+ Schema ,
125
+ Relation [ 'Row' ] ,
126
+ null ,
127
+ RelationName ,
128
+ Relationships ,
129
+ 'POST'
130
+ >
114
131
insert < Row extends Relation extends { Insert : unknown } ? Relation [ 'Insert' ] : never > (
115
132
values : Row [ ] ,
116
133
options ?: {
117
134
count ?: 'exact' | 'planned' | 'estimated'
118
135
defaultToNull ?: boolean
119
136
}
120
- ) : PostgrestFilterBuilder < Schema , Relation [ 'Row' ] , null , RelationName , Relationships , 'POST' >
137
+ ) : PostgrestFilterBuilder <
138
+ ClientOptions ,
139
+ Schema ,
140
+ Relation [ 'Row' ] ,
141
+ null ,
142
+ RelationName ,
143
+ Relationships ,
144
+ 'POST'
145
+ >
121
146
/**
122
147
* Perform an INSERT into the table or view.
123
148
*
@@ -153,7 +178,15 @@ export default class PostgrestQueryBuilder<
153
178
count ?: 'exact' | 'planned' | 'estimated'
154
179
defaultToNull ?: boolean
155
180
} = { }
156
- ) : PostgrestFilterBuilder < Schema , Relation [ 'Row' ] , null , RelationName , Relationships , 'POST' > {
181
+ ) : PostgrestFilterBuilder <
182
+ ClientOptions ,
183
+ Schema ,
184
+ Relation [ 'Row' ] ,
185
+ null ,
186
+ RelationName ,
187
+ Relationships ,
188
+ 'POST'
189
+ > {
157
190
const method = 'POST'
158
191
159
192
const prefersHeaders = [ ]
@@ -184,7 +217,7 @@ export default class PostgrestQueryBuilder<
184
217
body : values ,
185
218
fetch : this . fetch ,
186
219
allowEmpty : false ,
187
- } as unknown as PostgrestBuilder < null > )
220
+ } as unknown as PostgrestBuilder < ClientOptions , null > )
188
221
}
189
222
190
223
// TODO(v3): Make `defaultToNull` consistent for both single & bulk upserts.
@@ -195,7 +228,15 @@ export default class PostgrestQueryBuilder<
195
228
ignoreDuplicates ?: boolean
196
229
count ?: 'exact' | 'planned' | 'estimated'
197
230
}
198
- ) : PostgrestFilterBuilder < Schema , Relation [ 'Row' ] , null , RelationName , Relationships , 'POST' >
231
+ ) : PostgrestFilterBuilder <
232
+ ClientOptions ,
233
+ Schema ,
234
+ Relation [ 'Row' ] ,
235
+ null ,
236
+ RelationName ,
237
+ Relationships ,
238
+ 'POST'
239
+ >
199
240
upsert < Row extends Relation extends { Insert : unknown } ? Relation [ 'Insert' ] : never > (
200
241
values : Row [ ] ,
201
242
options ?: {
@@ -204,7 +245,15 @@ export default class PostgrestQueryBuilder<
204
245
count ?: 'exact' | 'planned' | 'estimated'
205
246
defaultToNull ?: boolean
206
247
}
207
- ) : PostgrestFilterBuilder < Schema , Relation [ 'Row' ] , null , RelationName , Relationships , 'POST' >
248
+ ) : PostgrestFilterBuilder <
249
+ ClientOptions ,
250
+ Schema ,
251
+ Relation [ 'Row' ] ,
252
+ null ,
253
+ RelationName ,
254
+ Relationships ,
255
+ 'POST'
256
+ >
208
257
/**
209
258
* Perform an UPSERT on the table or view. Depending on the column(s) passed
210
259
* to `onConflict`, `.upsert()` allows you to perform the equivalent of
@@ -256,7 +305,15 @@ export default class PostgrestQueryBuilder<
256
305
count ?: 'exact' | 'planned' | 'estimated'
257
306
defaultToNull ?: boolean
258
307
} = { }
259
- ) : PostgrestFilterBuilder < Schema , Relation [ 'Row' ] , null , RelationName , Relationships , 'POST' > {
308
+ ) : PostgrestFilterBuilder <
309
+ ClientOptions ,
310
+ Schema ,
311
+ Relation [ 'Row' ] ,
312
+ null ,
313
+ RelationName ,
314
+ Relationships ,
315
+ 'POST'
316
+ > {
260
317
const method = 'POST'
261
318
262
319
const prefersHeaders = [ `resolution=${ ignoreDuplicates ? 'ignore' : 'merge' } -duplicates` ]
@@ -289,7 +346,7 @@ export default class PostgrestQueryBuilder<
289
346
body : values ,
290
347
fetch : this . fetch ,
291
348
allowEmpty : false ,
292
- } as unknown as PostgrestBuilder < null > )
349
+ } as unknown as PostgrestBuilder < ClientOptions , null > )
293
350
}
294
351
295
352
/**
@@ -320,7 +377,15 @@ export default class PostgrestQueryBuilder<
320
377
} : {
321
378
count ?: 'exact' | 'planned' | 'estimated'
322
379
} = { }
323
- ) : PostgrestFilterBuilder < Schema , Relation [ 'Row' ] , null , RelationName , Relationships , 'PATCH' > {
380
+ ) : PostgrestFilterBuilder <
381
+ ClientOptions ,
382
+ Schema ,
383
+ Relation [ 'Row' ] ,
384
+ null ,
385
+ RelationName ,
386
+ Relationships ,
387
+ 'PATCH'
388
+ > {
324
389
const method = 'PATCH'
325
390
const prefersHeaders = [ ]
326
391
if ( this . headers [ 'Prefer' ] ) {
@@ -339,7 +404,7 @@ export default class PostgrestQueryBuilder<
339
404
body : values ,
340
405
fetch : this . fetch ,
341
406
allowEmpty : false ,
342
- } as unknown as PostgrestBuilder < null > )
407
+ } as unknown as PostgrestBuilder < ClientOptions , null > )
343
408
}
344
409
345
410
/**
@@ -366,6 +431,7 @@ export default class PostgrestQueryBuilder<
366
431
} : {
367
432
count ?: 'exact' | 'planned' | 'estimated'
368
433
} = { } ) : PostgrestFilterBuilder <
434
+ ClientOptions ,
369
435
Schema ,
370
436
Relation [ 'Row' ] ,
371
437
null ,
@@ -390,6 +456,6 @@ export default class PostgrestQueryBuilder<
390
456
schema : this . schema ,
391
457
fetch : this . fetch ,
392
458
allowEmpty : false ,
393
- } as unknown as PostgrestBuilder < null > )
459
+ } as unknown as PostgrestBuilder < ClientOptions , null > )
394
460
}
395
461
}
0 commit comments