@depup/postgres 3.4.8-depup.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,743 @@
1
+ import { Readable, Writable } from 'node:stream'
2
+
3
+ /**
4
+ * Establish a connection to a PostgreSQL server.
5
+ * @param options Connection options - default to the same as psql
6
+ * @returns An utility function to make queries to the server
7
+ */
8
+ declare function postgres<T extends Record<string, postgres.PostgresType> = {}>(options?: postgres.Options<T> | undefined): postgres.Sql<Record<string, postgres.PostgresType> extends T ? {} : { [type in keyof T]: T[type] extends {
9
+ serialize: (value: infer R) => any,
10
+ parse: (raw: any) => infer R
11
+ } ? R : never }>
12
+ /**
13
+ * Establish a connection to a PostgreSQL server.
14
+ * @param url Connection string used for authentication
15
+ * @param options Connection options - default to the same as psql
16
+ * @returns An utility function to make queries to the server
17
+ */
18
+ declare function postgres<T extends Record<string, postgres.PostgresType> = {}>(url: string, options?: postgres.Options<T> | undefined): postgres.Sql<Record<string, postgres.PostgresType> extends T ? {} : { [type in keyof T]: T[type] extends {
19
+ serialize: (value: infer R) => any,
20
+ parse: (raw: any) => infer R
21
+ } ? R : never }>
22
+
23
+ /**
24
+ * Connection options of Postgres.
25
+ */
26
+ interface BaseOptions<T extends Record<string, postgres.PostgresType>> {
27
+ /** Postgres ip address[s] or domain name[s] */
28
+ host: string | string[] | undefined;
29
+ /** Postgres server[s] port[s] */
30
+ port: number | number[] | undefined;
31
+ /** unix socket path (usually '/tmp') */
32
+ path: string | undefined;
33
+ /**
34
+ * Name of database to connect to
35
+ * @default process.env['PGDATABASE'] || options.user
36
+ */
37
+ database: string;
38
+ /**
39
+ * Username of database user
40
+ * @default process.env['PGUSERNAME'] || process.env['PGUSER'] || require('os').userInfo().username
41
+ */
42
+ user: string;
43
+ /**
44
+ * How to deal with ssl (can be a tls.connect option object)
45
+ * @default false
46
+ */
47
+ ssl: 'require' | 'allow' | 'prefer' | 'verify-full' | boolean | object;
48
+ /**
49
+ * Max number of connections
50
+ * @default 10
51
+ */
52
+ max: number;
53
+ /**
54
+ * Idle connection timeout in seconds
55
+ * @default process.env['PGIDLE_TIMEOUT']
56
+ */
57
+ idle_timeout: number | undefined;
58
+ /**
59
+ * Connect timeout in seconds
60
+ * @default process.env['PGCONNECT_TIMEOUT']
61
+ */
62
+ connect_timeout: number;
63
+ /** Array of custom types; see more in the README */
64
+ types: T;
65
+ /**
66
+ * Enables prepare mode.
67
+ * @default true
68
+ */
69
+ prepare: boolean;
70
+ /**
71
+ * Called when a notice is received
72
+ * @default console.log
73
+ */
74
+ onnotice: (notice: postgres.Notice) => void;
75
+ /** (key; value) when a server param change */
76
+ onparameter: (key: string, value: any) => void;
77
+ /** Is called with (connection; query; parameters) */
78
+ debug: boolean | ((connection: number, query: string, parameters: any[], paramTypes: any[]) => void);
79
+ /** Transform hooks */
80
+ transform: {
81
+ /** Transforms outcoming undefined values */
82
+ undefined?: any
83
+
84
+ /** Transforms incoming and outgoing column names */
85
+ column?: ((column: string) => string) | {
86
+ /** Transform function for column names in result rows */
87
+ from?: ((column: string) => string) | undefined;
88
+ /** Transform function for column names in interpolated values passed to tagged template literal */
89
+ to?: ((column: string) => string) | undefined;
90
+ } | undefined;
91
+ /** Transforms incoming and outgoing row values */
92
+ value?: ((value: any) => any) | {
93
+ /** Transform function for values in result rows */
94
+ from?: ((value: unknown, column: postgres.Column<string>) => any) | undefined;
95
+ // to?: ((value: unknown) => any) | undefined; // unused
96
+ } | undefined;
97
+ /** Transforms entire rows */
98
+ row?: ((row: postgres.Row) => any) | {
99
+ /** Transform function for entire result rows */
100
+ from?: ((row: postgres.Row) => any) | undefined;
101
+ // to?: ((row: postgres.Row) => any) | undefined; // unused
102
+ } | undefined;
103
+ };
104
+ /** Connection parameters */
105
+ connection: Partial<postgres.ConnectionParameters>;
106
+ /**
107
+ * Use 'read-write' with multiple hosts to ensure only connecting to primary
108
+ * @default process.env['PGTARGETSESSIONATTRS']
109
+ */
110
+ target_session_attrs: undefined | 'read-write' | 'read-only' | 'primary' | 'standby' | 'prefer-standby';
111
+ /**
112
+ * Automatically fetches types on connect
113
+ * @default true
114
+ */
115
+ fetch_types: boolean;
116
+ /**
117
+ * Publications to subscribe to (only relevant when calling `sql.subscribe()`)
118
+ * @default 'alltables'
119
+ */
120
+ publications: string
121
+ onclose: (connId: number) => void;
122
+ backoff: boolean | ((attemptNum: number) => number);
123
+ max_lifetime: number | null;
124
+ keep_alive: number | null;
125
+ }
126
+
127
+
128
+ declare const PRIVATE: unique symbol;
129
+
130
+ declare class NotAPromise {
131
+ private [PRIVATE]: never; // prevent user-side interface implementation
132
+
133
+ /**
134
+ * @deprecated This object isn't an SQL query, and therefore not a Promise; use the tagged template string syntax instead: ```await sql\`...\`;```
135
+ * @throws NOT_TAGGED_CALL
136
+ */
137
+ private then(): never;
138
+ /**
139
+ * @deprecated This object isn't an SQL query, and therefore not a Promise; use the tagged template string syntax instead: ```await sql\`...\`;```
140
+ * @throws NOT_TAGGED_CALL
141
+ */
142
+ private catch(): never;
143
+ /**
144
+ * @deprecated This object isn't an SQL query, and therefore not a Promise; use the tagged template string syntax instead: ```await sql\`...\`;```
145
+ * @throws NOT_TAGGED_CALL
146
+ */
147
+ private finally(): never;
148
+ }
149
+
150
+ type UnwrapPromiseArray<T> = T extends any[] ? {
151
+ [k in keyof T]: T[k] extends Promise<infer R> ? R : T[k]
152
+ } : T;
153
+
154
+ type Keys = string
155
+
156
+ type SerializableObject<T, K extends readonly any[], TT> =
157
+ number extends K['length'] ? {} :
158
+ Partial<(Record<Keys & (keyof T) & (K['length'] extends 0 ? string : K[number]), postgres.ParameterOrJSON<TT> | undefined> & Record<string, any>)>
159
+
160
+ type First<T, K extends readonly any[], TT> =
161
+ // Tagged template string call
162
+ T extends TemplateStringsArray ? TemplateStringsArray :
163
+ // Identifiers helper
164
+ T extends string ? string :
165
+ // Dynamic values helper (depth 2)
166
+ T extends readonly any[][] ? readonly postgres.EscapableArray[] :
167
+ // Insert/update helper (depth 2)
168
+ T extends readonly (object & infer R)[] ? (R extends postgres.SerializableParameter<TT> ? readonly postgres.SerializableParameter<TT>[] : readonly SerializableObject<R, K, TT>[]) :
169
+ // Dynamic values/ANY helper (depth 1)
170
+ T extends readonly any[] ? (readonly postgres.SerializableParameter<TT>[]) :
171
+ // Insert/update helper (depth 1)
172
+ T extends object ? SerializableObject<T, K, TT> :
173
+ // Unexpected type
174
+ never
175
+
176
+ type Rest<T> =
177
+ T extends TemplateStringsArray ? never : // force fallback to the tagged template function overload
178
+ T extends string ? readonly string[] :
179
+ T extends readonly any[][] ? readonly [] :
180
+ T extends readonly (object & infer R)[] ? (
181
+ readonly (Keys & keyof R)[] // sql(data, "prop", "prop2") syntax
182
+ |
183
+ [readonly (Keys & keyof R)[]] // sql(data, ["prop", "prop2"]) syntax
184
+ ) :
185
+ T extends readonly any[] ? readonly [] :
186
+ T extends object ? (
187
+ readonly (Keys & keyof T)[] // sql(data, "prop", "prop2") syntax
188
+ |
189
+ [readonly (Keys & keyof T)[]] // sql(data, ["prop", "prop2"]) syntax
190
+ ) :
191
+ any
192
+
193
+ type Return<T, K extends readonly any[]> =
194
+ [T] extends [TemplateStringsArray] ?
195
+ [unknown] extends [T] ? postgres.Helper<T, K> : // ensure no `PendingQuery` with `any` types
196
+ [TemplateStringsArray] extends [T] ? postgres.PendingQuery<postgres.Row[]> :
197
+ postgres.Helper<T, K> :
198
+ postgres.Helper<T, K>
199
+
200
+ declare namespace postgres {
201
+ class PostgresError extends Error {
202
+ name: 'PostgresError';
203
+ severity_local: string;
204
+ severity: string;
205
+ code: string;
206
+ position: string;
207
+ file: string;
208
+ line: string;
209
+ routine: string;
210
+
211
+ detail?: string | undefined;
212
+ hint?: string | undefined;
213
+ internal_position?: string | undefined;
214
+ internal_query?: string | undefined;
215
+ where?: string | undefined;
216
+ schema_name?: string | undefined;
217
+ table_name?: string | undefined;
218
+ column_name?: string | undefined;
219
+ data?: string | undefined;
220
+ type_name?: string | undefined;
221
+ constraint_name?: string | undefined;
222
+
223
+ /** Only set when debug is enabled */
224
+ query: string;
225
+ /** Only set when debug is enabled */
226
+ parameters: any[];
227
+ }
228
+
229
+ /**
230
+ * Convert a snake_case string to PascalCase.
231
+ * @param str The string from snake_case to convert
232
+ * @returns The new string in PascalCase
233
+ */
234
+ function toPascal(str: string): string;
235
+ namespace toPascal {
236
+ namespace column { function from(str: string): string; }
237
+ namespace value { function from(str: unknown, column: Column<string>): string }
238
+ }
239
+ /**
240
+ * Convert a PascalCase string to snake_case.
241
+ * @param str The string from snake_case to convert
242
+ * @returns The new string in snake_case
243
+ */
244
+ function fromPascal(str: string): string;
245
+ namespace fromPascal {
246
+ namespace column { function to(str: string): string }
247
+ }
248
+ /**
249
+ * Convert snake_case to and from PascalCase.
250
+ */
251
+ namespace pascal {
252
+ namespace column {
253
+ function from(str: string): string;
254
+ function to(str: string): string;
255
+ }
256
+ namespace value { function from(str: unknown, column: Column<string>): string }
257
+ }
258
+ /**
259
+ * Convert a snake_case string to camelCase.
260
+ * @param str The string from snake_case to convert
261
+ * @returns The new string in camelCase
262
+ */
263
+ function toCamel(str: string): string;
264
+ namespace toCamel {
265
+ namespace column { function from(str: string): string; }
266
+ namespace value { function from(str: unknown, column: Column<string>): string }
267
+ }
268
+ /**
269
+ * Convert a camelCase string to snake_case.
270
+ * @param str The string from snake_case to convert
271
+ * @returns The new string in snake_case
272
+ */
273
+ function fromCamel(str: string): string;
274
+ namespace fromCamel {
275
+ namespace column { function to(str: string): string }
276
+ }
277
+ /**
278
+ * Convert snake_case to and from camelCase.
279
+ */
280
+ namespace camel {
281
+ namespace column {
282
+ function from(str: string): string;
283
+ function to(str: string): string;
284
+ }
285
+ namespace value { function from(str: unknown, column: Column<string>): string }
286
+ }
287
+ /**
288
+ * Convert a snake_case string to kebab-case.
289
+ * @param str The string from snake_case to convert
290
+ * @returns The new string in kebab-case
291
+ */
292
+ function toKebab(str: string): string;
293
+ namespace toKebab {
294
+ namespace column { function from(str: string): string; }
295
+ namespace value { function from(str: unknown, column: Column<string>): string }
296
+ }
297
+ /**
298
+ * Convert a kebab-case string to snake_case.
299
+ * @param str The string from snake_case to convert
300
+ * @returns The new string in snake_case
301
+ */
302
+ function fromKebab(str: string): string;
303
+ namespace fromKebab {
304
+ namespace column { function to(str: string): string }
305
+ }
306
+ /**
307
+ * Convert snake_case to and from kebab-case.
308
+ */
309
+ namespace kebab {
310
+ namespace column {
311
+ function from(str: string): string;
312
+ function to(str: string): string;
313
+ }
314
+ namespace value { function from(str: unknown, column: Column<string>): string }
315
+ }
316
+
317
+ const BigInt: PostgresType<bigint>;
318
+
319
+ interface PostgresType<T = any> {
320
+ to: number;
321
+ from: number[];
322
+ serialize: (value: T) => unknown;
323
+ parse: (raw: any) => T;
324
+ }
325
+
326
+ interface ConnectionParameters {
327
+ /**
328
+ * Default application_name
329
+ * @default 'postgres.js'
330
+ */
331
+ application_name: string;
332
+ default_transaction_isolation: 'read uncommitted' | 'read committed' | 'repeatable read' | 'serializable',
333
+ default_transaction_read_only: boolean,
334
+ default_transaction_deferrable: boolean,
335
+ statement_timeout: number,
336
+ lock_timeout: number,
337
+ idle_in_transaction_session_timeout: number,
338
+ idle_session_timeout: number,
339
+ DateStyle: string,
340
+ IntervalStyle: string,
341
+ TimeZone: string,
342
+ /** Other connection parameters */
343
+ [name: string]: string | number | boolean;
344
+ }
345
+
346
+ interface Options<T extends Record<string, postgres.PostgresType>> extends Partial<BaseOptions<T>> {
347
+ /** @inheritdoc */
348
+ host?: string | undefined;
349
+ /** @inheritdoc */
350
+ port?: number | undefined;
351
+ /** @inheritdoc */
352
+ path?: string | undefined;
353
+ /** Password of database user (an alias for `password`) */
354
+ pass?: Options<T>['password'] | undefined;
355
+ /**
356
+ * Password of database user
357
+ * @default process.env['PGPASSWORD']
358
+ */
359
+ password?: string | (() => string | Promise<string>) | undefined;
360
+ /** Name of database to connect to (an alias for `database`) */
361
+ db?: Options<T>['database'] | undefined;
362
+ /** Username of database user (an alias for `user`) */
363
+ username?: Options<T>['user'] | undefined;
364
+ /** Postgres ip address or domain name (an alias for `host`) */
365
+ hostname?: Options<T>['host'] | undefined;
366
+ /**
367
+ * Disable prepared mode
368
+ * @deprecated use "prepare" option instead
369
+ */
370
+ no_prepare?: boolean | undefined;
371
+ /**
372
+ * Idle connection timeout in seconds
373
+ * @deprecated use "idle_timeout" option instead
374
+ */
375
+ timeout?: Options<T>['idle_timeout'] | undefined;
376
+ }
377
+
378
+ interface ParsedOptions<T extends Record<string, unknown> = {}> extends BaseOptions<{ [name in keyof T]: PostgresType<T[name]> }> {
379
+ /** @inheritdoc */
380
+ host: string[];
381
+ /** @inheritdoc */
382
+ port: number[];
383
+ /** @inheritdoc */
384
+ pass: null;
385
+ /** @inheritdoc */
386
+ transform: Transform;
387
+ serializers: Record<number, (value: any) => unknown>;
388
+ parsers: Record<number, (value: any) => unknown>;
389
+ }
390
+
391
+ interface Transform {
392
+ /** Transforms outcoming undefined values */
393
+ undefined: any
394
+
395
+ column: {
396
+ /** Transform function for column names in result rows */
397
+ from: ((column: string) => string) | undefined;
398
+ /** Transform function for column names in interpolated values passed to tagged template literal */
399
+ to: ((column: string) => string) | undefined;
400
+ };
401
+ value: {
402
+ /** Transform function for values in result rows */
403
+ from: ((value: any, column?: Column<string>) => any) | undefined;
404
+ /** Transform function for interpolated values passed to tagged template literal */
405
+ to: undefined; // (value: any) => any
406
+ };
407
+ row: {
408
+ /** Transform function for entire result rows */
409
+ from: ((row: postgres.Row) => any) | undefined;
410
+ to: undefined; // (row: postgres.Row) => any
411
+ };
412
+ }
413
+
414
+ interface Notice {
415
+ [field: string]: string;
416
+ }
417
+
418
+ interface Parameter<T = SerializableParameter> extends NotAPromise {
419
+ /**
420
+ * PostgreSQL OID of the type
421
+ */
422
+ type: number;
423
+ /**
424
+ * Serialized value
425
+ */
426
+ value: string | null;
427
+ /**
428
+ * Raw value to serialize
429
+ */
430
+ raw: T | null;
431
+ }
432
+
433
+ interface ArrayParameter<T extends readonly any[] = readonly any[]> extends Parameter<T | T[]> {
434
+ array: true;
435
+ }
436
+
437
+ interface ConnectionError extends globalThis.Error {
438
+ code:
439
+ | 'CONNECTION_DESTROYED'
440
+ | 'CONNECT_TIMEOUT'
441
+ | 'CONNECTION_CLOSED'
442
+ | 'CONNECTION_ENDED';
443
+ errno: this['code'];
444
+ address: string;
445
+ port?: number | undefined;
446
+ }
447
+
448
+ interface NotSupportedError extends globalThis.Error {
449
+ code: 'MESSAGE_NOT_SUPPORTED';
450
+ name: string;
451
+ }
452
+
453
+ interface GenericError extends globalThis.Error {
454
+ code:
455
+ | '57014' // canceling statement due to user request
456
+ | 'NOT_TAGGED_CALL'
457
+ | 'UNDEFINED_VALUE'
458
+ | 'MAX_PARAMETERS_EXCEEDED'
459
+ | 'SASL_SIGNATURE_MISMATCH'
460
+ | 'UNSAFE_TRANSACTION';
461
+ message: string;
462
+ }
463
+
464
+ interface AuthNotImplementedError extends globalThis.Error {
465
+ code: 'AUTH_TYPE_NOT_IMPLEMENTED';
466
+ type: number | string;
467
+ message: string;
468
+ }
469
+
470
+ type Error = never
471
+ | PostgresError
472
+ | ConnectionError
473
+ | NotSupportedError
474
+ | GenericError
475
+ | AuthNotImplementedError;
476
+
477
+ interface ColumnInfo {
478
+ key: number;
479
+ name: string;
480
+ type: number;
481
+ parser?(raw: string): unknown;
482
+ atttypmod: number;
483
+ }
484
+
485
+ interface RelationInfo {
486
+ schema: string;
487
+ table: string;
488
+ columns: ColumnInfo[];
489
+ keys: ColumnInfo[];
490
+ }
491
+
492
+ type ReplicationEvent =
493
+ | { command: 'insert', relation: RelationInfo }
494
+ | { command: 'delete', relation: RelationInfo, key: boolean }
495
+ | { command: 'update', relation: RelationInfo, key: boolean, old: Row | null };
496
+
497
+ interface SubscriptionHandle {
498
+ unsubscribe(): void;
499
+ }
500
+
501
+ interface LargeObject {
502
+ writable(options?: {
503
+ highWaterMark?: number | undefined,
504
+ start?: number | undefined
505
+ } | undefined): Promise<Writable>;
506
+ readable(options?: {
507
+ highWaterMark?: number | undefined,
508
+ start?: number | undefined,
509
+ end?: number | undefined
510
+ } | undefined): Promise<Readable>;
511
+
512
+ close(): Promise<void>;
513
+ tell(): Promise<void>;
514
+ read(size: number): Promise<void>;
515
+ write(buffer: Uint8Array): Promise<[{ data: Uint8Array }]>;
516
+ truncate(size: number): Promise<void>;
517
+ seek(offset: number, whence?: number | undefined): Promise<void>;
518
+ size(): Promise<[{ position: bigint, size: bigint }]>;
519
+ }
520
+
521
+ type EscapableArray = (string | number)[]
522
+
523
+ type Serializable = never
524
+ | null
525
+ | boolean
526
+ | number
527
+ | string
528
+ | Date
529
+ | Uint8Array;
530
+
531
+ type SerializableParameter<T = never> = never
532
+ | T
533
+ | Serializable
534
+ | Helper<any>
535
+ | Parameter<any>
536
+ | ArrayParameter
537
+ | readonly SerializableParameter<T>[];
538
+
539
+ type JSONValue = // using a dedicated type to detect symbols, bigints, and other non serializable types
540
+ | null
541
+ | string
542
+ | number
543
+ | boolean
544
+ | Date // serialized as `string`
545
+ | readonly JSONValue[]
546
+ | { toJSON(): any } // `toJSON` called by `JSON.stringify`; not typing the return type, types definition is strict enough anyway
547
+ | {
548
+ readonly [prop: string | number]:
549
+ | undefined
550
+ | JSONValue
551
+ | ((...args: any) => any) // serialized as `undefined`
552
+ };
553
+
554
+ interface Row {
555
+ [column: string]: any;
556
+ }
557
+
558
+ type MaybeRow = Row | undefined;
559
+
560
+ interface Column<T extends string> {
561
+ name: T;
562
+ type: number;
563
+ table: number;
564
+ number: number;
565
+ parser?: ((raw: string) => unknown) | undefined;
566
+ }
567
+
568
+ type ColumnList<T> = (T extends string ? Column<T> : never)[];
569
+
570
+ interface State {
571
+ status: string;
572
+ pid: number;
573
+ secret: number;
574
+ }
575
+
576
+ interface Statement {
577
+ /** statement unique name */
578
+ name: string;
579
+ /** sql query */
580
+ string: string;
581
+ /** parameters types */
582
+ types: number[];
583
+ columns: ColumnList<string>;
584
+ }
585
+
586
+ interface ResultMeta<T extends number | null> {
587
+ count: T; // For tuples
588
+ command: string;
589
+ statement: Statement;
590
+ state: State;
591
+ }
592
+
593
+ interface ResultQueryMeta<T extends number | null, U> extends ResultMeta<T> {
594
+ columns: ColumnList<U>;
595
+ }
596
+
597
+ type ExecutionResult<T> = [] & ResultQueryMeta<number, keyof NonNullable<T>>;
598
+ type ValuesRowList<T extends readonly any[]> = T[number][keyof T[number]][][] & ResultQueryMeta<T['length'], keyof T[number]>;
599
+ type RawRowList<T extends readonly any[]> = Buffer[][] & Iterable<Buffer[][]> & ResultQueryMeta<T['length'], keyof T[number]>;
600
+ type RowList<T extends readonly any[]> = T & Iterable<NonNullable<T[number]>> & ResultQueryMeta<T['length'], keyof T[number]>;
601
+
602
+ interface PendingQueryModifiers<TRow extends readonly any[]> {
603
+ simple(): this;
604
+ readable(): Promise<Readable>;
605
+ writable(): Promise<Writable>;
606
+
607
+ execute(): this;
608
+ cancel(): void;
609
+
610
+ /**
611
+ * @deprecated `.stream` has been renamed to `.forEach`
612
+ * @throws
613
+ */
614
+ stream(cb: (row: NonNullable<TRow[number]>, result: ExecutionResult<TRow[number]>) => void): never;
615
+ forEach(cb: (row: NonNullable<TRow[number]>, result: ExecutionResult<TRow[number]>) => void): Promise<ExecutionResult<TRow[number]>>;
616
+
617
+ cursor(rows?: number | undefined): AsyncIterable<NonNullable<TRow[number]>[]>;
618
+ cursor(cb: (row: [NonNullable<TRow[number]>]) => void): Promise<ExecutionResult<TRow[number]>>;
619
+ cursor(rows: number, cb: (rows: NonNullable<TRow[number]>[]) => void): Promise<ExecutionResult<TRow[number]>>;
620
+ }
621
+
622
+ interface PendingDescribeQuery extends Promise<Statement> {
623
+ }
624
+
625
+ interface PendingValuesQuery<TRow extends readonly MaybeRow[]> extends Promise<ValuesRowList<TRow>>, PendingQueryModifiers<TRow[number][keyof TRow[number]][][]> {
626
+ describe(): PendingDescribeQuery;
627
+ }
628
+
629
+ interface PendingRawQuery<TRow extends readonly MaybeRow[]> extends Promise<RawRowList<TRow>>, PendingQueryModifiers<Buffer[][]> {
630
+ }
631
+
632
+ interface PendingQuery<TRow extends readonly MaybeRow[]> extends Promise<RowList<TRow>>, PendingQueryModifiers<TRow> {
633
+ describe(): PendingDescribeQuery;
634
+ values(): PendingValuesQuery<TRow>;
635
+ raw(): PendingRawQuery<TRow>;
636
+ }
637
+
638
+ interface PendingRequest extends Promise<[] & ResultMeta<null>> { }
639
+
640
+ interface ListenRequest extends Promise<ListenMeta> { }
641
+ interface ListenMeta extends ResultMeta<null> {
642
+ unlisten(): Promise<void>
643
+ }
644
+
645
+ interface Helper<T, U extends readonly any[] = T[]> extends NotAPromise {
646
+ first: T;
647
+ rest: U;
648
+ }
649
+
650
+ type Fragment = PendingQuery<any>
651
+
652
+ type ParameterOrJSON<T> =
653
+ | SerializableParameter<T>
654
+ | JSONValue
655
+
656
+ type ParameterOrFragment<T> =
657
+ | SerializableParameter<T>
658
+ | Fragment
659
+ | Fragment[]
660
+
661
+ interface Sql<TTypes extends Record<string, unknown> = {}> {
662
+ /**
663
+ * Query helper
664
+ * @param first Define how the helper behave
665
+ * @param rest Other optional arguments, depending on the helper type
666
+ * @returns An helper object usable as tagged template parameter in sql queries
667
+ */
668
+ <T, K extends Rest<T>>(first: T & First<T, K, TTypes[keyof TTypes]>, ...rest: K): Return<T, K>;
669
+
670
+ /**
671
+ * Execute the SQL query passed as a template string. Can only be used as template string tag.
672
+ * @param template The template generated from the template string
673
+ * @param parameters Interpoled values of the template string
674
+ * @returns A promise resolving to the result of your query
675
+ */
676
+ <T extends readonly (object | undefined)[] = Row[]>(template: TemplateStringsArray, ...parameters: readonly (ParameterOrFragment<TTypes[keyof TTypes]>)[]): PendingQuery<T>;
677
+
678
+ CLOSE: {};
679
+ END: this['CLOSE'];
680
+ PostgresError: typeof PostgresError;
681
+
682
+ options: ParsedOptions<TTypes>;
683
+ parameters: ConnectionParameters;
684
+ types: this['typed'];
685
+ typed: (<T>(value: T, oid: number) => Parameter<T>) & {
686
+ [name in keyof TTypes]: (value: TTypes[name]) => postgres.Parameter<TTypes[name]>
687
+ };
688
+
689
+ unsafe<T extends any[] = (Row & Iterable<Row>)[]>(query: string, parameters?: (ParameterOrJSON<TTypes[keyof TTypes]>)[] | undefined, queryOptions?: UnsafeQueryOptions | undefined): PendingQuery<T>;
690
+ end(options?: { timeout?: number | undefined } | undefined): Promise<void>;
691
+
692
+ listen(channel: string, onnotify: (value: string) => void, onlisten?: (() => void) | undefined): ListenRequest;
693
+ notify(channel: string, payload: string): PendingRequest;
694
+
695
+ subscribe(event: string, cb: (row: Row | null, info: ReplicationEvent) => void, onsubscribe?: (() => void), onerror?: (() => any)): Promise<SubscriptionHandle>;
696
+
697
+ largeObject(oid?: number | undefined, /** @default 0x00020000 | 0x00040000 */ mode?: number | undefined): Promise<LargeObject>;
698
+
699
+ begin<T>(cb: (sql: TransactionSql<TTypes>) => T | Promise<T>): Promise<UnwrapPromiseArray<T>>;
700
+ begin<T>(options: string, cb: (sql: TransactionSql<TTypes>) => T | Promise<T>): Promise<UnwrapPromiseArray<T>>;
701
+
702
+ array<T extends SerializableParameter<TTypes[keyof TTypes]>[] = SerializableParameter<TTypes[keyof TTypes]>[]>(value: T, type?: number | undefined): ArrayParameter<T>;
703
+ file<T extends readonly any[] = Row[]>(path: string | Buffer | URL | number, options?: { cache?: boolean | undefined } | undefined): PendingQuery<T>;
704
+ file<T extends readonly any[] = Row[]>(path: string | Buffer | URL | number, args: (ParameterOrJSON<TTypes[keyof TTypes]>)[], options?: { cache?: boolean | undefined } | undefined): PendingQuery<T>;
705
+ json(value: JSONValue): Parameter;
706
+
707
+ reserve(): Promise<ReservedSql<TTypes>>
708
+ }
709
+
710
+ interface UnsafeQueryOptions {
711
+ /**
712
+ * When executes query as prepared statement.
713
+ * @default false
714
+ */
715
+ prepare?: boolean | undefined;
716
+ }
717
+
718
+ interface TransactionSql<TTypes extends Record<string, unknown> = {}> extends Omit<Sql<TTypes>,
719
+ 'parameters' |
720
+ 'largeObject' |
721
+ 'subscribe' |
722
+ 'CLOSE' |
723
+ 'END' |
724
+ 'PostgresError' |
725
+ 'options' |
726
+ 'reserve' |
727
+ 'listen' |
728
+ 'begin' |
729
+ 'close' |
730
+ 'end'
731
+ > {
732
+ savepoint<T>(cb: (sql: TransactionSql<TTypes>) => T | Promise<T>): Promise<UnwrapPromiseArray<T>>;
733
+ savepoint<T>(name: string, cb: (sql: TransactionSql<TTypes>) => T | Promise<T>): Promise<UnwrapPromiseArray<T>>;
734
+
735
+ prepare<T>(name: string): Promise<UnwrapPromiseArray<T>>;
736
+ }
737
+
738
+ interface ReservedSql<TTypes extends Record<string, unknown> = {}> extends Sql<TTypes> {
739
+ release(): void;
740
+ }
741
+ }
742
+
743
+ export = postgres;