@fragno-dev/db 0.1.12 → 0.1.14

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.
Files changed (85) hide show
  1. package/.turbo/turbo-build.log +51 -44
  2. package/CHANGELOG.md +12 -0
  3. package/dist/adapters/adapters.d.ts +13 -1
  4. package/dist/adapters/adapters.d.ts.map +1 -1
  5. package/dist/adapters/adapters.js.map +1 -1
  6. package/dist/adapters/drizzle/drizzle-adapter.d.ts +2 -0
  7. package/dist/adapters/drizzle/drizzle-adapter.d.ts.map +1 -1
  8. package/dist/adapters/drizzle/drizzle-adapter.js +7 -2
  9. package/dist/adapters/drizzle/drizzle-adapter.js.map +1 -1
  10. package/dist/adapters/drizzle/drizzle-query.d.ts.map +1 -1
  11. package/dist/adapters/drizzle/drizzle-query.js +10 -4
  12. package/dist/adapters/drizzle/drizzle-query.js.map +1 -1
  13. package/dist/adapters/drizzle/drizzle-uow-compiler.d.ts +0 -1
  14. package/dist/adapters/drizzle/drizzle-uow-compiler.d.ts.map +1 -1
  15. package/dist/adapters/drizzle/drizzle-uow-compiler.js +51 -37
  16. package/dist/adapters/drizzle/drizzle-uow-compiler.js.map +1 -1
  17. package/dist/adapters/drizzle/drizzle-uow-decoder.js +26 -2
  18. package/dist/adapters/drizzle/drizzle-uow-decoder.js.map +1 -1
  19. package/dist/adapters/drizzle/generate.js +1 -1
  20. package/dist/adapters/drizzle/shared.d.ts +14 -1
  21. package/dist/adapters/drizzle/shared.d.ts.map +1 -0
  22. package/dist/adapters/kysely/kysely-adapter.d.ts +3 -1
  23. package/dist/adapters/kysely/kysely-adapter.d.ts.map +1 -1
  24. package/dist/adapters/kysely/kysely-adapter.js +7 -2
  25. package/dist/adapters/kysely/kysely-adapter.js.map +1 -1
  26. package/dist/adapters/kysely/kysely-query.d.ts.map +1 -1
  27. package/dist/adapters/kysely/kysely-query.js +34 -4
  28. package/dist/adapters/kysely/kysely-query.js.map +1 -1
  29. package/dist/adapters/kysely/kysely-shared.d.ts +11 -0
  30. package/dist/adapters/kysely/kysely-shared.d.ts.map +1 -0
  31. package/dist/adapters/kysely/kysely-uow-compiler.js +40 -10
  32. package/dist/adapters/kysely/kysely-uow-compiler.js.map +1 -1
  33. package/dist/adapters/kysely/migration/execute-base.js +1 -1
  34. package/dist/bind-services.d.ts +7 -0
  35. package/dist/bind-services.d.ts.map +1 -0
  36. package/dist/bind-services.js +14 -0
  37. package/dist/bind-services.js.map +1 -0
  38. package/dist/fragment.d.ts +131 -12
  39. package/dist/fragment.d.ts.map +1 -1
  40. package/dist/fragment.js +107 -8
  41. package/dist/fragment.js.map +1 -1
  42. package/dist/mod.d.ts +5 -2
  43. package/dist/mod.d.ts.map +1 -1
  44. package/dist/mod.js +4 -2
  45. package/dist/mod.js.map +1 -1
  46. package/dist/query/cursor.d.ts +67 -32
  47. package/dist/query/cursor.d.ts.map +1 -1
  48. package/dist/query/cursor.js +84 -31
  49. package/dist/query/cursor.js.map +1 -1
  50. package/dist/query/query.d.ts +7 -2
  51. package/dist/query/query.d.ts.map +1 -1
  52. package/dist/query/unit-of-work.d.ts +113 -18
  53. package/dist/query/unit-of-work.d.ts.map +1 -1
  54. package/dist/query/unit-of-work.js +266 -16
  55. package/dist/query/unit-of-work.js.map +1 -1
  56. package/package.json +2 -2
  57. package/src/adapters/adapters.ts +14 -0
  58. package/src/adapters/drizzle/drizzle-adapter-pglite.test.ts +78 -6
  59. package/src/adapters/drizzle/drizzle-adapter-sqlite.test.ts +139 -9
  60. package/src/adapters/drizzle/drizzle-adapter.ts +16 -1
  61. package/src/adapters/drizzle/drizzle-query.ts +35 -15
  62. package/src/adapters/drizzle/drizzle-uow-compiler.test.ts +76 -60
  63. package/src/adapters/drizzle/drizzle-uow-compiler.ts +82 -41
  64. package/src/adapters/drizzle/drizzle-uow-decoder.ts +42 -6
  65. package/src/adapters/kysely/kysely-adapter-pglite.test.ts +104 -6
  66. package/src/adapters/kysely/kysely-adapter.ts +16 -1
  67. package/src/adapters/kysely/kysely-query.ts +76 -16
  68. package/src/adapters/kysely/kysely-uow-compiler.test.ts +62 -46
  69. package/src/adapters/kysely/kysely-uow-compiler.ts +53 -16
  70. package/src/adapters/kysely/kysely-uow-joins.test.ts +30 -30
  71. package/src/bind-services.test.ts +214 -0
  72. package/src/bind-services.ts +37 -0
  73. package/src/db-fragment.test.ts +800 -0
  74. package/src/fragment.ts +557 -28
  75. package/src/mod.ts +25 -1
  76. package/src/query/cursor.test.ts +113 -68
  77. package/src/query/cursor.ts +127 -36
  78. package/src/query/query.ts +21 -2
  79. package/src/query/unit-of-work-multi-schema.test.ts +64 -0
  80. package/src/query/unit-of-work-types.test.ts +13 -0
  81. package/src/query/unit-of-work.test.ts +5 -9
  82. package/src/query/unit-of-work.ts +629 -62
  83. package/src/uow-context-integration.test.ts +102 -0
  84. package/src/uow-context.test.ts +182 -0
  85. package/src/fragment.test.ts +0 -341
