@fragno-dev/db 0.1.13 → 0.1.15
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/.turbo/turbo-build.log +179 -132
- package/CHANGELOG.md +30 -0
- package/dist/adapters/adapters.d.ts +27 -1
- package/dist/adapters/adapters.d.ts.map +1 -1
- package/dist/adapters/adapters.js.map +1 -1
- package/dist/adapters/drizzle/drizzle-adapter.d.ts +5 -1
- package/dist/adapters/drizzle/drizzle-adapter.d.ts.map +1 -1
- package/dist/adapters/drizzle/drizzle-adapter.js +15 -3
- package/dist/adapters/drizzle/drizzle-adapter.js.map +1 -1
- package/dist/adapters/drizzle/drizzle-query.js +7 -5
- package/dist/adapters/drizzle/drizzle-query.js.map +1 -1
- package/dist/adapters/drizzle/drizzle-uow-compiler.d.ts +0 -1
- package/dist/adapters/drizzle/drizzle-uow-compiler.d.ts.map +1 -1
- package/dist/adapters/drizzle/drizzle-uow-compiler.js +76 -44
- package/dist/adapters/drizzle/drizzle-uow-compiler.js.map +1 -1
- package/dist/adapters/drizzle/drizzle-uow-decoder.js +23 -16
- package/dist/adapters/drizzle/drizzle-uow-decoder.js.map +1 -1
- package/dist/adapters/drizzle/drizzle-uow-executor.js +18 -7
- package/dist/adapters/drizzle/drizzle-uow-executor.js.map +1 -1
- package/dist/adapters/drizzle/generate.d.ts +4 -1
- package/dist/adapters/drizzle/generate.d.ts.map +1 -1
- package/dist/adapters/drizzle/generate.js +11 -18
- package/dist/adapters/drizzle/generate.js.map +1 -1
- package/dist/adapters/drizzle/shared.d.ts +14 -1
- package/dist/adapters/drizzle/shared.d.ts.map +1 -0
- package/dist/adapters/kysely/kysely-adapter.d.ts +5 -1
- package/dist/adapters/kysely/kysely-adapter.d.ts.map +1 -1
- package/dist/adapters/kysely/kysely-adapter.js +14 -3
- package/dist/adapters/kysely/kysely-adapter.js.map +1 -1
- package/dist/adapters/kysely/kysely-query-builder.js +1 -1
- package/dist/adapters/kysely/kysely-query-compiler.js +3 -2
- package/dist/adapters/kysely/kysely-query-compiler.js.map +1 -1
- package/dist/adapters/kysely/kysely-query.d.ts +1 -0
- package/dist/adapters/kysely/kysely-query.d.ts.map +1 -1
- package/dist/adapters/kysely/kysely-query.js +28 -19
- package/dist/adapters/kysely/kysely-query.js.map +1 -1
- package/dist/adapters/kysely/kysely-shared.d.ts +14 -0
- package/dist/adapters/kysely/kysely-shared.d.ts.map +1 -0
- package/dist/adapters/kysely/kysely-shared.js +16 -1
- package/dist/adapters/kysely/kysely-shared.js.map +1 -1
- package/dist/adapters/kysely/kysely-uow-compiler.js +68 -16
- package/dist/adapters/kysely/kysely-uow-compiler.js.map +1 -1
- package/dist/adapters/kysely/kysely-uow-executor.js +8 -4
- package/dist/adapters/kysely/kysely-uow-executor.js.map +1 -1
- package/dist/adapters/kysely/migration/execute-base.js +1 -1
- package/dist/adapters/kysely/migration/execute-base.js.map +1 -1
- package/dist/db-fragment-definition-builder.d.ts +152 -0
- package/dist/db-fragment-definition-builder.d.ts.map +1 -0
- package/dist/db-fragment-definition-builder.js +137 -0
- package/dist/db-fragment-definition-builder.js.map +1 -0
- package/dist/fragments/internal-fragment.d.ts +19 -0
- package/dist/fragments/internal-fragment.d.ts.map +1 -0
- package/dist/fragments/internal-fragment.js +39 -0
- package/dist/fragments/internal-fragment.js.map +1 -0
- package/dist/migration-engine/generation-engine.d.ts.map +1 -1
- package/dist/migration-engine/generation-engine.js +35 -15
- package/dist/migration-engine/generation-engine.js.map +1 -1
- package/dist/mod.d.ts +8 -18
- package/dist/mod.d.ts.map +1 -1
- package/dist/mod.js +7 -34
- package/dist/mod.js.map +1 -1
- package/dist/node_modules/.pnpm/rou3@0.7.8/node_modules/rou3/dist/index.js +165 -0
- package/dist/node_modules/.pnpm/rou3@0.7.8/node_modules/rou3/dist/index.js.map +1 -0
- package/dist/packages/fragno/dist/api/bind-services.js +20 -0
- package/dist/packages/fragno/dist/api/bind-services.js.map +1 -0
- package/dist/packages/fragno/dist/api/error.js +48 -0
- package/dist/packages/fragno/dist/api/error.js.map +1 -0
- package/dist/packages/fragno/dist/api/fragment-definition-builder.js +320 -0
- package/dist/packages/fragno/dist/api/fragment-definition-builder.js.map +1 -0
- package/dist/packages/fragno/dist/api/fragment-instantiator.js +487 -0
- package/dist/packages/fragno/dist/api/fragment-instantiator.js.map +1 -0
- package/dist/packages/fragno/dist/api/fragno-response.js +73 -0
- package/dist/packages/fragno/dist/api/fragno-response.js.map +1 -0
- package/dist/packages/fragno/dist/api/internal/response-stream.js +81 -0
- package/dist/packages/fragno/dist/api/internal/response-stream.js.map +1 -0
- package/dist/packages/fragno/dist/api/internal/route.js +10 -0
- package/dist/packages/fragno/dist/api/internal/route.js.map +1 -0
- package/dist/packages/fragno/dist/api/mutable-request-state.js +97 -0
- package/dist/packages/fragno/dist/api/mutable-request-state.js.map +1 -0
- package/dist/packages/fragno/dist/api/request-context-storage.js +43 -0
- package/dist/packages/fragno/dist/api/request-context-storage.js.map +1 -0
- package/dist/packages/fragno/dist/api/request-input-context.js +118 -0
- package/dist/packages/fragno/dist/api/request-input-context.js.map +1 -0
- package/dist/packages/fragno/dist/api/request-middleware.js +83 -0
- package/dist/packages/fragno/dist/api/request-middleware.js.map +1 -0
- package/dist/packages/fragno/dist/api/request-output-context.js +119 -0
- package/dist/packages/fragno/dist/api/request-output-context.js.map +1 -0
- package/dist/packages/fragno/dist/api/route.js +17 -0
- package/dist/packages/fragno/dist/api/route.js.map +1 -0
- package/dist/packages/fragno/dist/internal/symbols.js +10 -0
- package/dist/packages/fragno/dist/internal/symbols.js.map +1 -0
- package/dist/query/cursor.d.ts +10 -2
- package/dist/query/cursor.d.ts.map +1 -1
- package/dist/query/cursor.js +11 -4
- package/dist/query/cursor.js.map +1 -1
- package/dist/query/execute-unit-of-work.d.ts +123 -0
- package/dist/query/execute-unit-of-work.d.ts.map +1 -0
- package/dist/query/execute-unit-of-work.js +184 -0
- package/dist/query/execute-unit-of-work.js.map +1 -0
- package/dist/query/query.d.ts +3 -3
- package/dist/query/query.d.ts.map +1 -1
- package/dist/query/result-transform.js +4 -2
- package/dist/query/result-transform.js.map +1 -1
- package/dist/query/retry-policy.d.ts +88 -0
- package/dist/query/retry-policy.d.ts.map +1 -0
- package/dist/query/retry-policy.js +61 -0
- package/dist/query/retry-policy.js.map +1 -0
- package/dist/query/unit-of-work.d.ts +171 -32
- package/dist/query/unit-of-work.d.ts.map +1 -1
- package/dist/query/unit-of-work.js +530 -133
- package/dist/query/unit-of-work.js.map +1 -1
- package/dist/schema/serialize.js +12 -7
- package/dist/schema/serialize.js.map +1 -1
- package/dist/with-database.d.ts +28 -0
- package/dist/with-database.d.ts.map +1 -0
- package/dist/with-database.js +34 -0
- package/dist/with-database.js.map +1 -0
- package/package.json +10 -3
- package/src/adapters/adapters.ts +30 -0
- package/src/adapters/drizzle/drizzle-adapter-pglite.test.ts +86 -17
- package/src/adapters/drizzle/drizzle-adapter-sqlite.test.ts +291 -7
- package/src/adapters/drizzle/drizzle-adapter.test.ts +3 -51
- package/src/adapters/drizzle/drizzle-adapter.ts +35 -7
- package/src/adapters/drizzle/drizzle-query.ts +25 -15
- package/src/adapters/drizzle/drizzle-uow-compiler-mysql.test.ts +1442 -0
- package/src/adapters/drizzle/drizzle-uow-compiler-sqlite.test.ts +1414 -0
- package/src/adapters/drizzle/drizzle-uow-compiler.test.ts +78 -61
- package/src/adapters/drizzle/drizzle-uow-compiler.ts +123 -42
- package/src/adapters/drizzle/drizzle-uow-decoder.ts +34 -27
- package/src/adapters/drizzle/drizzle-uow-executor.ts +41 -8
- package/src/adapters/drizzle/generate.test.ts +102 -269
- package/src/adapters/drizzle/generate.ts +12 -30
- package/src/adapters/drizzle/test-utils.ts +36 -5
- package/src/adapters/kysely/kysely-adapter-pglite.test.ts +66 -22
- package/src/adapters/kysely/kysely-adapter-sqlite.test.ts +156 -0
- package/src/adapters/kysely/kysely-adapter.ts +25 -2
- package/src/adapters/kysely/kysely-query-compiler.ts +3 -8
- package/src/adapters/kysely/kysely-query.ts +57 -37
- package/src/adapters/kysely/kysely-shared.ts +34 -0
- package/src/adapters/kysely/kysely-uow-compiler.test.ts +62 -74
- package/src/adapters/kysely/kysely-uow-compiler.ts +92 -24
- package/src/adapters/kysely/kysely-uow-executor.ts +26 -7
- package/src/adapters/kysely/kysely-uow-joins.test.ts +33 -50
- package/src/adapters/kysely/migration/execute-base.ts +1 -1
- package/src/db-fragment-definition-builder.test.ts +887 -0
- package/src/db-fragment-definition-builder.ts +506 -0
- package/src/db-fragment-instantiator.test.ts +467 -0
- package/src/db-fragment-integration.test.ts +408 -0
- package/src/fragments/internal-fragment.test.ts +160 -0
- package/src/fragments/internal-fragment.ts +85 -0
- package/src/migration-engine/generation-engine.test.ts +58 -15
- package/src/migration-engine/generation-engine.ts +78 -25
- package/src/mod.ts +35 -43
- package/src/query/cursor.test.ts +119 -0
- package/src/query/cursor.ts +17 -4
- package/src/query/execute-unit-of-work.test.ts +1310 -0
- package/src/query/execute-unit-of-work.ts +463 -0
- package/src/query/query.ts +4 -4
- package/src/query/result-transform.test.ts +129 -0
- package/src/query/result-transform.ts +4 -1
- package/src/query/retry-policy.test.ts +217 -0
- package/src/query/retry-policy.ts +141 -0
- package/src/query/unit-of-work-coordinator.test.ts +833 -0
- package/src/query/unit-of-work-types.test.ts +15 -2
- package/src/query/unit-of-work.test.ts +878 -200
- package/src/query/unit-of-work.ts +963 -321
- package/src/schema/serialize.ts +22 -11
- package/src/with-database.ts +140 -0
- package/tsdown.config.ts +1 -0
- package/dist/fragment.d.ts +0 -54
- package/dist/fragment.d.ts.map +0 -1
- package/dist/fragment.js +0 -92
- package/dist/fragment.js.map +0 -1
- package/dist/shared/settings-schema.js +0 -36
- package/dist/shared/settings-schema.js.map +0 -1
- package/src/fragment.test.ts +0 -341
- package/src/fragment.ts +0 -198
- package/src/shared/settings-schema.ts +0 -61
|
@@ -74,37 +74,37 @@ describe("drizzle-uow-compiler", () => {
|
|
|
74
74
|
});
|
|
75
75
|
|
|
76
76
|
function createTestUOWWithSchema<const T extends AnySchema>(schema: T) {
|
|
77
|
-
const compiler = createDrizzleUOWCompiler(
|
|
77
|
+
const compiler = createDrizzleUOWCompiler(pool, "postgresql");
|
|
78
78
|
const mockExecutor = {
|
|
79
79
|
executeRetrievalPhase: async () => [],
|
|
80
80
|
executeMutationPhase: async () => ({ success: true, createdInternalIds: [] }),
|
|
81
81
|
};
|
|
82
|
-
const mockDecoder: UOWDecoder
|
|
82
|
+
const mockDecoder: UOWDecoder = (rawResults, operations) => {
|
|
83
83
|
if (rawResults.length !== operations.length) {
|
|
84
84
|
throw new Error("rawResults and ops must have the same length");
|
|
85
85
|
}
|
|
86
86
|
return rawResults;
|
|
87
87
|
};
|
|
88
|
-
return new UnitOfWork(
|
|
88
|
+
return new UnitOfWork(compiler, mockExecutor, mockDecoder).forSchema(schema);
|
|
89
89
|
}
|
|
90
90
|
|
|
91
91
|
function createTestUOW(name?: string) {
|
|
92
|
-
const compiler = createDrizzleUOWCompiler(
|
|
92
|
+
const compiler = createDrizzleUOWCompiler(pool, "postgresql");
|
|
93
93
|
const mockExecutor = {
|
|
94
94
|
executeRetrievalPhase: async () => [],
|
|
95
95
|
executeMutationPhase: async () => ({ success: true, createdInternalIds: [] }),
|
|
96
96
|
};
|
|
97
|
-
const mockDecoder: UOWDecoder
|
|
97
|
+
const mockDecoder: UOWDecoder = (rawResults, operations) => {
|
|
98
98
|
if (rawResults.length !== operations.length) {
|
|
99
99
|
throw new Error("rawResults and ops must have the same length");
|
|
100
100
|
}
|
|
101
101
|
return rawResults;
|
|
102
102
|
};
|
|
103
|
-
return new UnitOfWork(
|
|
103
|
+
return new UnitOfWork(compiler, mockExecutor, mockDecoder, name).forSchema(testSchema);
|
|
104
104
|
}
|
|
105
105
|
|
|
106
106
|
it("should create a compiler with the correct structure", () => {
|
|
107
|
-
const compiler = createDrizzleUOWCompiler(
|
|
107
|
+
const compiler = createDrizzleUOWCompiler(pool, "postgresql");
|
|
108
108
|
|
|
109
109
|
expect(compiler).toBeDefined();
|
|
110
110
|
expect(compiler.compileRetrievalOperation).toBeInstanceOf(Function);
|
|
@@ -118,7 +118,7 @@ describe("drizzle-uow-compiler", () => {
|
|
|
118
118
|
b.whereIndex("idx_email", (eb) => eb("email", "=", "test@example.com")),
|
|
119
119
|
);
|
|
120
120
|
|
|
121
|
-
const compiler = createDrizzleUOWCompiler(
|
|
121
|
+
const compiler = createDrizzleUOWCompiler(pool, "postgresql");
|
|
122
122
|
const compiled = uow.compile(compiler);
|
|
123
123
|
|
|
124
124
|
expect(compiled.retrievalBatch).toHaveLength(1);
|
|
@@ -134,7 +134,7 @@ describe("drizzle-uow-compiler", () => {
|
|
|
134
134
|
b.whereIndex("idx_name", (eb) => eb("name", "=", "Alice")).select(["id", "name"]),
|
|
135
135
|
);
|
|
136
136
|
|
|
137
|
-
const compiler = createDrizzleUOWCompiler(
|
|
137
|
+
const compiler = createDrizzleUOWCompiler(pool, "postgresql");
|
|
138
138
|
const compiled = uow.compile(compiler);
|
|
139
139
|
|
|
140
140
|
expect(compiled.retrievalBatch).toHaveLength(1);
|
|
@@ -148,7 +148,7 @@ describe("drizzle-uow-compiler", () => {
|
|
|
148
148
|
const uow = createTestUOW();
|
|
149
149
|
uow.find("users", (b) => b.whereIndex("primary").pageSize(10));
|
|
150
150
|
|
|
151
|
-
const compiler = createDrizzleUOWCompiler(
|
|
151
|
+
const compiler = createDrizzleUOWCompiler(pool, "postgresql");
|
|
152
152
|
const compiled = uow.compile(compiler);
|
|
153
153
|
|
|
154
154
|
expect(compiled.retrievalBatch).toHaveLength(1);
|
|
@@ -162,7 +162,7 @@ describe("drizzle-uow-compiler", () => {
|
|
|
162
162
|
const uow = createTestUOW();
|
|
163
163
|
uow.find("users", (b) => b.whereIndex("primary").orderByIndex("primary", "desc"));
|
|
164
164
|
|
|
165
|
-
const compiler = createDrizzleUOWCompiler(
|
|
165
|
+
const compiler = createDrizzleUOWCompiler(pool, "postgresql");
|
|
166
166
|
const compiled = uow.compile(compiler);
|
|
167
167
|
|
|
168
168
|
expect(compiled.retrievalBatch).toHaveLength(1);
|
|
@@ -175,7 +175,7 @@ describe("drizzle-uow-compiler", () => {
|
|
|
175
175
|
const uow = createTestUOW();
|
|
176
176
|
uow.find("users", (b) => b.whereIndex("idx_name").orderByIndex("idx_name", "desc"));
|
|
177
177
|
|
|
178
|
-
const compiler = createDrizzleUOWCompiler(
|
|
178
|
+
const compiler = createDrizzleUOWCompiler(pool, "postgresql");
|
|
179
179
|
const compiled = uow.compile(compiler);
|
|
180
180
|
|
|
181
181
|
expect(compiled.retrievalBatch).toHaveLength(1);
|
|
@@ -191,7 +191,7 @@ describe("drizzle-uow-compiler", () => {
|
|
|
191
191
|
);
|
|
192
192
|
uow.find("posts", (b) => b.whereIndex("idx_title", (eb) => eb("title", "contains", "test")));
|
|
193
193
|
|
|
194
|
-
const compiler = createDrizzleUOWCompiler(
|
|
194
|
+
const compiler = createDrizzleUOWCompiler(pool, "postgresql");
|
|
195
195
|
const compiled = uow.compile(compiler);
|
|
196
196
|
|
|
197
197
|
expect(compiled.retrievalBatch).toHaveLength(2);
|
|
@@ -207,7 +207,7 @@ describe("drizzle-uow-compiler", () => {
|
|
|
207
207
|
const uow = createTestUOW();
|
|
208
208
|
uow.find("users", (b) => b.whereIndex("primary").selectCount());
|
|
209
209
|
|
|
210
|
-
const compiler = createDrizzleUOWCompiler(
|
|
210
|
+
const compiler = createDrizzleUOWCompiler(pool, "postgresql");
|
|
211
211
|
const compiled = uow.compile(compiler);
|
|
212
212
|
|
|
213
213
|
expect(compiled.retrievalBatch).toHaveLength(1);
|
|
@@ -222,7 +222,7 @@ describe("drizzle-uow-compiler", () => {
|
|
|
222
222
|
b.whereIndex("idx_name", (eb) => eb("name", "starts with", "John")).selectCount(),
|
|
223
223
|
);
|
|
224
224
|
|
|
225
|
-
const compiler = createDrizzleUOWCompiler(
|
|
225
|
+
const compiler = createDrizzleUOWCompiler(pool, "postgresql");
|
|
226
226
|
const compiled = uow.compile(compiler);
|
|
227
227
|
|
|
228
228
|
expect(compiled.retrievalBatch).toHaveLength(1);
|
|
@@ -244,7 +244,7 @@ describe("drizzle-uow-compiler", () => {
|
|
|
244
244
|
b.whereIndex("idx_name").orderByIndex("idx_name", "asc").after(cursor).pageSize(10),
|
|
245
245
|
);
|
|
246
246
|
|
|
247
|
-
const compiler = createDrizzleUOWCompiler(
|
|
247
|
+
const compiler = createDrizzleUOWCompiler(pool, "postgresql");
|
|
248
248
|
const compiled = uow.compile(compiler);
|
|
249
249
|
|
|
250
250
|
expect(compiled.retrievalBatch).toHaveLength(1);
|
|
@@ -266,7 +266,7 @@ describe("drizzle-uow-compiler", () => {
|
|
|
266
266
|
b.whereIndex("idx_name").orderByIndex("idx_name", "desc").before(cursor).pageSize(10),
|
|
267
267
|
);
|
|
268
268
|
|
|
269
|
-
const compiler = createDrizzleUOWCompiler(
|
|
269
|
+
const compiler = createDrizzleUOWCompiler(pool, "postgresql");
|
|
270
270
|
const compiled = uow.compile(compiler);
|
|
271
271
|
|
|
272
272
|
expect(compiled.retrievalBatch).toHaveLength(1);
|
|
@@ -292,7 +292,7 @@ describe("drizzle-uow-compiler", () => {
|
|
|
292
292
|
.pageSize(5),
|
|
293
293
|
);
|
|
294
294
|
|
|
295
|
-
const compiler = createDrizzleUOWCompiler(
|
|
295
|
+
const compiler = createDrizzleUOWCompiler(pool, "postgresql");
|
|
296
296
|
const compiled = uow.compile(compiler);
|
|
297
297
|
|
|
298
298
|
expect(compiled.retrievalBatch).toHaveLength(1);
|
|
@@ -310,7 +310,7 @@ describe("drizzle-uow-compiler", () => {
|
|
|
310
310
|
.join((jb) => jb.author()),
|
|
311
311
|
);
|
|
312
312
|
|
|
313
|
-
const compiler = createDrizzleUOWCompiler(
|
|
313
|
+
const compiler = createDrizzleUOWCompiler(pool, "postgresql");
|
|
314
314
|
const compiled = uow.compile(compiler);
|
|
315
315
|
|
|
316
316
|
expect(compiled.retrievalBatch).toHaveLength(1);
|
|
@@ -333,7 +333,7 @@ describe("drizzle-uow-compiler", () => {
|
|
|
333
333
|
),
|
|
334
334
|
);
|
|
335
335
|
|
|
336
|
-
const compiler = createDrizzleUOWCompiler(
|
|
336
|
+
const compiler = createDrizzleUOWCompiler(pool, "postgresql");
|
|
337
337
|
const compiled = uow.compile(compiler);
|
|
338
338
|
|
|
339
339
|
expect(compiled.retrievalBatch).toHaveLength(1);
|
|
@@ -351,7 +351,7 @@ describe("drizzle-uow-compiler", () => {
|
|
|
351
351
|
.join((jb) => jb.author((builder) => builder.orderByIndex("idx_name", "desc"))),
|
|
352
352
|
);
|
|
353
353
|
|
|
354
|
-
const compiler = createDrizzleUOWCompiler(
|
|
354
|
+
const compiler = createDrizzleUOWCompiler(pool, "postgresql");
|
|
355
355
|
const compiled = uow.compile(compiler);
|
|
356
356
|
|
|
357
357
|
expect(compiled.retrievalBatch).toHaveLength(1);
|
|
@@ -367,7 +367,7 @@ describe("drizzle-uow-compiler", () => {
|
|
|
367
367
|
b.whereIndex("primary").join((jb) => jb.author((builder) => builder.pageSize(5))),
|
|
368
368
|
);
|
|
369
369
|
|
|
370
|
-
const compiler = createDrizzleUOWCompiler(
|
|
370
|
+
const compiler = createDrizzleUOWCompiler(pool, "postgresql");
|
|
371
371
|
const compiled = uow.compile(compiler);
|
|
372
372
|
|
|
373
373
|
expect(compiled.retrievalBatch).toHaveLength(1);
|
|
@@ -388,7 +388,7 @@ describe("drizzle-uow-compiler", () => {
|
|
|
388
388
|
age: 30,
|
|
389
389
|
});
|
|
390
390
|
|
|
391
|
-
const compiler = createDrizzleUOWCompiler(
|
|
391
|
+
const compiler = createDrizzleUOWCompiler(pool, "postgresql");
|
|
392
392
|
const compiled = uow.compile(compiler);
|
|
393
393
|
const [batch] = compiled.mutationBatch;
|
|
394
394
|
assert(batch);
|
|
@@ -414,7 +414,7 @@ describe("drizzle-uow-compiler", () => {
|
|
|
414
414
|
viewCount: 5,
|
|
415
415
|
});
|
|
416
416
|
|
|
417
|
-
const compiler = createDrizzleUOWCompiler(
|
|
417
|
+
const compiler = createDrizzleUOWCompiler(pool, "postgresql");
|
|
418
418
|
const compiled = uow.compile(compiler);
|
|
419
419
|
const [batch] = compiled.mutationBatch;
|
|
420
420
|
assert(batch);
|
|
@@ -440,7 +440,7 @@ describe("drizzle-uow-compiler", () => {
|
|
|
440
440
|
userId: 12345n,
|
|
441
441
|
});
|
|
442
442
|
|
|
443
|
-
const compiler = createDrizzleUOWCompiler(
|
|
443
|
+
const compiler = createDrizzleUOWCompiler(pool, "postgresql");
|
|
444
444
|
const compiled = uow.compile(compiler);
|
|
445
445
|
const [batch] = compiled.mutationBatch;
|
|
446
446
|
assert(batch);
|
|
@@ -468,7 +468,7 @@ describe("drizzle-uow-compiler", () => {
|
|
|
468
468
|
userId,
|
|
469
469
|
});
|
|
470
470
|
|
|
471
|
-
const compiler = createDrizzleUOWCompiler(
|
|
471
|
+
const compiler = createDrizzleUOWCompiler(pool, "postgresql");
|
|
472
472
|
const compiled = uow.compile(compiler);
|
|
473
473
|
const [batch] = compiled.mutationBatch;
|
|
474
474
|
assert(batch);
|
|
@@ -488,7 +488,7 @@ describe("drizzle-uow-compiler", () => {
|
|
|
488
488
|
}),
|
|
489
489
|
);
|
|
490
490
|
|
|
491
|
-
const compiler = createDrizzleUOWCompiler(
|
|
491
|
+
const compiler = createDrizzleUOWCompiler(pool, "postgresql");
|
|
492
492
|
const compiled = uow.compile(compiler);
|
|
493
493
|
const [batch] = compiled.mutationBatch;
|
|
494
494
|
assert(batch);
|
|
@@ -512,7 +512,7 @@ describe("drizzle-uow-compiler", () => {
|
|
|
512
512
|
}),
|
|
513
513
|
);
|
|
514
514
|
|
|
515
|
-
const compiler = createDrizzleUOWCompiler(
|
|
515
|
+
const compiler = createDrizzleUOWCompiler(pool, "postgresql");
|
|
516
516
|
const compiled = uow.compile(compiler);
|
|
517
517
|
const [batch] = compiled.mutationBatch;
|
|
518
518
|
assert(batch);
|
|
@@ -538,7 +538,7 @@ describe("drizzle-uow-compiler", () => {
|
|
|
538
538
|
}),
|
|
539
539
|
);
|
|
540
540
|
|
|
541
|
-
const compiler = createDrizzleUOWCompiler(
|
|
541
|
+
const compiler = createDrizzleUOWCompiler(pool, "postgresql");
|
|
542
542
|
const compiled = uow.compile(compiler);
|
|
543
543
|
const [batch] = compiled.mutationBatch;
|
|
544
544
|
assert(batch);
|
|
@@ -554,7 +554,7 @@ describe("drizzle-uow-compiler", () => {
|
|
|
554
554
|
const userId = FragnoId.fromExternal("user123", 5);
|
|
555
555
|
uow.update("users", userId, (b) => b.set({ age: 18 }).check());
|
|
556
556
|
|
|
557
|
-
const compiler = createDrizzleUOWCompiler(
|
|
557
|
+
const compiler = createDrizzleUOWCompiler(pool, "postgresql");
|
|
558
558
|
const compiled = uow.compile(compiler);
|
|
559
559
|
const [batch] = compiled.mutationBatch;
|
|
560
560
|
assert(batch);
|
|
@@ -570,7 +570,7 @@ describe("drizzle-uow-compiler", () => {
|
|
|
570
570
|
const userId = FragnoId.fromExternal("user123", 0);
|
|
571
571
|
uow.delete("users", userId);
|
|
572
572
|
|
|
573
|
-
const compiler = createDrizzleUOWCompiler(
|
|
573
|
+
const compiler = createDrizzleUOWCompiler(pool, "postgresql");
|
|
574
574
|
const compiled = uow.compile(compiler);
|
|
575
575
|
const [batch] = compiled.mutationBatch;
|
|
576
576
|
assert(batch);
|
|
@@ -586,7 +586,7 @@ describe("drizzle-uow-compiler", () => {
|
|
|
586
586
|
const userId = FragnoId.fromExternal("user123", 3);
|
|
587
587
|
uow.delete("users", userId, (b) => b.check());
|
|
588
588
|
|
|
589
|
-
const compiler = createDrizzleUOWCompiler(
|
|
589
|
+
const compiler = createDrizzleUOWCompiler(pool, "postgresql");
|
|
590
590
|
const compiled = uow.compile(compiler);
|
|
591
591
|
const [batch] = compiled.mutationBatch;
|
|
592
592
|
assert(batch);
|
|
@@ -606,7 +606,7 @@ describe("drizzle-uow-compiler", () => {
|
|
|
606
606
|
}),
|
|
607
607
|
);
|
|
608
608
|
|
|
609
|
-
const compiler = createDrizzleUOWCompiler(
|
|
609
|
+
const compiler = createDrizzleUOWCompiler(pool, "postgresql");
|
|
610
610
|
const compiled = uow.compile(compiler);
|
|
611
611
|
const [batch] = compiled.mutationBatch;
|
|
612
612
|
assert(batch);
|
|
@@ -621,7 +621,7 @@ describe("drizzle-uow-compiler", () => {
|
|
|
621
621
|
const uow = createTestUOW();
|
|
622
622
|
uow.delete("users", "user123");
|
|
623
623
|
|
|
624
|
-
const compiler = createDrizzleUOWCompiler(
|
|
624
|
+
const compiler = createDrizzleUOWCompiler(pool, "postgresql");
|
|
625
625
|
const compiled = uow.compile(compiler);
|
|
626
626
|
const [batch] = compiled.mutationBatch;
|
|
627
627
|
assert(batch);
|
|
@@ -661,7 +661,7 @@ describe("drizzle-uow-compiler", () => {
|
|
|
661
661
|
const userId = FragnoId.fromExternal("user456", 0);
|
|
662
662
|
uow.delete("posts", userId);
|
|
663
663
|
|
|
664
|
-
const compiler = createDrizzleUOWCompiler(
|
|
664
|
+
const compiler = createDrizzleUOWCompiler(pool, "postgresql");
|
|
665
665
|
const compiled = uow.compile(compiler);
|
|
666
666
|
const [createBatch, updateBatch, deleteBatch] = compiled.mutationBatch;
|
|
667
667
|
|
|
@@ -700,7 +700,7 @@ describe("drizzle-uow-compiler", () => {
|
|
|
700
700
|
const userId = FragnoId.fromExternal("user123", 3);
|
|
701
701
|
uow.update("users", userId, (b) => b.set({ age: 31 }).check());
|
|
702
702
|
|
|
703
|
-
const compiler = createDrizzleUOWCompiler(
|
|
703
|
+
const compiler = createDrizzleUOWCompiler(pool, "postgresql");
|
|
704
704
|
const compiled = uow.compile(compiler);
|
|
705
705
|
|
|
706
706
|
expect(compiled.name).toBe("update-user-balance");
|
|
@@ -732,7 +732,7 @@ describe("drizzle-uow-compiler", () => {
|
|
|
732
732
|
),
|
|
733
733
|
);
|
|
734
734
|
|
|
735
|
-
const compiler = createDrizzleUOWCompiler(
|
|
735
|
+
const compiler = createDrizzleUOWCompiler(pool, "postgresql");
|
|
736
736
|
const compiled = uow.compile(compiler);
|
|
737
737
|
|
|
738
738
|
expect(compiled.retrievalBatch).toHaveLength(1);
|
|
@@ -746,7 +746,7 @@ describe("drizzle-uow-compiler", () => {
|
|
|
746
746
|
const uow = createTestUOW();
|
|
747
747
|
uow.find("users", (b) => b.whereIndex("primary", () => false));
|
|
748
748
|
|
|
749
|
-
const compiler = createDrizzleUOWCompiler(
|
|
749
|
+
const compiler = createDrizzleUOWCompiler(pool, "postgresql");
|
|
750
750
|
const compiled = uow.compile(compiler);
|
|
751
751
|
|
|
752
752
|
// When condition is false, the operation should return null and not be added to batch
|
|
@@ -757,7 +757,7 @@ describe("drizzle-uow-compiler", () => {
|
|
|
757
757
|
const uow = createTestUOW();
|
|
758
758
|
uow.find("users", (b) => b.whereIndex("primary", () => true));
|
|
759
759
|
|
|
760
|
-
const compiler = createDrizzleUOWCompiler(
|
|
760
|
+
const compiler = createDrizzleUOWCompiler(pool, "postgresql");
|
|
761
761
|
const compiled = uow.compile(compiler);
|
|
762
762
|
|
|
763
763
|
expect(compiled.retrievalBatch).toHaveLength(1);
|
|
@@ -774,7 +774,7 @@ describe("drizzle-uow-compiler", () => {
|
|
|
774
774
|
const userId = FragnoId.fromExternal("user123", 5);
|
|
775
775
|
uow.update("users", userId, (b) => b.set({ age: 31 }).check());
|
|
776
776
|
|
|
777
|
-
const compiler = createDrizzleUOWCompiler(
|
|
777
|
+
const compiler = createDrizzleUOWCompiler(pool, "postgresql");
|
|
778
778
|
const compiled = uow.compile(compiler);
|
|
779
779
|
const [batch] = compiled.mutationBatch;
|
|
780
780
|
assert(batch);
|
|
@@ -791,7 +791,7 @@ describe("drizzle-uow-compiler", () => {
|
|
|
791
791
|
const userId = FragnoId.fromExternal("user456", 3);
|
|
792
792
|
uow.delete("users", userId, (b) => b.check());
|
|
793
793
|
|
|
794
|
-
const compiler = createDrizzleUOWCompiler(
|
|
794
|
+
const compiler = createDrizzleUOWCompiler(pool, "postgresql");
|
|
795
795
|
const compiled = uow.compile(compiler);
|
|
796
796
|
const [batch] = compiled.mutationBatch;
|
|
797
797
|
assert(batch);
|
|
@@ -811,7 +811,7 @@ describe("drizzle-uow-compiler", () => {
|
|
|
811
811
|
uow.update("users", userId, (b) => b.set({ age: 30 }).check());
|
|
812
812
|
uow.update("posts", postId, (b) => b.set({ viewCount: 100 }).check());
|
|
813
813
|
|
|
814
|
-
const compiler = createDrizzleUOWCompiler(
|
|
814
|
+
const compiler = createDrizzleUOWCompiler(pool, "postgresql");
|
|
815
815
|
const compiled = uow.compile(compiler);
|
|
816
816
|
const [userBatch, postBatch] = compiled.mutationBatch;
|
|
817
817
|
|
|
@@ -838,7 +838,7 @@ describe("drizzle-uow-compiler", () => {
|
|
|
838
838
|
const userId = FragnoId.fromExternal("user1", 0);
|
|
839
839
|
uow.update("users", userId, (b) => b.set({ age: 25 }));
|
|
840
840
|
|
|
841
|
-
const compiler = createDrizzleUOWCompiler(
|
|
841
|
+
const compiler = createDrizzleUOWCompiler(pool, "postgresql");
|
|
842
842
|
const compiled = uow.compile(compiler);
|
|
843
843
|
const [batch] = compiled.mutationBatch;
|
|
844
844
|
assert(batch);
|
|
@@ -854,7 +854,7 @@ describe("drizzle-uow-compiler", () => {
|
|
|
854
854
|
it("should handle UOW with no operations", () => {
|
|
855
855
|
const uow = createTestUOW();
|
|
856
856
|
|
|
857
|
-
const compiler = createDrizzleUOWCompiler(
|
|
857
|
+
const compiler = createDrizzleUOWCompiler(pool, "postgresql");
|
|
858
858
|
const compiled = uow.compile(compiler);
|
|
859
859
|
|
|
860
860
|
expect(compiled.retrievalBatch).toHaveLength(0);
|
|
@@ -865,7 +865,7 @@ describe("drizzle-uow-compiler", () => {
|
|
|
865
865
|
const uow = createTestUOW();
|
|
866
866
|
uow.find("users");
|
|
867
867
|
|
|
868
|
-
const compiler = createDrizzleUOWCompiler(
|
|
868
|
+
const compiler = createDrizzleUOWCompiler(pool, "postgresql");
|
|
869
869
|
const compiled = uow.compile(compiler);
|
|
870
870
|
|
|
871
871
|
expect(compiled.retrievalBatch).toHaveLength(1);
|
|
@@ -879,7 +879,7 @@ describe("drizzle-uow-compiler", () => {
|
|
|
879
879
|
email: "test@example.com",
|
|
880
880
|
});
|
|
881
881
|
|
|
882
|
-
const compiler = createDrizzleUOWCompiler(
|
|
882
|
+
const compiler = createDrizzleUOWCompiler(pool, "postgresql");
|
|
883
883
|
const compiled = uow.compile(compiler);
|
|
884
884
|
|
|
885
885
|
expect(compiled.retrievalBatch).toHaveLength(0);
|
|
@@ -939,7 +939,7 @@ describe("drizzle-uow-compiler", () => {
|
|
|
939
939
|
message: "Test log",
|
|
940
940
|
});
|
|
941
941
|
|
|
942
|
-
const compiler = createDrizzleUOWCompiler(
|
|
942
|
+
const compiler = createDrizzleUOWCompiler(defaultsPool, "postgresql");
|
|
943
943
|
const compiled = uow.compile(compiler);
|
|
944
944
|
const [batch] = compiled.mutationBatch;
|
|
945
945
|
assert(batch);
|
|
@@ -969,7 +969,7 @@ describe("drizzle-uow-compiler", () => {
|
|
|
969
969
|
status: "active",
|
|
970
970
|
});
|
|
971
971
|
|
|
972
|
-
const compiler = createDrizzleUOWCompiler(
|
|
972
|
+
const compiler = createDrizzleUOWCompiler(defaultsPool, "postgresql");
|
|
973
973
|
const compiled = uow.compile(compiler);
|
|
974
974
|
const [batch] = compiled.mutationBatch;
|
|
975
975
|
assert(batch);
|
|
@@ -991,7 +991,7 @@ describe("drizzle-uow-compiler", () => {
|
|
|
991
991
|
counter: 999, // override the function default
|
|
992
992
|
});
|
|
993
993
|
|
|
994
|
-
const compiler = createDrizzleUOWCompiler(
|
|
994
|
+
const compiler = createDrizzleUOWCompiler(defaultsPool, "postgresql");
|
|
995
995
|
const compiled = uow.compile(compiler);
|
|
996
996
|
const [batch] = compiled.mutationBatch;
|
|
997
997
|
assert(batch);
|
|
@@ -1012,7 +1012,7 @@ describe("drizzle-uow-compiler", () => {
|
|
|
1012
1012
|
uow.create("logs", { message: "Log 2" });
|
|
1013
1013
|
uow.create("logs", { message: "Log 3" });
|
|
1014
1014
|
|
|
1015
|
-
const compiler = createDrizzleUOWCompiler(
|
|
1015
|
+
const compiler = createDrizzleUOWCompiler(defaultsPool, "postgresql");
|
|
1016
1016
|
const compiled = uow.compile(compiler);
|
|
1017
1017
|
|
|
1018
1018
|
expect(compiled.mutationBatch).toHaveLength(3);
|
|
@@ -1091,7 +1091,7 @@ describe("drizzle-uow-compiler", () => {
|
|
|
1091
1091
|
}, 20000);
|
|
1092
1092
|
|
|
1093
1093
|
function createNestedUOW(name?: string) {
|
|
1094
|
-
const compiler = createDrizzleUOWCompiler(
|
|
1094
|
+
const compiler = createDrizzleUOWCompiler(nestedPool, "postgresql");
|
|
1095
1095
|
const mockExecutor = {
|
|
1096
1096
|
executeRetrievalPhase: async () => [],
|
|
1097
1097
|
executeMutationPhase: async () => ({ success: true, createdInternalIds: [] }),
|
|
@@ -1102,7 +1102,7 @@ describe("drizzle-uow-compiler", () => {
|
|
|
1102
1102
|
}
|
|
1103
1103
|
return rawResults;
|
|
1104
1104
|
};
|
|
1105
|
-
return new UnitOfWork(
|
|
1105
|
+
return new UnitOfWork(compiler, mockExecutor, mockDecoder, name).forSchema(nestedSchema);
|
|
1106
1106
|
}
|
|
1107
1107
|
|
|
1108
1108
|
it("should compile nested joins (comments -> post -> author)", () => {
|
|
@@ -1119,7 +1119,7 @@ describe("drizzle-uow-compiler", () => {
|
|
|
1119
1119
|
),
|
|
1120
1120
|
);
|
|
1121
1121
|
|
|
1122
|
-
const compiler = createDrizzleUOWCompiler(
|
|
1122
|
+
const compiler = createDrizzleUOWCompiler(nestedPool, "postgresql");
|
|
1123
1123
|
const compiled = uow.compile(compiler);
|
|
1124
1124
|
|
|
1125
1125
|
expect(compiled.retrievalBatch).toHaveLength(1);
|
|
@@ -1157,7 +1157,7 @@ describe("drizzle-uow-compiler", () => {
|
|
|
1157
1157
|
),
|
|
1158
1158
|
);
|
|
1159
1159
|
|
|
1160
|
-
const compiler = createDrizzleUOWCompiler(
|
|
1160
|
+
const compiler = createDrizzleUOWCompiler(nestedPool, "postgresql");
|
|
1161
1161
|
const compiled = uow.compile(compiler);
|
|
1162
1162
|
|
|
1163
1163
|
expect(compiled.retrievalBatch).toHaveLength(1);
|
|
@@ -1190,7 +1190,7 @@ describe("drizzle-uow-compiler", () => {
|
|
|
1190
1190
|
),
|
|
1191
1191
|
);
|
|
1192
1192
|
|
|
1193
|
-
const compiler = createDrizzleUOWCompiler(
|
|
1193
|
+
const compiler = createDrizzleUOWCompiler(nestedPool, "postgresql");
|
|
1194
1194
|
const compiled = uow.compile(compiler);
|
|
1195
1195
|
|
|
1196
1196
|
expect(compiled.retrievalBatch).toHaveLength(1);
|
|
@@ -1212,7 +1212,7 @@ describe("drizzle-uow-compiler", () => {
|
|
|
1212
1212
|
),
|
|
1213
1213
|
);
|
|
1214
1214
|
|
|
1215
|
-
const compiler = createDrizzleUOWCompiler(
|
|
1215
|
+
const compiler = createDrizzleUOWCompiler(nestedPool, "postgresql");
|
|
1216
1216
|
const compiled = uow.compile(compiler);
|
|
1217
1217
|
|
|
1218
1218
|
expect(compiled.retrievalBatch).toHaveLength(1);
|
|
@@ -1286,18 +1286,18 @@ describe("drizzle-uow-compiler", () => {
|
|
|
1286
1286
|
}, 12000);
|
|
1287
1287
|
|
|
1288
1288
|
function createAuthUOW(name?: string) {
|
|
1289
|
-
const compiler = createDrizzleUOWCompiler(
|
|
1289
|
+
const compiler = createDrizzleUOWCompiler(authPool, "postgresql");
|
|
1290
1290
|
const mockExecutor = {
|
|
1291
1291
|
executeRetrievalPhase: async () => [],
|
|
1292
1292
|
executeMutationPhase: async () => ({ success: true, createdInternalIds: [] }),
|
|
1293
1293
|
};
|
|
1294
|
-
const mockDecoder: UOWDecoder
|
|
1294
|
+
const mockDecoder: UOWDecoder = (rawResults, operations) => {
|
|
1295
1295
|
if (rawResults.length !== operations.length) {
|
|
1296
1296
|
throw new Error("rawResults and ops must have the same length");
|
|
1297
1297
|
}
|
|
1298
1298
|
return rawResults;
|
|
1299
1299
|
};
|
|
1300
|
-
return new UnitOfWork(
|
|
1300
|
+
return new UnitOfWork(compiler, mockExecutor, mockDecoder, name).forSchema(authSchema);
|
|
1301
1301
|
}
|
|
1302
1302
|
|
|
1303
1303
|
it("should compile find session with user join", () => {
|
|
@@ -1309,7 +1309,7 @@ describe("drizzle-uow-compiler", () => {
|
|
|
1309
1309
|
.join((j) => j.sessionOwner((b) => b.select(["id", "email"]))),
|
|
1310
1310
|
);
|
|
1311
1311
|
|
|
1312
|
-
const compiler = createDrizzleUOWCompiler(
|
|
1312
|
+
const compiler = createDrizzleUOWCompiler(authPool, "postgresql");
|
|
1313
1313
|
const compiled = uow.compile(compiler);
|
|
1314
1314
|
|
|
1315
1315
|
expect(compiled.retrievalBatch).toHaveLength(1);
|
|
@@ -1335,7 +1335,7 @@ describe("drizzle-uow-compiler", () => {
|
|
|
1335
1335
|
expiresAt: new Date("2025-12-31"),
|
|
1336
1336
|
});
|
|
1337
1337
|
|
|
1338
|
-
const compiler = createDrizzleUOWCompiler(
|
|
1338
|
+
const compiler = createDrizzleUOWCompiler(authPool, "postgresql");
|
|
1339
1339
|
const compiled = uow.compile(compiler);
|
|
1340
1340
|
|
|
1341
1341
|
// Should have no retrieval operations
|
|
@@ -1379,5 +1379,22 @@ describe("drizzle-uow-compiler", () => {
|
|
|
1379
1379
|
internalId: undefined,
|
|
1380
1380
|
});
|
|
1381
1381
|
});
|
|
1382
|
+
|
|
1383
|
+
it("should compile check operation", () => {
|
|
1384
|
+
const uow = createTestUOW();
|
|
1385
|
+
const userId = FragnoId.fromExternal("user123", 5);
|
|
1386
|
+
uow.check("users", userId);
|
|
1387
|
+
|
|
1388
|
+
const compiler = createDrizzleUOWCompiler(pool, "postgresql");
|
|
1389
|
+
const compiled = uow.compile(compiler);
|
|
1390
|
+
const [batch] = compiled.mutationBatch;
|
|
1391
|
+
assert(batch);
|
|
1392
|
+
expect(batch.expectedAffectedRows).toBe(null);
|
|
1393
|
+
expect(batch.expectedReturnedRows).toBe(1);
|
|
1394
|
+
expect(batch.query.sql).toMatchInlineSnapshot(
|
|
1395
|
+
`"select 1 as "exists" from "users" where ("users"."id" = $1 and "users"."_version" = $2) limit $3"`,
|
|
1396
|
+
);
|
|
1397
|
+
expect(batch.query.params).toMatchObject(["user123", 5, 1]);
|
|
1398
|
+
});
|
|
1382
1399
|
});
|
|
1383
1400
|
});
|