@prisma/adapter-pg 7.10.1 → 7.11.0-dev.10
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.
- package/dist/index.d.mts +12 -2
- package/dist/index.d.ts +12 -2
- package/dist/index.js +105 -11
- package/dist/index.mjs +105 -11
- package/package.json +4 -5
package/dist/index.d.mts
CHANGED
|
@@ -9,10 +9,12 @@ import type { SqlResultSet } from '@prisma/driver-adapter-utils';
|
|
|
9
9
|
import type { Transaction } from '@prisma/driver-adapter-utils';
|
|
10
10
|
|
|
11
11
|
declare class PgQueryable<ClientT extends StdClient | TransactionClient> implements SqlQueryable {
|
|
12
|
+
#private;
|
|
12
13
|
protected readonly client: ClientT;
|
|
13
14
|
protected readonly pgOptions?: PrismaPgOptions | undefined;
|
|
14
15
|
readonly provider = "postgres";
|
|
15
16
|
readonly adapterName: string;
|
|
17
|
+
protected readonly serializeQueries: boolean;
|
|
16
18
|
constructor(client: ClientT, pgOptions?: PrismaPgOptions | undefined);
|
|
17
19
|
/**
|
|
18
20
|
* Execute a query given as SQL, interpolating the given parameters.
|
|
@@ -29,7 +31,8 @@ declare class PgQueryable<ClientT extends StdClient | TransactionClient> impleme
|
|
|
29
31
|
* Should the query fail due to a connection error, the connection is
|
|
30
32
|
* marked as unhealthy.
|
|
31
33
|
*/
|
|
32
|
-
|
|
34
|
+
protected performIO(query: SqlQuery): Promise<pg.QueryArrayResult<any>>;
|
|
35
|
+
protected sendQuery(query: SqlQuery): Promise<pg.QueryArrayResult<any>>;
|
|
33
36
|
protected onError(error: unknown): never;
|
|
34
37
|
}
|
|
35
38
|
|
|
@@ -47,6 +50,7 @@ export declare class PrismaPg implements SqlMigrationAwareDriverAdapterFactory {
|
|
|
47
50
|
declare class PrismaPgAdapter extends PgQueryable<StdClient> implements SqlDriverAdapter {
|
|
48
51
|
protected readonly pgOptions?: PrismaPgOptions | undefined;
|
|
49
52
|
private readonly release?;
|
|
53
|
+
protected readonly serializeQueries = false;
|
|
50
54
|
constructor(client: StdClient, pgOptions?: PrismaPgOptions | undefined, release?: (() => Promise<void>) | undefined);
|
|
51
55
|
startTransaction(isolationLevel?: IsolationLevel): Promise<Transaction>;
|
|
52
56
|
executeScript(script: string): Promise<void>;
|
|
@@ -56,7 +60,13 @@ declare class PrismaPgAdapter extends PgQueryable<StdClient> implements SqlDrive
|
|
|
56
60
|
}
|
|
57
61
|
|
|
58
62
|
declare type PrismaPgOptions = {
|
|
59
|
-
/**
|
|
63
|
+
/**
|
|
64
|
+
* The name of the schema to use in generated queries. Raw queries are not affected: they resolve
|
|
65
|
+
* unqualified names through the connection's `search_path`. Qualify the name in raw SQL
|
|
66
|
+
* (`"mySchema"."User"`), or set the search path on the database role
|
|
67
|
+
* (`ALTER ROLE ... SET search_path = ...`). The adapter does not set it itself, because behind a
|
|
68
|
+
* connection pooler in transaction mode a session setting is shared with the pooler's other clients.
|
|
69
|
+
*/
|
|
60
70
|
schema?: string;
|
|
61
71
|
/**
|
|
62
72
|
* Whether to call `pool.end()` on an externally provided pool when the adapter is disposed.
|
package/dist/index.d.ts
CHANGED
|
@@ -9,10 +9,12 @@ import type { SqlResultSet } from '@prisma/driver-adapter-utils';
|
|
|
9
9
|
import type { Transaction } from '@prisma/driver-adapter-utils';
|
|
10
10
|
|
|
11
11
|
declare class PgQueryable<ClientT extends StdClient | TransactionClient> implements SqlQueryable {
|
|
12
|
+
#private;
|
|
12
13
|
protected readonly client: ClientT;
|
|
13
14
|
protected readonly pgOptions?: PrismaPgOptions | undefined;
|
|
14
15
|
readonly provider = "postgres";
|
|
15
16
|
readonly adapterName: string;
|
|
17
|
+
protected readonly serializeQueries: boolean;
|
|
16
18
|
constructor(client: ClientT, pgOptions?: PrismaPgOptions | undefined);
|
|
17
19
|
/**
|
|
18
20
|
* Execute a query given as SQL, interpolating the given parameters.
|
|
@@ -29,7 +31,8 @@ declare class PgQueryable<ClientT extends StdClient | TransactionClient> impleme
|
|
|
29
31
|
* Should the query fail due to a connection error, the connection is
|
|
30
32
|
* marked as unhealthy.
|
|
31
33
|
*/
|
|
32
|
-
|
|
34
|
+
protected performIO(query: SqlQuery): Promise<pg.QueryArrayResult<any>>;
|
|
35
|
+
protected sendQuery(query: SqlQuery): Promise<pg.QueryArrayResult<any>>;
|
|
33
36
|
protected onError(error: unknown): never;
|
|
34
37
|
}
|
|
35
38
|
|
|
@@ -47,6 +50,7 @@ export declare class PrismaPg implements SqlMigrationAwareDriverAdapterFactory {
|
|
|
47
50
|
declare class PrismaPgAdapter extends PgQueryable<StdClient> implements SqlDriverAdapter {
|
|
48
51
|
protected readonly pgOptions?: PrismaPgOptions | undefined;
|
|
49
52
|
private readonly release?;
|
|
53
|
+
protected readonly serializeQueries = false;
|
|
50
54
|
constructor(client: StdClient, pgOptions?: PrismaPgOptions | undefined, release?: (() => Promise<void>) | undefined);
|
|
51
55
|
startTransaction(isolationLevel?: IsolationLevel): Promise<Transaction>;
|
|
52
56
|
executeScript(script: string): Promise<void>;
|
|
@@ -56,7 +60,13 @@ declare class PrismaPgAdapter extends PgQueryable<StdClient> implements SqlDrive
|
|
|
56
60
|
}
|
|
57
61
|
|
|
58
62
|
declare type PrismaPgOptions = {
|
|
59
|
-
/**
|
|
63
|
+
/**
|
|
64
|
+
* The name of the schema to use in generated queries. Raw queries are not affected: they resolve
|
|
65
|
+
* unqualified names through the connection's `search_path`. Qualify the name in raw SQL
|
|
66
|
+
* (`"mySchema"."User"`), or set the search path on the database role
|
|
67
|
+
* (`ALTER ROLE ... SET search_path = ...`). The adapter does not set it itself, because behind a
|
|
68
|
+
* connection pooler in transaction mode a session setting is shared with the pooler's other clients.
|
|
69
|
+
*/
|
|
60
70
|
schema?: string;
|
|
61
71
|
/**
|
|
62
72
|
* Whether to call `pool.end()` on an externally provided pool when the adapter is disposed.
|
package/dist/index.js
CHANGED
|
@@ -75,6 +75,7 @@ var ArrayColumnType = {
|
|
|
75
75
|
TEXT_ARRAY: 1009,
|
|
76
76
|
TIMESTAMP_ARRAY: 1115,
|
|
77
77
|
TIMESTAMPTZ_ARRAY: 1185,
|
|
78
|
+
TIMETZ_ARRAY: 1270,
|
|
78
79
|
TIME_ARRAY: 1183,
|
|
79
80
|
UUID_ARRAY: 2951,
|
|
80
81
|
VARBIT_ARRAY: 1563,
|
|
@@ -273,6 +274,7 @@ function fieldToColumnType(fieldTypeId) {
|
|
|
273
274
|
case ArrayColumnType.DATE_ARRAY:
|
|
274
275
|
return import_driver_adapter_utils.ColumnTypeEnum.DateArray;
|
|
275
276
|
case ArrayColumnType.TIME_ARRAY:
|
|
277
|
+
case ArrayColumnType.TIMETZ_ARRAY:
|
|
276
278
|
return import_driver_adapter_utils.ColumnTypeEnum.TimeArray;
|
|
277
279
|
case ArrayColumnType.TIMESTAMP_ARRAY:
|
|
278
280
|
return import_driver_adapter_utils.ColumnTypeEnum.DateTimeArray;
|
|
@@ -301,23 +303,41 @@ function normalize_array(element_normalizer) {
|
|
|
301
303
|
function normalize_numeric(numeric) {
|
|
302
304
|
return numeric;
|
|
303
305
|
}
|
|
306
|
+
function expandYear(value) {
|
|
307
|
+
return value.replace(/^(\d{5,})(?=-)/, (_, year) => `+${year.padStart(6, "0")}`);
|
|
308
|
+
}
|
|
304
309
|
function normalize_date(date) {
|
|
305
|
-
return date;
|
|
310
|
+
return expandYear(date);
|
|
306
311
|
}
|
|
307
312
|
function normalize_timestamp(time) {
|
|
308
|
-
return `${time.replace(" ", "T")}+00:00
|
|
313
|
+
return expandYear(`${time.replace(" ", "T")}+00:00`);
|
|
309
314
|
}
|
|
310
315
|
function normalize_timestamptz(time) {
|
|
311
|
-
return time.replace(" ", "T").replace(/[+-]\d{2}(:\d{2})?$/, "+00:00");
|
|
316
|
+
return expandYear(time.replace(" ", "T").replace(/[+-]\d{2}(:\d{2})?$/, "+00:00"));
|
|
312
317
|
}
|
|
313
318
|
function normalize_time(time) {
|
|
314
319
|
return time;
|
|
315
320
|
}
|
|
316
321
|
function normalize_timez(time) {
|
|
317
|
-
|
|
322
|
+
const match = time.match(/^(\d{2}):(\d{2}):(\d{2})(\.\d+)?([+-])(\d{2})(?::(\d{2}))?(?::(\d{2}))?$/);
|
|
323
|
+
if (!match) return time;
|
|
324
|
+
const [, h, m, s, fraction = "", sign, oh, om = "0", os = "0"] = match;
|
|
325
|
+
const offset = (sign === "+" ? 1 : -1) * (Number(oh) * 3600 + Number(om) * 60 + Number(os));
|
|
326
|
+
if (offset === 0) return `${h}:${m}:${s}${fraction}`;
|
|
327
|
+
const seconds = ((Number(h) * 3600 + Number(m) * 60 + Number(s) - offset) % 86400 + 86400) % 86400;
|
|
328
|
+
const pad = (n) => String(n).padStart(2, "0");
|
|
329
|
+
return `${pad(Math.floor(seconds / 3600))}:${pad(Math.floor(seconds / 60) % 60)}:${pad(seconds % 60)}${fraction}`;
|
|
318
330
|
}
|
|
331
|
+
var SUPPORTED_MONEY_FORMAT = /^(?:(-)[\p{L}\p{Sc}]+|[\p{L}\p{Sc}]+(-)?)(\d{1,3}(?:,\d{3})*)(\.(?!\d{3}$)\d+)?$/u;
|
|
319
332
|
function normalize_money(money) {
|
|
320
|
-
|
|
333
|
+
const match = SUPPORTED_MONEY_FORMAT.exec(money);
|
|
334
|
+
if (match === null) {
|
|
335
|
+
throw new Error(
|
|
336
|
+
`Unsupported money format "${money}": expected a currency symbol directly followed by an amount with "," thousands separators and a "." decimal point, such as -\xA31,234.50`
|
|
337
|
+
);
|
|
338
|
+
}
|
|
339
|
+
const [, signBeforeSymbol = "", signAfterSymbol = "", integer, fraction = ""] = match;
|
|
340
|
+
return `${signBeforeSymbol}${signAfterSymbol}${integer.replaceAll(",", "")}${fraction}`;
|
|
321
341
|
}
|
|
322
342
|
function normalize_xml(xml) {
|
|
323
343
|
return xml;
|
|
@@ -339,6 +359,7 @@ var customParsers = {
|
|
|
339
359
|
[ScalarColumnType.TIME]: normalize_time,
|
|
340
360
|
[ArrayColumnType.TIME_ARRAY]: normalize_array(normalize_time),
|
|
341
361
|
[ScalarColumnType.TIMETZ]: normalize_timez,
|
|
362
|
+
[ArrayColumnType.TIMETZ_ARRAY]: normalize_array(normalize_timez),
|
|
342
363
|
[ScalarColumnType.DATE]: normalize_date,
|
|
343
364
|
[ArrayColumnType.DATE_ARRAY]: normalize_array(normalize_date),
|
|
344
365
|
[ScalarColumnType.TIMESTAMP]: normalize_timestamp,
|
|
@@ -370,8 +391,9 @@ function mapArg(arg, argType) {
|
|
|
370
391
|
if (arg instanceof Date) {
|
|
371
392
|
switch (argType.dbType) {
|
|
372
393
|
case "TIME":
|
|
373
|
-
case "TIMETZ":
|
|
374
394
|
return formatTime(arg);
|
|
395
|
+
case "TIMETZ":
|
|
396
|
+
return formatTime(arg) + "+00";
|
|
375
397
|
case "DATE":
|
|
376
398
|
return formatDate(arg);
|
|
377
399
|
default:
|
|
@@ -615,6 +637,13 @@ function isTlsError(error) {
|
|
|
615
637
|
// src/pg.ts
|
|
616
638
|
var types2 = import_pg2.default.types;
|
|
617
639
|
var debug = (0, import_driver_adapter_utils2.Debug)("prisma:driver-adapter:pg");
|
|
640
|
+
function isPgPoolLike(poolOrConfig) {
|
|
641
|
+
if (typeof poolOrConfig !== "object" || poolOrConfig === null) {
|
|
642
|
+
return false;
|
|
643
|
+
}
|
|
644
|
+
const candidate = poolOrConfig;
|
|
645
|
+
return typeof candidate.query === "function" && typeof candidate.connect === "function" && typeof candidate.end === "function" && typeof candidate.on === "function" && typeof candidate.removeListener === "function" && typeof candidate.options === "object" && candidate.options !== null;
|
|
646
|
+
}
|
|
618
647
|
var PgQueryable = class {
|
|
619
648
|
constructor(client, pgOptions) {
|
|
620
649
|
this.client = client;
|
|
@@ -622,6 +651,14 @@ var PgQueryable = class {
|
|
|
622
651
|
}
|
|
623
652
|
provider = "postgres";
|
|
624
653
|
adapterName = name;
|
|
654
|
+
// `pg.Client` and `pg.PoolClient` are single connections and don't support
|
|
655
|
+
// concurrent queries (deprecated in pg@8, an error in pg@9), so queries must
|
|
656
|
+
// be serialized. `pg.Pool` handles concurrency itself and must not be
|
|
657
|
+
// serialized, or the whole pool would be limited to one query at a time.
|
|
658
|
+
serializeQueries = true;
|
|
659
|
+
// Resolve-only lock: it tracks completion of the previous query and can
|
|
660
|
+
// never carry its error, so a failed query rejects only its own caller.
|
|
661
|
+
#queryLock = Promise.resolve();
|
|
625
662
|
/**
|
|
626
663
|
* Execute a query given as SQL, interpolating the given parameters.
|
|
627
664
|
*/
|
|
@@ -675,6 +712,20 @@ var PgQueryable = class {
|
|
|
675
712
|
* marked as unhealthy.
|
|
676
713
|
*/
|
|
677
714
|
async performIO(query) {
|
|
715
|
+
if (!this.serializeQueries) {
|
|
716
|
+
return this.sendQuery(query);
|
|
717
|
+
}
|
|
718
|
+
const previous = this.#queryLock;
|
|
719
|
+
let release;
|
|
720
|
+
this.#queryLock = new Promise((resolve) => release = resolve);
|
|
721
|
+
await previous;
|
|
722
|
+
try {
|
|
723
|
+
return await this.sendQuery(query);
|
|
724
|
+
} finally {
|
|
725
|
+
release();
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
async sendQuery(query) {
|
|
678
729
|
const { sql, args } = query;
|
|
679
730
|
const values = args.map((arg, i) => mapArg(arg, query.argTypes[i]));
|
|
680
731
|
try {
|
|
@@ -709,15 +760,57 @@ var PgTransaction = class extends PgQueryable {
|
|
|
709
760
|
this.pgOptions = pgOptions;
|
|
710
761
|
this.cleanup = cleanup;
|
|
711
762
|
}
|
|
763
|
+
closed = false;
|
|
764
|
+
runningStatements = 0;
|
|
765
|
+
async performIO(query) {
|
|
766
|
+
this.assertOpen();
|
|
767
|
+
this.runningStatements++;
|
|
768
|
+
try {
|
|
769
|
+
return await super.performIO(query);
|
|
770
|
+
} finally {
|
|
771
|
+
this.runningStatements--;
|
|
772
|
+
}
|
|
773
|
+
}
|
|
774
|
+
async sendQuery(query) {
|
|
775
|
+
this.assertOpen();
|
|
776
|
+
return super.sendQuery(query);
|
|
777
|
+
}
|
|
778
|
+
assertOpen() {
|
|
779
|
+
if (this.closed) {
|
|
780
|
+
throw new import_driver_adapter_utils2.DriverAdapterError({
|
|
781
|
+
kind: "TransactionAlreadyClosed",
|
|
782
|
+
cause: "The transaction has already been committed or rolled back"
|
|
783
|
+
});
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
/**
|
|
787
|
+
* Closes the transaction at most once. Once the pool has lent the client to
|
|
788
|
+
* a new owner, a second `release()` would corrupt the pool's bookkeeping, so
|
|
789
|
+
* it is skipped. A client with a statement still running is released with an
|
|
790
|
+
* error so the pool destroys it instead of lending out a busy connection.
|
|
791
|
+
*/
|
|
792
|
+
close() {
|
|
793
|
+
if (this.closed) {
|
|
794
|
+
return;
|
|
795
|
+
}
|
|
796
|
+
this.closed = true;
|
|
797
|
+
try {
|
|
798
|
+
this.cleanup?.();
|
|
799
|
+
} finally {
|
|
800
|
+
if (this.runningStatements > 0) {
|
|
801
|
+
this.client.release(new Error("Transaction closed with a statement still running"));
|
|
802
|
+
} else {
|
|
803
|
+
this.client.release();
|
|
804
|
+
}
|
|
805
|
+
}
|
|
806
|
+
}
|
|
712
807
|
async commit() {
|
|
713
808
|
debug(`[js::commit]`);
|
|
714
|
-
this.
|
|
715
|
-
this.client.release();
|
|
809
|
+
this.close();
|
|
716
810
|
}
|
|
717
811
|
async rollback() {
|
|
718
812
|
debug(`[js::rollback]`);
|
|
719
|
-
this.
|
|
720
|
-
this.client.release();
|
|
813
|
+
this.close();
|
|
721
814
|
}
|
|
722
815
|
async createSavepoint(name2) {
|
|
723
816
|
await this.executeRaw({ sql: `SAVEPOINT ${name2}`, args: [], argTypes: [] });
|
|
@@ -735,6 +828,7 @@ var PrismaPgAdapter = class extends PgQueryable {
|
|
|
735
828
|
this.pgOptions = pgOptions;
|
|
736
829
|
this.release = release;
|
|
737
830
|
}
|
|
831
|
+
serializeQueries = false;
|
|
738
832
|
async startTransaction(isolationLevel) {
|
|
739
833
|
const options = {
|
|
740
834
|
usePhantomQuery: false
|
|
@@ -793,7 +887,7 @@ var PrismaPgAdapter = class extends PgQueryable {
|
|
|
793
887
|
var PrismaPgAdapterFactory = class {
|
|
794
888
|
constructor(poolOrConfig, options) {
|
|
795
889
|
this.options = options;
|
|
796
|
-
if (poolOrConfig
|
|
890
|
+
if (isPgPoolLike(poolOrConfig)) {
|
|
797
891
|
this.externalPool = poolOrConfig;
|
|
798
892
|
this.config = poolOrConfig.options;
|
|
799
893
|
} else if (typeof poolOrConfig === "string") {
|
package/dist/index.mjs
CHANGED
|
@@ -39,6 +39,7 @@ var ArrayColumnType = {
|
|
|
39
39
|
TEXT_ARRAY: 1009,
|
|
40
40
|
TIMESTAMP_ARRAY: 1115,
|
|
41
41
|
TIMESTAMPTZ_ARRAY: 1185,
|
|
42
|
+
TIMETZ_ARRAY: 1270,
|
|
42
43
|
TIME_ARRAY: 1183,
|
|
43
44
|
UUID_ARRAY: 2951,
|
|
44
45
|
VARBIT_ARRAY: 1563,
|
|
@@ -237,6 +238,7 @@ function fieldToColumnType(fieldTypeId) {
|
|
|
237
238
|
case ArrayColumnType.DATE_ARRAY:
|
|
238
239
|
return ColumnTypeEnum.DateArray;
|
|
239
240
|
case ArrayColumnType.TIME_ARRAY:
|
|
241
|
+
case ArrayColumnType.TIMETZ_ARRAY:
|
|
240
242
|
return ColumnTypeEnum.TimeArray;
|
|
241
243
|
case ArrayColumnType.TIMESTAMP_ARRAY:
|
|
242
244
|
return ColumnTypeEnum.DateTimeArray;
|
|
@@ -265,23 +267,41 @@ function normalize_array(element_normalizer) {
|
|
|
265
267
|
function normalize_numeric(numeric) {
|
|
266
268
|
return numeric;
|
|
267
269
|
}
|
|
270
|
+
function expandYear(value) {
|
|
271
|
+
return value.replace(/^(\d{5,})(?=-)/, (_, year) => `+${year.padStart(6, "0")}`);
|
|
272
|
+
}
|
|
268
273
|
function normalize_date(date) {
|
|
269
|
-
return date;
|
|
274
|
+
return expandYear(date);
|
|
270
275
|
}
|
|
271
276
|
function normalize_timestamp(time) {
|
|
272
|
-
return `${time.replace(" ", "T")}+00:00
|
|
277
|
+
return expandYear(`${time.replace(" ", "T")}+00:00`);
|
|
273
278
|
}
|
|
274
279
|
function normalize_timestamptz(time) {
|
|
275
|
-
return time.replace(" ", "T").replace(/[+-]\d{2}(:\d{2})?$/, "+00:00");
|
|
280
|
+
return expandYear(time.replace(" ", "T").replace(/[+-]\d{2}(:\d{2})?$/, "+00:00"));
|
|
276
281
|
}
|
|
277
282
|
function normalize_time(time) {
|
|
278
283
|
return time;
|
|
279
284
|
}
|
|
280
285
|
function normalize_timez(time) {
|
|
281
|
-
|
|
286
|
+
const match = time.match(/^(\d{2}):(\d{2}):(\d{2})(\.\d+)?([+-])(\d{2})(?::(\d{2}))?(?::(\d{2}))?$/);
|
|
287
|
+
if (!match) return time;
|
|
288
|
+
const [, h, m, s, fraction = "", sign, oh, om = "0", os = "0"] = match;
|
|
289
|
+
const offset = (sign === "+" ? 1 : -1) * (Number(oh) * 3600 + Number(om) * 60 + Number(os));
|
|
290
|
+
if (offset === 0) return `${h}:${m}:${s}${fraction}`;
|
|
291
|
+
const seconds = ((Number(h) * 3600 + Number(m) * 60 + Number(s) - offset) % 86400 + 86400) % 86400;
|
|
292
|
+
const pad = (n) => String(n).padStart(2, "0");
|
|
293
|
+
return `${pad(Math.floor(seconds / 3600))}:${pad(Math.floor(seconds / 60) % 60)}:${pad(seconds % 60)}${fraction}`;
|
|
282
294
|
}
|
|
295
|
+
var SUPPORTED_MONEY_FORMAT = /^(?:(-)[\p{L}\p{Sc}]+|[\p{L}\p{Sc}]+(-)?)(\d{1,3}(?:,\d{3})*)(\.(?!\d{3}$)\d+)?$/u;
|
|
283
296
|
function normalize_money(money) {
|
|
284
|
-
|
|
297
|
+
const match = SUPPORTED_MONEY_FORMAT.exec(money);
|
|
298
|
+
if (match === null) {
|
|
299
|
+
throw new Error(
|
|
300
|
+
`Unsupported money format "${money}": expected a currency symbol directly followed by an amount with "," thousands separators and a "." decimal point, such as -\xA31,234.50`
|
|
301
|
+
);
|
|
302
|
+
}
|
|
303
|
+
const [, signBeforeSymbol = "", signAfterSymbol = "", integer, fraction = ""] = match;
|
|
304
|
+
return `${signBeforeSymbol}${signAfterSymbol}${integer.replaceAll(",", "")}${fraction}`;
|
|
285
305
|
}
|
|
286
306
|
function normalize_xml(xml) {
|
|
287
307
|
return xml;
|
|
@@ -303,6 +323,7 @@ var customParsers = {
|
|
|
303
323
|
[ScalarColumnType.TIME]: normalize_time,
|
|
304
324
|
[ArrayColumnType.TIME_ARRAY]: normalize_array(normalize_time),
|
|
305
325
|
[ScalarColumnType.TIMETZ]: normalize_timez,
|
|
326
|
+
[ArrayColumnType.TIMETZ_ARRAY]: normalize_array(normalize_timez),
|
|
306
327
|
[ScalarColumnType.DATE]: normalize_date,
|
|
307
328
|
[ArrayColumnType.DATE_ARRAY]: normalize_array(normalize_date),
|
|
308
329
|
[ScalarColumnType.TIMESTAMP]: normalize_timestamp,
|
|
@@ -334,8 +355,9 @@ function mapArg(arg, argType) {
|
|
|
334
355
|
if (arg instanceof Date) {
|
|
335
356
|
switch (argType.dbType) {
|
|
336
357
|
case "TIME":
|
|
337
|
-
case "TIMETZ":
|
|
338
358
|
return formatTime(arg);
|
|
359
|
+
case "TIMETZ":
|
|
360
|
+
return formatTime(arg) + "+00";
|
|
339
361
|
case "DATE":
|
|
340
362
|
return formatDate(arg);
|
|
341
363
|
default:
|
|
@@ -579,6 +601,13 @@ function isTlsError(error) {
|
|
|
579
601
|
// src/pg.ts
|
|
580
602
|
var types2 = pg2.types;
|
|
581
603
|
var debug = Debug("prisma:driver-adapter:pg");
|
|
604
|
+
function isPgPoolLike(poolOrConfig) {
|
|
605
|
+
if (typeof poolOrConfig !== "object" || poolOrConfig === null) {
|
|
606
|
+
return false;
|
|
607
|
+
}
|
|
608
|
+
const candidate = poolOrConfig;
|
|
609
|
+
return typeof candidate.query === "function" && typeof candidate.connect === "function" && typeof candidate.end === "function" && typeof candidate.on === "function" && typeof candidate.removeListener === "function" && typeof candidate.options === "object" && candidate.options !== null;
|
|
610
|
+
}
|
|
582
611
|
var PgQueryable = class {
|
|
583
612
|
constructor(client, pgOptions) {
|
|
584
613
|
this.client = client;
|
|
@@ -586,6 +615,14 @@ var PgQueryable = class {
|
|
|
586
615
|
}
|
|
587
616
|
provider = "postgres";
|
|
588
617
|
adapterName = name;
|
|
618
|
+
// `pg.Client` and `pg.PoolClient` are single connections and don't support
|
|
619
|
+
// concurrent queries (deprecated in pg@8, an error in pg@9), so queries must
|
|
620
|
+
// be serialized. `pg.Pool` handles concurrency itself and must not be
|
|
621
|
+
// serialized, or the whole pool would be limited to one query at a time.
|
|
622
|
+
serializeQueries = true;
|
|
623
|
+
// Resolve-only lock: it tracks completion of the previous query and can
|
|
624
|
+
// never carry its error, so a failed query rejects only its own caller.
|
|
625
|
+
#queryLock = Promise.resolve();
|
|
589
626
|
/**
|
|
590
627
|
* Execute a query given as SQL, interpolating the given parameters.
|
|
591
628
|
*/
|
|
@@ -639,6 +676,20 @@ var PgQueryable = class {
|
|
|
639
676
|
* marked as unhealthy.
|
|
640
677
|
*/
|
|
641
678
|
async performIO(query) {
|
|
679
|
+
if (!this.serializeQueries) {
|
|
680
|
+
return this.sendQuery(query);
|
|
681
|
+
}
|
|
682
|
+
const previous = this.#queryLock;
|
|
683
|
+
let release;
|
|
684
|
+
this.#queryLock = new Promise((resolve) => release = resolve);
|
|
685
|
+
await previous;
|
|
686
|
+
try {
|
|
687
|
+
return await this.sendQuery(query);
|
|
688
|
+
} finally {
|
|
689
|
+
release();
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
async sendQuery(query) {
|
|
642
693
|
const { sql, args } = query;
|
|
643
694
|
const values = args.map((arg, i) => mapArg(arg, query.argTypes[i]));
|
|
644
695
|
try {
|
|
@@ -673,15 +724,57 @@ var PgTransaction = class extends PgQueryable {
|
|
|
673
724
|
this.pgOptions = pgOptions;
|
|
674
725
|
this.cleanup = cleanup;
|
|
675
726
|
}
|
|
727
|
+
closed = false;
|
|
728
|
+
runningStatements = 0;
|
|
729
|
+
async performIO(query) {
|
|
730
|
+
this.assertOpen();
|
|
731
|
+
this.runningStatements++;
|
|
732
|
+
try {
|
|
733
|
+
return await super.performIO(query);
|
|
734
|
+
} finally {
|
|
735
|
+
this.runningStatements--;
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
async sendQuery(query) {
|
|
739
|
+
this.assertOpen();
|
|
740
|
+
return super.sendQuery(query);
|
|
741
|
+
}
|
|
742
|
+
assertOpen() {
|
|
743
|
+
if (this.closed) {
|
|
744
|
+
throw new DriverAdapterError({
|
|
745
|
+
kind: "TransactionAlreadyClosed",
|
|
746
|
+
cause: "The transaction has already been committed or rolled back"
|
|
747
|
+
});
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
/**
|
|
751
|
+
* Closes the transaction at most once. Once the pool has lent the client to
|
|
752
|
+
* a new owner, a second `release()` would corrupt the pool's bookkeeping, so
|
|
753
|
+
* it is skipped. A client with a statement still running is released with an
|
|
754
|
+
* error so the pool destroys it instead of lending out a busy connection.
|
|
755
|
+
*/
|
|
756
|
+
close() {
|
|
757
|
+
if (this.closed) {
|
|
758
|
+
return;
|
|
759
|
+
}
|
|
760
|
+
this.closed = true;
|
|
761
|
+
try {
|
|
762
|
+
this.cleanup?.();
|
|
763
|
+
} finally {
|
|
764
|
+
if (this.runningStatements > 0) {
|
|
765
|
+
this.client.release(new Error("Transaction closed with a statement still running"));
|
|
766
|
+
} else {
|
|
767
|
+
this.client.release();
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
}
|
|
676
771
|
async commit() {
|
|
677
772
|
debug(`[js::commit]`);
|
|
678
|
-
this.
|
|
679
|
-
this.client.release();
|
|
773
|
+
this.close();
|
|
680
774
|
}
|
|
681
775
|
async rollback() {
|
|
682
776
|
debug(`[js::rollback]`);
|
|
683
|
-
this.
|
|
684
|
-
this.client.release();
|
|
777
|
+
this.close();
|
|
685
778
|
}
|
|
686
779
|
async createSavepoint(name2) {
|
|
687
780
|
await this.executeRaw({ sql: `SAVEPOINT ${name2}`, args: [], argTypes: [] });
|
|
@@ -699,6 +792,7 @@ var PrismaPgAdapter = class extends PgQueryable {
|
|
|
699
792
|
this.pgOptions = pgOptions;
|
|
700
793
|
this.release = release;
|
|
701
794
|
}
|
|
795
|
+
serializeQueries = false;
|
|
702
796
|
async startTransaction(isolationLevel) {
|
|
703
797
|
const options = {
|
|
704
798
|
usePhantomQuery: false
|
|
@@ -757,7 +851,7 @@ var PrismaPgAdapter = class extends PgQueryable {
|
|
|
757
851
|
var PrismaPgAdapterFactory = class {
|
|
758
852
|
constructor(poolOrConfig, options) {
|
|
759
853
|
this.options = options;
|
|
760
|
-
if (poolOrConfig
|
|
854
|
+
if (isPgPoolLike(poolOrConfig)) {
|
|
761
855
|
this.externalPool = poolOrConfig;
|
|
762
856
|
this.config = poolOrConfig.options;
|
|
763
857
|
} else if (typeof poolOrConfig === "string") {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma/adapter-pg",
|
|
3
|
-
"version": "7.10
|
|
3
|
+
"version": "7.11.0-dev.10",
|
|
4
4
|
"description": "Prisma's driver adapter for \"pg\"",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -34,14 +34,13 @@
|
|
|
34
34
|
"pg": "^8.16.3",
|
|
35
35
|
"postgres-array": "3.0.4",
|
|
36
36
|
"@types/pg": "^8.16.0",
|
|
37
|
-
"@prisma/driver-adapter-utils": "7.10
|
|
37
|
+
"@prisma/driver-adapter-utils": "7.11.0-dev.10"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@prisma/debug": "7.10
|
|
40
|
+
"@prisma/debug": "7.11.0-dev.10"
|
|
41
41
|
},
|
|
42
42
|
"scripts": {
|
|
43
43
|
"dev": "DEV=true tsx helpers/build.ts",
|
|
44
|
-
"build": "tsx helpers/build.ts"
|
|
45
|
-
"test": "vitest run"
|
|
44
|
+
"build": "tsx helpers/build.ts"
|
|
46
45
|
}
|
|
47
46
|
}
|