metal-orm 1.0.58 → 1.0.60

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 (41) hide show
  1. package/README.md +34 -31
  2. package/dist/index.cjs +1583 -901
  3. package/dist/index.cjs.map +1 -1
  4. package/dist/index.d.cts +400 -129
  5. package/dist/index.d.ts +400 -129
  6. package/dist/index.js +1575 -901
  7. package/dist/index.js.map +1 -1
  8. package/package.json +1 -1
  9. package/src/core/ddl/schema-generator.ts +44 -1
  10. package/src/decorators/bootstrap.ts +183 -146
  11. package/src/decorators/column-decorator.ts +8 -49
  12. package/src/decorators/decorator-metadata.ts +10 -46
  13. package/src/decorators/entity.ts +30 -40
  14. package/src/decorators/relations.ts +30 -56
  15. package/src/index.ts +7 -7
  16. package/src/orm/entity-hydration.ts +72 -0
  17. package/src/orm/entity-meta.ts +13 -11
  18. package/src/orm/entity-metadata.ts +240 -238
  19. package/src/orm/entity-relation-cache.ts +39 -0
  20. package/src/orm/entity-relations.ts +207 -0
  21. package/src/orm/entity.ts +124 -410
  22. package/src/orm/execute.ts +4 -4
  23. package/src/orm/lazy-batch/belongs-to-many.ts +134 -0
  24. package/src/orm/lazy-batch/belongs-to.ts +108 -0
  25. package/src/orm/lazy-batch/has-many.ts +69 -0
  26. package/src/orm/lazy-batch/has-one.ts +68 -0
  27. package/src/orm/lazy-batch/shared.ts +125 -0
  28. package/src/orm/lazy-batch.ts +4 -492
  29. package/src/orm/relations/many-to-many.ts +2 -1
  30. package/src/query-builder/relation-cte-builder.ts +63 -0
  31. package/src/query-builder/relation-filter-utils.ts +159 -0
  32. package/src/query-builder/relation-include-strategies.ts +177 -0
  33. package/src/query-builder/relation-join-planner.ts +80 -0
  34. package/src/query-builder/relation-service.ts +119 -479
  35. package/src/query-builder/relation-types.ts +41 -10
  36. package/src/query-builder/select/projection-facet.ts +23 -23
  37. package/src/query-builder/select/select-operations.ts +145 -0
  38. package/src/query-builder/select.ts +329 -221
  39. package/src/schema/relation.ts +22 -18
  40. package/src/schema/table.ts +22 -9
  41. package/src/schema/types.ts +14 -12