@@ -14,6 +14,7 @@ import type { CompiledQuery, Kysely } from "kysely";
14
14
  import type { TableNameMapper } from "./kysely-shared";
15
15
  import type { ConnectionPool } from "../../shared/connection-pool";
16
16
  import type { SQLProvider } from "../../shared/providers";
17
+ import { createCursorFromRecord, Cursor, type CursorResult } from "../../query/cursor";
17
18
 
18
19
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
19
20
  type KyselyAny = Kysely<any>;
@@ -76,6 +77,8 @@ class UpdateManySpecialBuilder<TTable extends AnyTable> {
76
77
  * @param pool - Connection pool for acquiring database connections
77
78
  * @param provider - SQL provider (postgresql, mysql, sqlite, etc.)
78
79
  * @param mapper - Optional table name mapper for namespace prefixing
80
+ * @param uowConfig - Optional UOW configuration
81
+ * @param schemaNamespaceMap - Optional WeakMap for schema-to-namespace lookups
79
82
  * @returns An AbstractQuery instance for performing database operations
80
83
  *
81
84
  * @example
@@ -95,9 +98,10 @@ export function fromKysely<T extends AnySchema>(
95
98
  provider: SQLProvider,
96
99
  mapper?: TableNameMapper,
97
100
  uowConfig?: KyselyUOWConfig,
101
+ schemaNamespaceMap?: WeakMap<AnySchema, string>,
98
102
  ): AbstractQuery<T, KyselyUOWConfig> {
99
103
  function createUOW(opts: { name?: string; config?: KyselyUOWConfig }) {
100
- const uowCompiler = createKyselyUOWCompiler(schema, pool, provider, mapper);
104
+ const uowCompiler = createKyselyUOWCompiler(pool, provider, mapper);
101
105
 
102
106
  const executor: UOWExecutor<CompiledQuery, unknown> = {
103
107
  async executeRetrievalPhase(retrievalBatch: CompiledQuery[]) {
@@ -132,7 +136,7 @@ export function fromKysely<T extends AnySchema>(
132
136
  };
133
137
 
134
138
  // Create a decoder function to transform raw results into application format
135
- const decoder: UOWDecoder<T> = (rawResults, ops) => {
139
+ const decoder: UOWDecoder<unknown> = (rawResults, ops) => {
136
140
  if (rawResults.length !== ops.length) {
137
141
  throw new Error("rawResults and ops must have the same length");
138
142
  }
@@ -159,26 +163,72 @@ export function fromKysely<T extends AnySchema>(
159
163
 
160
164
  // Each result is an array of rows - decode each row
161
165
  const rowArray = rows as Record<string, unknown>[];
162
- return rowArray.map((row) => decodeResult(row, op.table, provider));
166
+ const decodedRows = rowArray.map((row) => decodeResult(row, op.table, provider));
167
+
168
+ // If cursor generation is requested, wrap in CursorResult
169
+ if (op.withCursor) {
170
+ let cursor: Cursor | undefined;
171
+
172
+ // Generate cursor from last item if results exist
173
+ if (decodedRows.length > 0 && op.options.orderByIndex && op.options.pageSize) {
174
+ const lastItem = decodedRows[decodedRows.length - 1];
175
+ const indexName = op.options.orderByIndex.indexName;
176
+
177
+ // Get index columns
178
+ let indexColumns;
179
+ if (indexName === "_primary") {
180
+ indexColumns = [op.table.getIdColumn()];
181
+ } else {
182
+ const index = op.table.indexes[indexName];
183
+ if (index) {
184
+ indexColumns = index.columns;
185
+ }
186
+ }
187
+
188
+ if (indexColumns && lastItem) {
189
+ cursor = createCursorFromRecord(lastItem as Record<string, unknown>, indexColumns, {
190
+ indexName: op.options.orderByIndex.indexName,
191
+ orderDirection: op.options.orderByIndex.direction,
192
+ pageSize: op.options.pageSize,
193
+ });
194
+ }
195
+ }
196
+
197
+ const result: CursorResult<unknown> = {
198
+ items: decodedRows,
199
+ cursor,
200
+ };
201
+ return result;
202
+ }
203
+
204
+ return decodedRows;
163
205
  });
164
206
  };
165
207
 
166
208
  const { onQuery, ...restUowConfig } = opts.config ?? {};
167
209
 
168
- return new UnitOfWork(schema, uowCompiler, executor, decoder, opts.name, {
169
- ...restUowConfig,
170
- onQuery: (query) => {
171
- // CompiledMutation has { query: CompiledQuery, expectedAffectedRows: number | null }
172
- // CompiledQuery has { query: QueryAST, sql: string, parameters: unknown[] }
173
- // Check for expectedAffectedRows to distinguish CompiledMutation from CompiledQuery
174
- const actualQuery =
175
- query && typeof query === "object" && "expectedAffectedRows" in query
176
- ? (query as CompiledMutation<CompiledQuery>).query
177
- : (query as CompiledQuery);
178
-
179
- opts.config?.onQuery?.(actualQuery);
210
+ return new UnitOfWork(
211
+ schema,
212
+ uowCompiler,
213
+ executor,
214
+ decoder,
215
+ opts.name,
216
+ {
217
+ ...restUowConfig,
218
+ onQuery: (query) => {
219
+ // CompiledMutation has { query: CompiledQuery, expectedAffectedRows: number | null }
220
+ // CompiledQuery has { query: QueryAST, sql: string, parameters: unknown[] }
221
+ // Check for expectedAffectedRows to distinguish CompiledMutation from CompiledQuery
222
+ const actualQuery =
223
+ query && typeof query === "object" && "expectedAffectedRows" in query
224
+ ? (query as CompiledMutation<CompiledQuery>).query
225
+ : (query as CompiledQuery);
226
+
227
+ opts.config?.onQuery?.(actualQuery);
228
+ },
180
229
  },
181
- });
230
+ schemaNamespaceMap,
231
+ );
182
232
  }
183
233
 
184
234
  return {
@@ -193,6 +243,16 @@ export function fromKysely<T extends AnySchema>(
193
243
  return result ?? [];
194
244
  },
195
245
 
246
+ async findWithCursor(tableName, builderFn) {
247
+ // Safe: builderFn returns a FindBuilder, which matches UnitOfWork signature
248
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
249
+ const uow = createUOW({ config: uowConfig }).findWithCursor(tableName, builderFn as any);
250
+ // executeRetrieve returns an array of results (one per find operation)
251
+ // Since we only have one findWithCursor, unwrap the first result
252
+ const [result] = await uow.executeRetrieve();
253
+ return result as CursorResult<unknown>;
254
+ },
255
+
196
256
  async findFirst(tableName, builderFn) {
197
257
  const uow = createUOW({ config: uowConfig });
198
258
  if (builderFn) {
@@ -5,6 +5,7 @@ import { UnitOfWork, type UOWDecoder } from "../../query/unit-of-work";
5
5
  import { createKyselyUOWCompiler } from "./kysely-uow-compiler";
6
6
  import type { ConnectionPool } from "../../shared/connection-pool";
7
7
  import { createKyselyConnectionPool } from "./kysely-connection-pool";
8
+ import { Cursor } from "../../query/cursor";
8
9
 
9
10
  describe("kysely-uow-compiler", () => {
10
11
  const testSchema = schema((s) => {
@@ -113,12 +114,12 @@ describe("kysely-uow-compiler", () => {
113
114
 
114
115
  // Helper to create UnitOfWork for testing
115
116
  function createTestUOW(name?: string) {
116
- const mockCompiler = createKyselyUOWCompiler(testSchema, pool, "postgresql");
117
+ const mockCompiler = createKyselyUOWCompiler(pool, "postgresql");
117
118
  const mockExecutor = {
118
119
  executeRetrievalPhase: async () => [],
119
120
  executeMutationPhase: async () => ({ success: true, createdInternalIds: [] }),
120
121
  };
121
- const mockDecoder: UOWDecoder<typeof testSchema> = (rawResults, operations) => {
122
+ const mockDecoder: UOWDecoder = (rawResults, operations) => {
122
123
  if (rawResults.length !== operations.length) {
123
124
  throw new Error("rawResults and ops must have the same length");
124
125
  }
@@ -135,7 +136,7 @@ describe("kysely-uow-compiler", () => {
135
136
  b.whereIndex("idx_email", (eb) => eb("email", "=", "test@example.com")),
136
137
  );
137
138
 
138
- const compiler = createKyselyUOWCompiler(testSchema, pool, "postgresql");
139
+ const compiler = createKyselyUOWCompiler(pool, "postgresql");
139
140
  const compiled = uow.compile(compiler);
140
141
 
141
142
  expect(compiled.retrievalBatch).toHaveLength(1);
@@ -151,7 +152,7 @@ describe("kysely-uow-compiler", () => {
151
152
  b.whereIndex("idx_name", (eb) => eb("name", "=", "Alice")).select(["id", "name"]),
152
153
  );
153
154
 
154
- const compiler = createKyselyUOWCompiler(testSchema, pool, "postgresql");
155
+ const compiler = createKyselyUOWCompiler(pool, "postgresql");
155
156
  const compiled = uow.compile(compiler);
156
157
 
157
158
  expect(compiled.retrievalBatch).toHaveLength(1);
@@ -165,7 +166,7 @@ describe("kysely-uow-compiler", () => {
165
166
  const uow = createTestUOW();
166
167
  uow.find("users", (b) => b.whereIndex("primary").pageSize(10));
167
168
 
168
- const compiler = createKyselyUOWCompiler(testSchema, pool, "postgresql");
169
+ const compiler = createKyselyUOWCompiler(pool, "postgresql");
169
170
  const compiled = uow.compile(compiler);
170
171
 
171
172
  expect(compiled.retrievalBatch).toHaveLength(1);
@@ -179,7 +180,7 @@ describe("kysely-uow-compiler", () => {
179
180
  const uow = createTestUOW();
180
181
  uow.find("users", (b) => b.whereIndex("primary").orderByIndex("primary", "desc"));
181
182
 
182
- const compiler = createKyselyUOWCompiler(testSchema, pool, "postgresql");
183
+ const compiler = createKyselyUOWCompiler(pool, "postgresql");
183
184
  const compiled = uow.compile(compiler);
184
185
 
185
186
  expect(compiled.retrievalBatch).toHaveLength(1);
@@ -192,7 +193,7 @@ describe("kysely-uow-compiler", () => {
192
193
  const uow = createTestUOW();
193
194
  uow.find("users", (b) => b.whereIndex("idx_name").orderByIndex("idx_name", "desc"));
194
195
 
195
- const compiler = createKyselyUOWCompiler(testSchema, pool, "postgresql");
196
+ const compiler = createKyselyUOWCompiler(pool, "postgresql");
196
197
  const compiled = uow.compile(compiler);
197
198
 
198
199
  expect(compiled.retrievalBatch).toHaveLength(1);
@@ -208,7 +209,7 @@ describe("kysely-uow-compiler", () => {
208
209
  );
209
210
  uow.find("posts", (b) => b.whereIndex("idx_title", (eb) => eb("title", "contains", "test")));
210
211
 
211
- const compiler = createKyselyUOWCompiler(testSchema, pool, "postgresql");
212
+ const compiler = createKyselyUOWCompiler(pool, "postgresql");
212
213
  const compiled = uow.compile(compiler);
213
214
 
214
215
  expect(compiled.retrievalBatch).toHaveLength(2);
@@ -227,7 +228,7 @@ describe("kysely-uow-compiler", () => {
227
228
  return b;
228
229
  });
229
230
 
230
- const compiler = createKyselyUOWCompiler(testSchema, pool, "postgresql");
231
+ const compiler = createKyselyUOWCompiler(pool, "postgresql");
231
232
  const compiled = uow.compile(compiler);
232
233
 
233
234
  expect(compiled.retrievalBatch).toHaveLength(1);
@@ -240,7 +241,7 @@ describe("kysely-uow-compiler", () => {
240
241
  const uow = createTestUOW();
241
242
  uow.find("users", (b) => b.whereIndex("idx_age", (eb) => eb("age", ">", 25)).selectCount());
242
243
 
243
- const compiler = createKyselyUOWCompiler(testSchema, pool, "postgresql");
244
+ const compiler = createKyselyUOWCompiler(pool, "postgresql");
244
245
  const compiled = uow.compile(compiler);
245
246
 
246
247
  expect(compiled.retrievalBatch).toHaveLength(1);
@@ -252,12 +253,17 @@ describe("kysely-uow-compiler", () => {
252
253
 
253
254
  it("should compile find operation with cursor pagination using after", () => {
254
255
  const uow = createTestUOW();
255
- const cursor = "eyJpbmRleFZhbHVlcyI6eyJuYW1lIjoiQWxpY2UifSwiZGlyZWN0aW9uIjoiZm9yd2FyZCJ9"; // {"indexValues":{"name":"Alice"},"direction":"forward"}
256
+ const cursor = new Cursor({
257
+ indexName: "idx_name",
258
+ orderDirection: "asc",
259
+ pageSize: 10,
260
+ indexValues: { name: "Alice" },
261
+ });
256
262
  uow.find("users", (b) =>
257
263
  b.whereIndex("idx_name").orderByIndex("idx_name", "asc").after(cursor).pageSize(10),
258
264
  );
259
265
 
260
- const compiler = createKyselyUOWCompiler(testSchema, pool, "postgresql");
266
+ const compiler = createKyselyUOWCompiler(pool, "postgresql");
261
267
  const compiled = uow.compile(compiler);
262
268
 
263
269
  expect(compiled.retrievalBatch).toHaveLength(1);
@@ -269,12 +275,17 @@ describe("kysely-uow-compiler", () => {
269
275
 
270
276
  it("should compile find operation with cursor pagination using before", () => {
271
277
  const uow = createTestUOW();
272
- const cursor = "eyJpbmRleFZhbHVlcyI6eyJuYW1lIjoiQm9iIn0sImRpcmVjdGlvbiI6ImJhY2t3YXJkIn0="; // {"indexValues":{"name":"Bob"},"direction":"backward"}
278
+ const cursor = new Cursor({
279
+ indexName: "idx_name",
280
+ orderDirection: "desc",
281
+ pageSize: 10,
282
+ indexValues: { name: "Bob" },
283
+ });
273
284
  uow.find("users", (b) =>
274
285
  b.whereIndex("idx_name").orderByIndex("idx_name", "desc").before(cursor).pageSize(10),
275
286
  );
276
287
 
277
- const compiler = createKyselyUOWCompiler(testSchema, pool, "postgresql");
288
+ const compiler = createKyselyUOWCompiler(pool, "postgresql");
278
289
  const compiled = uow.compile(compiler);
279
290
 
280
291
  expect(compiled.retrievalBatch).toHaveLength(1);
@@ -286,7 +297,12 @@ describe("kysely-uow-compiler", () => {
286
297
 
287
298
  it("should compile find operation with cursor pagination and additional where conditions", () => {
288
299
  const uow = createTestUOW();
289
- const cursor = "eyJpbmRleFZhbHVlcyI6eyJuYW1lIjoiQWxpY2UifSwiZGlyZWN0aW9uIjoiZm9yd2FyZCJ9";
300
+ const cursor = new Cursor({
301
+ indexName: "idx_name",
302
+ orderDirection: "asc",
303
+ pageSize: 5,
304
+ indexValues: { name: "Alice" },
305
+ });
290
306
  uow.find("users", (b) =>
291
307
  b
292
308
  .whereIndex("idx_name", (eb) => eb("name", "starts with", "John"))
@@ -295,7 +311,7 @@ describe("kysely-uow-compiler", () => {
295
311
  .pageSize(5),
296
312
  );
297
313
 
298
- const compiler = createKyselyUOWCompiler(testSchema, pool, "postgresql");
314
+ const compiler = createKyselyUOWCompiler(pool, "postgresql");
299
315
  const compiled = uow.compile(compiler);
300
316
 
301
317
  expect(compiled.retrievalBatch).toHaveLength(1);
@@ -315,7 +331,7 @@ describe("kysely-uow-compiler", () => {
315
331
  age: 30,
316
332
  });
317
333
 
318
- const compiler = createKyselyUOWCompiler(testSchema, pool, "postgresql");
334
+ const compiler = createKyselyUOWCompiler(pool, "postgresql");
319
335
  const compiled = uow.compile(compiler);
320
336
  const [batch] = compiled.mutationBatch;
321
337
  assert(batch);
@@ -341,7 +357,7 @@ describe("kysely-uow-compiler", () => {
341
357
  }),
342
358
  );
343
359
 
344
- const compiler = createKyselyUOWCompiler(testSchema, pool, "postgresql");
360
+ const compiler = createKyselyUOWCompiler(pool, "postgresql");
345
361
  const compiled = uow.compile(compiler);
346
362
  const [batch] = compiled.mutationBatch;
347
363
  assert(batch);
@@ -357,7 +373,7 @@ describe("kysely-uow-compiler", () => {
357
373
  const userId = FragnoId.fromExternal("user123", 5);
358
374
  uow.update("users", userId, (b) => b.set({ age: 18 }).check());
359
375
 
360
- const compiler = createKyselyUOWCompiler(testSchema, pool, "postgresql");
376
+ const compiler = createKyselyUOWCompiler(pool, "postgresql");
361
377
  const compiled = uow.compile(compiler);
362
378
  const [batch] = compiled.mutationBatch;
363
379
  assert(batch);
@@ -373,7 +389,7 @@ describe("kysely-uow-compiler", () => {
373
389
  const userId = FragnoId.fromExternal("user123", 0);
374
390
  uow.delete("users", userId);
375
391
 
376
- const compiler = createKyselyUOWCompiler(testSchema, pool, "postgresql");
392
+ const compiler = createKyselyUOWCompiler(pool, "postgresql");
377
393
  const compiled = uow.compile(compiler);
378
394
  const [batch] = compiled.mutationBatch;
379
395
  assert(batch);
@@ -389,7 +405,7 @@ describe("kysely-uow-compiler", () => {
389
405
  const userId = FragnoId.fromExternal("user123", 3);
390
406
  uow.delete("users", userId, (b) => b.check());
391
407
 
392
- const compiler = createKyselyUOWCompiler(testSchema, pool, "postgresql");
408
+ const compiler = createKyselyUOWCompiler(pool, "postgresql");
393
409
  const compiled = uow.compile(compiler);
394
410
  const [batch] = compiled.mutationBatch;
395
411
  assert(batch);
@@ -409,7 +425,7 @@ describe("kysely-uow-compiler", () => {
409
425
  }),
410
426
  );
411
427
 
412
- const compiler = createKyselyUOWCompiler(testSchema, pool, "postgresql");
428
+ const compiler = createKyselyUOWCompiler(pool, "postgresql");
413
429
  const compiled = uow.compile(compiler);
414
430
  const [batch] = compiled.mutationBatch;
415
431
  assert(batch);
@@ -424,7 +440,7 @@ describe("kysely-uow-compiler", () => {
424
440
  const uow = createTestUOW();
425
441
  uow.delete("users", "user123");
426
442
 
427
- const compiler = createKyselyUOWCompiler(testSchema, pool, "postgresql");
443
+ const compiler = createKyselyUOWCompiler(pool, "postgresql");
428
444
  const compiled = uow.compile(compiler);
429
445
  const [batch] = compiled.mutationBatch;
430
446
  assert(batch);
@@ -464,7 +480,7 @@ describe("kysely-uow-compiler", () => {
464
480
  const userId = FragnoId.fromExternal("user456", 0);
465
481
  uow.delete("posts", userId);
466
482
 
467
- const compiler = createKyselyUOWCompiler(testSchema, pool, "postgresql");
483
+ const compiler = createKyselyUOWCompiler(pool, "postgresql");
468
484
  const compiled = uow.compile(compiler);
469
485
  const [createBatch, updateBatch, deleteBatch] = compiled.mutationBatch;
470
486
 
@@ -503,7 +519,7 @@ describe("kysely-uow-compiler", () => {
503
519
  const userId = FragnoId.fromExternal("user123", 3);
504
520
  uow.update("users", userId, (b) => b.set({ age: 31 }).check());
505
521
 
506
- const compiler = createKyselyUOWCompiler(testSchema, pool, "postgresql");
522
+ const compiler = createKyselyUOWCompiler(pool, "postgresql");
507
523
  const compiled = uow.compile(compiler);
508
524
 
509
525
  expect(compiled.name).toBe("update-user-balance");
@@ -535,7 +551,7 @@ describe("kysely-uow-compiler", () => {
535
551
  ),
536
552
  );
537
553
 
538
- const compiler = createKyselyUOWCompiler(testSchema, pool, "postgresql");
554
+ const compiler = createKyselyUOWCompiler(pool, "postgresql");
539
555
  const compiled = uow.compile(compiler);
540
556
 
541
557
  expect(compiled.retrievalBatch).toHaveLength(1);
@@ -549,7 +565,7 @@ describe("kysely-uow-compiler", () => {
549
565
  const uow = createTestUOW();
550
566
  uow.find("users", (b) => b.whereIndex("primary", () => false));
551
567
 
552
- const compiler = createKyselyUOWCompiler(testSchema, pool, "postgresql");
568
+ const compiler = createKyselyUOWCompiler(pool, "postgresql");
553
569
  const compiled = uow.compile(compiler);
554
570
 
555
571
  // When condition is false, the operation should return null and not be added to batch
@@ -560,7 +576,7 @@ describe("kysely-uow-compiler", () => {
560
576
  const uow = createTestUOW();
561
577
  uow.find("users", (b) => b.whereIndex("primary", () => true));
562
578
 
563
- const compiler = createKyselyUOWCompiler(testSchema, pool, "postgresql");
579
+ const compiler = createKyselyUOWCompiler(pool, "postgresql");
564
580
  const compiled = uow.compile(compiler);
565
581
 
566
582
  expect(compiled.retrievalBatch).toHaveLength(1);
@@ -577,7 +593,7 @@ describe("kysely-uow-compiler", () => {
577
593
  const userId = FragnoId.fromExternal("user123", 5);
578
594
  uow.update("users", userId, (b) => b.set({ age: 31 }).check());
579
595
 
580
- const compiler = createKyselyUOWCompiler(testSchema, pool, "postgresql");
596
+ const compiler = createKyselyUOWCompiler(pool, "postgresql");
581
597
  const compiled = uow.compile(compiler);
582
598
  const [batch] = compiled.mutationBatch;
583
599
  assert(batch);
@@ -594,7 +610,7 @@ describe("kysely-uow-compiler", () => {
594
610
  const userId = FragnoId.fromExternal("user456", 3);
595
611
  uow.delete("users", userId, (b) => b.check());
596
612
 
597
- const compiler = createKyselyUOWCompiler(testSchema, pool, "postgresql");
613
+ const compiler = createKyselyUOWCompiler(pool, "postgresql");
598
614
  const compiled = uow.compile(compiler);
599
615
  const [batch] = compiled.mutationBatch;
600
616
  assert(batch);
@@ -614,7 +630,7 @@ describe("kysely-uow-compiler", () => {
614
630
  uow.update("users", userId, (b) => b.set({ age: 30 }).check());
615
631
  uow.update("posts", postId, (b) => b.set({ viewCount: 100 }).check());
616
632
 
617
- const compiler = createKyselyUOWCompiler(testSchema, pool, "postgresql");
633
+ const compiler = createKyselyUOWCompiler(pool, "postgresql");
618
634
  const compiled = uow.compile(compiler);
619
635
  const [userBatch, postBatch] = compiled.mutationBatch;
620
636
 
@@ -641,7 +657,7 @@ describe("kysely-uow-compiler", () => {
641
657
  const userId = FragnoId.fromExternal("user1", 0);
642
658
  uow.update("users", userId, (b) => b.set({ age: 25 }));
643
659
 
644
- const compiler = createKyselyUOWCompiler(testSchema, pool, "postgresql");
660
+ const compiler = createKyselyUOWCompiler(pool, "postgresql");
645
661
  const compiled = uow.compile(compiler);
646
662
  const [batch] = compiled.mutationBatch;
647
663
  assert(batch);
@@ -660,7 +676,7 @@ describe("kysely-uow-compiler", () => {
660
676
  b.whereIndex("primary").join((jb) => jb.author((ab) => ab.select(["name", "email"]))),
661
677
  );
662
678
 
663
- const compiler = createKyselyUOWCompiler(testSchema, pool, "postgresql");
679
+ const compiler = createKyselyUOWCompiler(pool, "postgresql");
664
680
  const compiled = uow.compile(compiler);
665
681
 
666
682
  expect(compiled.retrievalBatch).toHaveLength(1);
@@ -684,7 +700,7 @@ describe("kysely-uow-compiler", () => {
684
700
  ),
685
701
  );
686
702
 
687
- const compiler = createKyselyUOWCompiler(testSchema, pool, "postgresql");
703
+ const compiler = createKyselyUOWCompiler(pool, "postgresql");
688
704
  const compiled = uow.compile(compiler);
689
705
 
690
706
  expect(compiled.retrievalBatch).toHaveLength(1);
@@ -703,7 +719,7 @@ describe("kysely-uow-compiler", () => {
703
719
  .join((jb) => jb.author((ab) => ab.select(["name"]).orderByIndex("idx_name", "desc"))),
704
720
  );
705
721
 
706
- const compiler = createKyselyUOWCompiler(testSchema, pool, "postgresql");
722
+ const compiler = createKyselyUOWCompiler(pool, "postgresql");
707
723
  const compiled = uow.compile(compiler);
708
724
 
709
725
  expect(compiled.retrievalBatch).toHaveLength(1);
@@ -719,7 +735,7 @@ describe("kysely-uow-compiler", () => {
719
735
  b.whereIndex("primary").join((jb) => jb.author((ab) => ab.select(["name"]).pageSize(5))),
720
736
  );
721
737
 
722
- const compiler = createKyselyUOWCompiler(testSchema, pool, "postgresql");
738
+ const compiler = createKyselyUOWCompiler(pool, "postgresql");
723
739
  const compiled = uow.compile(compiler);
724
740
 
725
741
  expect(compiled.retrievalBatch).toHaveLength(1);
@@ -750,7 +766,7 @@ describe("kysely-uow-compiler", () => {
750
766
  ),
751
767
  );
752
768
 
753
- const compiler = createKyselyUOWCompiler(testSchema, pool, "postgresql");
769
+ const compiler = createKyselyUOWCompiler(pool, "postgresql");
754
770
  const compiled = uow.compile(compiler);
755
771
 
756
772
  expect(compiled.retrievalBatch).toHaveLength(1);
@@ -769,7 +785,7 @@ describe("kysely-uow-compiler", () => {
769
785
  .join((jb) => jb.post((pb) => pb.select(["title"])).author((ab) => ab.select(["name"]))),
770
786
  );
771
787
 
772
- const compiler = createKyselyUOWCompiler(testSchema, pool, "postgresql");
788
+ const compiler = createKyselyUOWCompiler(pool, "postgresql");
773
789
  const compiled = uow.compile(compiler);
774
790
 
775
791
  expect(compiled.retrievalBatch).toHaveLength(1);
@@ -787,7 +803,7 @@ describe("kysely-uow-compiler", () => {
787
803
  b.whereIndex("primary").join((jb) => jb.inviter((ib) => ib.select(["name", "email"]))),
788
804
  );
789
805
 
790
- const compiler = createKyselyUOWCompiler(testSchema, pool, "postgresql");
806
+ const compiler = createKyselyUOWCompiler(pool, "postgresql");
791
807
  const compiled = uow.compile(compiler);
792
808
 
793
809
  expect(compiled.retrievalBatch).toHaveLength(1);
@@ -817,7 +833,7 @@ describe("kysely-uow-compiler", () => {
817
833
  ),
818
834
  );
819
835
 
820
- const compiler = createKyselyUOWCompiler(testSchema, pool, "postgresql");
836
+ const compiler = createKyselyUOWCompiler(pool, "postgresql");
821
837
  const compiled = uow.compile(compiler);
822
838
 
823
839
  expect(compiled.retrievalBatch).toHaveLength(1);
@@ -840,7 +856,7 @@ describe("kysely-uow-compiler", () => {
840
856
  .join((jb) => jb.post((pb) => pb.select(["title"])).tag((tb) => tb.select(["name"]))),
841
857
  );
842
858
 
843
- const compiler = createKyselyUOWCompiler(testSchema, pool, "postgresql");
859
+ const compiler = createKyselyUOWCompiler(pool, "postgresql");
844
860
  const compiled = uow.compile(compiler);
845
861
 
846
862
  expect(compiled.retrievalBatch).toHaveLength(1);
@@ -865,7 +881,7 @@ describe("kysely-uow-compiler", () => {
865
881
  ),
866
882
  );
867
883
 
868
- const compiler = createKyselyUOWCompiler(testSchema, pool, "postgresql");
884
+ const compiler = createKyselyUOWCompiler(pool, "postgresql");
869
885
  const compiled = uow.compile(compiler);
870
886
 
871
887
  expect(compiled.retrievalBatch).toHaveLength(1);
@@ -881,7 +897,7 @@ describe("kysely-uow-compiler", () => {
881
897
  it("should handle UOW with no operations", () => {
882
898
  const uow = createTestUOW();
883
899
 
884
- const compiler = createKyselyUOWCompiler(testSchema, pool, "postgresql");
900
+ const compiler = createKyselyUOWCompiler(pool, "postgresql");
885
901
  const compiled = uow.compile(compiler);
886
902
 
887
903
  expect(compiled.retrievalBatch).toHaveLength(0);
@@ -892,7 +908,7 @@ describe("kysely-uow-compiler", () => {
892
908
  const uow = createTestUOW();
893
909
  uow.find("users");
894
910
 
895
- const compiler = createKyselyUOWCompiler(testSchema, pool, "postgresql");
911
+ const compiler = createKyselyUOWCompiler(pool, "postgresql");
896
912
  const compiled = uow.compile(compiler);
897
913
 
898
914
  expect(compiled.retrievalBatch).toHaveLength(1);
@@ -906,7 +922,7 @@ describe("kysely-uow-compiler", () => {
906
922
  email: "test@example.com",
907
923
  });
908
924
 
909
- const compiler = createKyselyUOWCompiler(testSchema, pool, "postgresql");
925
+ const compiler = createKyselyUOWCompiler(pool, "postgresql");
910
926
  const compiled = uow.compile(compiler);
911
927
 
912
928
  expect(compiled.retrievalBatch).toHaveLength(0);
@@ -933,7 +949,7 @@ describe("kysely-uow-compiler", () => {
933
949
  content: "This is my first post",
934
950
  });
935
951
 
936
- const compiler = createKyselyUOWCompiler(testSchema, pool, "postgresql");
952
+ const compiler = createKyselyUOWCompiler(pool, "postgresql");
937
953
  const compiled = uow.compile(compiler);
938
954
 
939
955
  // Should have no retrieval operations