drizzle-orm 1.0.0-beta.8-dbc3565 → 1.0.0-beta.8-c55bf0f
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/effect-postgres/migrator.cjs +34 -0
- package/effect-postgres/migrator.cjs.map +1 -0
- package/effect-postgres/migrator.d.cts +4 -0
- package/effect-postgres/migrator.d.ts +4 -0
- package/effect-postgres/migrator.js +10 -0
- package/effect-postgres/migrator.js.map +1 -0
- package/effect-postgres/session.cjs +77 -26
- package/effect-postgres/session.cjs.map +1 -1
- package/effect-postgres/session.d.cts +15 -5
- package/effect-postgres/session.d.ts +15 -5
- package/effect-postgres/session.js +77 -27
- package/effect-postgres/session.js.map +1 -1
- package/package.json +13 -1
- package/pg-core/async/session.cjs +2 -2
- package/pg-core/async/session.cjs.map +1 -1
- package/pg-core/async/session.js +2 -2
- package/pg-core/async/session.js.map +1 -1
- package/pg-core/effect/db.cjs +5 -0
- package/pg-core/effect/db.cjs.map +1 -1
- package/pg-core/effect/db.d.cts +6 -3
- package/pg-core/effect/db.d.ts +6 -3
- package/pg-core/effect/db.js +5 -0
- package/pg-core/effect/db.js.map +1 -1
- package/pg-core/effect/session.cjs +93 -2
- package/pg-core/effect/session.cjs.map +1 -1
- package/pg-core/effect/session.d.cts +28 -4
- package/pg-core/effect/session.d.ts +28 -4
- package/pg-core/effect/session.js +95 -3
- package/pg-core/effect/session.js.map +1 -1
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var migrator_exports = {};
|
|
20
|
+
__export(migrator_exports, {
|
|
21
|
+
migrate: () => migrate
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(migrator_exports);
|
|
24
|
+
var import_migrator = require("../migrator.cjs");
|
|
25
|
+
var import_session = require("../pg-core/effect/session.cjs");
|
|
26
|
+
async function migrate(db, config) {
|
|
27
|
+
const migrations = (0, import_migrator.readMigrationFiles)(config);
|
|
28
|
+
return (0, import_session.migrate)(migrations, db.session, config);
|
|
29
|
+
}
|
|
30
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
31
|
+
0 && (module.exports = {
|
|
32
|
+
migrate
|
|
33
|
+
});
|
|
34
|
+
//# sourceMappingURL=migrator.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/effect-postgres/migrator.ts"],"sourcesContent":["import type { MigrationConfig } from '~/migrator.ts';\nimport { readMigrationFiles } from '~/migrator.ts';\nimport { migrate as coreMigrate } from '~/pg-core/effect/session.ts';\nimport type { AnyRelations } from '~/relations.ts';\nimport type { EffectPgDatabase } from './driver.ts';\n\nexport async function migrate<TSchema extends Record<string, unknown>, TRelations extends AnyRelations>(\n\tdb: EffectPgDatabase<TSchema, TRelations>,\n\tconfig: MigrationConfig,\n) {\n\tconst migrations = readMigrationFiles(config);\n\treturn coreMigrate(migrations, db.session, config);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,sBAAmC;AACnC,qBAAuC;AAIvC,eAAsB,QACrB,IACA,QACC;AACD,QAAM,iBAAa,oCAAmB,MAAM;AAC5C,aAAO,eAAAA,SAAY,YAAY,GAAG,SAAS,MAAM;AAClD;","names":["coreMigrate"]}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { MigrationConfig } from "../migrator.cjs";
|
|
2
|
+
import type { AnyRelations } from "../relations.cjs";
|
|
3
|
+
import type { EffectPgDatabase } from "./driver.cjs";
|
|
4
|
+
export declare function migrate<TSchema extends Record<string, unknown>, TRelations extends AnyRelations>(db: EffectPgDatabase<TSchema, TRelations>, config: MigrationConfig): Promise<import("effect/Effect").Effect<void | import("../migrator.ts").MigratorInitFailResponse, import("../errors.ts").DrizzleQueryError, never>>;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { MigrationConfig } from "../migrator.js";
|
|
2
|
+
import type { AnyRelations } from "../relations.js";
|
|
3
|
+
import type { EffectPgDatabase } from "./driver.js";
|
|
4
|
+
export declare function migrate<TSchema extends Record<string, unknown>, TRelations extends AnyRelations>(db: EffectPgDatabase<TSchema, TRelations>, config: MigrationConfig): Promise<import("effect/Effect").Effect<void | import("../migrator.js").MigratorInitFailResponse, import("../errors.js").DrizzleQueryError, never>>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { readMigrationFiles } from "../migrator.js";
|
|
2
|
+
import { migrate as coreMigrate } from "../pg-core/effect/session.js";
|
|
3
|
+
async function migrate(db, config) {
|
|
4
|
+
const migrations = readMigrationFiles(config);
|
|
5
|
+
return coreMigrate(migrations, db.session, config);
|
|
6
|
+
}
|
|
7
|
+
export {
|
|
8
|
+
migrate
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=migrator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/effect-postgres/migrator.ts"],"sourcesContent":["import type { MigrationConfig } from '~/migrator.ts';\nimport { readMigrationFiles } from '~/migrator.ts';\nimport { migrate as coreMigrate } from '~/pg-core/effect/session.ts';\nimport type { AnyRelations } from '~/relations.ts';\nimport type { EffectPgDatabase } from './driver.ts';\n\nexport async function migrate<TSchema extends Record<string, unknown>, TRelations extends AnyRelations>(\n\tdb: EffectPgDatabase<TSchema, TRelations>,\n\tconfig: MigrationConfig,\n) {\n\tconst migrations = readMigrationFiles(config);\n\treturn coreMigrate(migrations, db.session, config);\n}\n"],"mappings":"AACA,SAAS,0BAA0B;AACnC,SAAS,WAAW,mBAAmB;AAIvC,eAAsB,QACrB,IACA,QACC;AACD,QAAM,aAAa,mBAAmB,MAAM;AAC5C,SAAO,YAAY,YAAY,GAAG,SAAS,MAAM;AAClD;","names":[]}
|
|
@@ -19,7 +19,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
19
19
|
var session_exports = {};
|
|
20
20
|
__export(session_exports, {
|
|
21
21
|
EffectPgPreparedQuery: () => EffectPgPreparedQuery,
|
|
22
|
-
EffectPgSession: () => EffectPgSession
|
|
22
|
+
EffectPgSession: () => EffectPgSession,
|
|
23
|
+
EffectPgTransaction: () => EffectPgTransaction
|
|
23
24
|
});
|
|
24
25
|
module.exports = __toCommonJS(session_exports);
|
|
25
26
|
var import_effect = require("effect");
|
|
@@ -30,7 +31,7 @@ var import_session = require("../pg-core/effect/session.cjs");
|
|
|
30
31
|
var import_sql = require("../sql/sql.cjs");
|
|
31
32
|
var import_utils = require("../utils.cjs");
|
|
32
33
|
class EffectPgPreparedQuery extends import_session.PgEffectPreparedQuery {
|
|
33
|
-
constructor(client, queryString, params, logger, cache, queryMetadata, cacheConfig, fields, name, _isResponseInArrayMode, customResultMapper, isRqbV2Query) {
|
|
34
|
+
constructor(client, queryString, params, logger, cache, queryMetadata, cacheConfig, fields, name, _isResponseInArrayMode, customResultMapper, isRqbV2Query, wrap = (t) => t) {
|
|
34
35
|
super({ sql: queryString, params }, cache, queryMetadata, cacheConfig);
|
|
35
36
|
this.client = client;
|
|
36
37
|
this.queryString = queryString;
|
|
@@ -40,6 +41,7 @@ class EffectPgPreparedQuery extends import_session.PgEffectPreparedQuery {
|
|
|
40
41
|
this._isResponseInArrayMode = _isResponseInArrayMode;
|
|
41
42
|
this.customResultMapper = customResultMapper;
|
|
42
43
|
this.isRqbV2Query = isRqbV2Query;
|
|
44
|
+
this.wrap = wrap;
|
|
43
45
|
}
|
|
44
46
|
static [import_entity.entityKind] = "EffectPgPreparedQuery";
|
|
45
47
|
execute(placeholderValues) {
|
|
@@ -57,31 +59,35 @@ class EffectPgPreparedQuery extends import_session.PgEffectPreparedQuery {
|
|
|
57
59
|
return this.queryWithCache(
|
|
58
60
|
query.sql,
|
|
59
61
|
params,
|
|
60
|
-
|
|
61
|
-
(
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
62
|
+
this.wrap(
|
|
63
|
+
client.unsafe(query.sql, params).values.pipe(import_effect.Effect.andThen(
|
|
64
|
+
(rows) => {
|
|
65
|
+
if (customResultMapper) return customResultMapper(rows);
|
|
66
|
+
return rows.map(
|
|
67
|
+
(row) => (0, import_utils.mapResultRow)(
|
|
68
|
+
fields,
|
|
69
|
+
row,
|
|
70
|
+
joinsNotNullableMap
|
|
71
|
+
)
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
))
|
|
75
|
+
)
|
|
72
76
|
);
|
|
73
77
|
}
|
|
74
78
|
executeRqbV2(placeholderValues) {
|
|
75
79
|
const { query, logger, customResultMapper, client } = this;
|
|
76
80
|
const params = (0, import_sql.fillPlaceholders)(query.params, placeholderValues ?? {});
|
|
77
81
|
logger.logQuery(query.sql, params);
|
|
78
|
-
return
|
|
79
|
-
|
|
80
|
-
(
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
82
|
+
return this.wrap(
|
|
83
|
+
client.unsafe(query.sql, params).withoutTransform.pipe(
|
|
84
|
+
import_effect.Effect.andThen(
|
|
85
|
+
(v) => customResultMapper(v)
|
|
86
|
+
)
|
|
87
|
+
).pipe(import_effect.Effect.catchAll((e) => {
|
|
88
|
+
return import_effect.Effect.fail(new import_errors.DrizzleQueryError(query.sql, params, e instanceof Error ? e : void 0));
|
|
89
|
+
}))
|
|
90
|
+
);
|
|
85
91
|
}
|
|
86
92
|
all(placeholderValues) {
|
|
87
93
|
const { query, logger, client } = this;
|
|
@@ -90,7 +96,7 @@ class EffectPgPreparedQuery extends import_session.PgEffectPreparedQuery {
|
|
|
90
96
|
return this.queryWithCache(
|
|
91
97
|
query.sql,
|
|
92
98
|
params,
|
|
93
|
-
client.unsafe(query.sql, params).withoutTransform
|
|
99
|
+
this.wrap(client.unsafe(query.sql, params).withoutTransform)
|
|
94
100
|
);
|
|
95
101
|
}
|
|
96
102
|
/** @internal */
|
|
@@ -99,9 +105,13 @@ class EffectPgPreparedQuery extends import_session.PgEffectPreparedQuery {
|
|
|
99
105
|
}
|
|
100
106
|
}
|
|
101
107
|
class EffectPgSession extends import_session.PgEffectSession {
|
|
102
|
-
constructor(client, dialect, relations, schema, options = {}) {
|
|
108
|
+
constructor(client, dialect, relations, schema, options = {}, wrap = (t) => t, nestedIndex = 0) {
|
|
103
109
|
super(dialect);
|
|
104
110
|
this.client = client;
|
|
111
|
+
this.relations = relations;
|
|
112
|
+
this.schema = schema;
|
|
113
|
+
this.wrap = wrap;
|
|
114
|
+
this.nestedIndex = nestedIndex;
|
|
105
115
|
this.logger = options.logger ?? new import_logger.NoopLogger();
|
|
106
116
|
this.cache = options.cache;
|
|
107
117
|
}
|
|
@@ -120,7 +130,9 @@ class EffectPgSession extends import_session.PgEffectSession {
|
|
|
120
130
|
fields,
|
|
121
131
|
name,
|
|
122
132
|
isResponseInArrayMode,
|
|
123
|
-
customResultMapper
|
|
133
|
+
customResultMapper,
|
|
134
|
+
false,
|
|
135
|
+
this.wrap
|
|
124
136
|
);
|
|
125
137
|
}
|
|
126
138
|
prepareRelationalQuery(query, fields, name, customResultMapper) {
|
|
@@ -136,7 +148,8 @@ class EffectPgSession extends import_session.PgEffectSession {
|
|
|
136
148
|
name,
|
|
137
149
|
false,
|
|
138
150
|
customResultMapper,
|
|
139
|
-
true
|
|
151
|
+
true,
|
|
152
|
+
this.wrap
|
|
140
153
|
);
|
|
141
154
|
}
|
|
142
155
|
execute(query) {
|
|
@@ -155,10 +168,48 @@ class EffectPgSession extends import_session.PgEffectSession {
|
|
|
155
168
|
false
|
|
156
169
|
).all();
|
|
157
170
|
}
|
|
171
|
+
transaction(transaction) {
|
|
172
|
+
const { dialect, relations, schema, client, logger, cache, nestedIndex } = this;
|
|
173
|
+
const sp = `sp${this.nestedIndex}`;
|
|
174
|
+
return this.client.withTransaction(import_effect.Effect.gen(function* (txAdapter) {
|
|
175
|
+
const session = new EffectPgSession(
|
|
176
|
+
client,
|
|
177
|
+
dialect,
|
|
178
|
+
relations,
|
|
179
|
+
schema,
|
|
180
|
+
{ logger, cache },
|
|
181
|
+
txAdapter,
|
|
182
|
+
nestedIndex + 1
|
|
183
|
+
);
|
|
184
|
+
const tx = new EffectPgTransaction(
|
|
185
|
+
dialect,
|
|
186
|
+
session,
|
|
187
|
+
relations,
|
|
188
|
+
schema,
|
|
189
|
+
nestedIndex + 1
|
|
190
|
+
);
|
|
191
|
+
if (nestedIndex) yield* tx.execute(import_sql.sql.raw(`savepoint ${sp}`));
|
|
192
|
+
const res = yield* transaction(tx).pipe(import_effect.Effect.catchAll(
|
|
193
|
+
(e) => import_effect.Effect.gen(function* () {
|
|
194
|
+
if (nestedIndex) yield* tx.execute(import_sql.sql.raw(`rollback to savepoint ${sp}`));
|
|
195
|
+
return yield* import_effect.Effect.fail(e);
|
|
196
|
+
})
|
|
197
|
+
));
|
|
198
|
+
if (nestedIndex) yield* tx.execute(import_sql.sql.raw(`release savepoint ${sp}`));
|
|
199
|
+
return res;
|
|
200
|
+
}));
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
class EffectPgTransaction extends import_session.PgEffectTransaction {
|
|
204
|
+
static [import_entity.entityKind] = "EffectPgTransaction";
|
|
205
|
+
transaction(transaction) {
|
|
206
|
+
return this.session.transaction(transaction);
|
|
207
|
+
}
|
|
158
208
|
}
|
|
159
209
|
// Annotate the CommonJS export names for ESM import in node:
|
|
160
210
|
0 && (module.exports = {
|
|
161
211
|
EffectPgPreparedQuery,
|
|
162
|
-
EffectPgSession
|
|
212
|
+
EffectPgSession,
|
|
213
|
+
EffectPgTransaction
|
|
163
214
|
});
|
|
164
215
|
//# sourceMappingURL=session.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/effect-postgres/session.ts"],"sourcesContent":["import type { PgClient } from '@effect/sql-pg/PgClient';\nimport { Effect } from 'effect';\nimport type * as V1 from '~/_relations.ts';\nimport type { EffectCache } from '~/cache/core/cache-effect.ts';\nimport type { WithCacheConfig } from '~/cache/core/types.ts';\nimport { entityKind } from '~/entity.ts';\nimport { DrizzleQueryError } from '~/errors.ts';\nimport { type Logger, NoopLogger } from '~/logger.ts';\nimport type { PgDialect } from '~/pg-core/dialect.ts';\nimport { PgEffectPreparedQuery, PgEffectSession } from '~/pg-core/effect/session.ts';\nimport type { SelectedFieldsOrdered } from '~/pg-core/query-builders/select.types.ts';\nimport type { PgQueryResultHKT, PreparedQueryConfig } from '~/pg-core/session.ts';\nimport type { AnyRelations } from '~/relations.ts';\nimport type { Query, SQL } from '~/sql/sql.ts';\nimport { fillPlaceholders } from '~/sql/sql.ts';\nimport { mapResultRow } from '~/utils.ts';\n\nexport interface EffectPgQueryResultHKT extends PgQueryResultHKT {\n\ttype: readonly object[];\n}\n\nexport class EffectPgPreparedQuery<T extends PreparedQueryConfig, TIsRqbV2 extends boolean = false>\n\textends PgEffectPreparedQuery<T>\n{\n\tstatic override readonly [entityKind]: string = 'EffectPgPreparedQuery';\n\n\tconstructor(\n\t\tprivate client: PgClient,\n\t\tprivate queryString: string,\n\t\tprivate params: unknown[],\n\t\tprivate logger: Logger,\n\t\tcache: EffectCache | undefined,\n\t\tqueryMetadata: {\n\t\t\ttype: 'select' | 'update' | 'delete' | 'insert';\n\t\t\ttables: string[];\n\t\t} | undefined,\n\t\tcacheConfig: WithCacheConfig | undefined,\n\t\tprivate fields: SelectedFieldsOrdered | undefined,\n\t\tname: string | undefined,\n\t\tprivate _isResponseInArrayMode: boolean,\n\t\tprivate customResultMapper?: (\n\t\t\trows: TIsRqbV2 extends true ? Record<string, unknown>[] : unknown[][],\n\t\t) => T['execute'],\n\t\tprivate isRqbV2Query?: TIsRqbV2,\n\t) {\n\t\tsuper({ sql: queryString, params }, cache, queryMetadata, cacheConfig);\n\t}\n\n\texecute(placeholderValues?: Record<string, unknown>): Effect.Effect<T['execute'], DrizzleQueryError> {\n\t\tif (this.isRqbV2Query) return this.executeRqbV2(placeholderValues);\n\n\t\tconst { query, logger, customResultMapper, fields, joinsNotNullableMap, client } = this;\n\t\tconst params = fillPlaceholders(query.params, placeholderValues ?? {});\n\t\tlogger.logQuery(query.sql, params);\n\n\t\tif (!fields && !customResultMapper) {\n\t\t\treturn this.queryWithCache(\n\t\t\t\tquery.sql,\n\t\t\t\tparams,\n\t\t\t\tthis.client.unsafe(query.sql, params as any).withoutTransform,\n\t\t\t);\n\t\t}\n\n\t\treturn this.queryWithCache(\n\t\t\tquery.sql,\n\t\t\tparams,\n\t\t\tclient.unsafe(query.sql, params as any).values.pipe(Effect.andThen(\n\t\t\t\t(rows) => {\n\t\t\t\t\tif (customResultMapper) return (customResultMapper as (rows: unknown[][]) => unknown)(rows as unknown[][]);\n\n\t\t\t\t\treturn rows.map((row) =>\n\t\t\t\t\t\tmapResultRow(\n\t\t\t\t\t\t\tfields!,\n\t\t\t\t\t\t\trow as unknown[],\n\t\t\t\t\t\t\tjoinsNotNullableMap,\n\t\t\t\t\t\t)\n\t\t\t\t\t);\n\t\t\t\t},\n\t\t\t)),\n\t\t);\n\t}\n\n\tprivate executeRqbV2(\n\t\tplaceholderValues?: Record<string, unknown>,\n\t): Effect.Effect<T['execute'], DrizzleQueryError> {\n\t\tconst { query, logger, customResultMapper, client } = this;\n\t\tconst params = fillPlaceholders(query.params, placeholderValues ?? {});\n\n\t\tlogger.logQuery(query.sql, params);\n\t\treturn client.unsafe(query.sql, params as any).withoutTransform.pipe(\n\t\t\tEffect.andThen((v) =>\n\t\t\t\t(customResultMapper as (\n\t\t\t\t\trows: Record<string, unknown>[],\n\t\t\t\t\tmapColumnValue?: (value: unknown) => unknown,\n\t\t\t\t) => unknown)(v as Record<string, unknown>[])\n\t\t\t),\n\t\t).pipe(Effect.catchAll((e) => {\n\t\t\t// eslint-disable-next-line @drizzle-internal/no-instanceof\n\t\t\treturn Effect.fail(new DrizzleQueryError(query.sql, params, e instanceof Error ? e : undefined));\n\t\t}));\n\t}\n\n\toverride all(placeholderValues?: Record<string, unknown>): Effect.Effect<T['all'], DrizzleQueryError, never> {\n\t\tconst { query, logger, client } = this;\n\t\tconst params = fillPlaceholders(query.params, placeholderValues ?? {});\n\n\t\tlogger.logQuery(query.sql, params);\n\n\t\treturn this.queryWithCache(\n\t\t\tquery.sql,\n\t\t\tparams,\n\t\t\tclient.unsafe(query.sql, params as any).withoutTransform,\n\t\t);\n\t}\n\n\t/** @internal */\n\tisResponseInArrayMode(): boolean {\n\t\treturn this._isResponseInArrayMode;\n\t}\n}\n\nexport class EffectPgSession<\n\t_TFullSchema extends Record<string, unknown>,\n\tTRelations extends AnyRelations,\n\tTSchema extends V1.TablesRelationalConfig,\n> extends PgEffectSession {\n\tstatic override readonly [entityKind]: string = 'EffectPgSession';\n\n\tprivate logger: Logger;\n\tprivate cache: EffectCache | undefined;\n\n\tconstructor(\n\t\tprivate client: PgClient,\n\t\tdialect: PgDialect,\n\t\trelations: TRelations,\n\t\tschema: V1.RelationalSchemaConfig<TSchema> | undefined,\n\t\toptions: { logger?: Logger; cache?: EffectCache } = {},\n\t) {\n\t\tsuper(dialect);\n\t\tthis.logger = options.logger ?? new NoopLogger();\n\t\tthis.cache = options.cache;\n\t}\n\n\tprepareQuery<T extends PreparedQueryConfig = PreparedQueryConfig>(\n\t\tquery: Query,\n\t\tfields: SelectedFieldsOrdered | undefined,\n\t\tname: string | undefined,\n\t\tisResponseInArrayMode: boolean,\n\t\tcustomResultMapper?: (rows: unknown[][]) => T['execute'],\n\t\tqueryMetadata?: {\n\t\t\ttype: 'select' | 'update' | 'delete' | 'insert';\n\t\t\ttables: string[];\n\t\t},\n\t\tcacheConfig?: WithCacheConfig,\n\t) {\n\t\treturn new EffectPgPreparedQuery(\n\t\t\tthis.client,\n\t\t\tquery.sql,\n\t\t\tquery.params,\n\t\t\tthis.logger,\n\t\t\tthis.cache,\n\t\t\tqueryMetadata,\n\t\t\tcacheConfig,\n\t\t\tfields,\n\t\t\tname,\n\t\t\tisResponseInArrayMode,\n\t\t\tcustomResultMapper,\n\t\t);\n\t}\n\n\tprepareRelationalQuery<T extends PreparedQueryConfig = PreparedQueryConfig>(\n\t\tquery: Query,\n\t\tfields: SelectedFieldsOrdered | undefined,\n\t\tname: string | undefined,\n\t\tcustomResultMapper?: (rows: Record<string, unknown>[]) => T['execute'],\n\t): EffectPgPreparedQuery<T, true> {\n\t\treturn new EffectPgPreparedQuery<T, true>(\n\t\t\tthis.client,\n\t\t\tquery.sql,\n\t\t\tquery.params,\n\t\t\tthis.logger,\n\t\t\tthis.cache,\n\t\t\tundefined,\n\t\t\tundefined,\n\t\t\tfields,\n\t\t\tname,\n\t\t\tfalse,\n\t\t\tcustomResultMapper,\n\t\t\ttrue,\n\t\t);\n\t}\n\n\toverride execute<T>(query: SQL): Effect.Effect<T, DrizzleQueryError> {\n\t\treturn this.prepareQuery<PreparedQueryConfig & { execute: T }>(\n\t\t\tthis.dialect.sqlToQuery(query),\n\t\t\tundefined,\n\t\t\tundefined,\n\t\t\tfalse,\n\t\t).execute();\n\t}\n\n\toverride all<T>(query: SQL): Effect.Effect<T, DrizzleQueryError> {\n\t\treturn this.prepareQuery<PreparedQueryConfig & { all: T }>(\n\t\t\tthis.dialect.sqlToQuery(query),\n\t\t\tundefined,\n\t\t\tundefined,\n\t\t\tfalse,\n\t\t).all();\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,oBAAuB;AAIvB,oBAA2B;AAC3B,oBAAkC;AAClC,oBAAwC;AAExC,qBAAuD;AAKvD,iBAAiC;AACjC,mBAA6B;AAMtB,MAAM,8BACJ,qCACT;AAAA,EAGC,YACS,QACA,aACA,QACA,QACR,OACA,eAIA,aACQ,QACR,MACQ,wBACA,oBAGA,cACP;AACD,UAAM,EAAE,KAAK,aAAa,OAAO,GAAG,OAAO,eAAe,WAAW;AAlB7D;AACA;AACA;AACA;AAOA;AAEA;AACA;AAGA;AAAA,EAGT;AAAA,EAtBA,QAA0B,wBAAU,IAAY;AAAA,EAwBhD,QAAQ,mBAA6F;AACpG,QAAI,KAAK,aAAc,QAAO,KAAK,aAAa,iBAAiB;AAEjE,UAAM,EAAE,OAAO,QAAQ,oBAAoB,QAAQ,qBAAqB,OAAO,IAAI;AACnF,UAAM,aAAS,6BAAiB,MAAM,QAAQ,qBAAqB,CAAC,CAAC;AACrE,WAAO,SAAS,MAAM,KAAK,MAAM;AAEjC,QAAI,CAAC,UAAU,CAAC,oBAAoB;AACnC,aAAO,KAAK;AAAA,QACX,MAAM;AAAA,QACN;AAAA,QACA,KAAK,OAAO,OAAO,MAAM,KAAK,MAAa,EAAE;AAAA,MAC9C;AAAA,IACD;AAEA,WAAO,KAAK;AAAA,MACX,MAAM;AAAA,MACN;AAAA,MACA,OAAO,OAAO,MAAM,KAAK,MAAa,EAAE,OAAO,KAAK,qBAAO;AAAA,QAC1D,CAAC,SAAS;AACT,cAAI,mBAAoB,QAAQ,mBAAsD,IAAmB;AAEzG,iBAAO,KAAK;AAAA,YAAI,CAAC,YAChB;AAAA,cACC;AAAA,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,KAAK;AAAA,MACL,MAAM;AAAA,MACN,MAAM;AAAA,MACN,KAAK;AAAA,MACL,KAAK;AAAA,MACL;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACD;AAAA,EACD;AAAA,EAEA,uBACC,OACA,QACA,MACA,oBACiC;AACjC,WAAO,IAAI;AAAA,MACV,KAAK;AAAA,MACL,MAAM;AAAA,MACN,MAAM;AAAA,MACN,KAAK;AAAA,MACL,KAAK;AAAA,MACL;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACD;AAAA,EACD;AAAA,EAES,QAAW,OAAiD;AACpE,WAAO,KAAK;AAAA,MACX,KAAK,QAAQ,WAAW,KAAK;AAAA,MAC7B;AAAA,MACA;AAAA,MACA;AAAA,IACD,EAAE,QAAQ;AAAA,EACX;AAAA,EAES,IAAO,OAAiD;AAChE,WAAO,KAAK;AAAA,MACX,KAAK,QAAQ,WAAW,KAAK;AAAA,MAC7B;AAAA,MACA;AAAA,MACA;AAAA,IACD,EAAE,IAAI;AAAA,EACP;AACD;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/effect-postgres/session.ts"],"sourcesContent":["import type { PgClient } from '@effect/sql-pg/PgClient';\nimport { Effect } from 'effect';\nimport type * as V1 from '~/_relations.ts';\nimport type { EffectCache } from '~/cache/core/cache-effect.ts';\nimport type { WithCacheConfig } from '~/cache/core/types.ts';\nimport { entityKind } from '~/entity.ts';\nimport { DrizzleQueryError, type TransactionRollbackError } from '~/errors.ts';\nimport { type Logger, NoopLogger } from '~/logger.ts';\nimport type { PgDialect } from '~/pg-core/dialect.ts';\nimport { PgEffectPreparedQuery, PgEffectSession, PgEffectTransaction } from '~/pg-core/effect/session.ts';\nimport type { SelectedFieldsOrdered } from '~/pg-core/query-builders/select.types.ts';\nimport type { PgQueryResultHKT, PreparedQueryConfig } from '~/pg-core/session.ts';\nimport type { AnyRelations } from '~/relations.ts';\nimport type { Query, SQL } from '~/sql/sql.ts';\nimport { fillPlaceholders, sql } from '~/sql/sql.ts';\nimport { mapResultRow } from '~/utils.ts';\nexport interface EffectPgQueryResultHKT extends PgQueryResultHKT {\n\ttype: readonly object[];\n}\n\nexport class EffectPgPreparedQuery<T extends PreparedQueryConfig, TIsRqbV2 extends boolean = false>\n\textends PgEffectPreparedQuery<T>\n{\n\tstatic override readonly [entityKind]: string = 'EffectPgPreparedQuery';\n\n\tconstructor(\n\t\tprivate client: PgClient,\n\t\tprivate queryString: string,\n\t\tprivate params: unknown[],\n\t\tprivate logger: Logger,\n\t\tcache: EffectCache | undefined,\n\t\tqueryMetadata: {\n\t\t\ttype: 'select' | 'update' | 'delete' | 'insert';\n\t\t\ttables: string[];\n\t\t} | undefined,\n\t\tcacheConfig: WithCacheConfig | undefined,\n\t\tprivate fields: SelectedFieldsOrdered | undefined,\n\t\tname: string | undefined,\n\t\tprivate _isResponseInArrayMode: boolean,\n\t\tprivate customResultMapper?: (\n\t\t\trows: TIsRqbV2 extends true ? Record<string, unknown>[] : unknown[][],\n\t\t) => T['execute'],\n\t\tprivate isRqbV2Query?: TIsRqbV2,\n\t\tprivate wrap: Effect.Adapter = <T>(t: T): T => t,\n\t) {\n\t\tsuper({ sql: queryString, params }, cache, queryMetadata, cacheConfig);\n\t}\n\n\texecute(placeholderValues?: Record<string, unknown>): Effect.Effect<T['execute'], DrizzleQueryError> {\n\t\tif (this.isRqbV2Query) return this.executeRqbV2(placeholderValues);\n\n\t\tconst { query, logger, customResultMapper, fields, joinsNotNullableMap, client } = this;\n\t\tconst params = fillPlaceholders(query.params, placeholderValues ?? {});\n\t\tlogger.logQuery(query.sql, params);\n\n\t\tif (!fields && !customResultMapper) {\n\t\t\treturn this.queryWithCache(\n\t\t\t\tquery.sql,\n\t\t\t\tparams,\n\t\t\t\tthis.client.unsafe(query.sql, params as any).withoutTransform,\n\t\t\t);\n\t\t}\n\n\t\treturn this.queryWithCache(\n\t\t\tquery.sql,\n\t\t\tparams,\n\t\t\tthis.wrap(\n\t\t\t\tclient.unsafe(query.sql, params as any).values.pipe(Effect.andThen(\n\t\t\t\t\t(rows) => {\n\t\t\t\t\t\tif (customResultMapper) return (customResultMapper as (rows: unknown[][]) => unknown)(rows as unknown[][]);\n\n\t\t\t\t\t\treturn rows.map((row) =>\n\t\t\t\t\t\t\tmapResultRow(\n\t\t\t\t\t\t\t\tfields!,\n\t\t\t\t\t\t\t\trow as unknown[],\n\t\t\t\t\t\t\t\tjoinsNotNullableMap,\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t);\n\t\t\t\t\t},\n\t\t\t\t)),\n\t\t\t),\n\t\t);\n\t}\n\n\tprivate executeRqbV2(\n\t\tplaceholderValues?: Record<string, unknown>,\n\t): Effect.Effect<T['execute'], DrizzleQueryError> {\n\t\tconst { query, logger, customResultMapper, client } = this;\n\t\tconst params = fillPlaceholders(query.params, placeholderValues ?? {});\n\n\t\tlogger.logQuery(query.sql, params);\n\t\treturn this.wrap(\n\t\t\tclient.unsafe(query.sql, params as any).withoutTransform.pipe(\n\t\t\t\tEffect.andThen((v) =>\n\t\t\t\t\t(customResultMapper as (\n\t\t\t\t\t\trows: Record<string, unknown>[],\n\t\t\t\t\t\tmapColumnValue?: (value: unknown) => unknown,\n\t\t\t\t\t) => unknown)(v as Record<string, unknown>[])\n\t\t\t\t),\n\t\t\t).pipe(Effect.catchAll((e) => {\n\t\t\t\t// eslint-disable-next-line @drizzle-internal/no-instanceof\n\t\t\t\treturn Effect.fail(new DrizzleQueryError(query.sql, params, e instanceof Error ? e : undefined));\n\t\t\t})),\n\t\t);\n\t}\n\n\toverride all(placeholderValues?: Record<string, unknown>): Effect.Effect<T['all'], DrizzleQueryError, never> {\n\t\tconst { query, logger, client } = this;\n\t\tconst params = fillPlaceholders(query.params, placeholderValues ?? {});\n\n\t\tlogger.logQuery(query.sql, params);\n\n\t\treturn this.queryWithCache(\n\t\t\tquery.sql,\n\t\t\tparams,\n\t\t\tthis.wrap(client.unsafe(query.sql, params as any).withoutTransform),\n\t\t);\n\t}\n\n\t/** @internal */\n\tisResponseInArrayMode(): boolean {\n\t\treturn this._isResponseInArrayMode;\n\t}\n}\n\nexport class EffectPgSession<\n\tTQueryResult extends PgQueryResultHKT,\n\tTFullSchema extends Record<string, unknown>,\n\tTRelations extends AnyRelations,\n\tTSchema extends V1.TablesRelationalConfig,\n> extends PgEffectSession<TQueryResult, TFullSchema, TRelations, TSchema> {\n\tstatic override readonly [entityKind]: string = 'EffectPgSession';\n\n\tprivate logger: Logger;\n\tprivate cache: EffectCache | undefined;\n\n\tconstructor(\n\t\tprivate client: PgClient,\n\t\tdialect: PgDialect,\n\t\tprotected relations: TRelations,\n\t\tprotected schema: V1.RelationalSchemaConfig<TSchema> | undefined,\n\t\toptions: { logger?: Logger; cache?: EffectCache } = {},\n\t\tprivate wrap: Effect.Adapter = <T>(t: T): T => t,\n\t\tprivate nestedIndex = 0,\n\t) {\n\t\tsuper(dialect);\n\t\tthis.logger = options.logger ?? new NoopLogger();\n\t\tthis.cache = options.cache;\n\t}\n\n\tprepareQuery<T extends PreparedQueryConfig = PreparedQueryConfig>(\n\t\tquery: Query,\n\t\tfields: SelectedFieldsOrdered | undefined,\n\t\tname: string | undefined,\n\t\tisResponseInArrayMode: boolean,\n\t\tcustomResultMapper?: (rows: unknown[][]) => T['execute'],\n\t\tqueryMetadata?: {\n\t\t\ttype: 'select' | 'update' | 'delete' | 'insert';\n\t\t\ttables: string[];\n\t\t},\n\t\tcacheConfig?: WithCacheConfig,\n\t) {\n\t\treturn new EffectPgPreparedQuery(\n\t\t\tthis.client,\n\t\t\tquery.sql,\n\t\t\tquery.params,\n\t\t\tthis.logger,\n\t\t\tthis.cache,\n\t\t\tqueryMetadata,\n\t\t\tcacheConfig,\n\t\t\tfields,\n\t\t\tname,\n\t\t\tisResponseInArrayMode,\n\t\t\tcustomResultMapper,\n\t\t\tfalse,\n\t\t\tthis.wrap,\n\t\t);\n\t}\n\n\tprepareRelationalQuery<T extends PreparedQueryConfig = PreparedQueryConfig>(\n\t\tquery: Query,\n\t\tfields: SelectedFieldsOrdered | undefined,\n\t\tname: string | undefined,\n\t\tcustomResultMapper?: (rows: Record<string, unknown>[]) => T['execute'],\n\t): EffectPgPreparedQuery<T, true> {\n\t\treturn new EffectPgPreparedQuery<T, true>(\n\t\t\tthis.client,\n\t\t\tquery.sql,\n\t\t\tquery.params,\n\t\t\tthis.logger,\n\t\t\tthis.cache,\n\t\t\tundefined,\n\t\t\tundefined,\n\t\t\tfields,\n\t\t\tname,\n\t\t\tfalse,\n\t\t\tcustomResultMapper,\n\t\t\ttrue,\n\t\t\tthis.wrap,\n\t\t);\n\t}\n\n\toverride execute<T>(query: SQL): Effect.Effect<T, DrizzleQueryError> {\n\t\treturn this.prepareQuery<PreparedQueryConfig & { execute: T }>(\n\t\t\tthis.dialect.sqlToQuery(query),\n\t\t\tundefined,\n\t\t\tundefined,\n\t\t\tfalse,\n\t\t).execute();\n\t}\n\n\toverride all<T>(query: SQL): Effect.Effect<T, DrizzleQueryError> {\n\t\treturn this.prepareQuery<PreparedQueryConfig & { all: T }>(\n\t\t\tthis.dialect.sqlToQuery(query),\n\t\t\tundefined,\n\t\t\tundefined,\n\t\t\tfalse,\n\t\t).all();\n\t}\n\n\toverride transaction<T>(\n\t\ttransaction: (\n\t\t\ttx: EffectPgTransaction<\n\t\t\t\tTQueryResult,\n\t\t\t\tTFullSchema,\n\t\t\t\tTRelations,\n\t\t\t\tTSchema\n\t\t\t>,\n\t\t) => Effect.Effect<T, DrizzleQueryError | TransactionRollbackError, never>,\n\t): Effect.Effect<T, DrizzleQueryError | TransactionRollbackError, never> {\n\t\tconst { dialect, relations, schema, client, logger, cache, nestedIndex } = this;\n\t\tconst sp = `sp${this.nestedIndex}`;\n\n\t\treturn this.client.withTransaction(Effect.gen(function*(txAdapter) {\n\t\t\tconst session = new EffectPgSession(\n\t\t\t\tclient,\n\t\t\t\tdialect,\n\t\t\t\trelations,\n\t\t\t\tschema,\n\t\t\t\t{ logger, cache },\n\t\t\t\ttxAdapter,\n\t\t\t\tnestedIndex + 1,\n\t\t\t);\n\n\t\t\tconst tx = new EffectPgTransaction<TQueryResult, TFullSchema, TRelations, TSchema>(\n\t\t\t\tdialect,\n\t\t\t\tsession,\n\t\t\t\trelations,\n\t\t\t\tschema,\n\t\t\t\tnestedIndex + 1,\n\t\t\t);\n\n\t\t\tif (nestedIndex) yield* tx.execute(sql.raw(`savepoint ${sp}`));\n\n\t\t\tconst res = yield* transaction(tx).pipe(Effect.catchAll((e) =>\n\t\t\t\tEffect.gen(function*() {\n\t\t\t\t\tif (nestedIndex) yield* (tx.execute(sql.raw(`rollback to savepoint ${sp}`)));\n\t\t\t\t\treturn yield* Effect.fail(e);\n\t\t\t\t})\n\t\t\t));\n\t\t\tif (nestedIndex) yield* (tx.execute(sql.raw(`release savepoint ${sp}`)));\n\n\t\t\treturn res;\n\t\t}));\n\t}\n}\n\nexport class EffectPgTransaction<\n\tTQueryResult extends PgQueryResultHKT,\n\tTFullSchema extends Record<string, unknown>,\n\tTRelations extends AnyRelations,\n\tTSchema extends V1.TablesRelationalConfig,\n> extends PgEffectTransaction<TQueryResult, TFullSchema, TRelations, TSchema> {\n\tstatic override readonly [entityKind]: string = 'EffectPgTransaction';\n\n\toverride transaction<T>(\n\t\ttransaction: (\n\t\t\ttx: PgEffectTransaction<TQueryResult, TFullSchema, TRelations, TSchema>,\n\t\t) => Effect.Effect<T, DrizzleQueryError | TransactionRollbackError, never>,\n\t): Effect.Effect<T, DrizzleQueryError | TransactionRollbackError, never> {\n\t\treturn this.session.transaction(transaction);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,oBAAuB;AAIvB,oBAA2B;AAC3B,oBAAiE;AACjE,oBAAwC;AAExC,qBAA4E;AAK5E,iBAAsC;AACtC,mBAA6B;AAKtB,MAAM,8BACJ,qCACT;AAAA,E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1E,iBAAO,OAAO,qBAAO,KAAK,CAAC;AAAA,QAC5B,CAAC;AAAA,MACF,CAAC;AACD,UAAI,YAAa,QAAQ,GAAG,QAAQ,eAAI,IAAI,qBAAqB,EAAE,EAAE,CAAC;AAEtE,aAAO;AAAA,IACR,CAAC,CAAC;AAAA,EACH;AACD;AAEO,MAAM,4BAKH,mCAAoE;AAAA,EAC7E,QAA0B,wBAAU,IAAY;AAAA,EAEvC,YACR,aAGwE;AACxE,WAAO,KAAK,QAAQ,YAAY,WAAW;AAAA,EAC5C;AACD;","names":[]}
|
|
@@ -4,10 +4,10 @@ import type * as V1 from "../_relations.cjs";
|
|
|
4
4
|
import type { EffectCache } from "../cache/core/cache-effect.cjs";
|
|
5
5
|
import type { WithCacheConfig } from "../cache/core/types.cjs";
|
|
6
6
|
import { entityKind } from "../entity.cjs";
|
|
7
|
-
import { DrizzleQueryError } from "../errors.cjs";
|
|
7
|
+
import { DrizzleQueryError, type TransactionRollbackError } from "../errors.cjs";
|
|
8
8
|
import { type Logger } from "../logger.cjs";
|
|
9
9
|
import type { PgDialect } from "../pg-core/dialect.cjs";
|
|
10
|
-
import { PgEffectPreparedQuery, PgEffectSession } from "../pg-core/effect/session.cjs";
|
|
10
|
+
import { PgEffectPreparedQuery, PgEffectSession, PgEffectTransaction } from "../pg-core/effect/session.cjs";
|
|
11
11
|
import type { SelectedFieldsOrdered } from "../pg-core/query-builders/select.types.cjs";
|
|
12
12
|
import type { PgQueryResultHKT, PreparedQueryConfig } from "../pg-core/session.cjs";
|
|
13
13
|
import type { AnyRelations } from "../relations.cjs";
|
|
@@ -24,24 +24,29 @@ export declare class EffectPgPreparedQuery<T extends PreparedQueryConfig, TIsRqb
|
|
|
24
24
|
private _isResponseInArrayMode;
|
|
25
25
|
private customResultMapper?;
|
|
26
26
|
private isRqbV2Query?;
|
|
27
|
+
private wrap;
|
|
27
28
|
static readonly [entityKind]: string;
|
|
28
29
|
constructor(client: PgClient, queryString: string, params: unknown[], logger: Logger, cache: EffectCache | undefined, queryMetadata: {
|
|
29
30
|
type: 'select' | 'update' | 'delete' | 'insert';
|
|
30
31
|
tables: string[];
|
|
31
|
-
} | undefined, cacheConfig: WithCacheConfig | undefined, fields: SelectedFieldsOrdered | undefined, name: string | undefined, _isResponseInArrayMode: boolean, customResultMapper?: ((rows: TIsRqbV2 extends true ? Record<string, unknown>[] : unknown[][]) => T["execute"]) | undefined, isRqbV2Query?: TIsRqbV2 | undefined);
|
|
32
|
+
} | undefined, cacheConfig: WithCacheConfig | undefined, fields: SelectedFieldsOrdered | undefined, name: string | undefined, _isResponseInArrayMode: boolean, customResultMapper?: ((rows: TIsRqbV2 extends true ? Record<string, unknown>[] : unknown[][]) => T["execute"]) | undefined, isRqbV2Query?: TIsRqbV2 | undefined, wrap?: Effect.Adapter);
|
|
32
33
|
execute(placeholderValues?: Record<string, unknown>): Effect.Effect<T['execute'], DrizzleQueryError>;
|
|
33
34
|
private executeRqbV2;
|
|
34
35
|
all(placeholderValues?: Record<string, unknown>): Effect.Effect<T['all'], DrizzleQueryError, never>;
|
|
35
36
|
}
|
|
36
|
-
export declare class EffectPgSession<
|
|
37
|
+
export declare class EffectPgSession<TQueryResult extends PgQueryResultHKT, TFullSchema extends Record<string, unknown>, TRelations extends AnyRelations, TSchema extends V1.TablesRelationalConfig> extends PgEffectSession<TQueryResult, TFullSchema, TRelations, TSchema> {
|
|
37
38
|
private client;
|
|
39
|
+
protected relations: TRelations;
|
|
40
|
+
protected schema: V1.RelationalSchemaConfig<TSchema> | undefined;
|
|
41
|
+
private wrap;
|
|
42
|
+
private nestedIndex;
|
|
38
43
|
static readonly [entityKind]: string;
|
|
39
44
|
private logger;
|
|
40
45
|
private cache;
|
|
41
46
|
constructor(client: PgClient, dialect: PgDialect, relations: TRelations, schema: V1.RelationalSchemaConfig<TSchema> | undefined, options?: {
|
|
42
47
|
logger?: Logger;
|
|
43
48
|
cache?: EffectCache;
|
|
44
|
-
});
|
|
49
|
+
}, wrap?: Effect.Adapter, nestedIndex?: number);
|
|
45
50
|
prepareQuery<T extends PreparedQueryConfig = PreparedQueryConfig>(query: Query, fields: SelectedFieldsOrdered | undefined, name: string | undefined, isResponseInArrayMode: boolean, customResultMapper?: (rows: unknown[][]) => T['execute'], queryMetadata?: {
|
|
46
51
|
type: 'select' | 'update' | 'delete' | 'insert';
|
|
47
52
|
tables: string[];
|
|
@@ -49,4 +54,9 @@ export declare class EffectPgSession<_TFullSchema extends Record<string, unknown
|
|
|
49
54
|
prepareRelationalQuery<T extends PreparedQueryConfig = PreparedQueryConfig>(query: Query, fields: SelectedFieldsOrdered | undefined, name: string | undefined, customResultMapper?: (rows: Record<string, unknown>[]) => T['execute']): EffectPgPreparedQuery<T, true>;
|
|
50
55
|
execute<T>(query: SQL): Effect.Effect<T, DrizzleQueryError>;
|
|
51
56
|
all<T>(query: SQL): Effect.Effect<T, DrizzleQueryError>;
|
|
57
|
+
transaction<T>(transaction: (tx: EffectPgTransaction<TQueryResult, TFullSchema, TRelations, TSchema>) => Effect.Effect<T, DrizzleQueryError | TransactionRollbackError, never>): Effect.Effect<T, DrizzleQueryError | TransactionRollbackError, never>;
|
|
58
|
+
}
|
|
59
|
+
export declare class EffectPgTransaction<TQueryResult extends PgQueryResultHKT, TFullSchema extends Record<string, unknown>, TRelations extends AnyRelations, TSchema extends V1.TablesRelationalConfig> extends PgEffectTransaction<TQueryResult, TFullSchema, TRelations, TSchema> {
|
|
60
|
+
static readonly [entityKind]: string;
|
|
61
|
+
transaction<T>(transaction: (tx: PgEffectTransaction<TQueryResult, TFullSchema, TRelations, TSchema>) => Effect.Effect<T, DrizzleQueryError | TransactionRollbackError, never>): Effect.Effect<T, DrizzleQueryError | TransactionRollbackError, never>;
|
|
52
62
|
}
|
|
@@ -4,10 +4,10 @@ import type * as V1 from "../_relations.js";
|
|
|
4
4
|
import type { EffectCache } from "../cache/core/cache-effect.js";
|
|
5
5
|
import type { WithCacheConfig } from "../cache/core/types.js";
|
|
6
6
|
import { entityKind } from "../entity.js";
|
|
7
|
-
import { DrizzleQueryError } from "../errors.js";
|
|
7
|
+
import { DrizzleQueryError, type TransactionRollbackError } from "../errors.js";
|
|
8
8
|
import { type Logger } from "../logger.js";
|
|
9
9
|
import type { PgDialect } from "../pg-core/dialect.js";
|
|
10
|
-
import { PgEffectPreparedQuery, PgEffectSession } from "../pg-core/effect/session.js";
|
|
10
|
+
import { PgEffectPreparedQuery, PgEffectSession, PgEffectTransaction } from "../pg-core/effect/session.js";
|
|
11
11
|
import type { SelectedFieldsOrdered } from "../pg-core/query-builders/select.types.js";
|
|
12
12
|
import type { PgQueryResultHKT, PreparedQueryConfig } from "../pg-core/session.js";
|
|
13
13
|
import type { AnyRelations } from "../relations.js";
|
|
@@ -24,24 +24,29 @@ export declare class EffectPgPreparedQuery<T extends PreparedQueryConfig, TIsRqb
|
|
|
24
24
|
private _isResponseInArrayMode;
|
|
25
25
|
private customResultMapper?;
|
|
26
26
|
private isRqbV2Query?;
|
|
27
|
+
private wrap;
|
|
27
28
|
static readonly [entityKind]: string;
|
|
28
29
|
constructor(client: PgClient, queryString: string, params: unknown[], logger: Logger, cache: EffectCache | undefined, queryMetadata: {
|
|
29
30
|
type: 'select' | 'update' | 'delete' | 'insert';
|
|
30
31
|
tables: string[];
|
|
31
|
-
} | undefined, cacheConfig: WithCacheConfig | undefined, fields: SelectedFieldsOrdered | undefined, name: string | undefined, _isResponseInArrayMode: boolean, customResultMapper?: ((rows: TIsRqbV2 extends true ? Record<string, unknown>[] : unknown[][]) => T["execute"]) | undefined, isRqbV2Query?: TIsRqbV2 | undefined);
|
|
32
|
+
} | undefined, cacheConfig: WithCacheConfig | undefined, fields: SelectedFieldsOrdered | undefined, name: string | undefined, _isResponseInArrayMode: boolean, customResultMapper?: ((rows: TIsRqbV2 extends true ? Record<string, unknown>[] : unknown[][]) => T["execute"]) | undefined, isRqbV2Query?: TIsRqbV2 | undefined, wrap?: Effect.Adapter);
|
|
32
33
|
execute(placeholderValues?: Record<string, unknown>): Effect.Effect<T['execute'], DrizzleQueryError>;
|
|
33
34
|
private executeRqbV2;
|
|
34
35
|
all(placeholderValues?: Record<string, unknown>): Effect.Effect<T['all'], DrizzleQueryError, never>;
|
|
35
36
|
}
|
|
36
|
-
export declare class EffectPgSession<
|
|
37
|
+
export declare class EffectPgSession<TQueryResult extends PgQueryResultHKT, TFullSchema extends Record<string, unknown>, TRelations extends AnyRelations, TSchema extends V1.TablesRelationalConfig> extends PgEffectSession<TQueryResult, TFullSchema, TRelations, TSchema> {
|
|
37
38
|
private client;
|
|
39
|
+
protected relations: TRelations;
|
|
40
|
+
protected schema: V1.RelationalSchemaConfig<TSchema> | undefined;
|
|
41
|
+
private wrap;
|
|
42
|
+
private nestedIndex;
|
|
38
43
|
static readonly [entityKind]: string;
|
|
39
44
|
private logger;
|
|
40
45
|
private cache;
|
|
41
46
|
constructor(client: PgClient, dialect: PgDialect, relations: TRelations, schema: V1.RelationalSchemaConfig<TSchema> | undefined, options?: {
|
|
42
47
|
logger?: Logger;
|
|
43
48
|
cache?: EffectCache;
|
|
44
|
-
});
|
|
49
|
+
}, wrap?: Effect.Adapter, nestedIndex?: number);
|
|
45
50
|
prepareQuery<T extends PreparedQueryConfig = PreparedQueryConfig>(query: Query, fields: SelectedFieldsOrdered | undefined, name: string | undefined, isResponseInArrayMode: boolean, customResultMapper?: (rows: unknown[][]) => T['execute'], queryMetadata?: {
|
|
46
51
|
type: 'select' | 'update' | 'delete' | 'insert';
|
|
47
52
|
tables: string[];
|
|
@@ -49,4 +54,9 @@ export declare class EffectPgSession<_TFullSchema extends Record<string, unknown
|
|
|
49
54
|
prepareRelationalQuery<T extends PreparedQueryConfig = PreparedQueryConfig>(query: Query, fields: SelectedFieldsOrdered | undefined, name: string | undefined, customResultMapper?: (rows: Record<string, unknown>[]) => T['execute']): EffectPgPreparedQuery<T, true>;
|
|
50
55
|
execute<T>(query: SQL): Effect.Effect<T, DrizzleQueryError>;
|
|
51
56
|
all<T>(query: SQL): Effect.Effect<T, DrizzleQueryError>;
|
|
57
|
+
transaction<T>(transaction: (tx: EffectPgTransaction<TQueryResult, TFullSchema, TRelations, TSchema>) => Effect.Effect<T, DrizzleQueryError | TransactionRollbackError, never>): Effect.Effect<T, DrizzleQueryError | TransactionRollbackError, never>;
|
|
58
|
+
}
|
|
59
|
+
export declare class EffectPgTransaction<TQueryResult extends PgQueryResultHKT, TFullSchema extends Record<string, unknown>, TRelations extends AnyRelations, TSchema extends V1.TablesRelationalConfig> extends PgEffectTransaction<TQueryResult, TFullSchema, TRelations, TSchema> {
|
|
60
|
+
static readonly [entityKind]: string;
|
|
61
|
+
transaction<T>(transaction: (tx: PgEffectTransaction<TQueryResult, TFullSchema, TRelations, TSchema>) => Effect.Effect<T, DrizzleQueryError | TransactionRollbackError, never>): Effect.Effect<T, DrizzleQueryError | TransactionRollbackError, never>;
|
|
52
62
|
}
|
|
@@ -2,11 +2,11 @@ import { Effect } from "effect";
|
|
|
2
2
|
import { entityKind } from "../entity.js";
|
|
3
3
|
import { DrizzleQueryError } from "../errors.js";
|
|
4
4
|
import { NoopLogger } from "../logger.js";
|
|
5
|
-
import { PgEffectPreparedQuery, PgEffectSession } from "../pg-core/effect/session.js";
|
|
6
|
-
import { fillPlaceholders } from "../sql/sql.js";
|
|
5
|
+
import { PgEffectPreparedQuery, PgEffectSession, PgEffectTransaction } from "../pg-core/effect/session.js";
|
|
6
|
+
import { fillPlaceholders, sql } from "../sql/sql.js";
|
|
7
7
|
import { mapResultRow } from "../utils.js";
|
|
8
8
|
class EffectPgPreparedQuery extends PgEffectPreparedQuery {
|
|
9
|
-
constructor(client, queryString, params, logger, cache, queryMetadata, cacheConfig, fields, name, _isResponseInArrayMode, customResultMapper, isRqbV2Query) {
|
|
9
|
+
constructor(client, queryString, params, logger, cache, queryMetadata, cacheConfig, fields, name, _isResponseInArrayMode, customResultMapper, isRqbV2Query, wrap = (t) => t) {
|
|
10
10
|
super({ sql: queryString, params }, cache, queryMetadata, cacheConfig);
|
|
11
11
|
this.client = client;
|
|
12
12
|
this.queryString = queryString;
|
|
@@ -16,6 +16,7 @@ class EffectPgPreparedQuery extends PgEffectPreparedQuery {
|
|
|
16
16
|
this._isResponseInArrayMode = _isResponseInArrayMode;
|
|
17
17
|
this.customResultMapper = customResultMapper;
|
|
18
18
|
this.isRqbV2Query = isRqbV2Query;
|
|
19
|
+
this.wrap = wrap;
|
|
19
20
|
}
|
|
20
21
|
static [entityKind] = "EffectPgPreparedQuery";
|
|
21
22
|
execute(placeholderValues) {
|
|
@@ -33,31 +34,35 @@ class EffectPgPreparedQuery extends PgEffectPreparedQuery {
|
|
|
33
34
|
return this.queryWithCache(
|
|
34
35
|
query.sql,
|
|
35
36
|
params,
|
|
36
|
-
|
|
37
|
-
(
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
37
|
+
this.wrap(
|
|
38
|
+
client.unsafe(query.sql, params).values.pipe(Effect.andThen(
|
|
39
|
+
(rows) => {
|
|
40
|
+
if (customResultMapper) return customResultMapper(rows);
|
|
41
|
+
return rows.map(
|
|
42
|
+
(row) => mapResultRow(
|
|
43
|
+
fields,
|
|
44
|
+
row,
|
|
45
|
+
joinsNotNullableMap
|
|
46
|
+
)
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
))
|
|
50
|
+
)
|
|
48
51
|
);
|
|
49
52
|
}
|
|
50
53
|
executeRqbV2(placeholderValues) {
|
|
51
54
|
const { query, logger, customResultMapper, client } = this;
|
|
52
55
|
const params = fillPlaceholders(query.params, placeholderValues ?? {});
|
|
53
56
|
logger.logQuery(query.sql, params);
|
|
54
|
-
return
|
|
55
|
-
|
|
56
|
-
(
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
57
|
+
return this.wrap(
|
|
58
|
+
client.unsafe(query.sql, params).withoutTransform.pipe(
|
|
59
|
+
Effect.andThen(
|
|
60
|
+
(v) => customResultMapper(v)
|
|
61
|
+
)
|
|
62
|
+
).pipe(Effect.catchAll((e) => {
|
|
63
|
+
return Effect.fail(new DrizzleQueryError(query.sql, params, e instanceof Error ? e : void 0));
|
|
64
|
+
}))
|
|
65
|
+
);
|
|
61
66
|
}
|
|
62
67
|
all(placeholderValues) {
|
|
63
68
|
const { query, logger, client } = this;
|
|
@@ -66,7 +71,7 @@ class EffectPgPreparedQuery extends PgEffectPreparedQuery {
|
|
|
66
71
|
return this.queryWithCache(
|
|
67
72
|
query.sql,
|
|
68
73
|
params,
|
|
69
|
-
client.unsafe(query.sql, params).withoutTransform
|
|
74
|
+
this.wrap(client.unsafe(query.sql, params).withoutTransform)
|
|
70
75
|
);
|
|
71
76
|
}
|
|
72
77
|
/** @internal */
|
|
@@ -75,9 +80,13 @@ class EffectPgPreparedQuery extends PgEffectPreparedQuery {
|
|
|
75
80
|
}
|
|
76
81
|
}
|
|
77
82
|
class EffectPgSession extends PgEffectSession {
|
|
78
|
-
constructor(client, dialect, relations, schema, options = {}) {
|
|
83
|
+
constructor(client, dialect, relations, schema, options = {}, wrap = (t) => t, nestedIndex = 0) {
|
|
79
84
|
super(dialect);
|
|
80
85
|
this.client = client;
|
|
86
|
+
this.relations = relations;
|
|
87
|
+
this.schema = schema;
|
|
88
|
+
this.wrap = wrap;
|
|
89
|
+
this.nestedIndex = nestedIndex;
|
|
81
90
|
this.logger = options.logger ?? new NoopLogger();
|
|
82
91
|
this.cache = options.cache;
|
|
83
92
|
}
|
|
@@ -96,7 +105,9 @@ class EffectPgSession extends PgEffectSession {
|
|
|
96
105
|
fields,
|
|
97
106
|
name,
|
|
98
107
|
isResponseInArrayMode,
|
|
99
|
-
customResultMapper
|
|
108
|
+
customResultMapper,
|
|
109
|
+
false,
|
|
110
|
+
this.wrap
|
|
100
111
|
);
|
|
101
112
|
}
|
|
102
113
|
prepareRelationalQuery(query, fields, name, customResultMapper) {
|
|
@@ -112,7 +123,8 @@ class EffectPgSession extends PgEffectSession {
|
|
|
112
123
|
name,
|
|
113
124
|
false,
|
|
114
125
|
customResultMapper,
|
|
115
|
-
true
|
|
126
|
+
true,
|
|
127
|
+
this.wrap
|
|
116
128
|
);
|
|
117
129
|
}
|
|
118
130
|
execute(query) {
|
|
@@ -131,9 +143,47 @@ class EffectPgSession extends PgEffectSession {
|
|
|
131
143
|
false
|
|
132
144
|
).all();
|
|
133
145
|
}
|
|
146
|
+
transaction(transaction) {
|
|
147
|
+
const { dialect, relations, schema, client, logger, cache, nestedIndex } = this;
|
|
148
|
+
const sp = `sp${this.nestedIndex}`;
|
|
149
|
+
return this.client.withTransaction(Effect.gen(function* (txAdapter) {
|
|
150
|
+
const session = new EffectPgSession(
|
|
151
|
+
client,
|
|
152
|
+
dialect,
|
|
153
|
+
relations,
|
|
154
|
+
schema,
|
|
155
|
+
{ logger, cache },
|
|
156
|
+
txAdapter,
|
|
157
|
+
nestedIndex + 1
|
|
158
|
+
);
|
|
159
|
+
const tx = new EffectPgTransaction(
|
|
160
|
+
dialect,
|
|
161
|
+
session,
|
|
162
|
+
relations,
|
|
163
|
+
schema,
|
|
164
|
+
nestedIndex + 1
|
|
165
|
+
);
|
|
166
|
+
if (nestedIndex) yield* tx.execute(sql.raw(`savepoint ${sp}`));
|
|
167
|
+
const res = yield* transaction(tx).pipe(Effect.catchAll(
|
|
168
|
+
(e) => Effect.gen(function* () {
|
|
169
|
+
if (nestedIndex) yield* tx.execute(sql.raw(`rollback to savepoint ${sp}`));
|
|
170
|
+
return yield* Effect.fail(e);
|
|
171
|
+
})
|
|
172
|
+
));
|
|
173
|
+
if (nestedIndex) yield* tx.execute(sql.raw(`release savepoint ${sp}`));
|
|
174
|
+
return res;
|
|
175
|
+
}));
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
class EffectPgTransaction extends PgEffectTransaction {
|
|
179
|
+
static [entityKind] = "EffectPgTransaction";
|
|
180
|
+
transaction(transaction) {
|
|
181
|
+
return this.session.transaction(transaction);
|
|
182
|
+
}
|
|
134
183
|
}
|
|
135
184
|
export {
|
|
136
185
|
EffectPgPreparedQuery,
|
|
137
|
-
EffectPgSession
|
|
186
|
+
EffectPgSession,
|
|
187
|
+
EffectPgTransaction
|
|
138
188
|
};
|
|
139
189
|
//# sourceMappingURL=session.js.map
|