package/src/orm/entity.ts CHANGED
@@ -1,410 +1,124 @@
1
- import { TableDef } from '../schema/table.js';
2
- import { EntityInstance, RelationMap, HasManyCollection, HasOneReference, BelongsToReference, ManyToManyCollection } from '../schema/types.js';
3
- import { EntityContext } from './entity-context.js';
4
- import { ENTITY_META, EntityMeta, getEntityMeta } from './entity-meta.js';
5
- import { DefaultHasManyCollection } from './relations/has-many.js';
6
- import { DefaultHasOneReference } from './relations/has-one.js';
7
- import { DefaultBelongsToReference } from './relations/belongs-to.js';
8
- import { DefaultManyToManyCollection } from './relations/many-to-many.js';
9
- import { HasManyRelation, HasOneRelation, BelongsToRelation, BelongsToManyRelation, RelationKinds } from '../schema/relation.js';
10
- import { loadHasManyRelation, loadHasOneRelation, loadBelongsToRelation, loadBelongsToManyRelation } from './lazy-batch.js';
11
- import { findPrimaryKey } from '../query-builder/hydration-planner.js';
12
- import { RelationIncludeOptions } from '../query-builder/relation-types.js';
13
-
14
- /**
15
- * Type representing an array of database rows.
16
- */
17
- type Rows = Record<string, unknown>[];
18
-
19
- /**
20
- * Caches relation loader results across entities of the same type.
21
- * @template T - The cache type
22
- * @param meta - The entity metadata
23
- * @param relationName - The relation name
24
- * @param factory - The factory function to create the cache
25
- * @returns Promise with the cached relation data
26
- */
27
- export const relationLoaderCache = <T extends Map<string, unknown>>(
28
- meta: EntityMeta<TableDef>,
29
- relationName: string,
30
- factory: () => Promise<T>
31
- ): Promise<T> => {
32
- if (meta.relationCache.has(relationName)) {
33
- return meta.relationCache.get(relationName)! as Promise<T>;
34
- }
35
-
36
- const promise = factory().then(value => {
37
- for (const tracked of meta.ctx.getEntitiesForTable(meta.table)) {
38
- const otherMeta = getEntityMeta(tracked.entity);
39
- if (!otherMeta) continue;
40
- otherMeta.relationHydration.set(relationName, value);
41
- }
42
- return value;
43
- });
44
-
45
- meta.relationCache.set(relationName, promise);
46
-
47
- for (const tracked of meta.ctx.getEntitiesForTable(meta.table)) {
48
- const otherMeta = getEntityMeta(tracked.entity);
49
- if (!otherMeta) continue;
50
- otherMeta.relationCache.set(relationName, promise);
51
- }
52
-
53
- return promise;
54
- };
55
-
56
- /**
57
- * Creates an entity proxy with lazy loading capabilities.
58
- * @template TTable - The table type
59
- * @template TLazy - The lazy relation keys
60
- * @param ctx - The entity context
61
- * @param table - The table definition
62
- * @param row - The database row
63
- * @param lazyRelations - Optional lazy relations
64
- * @returns The entity instance
65
- */
66
- export const createEntityProxy = <
67
- TTable extends TableDef,
68
- TLazy extends keyof RelationMap<TTable> = keyof RelationMap<TTable>
69
- >(
70
- ctx: EntityContext,
71
- table: TTable,
72
- row: Record<string, unknown>,
73
- lazyRelations: TLazy[] = [] as TLazy[],
74
- lazyRelationOptions: Map<string, RelationIncludeOptions> = new Map()
75
- ): EntityInstance<TTable> => {
76
- const target: Record<string, unknown> = { ...row };
77
- const meta: EntityMeta<TTable> = {
78
- ctx,
79
- table,
80
- lazyRelations: [...lazyRelations],
81
- lazyRelationOptions: new Map(lazyRelationOptions),
82
- relationCache: new Map(),
83
- relationHydration: new Map(),
84
- relationWrappers: new Map()
85
- };
86
-
87
- Object.defineProperty(target, ENTITY_META, {
88
- value: meta,
89
- enumerable: false,
90
- writable: false
91
- });
92
-
93
- const handler: ProxyHandler<object> = {
94
- get(targetObj, prop, receiver) {
95
- if (prop === ENTITY_META) {
96
- return meta;
97
- }
98
-
99
- if (prop === '$load') {
100
- return async (relationName: keyof RelationMap<TTable>) => {
101
- const wrapper = getRelationWrapper(meta as unknown as EntityMeta<TableDef>, relationName as string, receiver);
102
- if (wrapper && typeof wrapper.load === 'function') {
103
- return wrapper.load();
104
- }
105
- return undefined;
106
- };
107
- }
108
-
109
- if (typeof prop === 'string' && table.relations[prop]) {
110
- return getRelationWrapper(meta as unknown as EntityMeta<TableDef>, prop, receiver);
111
- }
112
-
113
- return Reflect.get(targetObj, prop, receiver);
114
- },
115
-
116
- set(targetObj, prop, value, receiver) {
117
- const result = Reflect.set(targetObj, prop, value, receiver);
118
- if (typeof prop === 'string' && table.columns[prop]) {
119
- ctx.markDirty(receiver);
120
- }
121
- return result;
122
- }
123
- };
124
-
125
- const proxy = new Proxy(target, handler) as EntityInstance<TTable>;
126
- populateHydrationCache(proxy, row, meta);
127
- return proxy;
128
- };
129
-
130
- /**
131
- * Creates an entity instance from a database row.
132
- * @template TTable - The table type
133
- * @template TResult - The result type
134
- * @param ctx - The entity context
135
- * @param table - The table definition
136
- * @param row - The database row
137
- * @param lazyRelations - Optional lazy relations
138
- * @returns The entity instance
139
- */
140
- export const createEntityFromRow = <
141
- TTable extends TableDef,
142
- TResult extends EntityInstance<TTable> = EntityInstance<TTable>
143
- >(
144
- ctx: EntityContext,
145
- table: TTable,
146
- row: Record<string, unknown>,
147
- lazyRelations: (keyof RelationMap<TTable>)[] = [],
148
- lazyRelationOptions: Map<string, RelationIncludeOptions> = new Map()
149
- ): TResult => {
150
- const pkName = findPrimaryKey(table);
151
- const pkValue = row[pkName];
152
- if (pkValue !== undefined && pkValue !== null) {
153
- const tracked = ctx.getEntity(table, pkValue);
154
- if (tracked) return tracked as TResult;
155
- }
156
-
157
- const entity = createEntityProxy(ctx, table, row, lazyRelations, lazyRelationOptions);
158
- if (pkValue !== undefined && pkValue !== null) {
159
- ctx.trackManaged(table, pkValue, entity);
160
- } else {
161
- ctx.trackNew(table, entity);
162
- }
163
-
164
- return entity as TResult;
165
- };
166
-
167
- /**
168
- * Converts a value to a string key.
169
- * @param value - The value to convert
170
- * @returns String representation of the value
171
- */
172
- const toKey = (value: unknown): string => (value === null || value === undefined ? '' : String(value));
173
-
174
- /**
175
- * Populates the hydration cache with relation data from the database row.
176
- * @template TTable - The table type
177
- * @param entity - The entity instance
178
- * @param row - The database row
179
- * @param meta - The entity metadata
180
- */
181
- const populateHydrationCache = <TTable extends TableDef>(
182
- entity: Record<string, unknown>,
183
- row: Record<string, unknown>,
184
- meta: EntityMeta<TTable>
185
- ): void => {
186
- for (const relationName of Object.keys(meta.table.relations)) {
187
- const relation = meta.table.relations[relationName];
188
- const data = row[relationName];
189
- if (relation.type === RelationKinds.HasOne) {
190
- const localKey = relation.localKey || findPrimaryKey(meta.table);
191
- const rootValue = entity[localKey];
192
- if (rootValue === undefined || rootValue === null) continue;
193
- if (!data || typeof data !== 'object') continue;
194
- const cache = new Map<string, Record<string, unknown>>();
195
- cache.set(toKey(rootValue), data as Record<string, unknown>);
196
- meta.relationHydration.set(relationName, cache);
197
- meta.relationCache.set(relationName, Promise.resolve(cache));
198
- continue;
199
- }
200
-
201
- if (!Array.isArray(data)) continue;
202
-
203
- if (relation.type === RelationKinds.HasMany || relation.type === RelationKinds.BelongsToMany) {
204
- const localKey = relation.localKey || findPrimaryKey(meta.table);
205
- const rootValue = entity[localKey];
206
- if (rootValue === undefined || rootValue === null) continue;
207
- const cache = new Map<string, Rows>();
208
- cache.set(toKey(rootValue), data as Rows);
209
- meta.relationHydration.set(relationName, cache);
210
- meta.relationCache.set(relationName, Promise.resolve(cache));
211
- continue;
212
- }
213
-
214
- if (relation.type === RelationKinds.BelongsTo) {
215
- const targetKey = relation.localKey || findPrimaryKey(relation.target);
216
- const cache = new Map<string, Record<string, unknown>>();
217
- for (const item of data) {
218
- const pkValue = item[targetKey];
219
- if (pkValue === undefined || pkValue === null) continue;
220
- cache.set(toKey(pkValue), item);
221
- }
222
- if (cache.size) {
223
- meta.relationHydration.set(relationName, cache);
224
- meta.relationCache.set(relationName, Promise.resolve(cache));
225
- }
226
- }
227
- }
228
- };
229
-
230
- const proxifyRelationWrapper = <T extends object>(wrapper: T): T => {
231
- return new Proxy(wrapper, {
232
- get(target, prop, receiver) {
233
- if (typeof prop === 'symbol') {
234
- return Reflect.get(target, prop, receiver);
235
- }
236
-
237
- if (prop in target) {
238
- return Reflect.get(target, prop, receiver);
239
- }
240
-
241
- const getItems = (target as { getItems?: () => unknown }).getItems;
242
- if (typeof getItems === 'function') {
243
- const items = getItems.call(target);
244
- if (items && prop in (items as object)) {
245
- const propName = prop as string;
246
- const value = (items as Record<string, unknown>)[propName];
247
- return typeof value === 'function' ? value.bind(items) : value;
248
- }
249
- }
250
-
251
- const getRef = (target as { get?: () => unknown }).get;
252
- if (typeof getRef === 'function') {
253
- const current = getRef.call(target);
254
- if (current && prop in (current as object)) {
255
- const propName = prop as string;
256
- const value = (current as Record<string, unknown>)[propName];
257
- return typeof value === 'function' ? value.bind(current) : value;
258
- }
259
- }
260
-
261
- return undefined;
262
- },
263
-
264
- set(target, prop, value, receiver) {
265
- if (typeof prop === 'symbol') {
266
- return Reflect.set(target, prop, value, receiver);
267
- }
268
-
269
- if (prop in target) {
270
- return Reflect.set(target, prop, value, receiver);
271
- }
272
-
273
- const getRef = (target as { get?: () => unknown }).get;
274
- if (typeof getRef === 'function') {
275
- const current = getRef.call(target);
276
- if (current && typeof current === 'object') {
277
- return Reflect.set(current as object, prop, value);
278
- }
279
- }
280
-
281
- const getItems = (target as { getItems?: () => unknown }).getItems;
282
- if (typeof getItems === 'function') {
283
- const items = getItems.call(target);
284
- return Reflect.set(items as object, prop, value);
285
- }
286
-
287
- return Reflect.set(target, prop, value, receiver);
288
- }
289
- });
290
- };
291
-
292
- /**
293
- * Gets a relation wrapper for an entity.
294
- * @param meta - The entity metadata
295
- * @param relationName - The relation name
296
- * @param owner - The owner entity
297
- * @returns The relation wrapper or undefined
298
- */
299
- const getRelationWrapper = (
300
- meta: EntityMeta<TableDef>,
301
- relationName: string,
302
- owner: unknown
303
- ): HasManyCollection<unknown> | HasOneReference<object> | BelongsToReference<object> | ManyToManyCollection<unknown> | undefined => {
304
- if (meta.relationWrappers.has(relationName)) {
305
- return meta.relationWrappers.get(relationName) as HasManyCollection<unknown>;
306
- }
307
-
308
- const relation = meta.table.relations[relationName];
309
- if (!relation) return undefined;
310
-
311
- const wrapper = instantiateWrapper(meta, relationName, relation, owner);
312
- if (!wrapper) return undefined;
313
-
314
- const proxied = proxifyRelationWrapper(wrapper as object);
315
- meta.relationWrappers.set(relationName, proxied);
316
- return proxied as HasManyCollection<unknown>;
317
- };
318
-
319
- /**
320
- * Instantiates the appropriate relation wrapper based on relation type.
321
- * @param meta - The entity metadata
322
- * @param relationName - The relation name
323
- * @param relation - The relation definition
324
- * @param owner - The owner entity
325
- * @returns The relation wrapper or undefined
326
- */
327
- const instantiateWrapper = (
328
- meta: EntityMeta<TableDef>,
329
- relationName: string,
330
- relation: HasManyRelation | HasOneRelation | BelongsToRelation | BelongsToManyRelation,
331
- owner: unknown
332
- ): HasManyCollection<unknown> | HasOneReference<object> | BelongsToReference<object> | ManyToManyCollection<unknown> | undefined => {
333
- const lazyOptions = meta.lazyRelationOptions.get(relationName);
334
- switch (relation.type) {
335
- case RelationKinds.HasOne: {
336
- const hasOne = relation as HasOneRelation;
337
- const localKey = hasOne.localKey || findPrimaryKey(meta.table);
338
- const loader = () => relationLoaderCache(meta, relationName, () =>
339
- loadHasOneRelation(meta.ctx, meta.table, relationName, hasOne, lazyOptions)
340
- );
341
- return new DefaultHasOneReference(
342
- meta.ctx,
343
- meta,
344
- owner,
345
- relationName,
346
- hasOne,
347
- meta.table,
348
- loader,
349
- (row: Record<string, unknown>) => createEntityFromRow(meta.ctx, hasOne.target, row),
350
- localKey
351
- );
352
- }
353
- case RelationKinds.HasMany: {
354
- const hasMany = relation as HasManyRelation;
355
- const localKey = hasMany.localKey || findPrimaryKey(meta.table);
356
- const loader = () => relationLoaderCache(meta, relationName, () =>
357
- loadHasManyRelation(meta.ctx, meta.table, relationName, hasMany, lazyOptions)
358
- );
359
- return new DefaultHasManyCollection(
360
- meta.ctx,
361
- meta,
362
- owner,
363
- relationName,
364
- hasMany,
365
- meta.table,
366
- loader,
367
- (row: Record<string, unknown>) => createEntityFromRow(meta.ctx, relation.target, row),
368
- localKey
369
- );
370
- }
371
- case RelationKinds.BelongsTo: {
372
- const belongsTo = relation as BelongsToRelation;
373
- const targetKey = belongsTo.localKey || findPrimaryKey(belongsTo.target);
374
- const loader = () => relationLoaderCache(meta, relationName, () =>
375
- loadBelongsToRelation(meta.ctx, meta.table, relationName, belongsTo, lazyOptions)
376
- );
377
- return new DefaultBelongsToReference(
378
- meta.ctx,
379
- meta,
380
- owner,
381
- relationName,
382
- belongsTo,
383
- meta.table,
384
- loader,
385
- (row: Record<string, unknown>) => createEntityFromRow(meta.ctx, relation.target, row),
386
- targetKey
387
- );
388
- }
389
- case RelationKinds.BelongsToMany: {
390
- const many = relation as BelongsToManyRelation;
391
- const localKey = many.localKey || findPrimaryKey(meta.table);
392
- const loader = () => relationLoaderCache(meta, relationName, () =>
393
- loadBelongsToManyRelation(meta.ctx, meta.table, relationName, many, lazyOptions)
394
- );
395
- return new DefaultManyToManyCollection(
396
- meta.ctx,
397
- meta,
398
- owner,
399
- relationName,
400
- many,
401
- meta.table,
402
- loader,
403
- (row: Record<string, unknown>) => createEntityFromRow(meta.ctx, relation.target, row),
404
- localKey
405
- );
406
- }
407
- default:
408
- return undefined;
409
- }
410
- };
1
+ import { TableDef } from '../schema/table.js';
2
+ import { EntityInstance } from '../schema/types.js';
3
+ import { EntityContext } from './entity-context.js';
4
+ import { ENTITY_META, EntityMeta, RelationKey } from './entity-meta.js';
5
+ import { findPrimaryKey } from '../query-builder/hydration-planner.js';
6
+ import { RelationIncludeOptions } from '../query-builder/relation-types.js';
7
+ import { populateHydrationCache } from './entity-hydration.js';
8
+ import { getRelationWrapper, RelationEntityFactory } from './entity-relations.js';
9
+
10
+ export { relationLoaderCache } from './entity-relation-cache.js';
11
+
12
+ /**
13
+ * Creates an entity proxy with lazy loading capabilities.
14
+ * @template TTable - The table type
15
+ * @template TLazy - The lazy relation keys
16
+ * @param ctx - The entity context
17
+ * @param table - The table definition
18
+ * @param row - The database row
19
+ * @param lazyRelations - Optional lazy relations
20
+ * @returns The entity instance
21
+ */
22
+ export const createEntityProxy = <
23
+ TTable extends TableDef,
24
+ TLazy extends RelationKey<TTable> = RelationKey<TTable>
25
+ >(
26
+ ctx: EntityContext,
27
+ table: TTable,
28
+ row: Record<string, unknown>,
29
+ lazyRelations: TLazy[] = [] as TLazy[],
30
+ lazyRelationOptions: Map<string, RelationIncludeOptions> = new Map()
31
+ ): EntityInstance<TTable> => {
32
+ const target: Record<string, unknown> = { ...row };
33
+ const meta: EntityMeta<TTable> = {
34
+ ctx,
35
+ table,
36
+ lazyRelations: [...lazyRelations],
37
+ lazyRelationOptions: new Map(lazyRelationOptions),
38
+ relationCache: new Map(),
39
+ relationHydration: new Map(),
40
+ relationWrappers: new Map()
41
+ };
42
+
43
+ const createRelationEntity: RelationEntityFactory = (relationTable, relationRow) =>
44
+ createEntityFromRow(meta.ctx, relationTable, relationRow);
45
+
46
+ Object.defineProperty(target, ENTITY_META, {
47
+ value: meta,
48
+ enumerable: false,
49
+ writable: false
50
+ });
51
+
52
+ const handler: ProxyHandler<object> = {
53
+ get(targetObj, prop, receiver) {
54
+ if (prop === ENTITY_META) {
55
+ return meta;
56
+ }
57
+
58
+ if (prop === '$load') {
59
+ return async (relationName: RelationKey<TTable>) => {
60
+ const wrapper = getRelationWrapper(meta, relationName, receiver, createRelationEntity);
61
+ if (wrapper && typeof wrapper.load === 'function') {
62
+ return wrapper.load();
63
+ }
64
+ return undefined;
65
+ };
66
+ }
67
+
68
+ if (typeof prop === 'string' && table.relations[prop]) {
69
+ return getRelationWrapper(meta, prop as RelationKey<TTable>, receiver, createRelationEntity);
70
+ }
71
+
72
+ return Reflect.get(targetObj, prop, receiver);
73
+ },
74
+
75
+ set(targetObj, prop, value, receiver) {
76
+ const result = Reflect.set(targetObj, prop, value, receiver);
77
+ if (typeof prop === 'string' && table.columns[prop]) {
78
+ ctx.markDirty(receiver);
79
+ }
80
+ return result;
81
+ }
82
+ };
83
+
84
+ const proxy = new Proxy(target, handler) as EntityInstance<TTable>;
85
+ populateHydrationCache(proxy, row, meta);
86
+ return proxy;
87
+ };
88
+
89
+ /**
90
+ * Creates an entity instance from a database row.
91
+ * @template TTable - The table type
92
+ * @template TResult - The result type
93
+ * @param ctx - The entity context
94
+ * @param table - The table definition
95
+ * @param row - The database row
96
+ * @param lazyRelations - Optional lazy relations
97
+ * @returns The entity instance
98
+ */
99
+ export const createEntityFromRow = <
100
+ TTable extends TableDef,
101
+ TResult extends EntityInstance<TTable> = EntityInstance<TTable>
102
+ >(
103
+ ctx: EntityContext,
104
+ table: TTable,
105
+ row: Record<string, unknown>,
106
+ lazyRelations: RelationKey<TTable>[] = [],
107
+ lazyRelationOptions: Map<string, RelationIncludeOptions> = new Map()
108
+ ): TResult => {
109
+ const pkName = findPrimaryKey(table);
110
+ const pkValue = row[pkName];
111
+ if (pkValue !== undefined && pkValue !== null) {
112
+ const tracked = ctx.getEntity(table, pkValue);
113
+ if (tracked) return tracked as TResult;
114
+ }
115
+
116
+ const entity = createEntityProxy(ctx, table, row, lazyRelations, lazyRelationOptions);
117
+ if (pkValue !== undefined && pkValue !== null) {
118
+ ctx.trackManaged(table, pkValue, entity);
119
+ } else {
120
+ ctx.trackNew(table, entity);
121
+ }
122
+
123
+ return entity as TResult;
124
+ };
@@ -1,5 +1,5 @@
1
1
  import { TableDef } from '../schema/table.js';
