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/dist/index.d.ts CHANGED
@@ -251,10 +251,10 @@ interface BelongsToRelation<TTarget extends TableDef = TableDef> {
251
251
  /**
252
252
  * Many-to-many relationship definition with rich pivot metadata
253
253
  */
254
- interface BelongsToManyRelation<TTarget extends TableDef = TableDef> {
254
+ interface BelongsToManyRelation<TTarget extends TableDef = TableDef, TPivot extends TableDef = TableDef> {
255
255
  type: typeof RelationKinds.BelongsToMany;
256
256
  target: TTarget;
257
- pivotTable: TableDef;
257
+ pivotTable: TPivot;
258
258
  pivotForeignKeyToRoot: string;
259
259
  pivotForeignKeyToTarget: string;
260
260
  localKey?: string;
@@ -308,7 +308,7 @@ declare const belongsTo: <TTarget extends TableDef>(target: TTarget, foreignKey:
308
308
  * @param options - Pivot metadata configuration
309
309
  * @returns BelongsToManyRelation definition
310
310
  */
311
- declare const belongsToMany: <TTarget extends TableDef>(target: TTarget, pivotTable: TableDef, options: {
311
+ declare const belongsToMany: <TTarget extends TableDef, TPivot extends TableDef = TableDef>(target: TTarget, pivotTable: TPivot, options: {
312
312
  pivotForeignKeyToRoot: string;
313
313
  pivotForeignKeyToTarget: string;
314
314
  localKey?: string;
@@ -316,7 +316,7 @@ declare const belongsToMany: <TTarget extends TableDef>(target: TTarget, pivotTa
316
316
  pivotPrimaryKey?: string;
317
317
  defaultPivotColumns?: string[];
318
318
  cascade?: CascadeMode;
319
- }) => BelongsToManyRelation<TTarget>;
319
+ }) => BelongsToManyRelation<TTarget, TPivot>;
320
320
 
321
321
  interface IndexColumn {
322
322
  column: string;
@@ -397,6 +397,12 @@ interface TableDef<T extends Record<string, ColumnDef> = Record<string, ColumnDe
397
397
  * ```
398
398
  */
399
399
  declare const defineTable: <T extends Record<string, ColumnDef>>(name: string, columns: T, relations?: Record<string, RelationDef>, hooks?: TableHooks, options?: TableOptions) => TableDef<T>;
400
+ /**
401
+ * Assigns relations to a table definition while preserving literal typing.
402
+ */
403
+ declare function setRelations<TTable extends TableDef, TRelations extends Record<string, RelationDef>>(table: TTable, relations: TRelations): asserts table is TTable & {
404
+ relations: TRelations;
405
+ };
400
406
  type DirectColumnKeys<T extends TableDef> = Exclude<keyof T["columns"] & string, keyof T | "$">;
401
407
  type TableRef$1<T extends TableDef> = T & {
402
408
  [K in DirectColumnKeys<T>]: T["columns"][K];
@@ -438,7 +444,7 @@ declare function getColumn<T extends TableDef>(table: T, key: string): ColumnDef
438
444
  /**
439
445
  * Resolves a relation definition to its target table type.
440
446
  */
441
- type RelationTargetTable<TRel extends RelationDef> = TRel extends HasManyRelation<infer TTarget> ? TTarget : TRel extends HasOneRelation<infer TTarget> ? TTarget : TRel extends BelongsToRelation<infer TTarget> ? TTarget : TRel extends BelongsToManyRelation<infer TTarget> ? TTarget : never;
447
+ type RelationTargetTable<TRel extends RelationDef> = TRel extends HasManyRelation<infer TTarget> ? TTarget : TRel extends HasOneRelation<infer TTarget> ? TTarget : TRel extends BelongsToRelation<infer TTarget> ? TTarget : TRel extends BelongsToManyRelation<infer TTarget, TableDef> ? TTarget : never;
442
448
  type NormalizedColumnType<T extends ColumnDef> = Lowercase<T['type'] & string>;
443
449
  /**
444
450
  * Maps a ColumnDef to its TypeScript type representation
@@ -452,7 +458,7 @@ type ColumnToTs<T extends ColumnDef> = [
452
458
  type InferRow<TTable extends TableDef> = {
453
459
  [K in keyof TTable['columns']]: ColumnToTs<TTable['columns'][K]>;
454
460
  };
455
- type RelationResult$1<T extends RelationDef> = T extends HasManyRelation<infer TTarget> ? InferRow<TTarget>[] : T extends HasOneRelation<infer TTarget> ? InferRow<TTarget> | null : T extends BelongsToRelation<infer TTarget> ? InferRow<TTarget> | null : T extends BelongsToManyRelation<infer TTarget> ? (InferRow<TTarget> & {
461
+ type RelationResult$1<T extends RelationDef> = T extends HasManyRelation<infer TTarget> ? InferRow<TTarget>[] : T extends HasOneRelation<infer TTarget> ? InferRow<TTarget> | null : T extends BelongsToRelation<infer TTarget> ? InferRow<TTarget> | null : T extends BelongsToManyRelation<infer TTarget, TableDef> ? (InferRow<TTarget> & {
456
462
  _pivot?: Record<string, unknown>;
457
463
  })[] : never;
458
464
  /**
@@ -488,7 +494,7 @@ interface HasOneReferenceApi<TChild extends object = object> {
488
494
  set(data: Partial<TChild> | TChild | null): TChild | null;
489
495
  }
490
496
  type HasOneReference<TChild extends object = object> = HasOneReferenceApi<TChild> & Partial<TChild>;
491
- interface ManyToManyCollection<TTarget> {
497
+ interface ManyToManyCollection<TTarget, TPivot extends object | undefined = undefined> {
492
498
  length: number;
493
499
  [Symbol.iterator](): Iterator<TTarget>;
494
500
  load(): Promise<TTarget[]>;
@@ -496,6 +502,8 @@ interface ManyToManyCollection<TTarget> {
496
502
  attach(target: TTarget | number | string): void;
497
503
  detach(target: TTarget | number | string): void;
498
504
  syncByIds(ids: (number | string)[]): Promise<void>;
505
+ /** @internal Type-level marker for the related pivot entity */
506
+ readonly __pivotType?: TPivot;
499
507
  }
500
508
  type EntityInstance<TTable extends TableDef, TRow = InferRow<TTable>> = TRow & {
501
509
  [K in keyof RelationMap<TTable>]: RelationWrapper$1<TTable['relations'][K]>;
@@ -2157,10 +2165,25 @@ interface RelationIncludeOptions {
2157
2165
  filter?: ExpressionNode;
2158
2166
  joinKind?: RelationIncludeJoinKind;
2159
2167
  pivot?: {
2160
- columns?: string[];
2168
+ columns?: readonly string[];
2161
2169
  aliasPrefix?: string;
2162
2170
  };
2163
2171
  }
2172
+ type ColumnKeys$1<T> = T extends {
2173
+ columns: infer Columns;
2174
+ } ? keyof Columns & string : string;
2175
+ type PivotColumnKeys<TPivot> = ColumnKeys$1<TPivot> extends never ? string : ColumnKeys$1<TPivot>;
2176
+ type RelationTargetColumns<TRel extends RelationDef> = ColumnKeys$1<RelationTargetTable<TRel>>;
2177
+ type BelongsToManyPivotColumns<TRel extends RelationDef> = TRel extends BelongsToManyRelation<TableDef, infer TPivot> ? PivotColumnKeys<TPivot> : never;
2178
+ type TypedRelationIncludeOptions<TRel extends RelationDef> = TRel extends BelongsToManyRelation ? Omit<RelationIncludeOptions, 'columns' | 'pivot'> & {
2179
+ columns?: readonly RelationTargetColumns<TRel>[];
2180
+ pivot?: {
2181
+ columns?: readonly BelongsToManyPivotColumns<TRel>[];
2182
+ aliasPrefix?: string;
2183
+ };
2184
+ } : Omit<RelationIncludeOptions, 'columns' | 'pivot'> & {
2185
+ columns?: readonly RelationTargetColumns<TRel>[];
2186
+ };
2164
2187
 
2165
2188
  /**
2166
2189
  * Service for handling relation operations (joins, includes, etc.)
@@ -2171,6 +2194,8 @@ declare class RelationService {
2171
2194
  private readonly hydration;
2172
2195
  private readonly createQueryAstService;
2173
2196
  private readonly projectionHelper;
2197
+ private readonly joinPlanner;
2198
+ private readonly cteBuilder;
2174
2199
  /**
2175
2200
  * Creates a new RelationService instance
2176
2201
  * @param table - Table definition
@@ -2207,15 +2232,6 @@ declare class RelationService {
2207
2232
  * @returns Modified query AST with relation correlation
2208
2233
  */
2209
2234
  applyRelationCorrelation(relationName: string, ast: SelectQueryNode, additionalCorrelation?: ExpressionNode): SelectQueryNode;
2210
- /**
2211
- * Creates a join node for a relation
2212
- * @param state - Current query state
2213
- * @param relationName - Name of the relation
2214
- * @param joinKind - Type of join to use
2215
- * @param extraCondition - Additional join condition
2216
- * @returns Updated query state with join
2217
- */
2218
- private withJoin;
2219
2235
  /**
2220
2236
  * Selects columns for a relation
2221
2237
  * @param state - Current query state
@@ -2225,16 +2241,6 @@ declare class RelationService {
2225
2241
  */
2226
2242
  private selectColumns;
2227
2243
  private combineWithAnd;
2228
- private splitFilterExpressions;
2229
- private flattenAnd;
2230
- private isExpressionSelfContained;
2231
- private collectReferencedTables;
2232
- private collectFromExpression;
2233
- private collectFromOperand;
2234
- private collectFromOrderingTerm;
2235
- private createFilteredRelationCte;
2236
- private generateUniqueCteName;
2237
- private resolveTargetTableName;
2238
2244
  /**
2239
2245
  * Gets a relation definition by name
2240
2246
  * @param relationName - Name of the relation
@@ -2474,8 +2480,9 @@ type EntityConstructor<T = object> = new (...args: never[]) => T;
2474
2480
  type EntityOrTableTarget = EntityConstructor | TableDef;
2475
2481
  /**
2476
2482
  * Resolver for entity or table target, can be direct or function.
2483
+ * @typeParam T - Specific target type that should be resolved
2477
2484
  */
2478
- type EntityOrTableTargetResolver = EntityOrTableTarget | (() => EntityOrTableTarget);
2485
+ type EntityOrTableTargetResolver<T extends EntityOrTableTarget = EntityOrTableTarget> = T | (() => T);
2479
2486
  /**
2480
2487
  * Simplified column definition structure used during metadata registration.
2481
2488
  * @template T - Concrete column definition type being extended
@@ -2499,7 +2506,7 @@ interface HasManyRelationMetadata extends BaseRelationMetadata {
2499
2506
  /** The relation kind */
2500
2507
  kind: typeof RelationKinds.HasMany;
2501
2508
  /** The foreign key */
2502
- foreignKey: string;
2509
+ foreignKey?: string;
2503
2510
  /** Optional local key */
2504
2511
  localKey?: string;
2505
2512
  }
@@ -2510,7 +2517,7 @@ interface HasOneRelationMetadata extends BaseRelationMetadata {
2510
2517
  /** The relation kind */
2511
2518
  kind: typeof RelationKinds.HasOne;
2512
2519
  /** The foreign key */
2513
- foreignKey: string;
2520
+ foreignKey?: string;
2514
2521
  /** Optional local key */
2515
2522
  localKey?: string;
2516
2523
  }
@@ -2534,9 +2541,9 @@ interface BelongsToManyRelationMetadata extends BaseRelationMetadata {
2534
2541
  /** The pivot table */
2535
2542
  pivotTable: EntityOrTableTargetResolver;
2536
2543
  /** The pivot foreign key to root */
2537
- pivotForeignKeyToRoot: string;
2544
+ pivotForeignKeyToRoot?: string;
2538
2545
  /** The pivot foreign key to target */
2539
- pivotForeignKeyToTarget: string;
2546
+ pivotForeignKeyToTarget?: string;
2540
2547
  /** Optional local key */
2541
2548
  localKey?: string;
2542
2549
  /** Optional target key */
@@ -2584,7 +2591,7 @@ interface TrackedEntity {
2584
2591
  /**
2585
2592
  * Type representing a key for relation navigation
2586
2593
  */
2587
- type RelationKey = string;
2594
+ type RelationKey$1 = string;
2588
2595
  /**
2589
2596
  * Represents a change operation on a relation
2590
2597
  * @typeParam T - Type of the related entity
@@ -2609,7 +2616,7 @@ interface RelationChangeEntry {
2609
2616
  /** Root entity that owns the relation */
2610
2617
  root: unknown;
2611
2618
  /** Key of the relation being changed */
2612
- relationKey: RelationKey;
2619
+ relationKey: RelationKey$1;
2613
2620
  /** Table definition of the root entity */
2614
2621
  rootTable: TableDef;
2615
2622
  /** Name of the relation */
@@ -3197,7 +3204,7 @@ interface EntityContext {
3197
3204
  * @param relation - The relation definition
3198
3205
  * @param change - The relation change
3199
3206
  */
3200
- registerRelationChange(root: unknown, relationKey: RelationKey, rootTable: TableDef, relationName: string, relation: RelationDef, change: RelationChange<unknown>): void;
3207
+ registerRelationChange(root: unknown, relationKey: RelationKey$1, rootTable: TableDef, relationName: string, relation: RelationDef, change: RelationChange<unknown>): void;
3201
3208
  }
3202
3209
 
3203
3210
  /**
@@ -3380,7 +3387,7 @@ declare class OrmSession<E extends DomainEvent = OrmDomainEvent> implements Enti
3380
3387
  * @param relation - The relation definition
3381
3388
  * @param change - The relation change
3382
3389
  */
3383
- registerRelationChange: (root: unknown, relationKey: RelationKey, rootTable: TableDef, relationName: string, relation: RelationDef, change: RelationChange<unknown>) => void;
3390
+ registerRelationChange: (root: unknown, relationKey: RelationKey$1, rootTable: TableDef, relationName: string, relation: RelationDef, change: RelationChange<unknown>) => void;
3384
3391
  /**
3385
3392
  * Gets all tracked entities for a specific table.
3386
3393
  * @param table - The table definition
@@ -3480,6 +3487,11 @@ declare class OrmSession<E extends DomainEvent = OrmDomainEvent> implements Enti
3480
3487
  getHydrationContext(): HydrationContext<E>;
3481
3488
  }
3482
3489
 
3490
+ type WhereHasOptions = {
3491
+ correlate?: ExpressionNode;
3492
+ };
3493
+ type RelationCallback = <TChildTable extends TableDef>(qb: SelectQueryBuilder<unknown, TChildTable>) => SelectQueryBuilder<unknown, TChildTable>;
3494
+
3483
3495
  type SelectDialectInput = Dialect | DialectKey;
3484
3496
 
3485
3497
  type ColumnSelectionValue = ColumnDef | FunctionNode | CaseExpressionNode | WindowFunctionNode;
@@ -3492,10 +3504,6 @@ type DeepSelectEntry<TTable extends TableDef> = {
3492
3504
  columns: string[];
3493
3505
  };
3494
3506
  type DeepSelectConfig<TTable extends TableDef> = DeepSelectEntry<TTable>[];
3495
- type WhereHasOptions = {
3496
- correlate?: ExpressionNode;
3497
- };
3498
- type RelationCallback = <TChildTable extends TableDef>(qb: SelectQueryBuilder<unknown, TChildTable>) => SelectQueryBuilder<unknown, TChildTable>;
3499
3507
  /**
3500
3508
  * Main query builder class for constructing SQL SELECT queries
3501
3509
  * @typeParam T - Result type for projections (unused)
@@ -3505,7 +3513,13 @@ declare class SelectQueryBuilder<T = unknown, TTable extends TableDef = TableDef
3505
3513
  private readonly env;
3506
3514
  private readonly context;
3507
3515
  private readonly columnSelector;
3508
- private readonly relationManager;
3516
+ private readonly fromFacet;
3517
+ private readonly joinFacet;
3518
+ private readonly projectionFacet;
3519
+ private readonly predicateFacet;
3520
+ private readonly cteFacet;
3521
+ private readonly setOpFacet;
3522
+ private readonly relationFacet;
3509
3523
  private readonly lazyRelations;
3510
3524
  private readonly lazyRelationOptions;
3511
3525
  /**
@@ -3526,6 +3540,8 @@ declare class SelectQueryBuilder<T = unknown, TTable extends TableDef = TableDef
3526
3540
  /**
3527
3541
  * Applies an alias to the root FROM table.
3528
3542
  * @param alias - Alias to apply
3543
+ * @example
3544
+ * const qb = new SelectQueryBuilder(userTable).as('u');
3529
3545
  */
3530
3546
  as(alias: string): SelectQueryBuilder<T, TTable>;
3531
3547
  /**
@@ -3541,22 +3557,6 @@ declare class SelectQueryBuilder<T = unknown, TTable extends TableDef = TableDef
3541
3557
  * @returns New SelectQueryBuilder instance for the child table
3542
3558
  */
3543
3559
  private createChildBuilder;
3544
- /**
3545
- * Applies an AST mutation using the query AST service
3546
- * @param context - Current query context
3547
- * @param mutator - Function that mutates the AST
3548
- * @returns Updated query context
3549
- */
3550
- private applyAst;
3551
- /**
3552
- * Applies a join to the query context
3553
- * @param context - Current query context
3554
- * @param table - Table to join
3555
- * @param condition - Join condition
3556
- * @param kind - Join kind
3557
- * @returns Updated query context with join applied
3558
- */
3559
- private applyJoin;
3560
3560
  /**
3561
3561
  * Applies a set operation to the query
3562
3562
  * @param operator - Set operation kind
@@ -3569,6 +3569,15 @@ declare class SelectQueryBuilder<T = unknown, TTable extends TableDef = TableDef
3569
3569
  * Can be called with column names or a projection object.
3570
3570
  * @param args - Column names or projection object
3571
3571
  * @returns New query builder instance with selected columns
3572
+ * @example
3573
+ * // Select specific columns
3574
+ * qb.select('id', 'name', 'email');
3575
+ * @example
3576
+ * // Select with aliases and expressions
3577
+ * qb.select({
3578
+ * id: userTable.columns.id,
3579
+ * fullName: concat(userTable.columns.firstName, ' ', userTable.columns.lastName)
3580
+ * });
3572
3581
  */
3573
3582
  select<K extends keyof TTable['columns'] & string>(...args: K[]): SelectQueryBuilder<T, TTable>;
3574
3583
  select(columns: Record<string, ColumnSelectionValue>): SelectQueryBuilder<T, TTable>;
@@ -3576,6 +3585,8 @@ declare class SelectQueryBuilder<T = unknown, TTable extends TableDef = TableDef
3576
3585
  * Selects raw column expressions
3577
3586
  * @param cols - Column expressions as strings
3578
3587
  * @returns New query builder instance with raw column selections
3588
+ * @example
3589
+ * qb.selectRaw('COUNT(*) as total', 'UPPER(name) as upper_name');
3579
3590
  */
3580
3591
  selectRaw(...cols: string[]): SelectQueryBuilder<T, TTable>;
3581
3592
  /**
@@ -3584,6 +3595,12 @@ declare class SelectQueryBuilder<T = unknown, TTable extends TableDef = TableDef
3584
3595
  * @param query - Query builder or query node for the CTE
3585
3596
  * @param columns - Optional column names for the CTE
3586
3597
  * @returns New query builder instance with the CTE
3598
+ * @example
3599
+ * const recentUsers = new SelectQueryBuilder(userTable)
3600
+ * .where(gt(userTable.columns.createdAt, subDays(now(), 30)));
3601
+ * const qb = new SelectQueryBuilder(userTable)
3602
+ * .with('recent_users', recentUsers)
3603
+ * .from('recent_users');
3587
3604
  */
3588
3605
  with<TSub extends TableDef>(name: string, query: SelectQueryBuilder<unknown, TSub> | SelectQueryNode, columns?: string[]): SelectQueryBuilder<T, TTable>;
3589
3606
  /**
@@ -3592,6 +3609,19 @@ declare class SelectQueryBuilder<T = unknown, TTable extends TableDef = TableDef
3592
3609
  * @param query - Query builder or query node for the CTE
3593
3610
  * @param columns - Optional column names for the CTE
3594
3611
  * @returns New query builder instance with the recursive CTE
3612
+ * @example
3613
+ * // Base case: select root nodes
3614
+ * const baseQuery = new SelectQueryBuilder(orgTable)
3615
+ * .where(eq(orgTable.columns.parentId, 1));
3616
+ * // Recursive case: join with the CTE itself
3617
+ * const recursiveQuery = new SelectQueryBuilder(orgTable)
3618
+ * .join('org_hierarchy', 'oh', eq(orgTable.columns.parentId, col('oh.id')));
3619
+ * // Combine base and recursive parts
3620
+ * const orgHierarchy = baseQuery.union(recursiveQuery);
3621
+ * // Use in main query
3622
+ * const qb = new SelectQueryBuilder(orgTable)
3623
+ * .withRecursive('org_hierarchy', orgHierarchy)
3624
+ * .from('org_hierarchy');
3595
3625
  */
3596
3626
  withRecursive<TSub extends TableDef>(name: string, query: SelectQueryBuilder<unknown, TSub> | SelectQueryNode, columns?: string[]): SelectQueryBuilder<T, TTable>;
3597
3627
  /**
@@ -3600,6 +3630,11 @@ declare class SelectQueryBuilder<T = unknown, TTable extends TableDef = TableDef
3600
3630
  * @param alias - Alias for the derived table
3601
3631
  * @param columnAliases - Optional column alias list
3602
3632
  * @returns New query builder instance with updated FROM
3633
+ * @example
3634
+ * const subquery = new SelectQueryBuilder(userTable)
3635
+ * .select('id', 'name')
3636
+ * .where(gt(userTable.columns.score, 100));
3637
+ * qb.fromSubquery(subquery, 'high_scorers', ['userId', 'userName']);
3603
3638
  */
3604
3639
  fromSubquery<TSub extends TableDef>(subquery: SelectQueryBuilder<unknown, TSub> | SelectQueryNode, alias: string, columnAliases?: string[]): SelectQueryBuilder<T, TTable>;
3605
3640
  /**
@@ -3608,6 +3643,13 @@ declare class SelectQueryBuilder<T = unknown, TTable extends TableDef = TableDef
3608
3643
  * @param args - Optional function arguments
3609
3644
  * @param alias - Optional alias for the function table
3610
3645
  * @param options - Optional function-table metadata (lateral, ordinality, column aliases, schema)
3646
+ * @example
3647
+ * qb.fromFunctionTable(
3648
+ * 'generate_series',
3649
+ * [literal(1), literal(10), literal(1)],
3650
+ * 'series',
3651
+ * { columnAliases: ['value'] }
3652
+ * );
3611
3653
  */
3612
3654
  fromFunctionTable(name: string, args?: OperandNode[], alias?: string, options?: {
3613
3655
  lateral?: boolean;
@@ -3620,6 +3662,12 @@ declare class SelectQueryBuilder<T = unknown, TTable extends TableDef = TableDef
3620
3662
  * @param alias - Alias for the subquery column
3621
3663
  * @param sub - Query builder or query node for the subquery
3622
3664
  * @returns New query builder instance with the subquery selection
3665
+ * @example
3666
+ * const postCount = new SelectQueryBuilder(postTable)
3667
+ * .select(count(postTable.columns.id))
3668
+ * .where(eq(postTable.columns.userId, col('u.id')));
3669
+ * qb.select('id', 'name')
3670
+ * .selectSubquery('postCount', postCount);
3623
3671
  */
3624
3672
  selectSubquery<TSub extends TableDef>(alias: string, sub: SelectQueryBuilder<unknown, TSub> | SelectQueryNode): SelectQueryBuilder<T, TTable>;
3625
3673
  /**
@@ -3630,6 +3678,15 @@ declare class SelectQueryBuilder<T = unknown, TTable extends TableDef = TableDef
3630
3678
  * @param joinKind - Join kind (defaults to INNER)
3631
3679
  * @param columnAliases - Optional column alias list for the derived table
3632
3680
  * @returns New query builder instance with the derived-table join
3681
+ * @example
3682
+ * const activeUsers = new SelectQueryBuilder(userTable)
3683
+ * .where(eq(userTable.columns.active, true));
3684
+ * qb.joinSubquery(
3685
+ * activeUsers,
3686
+ * 'au',
3687
+ * eq(col('t.userId'), col('au.id')),
3688
+ * JOIN_KINDS.LEFT
3689
+ * );
3633
3690
  */
3634
3691
  joinSubquery<TSub extends TableDef>(subquery: SelectQueryBuilder<unknown, TSub> | SelectQueryNode, alias: string, condition: BinaryExpressionNode, joinKind?: JoinKind, columnAliases?: string[]): SelectQueryBuilder<T, TTable>;
3635
3692
  /**
@@ -3640,6 +3697,15 @@ declare class SelectQueryBuilder<T = unknown, TTable extends TableDef = TableDef
3640
3697
  * @param condition - Join condition expression
3641
3698
  * @param joinKind - Kind of join (defaults to INNER)
3642
3699
  * @param options - Optional metadata (lateral, ordinality, column aliases, schema)
3700
+ * @example
3701
+ * qb.joinFunctionTable(
3702
+ * 'generate_series',
3703
+ * [literal(1), literal(10)],
3704
+ * 'gs',
3705
+ * eq(col('t.value'), col('gs.value')),
3706
+ * JOIN_KINDS.INNER,
3707
+ * { columnAliases: ['value'] }
3708
+ * );
3643
3709
  */
3644
3710
  joinFunctionTable(name: string, args: OperandNode[], alias: string, condition: BinaryExpressionNode, joinKind?: JoinKind, options?: {
3645
3711
  lateral?: boolean;
@@ -3652,6 +3718,11 @@ declare class SelectQueryBuilder<T = unknown, TTable extends TableDef = TableDef
3652
3718
  * @param table - Table to join
3653
3719
  * @param condition - Join condition expression
3654
3720
  * @returns New query builder instance with the INNER JOIN
3721
+ * @example
3722
+ * qb.innerJoin(
3723
+ * postTable,
3724
+ * eq(userTable.columns.id, postTable.columns.userId)
3725
+ * );
3655
3726
  */
3656
3727
  innerJoin(table: TableDef, condition: BinaryExpressionNode): SelectQueryBuilder<T, TTable>;
3657
3728
  /**
@@ -3659,6 +3730,11 @@ declare class SelectQueryBuilder<T = unknown, TTable extends TableDef = TableDef
3659
3730
  * @param table - Table to join
3660
3731
  * @param condition - Join condition expression
3661
3732
  * @returns New query builder instance with the LEFT JOIN
3733
+ * @example
3734
+ * qb.leftJoin(
3735
+ * postTable,
3736
+ * eq(userTable.columns.id, postTable.columns.userId)
3737
+ * );
3662
3738
  */
3663
3739
  leftJoin(table: TableDef, condition: BinaryExpressionNode): SelectQueryBuilder<T, TTable>;
3664
3740
  /**
@@ -3666,6 +3742,11 @@ declare class SelectQueryBuilder<T = unknown, TTable extends TableDef = TableDef
3666
3742
  * @param table - Table to join
3667
3743
  * @param condition - Join condition expression
3668
3744
  * @returns New query builder instance with the RIGHT JOIN
3745
+ * @example
3746
+ * qb.rightJoin(
3747
+ * postTable,
3748
+ * eq(userTable.columns.id, postTable.columns.userId)
3749
+ * );
3669
3750
  */
3670
3751
  rightJoin(table: TableDef, condition: BinaryExpressionNode): SelectQueryBuilder<T, TTable>;
3671
3752
  /**
@@ -3673,6 +3754,8 @@ declare class SelectQueryBuilder<T = unknown, TTable extends TableDef = TableDef
3673
3754
  * @param relationName - Name of the relationship to match
3674
3755
  * @param predicate - Optional predicate expression
3675
3756
  * @returns New query builder instance with the relationship match
3757
+ * @example
3758
+ * qb.match('posts', eq(postTable.columns.published, true));
3676
3759
  */
3677
3760
  match<K extends keyof TTable['relations'] & string>(relationName: K, predicate?: ExpressionNode): SelectQueryBuilder<T, TTable>;
3678
3761
  /**
@@ -3681,6 +3764,10 @@ declare class SelectQueryBuilder<T = unknown, TTable extends TableDef = TableDef
3681
3764
  * @param joinKind - Type of join (defaults to INNER)
3682
3765
  * @param extraCondition - Optional additional join condition
3683
3766
  * @returns New query builder instance with the relationship join
3767
+ * @example
3768
+ * qb.joinRelation('posts', JOIN_KINDS.LEFT);
3769
+ * @example
3770
+ * qb.joinRelation('posts', JOIN_KINDS.INNER, eq(postTable.columns.published, true));
3684
3771
  */
3685
3772
  joinRelation<K extends keyof TTable['relations'] & string>(relationName: K, joinKind?: JoinKind, extraCondition?: ExpressionNode): SelectQueryBuilder<T, TTable>;
3686
3773
  /**
@@ -3688,23 +3775,44 @@ declare class SelectQueryBuilder<T = unknown, TTable extends TableDef = TableDef
3688
3775
  * @param relationName - Name of the relationship to include
3689
3776
  * @param options - Optional include options
3690
3777
  * @returns New query builder instance with the relationship inclusion
3778
+ * @example
3779
+ * qb.include('posts');
3780
+ * @example
3781
+ * qb.include('posts', { columns: ['id', 'title', 'published'] });
3782
+ * @example
3783
+ * qb.include('posts', {
3784
+ * columns: ['id', 'title'],
3785
+ * where: eq(postTable.columns.published, true)
3786
+ * });
3691
3787
  */
3692
- include<K extends keyof TTable['relations'] & string>(relationName: K, options?: RelationIncludeOptions): SelectQueryBuilder<T, TTable>;
3788
+ include<K extends keyof TTable['relations'] & string>(relationName: K, options?: TypedRelationIncludeOptions<TTable['relations'][K]>): SelectQueryBuilder<T, TTable>;
3693
3789
  /**
3694
3790
  * Includes a relation lazily in the query results
3695
3791
  * @param relationName - Name of the relation to include lazily
3696
3792
  * @param options - Optional include options for lazy loading
3697
3793
  * @returns New query builder instance with lazy relation inclusion
3794
+ * @example
3795
+ * const qb = new SelectQueryBuilder(userTable).includeLazy('posts');
3796
+ * const users = await qb.execute(session);
3797
+ * // Access posts later - they will be loaded on demand
3798
+ * const posts = await users[0].posts;
3698
3799
  */
3699
- includeLazy<K extends keyof RelationMap<TTable>>(relationName: K, options?: RelationIncludeOptions): SelectQueryBuilder<T, TTable>;
3800
+ includeLazy<K extends keyof RelationMap<TTable>>(relationName: K, options?: TypedRelationIncludeOptions<TTable['relations'][K]>): SelectQueryBuilder<T, TTable>;
3700
3801
  /**
3701
3802
  * Convenience alias for including only specific columns from a relation.
3803
+ * @example
3804
+ * qb.includePick('posts', ['id', 'title', 'createdAt']);
3702
3805
  */
3703
- includePick<K extends keyof TTable['relations'] & string, TRel extends RelationDef = TTable['relations'][K], TTarget extends TableDef = RelationTargetTable<TRel>, C extends keyof TTarget['columns'] & string = keyof TTarget['columns'] & string>(relationName: K, cols: C[]): SelectQueryBuilder<T, TTable>;
3806
+ includePick<K extends keyof TTable['relations'] & string, C extends RelationTargetColumns<TTable['relations'][K]>>(relationName: K, cols: C[]): SelectQueryBuilder<T, TTable>;
3704
3807
  /**
3705
3808
  * Selects columns for the root table and relations from an array of entries
3706
3809
  * @param config - Configuration array for deep column selection
3707
3810
  * @returns New query builder instance with deep column selections
3811
+ * @example
3812
+ * qb.selectColumnsDeep([
3813
+ * { type: 'root', columns: ['id', 'name'] },
3814
+ * { type: 'relation', relationName: 'posts', columns: ['id', 'title'] }
3815
+ * ]);
3708
3816
  */
3709
3817
  selectColumnsDeep(config: DeepSelectConfig<TTable>): SelectQueryBuilder<T, TTable>;
3710
3818
  /**
@@ -3726,10 +3834,25 @@ declare class SelectQueryBuilder<T = unknown, TTable extends TableDef = TableDef
3726
3834
  * Executes the query and returns hydrated results
3727
3835
  * @param ctx - ORM session context
3728
3836
  * @returns Promise of entity instances
3837
+ * @example
3838
+ * const users = await qb.select('id', 'name')
3839
+ * .where(eq(userTable.columns.active, true))
3840
+ * .execute(session);
3729
3841
  */
3730
3842
  execute(ctx: OrmSession): Promise<EntityInstance<TTable>[]>;
3731
- private withAst;
3843
+ /**
3844
+ * Executes a count query for the current builder without LIMIT/OFFSET clauses.
3845
+ *
3846
+ * @example
3847
+ * const total = await qb.count(session);
3848
+ */
3732
3849
  count(session: OrmSession): Promise<number>;
3850
+ /**
3851
+ * Executes the query and returns both the paged items and the total.
3852
+ *
3853
+ * @example
3854
+ * const { items, totalItems } = await qb.executePaged(session, { page: 1, pageSize: 20 });
3855
+ */
3733
3856
  executePaged(session: OrmSession, options: {
3734
3857
  page: number;
3735
3858
  pageSize: number;
@@ -3742,24 +3865,42 @@ declare class SelectQueryBuilder<T = unknown, TTable extends TableDef = TableDef
3742
3865
  * @param execCtx - Execution context
3743
3866
  * @param hydCtx - Hydration context
3744
3867
  * @returns Promise of entity instances
3868
+ * @example
3869
+ * const execCtx = new ExecutionContext(session);
3870
+ * const hydCtx = new HydrationContext();
3871
+ * const users = await qb.executeWithContexts(execCtx, hydCtx);
3745
3872
  */
3746
3873
  executeWithContexts(execCtx: ExecutionContext, hydCtx: HydrationContext): Promise<EntityInstance<TTable>[]>;
3747
3874
  /**
3748
3875
  * Adds a WHERE condition to the query
3749
3876
  * @param expr - Expression for the WHERE clause
3750
3877
  * @returns New query builder instance with the WHERE condition
3878
+ * @example
3879
+ * qb.where(eq(userTable.columns.id, 1));
3880
+ * @example
3881
+ * qb.where(and(
3882
+ * eq(userTable.columns.active, true),
3883
+ * gt(userTable.columns.createdAt, subDays(now(), 30))
3884
+ * ));
3751
3885
  */
3752
3886
  where(expr: ExpressionNode): SelectQueryBuilder<T, TTable>;
3753
3887
  /**
3754
3888
  * Adds a GROUP BY clause to the query
3755
3889
  * @param term - Column definition or ordering term to group by
3756
3890
  * @returns New query builder instance with the GROUP BY clause
3891
+ * @example
3892
+ * qb.select('departmentId', count(userTable.columns.id))
3893
+ * .groupBy(userTable.columns.departmentId);
3757
3894
  */
3758
3895
  groupBy(term: ColumnDef | OrderingTerm): SelectQueryBuilder<T, TTable>;
3759
3896
  /**
3760
3897
  * Adds a HAVING condition to the query
3761
3898
  * @param expr - Expression for the HAVING clause
3762
3899
  * @returns New query builder instance with the HAVING condition
3900
+ * @example
3901
+ * qb.select('departmentId', count(userTable.columns.id))
3902
+ * .groupBy(userTable.columns.departmentId)
3903
+ * .having(gt(count(userTable.columns.id), 5));
3763
3904
  */
3764
3905
  having(expr: ExpressionNode): SelectQueryBuilder<T, TTable>;
3765
3906
  /**
@@ -3767,6 +3908,9 @@ declare class SelectQueryBuilder<T = unknown, TTable extends TableDef = TableDef
3767
3908
  * @param term - Column definition or ordering term to order by
3768
3909
  * @param directionOrOptions - Order direction or options (defaults to ASC)
3769
3910
  * @returns New query builder instance with the ORDER BY clause
3911
+ *
3912
+ * @example
3913
+ * qb.orderBy(userTable.columns.createdAt, 'DESC');
3770
3914
  */
3771
3915
  orderBy(term: ColumnDef | OrderingTerm, directionOrOptions?: OrderDirection | {
3772
3916
  direction?: OrderDirection;
@@ -3777,54 +3921,95 @@ declare class SelectQueryBuilder<T = unknown, TTable extends TableDef = TableDef
3777
3921
  * Adds a DISTINCT clause to the query
3778
3922
  * @param cols - Columns to make distinct
3779
3923
  * @returns New query builder instance with the DISTINCT clause
3924
+ * @example
3925
+ * qb.distinct(userTable.columns.email);
3926
+ * @example
3927
+ * qb.distinct(userTable.columns.firstName, userTable.columns.lastName);
3780
3928
  */
3781
3929
  distinct(...cols: (ColumnDef | ColumnNode)[]): SelectQueryBuilder<T, TTable>;
3782
3930
  /**
3783
3931
  * Adds a LIMIT clause to the query
3784
3932
  * @param n - Maximum number of rows to return
3785
3933
  * @returns New query builder instance with the LIMIT clause
3934
+ * @example
3935
+ * qb.limit(10);
3936
+ * @example
3937
+ * qb.limit(20).offset(40); // Pagination: page 3 with 20 items per page
3786
3938
  */
3787
3939
  limit(n: number): SelectQueryBuilder<T, TTable>;
3788
3940
  /**
3789
3941
  * Adds an OFFSET clause to the query
3790
3942
  * @param n - Number of rows to skip
3791
3943
  * @returns New query builder instance with the OFFSET clause
3944
+ * @example
3945
+ * qb.offset(10);
3946
+ * @example
3947
+ * qb.limit(20).offset(40); // Pagination: page 3 with 20 items per page
3792
3948
  */
3793
3949
  offset(n: number): SelectQueryBuilder<T, TTable>;
3794
3950
  /**
3795
3951
  * Combines this query with another using UNION
3796
3952
  * @param query - Query to union with
3797
3953
  * @returns New query builder instance with the set operation
3954
+ * @example
3955
+ * const activeUsers = new SelectQueryBuilder(userTable)
3956
+ * .where(eq(userTable.columns.active, true));
3957
+ * const inactiveUsers = new SelectQueryBuilder(userTable)
3958
+ * .where(eq(userTable.columns.active, false));
3959
+ * qb.union(activeUsers).union(inactiveUsers);
3798
3960
  */
3799
3961
  union<TSub extends TableDef>(query: SelectQueryBuilder<unknown, TSub> | SelectQueryNode): SelectQueryBuilder<T, TTable>;
3800
3962
  /**
3801
3963
  * Combines this query with another using UNION ALL
3802
3964
  * @param query - Query to union with
3803
3965
  * @returns New query builder instance with the set operation
3966
+ * @example
3967
+ * const q1 = new SelectQueryBuilder(userTable).where(gt(userTable.columns.score, 80));
3968
+ * const q2 = new SelectQueryBuilder(userTable).where(lt(userTable.columns.score, 20));
3969
+ * qb.unionAll(q1).unionAll(q2);
3804
3970
  */
3805
3971
  unionAll<TSub extends TableDef>(query: SelectQueryBuilder<unknown, TSub> | SelectQueryNode): SelectQueryBuilder<T, TTable>;
3806
3972
  /**
3807
3973
  * Combines this query with another using INTERSECT
3808
3974
  * @param query - Query to intersect with
3809
3975
  * @returns New query builder instance with the set operation
3976
+ * @example
3977
+ * const activeUsers = new SelectQueryBuilder(userTable)
3978
+ * .where(eq(userTable.columns.active, true));
3979
+ * const premiumUsers = new SelectQueryBuilder(userTable)
3980
+ * .where(eq(userTable.columns.premium, true));
3981
+ * qb.intersect(activeUsers).intersect(premiumUsers);
3810
3982
  */
3811
3983
  intersect<TSub extends TableDef>(query: SelectQueryBuilder<unknown, TSub> | SelectQueryNode): SelectQueryBuilder<T, TTable>;
3812
3984
  /**
3813
3985
  * Combines this query with another using EXCEPT
3814
3986
  * @param query - Query to subtract
3815
3987
  * @returns New query builder instance with the set operation
3988
+ * @example
3989
+ * const allUsers = new SelectQueryBuilder(userTable);
3990
+ * const inactiveUsers = new SelectQueryBuilder(userTable)
3991
+ * .where(eq(userTable.columns.active, false));
3992
+ * qb.except(allUsers).except(inactiveUsers); // Only active users
3816
3993
  */
3817
3994
  except<TSub extends TableDef>(query: SelectQueryBuilder<unknown, TSub> | SelectQueryNode): SelectQueryBuilder<T, TTable>;
3818
3995
  /**
3819
3996
  * Adds a WHERE EXISTS condition to the query
3820
3997
  * @param subquery - Subquery to check for existence
3821
3998
  * @returns New query builder instance with the WHERE EXISTS condition
3999
+ * @example
4000
+ * const postsQuery = new SelectQueryBuilder(postTable)
4001
+ * .where(eq(postTable.columns.userId, col('u.id')));
4002
+ * qb.whereExists(postsQuery);
3822
4003
  */
3823
4004
  whereExists<TSub extends TableDef>(subquery: SelectQueryBuilder<unknown, TSub> | SelectQueryNode, correlate?: ExpressionNode): SelectQueryBuilder<T, TTable>;
3824
4005
  /**
3825
4006
  * Adds a WHERE NOT EXISTS condition to the query
3826
4007
  * @param subquery - Subquery to check for non-existence
3827
4008
  * @returns New query builder instance with the WHERE NOT EXISTS condition
4009
+ * @example
4010
+ * const postsQuery = new SelectQueryBuilder(postTable)
4011
+ * .where(eq(postTable.columns.userId, col('u.id')));
4012
+ * qb.whereNotExists(postsQuery); // Users without posts
3828
4013
  */
3829
4014
  whereNotExists<TSub extends TableDef>(subquery: SelectQueryBuilder<unknown, TSub> | SelectQueryNode, correlate?: ExpressionNode): SelectQueryBuilder<T, TTable>;
3830
4015
  /**
@@ -3832,6 +4017,9 @@ declare class SelectQueryBuilder<T = unknown, TTable extends TableDef = TableDef
3832
4017
  * @param relationName - Name of the relationship to check
3833
4018
  * @param callback - Optional callback to modify the relationship query
3834
4019
  * @returns New query builder instance with the relationship existence check
4020
+ *
4021
+ * @example
4022
+ * qb.whereHas('posts', postQb => postQb.where(eq(postTable.columns.published, true)));
3835
4023
  */
3836
4024
  whereHas<K extends keyof TTable['relations'] & string>(relationName: K, callbackOrOptions?: RelationCallback | WhereHasOptions, maybeOptions?: WhereHasOptions): SelectQueryBuilder<T, TTable>;
3837
4025
  /**
@@ -3839,28 +4027,48 @@ declare class SelectQueryBuilder<T = unknown, TTable extends TableDef = TableDef
3839
4027
  * @param relationName - Name of the relationship to check
3840
4028
  * @param callback - Optional callback to modify the relationship query
3841
4029
  * @returns New query builder instance with the relationship non-existence check
4030
+ *
4031
+ * @example
4032
+ * qb.whereHasNot('posts', postQb => postQb.where(eq(postTable.columns.published, true)));
3842
4033
  */
3843
4034
  whereHasNot<K extends keyof TTable['relations'] & string>(relationName: K, callbackOrOptions?: RelationCallback | WhereHasOptions, maybeOptions?: WhereHasOptions): SelectQueryBuilder<T, TTable>;
3844
4035
  /**
3845
4036
  * Compiles the query to SQL for a specific dialect
3846
4037
  * @param dialect - Database dialect to compile for
3847
4038
  * @returns Compiled query with SQL and parameters
4039
+ * @example
4040
+ * const compiled = qb.select('id', 'name')
4041
+ * .where(eq(userTable.columns.active, true))
4042
+ * .compile('postgres');
4043
+ * console.log(compiled.sql); // SELECT "id", "name" FROM "users" WHERE "active" = true
3848
4044
  */
3849
4045
  compile(dialect: SelectDialectInput): CompiledQuery;
3850
4046
  /**
3851
4047
  * Converts the query to SQL string for a specific dialect
3852
4048
  * @param dialect - Database dialect to generate SQL for
3853
4049
  * @returns SQL string representation of the query
4050
+ * @example
4051
+ * const sql = qb.select('id', 'name')
4052
+ * .where(eq(userTable.columns.active, true))
4053
+ * .toSql('postgres');
4054
+ * console.log(sql); // SELECT "id", "name" FROM "users" WHERE "active" = true
3854
4055
  */
3855
4056
  toSql(dialect: SelectDialectInput): string;
3856
4057
  /**
3857
4058
  * Gets the hydration plan for the query
3858
4059
  * @returns Hydration plan or undefined if none exists
4060
+ * @example
4061
+ * const plan = qb.include('posts').getHydrationPlan();
4062
+ * console.log(plan?.relations); // Information about included relations
3859
4063
  */
3860
4064
  getHydrationPlan(): HydrationPlan | undefined;
3861
4065
  /**
3862
4066
  * Gets the Abstract Syntax Tree (AST) representation of the query
3863
4067
  * @returns Query AST with hydration applied
4068
+ * @example
4069
+ * const ast = qb.select('id', 'name').getAST();
4070
+ * console.log(ast.columns); // Array of column nodes
4071
+ * console.log(ast.from); // From clause information
3864
4072
  */
3865
4073
  getAST(): SelectQueryNode;
3866
4074
  }
@@ -4259,6 +4467,68 @@ declare class DeleteQueryBuilder<T> {
4259
4467
  getAST(): DeleteQueryNode;
4260
4468
  }
4261
4469
 
4470
+ /**
4471
+ * Represents a target for query operations, which can be either a table definition
4472
+ * or an entity constructor. This type allows flexible targeting of database tables
4473
+ * through either direct table definitions or entity classes decorated with ORM metadata.
4474
+ *
4475
+ * @template TTable - The table definition type, defaults to TableDef
4476
+ */
4477
+ type QueryTarget<TTable extends TableDef = TableDef> = TTable | EntityConstructor;
4478
+
4479
+ /**
4480
+ * Creates a SELECT query builder for the specified table or entity.
4481
+ *
4482
+ * @template TTable - The table definition type
4483
+ * @param target - The table definition or entity constructor to query from
4484
+ * @returns A new SelectQueryBuilder instance for building SELECT queries
4485
+ *
4486
+ * @example
4487
+ * ```typescript
4488
+ * const query = selectFrom(UserTable).select('id', 'name');
4489
+ * ```
4490
+ */
4491
+ declare const selectFrom: <TTable extends TableDef>(target: QueryTarget<TTable>) => SelectQueryBuilder<unknown, TTable>;
4492
+ /**
4493
+ * Creates an INSERT query builder for the specified table or entity.
4494
+ *
4495
+ * @template TTable - The table definition type
4496
+ * @param target - The table definition or entity constructor to insert into
4497
+ * @returns A new InsertQueryBuilder instance for building INSERT queries
4498
+ *
4499
+ * @example
4500
+ * ```typescript
4501
+ * const query = insertInto(UserTable).values({ name: 'John', email: 'john@example.com' });
4502
+ * ```
4503
+ */
4504
+ declare const insertInto: <TTable extends TableDef>(target: QueryTarget<TTable>) => InsertQueryBuilder<unknown>;
4505
+ /**
4506
+ * Creates an UPDATE query builder for the specified table or entity.
4507
+ *
4508
+ * @template TTable - The table definition type
4509
+ * @param target - The table definition or entity constructor to update
4510
+ * @returns A new UpdateQueryBuilder instance for building UPDATE queries
4511
+ *
4512
+ * @example
4513
+ * ```typescript
4514
+ * const query = update(UserTable).set({ name: 'Jane' }).where(eq(UserTable.id, 1));
4515
+ * ```
4516
+ */
4517
+ declare const update: <TTable extends TableDef>(target: QueryTarget<TTable>) => UpdateQueryBuilder<unknown>;
4518
+ /**
4519
+ * Creates a DELETE query builder for the specified table or entity.
4520
+ *
4521
+ * @template TTable - The table definition type
4522
+ * @param target - The table definition or entity constructor to delete from
4523
+ * @returns A new DeleteQueryBuilder instance for building DELETE queries
4524
+ *
4525
+ * @example
4526
+ * ```typescript
4527
+ * const query = deleteFrom(UserTable).where(eq(UserTable.id, 1));
4528
+ * ```
4529
+ */
4530
+ declare const deleteFrom: <TTable extends TableDef>(target: QueryTarget<TTable>) => DeleteQueryBuilder<unknown>;
4531
+
4262
4532
  /**
4263
4533
  * Strategy interface for compiling pagination clauses.
4264
4534
  * Allows dialects to customize how pagination (LIMIT/OFFSET, ROWS FETCH, etc.) is generated.
@@ -4579,6 +4849,26 @@ declare const generateCreateTableSql: (table: TableDef, dialect: SchemaDialect)
4579
4849
  * @returns The SQL statements.
4580
4850
  */
4581
4851
  declare const generateSchemaSql: (tables: TableDef[], dialect: SchemaDialect) => string[];
4852
+ /**
4853
+ * Convenience wrapper for generateSchemaSql with rest args.
4854
+ * @param dialect - The schema dialect used to render SQL.
4855
+ * @param tables - The table definitions to create.
4856
+ */
4857
+ declare const generateSchemaSqlFor: (dialect: SchemaDialect, ...tables: TableDef[]) => string[];
4858
+ /**
4859
+ * Generates and executes schema SQL for the provided tables.
4860
+ * @param executor - The database executor to run statements with.
4861
+ * @param tables - The table definitions to create.
4862
+ * @param dialect - The schema dialect used to render SQL.
4863
+ */
4864
+ declare const executeSchemaSql: (executor: DbExecutor, tables: TableDef[], dialect: SchemaDialect) => Promise<void>;
4865
+ /**
4866
+ * Convenience wrapper for executeSchemaSql with rest args.
4867
+ * @param executor - The database executor to run statements with.
4868
+ * @param dialect - The schema dialect used to render SQL.
4869
+ * @param tables - The table definitions to create.
4870
+ */
4871
+ declare const executeSchemaSqlFor: (executor: DbExecutor, dialect: SchemaDialect, ...tables: TableDef[]) => Promise<void>;
4582
4872
 
4583
4873
  /** The kind of schema change. */
4584
4874
  type SchemaChangeKind = 'createTable' | 'dropTable' | 'addColumn' | 'dropColumn' | 'alterColumn' | 'addIndex' | 'dropIndex';
@@ -5468,6 +5758,7 @@ declare class TypeScriptGenerator implements ExpressionVisitor<string>, OperandV
5468
5758
  private mapOp;
5469
5759
  }
5470
5760
 
5761
+ type RelationKey<TTable extends TableDef> = Extract<keyof RelationMap<TTable>, string>;
5471
5762
  /**
5472
5763
  * Metadata stored on entity instances for ORM internal use
5473
5764
  * @typeParam TTable - Table definition type
@@ -5478,7 +5769,7 @@ interface EntityMeta<TTable extends TableDef> {
5478
5769
  /** Table definition */
5479
5770
  table: TTable;
5480
5771
  /** Relations that should be loaded lazily */
5481
- lazyRelations: (keyof RelationMap<TTable>)[];
5772
+ lazyRelations: RelationKey<TTable>[];
5482
5773
  /** Include options for lazy relations */
5483
5774
  lazyRelationOptions: Map<string, RelationIncludeOptions>;
5484
5775
  /** Cache for relation promises */
@@ -5497,7 +5788,8 @@ interface EntityMeta<TTable extends TableDef> {
5497
5788
  * @param factory - The factory function to create the cache
5498
5789
  * @returns Promise with the cached relation data
5499
5790
  */
5500
- declare const relationLoaderCache: <T extends Map<string, unknown>>(meta: EntityMeta<TableDef>, relationName: string, factory: () => Promise<T>) => Promise<T>;
5791
+ declare const relationLoaderCache: <TTable extends TableDef, T extends Map<string, unknown>>(meta: EntityMeta<TTable>, relationName: string, factory: () => Promise<T>) => Promise<T>;
5792
+
5501
5793
  /**
5502
5794
  * Creates an entity proxy with lazy loading capabilities.
5503
5795
  * @template TTable - The table type
@@ -5508,7 +5800,7 @@ declare const relationLoaderCache: <T extends Map<string, unknown>>(meta: Entity
5508
5800
  * @param lazyRelations - Optional lazy relations
5509
5801
  * @returns The entity instance
5510
5802
  */
5511
- declare const createEntityProxy: <TTable extends TableDef, TLazy extends keyof RelationMap<TTable> = keyof RelationMap<TTable>>(ctx: EntityContext, table: TTable, row: Record<string, unknown>, lazyRelations?: TLazy[], lazyRelationOptions?: Map<string, RelationIncludeOptions>) => EntityInstance<TTable>;
5803
+ declare const createEntityProxy: <TTable extends TableDef, TLazy extends RelationKey<TTable> = RelationKey<TTable>>(ctx: EntityContext, table: TTable, row: Record<string, unknown>, lazyRelations?: TLazy[], lazyRelationOptions?: Map<string, RelationIncludeOptions>) => EntityInstance<TTable>;
5512
5804
  /**
5513
5805
  * Creates an entity instance from a database row.
5514
5806
  * @template TTable - The table type
@@ -5519,12 +5811,13 @@ declare const createEntityProxy: <TTable extends TableDef, TLazy extends keyof R
5519
5811
  * @param lazyRelations - Optional lazy relations
5520
5812
  * @returns The entity instance
5521
5813
  */
5522
- declare const createEntityFromRow: <TTable extends TableDef, TResult extends EntityInstance<TTable> = EntityInstance<TTable>>(ctx: EntityContext, table: TTable, row: Record<string, unknown>, lazyRelations?: (keyof RelationMap<TTable>)[], lazyRelationOptions?: Map<string, RelationIncludeOptions>) => TResult;
5814
+ declare const createEntityFromRow: <TTable extends TableDef, TResult extends EntityInstance<TTable> = EntityInstance<TTable>>(ctx: EntityContext, table: TTable, row: Record<string, unknown>, lazyRelations?: RelationKey<TTable>[], lazyRelationOptions?: Map<string, RelationIncludeOptions>) => TResult;
5523
5815
 
5524
5816
  /**
5525
5817
  * An array of database rows, each represented as a record of string keys to unknown values.
5526
5818
  */
5527
5819
  type Rows$3 = Record<string, unknown>[];
5820
+
5528
5821
  /**
5529
5822
  * Loads related entities for a has-many relation in batch.
5530
5823
  * @param ctx - The entity context.
@@ -5534,6 +5827,7 @@ type Rows$3 = Record<string, unknown>[];
5534
5827
  * @returns A promise resolving to a map of root keys to arrays of related rows.
5535
5828
  */
5536
5829
  declare const loadHasManyRelation: (ctx: EntityContext, rootTable: TableDef, relationName: string, relation: HasManyRelation, options?: RelationIncludeOptions) => Promise<Map<string, Rows$3>>;
5830
+
5537
5831
  /**
5538
5832
  * Loads related entities for a has-one relation in batch.
5539
5833
  * @param ctx - The entity context.
@@ -5543,6 +5837,7 @@ declare const loadHasManyRelation: (ctx: EntityContext, rootTable: TableDef, rel
5543
5837
  * @returns A promise resolving to a map of root keys to single related rows.
5544
5838
  */
5545
5839
  declare const loadHasOneRelation: (ctx: EntityContext, rootTable: TableDef, relationName: string, relation: HasOneRelation, options?: RelationIncludeOptions) => Promise<Map<string, Record<string, unknown>>>;
5840
+
5546
5841
  /**
5547
5842
  * Loads related entities for a belongs-to relation in batch.
5548
5843
  * @param ctx - The entity context.
@@ -5552,6 +5847,7 @@ declare const loadHasOneRelation: (ctx: EntityContext, rootTable: TableDef, rela
5552
5847
  * @returns A promise resolving to a map of foreign keys to single related rows.
5553
5848
  */
5554
5849
  declare const loadBelongsToRelation: (ctx: EntityContext, rootTable: TableDef, relationName: string, relation: BelongsToRelation, options?: RelationIncludeOptions) => Promise<Map<string, Record<string, unknown>>>;
5850
+
5555
5851
  /**
5556
5852
  * Loads related entities for a belongs-to-many relation in batch, including pivot data.
5557
5853
  * @param ctx - The entity context.
@@ -5688,7 +5984,7 @@ type Rows = Record<string, unknown>[];
5688
5984
  *
5689
5985
  * @template TTarget The type of the target entities in the collection.
5690
5986
  */
5691
- declare class DefaultManyToManyCollection<TTarget> implements ManyToManyCollection<TTarget> {
5987
+ declare class DefaultManyToManyCollection<TTarget, TPivot extends object | undefined = undefined> implements ManyToManyCollection<TTarget, TPivot> {
5692
5988
  private readonly ctx;
5693
5989
  private readonly meta;
5694
5990
  private readonly root;
@@ -5789,51 +6085,6 @@ type Jsonify<T> = {
5789
6085
  */
5790
6086
  declare const jsonify: <T extends object>(value: T) => Jsonify<T>;
5791
6087
 
5792
- /**
5793
- * Context object provided by standard decorators in newer TypeScript versions.
5794
- */
5795
- interface StandardDecoratorContext {
5796
- kind: string;
5797
- name?: string | symbol;
5798
- metadata?: Record<PropertyKey, unknown>;
5799
- static?: boolean;
5800
- private?: boolean;
5801
- }
5802
- /**
5803
- * Dual-mode property decorator that supports both legacy and standard decorator syntax.
5804
- */
5805
- interface DualModePropertyDecorator {
5806
- (target: object, propertyKey: string | symbol): void;
5807
- (value: unknown, context: StandardDecoratorContext): void;
5808
- }
5809
- /**
5810
- * Dual-mode class decorator that supports both legacy and standard decorator syntax.
5811
- */
5812
- interface DualModeClassDecorator {
5813
- <TFunction extends Function>(value: TFunction): void | TFunction;
5814
- <TFunction extends Function>(value: TFunction, context: StandardDecoratorContext): void | TFunction;
5815
- }
5816
- /**
5817
- * Bag for storing decorator metadata during the decoration phase.
5818
- */
5819
- interface DecoratorMetadataBag {
5820
- columns: Array<{
5821
- propertyName: string;
5822
- column: ColumnDefLike;
5823
- }>;
5824
- relations: Array<{
5825
- propertyName: string;
5826
- relation: RelationMetadata;
5827
- }>;
5828
- }
5829
- /**
5830
- * Public helper to read decorator metadata from a class constructor.
5831
- * Standard decorators only; legacy metadata is intentionally ignored.
5832
- * @param ctor - The entity constructor.
5833
- * @returns The metadata bag if present.
5834
- */
5835
- declare const getDecoratorMetadata: (ctor: object) => DecoratorMetadataBag | undefined;
5836
-
5837
6088
  /**
5838
6089
  * Options for defining an entity.
5839
6090
  */
@@ -5846,7 +6097,7 @@ interface EntityOptions {
5846
6097
  * @param options - Configuration options for the entity.
5847
6098
  * @returns A class decorator that registers the entity metadata.
5848
6099
  */
5849
- declare function Entity(options?: EntityOptions): DualModeClassDecorator;
6100
+ declare function Entity(options?: EntityOptions): <T extends EntityConstructor>(value: T, context: ClassDecoratorContext) => T;
5850
6101
 
5851
6102
  /**
5852
6103
  * Options for defining a column in an entity.
@@ -5868,14 +6119,14 @@ type ColumnInput = ColumnOptions | ColumnDef;
5868
6119
  * @param definition - The column definition or options.
5869
6120
  * @returns A property decorator that registers the column metadata.
5870
6121
  */
5871
- declare function Column(definition: ColumnInput): DualModePropertyDecorator;
6122
+ declare function Column(definition: ColumnInput): (_value: unknown, context: ClassFieldDecoratorContext) => void;
5872
6123
  /**
5873
6124
  * Decorator to define a primary key column on an entity property.
5874
6125
  * Sets the primary flag to true and delegates to Column decorator.
5875
6126
  * @param definition - The column definition or options.
5876
6127
  * @returns A property decorator that registers the primary key column metadata.
5877
6128
  */
5878
- declare function PrimaryKey(definition: ColumnInput): DualModePropertyDecorator;
6129
+ declare function PrimaryKey(definition: ColumnInput): (_value: unknown, context: ClassFieldDecoratorContext) => void;
5879
6130
 
5880
6131
  interface BaseRelationOptions {
5881
6132
  target: EntityOrTableTargetResolver;
@@ -5886,28 +6137,28 @@ interface BaseRelationOptions {
5886
6137
  * Options for HasMany relation.
5887
6138
  */
5888
6139
  interface HasManyOptions extends BaseRelationOptions {
5889
- foreignKey: string;
6140
+ foreignKey?: string;
5890
6141
  }
5891
6142
  /**
5892
6143
  * Options for HasOne relation.
5893
6144
  */
5894
6145
  interface HasOneOptions extends BaseRelationOptions {
5895
- foreignKey: string;
6146
+ foreignKey?: string;
5896
6147
  }
5897
6148
  /**
5898
6149
  * Options for BelongsTo relation.
5899
6150
  */
5900
6151
  interface BelongsToOptions extends BaseRelationOptions {
5901
- foreignKey: string;
6152
+ foreignKey?: string;
5902
6153
  }
5903
6154
  /**
5904
6155
  * Options for BelongsToMany relation.
5905
6156
  */
5906
- interface BelongsToManyOptions {
5907
- target: EntityOrTableTargetResolver;
5908
- pivotTable: EntityOrTableTargetResolver;
5909
- pivotForeignKeyToRoot: string;
5910
- pivotForeignKeyToTarget: string;
6157
+ interface BelongsToManyOptions<TTarget extends EntityOrTableTarget = EntityOrTableTarget, TPivot extends EntityOrTableTarget = EntityOrTableTarget> {
6158
+ target: EntityOrTableTargetResolver<TTarget>;
6159
+ pivotTable: EntityOrTableTargetResolver<TPivot>;
6160
+ pivotForeignKeyToRoot?: string;
6161
+ pivotForeignKeyToTarget?: string;
5911
6162
  localKey?: string;
5912
6163
  targetKey?: string;
5913
6164
  pivotPrimaryKey?: string;
@@ -5919,25 +6170,25 @@ interface BelongsToManyOptions {
5919
6170
  * @param options - The relation options.
5920
6171
  * @returns A property decorator that registers the relation metadata.
5921
6172
  */
5922
- declare function HasMany(options: HasManyOptions): DualModePropertyDecorator;
6173
+ declare function HasMany(options: HasManyOptions): (_value: unknown, context: ClassFieldDecoratorContext) => void;
5923
6174
  /**
5924
6175
  * Decorator to define a HasOne relation on an entity property.
5925
6176
  * @param options - The relation options.
5926
6177
  * @returns A property decorator that registers the relation metadata.
5927
6178
  */
5928
- declare function HasOne(options: HasOneOptions): DualModePropertyDecorator;
6179
+ declare function HasOne(options: HasOneOptions): (_value: unknown, context: ClassFieldDecoratorContext) => void;
5929
6180
  /**
5930
6181
  * Decorator to define a BelongsTo relation on an entity property.
5931
6182
  * @param options - The relation options.
5932
6183
  * @returns A property decorator that registers the relation metadata.
5933
6184
  */
5934
- declare function BelongsTo(options: BelongsToOptions): DualModePropertyDecorator;
6185
+ declare function BelongsTo(options: BelongsToOptions): (_value: unknown, context: ClassFieldDecoratorContext) => void;
5935
6186
  /**
5936
6187
  * Decorator to define a BelongsToMany relation on an entity property.
5937
6188
  * @param options - The relation options.
5938
6189
  * @returns A property decorator that registers the relation metadata.
5939
6190
  */
5940
- declare function BelongsToMany(options: BelongsToManyOptions): DualModePropertyDecorator;
6191
+ declare function BelongsToMany<TTarget extends EntityOrTableTarget = EntityOrTableTarget, TPivot extends EntityOrTableTarget = EntityOrTableTarget>(options: BelongsToManyOptions<TTarget, TPivot>): (_value: unknown, context: ClassFieldDecoratorContext) => void;
5941
6192
 
5942
6193
  /**
5943
6194
  * Bootstraps all entities by building their table definitions and relations.
@@ -5964,7 +6215,7 @@ type EntityTable<TEntity extends object> = Omit<TableDef<{
5964
6215
  [K in SelectableKeys<TEntity>]: ColumnDef;
5965
6216
  }>, 'relations'> & {
5966
6217
  relations: {
5967
- [K in RelationKeys<TEntity>]: NonNullable<TEntity[K]> extends HasManyCollection<infer TChild> ? HasManyRelation<EntityTable<NonNullable<TChild> & object>> : NonNullable<TEntity[K]> extends ManyToManyCollection<infer TTarget> ? BelongsToManyRelation<EntityTable<NonNullable<TTarget> & object>> : NonNullable<TEntity[K]> extends HasOneReference<infer TChild> ? HasOneRelation<EntityTable<NonNullable<TChild> & object>> : NonNullable<TEntity[K]> extends BelongsToReference<infer TParent> ? BelongsToRelation<EntityTable<NonNullable<TParent> & object>> : NonNullable<TEntity[K]> extends object ? BelongsToRelation<EntityTable<NonNullable<TEntity[K]> & object>> : never;
6218
+ [K in RelationKeys<TEntity>]: NonNullable<TEntity[K]> extends HasManyCollection<infer TChild> ? HasManyRelation<EntityTable<NonNullable<TChild> & object>> : NonNullable<TEntity[K]> extends ManyToManyCollection<infer TTarget, infer TPivot> ? BelongsToManyRelation<EntityTable<NonNullable<TTarget> & object>, TPivot extends object ? EntityTable<NonNullable<TPivot> & object> : TableDef> : NonNullable<TEntity[K]> extends HasOneReference<infer TChild> ? HasOneRelation<EntityTable<NonNullable<TChild> & object>> : NonNullable<TEntity[K]> extends BelongsToReference<infer TParent> ? BelongsToRelation<EntityTable<NonNullable<TParent> & object>> : NonNullable<TEntity[K]> extends object ? BelongsToRelation<EntityTable<NonNullable<TEntity[K]> & object>> : never;
5968
6219
  };
5969
6220
  };
5970
6221
  declare const selectFromEntity: <TEntity extends object>(ctor: EntityConstructor<TEntity>) => SelectQueryBuilder<unknown, EntityTable<TEntity>>;
@@ -5974,7 +6225,27 @@ declare const selectFromEntity: <TEntity extends object>(ctor: EntityConstructor
5974
6225
  * Lazily bootstraps entity metadata (via getTableDefFromEntity) and returns a
5975
6226
  * `tableRef(...)`-style proxy so users can write `u.id` instead of `u.columns.id`.
5976
6227
  */
5977
- declare const entityRef: <TTable extends TableDef = TableDef>(ctor: EntityConstructor) => TableRef$1<TTable>;
6228
+ declare const entityRef: <TEntity extends object>(ctor: EntityConstructor<TEntity>) => TableRef$1<EntityTable<TEntity>>;
6229
+
6230
+ /**
6231
+ * Bag for storing decorator metadata during the decoration phase.
6232
+ */
6233
+ interface DecoratorMetadataBag {
6234
+ columns: Array<{
6235
+ propertyName: string;
6236
+ column: ColumnDefLike;
6237
+ }>;
6238
+ relations: Array<{
6239
+ propertyName: string;
6240
+ relation: RelationMetadata;
6241
+ }>;
6242
+ }
6243
+ /**
6244
+ * Public helper to read decorator metadata from a class constructor.
6245
+ * @param ctor - The entity constructor.
6246
+ * @returns The metadata bag if present.
6247
+ */
6248
+ declare const getDecoratorMetadata: (ctor: object) => DecoratorMetadataBag | undefined;
5978
6249
 
5979
6250
  type PoolOptions = {
5980
6251
  /** Maximum number of live resources (idle + leased). */
@@ -6139,4 +6410,4 @@ type PooledExecutorFactoryOptions<TConn> = {
6139
6410
  */
6140
6411
  declare function createPooledExecutorFactory<TConn>(opts: PooledExecutorFactoryOptions<TConn>): DbExecutorFactory;
6141
6412
 
6142
- export { type AliasRefNode, type AnyDomainEvent, type ArithmeticExpressionNode, type TableRef as AstTableRef, AsyncLocalStorage, BelongsTo, BelongsToMany, type BelongsToManyOptions, type BelongsToManyRelation, type BelongsToOptions, type BelongsToReference, type BelongsToReferenceApi, type BelongsToRelation, type BetweenExpressionNode, type BinaryExpressionNode, type BitwiseExpressionNode, type CascadeMode, type CaseExpressionNode, type CastExpressionNode, type CheckConstraint, type CollateExpressionNode, Column, type ColumnDef, type ColumnDiff, type ColumnInput, type ColumnNode, type ColumnOptions, type ColumnRef, type ColumnToTs, type ColumnType, type CreateTediousClientOptions, type DatabaseCheck, type DatabaseColumn, type DatabaseIndex, type DatabaseSchema, type DatabaseTable, type DbExecutor, type DbExecutorFactory, DefaultBelongsToReference, DefaultHasManyCollection, DefaultManyToManyCollection, type DefaultValue, DeleteQueryBuilder, type DialectName, type DomainEvent, DomainEventBus, type DomainEventHandler, Entity, type EntityContext, type EntityInstance, type EntityOptions, EntityStatus, type ExecutionContext, type ExistsExpressionNode, type ExpressionNode, type ExpressionVisitor, type ForeignKeyReference, type FunctionNode, type GroupConcatOptions, type HasDomainEvents, HasMany, type HasManyCollection, type HasManyOptions, type HasManyRelation, HasOne, type HasOneOptions, type HasOneReference, type HasOneReferenceApi, type HasOneRelation, type HydrationContext, type HydrationMetadata, type HydrationPivotPlan, type HydrationPlan, type HydrationRelationPlan, type InExpressionNode, type InExpressionRight, type IndexColumn, type IndexDef, type InferRow, type InitialHandlers, InsertQueryBuilder, type IntrospectOptions, type JsonPathNode, type Jsonify, type JsonifyScalar, type LiteralNode, type LiteralValue, type LogicalExpressionNode, type ManyToManyCollection, type MssqlClientLike, MySqlDialect, type MysqlClientLike, type NullExpressionNode, type OperandNode, type OperandVisitor, Orm, type OrmDomainEvent, type OrmInterceptor, type OrmOptions, OrmSession, type OrmSessionOptions, Pool, type PoolAdapter, type PoolLease, type PoolOptions, type PooledConnectionAdapter, type PostgresClientLike, PostgresDialect, PrimaryKey, type Primitive, type QueryLogEntry, type QueryLogger, type QueryResult, type RawDefaultValue, type ReferentialAction, type RelationChange, type RelationChangeEntry, type RelationDef, type RelationKey, RelationKinds, type RelationMap, type RelationTargetTable, type RelationType, type RenderColumnOptions, STANDARD_COLUMN_TYPES, type SaveGraphInputPayload, type SaveGraphInputScalar, type SaveGraphJsonScalar, type ScalarSubqueryNode, type SchemaChange, type SchemaChangeKind, type SchemaDiffOptions, type SchemaGenerateResult, type SchemaIntrospector, type SchemaPlan, SelectQueryBuilder, type SelectQueryInput, type SelectableKeys, type SimpleQueryRunner, SqlServerDialect, type SqliteClientLike, SqliteDialect, type StandardColumnType, type SynchronizeOptions, type TableDef, type TableHooks, type TableOptions, type TableRef$1 as TableRef, type TediousColumn, type TediousConnectionLike, type TediousModule, type TediousRequest, type TediousRequestCtor, type TediousTypes, type TrackedEntity, TypeScriptGenerator, UpdateQueryBuilder, type ValueOperandInput, type WindowFunctionNode, abs, acos, add, addDomainEvent, age, aliasRef, and, arrayAppend, ascii, asin, atan, atan2, avg, belongsTo, belongsToMany, between, bitAnd, bitLength, bitOr, bitXor, bootstrapEntities, caseWhen, cast, cbrt, ceil, ceiling, char, charLength, chr, clearExpressionDispatchers, clearOperandDispatchers, coalesce, col, collate, columnOperand, concat, concatWs, correlateBy, cos, cot, count, countAll, createEntityFromRow, createEntityProxy, createExecutorFromQueryRunner, createMssqlExecutor, createMysqlExecutor, createPooledExecutorFactory, createPostgresExecutor, createQueryLoggingExecutor, createSqliteExecutor, createTediousExecutor, createTediousMssqlClient, currentDate, currentTime, dateAdd, dateDiff, dateFormat, dateSub, dateTrunc, day, dayOfWeek, defineTable, degrees, denseRank, diffSchema, div, endOfMonth, entityRef, eq, esel, executeHydrated, executeHydratedWithContexts, exists, exp, extract, firstValue, floor, fromUnixTime, generateCreateTableSql, generateSchemaSql, getColumn, getDecoratorMetadata, getSchemaIntrospector, getTableDefFromEntity, greatest, groupConcat, gt, gte, hasMany, hasOne, hour, hydrateRows, ifNull, inList, inSubquery, initcap, instr, introspectSchema, isCaseExpressionNode, isCastExpressionNode, isCollateExpressionNode, isExpressionSelectionNode, isFunctionNode, isNotNull, isNull, isOperandNode, isValueOperandInput, isWindowFunctionNode, jsonArrayAgg, jsonContains, jsonLength, jsonPath, jsonSet, jsonify, lag, lastValue, lead, least, left, length, like, ln, loadBelongsToManyRelation, loadBelongsToRelation, loadHasManyRelation, loadHasOneRelation, localTime, localTimestamp, locate, log, log10, log2, logBase, lower, lpad, lt, lte, ltrim, max, md5, min, minute, mod, month, mul, neq, normalizeColumnType, notBetween, notExists, notInList, notInSubquery, notLike, now, ntile, nullif, octetLength, or, outerRef, pi, position, pow, power, quarter, radians, rand, random, rank, registerExpressionDispatcher, registerOperandDispatcher, registerSchemaIntrospector, relationLoaderCache, renderColumnDefinition, renderTypeWithArgs, repeat, replace, reverse, right, round, rowNumber, rowsToQueryResult, rpad, rtrim, second, sel, selectFromEntity, sha1, sha2, shiftLeft, shiftRight, sign, sin, space, sqrt, stddev, sub, substr, sum, synchronizeSchema, tableRef, tan, toColumnRef, toTableRef, trim, trunc, truncate, unixTimestamp, upper, utcNow, valueToOperand, variance, visitExpression, visitOperand, weekOfYear, windowFunction, year };
6413
+ export { type AliasRefNode, type AnyDomainEvent, type ArithmeticExpressionNode, type TableRef as AstTableRef, AsyncLocalStorage, BelongsTo, BelongsToMany, type BelongsToManyOptions, type BelongsToManyRelation, type BelongsToOptions, type BelongsToReference, type BelongsToReferenceApi, type BelongsToRelation, type BetweenExpressionNode, type BinaryExpressionNode, type BitwiseExpressionNode, type CascadeMode, type CaseExpressionNode, type CastExpressionNode, type CheckConstraint, type CollateExpressionNode, Column, type ColumnDef, type ColumnDiff, type ColumnInput, type ColumnNode, type ColumnOptions, type ColumnRef, type ColumnToTs, type ColumnType, type CreateTediousClientOptions, type DatabaseCheck, type DatabaseColumn, type DatabaseIndex, type DatabaseSchema, type DatabaseTable, type DbExecutor, type DbExecutorFactory, DefaultBelongsToReference, DefaultHasManyCollection, DefaultManyToManyCollection, type DefaultValue, DeleteQueryBuilder, type DialectName, type DomainEvent, DomainEventBus, type DomainEventHandler, Entity, type EntityContext, type EntityInstance, type EntityOptions, EntityStatus, type ExecutionContext, type ExistsExpressionNode, type ExpressionNode, type ExpressionVisitor, type ForeignKeyReference, type FunctionNode, type GroupConcatOptions, type HasDomainEvents, HasMany, type HasManyCollection, type HasManyOptions, type HasManyRelation, HasOne, type HasOneOptions, type HasOneReference, type HasOneReferenceApi, type HasOneRelation, type HydrationContext, type HydrationMetadata, type HydrationPivotPlan, type HydrationPlan, type HydrationRelationPlan, type InExpressionNode, type InExpressionRight, type IndexColumn, type IndexDef, type InferRow, type InitialHandlers, InsertQueryBuilder, type IntrospectOptions, type JsonPathNode, type Jsonify, type JsonifyScalar, type LiteralNode, type LiteralValue, type LogicalExpressionNode, type ManyToManyCollection, type MssqlClientLike, MySqlDialect, type MysqlClientLike, type NullExpressionNode, type OperandNode, type OperandVisitor, Orm, type OrmDomainEvent, type OrmInterceptor, type OrmOptions, OrmSession, type OrmSessionOptions, Pool, type PoolAdapter, type PoolLease, type PoolOptions, type PooledConnectionAdapter, type PostgresClientLike, PostgresDialect, PrimaryKey, type Primitive, type QueryLogEntry, type QueryLogger, type QueryResult, type RawDefaultValue, type ReferentialAction, type RelationChange, type RelationChangeEntry, type RelationDef, type RelationKey$1 as RelationKey, RelationKinds, type RelationMap, type RelationTargetTable, type RelationType, type RenderColumnOptions, STANDARD_COLUMN_TYPES, type SaveGraphInputPayload, type SaveGraphInputScalar, type SaveGraphJsonScalar, type ScalarSubqueryNode, type SchemaChange, type SchemaChangeKind, type SchemaDiffOptions, type SchemaGenerateResult, type SchemaIntrospector, type SchemaPlan, SelectQueryBuilder, type SelectQueryInput, type SelectableKeys, type SimpleQueryRunner, SqlServerDialect, type SqliteClientLike, SqliteDialect, type StandardColumnType, type SynchronizeOptions, type TableDef, type TableHooks, type TableOptions, type TableRef$1 as TableRef, type TediousColumn, type TediousConnectionLike, type TediousModule, type TediousRequest, type TediousRequestCtor, type TediousTypes, type TrackedEntity, TypeScriptGenerator, UpdateQueryBuilder, type ValueOperandInput, type WindowFunctionNode, abs, acos, add, addDomainEvent, age, aliasRef, and, arrayAppend, ascii, asin, atan, atan2, avg, belongsTo, belongsToMany, between, bitAnd, bitLength, bitOr, bitXor, bootstrapEntities, caseWhen, cast, cbrt, ceil, ceiling, char, charLength, chr, clearExpressionDispatchers, clearOperandDispatchers, coalesce, col, collate, columnOperand, concat, concatWs, correlateBy, cos, cot, count, countAll, createEntityFromRow, createEntityProxy, createExecutorFromQueryRunner, createMssqlExecutor, createMysqlExecutor, createPooledExecutorFactory, createPostgresExecutor, createQueryLoggingExecutor, createSqliteExecutor, createTediousExecutor, createTediousMssqlClient, currentDate, currentTime, dateAdd, dateDiff, dateFormat, dateSub, dateTrunc, day, dayOfWeek, defineTable, degrees, deleteFrom, denseRank, diffSchema, div, endOfMonth, entityRef, eq, esel, executeHydrated, executeHydratedWithContexts, executeSchemaSql, executeSchemaSqlFor, exists, exp, extract, firstValue, floor, fromUnixTime, generateCreateTableSql, generateSchemaSql, generateSchemaSqlFor, getColumn, getDecoratorMetadata, getSchemaIntrospector, getTableDefFromEntity, greatest, groupConcat, gt, gte, hasMany, hasOne, hour, hydrateRows, ifNull, inList, inSubquery, initcap, insertInto, instr, introspectSchema, isCaseExpressionNode, isCastExpressionNode, isCollateExpressionNode, isExpressionSelectionNode, isFunctionNode, isNotNull, isNull, isOperandNode, isValueOperandInput, isWindowFunctionNode, jsonArrayAgg, jsonContains, jsonLength, jsonPath, jsonSet, jsonify, lag, lastValue, lead, least, left, length, like, ln, loadBelongsToManyRelation, loadBelongsToRelation, loadHasManyRelation, loadHasOneRelation, localTime, localTimestamp, locate, log, log10, log2, logBase, lower, lpad, lt, lte, ltrim, max, md5, min, minute, mod, month, mul, neq, normalizeColumnType, notBetween, notExists, notInList, notInSubquery, notLike, now, ntile, nullif, octetLength, or, outerRef, pi, position, pow, power, quarter, radians, rand, random, rank, registerExpressionDispatcher, registerOperandDispatcher, registerSchemaIntrospector, relationLoaderCache, renderColumnDefinition, renderTypeWithArgs, repeat, replace, reverse, right, round, rowNumber, rowsToQueryResult, rpad, rtrim, second, sel, selectFrom, selectFromEntity, setRelations, sha1, sha2, shiftLeft, shiftRight, sign, sin, space, sqrt, stddev, sub, substr, sum, synchronizeSchema, tableRef, tan, toColumnRef, toTableRef, trim, trunc, truncate, unixTimestamp, update, upper, utcNow, valueToOperand, variance, visitExpression, visitOperand, weekOfYear, windowFunction, year };