@fragno-dev/db 0.0.1 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +137 -13
- package/.turbo/turbo-test.log +36 -0
- package/CHANGELOG.md +7 -0
- package/dist/adapters/adapters.d.ts +18 -0
- package/dist/adapters/adapters.d.ts.map +1 -0
- package/dist/adapters/drizzle/drizzle-adapter.d.ts +21 -0
- package/dist/adapters/drizzle/drizzle-adapter.d.ts.map +1 -0
- package/dist/adapters/drizzle/drizzle-adapter.js +62 -0
- package/dist/adapters/drizzle/drizzle-adapter.js.map +1 -0
- package/dist/adapters/drizzle/drizzle-query.d.ts +17 -0
- package/dist/adapters/drizzle/drizzle-query.d.ts.map +1 -0
- package/dist/adapters/drizzle/drizzle-query.js +139 -0
- package/dist/adapters/drizzle/drizzle-query.js.map +1 -0
- package/dist/adapters/drizzle/drizzle-uow-compiler.d.ts +9 -0
- package/dist/adapters/drizzle/drizzle-uow-compiler.d.ts.map +1 -0
- package/dist/adapters/drizzle/drizzle-uow-compiler.js +300 -0
- package/dist/adapters/drizzle/drizzle-uow-compiler.js.map +1 -0
- package/dist/adapters/drizzle/drizzle-uow-decoder.js +82 -0
- package/dist/adapters/drizzle/drizzle-uow-decoder.js.map +1 -0
- package/dist/adapters/drizzle/drizzle-uow-executor.js +125 -0
- package/dist/adapters/drizzle/drizzle-uow-executor.js.map +1 -0
- package/dist/adapters/drizzle/generate.js +273 -0
- package/dist/adapters/drizzle/generate.js.map +1 -0
- package/dist/adapters/drizzle/join-column-utils.js +28 -0
- package/dist/adapters/drizzle/join-column-utils.js.map +1 -0
- package/dist/adapters/drizzle/shared.js +11 -0
- package/dist/adapters/drizzle/shared.js.map +1 -0
- package/dist/adapters/kysely/kysely-adapter.d.ts +23 -0
- package/dist/adapters/kysely/kysely-adapter.d.ts.map +1 -0
- package/dist/adapters/kysely/kysely-adapter.js +119 -0
- package/dist/adapters/kysely/kysely-adapter.js.map +1 -0
- package/dist/adapters/kysely/kysely-query-builder.js +306 -0
- package/dist/adapters/kysely/kysely-query-builder.js.map +1 -0
- package/dist/adapters/kysely/kysely-query-compiler.js +67 -0
- package/dist/adapters/kysely/kysely-query-compiler.js.map +1 -0
- package/dist/adapters/kysely/kysely-query.js +158 -0
- package/dist/adapters/kysely/kysely-query.js.map +1 -0
- package/dist/adapters/kysely/kysely-uow-compiler.js +139 -0
- package/dist/adapters/kysely/kysely-uow-compiler.js.map +1 -0
- package/dist/adapters/kysely/kysely-uow-executor.js +89 -0
- package/dist/adapters/kysely/kysely-uow-executor.js.map +1 -0
- package/dist/adapters/kysely/migration/execute.js +176 -0
- package/dist/adapters/kysely/migration/execute.js.map +1 -0
- package/dist/fragment.d.ts +54 -0
- package/dist/fragment.d.ts.map +1 -0
- package/dist/fragment.js +92 -0
- package/dist/fragment.js.map +1 -0
- package/dist/id.d.ts +2 -0
- package/dist/migration-engine/auto-from-schema.js +116 -0
- package/dist/migration-engine/auto-from-schema.js.map +1 -0
- package/dist/migration-engine/create.d.ts +41 -0
- package/dist/migration-engine/create.d.ts.map +1 -0
- package/dist/migration-engine/create.js +58 -0
- package/dist/migration-engine/create.js.map +1 -0
- package/dist/migration-engine/shared.d.ts +90 -0
- package/dist/migration-engine/shared.d.ts.map +1 -0
- package/dist/migration-engine/shared.js +8 -0
- package/dist/migration-engine/shared.js.map +1 -0
- package/dist/mod.d.ts +55 -2
- package/dist/mod.d.ts.map +1 -1
- package/dist/mod.js +111 -2
- package/dist/mod.js.map +1 -1
- package/dist/node_modules/.bun/drizzle-orm@0.44.6_4fae081eecb963e2/node_modules/drizzle-orm/column-builder.js +108 -0
- package/dist/node_modules/.bun/drizzle-orm@0.44.6_4fae081eecb963e2/node_modules/drizzle-orm/column-builder.js.map +1 -0
- package/dist/node_modules/.bun/drizzle-orm@0.44.6_4fae081eecb963e2/node_modules/drizzle-orm/column.js +55 -0
- package/dist/node_modules/.bun/drizzle-orm@0.44.6_4fae081eecb963e2/node_modules/drizzle-orm/column.js.map +1 -0
- package/dist/node_modules/.bun/drizzle-orm@0.44.6_4fae081eecb963e2/node_modules/drizzle-orm/entity.js +18 -0
- package/dist/node_modules/.bun/drizzle-orm@0.44.6_4fae081eecb963e2/node_modules/drizzle-orm/entity.js.map +1 -0
- package/dist/node_modules/.bun/drizzle-orm@0.44.6_4fae081eecb963e2/node_modules/drizzle-orm/pg-core/columns/common.js +183 -0
- package/dist/node_modules/.bun/drizzle-orm@0.44.6_4fae081eecb963e2/node_modules/drizzle-orm/pg-core/columns/common.js.map +1 -0
- package/dist/node_modules/.bun/drizzle-orm@0.44.6_4fae081eecb963e2/node_modules/drizzle-orm/pg-core/columns/enum.js +58 -0
- package/dist/node_modules/.bun/drizzle-orm@0.44.6_4fae081eecb963e2/node_modules/drizzle-orm/pg-core/columns/enum.js.map +1 -0
- package/dist/node_modules/.bun/drizzle-orm@0.44.6_4fae081eecb963e2/node_modules/drizzle-orm/pg-core/foreign-keys.js +68 -0
- package/dist/node_modules/.bun/drizzle-orm@0.44.6_4fae081eecb963e2/node_modules/drizzle-orm/pg-core/foreign-keys.js.map +1 -0
- package/dist/node_modules/.bun/drizzle-orm@0.44.6_4fae081eecb963e2/node_modules/drizzle-orm/pg-core/unique-constraint.js +56 -0
- package/dist/node_modules/.bun/drizzle-orm@0.44.6_4fae081eecb963e2/node_modules/drizzle-orm/pg-core/unique-constraint.js.map +1 -0
- package/dist/node_modules/.bun/drizzle-orm@0.44.6_4fae081eecb963e2/node_modules/drizzle-orm/pg-core/utils/array.js +65 -0
- package/dist/node_modules/.bun/drizzle-orm@0.44.6_4fae081eecb963e2/node_modules/drizzle-orm/pg-core/utils/array.js.map +1 -0
- package/dist/node_modules/.bun/drizzle-orm@0.44.6_4fae081eecb963e2/node_modules/drizzle-orm/sql/expressions/conditions.js +81 -0
- package/dist/node_modules/.bun/drizzle-orm@0.44.6_4fae081eecb963e2/node_modules/drizzle-orm/sql/expressions/conditions.js.map +1 -0
- package/dist/node_modules/.bun/drizzle-orm@0.44.6_4fae081eecb963e2/node_modules/drizzle-orm/sql/expressions/select.js +13 -0
- package/dist/node_modules/.bun/drizzle-orm@0.44.6_4fae081eecb963e2/node_modules/drizzle-orm/sql/expressions/select.js.map +1 -0
- package/dist/node_modules/.bun/drizzle-orm@0.44.6_4fae081eecb963e2/node_modules/drizzle-orm/sql/functions/aggregate.js +10 -0
- package/dist/node_modules/.bun/drizzle-orm@0.44.6_4fae081eecb963e2/node_modules/drizzle-orm/sql/functions/aggregate.js.map +1 -0
- package/dist/node_modules/.bun/drizzle-orm@0.44.6_4fae081eecb963e2/node_modules/drizzle-orm/sql/sql.js +372 -0
- package/dist/node_modules/.bun/drizzle-orm@0.44.6_4fae081eecb963e2/node_modules/drizzle-orm/sql/sql.js.map +1 -0
- package/dist/node_modules/.bun/drizzle-orm@0.44.6_4fae081eecb963e2/node_modules/drizzle-orm/subquery.js +23 -0
- package/dist/node_modules/.bun/drizzle-orm@0.44.6_4fae081eecb963e2/node_modules/drizzle-orm/subquery.js.map +1 -0
- package/dist/node_modules/.bun/drizzle-orm@0.44.6_4fae081eecb963e2/node_modules/drizzle-orm/table.js +62 -0
- package/dist/node_modules/.bun/drizzle-orm@0.44.6_4fae081eecb963e2/node_modules/drizzle-orm/table.js.map +1 -0
- package/dist/node_modules/.bun/drizzle-orm@0.44.6_4fae081eecb963e2/node_modules/drizzle-orm/table.utils.js +6 -0
- package/dist/node_modules/.bun/drizzle-orm@0.44.6_4fae081eecb963e2/node_modules/drizzle-orm/table.utils.js.map +1 -0
- package/dist/node_modules/.bun/drizzle-orm@0.44.6_4fae081eecb963e2/node_modules/drizzle-orm/tracing-utils.js +8 -0
- package/dist/node_modules/.bun/drizzle-orm@0.44.6_4fae081eecb963e2/node_modules/drizzle-orm/tracing-utils.js.map +1 -0
- package/dist/node_modules/.bun/drizzle-orm@0.44.6_4fae081eecb963e2/node_modules/drizzle-orm/tracing.js +8 -0
- package/dist/node_modules/.bun/drizzle-orm@0.44.6_4fae081eecb963e2/node_modules/drizzle-orm/tracing.js.map +1 -0
- package/dist/node_modules/.bun/drizzle-orm@0.44.6_4fae081eecb963e2/node_modules/drizzle-orm/view-common.js +6 -0
- package/dist/node_modules/.bun/drizzle-orm@0.44.6_4fae081eecb963e2/node_modules/drizzle-orm/view-common.js.map +1 -0
- package/dist/query/condition-builder.d.ts +41 -0
- package/dist/query/condition-builder.d.ts.map +1 -0
- package/dist/query/condition-builder.js +93 -0
- package/dist/query/condition-builder.js.map +1 -0
- package/dist/query/cursor.d.ts +88 -0
- package/dist/query/cursor.d.ts.map +1 -0
- package/dist/query/cursor.js +103 -0
- package/dist/query/cursor.js.map +1 -0
- package/dist/query/orm/orm.d.ts +18 -0
- package/dist/query/orm/orm.d.ts.map +1 -0
- package/dist/query/orm/orm.js +48 -0
- package/dist/query/orm/orm.js.map +1 -0
- package/dist/query/query.d.ts +79 -0
- package/dist/query/query.d.ts.map +1 -0
- package/dist/query/query.js +1 -0
- package/dist/query/result-transform.js +155 -0
- package/dist/query/result-transform.js.map +1 -0
- package/dist/query/unit-of-work.d.ts +435 -0
- package/dist/query/unit-of-work.d.ts.map +1 -0
- package/dist/query/unit-of-work.js +549 -0
- package/dist/query/unit-of-work.js.map +1 -0
- package/dist/schema/create.d.ts +273 -116
- package/dist/schema/create.d.ts.map +1 -1
- package/dist/schema/create.js +410 -222
- package/dist/schema/create.js.map +1 -1
- package/dist/schema/serialize.js +101 -0
- package/dist/schema/serialize.js.map +1 -0
- package/dist/schema-generator/schema-generator.d.ts +15 -0
- package/dist/schema-generator/schema-generator.d.ts.map +1 -0
- package/dist/shared/providers.d.ts +6 -0
- package/dist/shared/providers.d.ts.map +1 -0
- package/dist/util/import-generator.js +26 -0
- package/dist/util/import-generator.js.map +1 -0
- package/dist/util/parse.js +15 -0
- package/dist/util/parse.js.map +1 -0
- package/dist/util/types.d.ts +8 -0
- package/dist/util/types.d.ts.map +1 -0
- package/package.json +63 -2
- package/src/adapters/adapters.ts +22 -0
- package/src/adapters/drizzle/drizzle-adapter-pglite.test.ts +433 -0
- package/src/adapters/drizzle/drizzle-adapter.test.ts +122 -0
- package/src/adapters/drizzle/drizzle-adapter.ts +118 -0
- package/src/adapters/drizzle/drizzle-query.ts +234 -0
- package/src/adapters/drizzle/drizzle-uow-compiler.test.ts +1084 -0
- package/src/adapters/drizzle/drizzle-uow-compiler.ts +546 -0
- package/src/adapters/drizzle/drizzle-uow-decoder.ts +165 -0
- package/src/adapters/drizzle/drizzle-uow-executor.ts +213 -0
- package/src/adapters/drizzle/generate.test.ts +643 -0
- package/src/adapters/drizzle/generate.ts +481 -0
- package/src/adapters/drizzle/join-column-utils.test.ts +79 -0
- package/src/adapters/drizzle/join-column-utils.ts +39 -0
- package/src/adapters/drizzle/migrate-drizzle.test.ts +226 -0
- package/src/adapters/drizzle/shared.ts +22 -0
- package/src/adapters/drizzle/test-utils.ts +56 -0
- package/src/adapters/kysely/kysely-adapter-pglite.test.ts +789 -0
- package/src/adapters/kysely/kysely-adapter.ts +196 -0
- package/src/adapters/kysely/kysely-query-builder.test.ts +1344 -0
- package/src/adapters/kysely/kysely-query-builder.ts +611 -0
- package/src/adapters/kysely/kysely-query-compiler.ts +124 -0
- package/src/adapters/kysely/kysely-query.ts +254 -0
- package/src/adapters/kysely/kysely-uow-compiler.test.ts +916 -0
- package/src/adapters/kysely/kysely-uow-compiler.ts +271 -0
- package/src/adapters/kysely/kysely-uow-executor.ts +149 -0
- package/src/adapters/kysely/kysely-uow-joins.test.ts +811 -0
- package/src/adapters/kysely/migration/execute-mysql.test.ts +1173 -0
- package/src/adapters/kysely/migration/execute-postgres.test.ts +2657 -0
- package/src/adapters/kysely/migration/execute.ts +382 -0
- package/src/adapters/kysely/migration/kysely-migrator.test.ts +197 -0
- package/src/fragment.test.ts +287 -0
- package/src/fragment.ts +198 -0
- package/src/migration-engine/auto-from-schema.test.ts +118 -58
- package/src/migration-engine/auto-from-schema.ts +103 -32
- package/src/migration-engine/create.test.ts +34 -46
- package/src/migration-engine/create.ts +41 -26
- package/src/migration-engine/shared.ts +26 -6
- package/src/mod.ts +197 -1
- package/src/query/condition-builder.test.ts +379 -0
- package/src/query/condition-builder.ts +294 -0
- package/src/query/cursor.test.ts +296 -0
- package/src/query/cursor.ts +147 -0
- package/src/query/orm/orm.ts +92 -0
- package/src/query/query-type.test.ts +429 -0
- package/src/query/query.ts +200 -0
- package/src/query/result-transform.test.ts +795 -0
- package/src/query/result-transform.ts +247 -0
- package/src/query/unit-of-work-types.test.ts +192 -0
- package/src/query/unit-of-work.test.ts +947 -0
- package/src/query/unit-of-work.ts +1199 -0
- package/src/schema/create.test.ts +653 -110
- package/src/schema/create.ts +708 -337
- package/src/schema/serialize.test.ts +559 -0
- package/src/schema/serialize.ts +359 -0
- package/src/schema-generator/schema-generator.ts +12 -0
- package/src/shared/config.ts +0 -8
- package/src/util/import-generator.ts +28 -0
- package/src/util/parse.ts +16 -0
- package/src/util/types.ts +4 -0
- package/tsconfig.json +1 -1
- package/tsdown.config.ts +11 -1
- package/vitest.config.ts +3 -0
- /package/dist/{cuid.js → id.js} +0 -0
- /package/src/{cuid.ts → id.ts} +0 -0
|
@@ -0,0 +1,916 @@
|
|
|
1
|
+
import { Kysely, PostgresDialect } from "kysely";
|
|
2
|
+
import { assert, beforeAll, describe, expect, it } from "vitest";
|
|
3
|
+
import { column, FragnoId, idColumn, referenceColumn, schema } from "../../schema/create";
|
|
4
|
+
import { UnitOfWork, type UOWDecoder } from "../../query/unit-of-work";
|
|
5
|
+
import { createKyselyUOWCompiler } from "./kysely-uow-compiler";
|
|
6
|
+
import type { KyselyConfig } from "./kysely-adapter";
|
|
7
|
+
|
|
8
|
+
describe("kysely-uow-compiler", () => {
|
|
9
|
+
const testSchema = schema((s) => {
|
|
10
|
+
return s
|
|
11
|
+
.addTable("users", (t) => {
|
|
12
|
+
return t
|
|
13
|
+
.addColumn("id", idColumn())
|
|
14
|
+
.addColumn("name", column("string"))
|
|
15
|
+
.addColumn("email", column("string"))
|
|
16
|
+
.addColumn("age", column("integer").nullable())
|
|
17
|
+
.addColumn("invitedBy", referenceColumn().nullable())
|
|
18
|
+
.createIndex("idx_email", ["email"], { unique: true })
|
|
19
|
+
.createIndex("idx_name", ["name"])
|
|
20
|
+
.createIndex("idx_age", ["age"]);
|
|
21
|
+
})
|
|
22
|
+
.addTable("posts", (t) => {
|
|
23
|
+
return t
|
|
24
|
+
.addColumn("id", idColumn())
|
|
25
|
+
.addColumn("title", column("string"))
|
|
26
|
+
.addColumn("content", column("string"))
|
|
27
|
+
.addColumn("userId", referenceColumn())
|
|
28
|
+
.addColumn("viewCount", column("integer").defaultTo(0))
|
|
29
|
+
.createIndex("idx_user", ["userId"])
|
|
30
|
+
.createIndex("idx_title", ["title"]);
|
|
31
|
+
})
|
|
32
|
+
.addTable("comments", (t) => {
|
|
33
|
+
return t
|
|
34
|
+
.addColumn("id", idColumn())
|
|
35
|
+
.addColumn("content", column("string"))
|
|
36
|
+
.addColumn("postId", referenceColumn())
|
|
37
|
+
.addColumn("authorId", referenceColumn())
|
|
38
|
+
.createIndex("idx_post", ["postId"])
|
|
39
|
+
.createIndex("idx_author", ["authorId"]);
|
|
40
|
+
})
|
|
41
|
+
.addTable("tags", (t) => {
|
|
42
|
+
return t
|
|
43
|
+
.addColumn("id", idColumn())
|
|
44
|
+
.addColumn("name", column("string"))
|
|
45
|
+
.createIndex("idx_name", ["name"]);
|
|
46
|
+
})
|
|
47
|
+
.addTable("post_tags", (t) => {
|
|
48
|
+
return t
|
|
49
|
+
.addColumn("id", idColumn())
|
|
50
|
+
.addColumn("postId", referenceColumn())
|
|
51
|
+
.addColumn("tagId", referenceColumn())
|
|
52
|
+
.createIndex("idx_post", ["postId"])
|
|
53
|
+
.createIndex("idx_tag", ["tagId"]);
|
|
54
|
+
})
|
|
55
|
+
.addReference("author", {
|
|
56
|
+
type: "one",
|
|
57
|
+
from: { table: "posts", column: "userId" },
|
|
58
|
+
to: { table: "users", column: "id" },
|
|
59
|
+
})
|
|
60
|
+
.addReference("inviter", {
|
|
61
|
+
type: "one",
|
|
62
|
+
from: { table: "users", column: "invitedBy" },
|
|
63
|
+
to: { table: "users", column: "id" },
|
|
64
|
+
})
|
|
65
|
+
.addReference("post", {
|
|
66
|
+
type: "one",
|
|
67
|
+
from: { table: "comments", column: "postId" },
|
|
68
|
+
to: { table: "posts", column: "id" },
|
|
69
|
+
})
|
|
70
|
+
.addReference("author", {
|
|
71
|
+
type: "one",
|
|
72
|
+
from: { table: "comments", column: "authorId" },
|
|
73
|
+
to: { table: "users", column: "id" },
|
|
74
|
+
})
|
|
75
|
+
.addReference("post", {
|
|
76
|
+
type: "one",
|
|
77
|
+
from: { table: "post_tags", column: "postId" },
|
|
78
|
+
to: { table: "posts", column: "id" },
|
|
79
|
+
})
|
|
80
|
+
.addReference("tag", {
|
|
81
|
+
type: "one",
|
|
82
|
+
from: { table: "post_tags", column: "tagId" },
|
|
83
|
+
to: { table: "tags", column: "id" },
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
88
|
+
let kysely: Kysely<any>;
|
|
89
|
+
let config: KyselyConfig;
|
|
90
|
+
|
|
91
|
+
beforeAll(() => {
|
|
92
|
+
// Create a mock Kysely instance (we won't execute queries, just compile them)
|
|
93
|
+
// We need a minimal pool that won't actually connect
|
|
94
|
+
const mockPool = {
|
|
95
|
+
connect: () => Promise.reject(new Error("Mock pool - no actual connections")),
|
|
96
|
+
end: () => Promise.resolve(),
|
|
97
|
+
on: () => {},
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
kysely = new Kysely({
|
|
101
|
+
dialect: new PostgresDialect({
|
|
102
|
+
// Safe: we're only compiling queries, not executing them
|
|
103
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
104
|
+
pool: mockPool as any,
|
|
105
|
+
}),
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
config = {
|
|
109
|
+
db: kysely,
|
|
110
|
+
provider: "postgresql",
|
|
111
|
+
};
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
// Helper to create UnitOfWork for testing
|
|
115
|
+
function createTestUOW(name?: string) {
|
|
116
|
+
const mockCompiler = createKyselyUOWCompiler(testSchema, config);
|
|
117
|
+
const mockExecutor = {
|
|
118
|
+
executeRetrievalPhase: async () => [],
|
|
119
|
+
executeMutationPhase: async () => ({ success: true, createdInternalIds: [] }),
|
|
120
|
+
};
|
|
121
|
+
const mockDecoder: UOWDecoder<typeof testSchema> = (rawResults, operations) => {
|
|
122
|
+
if (rawResults.length !== operations.length) {
|
|
123
|
+
throw new Error("rawResults and ops must have the same length");
|
|
124
|
+
}
|
|
125
|
+
return rawResults;
|
|
126
|
+
};
|
|
127
|
+
// Pass undefined for decoder since we're only testing compilation, not execution
|
|
128
|
+
return new UnitOfWork(testSchema, mockCompiler, mockExecutor, mockDecoder, name);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
describe("compileRetrievalOperation", () => {
|
|
132
|
+
it("should compile find operation with where clause", () => {
|
|
133
|
+
const uow = createTestUOW();
|
|
134
|
+
uow.find("users", (b) =>
|
|
135
|
+
b.whereIndex("idx_email", (eb) => eb("email", "=", "test@example.com")),
|
|
136
|
+
);
|
|
137
|
+
|
|
138
|
+
const compiler = createKyselyUOWCompiler(testSchema, config);
|
|
139
|
+
const compiled = uow.compile(compiler);
|
|
140
|
+
|
|
141
|
+
expect(compiled.retrievalBatch).toHaveLength(1);
|
|
142
|
+
expect(compiled.retrievalBatch[0].sql).toMatchInlineSnapshot(
|
|
143
|
+
`"select "users"."id" as "id", "users"."name" as "name", "users"."email" as "email", "users"."age" as "age", "users"."invitedBy" as "invitedBy", "users"."_internalId" as "_internalId", "users"."_version" as "_version" from "users" where "users"."email" = $1"`,
|
|
144
|
+
);
|
|
145
|
+
expect(compiled.retrievalBatch[0].parameters).toEqual(["test@example.com"]);
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
it("should compile find operation with select clause", () => {
|
|
149
|
+
const uow = createTestUOW();
|
|
150
|
+
uow.find("users", (b) =>
|
|
151
|
+
b.whereIndex("idx_name", (eb) => eb("name", "=", "Alice")).select(["id", "name"]),
|
|
152
|
+
);
|
|
153
|
+
|
|
154
|
+
const compiler = createKyselyUOWCompiler(testSchema, config);
|
|
155
|
+
const compiled = uow.compile(compiler);
|
|
156
|
+
|
|
157
|
+
expect(compiled.retrievalBatch).toHaveLength(1);
|
|
158
|
+
expect(compiled.retrievalBatch[0].sql).toMatchInlineSnapshot(
|
|
159
|
+
`"select "users"."id" as "id", "users"."name" as "name", "users"."_internalId" as "_internalId", "users"."_version" as "_version" from "users" where "users"."name" = $1"`,
|
|
160
|
+
);
|
|
161
|
+
expect(compiled.retrievalBatch[0].parameters).toEqual(["Alice"]);
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
it("should compile find operation with pageSize", () => {
|
|
165
|
+
const uow = createTestUOW();
|
|
166
|
+
uow.find("users", (b) => b.whereIndex("primary").pageSize(10));
|
|
167
|
+
|
|
168
|
+
const compiler = createKyselyUOWCompiler(testSchema, config);
|
|
169
|
+
const compiled = uow.compile(compiler);
|
|
170
|
+
|
|
171
|
+
expect(compiled.retrievalBatch).toHaveLength(1);
|
|
172
|
+
expect(compiled.retrievalBatch[0].sql).toMatchInlineSnapshot(
|
|
173
|
+
`"select "users"."id" as "id", "users"."name" as "name", "users"."email" as "email", "users"."age" as "age", "users"."invitedBy" as "invitedBy", "users"."_internalId" as "_internalId", "users"."_version" as "_version" from "users" limit $1"`,
|
|
174
|
+
);
|
|
175
|
+
expect(compiled.retrievalBatch[0].parameters).toEqual([10]);
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
it("should compile find operation with orderByIndex on primary index", () => {
|
|
179
|
+
const uow = createTestUOW();
|
|
180
|
+
uow.find("users", (b) => b.whereIndex("primary").orderByIndex("primary", "desc"));
|
|
181
|
+
|
|
182
|
+
const compiler = createKyselyUOWCompiler(testSchema, config);
|
|
183
|
+
const compiled = uow.compile(compiler);
|
|
184
|
+
|
|
185
|
+
expect(compiled.retrievalBatch).toHaveLength(1);
|
|
186
|
+
expect(compiled.retrievalBatch[0].sql).toMatchInlineSnapshot(
|
|
187
|
+
`"select "users"."id" as "id", "users"."name" as "name", "users"."email" as "email", "users"."age" as "age", "users"."invitedBy" as "invitedBy", "users"."_internalId" as "_internalId", "users"."_version" as "_version" from "users" order by "users"."id" desc"`,
|
|
188
|
+
);
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
it("should compile find operation with orderByIndex", () => {
|
|
192
|
+
const uow = createTestUOW();
|
|
193
|
+
uow.find("users", (b) => b.whereIndex("idx_name").orderByIndex("idx_name", "desc"));
|
|
194
|
+
|
|
195
|
+
const compiler = createKyselyUOWCompiler(testSchema, config);
|
|
196
|
+
const compiled = uow.compile(compiler);
|
|
197
|
+
|
|
198
|
+
expect(compiled.retrievalBatch).toHaveLength(1);
|
|
199
|
+
expect(compiled.retrievalBatch[0].sql).toMatchInlineSnapshot(
|
|
200
|
+
`"select "users"."id" as "id", "users"."name" as "name", "users"."email" as "email", "users"."age" as "age", "users"."invitedBy" as "invitedBy", "users"."_internalId" as "_internalId", "users"."_version" as "_version" from "users" order by "users"."name" desc"`,
|
|
201
|
+
);
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
it("should compile multiple find operations", () => {
|
|
205
|
+
const uow = createTestUOW();
|
|
206
|
+
uow.find("users", (b) =>
|
|
207
|
+
b.whereIndex("idx_email", (eb) => eb("email", "=", "user1@example.com")),
|
|
208
|
+
);
|
|
209
|
+
uow.find("posts", (b) => b.whereIndex("idx_title", (eb) => eb("title", "contains", "test")));
|
|
210
|
+
|
|
211
|
+
const compiler = createKyselyUOWCompiler(testSchema, config);
|
|
212
|
+
const compiled = uow.compile(compiler);
|
|
213
|
+
|
|
214
|
+
expect(compiled.retrievalBatch).toHaveLength(2);
|
|
215
|
+
expect(compiled.retrievalBatch[0].sql).toMatchInlineSnapshot(
|
|
216
|
+
`"select "users"."id" as "id", "users"."name" as "name", "users"."email" as "email", "users"."age" as "age", "users"."invitedBy" as "invitedBy", "users"."_internalId" as "_internalId", "users"."_version" as "_version" from "users" where "users"."email" = $1"`,
|
|
217
|
+
);
|
|
218
|
+
expect(compiled.retrievalBatch[1].sql).toMatchInlineSnapshot(
|
|
219
|
+
`"select "posts"."id" as "id", "posts"."title" as "title", "posts"."content" as "content", "posts"."userId" as "userId", "posts"."viewCount" as "viewCount", "posts"."_internalId" as "_internalId", "posts"."_version" as "_version" from "posts" where "posts"."title" like $1"`,
|
|
220
|
+
);
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
it("should compile find operation with selectCount", () => {
|
|
224
|
+
const uow = createTestUOW();
|
|
225
|
+
uow.find("users", (b) => {
|
|
226
|
+
b.whereIndex("primary").selectCount();
|
|
227
|
+
return b;
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
const compiler = createKyselyUOWCompiler(testSchema, config);
|
|
231
|
+
const compiled = uow.compile(compiler);
|
|
232
|
+
|
|
233
|
+
expect(compiled.retrievalBatch).toHaveLength(1);
|
|
234
|
+
expect(compiled.retrievalBatch[0].sql).toMatchInlineSnapshot(
|
|
235
|
+
`"select count(*) as "count" from "users""`,
|
|
236
|
+
);
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
it("should compile find operation with selectCount and where clause", () => {
|
|
240
|
+
const uow = createTestUOW();
|
|
241
|
+
uow.find("users", (b) => b.whereIndex("idx_age", (eb) => eb("age", ">", 25)).selectCount());
|
|
242
|
+
|
|
243
|
+
const compiler = createKyselyUOWCompiler(testSchema, config);
|
|
244
|
+
const compiled = uow.compile(compiler);
|
|
245
|
+
|
|
246
|
+
expect(compiled.retrievalBatch).toHaveLength(1);
|
|
247
|
+
expect(compiled.retrievalBatch[0].sql).toMatchInlineSnapshot(
|
|
248
|
+
`"select count(*) as "count" from "users" where "users"."age" > $1"`,
|
|
249
|
+
);
|
|
250
|
+
expect(compiled.retrievalBatch[0].parameters).toEqual([25]);
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
it("should compile find operation with cursor pagination using after", () => {
|
|
254
|
+
const uow = createTestUOW();
|
|
255
|
+
const cursor = "eyJpbmRleFZhbHVlcyI6eyJuYW1lIjoiQWxpY2UifSwiZGlyZWN0aW9uIjoiZm9yd2FyZCJ9"; // {"indexValues":{"name":"Alice"},"direction":"forward"}
|
|
256
|
+
uow.find("users", (b) =>
|
|
257
|
+
b.whereIndex("idx_name").orderByIndex("idx_name", "asc").after(cursor).pageSize(10),
|
|
258
|
+
);
|
|
259
|
+
|
|
260
|
+
const compiler = createKyselyUOWCompiler(testSchema, config);
|
|
261
|
+
const compiled = uow.compile(compiler);
|
|
262
|
+
|
|
263
|
+
expect(compiled.retrievalBatch).toHaveLength(1);
|
|
264
|
+
expect(compiled.retrievalBatch[0].sql).toMatchInlineSnapshot(
|
|
265
|
+
`"select "users"."id" as "id", "users"."name" as "name", "users"."email" as "email", "users"."age" as "age", "users"."invitedBy" as "invitedBy", "users"."_internalId" as "_internalId", "users"."_version" as "_version" from "users" where "users"."name" > $1 order by "users"."name" asc limit $2"`,
|
|
266
|
+
);
|
|
267
|
+
expect(compiled.retrievalBatch[0].parameters).toEqual(["Alice", 10]);
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
it("should compile find operation with cursor pagination using before", () => {
|
|
271
|
+
const uow = createTestUOW();
|
|
272
|
+
const cursor = "eyJpbmRleFZhbHVlcyI6eyJuYW1lIjoiQm9iIn0sImRpcmVjdGlvbiI6ImJhY2t3YXJkIn0="; // {"indexValues":{"name":"Bob"},"direction":"backward"}
|
|
273
|
+
uow.find("users", (b) =>
|
|
274
|
+
b.whereIndex("idx_name").orderByIndex("idx_name", "desc").before(cursor).pageSize(10),
|
|
275
|
+
);
|
|
276
|
+
|
|
277
|
+
const compiler = createKyselyUOWCompiler(testSchema, config);
|
|
278
|
+
const compiled = uow.compile(compiler);
|
|
279
|
+
|
|
280
|
+
expect(compiled.retrievalBatch).toHaveLength(1);
|
|
281
|
+
expect(compiled.retrievalBatch[0].sql).toMatchInlineSnapshot(
|
|
282
|
+
`"select "users"."id" as "id", "users"."name" as "name", "users"."email" as "email", "users"."age" as "age", "users"."invitedBy" as "invitedBy", "users"."_internalId" as "_internalId", "users"."_version" as "_version" from "users" where "users"."name" > $1 order by "users"."name" desc limit $2"`,
|
|
283
|
+
);
|
|
284
|
+
expect(compiled.retrievalBatch[0].parameters).toEqual(["Bob", 10]);
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
it("should compile find operation with cursor pagination and additional where conditions", () => {
|
|
288
|
+
const uow = createTestUOW();
|
|
289
|
+
const cursor = "eyJpbmRleFZhbHVlcyI6eyJuYW1lIjoiQWxpY2UifSwiZGlyZWN0aW9uIjoiZm9yd2FyZCJ9";
|
|
290
|
+
uow.find("users", (b) =>
|
|
291
|
+
b
|
|
292
|
+
.whereIndex("idx_name", (eb) => eb("name", "starts with", "John"))
|
|
293
|
+
.orderByIndex("idx_name", "asc")
|
|
294
|
+
.after(cursor)
|
|
295
|
+
.pageSize(5),
|
|
296
|
+
);
|
|
297
|
+
|
|
298
|
+
const compiler = createKyselyUOWCompiler(testSchema, config);
|
|
299
|
+
const compiled = uow.compile(compiler);
|
|
300
|
+
|
|
301
|
+
expect(compiled.retrievalBatch).toHaveLength(1);
|
|
302
|
+
expect(compiled.retrievalBatch[0].sql).toMatchInlineSnapshot(
|
|
303
|
+
`"select "users"."id" as "id", "users"."name" as "name", "users"."email" as "email", "users"."age" as "age", "users"."invitedBy" as "invitedBy", "users"."_internalId" as "_internalId", "users"."_version" as "_version" from "users" where ("users"."name" like $1 and "users"."name" > $2) order by "users"."name" asc limit $3"`,
|
|
304
|
+
);
|
|
305
|
+
expect(compiled.retrievalBatch[0].parameters).toEqual(["John%", "Alice", 5]);
|
|
306
|
+
});
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
describe("compileMutationOperation", () => {
|
|
310
|
+
it("should compile create operation", () => {
|
|
311
|
+
const uow = createTestUOW();
|
|
312
|
+
uow.create("users", {
|
|
313
|
+
name: "John Doe",
|
|
314
|
+
email: "john@example.com",
|
|
315
|
+
age: 30,
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
const compiler = createKyselyUOWCompiler(testSchema, config);
|
|
319
|
+
const compiled = uow.compile(compiler);
|
|
320
|
+
const [batch] = compiled.mutationBatch;
|
|
321
|
+
assert(batch);
|
|
322
|
+
expect(batch.expectedAffectedRows).toBeNull();
|
|
323
|
+
expect(batch.query.sql).toMatchInlineSnapshot(
|
|
324
|
+
`"insert into "users" ("id", "name", "email", "age") values ($1, $2, $3, $4) returning "users"."id" as "id", "users"."name" as "name", "users"."email" as "email", "users"."age" as "age", "users"."invitedBy" as "invitedBy", "users"."_internalId" as "_internalId", "users"."_version" as "_version""`,
|
|
325
|
+
);
|
|
326
|
+
expect(batch.query.parameters).toMatchObject([
|
|
327
|
+
expect.any(String),
|
|
328
|
+
"John Doe",
|
|
329
|
+
"john@example.com",
|
|
330
|
+
30,
|
|
331
|
+
]);
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
it("should compile update operation with ID", () => {
|
|
335
|
+
const uow = createTestUOW();
|
|
336
|
+
const userId = FragnoId.fromExternal("user123", 0);
|
|
337
|
+
uow.update("users", userId, (b) =>
|
|
338
|
+
b.set({
|
|
339
|
+
name: "Jane Doe",
|
|
340
|
+
age: 25,
|
|
341
|
+
}),
|
|
342
|
+
);
|
|
343
|
+
|
|
344
|
+
const compiler = createKyselyUOWCompiler(testSchema, config);
|
|
345
|
+
const compiled = uow.compile(compiler);
|
|
346
|
+
const [batch] = compiled.mutationBatch;
|
|
347
|
+
assert(batch);
|
|
348
|
+
expect(batch.expectedAffectedRows).toBeNull();
|
|
349
|
+
expect(batch.query.sql).toMatchInlineSnapshot(
|
|
350
|
+
`"update "users" set "name" = $1, "age" = $2, "_version" = COALESCE(_version, 0) + 1 where "users"."id" = $3"`,
|
|
351
|
+
);
|
|
352
|
+
expect(batch.query.parameters).toMatchObject(["Jane Doe", 25, "user123"]);
|
|
353
|
+
});
|
|
354
|
+
|
|
355
|
+
it("should compile update operation with version check", () => {
|
|
356
|
+
const uow = createTestUOW();
|
|
357
|
+
const userId = FragnoId.fromExternal("user123", 5);
|
|
358
|
+
uow.update("users", userId, (b) => b.set({ age: 18 }).check());
|
|
359
|
+
|
|
360
|
+
const compiler = createKyselyUOWCompiler(testSchema, config);
|
|
361
|
+
const compiled = uow.compile(compiler);
|
|
362
|
+
const [batch] = compiled.mutationBatch;
|
|
363
|
+
assert(batch);
|
|
364
|
+
expect(batch.expectedAffectedRows).toBe(1);
|
|
365
|
+
expect(batch.query.sql).toMatchInlineSnapshot(
|
|
366
|
+
`"update "users" set "age" = $1, "_version" = COALESCE(_version, 0) + 1 where ("users"."id" = $2 and "users"."_version" = $3)"`,
|
|
367
|
+
);
|
|
368
|
+
expect(batch.query.parameters).toMatchObject([18, "user123", 5]);
|
|
369
|
+
});
|
|
370
|
+
|
|
371
|
+
it("should compile delete operation with ID", () => {
|
|
372
|
+
const uow = createTestUOW();
|
|
373
|
+
const userId = FragnoId.fromExternal("user123", 0);
|
|
374
|
+
uow.delete("users", userId);
|
|
375
|
+
|
|
376
|
+
const compiler = createKyselyUOWCompiler(testSchema, config);
|
|
377
|
+
const compiled = uow.compile(compiler);
|
|
378
|
+
const [batch] = compiled.mutationBatch;
|
|
379
|
+
assert(batch);
|
|
380
|
+
expect(batch.expectedAffectedRows).toBeNull();
|
|
381
|
+
expect(batch.query.sql).toMatchInlineSnapshot(
|
|
382
|
+
`"delete from "users" where "users"."id" = $1"`,
|
|
383
|
+
);
|
|
384
|
+
expect(batch.query.parameters).toMatchObject(["user123"]);
|
|
385
|
+
});
|
|
386
|
+
|
|
387
|
+
it("should compile delete operation with version check", () => {
|
|
388
|
+
const uow = createTestUOW();
|
|
389
|
+
const userId = FragnoId.fromExternal("user123", 3);
|
|
390
|
+
uow.delete("users", userId, (b) => b.check());
|
|
391
|
+
|
|
392
|
+
const compiler = createKyselyUOWCompiler(testSchema, config);
|
|
393
|
+
const compiled = uow.compile(compiler);
|
|
394
|
+
const [batch] = compiled.mutationBatch;
|
|
395
|
+
assert(batch);
|
|
396
|
+
expect(batch.expectedAffectedRows).toBe(1);
|
|
397
|
+
expect(batch.query.sql).toMatchInlineSnapshot(
|
|
398
|
+
`"delete from "users" where ("users"."id" = $1 and "users"."_version" = $2)"`,
|
|
399
|
+
);
|
|
400
|
+
expect(batch.query.parameters).toMatchObject(["user123", 3]);
|
|
401
|
+
});
|
|
402
|
+
|
|
403
|
+
it("should compile update operation with string ID", () => {
|
|
404
|
+
const uow = createTestUOW();
|
|
405
|
+
uow.update("users", "user123", (b) =>
|
|
406
|
+
b.set({
|
|
407
|
+
name: "Jane Doe",
|
|
408
|
+
age: 25,
|
|
409
|
+
}),
|
|
410
|
+
);
|
|
411
|
+
|
|
412
|
+
const compiler = createKyselyUOWCompiler(testSchema, config);
|
|
413
|
+
const compiled = uow.compile(compiler);
|
|
414
|
+
const [batch] = compiled.mutationBatch;
|
|
415
|
+
assert(batch);
|
|
416
|
+
expect(batch.expectedAffectedRows).toBeNull();
|
|
417
|
+
expect(batch.query.sql).toMatchInlineSnapshot(
|
|
418
|
+
`"update "users" set "name" = $1, "age" = $2, "_version" = COALESCE(_version, 0) + 1 where "users"."id" = $3"`,
|
|
419
|
+
);
|
|
420
|
+
expect(batch.query.parameters).toMatchObject(["Jane Doe", 25, "user123"]);
|
|
421
|
+
});
|
|
422
|
+
|
|
423
|
+
it("should compile delete operation with string ID", () => {
|
|
424
|
+
const uow = createTestUOW();
|
|
425
|
+
uow.delete("users", "user123");
|
|
426
|
+
|
|
427
|
+
const compiler = createKyselyUOWCompiler(testSchema, config);
|
|
428
|
+
const compiled = uow.compile(compiler);
|
|
429
|
+
const [batch] = compiled.mutationBatch;
|
|
430
|
+
assert(batch);
|
|
431
|
+
expect(batch.expectedAffectedRows).toBeNull();
|
|
432
|
+
expect(batch.query.sql).toMatchInlineSnapshot(
|
|
433
|
+
`"delete from "users" where "users"."id" = $1"`,
|
|
434
|
+
);
|
|
435
|
+
expect(batch.query.parameters).toMatchObject(["user123"]);
|
|
436
|
+
});
|
|
437
|
+
|
|
438
|
+
it("should throw when trying to check() with string ID on update", () => {
|
|
439
|
+
const uow = createTestUOW();
|
|
440
|
+
expect(() => {
|
|
441
|
+
uow.update("users", "user123", (b) => b.set({ name: "Jane" }).check());
|
|
442
|
+
}).toThrow(
|
|
443
|
+
'Cannot use check() with a string ID on table "users". Version checking requires a FragnoId with version information.',
|
|
444
|
+
);
|
|
445
|
+
});
|
|
446
|
+
|
|
447
|
+
it("should throw when trying to check() with string ID on delete", () => {
|
|
448
|
+
const uow = createTestUOW();
|
|
449
|
+
expect(() => {
|
|
450
|
+
uow.delete("users", "user123", (b) => b.check());
|
|
451
|
+
}).toThrow(
|
|
452
|
+
'Cannot use check() with a string ID on table "users". Version checking requires a FragnoId with version information.',
|
|
453
|
+
);
|
|
454
|
+
});
|
|
455
|
+
|
|
456
|
+
it("should compile multiple mutation operations", () => {
|
|
457
|
+
const uow = createTestUOW();
|
|
458
|
+
uow.create("users", {
|
|
459
|
+
name: "Alice",
|
|
460
|
+
email: "alice@example.com",
|
|
461
|
+
});
|
|
462
|
+
const postId = FragnoId.fromExternal("post123", 0);
|
|
463
|
+
uow.update("posts", postId, (b) => b.set({ viewCount: 10 }));
|
|
464
|
+
const userId = FragnoId.fromExternal("user456", 0);
|
|
465
|
+
uow.delete("posts", userId);
|
|
466
|
+
|
|
467
|
+
const compiler = createKyselyUOWCompiler(testSchema, config);
|
|
468
|
+
const compiled = uow.compile(compiler);
|
|
469
|
+
const [createBatch, updateBatch, deleteBatch] = compiled.mutationBatch;
|
|
470
|
+
|
|
471
|
+
expect(compiled.mutationBatch).toHaveLength(3);
|
|
472
|
+
|
|
473
|
+
assert(createBatch);
|
|
474
|
+
expect(createBatch.query.sql).toMatchInlineSnapshot(
|
|
475
|
+
`"insert into "users" ("id", "name", "email") values ($1, $2, $3) returning "users"."id" as "id", "users"."name" as "name", "users"."email" as "email", "users"."age" as "age", "users"."invitedBy" as "invitedBy", "users"."_internalId" as "_internalId", "users"."_version" as "_version""`,
|
|
476
|
+
);
|
|
477
|
+
expect(createBatch.query.parameters).toMatchObject([
|
|
478
|
+
expect.any(String),
|
|
479
|
+
"Alice",
|
|
480
|
+
"alice@example.com",
|
|
481
|
+
]);
|
|
482
|
+
|
|
483
|
+
assert(updateBatch);
|
|
484
|
+
expect(updateBatch.query.sql).toMatchInlineSnapshot(
|
|
485
|
+
`"update "posts" set "viewCount" = $1, "_version" = COALESCE(_version, 0) + 1 where "posts"."id" = $2"`,
|
|
486
|
+
);
|
|
487
|
+
|
|
488
|
+
assert(deleteBatch);
|
|
489
|
+
expect(deleteBatch.query.sql).toMatchInlineSnapshot(
|
|
490
|
+
`"delete from "posts" where "posts"."id" = $1"`,
|
|
491
|
+
);
|
|
492
|
+
});
|
|
493
|
+
});
|
|
494
|
+
|
|
495
|
+
describe("complete UOW workflow", () => {
|
|
496
|
+
it("should compile retrieval and mutation phases together", () => {
|
|
497
|
+
const uow = createTestUOW("update-user-balance");
|
|
498
|
+
|
|
499
|
+
// Retrieval phase
|
|
500
|
+
uow.find("users", (b) => b.whereIndex("primary", (eb) => eb("id", "=", "user123")));
|
|
501
|
+
|
|
502
|
+
// Mutation phase
|
|
503
|
+
const userId = FragnoId.fromExternal("user123", 3);
|
|
504
|
+
uow.update("users", userId, (b) => b.set({ age: 31 }).check());
|
|
505
|
+
|
|
506
|
+
const compiler = createKyselyUOWCompiler(testSchema, config);
|
|
507
|
+
const compiled = uow.compile(compiler);
|
|
508
|
+
|
|
509
|
+
expect(compiled.name).toBe("update-user-balance");
|
|
510
|
+
expect(compiled.retrievalBatch).toHaveLength(1);
|
|
511
|
+
expect(compiled.mutationBatch).toHaveLength(1);
|
|
512
|
+
|
|
513
|
+
expect(compiled.retrievalBatch[0].sql).toMatchInlineSnapshot(
|
|
514
|
+
`"select "users"."id" as "id", "users"."name" as "name", "users"."email" as "email", "users"."age" as "age", "users"."invitedBy" as "invitedBy", "users"."_internalId" as "_internalId", "users"."_version" as "_version" from "users" where "users"."id" = $1"`,
|
|
515
|
+
);
|
|
516
|
+
|
|
517
|
+
// Update should include version check in WHERE clause
|
|
518
|
+
const [batch] = compiled.mutationBatch;
|
|
519
|
+
assert(batch);
|
|
520
|
+
expect(batch.expectedAffectedRows).toBe(1);
|
|
521
|
+
expect(batch.query.sql).toMatchInlineSnapshot(
|
|
522
|
+
`"update "users" set "age" = $1, "_version" = COALESCE(_version, 0) + 1 where ("users"."id" = $2 and "users"."_version" = $3)"`,
|
|
523
|
+
);
|
|
524
|
+
});
|
|
525
|
+
|
|
526
|
+
it("should handle complex where conditions", () => {
|
|
527
|
+
const uow = createTestUOW();
|
|
528
|
+
uow.find("users", (b) =>
|
|
529
|
+
b.whereIndex("idx_email", (eb) =>
|
|
530
|
+
eb.and(
|
|
531
|
+
eb("email", "contains", "@example.com"),
|
|
532
|
+
// @ts-expect-error - name is not indexed
|
|
533
|
+
eb.or(eb("name", "=", "Alice"), eb("name", "=", "Bob")),
|
|
534
|
+
),
|
|
535
|
+
),
|
|
536
|
+
);
|
|
537
|
+
|
|
538
|
+
const compiler = createKyselyUOWCompiler(testSchema, config);
|
|
539
|
+
const compiled = uow.compile(compiler);
|
|
540
|
+
|
|
541
|
+
expect(compiled.retrievalBatch).toHaveLength(1);
|
|
542
|
+
expect(compiled.retrievalBatch[0].sql).toMatchInlineSnapshot(
|
|
543
|
+
`"select "users"."id" as "id", "users"."name" as "name", "users"."email" as "email", "users"."age" as "age", "users"."invitedBy" as "invitedBy", "users"."_internalId" as "_internalId", "users"."_version" as "_version" from "users" where ("users"."email" like $1 and ("users"."name" = $2 or "users"."name" = $3))"`,
|
|
544
|
+
);
|
|
545
|
+
expect(compiled.retrievalBatch[0].parameters).toEqual(["%@example.com%", "Alice", "Bob"]);
|
|
546
|
+
});
|
|
547
|
+
|
|
548
|
+
it("should return null for operations with always-false conditions", () => {
|
|
549
|
+
const uow = createTestUOW();
|
|
550
|
+
uow.find("users", (b) => b.whereIndex("primary", () => false));
|
|
551
|
+
|
|
552
|
+
const compiler = createKyselyUOWCompiler(testSchema, config);
|
|
553
|
+
const compiled = uow.compile(compiler);
|
|
554
|
+
|
|
555
|
+
// When condition is false, the operation should return null and not be added to batch
|
|
556
|
+
expect(compiled.retrievalBatch).toHaveLength(0);
|
|
557
|
+
});
|
|
558
|
+
|
|
559
|
+
it("should handle always-true conditions", () => {
|
|
560
|
+
const uow = createTestUOW();
|
|
561
|
+
uow.find("users", (b) => b.whereIndex("primary", () => true));
|
|
562
|
+
|
|
563
|
+
const compiler = createKyselyUOWCompiler(testSchema, config);
|
|
564
|
+
const compiled = uow.compile(compiler);
|
|
565
|
+
|
|
566
|
+
expect(compiled.retrievalBatch).toHaveLength(1);
|
|
567
|
+
expect(compiled.retrievalBatch[0].sql).toMatchInlineSnapshot(
|
|
568
|
+
`"select "users"."id" as "id", "users"."name" as "name", "users"."email" as "email", "users"."age" as "age", "users"."invitedBy" as "invitedBy", "users"."_internalId" as "_internalId", "users"."_version" as "_version" from "users""`,
|
|
569
|
+
);
|
|
570
|
+
});
|
|
571
|
+
});
|
|
572
|
+
|
|
573
|
+
describe("version checking", () => {
|
|
574
|
+
it("should embed version check in update WHERE clause", () => {
|
|
575
|
+
const uow = createTestUOW();
|
|
576
|
+
|
|
577
|
+
const userId = FragnoId.fromExternal("user123", 5);
|
|
578
|
+
uow.update("users", userId, (b) => b.set({ age: 31 }).check());
|
|
579
|
+
|
|
580
|
+
const compiler = createKyselyUOWCompiler(testSchema, config);
|
|
581
|
+
const compiled = uow.compile(compiler);
|
|
582
|
+
const [batch] = compiled.mutationBatch;
|
|
583
|
+
assert(batch);
|
|
584
|
+
expect(batch.expectedAffectedRows).toBe(1);
|
|
585
|
+
expect(batch.query.sql).toMatchInlineSnapshot(
|
|
586
|
+
`"update "users" set "age" = $1, "_version" = COALESCE(_version, 0) + 1 where ("users"."id" = $2 and "users"."_version" = $3)"`,
|
|
587
|
+
);
|
|
588
|
+
expect(batch.query.parameters).toMatchObject([31, "user123", 5]);
|
|
589
|
+
});
|
|
590
|
+
|
|
591
|
+
it("should embed version check in delete WHERE clause", () => {
|
|
592
|
+
const uow = createTestUOW();
|
|
593
|
+
|
|
594
|
+
const userId = FragnoId.fromExternal("user456", 3);
|
|
595
|
+
uow.delete("users", userId, (b) => b.check());
|
|
596
|
+
|
|
597
|
+
const compiler = createKyselyUOWCompiler(testSchema, config);
|
|
598
|
+
const compiled = uow.compile(compiler);
|
|
599
|
+
const [batch] = compiled.mutationBatch;
|
|
600
|
+
assert(batch);
|
|
601
|
+
expect(batch.expectedAffectedRows).toBe(1);
|
|
602
|
+
expect(batch.query.sql).toMatchInlineSnapshot(
|
|
603
|
+
`"delete from "users" where ("users"."id" = $1 and "users"."_version" = $2)"`,
|
|
604
|
+
);
|
|
605
|
+
expect(batch.query.parameters).toMatchObject(["user456", 3]);
|
|
606
|
+
});
|
|
607
|
+
|
|
608
|
+
it("should handle version checks on different tables", () => {
|
|
609
|
+
const uow = createTestUOW();
|
|
610
|
+
|
|
611
|
+
const userId = FragnoId.fromExternal("user1", 2);
|
|
612
|
+
const postId = FragnoId.fromExternal("post1", 1);
|
|
613
|
+
|
|
614
|
+
uow.update("users", userId, (b) => b.set({ age: 30 }).check());
|
|
615
|
+
uow.update("posts", postId, (b) => b.set({ viewCount: 100 }).check());
|
|
616
|
+
|
|
617
|
+
const compiler = createKyselyUOWCompiler(testSchema, config);
|
|
618
|
+
const compiled = uow.compile(compiler);
|
|
619
|
+
const [userBatch, postBatch] = compiled.mutationBatch;
|
|
620
|
+
|
|
621
|
+
expect(compiled.mutationBatch).toHaveLength(2);
|
|
622
|
+
|
|
623
|
+
assert(userBatch);
|
|
624
|
+
expect(userBatch.expectedAffectedRows).toBe(1);
|
|
625
|
+
expect(userBatch.query.sql).toMatchInlineSnapshot(
|
|
626
|
+
`"update "users" set "age" = $1, "_version" = COALESCE(_version, 0) + 1 where ("users"."id" = $2 and "users"."_version" = $3)"`,
|
|
627
|
+
);
|
|
628
|
+
expect(userBatch.query.parameters).toMatchObject([30, "user1", 2]);
|
|
629
|
+
|
|
630
|
+
assert(postBatch);
|
|
631
|
+
expect(postBatch.expectedAffectedRows).toBe(1);
|
|
632
|
+
expect(postBatch.query.sql).toMatchInlineSnapshot(
|
|
633
|
+
`"update "posts" set "viewCount" = $1, "_version" = COALESCE(_version, 0) + 1 where ("posts"."id" = $2 and "posts"."_version" = $3)"`,
|
|
634
|
+
);
|
|
635
|
+
expect(postBatch.query.parameters).toMatchObject([100, "post1", 1]);
|
|
636
|
+
});
|
|
637
|
+
|
|
638
|
+
it("should not affect updates without version checks", () => {
|
|
639
|
+
const uow = createTestUOW();
|
|
640
|
+
|
|
641
|
+
const userId = FragnoId.fromExternal("user1", 0);
|
|
642
|
+
uow.update("users", userId, (b) => b.set({ age: 25 }));
|
|
643
|
+
|
|
644
|
+
const compiler = createKyselyUOWCompiler(testSchema, config);
|
|
645
|
+
const compiled = uow.compile(compiler);
|
|
646
|
+
const [batch] = compiled.mutationBatch;
|
|
647
|
+
assert(batch);
|
|
648
|
+
expect(batch.expectedAffectedRows).toBeNull();
|
|
649
|
+
// Should be normal update without version check
|
|
650
|
+
expect(batch.query.sql).toMatchInlineSnapshot(
|
|
651
|
+
`"update "users" set "age" = $1, "_version" = COALESCE(_version, 0) + 1 where "users"."id" = $2"`,
|
|
652
|
+
);
|
|
653
|
+
});
|
|
654
|
+
});
|
|
655
|
+
|
|
656
|
+
describe("join operations", () => {
|
|
657
|
+
it("should compile find operation with basic join", () => {
|
|
658
|
+
const uow = createTestUOW();
|
|
659
|
+
uow.find("posts", (b) =>
|
|
660
|
+
b.whereIndex("primary").join((jb) => jb.author((ab) => ab.select(["name", "email"]))),
|
|
661
|
+
);
|
|
662
|
+
|
|
663
|
+
const compiler = createKyselyUOWCompiler(testSchema, config);
|
|
664
|
+
const compiled = uow.compile(compiler);
|
|
665
|
+
|
|
666
|
+
expect(compiled.retrievalBatch).toHaveLength(1);
|
|
667
|
+
const query = compiled.retrievalBatch[0];
|
|
668
|
+
assert(query);
|
|
669
|
+
expect(query.sql).toContain("left join");
|
|
670
|
+
expect(query.sql).toContain('"users" as "author"');
|
|
671
|
+
expect(query.sql).toContain('"author"."name"');
|
|
672
|
+
expect(query.sql).toContain('"author"."email"');
|
|
673
|
+
});
|
|
674
|
+
|
|
675
|
+
it("should compile join with whereIndex filtering", () => {
|
|
676
|
+
const uow = createTestUOW();
|
|
677
|
+
uow.find("posts", (b) =>
|
|
678
|
+
b
|
|
679
|
+
.whereIndex("primary")
|
|
680
|
+
.join((jb) =>
|
|
681
|
+
jb.author((ab) =>
|
|
682
|
+
ab.select(["name"]).whereIndex("idx_name", (eb) => eb("name", "=", "Alice")),
|
|
683
|
+
),
|
|
684
|
+
),
|
|
685
|
+
);
|
|
686
|
+
|
|
687
|
+
const compiler = createKyselyUOWCompiler(testSchema, config);
|
|
688
|
+
const compiled = uow.compile(compiler);
|
|
689
|
+
|
|
690
|
+
expect(compiled.retrievalBatch).toHaveLength(1);
|
|
691
|
+
const query = compiled.retrievalBatch[0];
|
|
692
|
+
assert(query);
|
|
693
|
+
expect(query.sql).toContain("left join");
|
|
694
|
+
expect(query.sql).toContain('"users"."name" = $1');
|
|
695
|
+
expect(query.parameters).toContain("Alice");
|
|
696
|
+
});
|
|
697
|
+
|
|
698
|
+
it("should compile join with orderByIndex", () => {
|
|
699
|
+
const uow = createTestUOW();
|
|
700
|
+
uow.find("posts", (b) =>
|
|
701
|
+
b
|
|
702
|
+
.whereIndex("primary")
|
|
703
|
+
.join((jb) => jb.author((ab) => ab.select(["name"]).orderByIndex("idx_name", "desc"))),
|
|
704
|
+
);
|
|
705
|
+
|
|
706
|
+
const compiler = createKyselyUOWCompiler(testSchema, config);
|
|
707
|
+
const compiled = uow.compile(compiler);
|
|
708
|
+
|
|
709
|
+
expect(compiled.retrievalBatch).toHaveLength(1);
|
|
710
|
+
const query = compiled.retrievalBatch[0];
|
|
711
|
+
assert(query);
|
|
712
|
+
expect(query.sql).toContain("left join");
|
|
713
|
+
expect(query.sql).toContain('"users" as "author"');
|
|
714
|
+
});
|
|
715
|
+
|
|
716
|
+
it("should compile join with pageSize", () => {
|
|
717
|
+
const uow = createTestUOW();
|
|
718
|
+
uow.find("posts", (b) =>
|
|
719
|
+
b.whereIndex("primary").join((jb) => jb.author((ab) => ab.select(["name"]).pageSize(5))),
|
|
720
|
+
);
|
|
721
|
+
|
|
722
|
+
const compiler = createKyselyUOWCompiler(testSchema, config);
|
|
723
|
+
const compiled = uow.compile(compiler);
|
|
724
|
+
|
|
725
|
+
expect(compiled.retrievalBatch).toHaveLength(1);
|
|
726
|
+
const query = compiled.retrievalBatch[0];
|
|
727
|
+
assert(query);
|
|
728
|
+
expect(query.sql).toContain("left join");
|
|
729
|
+
});
|
|
730
|
+
|
|
731
|
+
it("should compile nested joins", () => {
|
|
732
|
+
const uow = createTestUOW();
|
|
733
|
+
uow.find("posts", (b) =>
|
|
734
|
+
b.whereIndex("primary").join((jb) =>
|
|
735
|
+
jb.author((ab) =>
|
|
736
|
+
// FIXME: inviter should be strongly typed
|
|
737
|
+
ab.select(["name"]).join((jb2) => {
|
|
738
|
+
// type Prettify<T> = {
|
|
739
|
+
// [K in keyof T]: T[K];
|
|
740
|
+
// } & {};
|
|
741
|
+
|
|
742
|
+
// type InviterFn = Prettify<(typeof jb2)["inviter"]>;
|
|
743
|
+
// expectTypeOf<InviterFn>().toEqualTypeOf<{ [x: string]: any }>();
|
|
744
|
+
// type BuilderKeys = Prettify<keyof typeof jb2>;
|
|
745
|
+
// expectTypeOf<BuilderKeys>().toEqualTypeOf<string | symbol | number>();
|
|
746
|
+
|
|
747
|
+
return jb2["inviter"]((ib) => ib.select(["name"]));
|
|
748
|
+
}),
|
|
749
|
+
),
|
|
750
|
+
),
|
|
751
|
+
);
|
|
752
|
+
|
|
753
|
+
const compiler = createKyselyUOWCompiler(testSchema, config);
|
|
754
|
+
const compiled = uow.compile(compiler);
|
|
755
|
+
|
|
756
|
+
expect(compiled.retrievalBatch).toHaveLength(1);
|
|
757
|
+
const query = compiled.retrievalBatch[0];
|
|
758
|
+
assert(query);
|
|
759
|
+
expect(query.sql).toMatchInlineSnapshot(
|
|
760
|
+
`"select "author"."name" as "author:name", "author"."_internalId" as "author:_internalId", "author"."_version" as "author:_version", "author_inviter"."name" as "author:inviter:name", "author_inviter"."_internalId" as "author:inviter:_internalId", "author_inviter"."_version" as "author:inviter:_version", "posts"."id" as "id", "posts"."title" as "title", "posts"."content" as "content", "posts"."userId" as "userId", "posts"."viewCount" as "viewCount", "posts"."_internalId" as "_internalId", "posts"."_version" as "_version" from "posts" left join "users" as "author" on "posts"."userId" = "author"."_internalId" left join "users" as "author_inviter" on "author"."invitedBy" = "author_inviter"."_internalId""`,
|
|
761
|
+
);
|
|
762
|
+
});
|
|
763
|
+
|
|
764
|
+
it("should compile multiple joins", () => {
|
|
765
|
+
const uow = createTestUOW();
|
|
766
|
+
uow.find("comments", (b) =>
|
|
767
|
+
b
|
|
768
|
+
.whereIndex("primary")
|
|
769
|
+
.join((jb) => jb.post((pb) => pb.select(["title"])).author((ab) => ab.select(["name"]))),
|
|
770
|
+
);
|
|
771
|
+
|
|
772
|
+
const compiler = createKyselyUOWCompiler(testSchema, config);
|
|
773
|
+
const compiled = uow.compile(compiler);
|
|
774
|
+
|
|
775
|
+
expect(compiled.retrievalBatch).toHaveLength(1);
|
|
776
|
+
const query = compiled.retrievalBatch[0];
|
|
777
|
+
assert(query);
|
|
778
|
+
expect(query.sql).toContain('"posts" as "post"');
|
|
779
|
+
expect(query.sql).toContain('"users" as "author"');
|
|
780
|
+
expect(query.sql).toContain('"post"."title"');
|
|
781
|
+
expect(query.sql).toContain('"author"."name"');
|
|
782
|
+
});
|
|
783
|
+
|
|
784
|
+
it("should compile self-referencing join", () => {
|
|
785
|
+
const uow = createTestUOW();
|
|
786
|
+
uow.find("users", (b) =>
|
|
787
|
+
b.whereIndex("primary").join((jb) => jb.inviter((ib) => ib.select(["name", "email"]))),
|
|
788
|
+
);
|
|
789
|
+
|
|
790
|
+
const compiler = createKyselyUOWCompiler(testSchema, config);
|
|
791
|
+
const compiled = uow.compile(compiler);
|
|
792
|
+
|
|
793
|
+
expect(compiled.retrievalBatch).toHaveLength(1);
|
|
794
|
+
const query = compiled.retrievalBatch[0];
|
|
795
|
+
assert(query);
|
|
796
|
+
expect(query.sql).toContain('"users" as "inviter"');
|
|
797
|
+
expect(query.sql).toContain('"inviter"."name"');
|
|
798
|
+
expect(query.sql).toContain('"inviter"."email"');
|
|
799
|
+
});
|
|
800
|
+
|
|
801
|
+
it("should compile join with all builder features combined", () => {
|
|
802
|
+
const uow = createTestUOW();
|
|
803
|
+
uow.find("posts", (b) =>
|
|
804
|
+
b
|
|
805
|
+
.whereIndex("idx_title", (eb) => eb("title", "contains", "test"))
|
|
806
|
+
.select(["id", "title"])
|
|
807
|
+
.orderByIndex("idx_title", "asc")
|
|
808
|
+
.pageSize(10)
|
|
809
|
+
.join((jb) =>
|
|
810
|
+
jb.author((ab) =>
|
|
811
|
+
ab
|
|
812
|
+
.select(["name", "email"])
|
|
813
|
+
.whereIndex("idx_name", (eb) => eb("name", "starts with", "A"))
|
|
814
|
+
.orderByIndex("idx_name", "desc")
|
|
815
|
+
.pageSize(5),
|
|
816
|
+
),
|
|
817
|
+
),
|
|
818
|
+
);
|
|
819
|
+
|
|
820
|
+
const compiler = createKyselyUOWCompiler(testSchema, config);
|
|
821
|
+
const compiled = uow.compile(compiler);
|
|
822
|
+
|
|
823
|
+
expect(compiled.retrievalBatch).toHaveLength(1);
|
|
824
|
+
const query = compiled.retrievalBatch[0];
|
|
825
|
+
assert(query);
|
|
826
|
+
// Main query features
|
|
827
|
+
expect(query.sql).toContain('"posts"."title" like');
|
|
828
|
+
expect(query.sql).toContain("order by");
|
|
829
|
+
expect(query.sql).toContain("limit");
|
|
830
|
+
// Join features
|
|
831
|
+
expect(query.sql).toContain('"users" as "author"');
|
|
832
|
+
expect(query.sql).toContain('"users"."name" like');
|
|
833
|
+
});
|
|
834
|
+
|
|
835
|
+
it("should compile many-to-many join through junction table", () => {
|
|
836
|
+
const uow = createTestUOW();
|
|
837
|
+
uow.find("post_tags", (b) =>
|
|
838
|
+
b
|
|
839
|
+
.whereIndex("primary")
|
|
840
|
+
.join((jb) => jb.post((pb) => pb.select(["title"])).tag((tb) => tb.select(["name"]))),
|
|
841
|
+
);
|
|
842
|
+
|
|
843
|
+
const compiler = createKyselyUOWCompiler(testSchema, config);
|
|
844
|
+
const compiled = uow.compile(compiler);
|
|
845
|
+
|
|
846
|
+
expect(compiled.retrievalBatch).toHaveLength(1);
|
|
847
|
+
const query = compiled.retrievalBatch[0];
|
|
848
|
+
assert(query);
|
|
849
|
+
expect(query.sql).toMatchInlineSnapshot(
|
|
850
|
+
`"select "post"."title" as "post:title", "post"."_internalId" as "post:_internalId", "post"."_version" as "post:_version", "tag"."name" as "tag:name", "tag"."_internalId" as "tag:_internalId", "tag"."_version" as "tag:_version", "post_tags"."id" as "id", "post_tags"."postId" as "postId", "post_tags"."tagId" as "tagId", "post_tags"."_internalId" as "_internalId", "post_tags"."_version" as "_version" from "post_tags" left join "posts" as "post" on "post_tags"."postId" = "post"."_internalId" left join "tags" as "tag" on "post_tags"."tagId" = "tag"."_internalId""`,
|
|
851
|
+
);
|
|
852
|
+
});
|
|
853
|
+
|
|
854
|
+
it("should compile nested many-to-many join (post_tags -> post -> author)", () => {
|
|
855
|
+
const uow = createTestUOW();
|
|
856
|
+
uow.find("post_tags", (b) =>
|
|
857
|
+
b
|
|
858
|
+
.whereIndex("primary")
|
|
859
|
+
.join((jb) =>
|
|
860
|
+
jb.post((pb) =>
|
|
861
|
+
pb
|
|
862
|
+
.select(["title"])
|
|
863
|
+
.join((jb2) => jb2["author"]((ab) => ab.select(["name", "email"]))),
|
|
864
|
+
),
|
|
865
|
+
),
|
|
866
|
+
);
|
|
867
|
+
|
|
868
|
+
const compiler = createKyselyUOWCompiler(testSchema, config);
|
|
869
|
+
const compiled = uow.compile(compiler);
|
|
870
|
+
|
|
871
|
+
expect(compiled.retrievalBatch).toHaveLength(1);
|
|
872
|
+
const query = compiled.retrievalBatch[0];
|
|
873
|
+
assert(query);
|
|
874
|
+
expect(query.sql).toMatchInlineSnapshot(
|
|
875
|
+
`"select "post"."title" as "post:title", "post"."_internalId" as "post:_internalId", "post"."_version" as "post:_version", "post_author"."name" as "post:author:name", "post_author"."email" as "post:author:email", "post_author"."_internalId" as "post:author:_internalId", "post_author"."_version" as "post:author:_version", "post_tags"."id" as "id", "post_tags"."postId" as "postId", "post_tags"."tagId" as "tagId", "post_tags"."_internalId" as "_internalId", "post_tags"."_version" as "_version" from "post_tags" left join "posts" as "post" on "post_tags"."postId" = "post"."_internalId" left join "users" as "post_author" on "post"."userId" = "post_author"."_internalId""`,
|
|
876
|
+
);
|
|
877
|
+
});
|
|
878
|
+
});
|
|
879
|
+
|
|
880
|
+
describe("edge cases", () => {
|
|
881
|
+
it("should handle UOW with no operations", () => {
|
|
882
|
+
const uow = createTestUOW();
|
|
883
|
+
|
|
884
|
+
const compiler = createKyselyUOWCompiler(testSchema, config);
|
|
885
|
+
const compiled = uow.compile(compiler);
|
|
886
|
+
|
|
887
|
+
expect(compiled.retrievalBatch).toHaveLength(0);
|
|
888
|
+
expect(compiled.mutationBatch).toHaveLength(0);
|
|
889
|
+
});
|
|
890
|
+
|
|
891
|
+
it("should handle UOW with only retrieval operations", () => {
|
|
892
|
+
const uow = createTestUOW();
|
|
893
|
+
uow.find("users");
|
|
894
|
+
|
|
895
|
+
const compiler = createKyselyUOWCompiler(testSchema, config);
|
|
896
|
+
const compiled = uow.compile(compiler);
|
|
897
|
+
|
|
898
|
+
expect(compiled.retrievalBatch).toHaveLength(1);
|
|
899
|
+
expect(compiled.mutationBatch).toHaveLength(0);
|
|
900
|
+
});
|
|
901
|
+
|
|
902
|
+
it("should handle UOW with only mutation operations", () => {
|
|
903
|
+
const uow = createTestUOW();
|
|
904
|
+
uow.create("users", {
|
|
905
|
+
name: "Test User",
|
|
906
|
+
email: "test@example.com",
|
|
907
|
+
});
|
|
908
|
+
|
|
909
|
+
const compiler = createKyselyUOWCompiler(testSchema, config);
|
|
910
|
+
const compiled = uow.compile(compiler);
|
|
911
|
+
|
|
912
|
+
expect(compiled.retrievalBatch).toHaveLength(0);
|
|
913
|
+
expect(compiled.mutationBatch).toHaveLength(1);
|
|
914
|
+
});
|
|
915
|
+
});
|
|
916
|
+
});
|