2
- import { EntityInstance, RelationMap } from '../schema/types.js';
2
+ import { EntityInstance } from '../schema/types.js';
3
3
  import { RelationKinds } from '../schema/relation.js';
4
4
  import { hydrateRows } from './hydration.js';
5
5
  import { OrmSession } from './orm-session.ts';
@@ -13,7 +13,7 @@ import { EntityContext } from './entity-context.js';
13
13
  import { ExecutionContext } from './execution-context.js';
14
14
  import { HydrationContext } from './hydration-context.js';
15
15
  import { RelationIncludeOptions } from '../query-builder/relation-types.js';
16
- import { getEntityMeta } from './entity-meta.js';
16
+ import { getEntityMeta, RelationKey } from './entity-meta.js';
17
17
  import {
18
18
  loadHasManyRelation,
19
19
  loadHasOneRelation,
@@ -47,7 +47,7 @@ const executeWithContexts = async <TTable extends TableDef>(
47
47
  const compiled = execCtx.dialect.compileSelect(ast);
48
48
  const executed = await execCtx.interceptors.run({ sql: compiled.sql, params: compiled.params }, execCtx.executor);
49
49
  const rows = flattenResults(executed);
50
- const lazyRelations = qb.getLazyRelations();
50
+ const lazyRelations = qb.getLazyRelations() as RelationKey<TTable>[];
51
51
  const lazyRelationOptions = qb.getLazyRelationOptions();
52
52
 
53
53
  if (ast.setOps && ast.setOps.length > 0) {
@@ -99,7 +99,7 @@ export async function executeHydratedWithContexts<TTable extends TableDef>(
99
99
  const loadLazyRelationsForTable = async <TTable extends TableDef>(
100
100
  ctx: EntityContext,
101
101
  table: TTable,
102
- lazyRelations: (keyof RelationMap<TTable>)[],
102
+ lazyRelations: RelationKey<TTable>[],
103
103
  lazyRelationOptions: Map<string, RelationIncludeOptions>
104
104
  ): Promise<void> => {
105
105
  if (!lazyRelations.length) return;