@prisma/adapter-pg 7.11.0-dev.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 +9 -5
- package/dist/index.d.ts +9 -5
- package/dist/index.js +57 -41
- package/dist/index.mjs +57 -41
- package/package.json +3 -3
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.
|
|
@@ -30,6 +32,7 @@ declare class PgQueryable<ClientT extends StdClient | TransactionClient> impleme
|
|
|
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>;
|
|
@@ -57,11 +61,11 @@ declare class PrismaPgAdapter extends PgQueryable<StdClient> implements SqlDrive
|
|
|
57
61
|
|
|
58
62
|
declare type PrismaPgOptions = {
|
|
59
63
|
/**
|
|
60
|
-
* The name of the schema to use in generated queries.
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
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.
|
|
65
69
|
*/
|
|
66
70
|
schema?: string;
|
|
67
71
|
/**
|
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.
|
|
@@ -30,6 +32,7 @@ declare class PgQueryable<ClientT extends StdClient | TransactionClient> impleme
|
|
|
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>;
|
|
@@ -57,11 +61,11 @@ declare class PrismaPgAdapter extends PgQueryable<StdClient> implements SqlDrive
|
|
|
57
61
|
|
|
58
62
|
declare type PrismaPgOptions = {
|
|
59
63
|
/**
|
|
60
|
-
* The name of the schema to use in generated queries.
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
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.
|
|
65
69
|
*/
|
|
66
70
|
schema?: string;
|
|
67
71
|
/**
|
package/dist/index.js
CHANGED
|
@@ -303,14 +303,17 @@ function normalize_array(element_normalizer) {
|
|
|
303
303
|
function normalize_numeric(numeric) {
|
|
304
304
|
return numeric;
|
|
305
305
|
}
|
|
306
|
+
function expandYear(value) {
|
|
307
|
+
return value.replace(/^(\d{5,})(?=-)/, (_, year) => `+${year.padStart(6, "0")}`);
|
|
308
|
+
}
|
|
306
309
|
function normalize_date(date) {
|
|
307
|
-
return date;
|
|
310
|
+
return expandYear(date);
|
|
308
311
|
}
|
|
309
312
|
function normalize_timestamp(time) {
|
|
310
|
-
return `${time.replace(" ", "T")}+00:00
|
|
313
|
+
return expandYear(`${time.replace(" ", "T")}+00:00`);
|
|
311
314
|
}
|
|
312
315
|
function normalize_timestamptz(time) {
|
|
313
|
-
return time.replace(" ", "T").replace(/[+-]\d{2}(:\d{2})?$/, "+00:00");
|
|
316
|
+
return expandYear(time.replace(" ", "T").replace(/[+-]\d{2}(:\d{2})?$/, "+00:00"));
|
|
314
317
|
}
|
|
315
318
|
function normalize_time(time) {
|
|
316
319
|
return time;
|
|
@@ -325,13 +328,16 @@ function normalize_timez(time) {
|
|
|
325
328
|
const pad = (n) => String(n).padStart(2, "0");
|
|
326
329
|
return `${pad(Math.floor(seconds / 3600))}:${pad(Math.floor(seconds / 60) % 60)}:${pad(seconds % 60)}${fraction}`;
|
|
327
330
|
}
|
|
331
|
+
var SUPPORTED_MONEY_FORMAT = /^(?:(-)[\p{L}\p{Sc}]+|[\p{L}\p{Sc}]+(-)?)(\d{1,3}(?:,\d{3})*)(\.(?!\d{3}$)\d+)?$/u;
|
|
328
332
|
function normalize_money(money) {
|
|
329
|
-
|
|
333
|
+
const match = SUPPORTED_MONEY_FORMAT.exec(money);
|
|
334
|
+
if (match === null) {
|
|
330
335
|
throw new Error(
|
|
331
|
-
`Unsupported money format "${money}":
|
|
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`
|
|
332
337
|
);
|
|
333
338
|
}
|
|
334
|
-
|
|
339
|
+
const [, signBeforeSymbol = "", signAfterSymbol = "", integer, fraction = ""] = match;
|
|
340
|
+
return `${signBeforeSymbol}${signAfterSymbol}${integer.replaceAll(",", "")}${fraction}`;
|
|
335
341
|
}
|
|
336
342
|
function normalize_xml(xml) {
|
|
337
343
|
return xml;
|
|
@@ -631,6 +637,13 @@ function isTlsError(error) {
|
|
|
631
637
|
// src/pg.ts
|
|
632
638
|
var types2 = import_pg2.default.types;
|
|
633
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
|
+
}
|
|
634
647
|
var PgQueryable = class {
|
|
635
648
|
constructor(client, pgOptions) {
|
|
636
649
|
this.client = client;
|
|
@@ -638,6 +651,14 @@ var PgQueryable = class {
|
|
|
638
651
|
}
|
|
639
652
|
provider = "postgres";
|
|
640
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();
|
|
641
662
|
/**
|
|
642
663
|
* Execute a query given as SQL, interpolating the given parameters.
|
|
643
664
|
*/
|
|
@@ -691,6 +712,20 @@ var PgQueryable = class {
|
|
|
691
712
|
* marked as unhealthy.
|
|
692
713
|
*/
|
|
693
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) {
|
|
694
729
|
const { sql, args } = query;
|
|
695
730
|
const values = args.map((arg, i) => mapArg(arg, query.argTypes[i]));
|
|
696
731
|
try {
|
|
@@ -728,12 +763,7 @@ var PgTransaction = class extends PgQueryable {
|
|
|
728
763
|
closed = false;
|
|
729
764
|
runningStatements = 0;
|
|
730
765
|
async performIO(query) {
|
|
731
|
-
|
|
732
|
-
throw new import_driver_adapter_utils2.DriverAdapterError({
|
|
733
|
-
kind: "TransactionAlreadyClosed",
|
|
734
|
-
cause: "The transaction has already been committed or rolled back"
|
|
735
|
-
});
|
|
736
|
-
}
|
|
766
|
+
this.assertOpen();
|
|
737
767
|
this.runningStatements++;
|
|
738
768
|
try {
|
|
739
769
|
return await super.performIO(query);
|
|
@@ -741,6 +771,18 @@ var PgTransaction = class extends PgQueryable {
|
|
|
741
771
|
this.runningStatements--;
|
|
742
772
|
}
|
|
743
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
|
+
}
|
|
744
786
|
/**
|
|
745
787
|
* Closes the transaction at most once. Once the pool has lent the client to
|
|
746
788
|
* a new owner, a second `release()` would corrupt the pool's bookkeeping, so
|
|
@@ -786,6 +828,7 @@ var PrismaPgAdapter = class extends PgQueryable {
|
|
|
786
828
|
this.pgOptions = pgOptions;
|
|
787
829
|
this.release = release;
|
|
788
830
|
}
|
|
831
|
+
serializeQueries = false;
|
|
789
832
|
async startTransaction(isolationLevel) {
|
|
790
833
|
const options = {
|
|
791
834
|
usePhantomQuery: false
|
|
@@ -844,7 +887,7 @@ var PrismaPgAdapter = class extends PgQueryable {
|
|
|
844
887
|
var PrismaPgAdapterFactory = class {
|
|
845
888
|
constructor(poolOrConfig, options) {
|
|
846
889
|
this.options = options;
|
|
847
|
-
if (poolOrConfig
|
|
890
|
+
if (isPgPoolLike(poolOrConfig)) {
|
|
848
891
|
this.externalPool = poolOrConfig;
|
|
849
892
|
this.config = poolOrConfig.options;
|
|
850
893
|
} else if (typeof poolOrConfig === "string") {
|
|
@@ -860,12 +903,7 @@ var PrismaPgAdapterFactory = class {
|
|
|
860
903
|
config;
|
|
861
904
|
externalPool;
|
|
862
905
|
async connect() {
|
|
863
|
-
const client = this.externalPool ?? new import_pg2.default.Pool(
|
|
864
|
-
if (this.externalPool !== null && this.options?.schema !== void 0) {
|
|
865
|
-
debug(
|
|
866
|
-
`The search path is not set on externally provided pools, schema "${this.options.schema}" is only used for generated queries. Set the search path on the pool itself if raw queries need it.`
|
|
867
|
-
);
|
|
868
|
-
}
|
|
906
|
+
const client = this.externalPool ?? new import_pg2.default.Pool(this.config);
|
|
869
907
|
const onIdleClientError = (err) => {
|
|
870
908
|
debug(`Error from idle pool client: ${err.message} %O`, err);
|
|
871
909
|
this.options?.onPoolError?.(err);
|
|
@@ -895,28 +933,6 @@ var PrismaPgAdapterFactory = class {
|
|
|
895
933
|
});
|
|
896
934
|
}
|
|
897
935
|
};
|
|
898
|
-
function withSearchPath(config, schema) {
|
|
899
|
-
if (schema === void 0 || setsSearchPath(config.options)) {
|
|
900
|
-
return config;
|
|
901
|
-
}
|
|
902
|
-
const searchPath = `-c search_path=${escapeOptionValue(quoteIdentifierIfNeeded(schema))},public`;
|
|
903
|
-
return {
|
|
904
|
-
...config,
|
|
905
|
-
options: config.options ? `${config.options} ${searchPath}` : searchPath
|
|
906
|
-
};
|
|
907
|
-
}
|
|
908
|
-
function setsSearchPath(options) {
|
|
909
|
-
return options !== void 0 && /(?:^|\s)(?:-c\s*|--)search[_-]path=/i.test(options);
|
|
910
|
-
}
|
|
911
|
-
function quoteIdentifierIfNeeded(name2) {
|
|
912
|
-
if (/^[a-z_][a-z0-9_$]*$/.test(name2)) {
|
|
913
|
-
return name2;
|
|
914
|
-
}
|
|
915
|
-
return `"${name2.replaceAll('"', '""')}"`;
|
|
916
|
-
}
|
|
917
|
-
function escapeOptionValue(value) {
|
|
918
|
-
return value.replace(/[\\\s]/g, (char) => `\\${char}`);
|
|
919
|
-
}
|
|
920
936
|
// Annotate the CommonJS export names for ESM import in node:
|
|
921
937
|
0 && (module.exports = {
|
|
922
938
|
PrismaPg
|
package/dist/index.mjs
CHANGED
|
@@ -267,14 +267,17 @@ function normalize_array(element_normalizer) {
|
|
|
267
267
|
function normalize_numeric(numeric) {
|
|
268
268
|
return numeric;
|
|
269
269
|
}
|
|
270
|
+
function expandYear(value) {
|
|
271
|
+
return value.replace(/^(\d{5,})(?=-)/, (_, year) => `+${year.padStart(6, "0")}`);
|
|
272
|
+
}
|
|
270
273
|
function normalize_date(date) {
|
|
271
|
-
return date;
|
|
274
|
+
return expandYear(date);
|
|
272
275
|
}
|
|
273
276
|
function normalize_timestamp(time) {
|
|
274
|
-
return `${time.replace(" ", "T")}+00:00
|
|
277
|
+
return expandYear(`${time.replace(" ", "T")}+00:00`);
|
|
275
278
|
}
|
|
276
279
|
function normalize_timestamptz(time) {
|
|
277
|
-
return time.replace(" ", "T").replace(/[+-]\d{2}(:\d{2})?$/, "+00:00");
|
|
280
|
+
return expandYear(time.replace(" ", "T").replace(/[+-]\d{2}(:\d{2})?$/, "+00:00"));
|
|
278
281
|
}
|
|
279
282
|
function normalize_time(time) {
|
|
280
283
|
return time;
|
|
@@ -289,13 +292,16 @@ function normalize_timez(time) {
|
|
|
289
292
|
const pad = (n) => String(n).padStart(2, "0");
|
|
290
293
|
return `${pad(Math.floor(seconds / 3600))}:${pad(Math.floor(seconds / 60) % 60)}:${pad(seconds % 60)}${fraction}`;
|
|
291
294
|
}
|
|
295
|
+
var SUPPORTED_MONEY_FORMAT = /^(?:(-)[\p{L}\p{Sc}]+|[\p{L}\p{Sc}]+(-)?)(\d{1,3}(?:,\d{3})*)(\.(?!\d{3}$)\d+)?$/u;
|
|
292
296
|
function normalize_money(money) {
|
|
293
|
-
|
|
297
|
+
const match = SUPPORTED_MONEY_FORMAT.exec(money);
|
|
298
|
+
if (match === null) {
|
|
294
299
|
throw new Error(
|
|
295
|
-
`Unsupported money format "${money}":
|
|
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`
|
|
296
301
|
);
|
|
297
302
|
}
|
|
298
|
-
|
|
303
|
+
const [, signBeforeSymbol = "", signAfterSymbol = "", integer, fraction = ""] = match;
|
|
304
|
+
return `${signBeforeSymbol}${signAfterSymbol}${integer.replaceAll(",", "")}${fraction}`;
|
|
299
305
|
}
|
|
300
306
|
function normalize_xml(xml) {
|
|
301
307
|
return xml;
|
|
@@ -595,6 +601,13 @@ function isTlsError(error) {
|
|
|
595
601
|
// src/pg.ts
|
|
596
602
|
var types2 = pg2.types;
|
|
597
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
|
+
}
|
|
598
611
|
var PgQueryable = class {
|
|
599
612
|
constructor(client, pgOptions) {
|
|
600
613
|
this.client = client;
|
|
@@ -602,6 +615,14 @@ var PgQueryable = class {
|
|
|
602
615
|
}
|
|
603
616
|
provider = "postgres";
|
|
604
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();
|
|
605
626
|
/**
|
|
606
627
|
* Execute a query given as SQL, interpolating the given parameters.
|
|
607
628
|
*/
|
|
@@ -655,6 +676,20 @@ var PgQueryable = class {
|
|
|
655
676
|
* marked as unhealthy.
|
|
656
677
|
*/
|
|
657
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) {
|
|
658
693
|
const { sql, args } = query;
|
|
659
694
|
const values = args.map((arg, i) => mapArg(arg, query.argTypes[i]));
|
|
660
695
|
try {
|
|
@@ -692,12 +727,7 @@ var PgTransaction = class extends PgQueryable {
|
|
|
692
727
|
closed = false;
|
|
693
728
|
runningStatements = 0;
|
|
694
729
|
async performIO(query) {
|
|
695
|
-
|
|
696
|
-
throw new DriverAdapterError({
|
|
697
|
-
kind: "TransactionAlreadyClosed",
|
|
698
|
-
cause: "The transaction has already been committed or rolled back"
|
|
699
|
-
});
|
|
700
|
-
}
|
|
730
|
+
this.assertOpen();
|
|
701
731
|
this.runningStatements++;
|
|
702
732
|
try {
|
|
703
733
|
return await super.performIO(query);
|
|
@@ -705,6 +735,18 @@ var PgTransaction = class extends PgQueryable {
|
|
|
705
735
|
this.runningStatements--;
|
|
706
736
|
}
|
|
707
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
|
+
}
|
|
708
750
|
/**
|
|
709
751
|
* Closes the transaction at most once. Once the pool has lent the client to
|
|
710
752
|
* a new owner, a second `release()` would corrupt the pool's bookkeeping, so
|
|
@@ -750,6 +792,7 @@ var PrismaPgAdapter = class extends PgQueryable {
|
|
|
750
792
|
this.pgOptions = pgOptions;
|
|
751
793
|
this.release = release;
|
|
752
794
|
}
|
|
795
|
+
serializeQueries = false;
|
|
753
796
|
async startTransaction(isolationLevel) {
|
|
754
797
|
const options = {
|
|
755
798
|
usePhantomQuery: false
|
|
@@ -808,7 +851,7 @@ var PrismaPgAdapter = class extends PgQueryable {
|
|
|
808
851
|
var PrismaPgAdapterFactory = class {
|
|
809
852
|
constructor(poolOrConfig, options) {
|
|
810
853
|
this.options = options;
|
|
811
|
-
if (poolOrConfig
|
|
854
|
+
if (isPgPoolLike(poolOrConfig)) {
|
|
812
855
|
this.externalPool = poolOrConfig;
|
|
813
856
|
this.config = poolOrConfig.options;
|
|
814
857
|
} else if (typeof poolOrConfig === "string") {
|
|
@@ -824,12 +867,7 @@ var PrismaPgAdapterFactory = class {
|
|
|
824
867
|
config;
|
|
825
868
|
externalPool;
|
|
826
869
|
async connect() {
|
|
827
|
-
const client = this.externalPool ?? new pg2.Pool(
|
|
828
|
-
if (this.externalPool !== null && this.options?.schema !== void 0) {
|
|
829
|
-
debug(
|
|
830
|
-
`The search path is not set on externally provided pools, schema "${this.options.schema}" is only used for generated queries. Set the search path on the pool itself if raw queries need it.`
|
|
831
|
-
);
|
|
832
|
-
}
|
|
870
|
+
const client = this.externalPool ?? new pg2.Pool(this.config);
|
|
833
871
|
const onIdleClientError = (err) => {
|
|
834
872
|
debug(`Error from idle pool client: ${err.message} %O`, err);
|
|
835
873
|
this.options?.onPoolError?.(err);
|
|
@@ -859,28 +897,6 @@ var PrismaPgAdapterFactory = class {
|
|
|
859
897
|
});
|
|
860
898
|
}
|
|
861
899
|
};
|
|
862
|
-
function withSearchPath(config, schema) {
|
|
863
|
-
if (schema === void 0 || setsSearchPath(config.options)) {
|
|
864
|
-
return config;
|
|
865
|
-
}
|
|
866
|
-
const searchPath = `-c search_path=${escapeOptionValue(quoteIdentifierIfNeeded(schema))},public`;
|
|
867
|
-
return {
|
|
868
|
-
...config,
|
|
869
|
-
options: config.options ? `${config.options} ${searchPath}` : searchPath
|
|
870
|
-
};
|
|
871
|
-
}
|
|
872
|
-
function setsSearchPath(options) {
|
|
873
|
-
return options !== void 0 && /(?:^|\s)(?:-c\s*|--)search[_-]path=/i.test(options);
|
|
874
|
-
}
|
|
875
|
-
function quoteIdentifierIfNeeded(name2) {
|
|
876
|
-
if (/^[a-z_][a-z0-9_$]*$/.test(name2)) {
|
|
877
|
-
return name2;
|
|
878
|
-
}
|
|
879
|
-
return `"${name2.replaceAll('"', '""')}"`;
|
|
880
|
-
}
|
|
881
|
-
function escapeOptionValue(value) {
|
|
882
|
-
return value.replace(/[\\\s]/g, (char) => `\\${char}`);
|
|
883
|
-
}
|
|
884
900
|
export {
|
|
885
901
|
PrismaPgAdapterFactory as PrismaPg
|
|
886
902
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma/adapter-pg",
|
|
3
|
-
"version": "7.11.0-dev.
|
|
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,10 +34,10 @@
|
|
|
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.11.0-dev.
|
|
37
|
+
"@prisma/driver-adapter-utils": "7.11.0-dev.10"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@prisma/debug": "7.11.0-dev.
|
|
40
|
+
"@prisma/debug": "7.11.0-dev.10"
|
|
41
41
|
},
|
|
42
42
|
"scripts": {
|
|
43
43
|
"dev": "DEV=true tsx helpers/build.ts",
|