@pgxsinkit/pgwasm 0.6.0-rc.2 → 0.6.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.
- package/NOTICE +1 -1
- package/dist/drizzle/codecs.d.ts.map +1 -1
- package/dist/drizzle/driver.d.ts.map +1 -1
- package/dist/drizzle/index.js +11 -33
- package/dist/drizzle/index.js.map +5 -5
- package/dist/drizzle/session.d.ts +1 -4
- package/dist/drizzle/session.d.ts.map +1 -1
- package/package.json +1 -1
- package/skills/opfs/SKILL.md +1 -1
- package/src/drizzle/codecs.ts +6 -21
- package/src/drizzle/driver.ts +1 -6
- package/src/drizzle/session.ts +3 -21
package/NOTICE
CHANGED
|
@@ -96,7 +96,7 @@ began as a copy of drizzle-orm's PGlite driver (`src/pglite/driver.ts`,
|
|
|
96
96
|
|
|
97
97
|
Changes: the session, transaction and database classes are rebound from PGlite to
|
|
98
98
|
pgwasm; the driver never constructs its own database; it has its own JIT capability
|
|
99
|
-
probe;
|
|
99
|
+
probe; its codecs and prepared-query session follow Drizzle RC6. The Apache-2.0 terms are
|
|
100
100
|
permanent. A copy of the Apache License 2.0 ships with this package in
|
|
101
101
|
LICENSE-APACHE-2.0 (from https://www.apache.org/licenses/LICENSE-2.0.txt).
|
|
102
102
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codecs.d.ts","sourceRoot":"","sources":["../../src/drizzle/codecs.ts"],"names":[],"mappings":"AAMA,OAAO,
|
|
1
|
+
{"version":3,"file":"codecs.d.ts","sourceRoot":"","sources":["../../src/drizzle/codecs.ts"],"names":[],"mappings":"AAMA,OAAO,EAUL,KAAK,QAAQ,EACd,MAAM,4BAA4B,CAAC;AAGpC,OAAO,EAAuD,KAAK,MAAM,EAAE,MAAM,UAAU,CAAC;AAE5F;;;;;GAKG;AACH,eAAO,MAAM,cAAc,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAS3D,CAAC;AAMF,iGAAiG;AACjG,eAAO,MAAM,YAAY,EAAE,QAwEzB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"driver.d.ts","sourceRoot":"","sources":["../../src/drizzle/driver.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"driver.d.ts","sourceRoot":"","sources":["../../src/drizzle/driver.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEhD,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAE/D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAE1E,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAE3C,OAAO,EAAiB,KAAK,oBAAoB,EAA4B,MAAM,WAAW,CAAC;AAE/F,qBAAa,cAAc,CAAC,UAAU,SAAS,YAAY,GAAG,cAAc,CAAE,SAAQ,eAAe,CACnG,oBAAoB,EACpB,UAAU,CACX;IACC,gBAAyB,CAAC,UAAU,CAAC,EAAE,MAAM,CAAoB;CAClE;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,OAAO,GAAG,SAAS,GAAG,OAAO,CASxE;AAqBD,+EAA+E;AAC/E,MAAM,MAAM,mBAAmB,CAC7B,UAAU,SAAS,YAAY,GAAG,cAAc,EAChD,OAAO,SAAS,MAAM,GAAG,MAAM,IAC7B,eAAe,CAAC,UAAU,CAAC,GAAG;IAAE,MAAM,EAAE,OAAO,CAAA;CAAE,CAAC;AAEtD,uFAAuF;AACvF,MAAM,MAAM,sBAAsB,GAAG,YAAY,GAAG,mBAAmB,GAAG,WAAW,CAAC;AAEtF;;;;GAIG;AACH,qBAAa,6BAA8B,SAAQ,WAAW;IACnD,IAAI,SAAmC;IAChD,QAAQ,CAAC,IAAI,EAAE,sBAAsB,CAAC;IAEtC,YAAY,IAAI,EAAE,sBAAsB,EAYvC;CACF;AAMD;;;;;GAKG;AACH,wBAAgB,OAAO,CAAC,UAAU,SAAS,YAAY,GAAG,cAAc,EAAE,OAAO,SAAS,MAAM,GAAG,MAAM,EACvG,MAAM,EAAE,OAAO,EACf,MAAM,CAAC,EAAE,eAAe,CAAC,UAAU,CAAC,GACnC,cAAc,CAAC,UAAU,CAAC,GAAG;IAAE,OAAO,EAAE,OAAO,CAAA;CAAE,CAAC;yBAHrC,OAAO;eA8BM,UAAU,SAAS,YAAY,4BACjD,eAAe,CAAC,UAAU,CAAC,KACnC,cAAc,CAAC,UAAU,CAAC,GAAG;QAAE,OAAO,EAAE,4CAA4C,CAAA;KAAE;;AA5BzF,wBAAgB,OAAO,CAAC,UAAU,SAAS,YAAY,GAAG,cAAc,EAAE,OAAO,SAAS,MAAM,GAAG,MAAM,EACvG,MAAM,EAAE,mBAAmB,CAAC,UAAU,EAAE,OAAO,CAAC,GAC/C,cAAc,CAAC,UAAU,CAAC,GAAG;IAAE,OAAO,EAAE,OAAO,CAAA;CAAE,CAAC"}
|
package/dist/drizzle/index.js
CHANGED
|
@@ -20,8 +20,6 @@ import { PgDialect } from "drizzle-orm/pg-core/dialect";
|
|
|
20
20
|
import { makePgArray, parsePgArray } from "drizzle-orm/pg-core/array";
|
|
21
21
|
import {
|
|
22
22
|
arrayCompatNormalize,
|
|
23
|
-
castToText,
|
|
24
|
-
castToTextArr,
|
|
25
23
|
genericPgCodecs,
|
|
26
24
|
makeGeometryArray,
|
|
27
25
|
parseGeometryArrayAndNormalize,
|
|
@@ -31,7 +29,7 @@ import {
|
|
|
31
29
|
textToDate,
|
|
32
30
|
textToDateWithTz
|
|
33
31
|
} from "drizzle-orm/pg-core/codecs";
|
|
34
|
-
import {
|
|
32
|
+
import { pgHexToUint8Array } from "drizzle-orm/utils";
|
|
35
33
|
var drizzleParsers = {
|
|
36
34
|
[TIMESTAMP]: (value) => value,
|
|
37
35
|
[TIMESTAMPTZ]: (value) => value,
|
|
@@ -46,27 +44,19 @@ var hasBuffer = typeof Buffer !== "undefined";
|
|
|
46
44
|
var normalizeNullableArray = (normalize) => arrayCompatNormalize((value) => value === null ? null : normalize(value));
|
|
47
45
|
var pgwasmCodecs = refineGenericPgCodecs({
|
|
48
46
|
bigint: {
|
|
49
|
-
cast: castToText,
|
|
50
|
-
castArray: castToTextArr,
|
|
51
47
|
normalize: BigInt,
|
|
52
48
|
normalizeArray: normalizeNullableArray(BigInt)
|
|
53
49
|
},
|
|
54
|
-
"bigint:string": {
|
|
50
|
+
"bigint:string": { normalize: String, normalizeArray: normalizeNullableArray(String) },
|
|
55
51
|
"bigint:number": {
|
|
56
|
-
cast: castToText,
|
|
57
|
-
castArray: castToTextArr,
|
|
58
52
|
normalize: Number,
|
|
59
53
|
normalizeArray: normalizeNullableArray(Number)
|
|
60
54
|
},
|
|
61
55
|
bigserial: {
|
|
62
56
|
normalize: BigInt,
|
|
63
|
-
normalizeArray: normalizeNullableArray(BigInt)
|
|
64
|
-
cast: castToText,
|
|
65
|
-
castArray: castToTextArr
|
|
57
|
+
normalizeArray: normalizeNullableArray(BigInt)
|
|
66
58
|
},
|
|
67
59
|
"bigserial:number": {
|
|
68
|
-
cast: castToText,
|
|
69
|
-
castArray: castToTextArr,
|
|
70
60
|
normalize: Number,
|
|
71
61
|
normalizeArray: normalizeNullableArray(Number)
|
|
72
62
|
},
|
|
@@ -78,20 +68,15 @@ var pgwasmCodecs = refineGenericPgCodecs({
|
|
|
78
68
|
normalize: (value) => Buffer.from(value),
|
|
79
69
|
normalizeArray: normalizeNullableArray((value) => Buffer.from(value))
|
|
80
70
|
} : {
|
|
81
|
-
normalizeInJson:
|
|
82
|
-
normalizeArrayInJson: arrayCompatNormalize(
|
|
71
|
+
normalizeInJson: pgHexToUint8Array,
|
|
72
|
+
normalizeArrayInJson: arrayCompatNormalize(pgHexToUint8Array)
|
|
83
73
|
},
|
|
84
|
-
|
|
85
|
-
date: { castArray: castToTextArr, normalize: textToDate, normalizeArray: normalizeNullableArray(textToDate) },
|
|
86
|
-
"date:string": { castArray: castToTextArr },
|
|
74
|
+
date: { normalize: textToDate, normalizeArray: normalizeNullableArray(textToDate) },
|
|
87
75
|
timestamp: {
|
|
88
|
-
castArray: castToTextArr,
|
|
89
76
|
normalize: textToDateWithTz,
|
|
90
77
|
normalizeArray: normalizeNullableArray(textToDateWithTz)
|
|
91
78
|
},
|
|
92
|
-
timestamptz: {
|
|
93
|
-
"timestamp:string": { castArray: castToTextArr },
|
|
94
|
-
"timestamptz:string": { castArray: castToTextArr },
|
|
79
|
+
timestamptz: { normalize: textToDate, normalizeArray: normalizeNullableArray(textToDate) },
|
|
95
80
|
json: { normalizeParam: (value) => typeof value === "object" ? value : JSON.stringify(value) },
|
|
96
81
|
jsonb: { normalizeParam: (value) => typeof value === "object" ? value : JSON.stringify(value) },
|
|
97
82
|
"geometry(point)": {
|
|
@@ -125,7 +110,6 @@ var pgwasmCodecs = refineGenericPgCodecs({
|
|
|
125
110
|
});
|
|
126
111
|
|
|
127
112
|
// packages/pgwasm/src/drizzle/session.ts
|
|
128
|
-
import { NoopCache } from "drizzle-orm/cache/core/cache";
|
|
129
113
|
import { entityKind } from "drizzle-orm/entity";
|
|
130
114
|
import { NoopLogger } from "drizzle-orm/logger";
|
|
131
115
|
import { PgAsyncPreparedQuery, PgAsyncSession, PgAsyncTransaction } from "drizzle-orm/pg-core/async/session";
|
|
@@ -136,24 +120,22 @@ class PgwasmSession extends PgAsyncSession {
|
|
|
136
120
|
#relations;
|
|
137
121
|
#options;
|
|
138
122
|
#logger;
|
|
139
|
-
#cache;
|
|
140
123
|
constructor(client, dialect, relations, options = {}) {
|
|
141
124
|
super(dialect);
|
|
142
125
|
this.#client = client;
|
|
143
126
|
this.#relations = relations;
|
|
144
127
|
this.#options = options;
|
|
145
128
|
this.#logger = options.logger ?? new NoopLogger;
|
|
146
|
-
this.#cache = options.cache ?? new NoopCache;
|
|
147
129
|
}
|
|
148
|
-
prepareQuery(query, mode, _name, mapper
|
|
130
|
+
prepareQuery(query, mode, _name, mapper) {
|
|
149
131
|
const executor = async (params) => {
|
|
150
132
|
const result = await this.#client.query(query.sql, params, {
|
|
151
133
|
rowMode: mode === "arrays" ? "array" : "object",
|
|
152
|
-
parsers: drizzleParsers
|
|
134
|
+
...mode === "call" ? {} : { parsers: drizzleParsers }
|
|
153
135
|
});
|
|
154
136
|
return mode === "raw" ? result : result.rows;
|
|
155
137
|
};
|
|
156
|
-
return new PgAsyncPreparedQuery(executor, query, mapper, mode, this.#logger, this.#
|
|
138
|
+
return new PgAsyncPreparedQuery(executor, query, mapper, mode, this.#logger, this.#options.paramsInErrors);
|
|
157
139
|
}
|
|
158
140
|
async transaction(transaction, config) {
|
|
159
141
|
const client = this.#client;
|
|
@@ -217,13 +199,9 @@ function construct(client, config = {}) {
|
|
|
217
199
|
const relations = config.relations ?? {};
|
|
218
200
|
const session = new PgwasmSession(client, dialect, relations, {
|
|
219
201
|
...logger ? { logger } : {},
|
|
220
|
-
...config.cache ? { cache: config.cache } : {},
|
|
221
202
|
...config.paramsInErrors !== undefined ? { paramsInErrors: config.paramsInErrors } : {}
|
|
222
203
|
});
|
|
223
204
|
const db = new PgwasmDatabase(dialect, session, relations);
|
|
224
|
-
const cache = config.cache;
|
|
225
|
-
if (cache)
|
|
226
|
-
db.$cache = { invalidate: (params) => cache.onMutate(params) };
|
|
227
205
|
return Object.assign(db, { $client: client });
|
|
228
206
|
}
|
|
229
207
|
|
|
@@ -273,4 +251,4 @@ export {
|
|
|
273
251
|
pgwasmCodecs
|
|
274
252
|
};
|
|
275
253
|
|
|
276
|
-
//# debugId=
|
|
254
|
+
//# debugId=EA54608DFCE3360564756E2164756E21
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/drizzle/driver.ts", "../src/drizzle/codecs.ts", "../src/drizzle/session.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"// Began as a copy of drizzle-orm's PGlite driver (`src/pglite/*.ts` at 1.0.0-rc.4; Apache-2.0, © Drizzle Team\n// and contributors — see NOTICE). Changes: rebound from PGlite to pgwasm; the driver never constructs its\n// own database; its own JIT capability probe
|
|
6
|
-
"// Began as a copy of drizzle-orm's PGlite driver (`src/pglite/*.ts` at 1.0.0-rc.4; Apache-2.0, © Drizzle Team\n// and contributors — see NOTICE). Changes: rebound from PGlite to pgwasm; the driver never constructs its\n// own database. Owned outright (ADR-0062).\n\nimport type { NormalizeCodec } from \"drizzle-orm/codecs\";\nimport { makePgArray, parsePgArray } from \"drizzle-orm/pg-core/array\";\nimport {\n arrayCompatNormalize,\n
|
|
7
|
-
"// Began as a copy of drizzle-orm's PGlite driver (`src/pglite/*.ts` at 1.0.0-rc.4; Apache-2.0, © Drizzle Team\n// and contributors — see NOTICE). Changes: rebound from PGlite to pgwasm; the driver never constructs its\n// own database. Owned outright (ADR-0062).\n\nimport
|
|
5
|
+
"// Began as a copy of drizzle-orm's PGlite driver (`src/pglite/*.ts` at 1.0.0-rc.4; Apache-2.0, © Drizzle Team\n// and contributors — see NOTICE). Changes: rebound from PGlite to pgwasm; the driver never constructs its\n// own database; its own JIT capability probe. Owned outright (ADR-0062).\n\nimport { entityKind } from \"drizzle-orm/entity\";\nimport { DefaultLogger, type Logger } from \"drizzle-orm/logger\";\nimport { PgAsyncDatabase } from \"drizzle-orm/pg-core/async/db\";\nimport { PgDialect } from \"drizzle-orm/pg-core/dialect\";\nimport type { DrizzlePgConfig } from \"drizzle-orm/pg-core/utils\";\nimport type { AnyRelations, EmptyRelations } from \"drizzle-orm/relations\";\n\nimport { PgwasmError } from \"../errors\";\nimport type { Pgwasm } from \"../interface\";\nimport { pgwasmCodecs } from \"./codecs\";\nimport { PgwasmSession, type PgwasmQueryResultHKT, type PgwasmSessionClient } from \"./session\";\n\nexport class PgwasmDatabase<TRelations extends AnyRelations = EmptyRelations> extends PgAsyncDatabase<\n PgwasmQueryResultHKT,\n TRelations\n> {\n static override readonly [entityKind]: string = \"PgwasmDatabase\";\n}\n\n/**\n * Whether to use JIT row mappers: only when asked for (`jit: true`) and `new Function` works here. JIT\n * mappers are compiled with it, and a strict content security policy (an MV3 extension page's) makes it\n * throw; the driver then falls back to the premade mappers instead of failing every query.\n */\nexport function jitMappersUsable(requested: boolean | undefined): boolean {\n if (requested !== true) return false;\n try {\n // oxlint-disable-next-line typescript/no-implied-eval -- the probe: does this context allow it at all\n const identity = new Function(\"input\", '\"use strict\"; return input;') as (input: unknown) => unknown;\n return identity(true) === true;\n } catch {\n return false;\n }\n}\n\nfunction construct<TRelations extends AnyRelations, TClient extends PgwasmSessionClient>(\n client: TClient,\n config: DrizzlePgConfig<TRelations> = {},\n): PgwasmDatabase<TRelations> & { $client: TClient } {\n const dialect = new PgDialect({\n useJitMappers: jitMappersUsable(config.jit),\n codecs: config.codecs ?? pgwasmCodecs,\n });\n const logger: Logger | undefined =\n config.logger === true ? new DefaultLogger() : config.logger === false ? undefined : config.logger;\n const relations = (config.relations ?? {}) as TRelations;\n const session = new PgwasmSession<TRelations>(client, dialect, relations, {\n ...(logger ? { logger } : {}),\n ...(config.paramsInErrors !== undefined ? { paramsInErrors: config.paramsInErrors } : {}),\n });\n const db = new PgwasmDatabase<TRelations>(dialect, session, relations);\n return Object.assign(db, { $client: client });\n}\n\n/** drizzle's object form: its config, with the pgwasm database as `client`. */\nexport type PgwasmDrizzleConfig<\n TRelations extends AnyRelations = EmptyRelations,\n TClient extends Pgwasm = Pgwasm,\n> = DrizzlePgConfig<TRelations> & { client: TClient };\n\n/** The form of a `drizzle()` call that would have the driver open its own database. */\nexport type UnsupportedDrizzleForm = \"connection\" | \"connection string\" | \"no client\";\n\n/**\n * A `drizzle()` call without a pgwasm database: `drizzle({ connection })`, `drizzle(\"…\")`, `drizzle()`, or a\n * `client` that is not a pgwasm database. The driver never opens its own database: create one with\n * `createPgwasm()` and pass it in.\n */\nexport class UnsupportedDrizzleConfigError extends PgwasmError {\n override name = \"UnsupportedDrizzleConfigError\";\n readonly form: UnsupportedDrizzleForm;\n\n constructor(form: UnsupportedDrizzleForm) {\n const given =\n form === \"connection\"\n ? \"drizzle({ connection })\"\n : form === \"connection string\"\n ? \"drizzle(connectionString)\"\n : \"a drizzle() call without a pgwasm database\";\n super(\n `@pgxsinkit/pgwasm/drizzle does not open its own database, so ${given} is not supported: create the ` +\n \"database with createPgwasm() and pass it as drizzle(pg, config) or drizzle({ client: pg, ...config }).\",\n );\n this.form = form;\n }\n}\n\nfunction isPgwasm(value: unknown): value is Pgwasm {\n return typeof value === \"object\" && value !== null && typeof (value as Partial<Pgwasm>).query === \"function\";\n}\n\n/**\n * A Drizzle database over a pgwasm database: `drizzle(pg, config)`, or drizzle's object form\n * `drizzle({ client: pg, ...config })`, which is the same thing. The driver never opens its own database, so\n * the forms that would (`{ connection }`, a connection string) are not accepted; at runtime they throw\n * {@link UnsupportedDrizzleConfigError}.\n */\nexport function drizzle<TRelations extends AnyRelations = EmptyRelations, TClient extends Pgwasm = Pgwasm>(\n client: TClient,\n config?: DrizzlePgConfig<TRelations>,\n): PgwasmDatabase<TRelations> & { $client: TClient };\nexport function drizzle<TRelations extends AnyRelations = EmptyRelations, TClient extends Pgwasm = Pgwasm>(\n config: PgwasmDrizzleConfig<TRelations, TClient>,\n): PgwasmDatabase<TRelations> & { $client: TClient };\nexport function drizzle<TRelations extends AnyRelations = EmptyRelations>(\n clientOrConfig: Pgwasm | PgwasmDrizzleConfig<TRelations>,\n config?: DrizzlePgConfig<TRelations>,\n): PgwasmDatabase<TRelations> & { $client: Pgwasm } {\n const given: unknown = clientOrConfig;\n if (isPgwasm(given)) return construct(given, config);\n if (typeof given === \"string\") throw new UnsupportedDrizzleConfigError(\"connection string\");\n if (typeof given === \"object\" && given !== null) {\n const { client, ...rest } = given as Partial<PgwasmDrizzleConfig<TRelations>> & { connection?: unknown };\n // A `connection` next to a pgwasm `client` is ignored, as drizzle's own drivers do.\n if (isPgwasm(client)) return construct(client, rest);\n if (client === undefined && \"connection\" in given) throw new UnsupportedDrizzleConfigError(\"connection\");\n }\n throw new UnsupportedDrizzleConfigError(\"no client\");\n}\n\nconst unavailable: PgwasmSessionClient = {\n query: () => {\n throw new Error(\"drizzle.mock() has no database: build queries with it, run them elsewhere.\");\n },\n};\n\n/** A Drizzle database with no database behind it, for building SQL (`.toSQL()`). */\ndrizzle.mock = function mock<TRelations extends AnyRelations = EmptyRelations>(\n config?: DrizzlePgConfig<TRelations>,\n): PgwasmDatabase<TRelations> & { $client: \"$client is not available on drizzle.mock()\" } {\n const db = construct(unavailable, config);\n return Object.assign(db, { $client: \"$client is not available on drizzle.mock()\" as const });\n};\n",
|
|
6
|
+
"// Began as a copy of drizzle-orm's PGlite driver (`src/pglite/*.ts` at 1.0.0-rc.4; Apache-2.0, © Drizzle Team\n// and contributors — see NOTICE). Changes: rebound from PGlite to pgwasm; the driver never constructs its\n// own database. Owned outright (ADR-0062).\n\nimport type { NormalizeCodec } from \"drizzle-orm/codecs\";\nimport { makePgArray, parsePgArray } from \"drizzle-orm/pg-core/array\";\nimport {\n arrayCompatNormalize,\n genericPgCodecs,\n makeGeometryArray,\n parseGeometryArrayAndNormalize,\n parseGeometryTuple,\n parseGeometryXY,\n refineGenericPgCodecs,\n textToDate,\n textToDateWithTz,\n type PgCodecs,\n} from \"drizzle-orm/pg-core/codecs\";\nimport { pgHexToUint8Array } from \"drizzle-orm/utils\";\n\nimport { arrayParser, DATE, INTERVAL, TIMESTAMP, TIMESTAMPTZ, type Parser } from \"../types\";\n\n/**\n * The identity parsers the driver passes with every query: these types reach drizzle as Postgres'\n * text, and drizzle's codecs turn them into values. Array parsers keep each element's text while\n * preserving PostgreSQL nulls and dimensions; the scalar Date parser must not run before Drizzle's\n * mode-specific normalizer. Numeric arrays use pgwasm's native precision-preserving parser.\n */\nexport const drizzleParsers: Readonly<Record<number, Parser>> = {\n [TIMESTAMP]: (value) => value,\n [TIMESTAMPTZ]: (value) => value,\n [INTERVAL]: (value) => value,\n [DATE]: (value) => value,\n 1115: (value) => arrayParser(value, undefined, 1115), // timestamp[]\n 1185: (value) => arrayParser(value, undefined, 1185), // timestamptz[]\n 1187: (value) => arrayParser(value, undefined, 1187), // interval[]\n 1182: (value) => arrayParser(value, undefined, 1182), // date[]\n};\n\nconst hasBuffer = typeof Buffer !== \"undefined\";\nconst normalizeNullableArray = (normalize: NormalizeCodec) =>\n arrayCompatNormalize((value) => (value === null ? null : normalize(value)));\n\n/** drizzle's codecs for pgwasm's value formats (the text protocol, pgwasm's default parsers). */\nexport const pgwasmCodecs: PgCodecs = refineGenericPgCodecs({\n bigint: {\n normalize: BigInt,\n normalizeArray: normalizeNullableArray(BigInt),\n },\n \"bigint:string\": { normalize: String, normalizeArray: normalizeNullableArray(String) },\n \"bigint:number\": {\n normalize: Number,\n normalizeArray: normalizeNullableArray(Number),\n },\n bigserial: {\n normalize: BigInt,\n normalizeArray: normalizeNullableArray(BigInt),\n },\n \"bigserial:number\": {\n normalize: Number,\n normalizeArray: normalizeNullableArray(Number),\n },\n \"numeric:number\": { normalize: Number, normalizeArray: normalizeNullableArray(Number) },\n \"numeric:bigint\": { normalize: BigInt, normalizeArray: normalizeNullableArray(BigInt) },\n bytea: hasBuffer\n ? {\n normalizeInJson: genericPgCodecs.bytea?.normalizeInJson,\n normalizeArrayInJson: genericPgCodecs.bytea?.normalizeArrayInJson,\n normalize: (value: Uint8Array) => Buffer.from(value),\n normalizeArray: normalizeNullableArray((value: Uint8Array) => Buffer.from(value)),\n }\n : {\n normalizeInJson: pgHexToUint8Array,\n normalizeArrayInJson: arrayCompatNormalize(pgHexToUint8Array),\n },\n date: { normalize: textToDate, normalizeArray: normalizeNullableArray(textToDate) },\n timestamp: {\n normalize: textToDateWithTz,\n normalizeArray: normalizeNullableArray(textToDateWithTz),\n },\n timestamptz: { normalize: textToDate, normalizeArray: normalizeNullableArray(textToDate) },\n json: { normalizeParam: (value: unknown) => (typeof value === \"object\" ? value : JSON.stringify(value)) },\n jsonb: { normalizeParam: (value: unknown) => (typeof value === \"object\" ? value : JSON.stringify(value)) },\n \"geometry(point)\": {\n normalizeArray: parseGeometryArrayAndNormalize(parseGeometryXY),\n castParam: (name: string) => `${name}::geometry`,\n castArrayParam: (name: string, _column: unknown, dimensions: number) =>\n `${name}::geometry${\"[]\".repeat(dimensions)}`,\n normalizeParamArray: makeGeometryArray,\n },\n \"geometry(point):tuple\": {\n normalizeArray: parseGeometryArrayAndNormalize(parseGeometryTuple),\n castParam: (name: string) => `${name}::geometry`,\n castArrayParam: (name: string, _column: unknown, dimensions: number) =>\n `${name}::geometry${\"[]\".repeat(dimensions)}`,\n normalizeParamArray: makeGeometryArray,\n },\n halfvec: {\n castParam: (name: string) => `${name}::halfvec`,\n castArrayParam: (name: string, _column: unknown, dimensions: number) =>\n `${name}::halfvec${\"[]\".repeat(dimensions)}`,\n // Codec callbacks receive array dimensions as their second argument, not a text delimiter.\n normalizeParamArray: (value) => makePgArray(value),\n },\n vector: {\n castParam: (name: string) => `${name}::vector`,\n castArrayParam: (name: string, _column: unknown, dimensions: number) => `${name}::vector${\"[]\".repeat(dimensions)}`,\n normalizeParamArray: (value) => makePgArray(value),\n },\n sparsevec: {\n normalizeArray: (value) => parsePgArray(value),\n castParam: (name: string) => `${name}::sparsevec`,\n castArrayParam: (name: string, _column: unknown, dimensions: number) =>\n `${name}::sparsevec${\"[]\".repeat(dimensions)}`,\n normalizeParamArray: (value) => makePgArray(value),\n },\n});\n",
|
|
7
|
+
"// Began as a copy of drizzle-orm's PGlite driver (`src/pglite/*.ts` at 1.0.0-rc.4; Apache-2.0, © Drizzle Team\n// and contributors — see NOTICE). Changes: rebound from PGlite to pgwasm; the driver never constructs its\n// own database. Owned outright (ADR-0062).\n\nimport { entityKind } from \"drizzle-orm/entity\";\nimport { NoopLogger, type Logger } from \"drizzle-orm/logger\";\nimport { PgAsyncPreparedQuery, PgAsyncSession, PgAsyncTransaction } from \"drizzle-orm/pg-core/async/session\";\nimport type { PgDialect } from \"drizzle-orm/pg-core/dialect\";\nimport type { PgQueryResultHKT, PgTransactionConfig, PreparedQueryConfig } from \"drizzle-orm/pg-core/session\";\nimport type { AnyRelations } from \"drizzle-orm/relations\";\nimport { sql, type Query } from \"drizzle-orm/sql/sql\";\nimport type { Assume } from \"drizzle-orm/utils\";\n\nimport type { Pgwasm, Results, Row, Transaction } from \"../interface\";\nimport { drizzleParsers } from \"./codecs\";\n\n/** What a session runs statements on: a database, or a transaction's handle. */\nexport type PgwasmSessionClient = Pick<Pgwasm, \"query\"> & Partial<Pick<Pgwasm, \"transaction\">>;\n\nexport interface PgwasmSessionOptions {\n logger?: Logger;\n paramsInErrors?: boolean;\n}\n\nexport interface PgwasmQueryResultHKT extends PgQueryResultHKT {\n type: Results<Assume<this[\"row\"], Row>>;\n}\n\nexport class PgwasmSession<TRelations extends AnyRelations> extends PgAsyncSession<PgwasmQueryResultHKT, TRelations> {\n static override readonly [entityKind]: string = \"PgwasmSession\";\n readonly #client: PgwasmSessionClient;\n readonly #relations: TRelations;\n readonly #options: PgwasmSessionOptions;\n readonly #logger: Logger;\n\n constructor(\n client: PgwasmSessionClient,\n dialect: PgDialect,\n relations: TRelations,\n options: PgwasmSessionOptions = {},\n ) {\n super(dialect);\n this.#client = client;\n this.#relations = relations;\n this.#options = options;\n this.#logger = options.logger ?? new NoopLogger();\n }\n\n prepareQuery<T extends PreparedQueryConfig = PreparedQueryConfig>(\n query: Query,\n mode: \"arrays\" | \"objects\" | \"raw\" | \"call\",\n _name: string | boolean,\n mapper: ((rows: unknown[]) => unknown) | undefined,\n ): PgAsyncPreparedQuery<T> {\n const executor = async (params?: unknown[]) => {\n const result = await this.#client.query(query.sql, params, {\n rowMode: mode === \"arrays\" ? \"array\" : \"object\",\n ...(mode === \"call\" ? {} : { parsers: drizzleParsers }),\n });\n return mode === \"raw\" ? result : result.rows;\n };\n return new PgAsyncPreparedQuery<T>(executor, query, mapper, mode, this.#logger, this.#options.paramsInErrors);\n }\n\n async transaction<T>(\n transaction: (tx: PgwasmTransaction<TRelations>) => Promise<T>,\n config?: PgTransactionConfig,\n ): Promise<T> {\n const client = this.#client;\n if (client.transaction === undefined) {\n throw new Error(\"A transaction's session cannot begin another transaction; nest with tx.transaction().\");\n }\n return await client.transaction(async (handle: Transaction) => {\n const session = new PgwasmSession(handle, this.dialect, this.#relations, this.#options);\n const tx = new PgwasmTransaction(this.dialect, session, this.#relations, undefined, false);\n if (config) await tx.setTransaction(config);\n return await transaction(tx);\n });\n }\n}\n\nexport class PgwasmTransaction<TRelations extends AnyRelations> extends PgAsyncTransaction<\n PgwasmQueryResultHKT,\n TRelations\n> {\n static override readonly [entityKind]: string = \"PgwasmTransaction\";\n readonly #dialect: PgDialect;\n readonly #session: PgwasmSession<TRelations>;\n\n constructor(\n dialect: PgDialect,\n session: PgwasmSession<TRelations>,\n relations: TRelations,\n nestedIndex: number | undefined,\n parseRqbJson: boolean | undefined,\n ) {\n super(dialect, session, relations, nestedIndex, parseRqbJson);\n this.#dialect = dialect;\n this.#session = session;\n }\n\n async transaction<T>(transaction: (tx: PgwasmTransaction<TRelations>) => Promise<T>): Promise<T> {\n const savepointName = `sp${this.nestedIndex + 1}`;\n const tx = new PgwasmTransaction(this.#dialect, this.#session, this._.relations, this.nestedIndex + 1, false);\n await tx.execute(sql.raw(`savepoint ${savepointName}`));\n try {\n const result = await transaction(tx);\n await tx.execute(sql.raw(`release savepoint ${savepointName}`));\n return result;\n } catch (error) {\n await tx.execute(sql.raw(`rollback to savepoint ${savepointName}`));\n throw error;\n }\n }\n}\n"
|
|
8
8
|
],
|
|
9
|
-
"mappings": ";;;;;;;;;;;;;
|
|
10
|
-
"debugId": "
|
|
9
|
+
"mappings": ";;;;;;;;;;;;;AAIA,uBAAS;AACT;AACA;AACA;;;ACFA;AACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAA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BAA8B,mBAAmB;AAAA,EAC1F,IAAI,OAAO,UAAU,YAAY,UAAU,MAAM;AAAA,IAC/C,QAAQ,WAAW,SAAS;AAAA,IAE5B,IAAI,SAAS,MAAM;AAAA,MAAG,OAAO,UAAU,QAAQ,IAAI;AAAA,IACnD,IAAI,WAAW,aAAa,gBAAgB;AAAA,MAAO,MAAM,IAAI,8BAA8B,YAAY;AAAA,EACzG;AAAA,EACA,MAAM,IAAI,8BAA8B,WAAW;AAAA;AAGrD,IAAM,cAAmC;AAAA,EACvC,OAAO,MAAM;AAAA,IACX,MAAM,IAAI,MAAM,4EAA4E;AAAA;AAEhG;AAGA,QAAQ,OAAO,SAAS,IAAsD,CAC5E,QACwF;AAAA,EACxF,MAAM,KAAK,UAAU,aAAa,MAAM;AAAA,EACxC,OAAO,OAAO,OAAO,IAAI,EAAE,SAAS,6CAAsD,CAAC;AAAA;",
|
|
10
|
+
"debugId": "EA54608DFCE3360564756E2164756E21",
|
|
11
11
|
"names": []
|
|
12
12
|
}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import type { Cache } from "drizzle-orm/cache/core/cache";
|
|
2
|
-
import type { QueryMetadata, WithCacheConfig } from "drizzle-orm/cache/core/types";
|
|
3
1
|
import { entityKind } from "drizzle-orm/entity";
|
|
4
2
|
import { type Logger } from "drizzle-orm/logger";
|
|
5
3
|
import { PgAsyncPreparedQuery, PgAsyncSession, PgAsyncTransaction } from "drizzle-orm/pg-core/async/session";
|
|
@@ -13,7 +11,6 @@ import type { Pgwasm, Results, Row } from "../interface";
|
|
|
13
11
|
export type PgwasmSessionClient = Pick<Pgwasm, "query"> & Partial<Pick<Pgwasm, "transaction">>;
|
|
14
12
|
export interface PgwasmSessionOptions {
|
|
15
13
|
logger?: Logger;
|
|
16
|
-
cache?: Cache;
|
|
17
14
|
paramsInErrors?: boolean;
|
|
18
15
|
}
|
|
19
16
|
export interface PgwasmQueryResultHKT extends PgQueryResultHKT {
|
|
@@ -23,7 +20,7 @@ export declare class PgwasmSession<TRelations extends AnyRelations> extends PgAs
|
|
|
23
20
|
#private;
|
|
24
21
|
static readonly [entityKind]: string;
|
|
25
22
|
constructor(client: PgwasmSessionClient, dialect: PgDialect, relations: TRelations, options?: PgwasmSessionOptions);
|
|
26
|
-
prepareQuery<T extends PreparedQueryConfig = PreparedQueryConfig>(query: Query, mode: "arrays" | "objects" | "raw", _name: string | boolean, mapper: ((rows: unknown[]) => unknown) | undefined
|
|
23
|
+
prepareQuery<T extends PreparedQueryConfig = PreparedQueryConfig>(query: Query, mode: "arrays" | "objects" | "raw" | "call", _name: string | boolean, mapper: ((rows: unknown[]) => unknown) | undefined): PgAsyncPreparedQuery<T>;
|
|
27
24
|
transaction<T>(transaction: (tx: PgwasmTransaction<TRelations>) => Promise<T>, config?: PgTransactionConfig): Promise<T>;
|
|
28
25
|
}
|
|
29
26
|
export declare class PgwasmTransaction<TRelations extends AnyRelations> extends PgAsyncTransaction<PgwasmQueryResultHKT, TRelations> {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../src/drizzle/session.ts"],"names":[],"mappings":"AAIA,OAAO,
|
|
1
|
+
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../src/drizzle/session.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAc,KAAK,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,EAAE,oBAAoB,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AAC7G,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,KAAK,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAC9G,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAO,KAAK,KAAK,EAAE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AAC,EAC9D,MAAM,CAAC,EAAE,mBAAmB,GAC3B,OAAO,CAAC,CAAC,CAAC,CAWZ;CACF;AAED,qBAAa,iBAAiB,CAAC,UAAU,SAAS,YAAY,CAAE,SAAQ,kBAAkB,CACxF,oBAAoB,EACpB,UAAU,CACX;;IACC,gBAAyB,CAAC,UAAU,CAAC,EAAE,MAAM,CAAuB;IAIpE,YACE,OAAO,EAAE,SAAS,EAClB,OAAO,EAAE,aAAa,CAAC,UAAU,CAAC,EAClC,SAAS,EAAE,UAAU,EACrB,WAAW,EAAE,MAAM,GAAG,SAAS,EAC/B,YAAY,EAAE,OAAO,GAAG,SAAS,EAKlC;IAEK,WAAW,CAAC,CAAC,EAAE,WAAW,EAAE,CAAC,EAAE,EAAE,iBAAiB,CAAC,UAAU,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAY/F;CACF"}
|
package/package.json
CHANGED
package/skills/opfs/SKILL.md
CHANGED
package/src/drizzle/codecs.ts
CHANGED
|
@@ -6,8 +6,6 @@ import type { NormalizeCodec } from "drizzle-orm/codecs";
|
|
|
6
6
|
import { makePgArray, parsePgArray } from "drizzle-orm/pg-core/array";
|
|
7
7
|
import {
|
|
8
8
|
arrayCompatNormalize,
|
|
9
|
-
castToText,
|
|
10
|
-
castToTextArr,
|
|
11
9
|
genericPgCodecs,
|
|
12
10
|
makeGeometryArray,
|
|
13
11
|
parseGeometryArrayAndNormalize,
|
|
@@ -18,7 +16,7 @@ import {
|
|
|
18
16
|
textToDateWithTz,
|
|
19
17
|
type PgCodecs,
|
|
20
18
|
} from "drizzle-orm/pg-core/codecs";
|
|
21
|
-
import {
|
|
19
|
+
import { pgHexToUint8Array } from "drizzle-orm/utils";
|
|
22
20
|
|
|
23
21
|
import { arrayParser, DATE, INTERVAL, TIMESTAMP, TIMESTAMPTZ, type Parser } from "../types";
|
|
24
22
|
|
|
@@ -46,27 +44,19 @@ const normalizeNullableArray = (normalize: NormalizeCodec) =>
|
|
|
46
44
|
/** drizzle's codecs for pgwasm's value formats (the text protocol, pgwasm's default parsers). */
|
|
47
45
|
export const pgwasmCodecs: PgCodecs = refineGenericPgCodecs({
|
|
48
46
|
bigint: {
|
|
49
|
-
cast: castToText,
|
|
50
|
-
castArray: castToTextArr,
|
|
51
47
|
normalize: BigInt,
|
|
52
48
|
normalizeArray: normalizeNullableArray(BigInt),
|
|
53
49
|
},
|
|
54
|
-
"bigint:string": {
|
|
50
|
+
"bigint:string": { normalize: String, normalizeArray: normalizeNullableArray(String) },
|
|
55
51
|
"bigint:number": {
|
|
56
|
-
cast: castToText,
|
|
57
|
-
castArray: castToTextArr,
|
|
58
52
|
normalize: Number,
|
|
59
53
|
normalizeArray: normalizeNullableArray(Number),
|
|
60
54
|
},
|
|
61
55
|
bigserial: {
|
|
62
56
|
normalize: BigInt,
|
|
63
57
|
normalizeArray: normalizeNullableArray(BigInt),
|
|
64
|
-
cast: castToText,
|
|
65
|
-
castArray: castToTextArr,
|
|
66
58
|
},
|
|
67
59
|
"bigserial:number": {
|
|
68
|
-
cast: castToText,
|
|
69
|
-
castArray: castToTextArr,
|
|
70
60
|
normalize: Number,
|
|
71
61
|
normalizeArray: normalizeNullableArray(Number),
|
|
72
62
|
},
|
|
@@ -80,20 +70,15 @@ export const pgwasmCodecs: PgCodecs = refineGenericPgCodecs({
|
|
|
80
70
|
normalizeArray: normalizeNullableArray((value: Uint8Array) => Buffer.from(value)),
|
|
81
71
|
}
|
|
82
72
|
: {
|
|
83
|
-
normalizeInJson:
|
|
84
|
-
normalizeArrayInJson: arrayCompatNormalize(
|
|
73
|
+
normalizeInJson: pgHexToUint8Array,
|
|
74
|
+
normalizeArrayInJson: arrayCompatNormalize(pgHexToUint8Array),
|
|
85
75
|
},
|
|
86
|
-
|
|
87
|
-
date: { castArray: castToTextArr, normalize: textToDate, normalizeArray: normalizeNullableArray(textToDate) },
|
|
88
|
-
"date:string": { castArray: castToTextArr },
|
|
76
|
+
date: { normalize: textToDate, normalizeArray: normalizeNullableArray(textToDate) },
|
|
89
77
|
timestamp: {
|
|
90
|
-
castArray: castToTextArr,
|
|
91
78
|
normalize: textToDateWithTz,
|
|
92
79
|
normalizeArray: normalizeNullableArray(textToDateWithTz),
|
|
93
80
|
},
|
|
94
|
-
timestamptz: {
|
|
95
|
-
"timestamp:string": { castArray: castToTextArr },
|
|
96
|
-
"timestamptz:string": { castArray: castToTextArr },
|
|
81
|
+
timestamptz: { normalize: textToDate, normalizeArray: normalizeNullableArray(textToDate) },
|
|
97
82
|
json: { normalizeParam: (value: unknown) => (typeof value === "object" ? value : JSON.stringify(value)) },
|
|
98
83
|
jsonb: { normalizeParam: (value: unknown) => (typeof value === "object" ? value : JSON.stringify(value)) },
|
|
99
84
|
"geometry(point)": {
|
package/src/drizzle/driver.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
// Began as a copy of drizzle-orm's PGlite driver (`src/pglite/*.ts` at 1.0.0-rc.4; Apache-2.0, © Drizzle Team
|
|
2
2
|
// and contributors — see NOTICE). Changes: rebound from PGlite to pgwasm; the driver never constructs its
|
|
3
|
-
// own database; its own JIT capability probe
|
|
4
|
-
// cache object. Owned outright (ADR-0062).
|
|
3
|
+
// own database; its own JIT capability probe. Owned outright (ADR-0062).
|
|
5
4
|
|
|
6
5
|
import { entityKind } from "drizzle-orm/entity";
|
|
7
6
|
import { DefaultLogger, type Logger } from "drizzle-orm/logger";
|
|
@@ -51,13 +50,9 @@ function construct<TRelations extends AnyRelations, TClient extends PgwasmSessio
|
|
|
51
50
|
const relations = (config.relations ?? {}) as TRelations;
|
|
52
51
|
const session = new PgwasmSession<TRelations>(client, dialect, relations, {
|
|
53
52
|
...(logger ? { logger } : {}),
|
|
54
|
-
...(config.cache ? { cache: config.cache } : {}),
|
|
55
53
|
...(config.paramsInErrors !== undefined ? { paramsInErrors: config.paramsInErrors } : {}),
|
|
56
54
|
});
|
|
57
55
|
const db = new PgwasmDatabase<TRelations>(dialect, session, relations);
|
|
58
|
-
// `db.$cache.invalidate` is the cache's own invalidation; with no cache it stays the no-op it starts as.
|
|
59
|
-
const cache = config.cache;
|
|
60
|
-
if (cache) db.$cache = { invalidate: (params) => cache.onMutate(params) };
|
|
61
56
|
return Object.assign(db, { $client: client });
|
|
62
57
|
}
|
|
63
58
|
|
package/src/drizzle/session.ts
CHANGED
|
@@ -2,9 +2,6 @@
|
|
|
2
2
|
// and contributors — see NOTICE). Changes: rebound from PGlite to pgwasm; the driver never constructs its
|
|
3
3
|
// own database. Owned outright (ADR-0062).
|
|
4
4
|
|
|
5
|
-
import type { Cache } from "drizzle-orm/cache/core/cache";
|
|
6
|
-
import { NoopCache } from "drizzle-orm/cache/core/cache";
|
|
7
|
-
import type { QueryMetadata, WithCacheConfig } from "drizzle-orm/cache/core/types";
|
|
8
5
|
import { entityKind } from "drizzle-orm/entity";
|
|
9
6
|
import { NoopLogger, type Logger } from "drizzle-orm/logger";
|
|
10
7
|
import { PgAsyncPreparedQuery, PgAsyncSession, PgAsyncTransaction } from "drizzle-orm/pg-core/async/session";
|
|
@@ -22,7 +19,6 @@ export type PgwasmSessionClient = Pick<Pgwasm, "query"> & Partial<Pick<Pgwasm, "
|
|
|
22
19
|
|
|
23
20
|
export interface PgwasmSessionOptions {
|
|
24
21
|
logger?: Logger;
|
|
25
|
-
cache?: Cache;
|
|
26
22
|
paramsInErrors?: boolean;
|
|
27
23
|
}
|
|
28
24
|
|
|
@@ -36,7 +32,6 @@ export class PgwasmSession<TRelations extends AnyRelations> extends PgAsyncSessi
|
|
|
36
32
|
readonly #relations: TRelations;
|
|
37
33
|
readonly #options: PgwasmSessionOptions;
|
|
38
34
|
readonly #logger: Logger;
|
|
39
|
-
readonly #cache: Cache;
|
|
40
35
|
|
|
41
36
|
constructor(
|
|
42
37
|
client: PgwasmSessionClient,
|
|
@@ -49,35 +44,22 @@ export class PgwasmSession<TRelations extends AnyRelations> extends PgAsyncSessi
|
|
|
49
44
|
this.#relations = relations;
|
|
50
45
|
this.#options = options;
|
|
51
46
|
this.#logger = options.logger ?? new NoopLogger();
|
|
52
|
-
this.#cache = options.cache ?? new NoopCache();
|
|
53
47
|
}
|
|
54
48
|
|
|
55
49
|
prepareQuery<T extends PreparedQueryConfig = PreparedQueryConfig>(
|
|
56
50
|
query: Query,
|
|
57
|
-
mode: "arrays" | "objects" | "raw",
|
|
51
|
+
mode: "arrays" | "objects" | "raw" | "call",
|
|
58
52
|
_name: string | boolean,
|
|
59
53
|
mapper: ((rows: unknown[]) => unknown) | undefined,
|
|
60
|
-
queryMetadata?: QueryMetadata,
|
|
61
|
-
cacheConfig?: WithCacheConfig,
|
|
62
54
|
): PgAsyncPreparedQuery<T> {
|
|
63
55
|
const executor = async (params?: unknown[]) => {
|
|
64
56
|
const result = await this.#client.query(query.sql, params, {
|
|
65
57
|
rowMode: mode === "arrays" ? "array" : "object",
|
|
66
|
-
parsers: drizzleParsers,
|
|
58
|
+
...(mode === "call" ? {} : { parsers: drizzleParsers }),
|
|
67
59
|
});
|
|
68
60
|
return mode === "raw" ? result : result.rows;
|
|
69
61
|
};
|
|
70
|
-
return new PgAsyncPreparedQuery<T>(
|
|
71
|
-
executor,
|
|
72
|
-
query,
|
|
73
|
-
mapper,
|
|
74
|
-
mode,
|
|
75
|
-
this.#logger,
|
|
76
|
-
this.#cache,
|
|
77
|
-
queryMetadata,
|
|
78
|
-
cacheConfig,
|
|
79
|
-
this.#options.paramsInErrors,
|
|
80
|
-
);
|
|
62
|
+
return new PgAsyncPreparedQuery<T>(executor, query, mapper, mode, this.#logger, this.#options.paramsInErrors);
|
|
81
63
|
}
|
|
82
64
|
|
|
83
65
|
async transaction<T>(
|