metal-orm 1.0.14 → 1.0.16

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 (129) hide show
  1. package/README.md +69 -67
  2. package/dist/decorators/index.cjs +1983 -224
  3. package/dist/decorators/index.cjs.map +1 -1
  4. package/dist/decorators/index.d.cts +6 -6
  5. package/dist/decorators/index.d.ts +6 -6
  6. package/dist/decorators/index.js +1982 -224
  7. package/dist/decorators/index.js.map +1 -1
  8. package/dist/index.cjs +5284 -3751
  9. package/dist/index.cjs.map +1 -1
  10. package/dist/index.d.cts +524 -169
  11. package/dist/index.d.ts +524 -169
  12. package/dist/index.js +5197 -3736
  13. package/dist/index.js.map +1 -1
  14. package/dist/{select-CCp1oz9p.d.cts → select-BKZrMRCQ.d.cts} +555 -94
  15. package/dist/{select-CCp1oz9p.d.ts → select-BKZrMRCQ.d.ts} +555 -94
  16. package/package.json +1 -1
  17. package/src/codegen/naming-strategy.ts +64 -0
  18. package/src/codegen/typescript.ts +19 -21
  19. package/src/core/ast/adapters.ts +21 -0
  20. package/src/core/ast/aggregate-functions.ts +13 -13
  21. package/src/core/ast/builders.ts +56 -43
  22. package/src/core/ast/expression-builders.ts +34 -34
  23. package/src/core/ast/expression-nodes.ts +18 -16
  24. package/src/core/ast/expression-visitor.ts +122 -69
  25. package/src/core/ast/expression.ts +6 -4
  26. package/src/core/ast/join-metadata.ts +15 -0
  27. package/src/core/ast/join-node.ts +22 -20
  28. package/src/core/ast/join.ts +5 -5
  29. package/src/core/ast/query.ts +52 -88
  30. package/src/core/ast/types.ts +20 -0
  31. package/src/core/ast/window-functions.ts +55 -55
  32. package/src/core/ddl/dialects/base-schema-dialect.ts +20 -6
  33. package/src/core/ddl/dialects/mssql-schema-dialect.ts +32 -8
  34. package/src/core/ddl/dialects/mysql-schema-dialect.ts +21 -10
  35. package/src/core/ddl/dialects/postgres-schema-dialect.ts +52 -7
  36. package/src/core/ddl/dialects/sqlite-schema-dialect.ts +23 -9
  37. package/src/core/ddl/introspect/catalogs/index.ts +1 -0
  38. package/src/core/ddl/introspect/catalogs/postgres.ts +143 -0
  39. package/src/core/ddl/introspect/context.ts +9 -0
  40. package/src/core/ddl/introspect/functions/postgres.ts +26 -0
  41. package/src/core/ddl/introspect/mssql.ts +149 -149
  42. package/src/core/ddl/introspect/mysql.ts +99 -99
  43. package/src/core/ddl/introspect/postgres.ts +245 -154
  44. package/src/core/ddl/introspect/registry.ts +26 -0
  45. package/src/core/ddl/introspect/run-select.ts +25 -0
  46. package/src/core/ddl/introspect/sqlite.ts +7 -7
  47. package/src/core/ddl/introspect/types.ts +23 -19
  48. package/src/core/ddl/introspect/utils.ts +1 -1
  49. package/src/core/ddl/naming-strategy.ts +10 -0
  50. package/src/core/ddl/schema-dialect.ts +41 -0
  51. package/src/core/ddl/schema-diff.ts +211 -179
  52. package/src/core/ddl/schema-generator.ts +17 -90
  53. package/src/core/ddl/schema-introspect.ts +25 -32
  54. package/src/core/ddl/schema-plan-executor.ts +17 -0
  55. package/src/core/ddl/schema-types.ts +46 -39
  56. package/src/core/ddl/sql-writing.ts +170 -0
  57. package/src/core/dialect/abstract.ts +172 -126
  58. package/src/core/dialect/base/cte-compiler.ts +33 -0
  59. package/src/core/dialect/base/function-table-formatter.ts +132 -0
  60. package/src/core/dialect/base/groupby-compiler.ts +21 -0
  61. package/src/core/dialect/base/join-compiler.ts +26 -0
  62. package/src/core/dialect/base/orderby-compiler.ts +21 -0
  63. package/src/core/dialect/base/pagination-strategy.ts +32 -0
  64. package/src/core/dialect/base/returning-strategy.ts +56 -0
  65. package/src/core/dialect/base/sql-dialect.ts +181 -204
  66. package/src/core/dialect/dialect-factory.ts +91 -0
  67. package/src/core/dialect/mssql/functions.ts +101 -0
  68. package/src/core/dialect/mssql/index.ts +128 -126
  69. package/src/core/dialect/mysql/functions.ts +101 -0
  70. package/src/core/dialect/mysql/index.ts +20 -18
  71. package/src/core/dialect/postgres/functions.ts +95 -0
  72. package/src/core/dialect/postgres/index.ts +30 -28
  73. package/src/core/dialect/sqlite/functions.ts +115 -0
  74. package/src/core/dialect/sqlite/index.ts +30 -28
  75. package/src/core/driver/database-driver.ts +11 -0
  76. package/src/core/driver/mssql-driver.ts +20 -0
  77. package/src/core/driver/mysql-driver.ts +20 -0
  78. package/src/core/driver/postgres-driver.ts +20 -0
  79. package/src/core/driver/sqlite-driver.ts +20 -0
  80. package/src/core/execution/db-executor.ts +63 -0
  81. package/src/core/execution/executors/mssql-executor.ts +39 -0
  82. package/src/core/execution/executors/mysql-executor.ts +47 -0
  83. package/src/core/execution/executors/postgres-executor.ts +32 -0
  84. package/src/core/execution/executors/sqlite-executor.ts +31 -0
  85. package/src/core/functions/datetime.ts +132 -0
  86. package/src/core/functions/numeric.ts +179 -0
  87. package/src/core/functions/standard-strategy.ts +47 -0
  88. package/src/core/functions/text.ts +147 -0
  89. package/src/core/functions/types.ts +18 -0
  90. package/src/core/hydration/types.ts +57 -0
  91. package/src/decorators/bootstrap.ts +10 -0
  92. package/src/decorators/column.ts +13 -4
  93. package/src/decorators/relations.ts +15 -0
  94. package/src/index.ts +37 -19
  95. package/src/orm/entity-context.ts +30 -0
  96. package/src/orm/entity-meta.ts +2 -2
  97. package/src/orm/entity-metadata.ts +8 -6
  98. package/src/orm/entity.ts +72 -41
  99. package/src/orm/execute.ts +42 -25
  100. package/src/orm/execution-context.ts +12 -0
  101. package/src/orm/hydration-context.ts +14 -0
  102. package/src/orm/hydration.ts +25 -17
  103. package/src/orm/identity-map.ts +4 -0
  104. package/src/orm/interceptor-pipeline.ts +29 -0
  105. package/src/orm/lazy-batch.ts +50 -6
  106. package/src/orm/orm-session.ts +234 -0
  107. package/src/orm/orm.ts +58 -0
  108. package/src/orm/query-logger.ts +1 -1
  109. package/src/orm/relation-change-processor.ts +48 -3
  110. package/src/orm/relations/belongs-to.ts +45 -44
  111. package/src/orm/relations/has-many.ts +44 -43
  112. package/src/orm/relations/has-one.ts +140 -0
  113. package/src/orm/relations/many-to-many.ts +46 -45
  114. package/src/orm/transaction-runner.ts +1 -1
  115. package/src/orm/unit-of-work.ts +66 -61
  116. package/src/query-builder/delete.ts +22 -5
  117. package/src/query-builder/hydration-manager.ts +2 -1
  118. package/src/query-builder/hydration-planner.ts +8 -7
  119. package/src/query-builder/insert.ts +22 -5
  120. package/src/query-builder/relation-conditions.ts +9 -8
  121. package/src/query-builder/relation-service.ts +3 -2
  122. package/src/query-builder/select.ts +575 -64
  123. package/src/query-builder/update.ts +22 -5
  124. package/src/schema/column.ts +246 -246
  125. package/src/schema/relation.ts +35 -1
  126. package/src/schema/table.ts +28 -28
  127. package/src/schema/types.ts +41 -31
  128. package/src/orm/db-executor.ts +0 -11
  129. package/src/orm/orm-context.ts +0 -159
@@ -154,6 +154,8 @@ declare const col: {
154
154
  * Types of relationships supported between tables
155
155
  */
156
156
  declare const RelationKinds: {
157
+ /** One-to-one relationship */
158
+ readonly HasOne: "HAS_ONE";
157
159
  /** One-to-many relationship */
158
160
  readonly HasMany: "HAS_MANY";
159
161
  /** Many-to-one relationship */
@@ -176,6 +178,16 @@ interface HasManyRelation<TTarget extends TableDef = TableDef> {
176
178
  localKey?: string;
177
179
  cascade?: CascadeMode;
178
180
  }
181
+ /**
182
+ * One-to-one relationship definition
183
+ */
184
+ interface HasOneRelation<TTarget extends TableDef = TableDef> {
185
+ type: typeof RelationKinds.HasOne;
186
+ target: TTarget;
187
+ foreignKey: string;
188
+ localKey?: string;
189
+ cascade?: CascadeMode;
190
+ }
179
191
  /**
180
192
  * Many-to-one relationship definition
181
193
  */
@@ -204,7 +216,7 @@ interface BelongsToManyRelation<TTarget extends TableDef = TableDef> {
204
216
  /**
205
217
  * Union type representing any supported relationship definition
206
218
  */
207
- type RelationDef = HasManyRelation | BelongsToRelation | BelongsToManyRelation;
219
+ type RelationDef = HasManyRelation | HasOneRelation | BelongsToRelation | BelongsToManyRelation;
208
220
  /**
209
221
  * Creates a one-to-many relationship definition
210
222
  * @param target - Target table of the relationship
@@ -218,6 +230,14 @@ type RelationDef = HasManyRelation | BelongsToRelation | BelongsToManyRelation;
218
230
  * ```
219
231
  */
220
232
  declare const hasMany: <TTarget extends TableDef>(target: TTarget, foreignKey: string, localKey?: string, cascade?: CascadeMode) => HasManyRelation<TTarget>;
233
+ /**
234
+ * Creates a one-to-one relationship definition
235
+ * @param target - Target table of the relationship
236
+ * @param foreignKey - Foreign key column name on the child table
237
+ * @param localKey - Local key column name (optional)
238
+ * @returns HasOneRelation definition
239
+ */
240
+ declare const hasOne: <TTarget extends TableDef>(target: TTarget, foreignKey: string, localKey?: string, cascade?: CascadeMode) => HasOneRelation<TTarget>;
221
241
  /**
222
242
  * Creates a many-to-one relationship definition
223
243
  * @param target - Target table of the relationship
@@ -338,7 +358,7 @@ type ColumnToTs<T extends ColumnDef> = T['type'] extends 'INT' | 'INTEGER' | 'in
338
358
  type InferRow<TTable extends TableDef> = {
339
359
  [K in keyof TTable['columns']]: ColumnToTs<TTable['columns'][K]>;
340
360
  };
341
- type RelationResult$1<T extends RelationDef> = T extends HasManyRelation<infer TTarget> ? InferRow<TTarget>[] : T extends BelongsToRelation<infer TTarget> ? InferRow<TTarget> | null : T extends BelongsToManyRelation<infer TTarget> ? (InferRow<TTarget> & {
361
+ 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> & {
342
362
  _pivot?: any;
343
363
  })[] : never;
344
364
  /**
@@ -360,6 +380,11 @@ interface BelongsToReference<TParent> {
360
380
  get(): TParent | null;
361
381
  set(data: Partial<TParent> | TParent | null): TParent | null;
362
382
  }
383
+ interface HasOneReference<TChild> {
384
+ load(): Promise<TChild | null>;
385
+ get(): TChild | null;
386
+ set(data: Partial<TChild> | TChild | null): TChild | null;
387
+ }
363
388
  interface ManyToManyCollection<TTarget> {
364
389
  load(): Promise<TTarget[]>;
365
390
  getItems(): TTarget[];
@@ -368,7 +393,7 @@ interface ManyToManyCollection<TTarget> {
368
393
  syncByIds(ids: (number | string)[]): Promise<void>;
369
394
  }
370
395
  type Entity<TTable extends TableDef, TRow = InferRow<TTable>> = TRow & {
371
- [K in keyof RelationMap<TTable>]: TTable['relations'][K] extends HasManyRelation<infer TTarget> ? HasManyCollection<Entity<TTarget>> : TTable['relations'][K] extends BelongsToManyRelation<infer TTarget> ? ManyToManyCollection<Entity<TTarget>> : TTable['relations'][K] extends BelongsToRelation<infer TTarget> ? BelongsToReference<Entity<TTarget>> : never;
396
+ [K in keyof RelationMap<TTable>]: TTable['relations'][K] extends HasManyRelation<infer TTarget> ? HasManyCollection<Entity<TTarget>> : TTable['relations'][K] extends HasOneRelation<infer TTarget> ? HasOneReference<Entity<TTarget>> : TTable['relations'][K] extends BelongsToManyRelation<infer TTarget> ? ManyToManyCollection<Entity<TTarget>> : TTable['relations'][K] extends BelongsToRelation<infer TTarget> ? BelongsToReference<Entity<TTarget>> : never;
372
397
  } & {
373
398
  $load<K extends keyof RelationMap<TTable>>(relation: K): Promise<RelationMap<TTable>[K]>;
374
399
  };
@@ -448,6 +473,43 @@ declare const ORDER_DIRECTIONS: {
448
473
  * Type representing any supported order direction
449
474
  */
450
475
  type OrderDirection = (typeof ORDER_DIRECTIONS)[keyof typeof ORDER_DIRECTIONS];
476
+ /**
477
+ * Supported database dialects
478
+ */
479
+ declare const SUPPORTED_DIALECTS: {
480
+ /** MySQL database dialect */
481
+ readonly MYSQL: "mysql";
482
+ /** SQLite database dialect */
483
+ readonly SQLITE: "sqlite";
484
+ /** Microsoft SQL Server dialect */
485
+ readonly MSSQL: "mssql";
486
+ /** PostgreSQL database dialect */
487
+ readonly POSTGRES: "postgres";
488
+ };
489
+ /**
490
+ * Type representing any supported database dialect
491
+ */
492
+ type DialectName = (typeof SUPPORTED_DIALECTS)[keyof typeof SUPPORTED_DIALECTS];
493
+
494
+ /**
495
+ * Minimal column reference used by AST builders.
496
+ * Accepts any object with a name and optional table/alias fields
497
+ * (schema ColumnDef/TableDef remain structurally compatible).
498
+ */
499
+ interface ColumnRef {
500
+ name: string;
501
+ table?: string;
502
+ alias?: string;
503
+ }
504
+ /**
505
+ * Minimal table reference used by AST builders.
506
+ * Keeps AST decoupled from full schema TableDef shape.
507
+ */
508
+ interface TableRef {
509
+ name: string;
510
+ schema?: string;
511
+ alias?: string;
512
+ }
451
513
 
452
514
  /**
453
515
  * AST node representing a literal value
@@ -476,8 +538,10 @@ interface FunctionNode {
476
538
  type: 'Function';
477
539
  /** Function name (e.g., COUNT, SUM) */
478
540
  name: string;
541
+ /** Optional canonical function key for dialect-aware rendering */
542
+ fn?: string;
479
543
  /** Function arguments */
480
- args: (ColumnNode | LiteralNode | JsonPathNode)[];
544
+ args: OperandNode[];
481
545
  /** Optional alias for the function result */
482
546
  alias?: string;
483
547
  }
@@ -542,7 +606,7 @@ declare const isOperandNode: (node: any) => node is OperandNode;
542
606
  declare const isFunctionNode: (node: any) => node is FunctionNode;
543
607
  declare const isCaseExpressionNode: (node: any) => node is CaseExpressionNode;
544
608
  declare const isWindowFunctionNode: (node: any) => node is WindowFunctionNode;
545
- declare const isExpressionSelectionNode: (node: ColumnDef | FunctionNode | CaseExpressionNode | WindowFunctionNode) => node is FunctionNode | CaseExpressionNode | WindowFunctionNode;
609
+ declare const isExpressionSelectionNode: (node: ColumnRef | FunctionNode | CaseExpressionNode | WindowFunctionNode) => node is FunctionNode | CaseExpressionNode | WindowFunctionNode;
546
610
  /**
547
611
  * AST node representing a binary expression (e.g., column = value)
548
612
  */
@@ -626,11 +690,11 @@ interface JoinNode {
626
690
  /** Type of join (INNER, LEFT, RIGHT, etc.) */
627
691
  kind: JoinKind;
628
692
  /** Table to join */
629
- table: TableNode;
693
+ table: TableNode | FunctionTableNode;
630
694
  /** Join condition expression */
631
695
  condition: ExpressionNode;
632
- /** Optional relation name for code generation */
633
- relationName?: string;
696
+ /** Optional metadata for non-SQL concerns (e.g., relation name) */
697
+ meta?: Record<string, unknown>;
634
698
  }
635
699
 
636
700
  /**
@@ -645,6 +709,26 @@ interface TableNode {
645
709
  /** Optional table alias */
646
710
  alias?: string;
647
711
  }
712
+ /**
713
+ * AST node representing a function used as a table source (table-valued function)
714
+ */
715
+ interface FunctionTableNode {
716
+ type: 'FunctionTable';
717
+ /** Function name */
718
+ name: string;
719
+ /** Optional schema for the function (some dialects) */
720
+ schema?: string;
721
+ /** Function arguments as operand nodes */
722
+ args?: any[];
723
+ /** Optional alias for the function table */
724
+ alias?: string;
725
+ /** LATERAL flag */
726
+ lateral?: boolean;
727
+ /** WITH ORDINALITY flag */
728
+ withOrdinality?: boolean;
729
+ /** Optional column aliases */
730
+ columnAliases?: string[];
731
+ }
648
732
  /**
649
733
  * AST node representing an ORDER BY clause
650
734
  */
@@ -655,58 +739,6 @@ interface OrderByNode {
655
739
  /** Order direction (ASC or DESC) */
656
740
  direction: OrderDirection;
657
741
  }
658
- /**
659
- * Plan describing pivot columns needed for hydration
660
- */
661
- interface HydrationPivotPlan {
662
- table: string;
663
- primaryKey: string;
664
- aliasPrefix: string;
665
- columns: string[];
666
- }
667
- /**
668
- * Plan for hydrating relationship data
669
- */
670
- interface HydrationRelationPlan {
671
- /** Name of the relationship */
672
- name: string;
673
- /** Alias prefix for the relationship */
674
- aliasPrefix: string;
675
- /** Type of relationship */
676
- type: RelationType;
677
- /** Target table name */
678
- targetTable: string;
679
- /** Target table primary key */
680
- targetPrimaryKey: string;
681
- /** Foreign key column */
682
- foreignKey: string;
683
- /** Local key column */
684
- localKey: string;
685
- /** Columns to include */
686
- columns: string[];
687
- /** Optional pivot plan for many-to-many relationships */
688
- pivot?: HydrationPivotPlan;
689
- }
690
- /**
691
- * Complete hydration plan for a query
692
- */
693
- interface HydrationPlan {
694
- /** Root table name */
695
- rootTable: string;
696
- /** Root table primary key */
697
- rootPrimaryKey: string;
698
- /** Root table columns */
699
- rootColumns: string[];
700
- /** Relationship hydration plans */
701
- relations: HydrationRelationPlan[];
702
- }
703
- /**
704
- * Query metadata including hydration information
705
- */
706
- interface QueryMetadata {
707
- /** Optional hydration plan */
708
- hydration?: HydrationPlan;
709
- }
710
742
  /**
711
743
  * AST node representing a Common Table Expression (CTE)
712
744
  */
@@ -742,8 +774,8 @@ interface SelectQueryNode {
742
774
  type: 'SelectQuery';
743
775
  /** Optional CTEs (WITH clauses) */
744
776
  ctes?: CommonTableExpressionNode[];
745
- /** FROM clause table */
746
- from: TableNode;
777
+ /** FROM clause table (either a Table or a FunctionTable) */
778
+ from: TableNode | FunctionTableNode;
747
779
  /** SELECT clause columns */
748
780
  columns: (ColumnNode | FunctionNode | ScalarSubqueryNode | CaseExpressionNode | WindowFunctionNode)[];
749
781
  /** JOIN clauses */
@@ -761,7 +793,7 @@ interface SelectQueryNode {
761
793
  /** Optional OFFSET clause */
762
794
  offset?: number;
763
795
  /** Optional query metadata */
764
- meta?: QueryMetadata;
796
+ meta?: Record<string, unknown>;
765
797
  /** Optional DISTINCT clause */
766
798
  distinct?: ColumnNode[];
767
799
  /** Optional set operations chaining this query with others */
@@ -805,6 +837,72 @@ interface DeleteQueryNode {
805
837
  returning?: ColumnNode[];
806
838
  }
807
839
 
840
+ /**
841
+ * Plan describing pivot columns needed for hydration
842
+ */
843
+ interface HydrationPivotPlan {
844
+ table: string;
845
+ primaryKey: string;
846
+ aliasPrefix: string;
847
+ columns: string[];
848
+ }
849
+ /**
850
+ * Plan for hydrating relationship data
851
+ */
852
+ interface HydrationRelationPlan {
853
+ /** Name of the relationship */
854
+ name: string;
855
+ /** Alias prefix for the relationship */
856
+ aliasPrefix: string;
857
+ /** Type of relationship */
858
+ type: RelationType;
859
+ /** Target table name */
860
+ targetTable: string;
861
+ /** Target table primary key */
862
+ targetPrimaryKey: string;
863
+ /** Foreign key column */
864
+ foreignKey: string;
865
+ /** Local key column */
866
+ localKey: string;
867
+ /** Columns to include */
868
+ columns: string[];
869
+ /** Optional pivot plan for many-to-many relationships */
870
+ pivot?: HydrationPivotPlan;
871
+ }
872
+ /**
873
+ * Complete hydration plan for a query
874
+ */
875
+ interface HydrationPlan {
876
+ /** Root table name */
877
+ rootTable: string;
878
+ /** Root table primary key */
879
+ rootPrimaryKey: string;
880
+ /** Root table columns */
881
+ rootColumns: string[];
882
+ /** Relationship hydration plans */
883
+ relations: HydrationRelationPlan[];
884
+ }
885
+ /**
886
+ * Metadata bag for attaching hydration to query ASTs without coupling AST types.
887
+ */
888
+ interface HydrationMetadata {
889
+ hydration?: HydrationPlan;
890
+ [key: string]: unknown;
891
+ }
892
+
893
+ interface FunctionRenderContext {
894
+ node: FunctionNode;
895
+ compiledArgs: string[];
896
+ }
897
+ type FunctionRenderer = (ctx: FunctionRenderContext) => string;
898
+ interface FunctionStrategy {
899
+ /**
900
+ * Returns a renderer for a specific function name (e.g. "DATE_ADD").
901
+ * Returns undefined if this dialect doesn't support the function.
902
+ */
903
+ getRenderer(functionName: string): FunctionRenderer | undefined;
904
+ }
905
+
808
906
  /**
809
907
  * Context for SQL compilation with parameter management
810
908
  */
@@ -839,6 +937,8 @@ interface DeleteCompiler {
839
937
  * Abstract base class for SQL dialect implementations
840
938
  */
841
939
  declare abstract class Dialect implements SelectCompiler, InsertCompiler, UpdateCompiler, DeleteCompiler {
940
+ /** Dialect identifier used for function rendering and formatting */
941
+ protected abstract readonly dialect: DialectName;
842
942
  /**
843
943
  * Compiles a SELECT query AST to SQL
844
944
  * @param ast - Query AST to compile
@@ -921,7 +1021,14 @@ declare abstract class Dialect implements SelectCompiler, InsertCompiler, Update
921
1021
  protected normalizeSelectAst(ast: SelectQueryNode): SelectQueryNode;
922
1022
  private readonly expressionCompilers;
923
1023
  private readonly operandCompilers;
924
- protected constructor();
1024
+ protected readonly functionStrategy: FunctionStrategy;
1025
+ protected constructor(functionStrategy?: FunctionStrategy);
1026
+ /**
1027
+ * Creates a new Dialect instance (for testing purposes)
1028
+ * @param functionStrategy - Optional function strategy
1029
+ * @returns New Dialect instance
1030
+ */
1031
+ static create(functionStrategy?: FunctionStrategy): Dialect;
925
1032
  /**
926
1033
  * Registers an expression compiler for a specific node type
927
1034
  * @param type - Expression node type
@@ -951,8 +1058,14 @@ declare abstract class Dialect implements SelectCompiler, InsertCompiler, Update
951
1058
  private registerDefaultExpressionCompilers;
952
1059
  private registerDefaultOperandCompilers;
953
1060
  protected compileJsonPath(node: JsonPathNode): string;
1061
+ /**
1062
+ * Compiles a function operand, using the dialect's function strategy.
1063
+ */
1064
+ protected compileFunctionOperand(fnNode: FunctionNode, ctx: CompilerContext): string;
954
1065
  }
955
1066
 
1067
+ type DialectKey = 'postgres' | 'mysql' | 'sqlite' | 'mssql' | (string & {});
1068
+
956
1069
  /**
957
1070
  * Node types that can be used in query projections
958
1071
  */
@@ -1452,6 +1565,82 @@ interface DbExecutor {
1452
1565
  commitTransaction?(): Promise<void>;
1453
1566
  rollbackTransaction?(): Promise<void>;
1454
1567
  }
1568
+ /**
1569
+ * Convert an array of row objects into a QueryResult.
1570
+ */
1571
+ declare function rowsToQueryResult(rows: Array<Record<string, unknown>>): QueryResult;
1572
+ /**
1573
+ * Minimal contract that most SQL clients can implement.
1574
+ */
1575
+ interface SimpleQueryRunner {
1576
+ query(sql: string, params?: unknown[]): Promise<Array<Record<string, unknown>>>;
1577
+ beginTransaction?(): Promise<void>;
1578
+ commitTransaction?(): Promise<void>;
1579
+ rollbackTransaction?(): Promise<void>;
1580
+ }
1581
+ /**
1582
+ * Generic factory: turn any SimpleQueryRunner into a DbExecutor.
1583
+ */
1584
+ declare function createExecutorFromQueryRunner(runner: SimpleQueryRunner): DbExecutor;
1585
+
1586
+ type EntityConstructor = new (...args: any[]) => any;
1587
+ type EntityOrTableTarget = EntityConstructor | TableDef;
1588
+ type EntityOrTableTargetResolver = EntityOrTableTarget | (() => EntityOrTableTarget);
1589
+
1590
+ /**
1591
+ * Strategy interface for converting database names to TypeScript identifiers
1592
+ */
1593
+ interface NamingStrategy {
1594
+ /**
1595
+ * Converts a table name to a TypeScript symbol name
1596
+ * @param table - Table node, function table node, or name
1597
+ * @returns Valid TypeScript identifier
1598
+ */
1599
+ tableToSymbol(table: TableNode | FunctionTableNode | string): string;
1600
+ /**
1601
+ * Converts a column reference to a property name
1602
+ * @param column - Column node
1603
+ * @returns Valid TypeScript property name
1604
+ */
1605
+ columnToProperty(column: ColumnNode): string;
1606
+ }
1607
+
1608
+ interface QueryContext {
1609
+ sql: string;
1610
+ params: unknown[];
1611
+ }
1612
+ type QueryInterceptor = (ctx: QueryContext, next: () => Promise<QueryResult[]>) => Promise<QueryResult[]>;
1613
+ declare class InterceptorPipeline {
1614
+ private interceptors;
1615
+ use(interceptor: QueryInterceptor): void;
1616
+ run(ctx: QueryContext, executor: DbExecutor): Promise<QueryResult[]>;
1617
+ }
1618
+
1619
+ interface OrmOptions {
1620
+ dialect: Dialect;
1621
+ executorFactory: DbExecutorFactory;
1622
+ interceptors?: InterceptorPipeline;
1623
+ namingStrategy?: NamingStrategy;
1624
+ }
1625
+ interface DbExecutorFactory {
1626
+ createExecutor(options?: {
1627
+ tx?: ExternalTransaction;
1628
+ }): DbExecutor;
1629
+ createTransactionalExecutor(): DbExecutor;
1630
+ }
1631
+ interface ExternalTransaction {
1632
+ }
1633
+ declare class Orm {
1634
+ readonly dialect: Dialect;
1635
+ readonly interceptors: InterceptorPipeline;
1636
+ readonly namingStrategy: NamingStrategy;
1637
+ private readonly executorFactory;
1638
+ constructor(opts: OrmOptions);
1639
+ createSession(options?: {
1640
+ tx?: ExternalTransaction;
1641
+ }): OrmSession;
1642
+ transaction<T>(fn: (session: OrmSession) => Promise<T>): Promise<T>;
1643
+ }
1455
1644
 
1456
1645
  declare enum EntityStatus {
1457
1646
  New = "new",
@@ -1481,61 +1670,184 @@ type RelationChange<T> = {
1481
1670
  kind: 'detach';
1482
1671
  entity: T;
1483
1672
  };
1673
+ interface RelationChangeEntry {
1674
+ root: any;
1675
+ relationKey: RelationKey;
1676
+ rootTable: TableDef;
1677
+ relationName: string;
1678
+ relation: RelationDef;
1679
+ change: RelationChange<any>;
1680
+ }
1484
1681
  interface HasDomainEvents {
1485
1682
  domainEvents?: any[];
1486
1683
  }
1487
1684
 
1488
- type DomainEventHandler$1<Context> = (event: any, ctx: Context) => Promise<void> | void;
1685
+ declare class IdentityMap {
1686
+ private readonly buckets;
1687
+ get bucketsMap(): Map<string, Map<string, TrackedEntity>>;
1688
+ getEntity(table: TableDef, pk: string | number): any | undefined;
1689
+ register(tracked: TrackedEntity): void;
1690
+ remove(tracked: TrackedEntity): void;
1691
+ getEntitiesForTable(table: TableDef): TrackedEntity[];
1692
+ clear(): void;
1693
+ private toIdentityKey;
1694
+ }
1695
+
1696
+ declare class UnitOfWork {
1697
+ private readonly dialect;
1698
+ private readonly executor;
1699
+ private readonly identityMap;
1700
+ private readonly hookContext;
1701
+ private readonly trackedEntities;
1702
+ constructor(dialect: Dialect, executor: DbExecutor, identityMap: IdentityMap, hookContext: () => unknown);
1703
+ get identityBuckets(): Map<string, Map<string, TrackedEntity>>;
1704
+ getTracked(): TrackedEntity[];
1705
+ getEntity(table: TableDef, pk: string | number): any | undefined;
1706
+ getEntitiesForTable(table: TableDef): TrackedEntity[];
1707
+ findTracked(entity: any): TrackedEntity | undefined;
1708
+ setEntity(table: TableDef, pk: string | number, entity: any): void;
1709
+ trackNew(table: TableDef, entity: any, pk?: string | number): void;
1710
+ trackManaged(table: TableDef, pk: string | number, entity: any): void;
1711
+ markDirty(entity: any): void;
1712
+ markRemoved(entity: any): void;
1713
+ flush(): Promise<void>;
1714
+ reset(): void;
1715
+ private flushInsert;
1716
+ private flushUpdate;
1717
+ private flushDelete;
1718
+ private runHook;
1719
+ private computeChanges;
1720
+ private extractColumns;
1721
+ private executeCompiled;
1722
+ private getReturningColumns;
1723
+ private applyReturningResults;
1724
+ private normalizeColumnName;
1725
+ private registerIdentity;
1726
+ private createSnapshot;
1727
+ private getPrimaryKeyValue;
1728
+ }
1729
+
1730
+ type DomainEventHandler<Context> = (event: any, ctx: Context) => Promise<void> | void;
1731
+ declare class DomainEventBus<Context> {
1732
+ private readonly handlers;
1733
+ constructor(initialHandlers?: Record<string, DomainEventHandler<Context>[]>);
1734
+ register(name: string, handler: DomainEventHandler<Context>): void;
1735
+ dispatch(trackedEntities: Iterable<TrackedEntity>, ctx: Context): Promise<void>;
1736
+ private getEventName;
1737
+ }
1489
1738
  declare const addDomainEvent: (entity: HasDomainEvents, event: any) => void;
1490
1739
 
1740
+ declare class RelationChangeProcessor {
1741
+ private readonly unitOfWork;
1742
+ private readonly dialect;
1743
+ private readonly executor;
1744
+ private readonly relationChanges;
1745
+ constructor(unitOfWork: UnitOfWork, dialect: Dialect, executor: DbExecutor);
1746
+ registerChange(entry: RelationChangeEntry): void;
1747
+ reset(): void;
1748
+ process(): Promise<void>;
1749
+ private handleHasManyChange;
1750
+ private handleHasOneChange;
1751
+ private handleBelongsToChange;
1752
+ private handleBelongsToManyChange;
1753
+ private assignHasManyForeignKey;
1754
+ private detachHasManyChild;
1755
+ private assignHasOneForeignKey;
1756
+ private detachHasOneChild;
1757
+ private insertPivotRow;
1758
+ private deletePivotRow;
1759
+ private resolvePrimaryKeyValue;
1760
+ }
1761
+
1491
1762
  interface QueryLogEntry {
1492
1763
  sql: string;
1493
1764
  params?: unknown[];
1494
1765
  }
1495
1766
  type QueryLogger = (entry: QueryLogEntry) => void;
1767
+ declare const createQueryLoggingExecutor: (executor: DbExecutor, logger?: QueryLogger) => DbExecutor;
1496
1768
 
1497
- interface OrmInterceptor {
1498
- beforeFlush?(ctx: OrmContext): Promise<void> | void;
1499
- afterFlush?(ctx: OrmContext): Promise<void> | void;
1769
+ interface ExecutionContext {
1770
+ dialect: Dialect;
1771
+ executor: DbExecutor;
1772
+ interceptors: InterceptorPipeline;
1500
1773
  }
1501
- type DomainEventHandler = DomainEventHandler$1<OrmContext>;
1502
- interface OrmContextOptions {
1774
+
1775
+ interface EntityContext {
1503
1776
  dialect: Dialect;
1504
1777
  executor: DbExecutor;
1505
- interceptors?: OrmInterceptor[];
1506
- domainEventHandlers?: Record<string, DomainEventHandler[]>;
1507
- queryLogger?: QueryLogger;
1778
+ getEntity(table: TableDef, pk: any): any;
1779
+ setEntity(table: TableDef, pk: any, entity: any): void;
1780
+ trackNew(table: TableDef, entity: any, pk?: any): void;
1781
+ trackManaged(table: TableDef, pk: any, entity: any): void;
1782
+ markDirty(entity: any): void;
1783
+ markRemoved(entity: any): void;
1784
+ getEntitiesForTable(table: TableDef): TrackedEntity[];
1785
+ registerRelationChange(root: any, relationKey: RelationKey, rootTable: TableDef, relationName: string, relation: RelationDef, change: RelationChange<any>): void;
1508
1786
  }
1509
- declare class OrmContext {
1510
- private readonly options;
1511
- private readonly identityMap;
1512
- private readonly executorWithLogging;
1513
- private readonly unitOfWork;
1514
- private readonly relationChanges;
1787
+
1788
+ interface HydrationContext {
1789
+ identityMap: IdentityMap;
1790
+ unitOfWork: UnitOfWork;
1791
+ domainEvents: DomainEventBus<any>;
1792
+ relationChanges: RelationChangeProcessor;
1793
+ entityContext: EntityContext;
1794
+ }
1795
+
1796
+ interface OrmInterceptor {
1797
+ beforeFlush?(ctx: EntityContext): Promise<void> | void;
1798
+ afterFlush?(ctx: EntityContext): Promise<void> | void;
1799
+ }
1800
+ interface OrmSessionOptions {
1801
+ orm: Orm;
1802
+ executor: DbExecutor;
1803
+ queryLogger?: QueryLogger;
1804
+ interceptors?: OrmInterceptor[];
1805
+ domainEventHandlers?: Record<string, DomainEventHandler<OrmSession>[]>;
1806
+ }
1807
+ declare class OrmSession implements EntityContext {
1808
+ readonly orm: Orm;
1809
+ readonly executor: DbExecutor;
1810
+ readonly identityMap: IdentityMap;
1811
+ readonly unitOfWork: UnitOfWork;
1812
+ readonly domainEvents: DomainEventBus<OrmSession>;
1813
+ readonly relationChanges: RelationChangeProcessor;
1515
1814
  private readonly interceptors;
1516
- private readonly domainEvents;
1517
- constructor(options: OrmContextOptions);
1815
+ constructor(opts: OrmSessionOptions);
1518
1816
  get dialect(): Dialect;
1519
- get executor(): DbExecutor;
1520
1817
  get identityBuckets(): Map<string, Map<string, TrackedEntity>>;
1521
1818
  get tracked(): TrackedEntity[];
1522
- getEntity(table: TableDef, pk: string | number): any | undefined;
1523
- setEntity(table: TableDef, pk: string | number, entity: any): void;
1524
- trackNew(table: TableDef, entity: any, pk?: string | number): void;
1525
- trackManaged(table: TableDef, pk: string | number, entity: any): void;
1819
+ getEntity(table: TableDef, pk: any): any | undefined;
1820
+ setEntity(table: TableDef, pk: any, entity: any): void;
1821
+ trackNew(table: TableDef, entity: any, pk?: any): void;
1822
+ trackManaged(table: TableDef, pk: any, entity: any): void;
1526
1823
  markDirty(entity: any): void;
1527
1824
  markRemoved(entity: any): void;
1528
- registerRelationChange(root: any, relationKey: RelationKey, rootTable: TableDef, relationName: string, relation: RelationDef, change: RelationChange<any>): void;
1529
- registerInterceptor(interceptor: OrmInterceptor): void;
1530
- registerDomainEventHandler(name: string, handler: DomainEventHandler): void;
1531
- saveChanges(): Promise<void>;
1825
+ registerRelationChange: (root: any, relationKey: RelationKey, rootTable: TableDef, relationName: string, relation: RelationDef, change: RelationChange<any>) => void;
1532
1826
  getEntitiesForTable(table: TableDef): TrackedEntity[];
1827
+ registerInterceptor(interceptor: OrmInterceptor): void;
1828
+ registerDomainEventHandler(name: string, handler: DomainEventHandler<OrmSession>): void;
1829
+ find<TTable extends TableDef>(entityClass: EntityConstructor, id: any): Promise<Entity<TTable> | null>;
1830
+ findOne<TTable extends TableDef>(qb: SelectQueryBuilder<any, TTable>): Promise<Entity<TTable> | null>;
1831
+ findMany<TTable extends TableDef>(qb: SelectQueryBuilder<any, TTable>): Promise<Entity<TTable>[]>;
1832
+ persist(entity: object): Promise<void>;
1833
+ remove(entity: object): Promise<void>;
1834
+ flush(): Promise<void>;
1835
+ commit(): Promise<void>;
1836
+ rollback(): Promise<void>;
1837
+ getExecutionContext(): ExecutionContext;
1838
+ getHydrationContext(): HydrationContext;
1533
1839
  }
1534
1840
 
1841
+ type SelectDialectInput = Dialect | DialectKey;
1842
+
1535
1843
  /**
1844
+
1536
1845
  * Main query builder class for constructing SQL SELECT queries
1846
+
1537
1847
  * @typeParam T - Result type for projections (unused)
1848
+
1538
1849
  * @typeParam TTable - Table definition being queried
1850
+
1539
1851
  */
1540
1852
  declare class SelectQueryBuilder<T = any, TTable extends TableDef = TableDef> {
1541
1853
  private readonly env;
@@ -1544,11 +1856,17 @@ declare class SelectQueryBuilder<T = any, TTable extends TableDef = TableDef> {
1544
1856
  private readonly relationManager;
1545
1857
  private readonly lazyRelations;
1546
1858
  /**
1859
+
1547
1860
  * Creates a new SelectQueryBuilder instance
1861
+
1548
1862
  * @param table - Table definition to query
1863
+
1549
1864
  * @param state - Optional initial query state
1865
+
1550
1866
  * @param hydration - Optional hydration manager
1867
+
1551
1868
  * @param dependencies - Optional query builder dependencies
1869
+
1552
1870
  */
1553
1871
  constructor(table: TTable, state?: SelectQueryState, hydration?: HydrationManager, dependencies?: Partial<SelectQueryBuilderDependencies>, lazyRelations?: Set<string>);
1554
1872
  private clone;
@@ -1558,215 +1876,358 @@ declare class SelectQueryBuilder<T = any, TTable extends TableDef = TableDef> {
1558
1876
  private applyJoin;
1559
1877
  private applySetOperation;
1560
1878
  /**
1879
+
1561
1880
  * Selects specific columns for the query
1881
+
1562
1882
  * @param columns - Record of column definitions, function nodes, case expressions, or window functions
1883
+
1563
1884
  * @returns New query builder instance with selected columns
1885
+
1564
1886
  */
1565
1887
  select(columns: Record<string, ColumnDef | FunctionNode | CaseExpressionNode | WindowFunctionNode>): SelectQueryBuilder<T, TTable>;
1566
1888
  /**
1889
+
1567
1890
  * Selects raw column expressions
1891
+
1568
1892
  * @param cols - Column expressions as strings
1893
+
1569
1894
  * @returns New query builder instance with raw column selections
1895
+
1570
1896
  */
1571
1897
  selectRaw(...cols: string[]): SelectQueryBuilder<T, TTable>;
1572
1898
  /**
1899
+
1573
1900
  * Adds a Common Table Expression (CTE) to the query
1901
+
1574
1902
  * @param name - Name of the CTE
1903
+
1575
1904
  * @param query - Query builder or query node for the CTE
1905
+
1576
1906
  * @param columns - Optional column names for the CTE
1907
+
1577
1908
  * @returns New query builder instance with the CTE
1909
+
1578
1910
  */
1579
1911
  with(name: string, query: SelectQueryBuilder<any, TableDef<any>> | SelectQueryNode, columns?: string[]): SelectQueryBuilder<T, TTable>;
1580
1912
  /**
1913
+
1581
1914
  * Adds a recursive Common Table Expression (CTE) to the query
1915
+
1582
1916
  * @param name - Name of the CTE
1917
+
1583
1918
  * @param query - Query builder or query node for the CTE
1919
+
1584
1920
  * @param columns - Optional column names for the CTE
1921
+
1585
1922
  * @returns New query builder instance with the recursive CTE
1923
+
1586
1924
  */
1587
1925
  withRecursive(name: string, query: SelectQueryBuilder<any, TableDef<any>> | SelectQueryNode, columns?: string[]): SelectQueryBuilder<T, TTable>;
1588
1926
  /**
1927
+
1589
1928
  * Selects a subquery as a column
1929
+
1590
1930
  * @param alias - Alias for the subquery column
1931
+
1591
1932
  * @param sub - Query builder or query node for the subquery
1933
+
1592
1934
  * @returns New query builder instance with the subquery selection
1935
+
1593
1936
  */
1594
1937
  selectSubquery(alias: string, sub: SelectQueryBuilder<any, TableDef<any>> | SelectQueryNode): SelectQueryBuilder<T, TTable>;
1595
1938
  /**
1939
+
1596
1940
  * Adds an INNER JOIN to the query
1941
+
1597
1942
  * @param table - Table to join
1943
+
1598
1944
  * @param condition - Join condition expression
1945
+
1599
1946
  * @returns New query builder instance with the INNER JOIN
1947
+
1600
1948
  */
1601
1949
  innerJoin(table: TableDef, condition: BinaryExpressionNode): SelectQueryBuilder<T, TTable>;
1602
1950
  /**
1951
+
1603
1952
  * Adds a LEFT JOIN to the query
1953
+
1604
1954
  * @param table - Table to join
1955
+
1605
1956
  * @param condition - Join condition expression
1957
+
1606
1958
  * @returns New query builder instance with the LEFT JOIN
1959
+
1607
1960
  */
1608
1961
  leftJoin(table: TableDef, condition: BinaryExpressionNode): SelectQueryBuilder<T, TTable>;
1609
1962
  /**
1963
+
1610
1964
  * Adds a RIGHT JOIN to the query
1965
+
1611
1966
  * @param table - Table to join
1967
+
1612
1968
  * @param condition - Join condition expression
1969
+
1613
1970
  * @returns New query builder instance with the RIGHT JOIN
1971
+
1614
1972
  */
1615
1973
  rightJoin(table: TableDef, condition: BinaryExpressionNode): SelectQueryBuilder<T, TTable>;
1616
1974
  /**
1975
+
1617
1976
  * Matches records based on a relationship
1977
+
1618
1978
  * @param relationName - Name of the relationship to match
1979
+
1619
1980
  * @param predicate - Optional predicate expression
1981
+
1620
1982
  * @returns New query builder instance with the relationship match
1983
+
1621
1984
  */
1622
1985
  match(relationName: string, predicate?: ExpressionNode): SelectQueryBuilder<T, TTable>;
1623
1986
  /**
1987
+
1624
1988
  * Joins a related table
1989
+
1625
1990
  * @param relationName - Name of the relationship to join
1991
+
1626
1992
  * @param joinKind - Type of join (defaults to INNER)
1993
+
1627
1994
  * @param extraCondition - Optional additional join condition
1995
+
1628
1996
  * @returns New query builder instance with the relationship join
1997
+
1629
1998
  */
1630
1999
  joinRelation(relationName: string, joinKind?: JoinKind, extraCondition?: ExpressionNode): SelectQueryBuilder<T, TTable>;
1631
2000
  /**
2001
+
1632
2002
  * Includes related data in the query results
2003
+
1633
2004
  * @param relationName - Name of the relationship to include
2005
+
1634
2006
  * @param options - Optional include options
2007
+
1635
2008
  * @returns New query builder instance with the relationship inclusion
2009
+
1636
2010
  */
1637
2011
  include(relationName: string, options?: RelationIncludeOptions): SelectQueryBuilder<T, TTable>;
1638
2012
  includeLazy<K extends keyof RelationMap<TTable>>(relationName: K): SelectQueryBuilder<T, TTable>;
1639
2013
  getLazyRelations(): (keyof RelationMap<TTable>)[];
1640
2014
  getTable(): TTable;
1641
- execute(ctx: OrmContext): Promise<Entity<TTable>[]>;
2015
+ execute(ctx: OrmSession): Promise<Entity<TTable>[]>;
2016
+ executeWithContexts(execCtx: ExecutionContext, hydCtx: HydrationContext): Promise<Entity<TTable>[]>;
1642
2017
  /**
2018
+
1643
2019
  * Adds a WHERE condition to the query
2020
+
1644
2021
  * @param expr - Expression for the WHERE clause
2022
+
1645
2023
  * @returns New query builder instance with the WHERE condition
2024
+
1646
2025
  */
1647
2026
  where(expr: ExpressionNode): SelectQueryBuilder<T, TTable>;
1648
2027
  /**
2028
+
1649
2029
  * Adds a GROUP BY clause to the query
2030
+
1650
2031
  * @param col - Column definition or column node to group by
2032
+
1651
2033
  * @returns New query builder instance with the GROUP BY clause
2034
+
1652
2035
  */
1653
2036
  groupBy(col: ColumnDef | ColumnNode): SelectQueryBuilder<T, TTable>;
1654
2037
  /**
2038
+
1655
2039
  * Adds a HAVING condition to the query
2040
+
1656
2041
  * @param expr - Expression for the HAVING clause
2042
+
1657
2043
  * @returns New query builder instance with the HAVING condition
2044
+
1658
2045
  */
1659
2046
  having(expr: ExpressionNode): SelectQueryBuilder<T, TTable>;
1660
2047
  /**
2048
+
1661
2049
  * Adds an ORDER BY clause to the query
2050
+
1662
2051
  * @param col - Column definition or column node to order by
2052
+
1663
2053
  * @param direction - Order direction (defaults to ASC)
2054
+
1664
2055
  * @returns New query builder instance with the ORDER BY clause
2056
+
1665
2057
  */
1666
2058
  orderBy(col: ColumnDef | ColumnNode, direction?: OrderDirection): SelectQueryBuilder<T, TTable>;
1667
2059
  /**
2060
+
1668
2061
  * Adds a DISTINCT clause to the query
2062
+
1669
2063
  * @param cols - Columns to make distinct
2064
+
1670
2065
  * @returns New query builder instance with the DISTINCT clause
2066
+
1671
2067
  */
1672
2068
  distinct(...cols: (ColumnDef | ColumnNode)[]): SelectQueryBuilder<T, TTable>;
1673
2069
  /**
2070
+
1674
2071
  * Adds a LIMIT clause to the query
2072
+
1675
2073
  * @param n - Maximum number of rows to return
2074
+
1676
2075
  * @returns New query builder instance with the LIMIT clause
2076
+
1677
2077
  */
1678
2078
  limit(n: number): SelectQueryBuilder<T, TTable>;
1679
2079
  /**
2080
+
1680
2081
  * Adds an OFFSET clause to the query
2082
+
1681
2083
  * @param n - Number of rows to skip
2084
+
1682
2085
  * @returns New query builder instance with the OFFSET clause
2086
+
1683
2087
  */
1684
2088
  offset(n: number): SelectQueryBuilder<T, TTable>;
1685
2089
  /**
2090
+
1686
2091
  * Combines this query with another using UNION
2092
+
1687
2093
  * @param query - Query to union with
2094
+
1688
2095
  * @returns New query builder instance with the set operation
2096
+
1689
2097
  */
1690
2098
  union(query: SelectQueryBuilder<any, TableDef<any>> | SelectQueryNode): SelectQueryBuilder<T, TTable>;
1691
2099
  /**
2100
+
1692
2101
  * Combines this query with another using UNION ALL
2102
+
1693
2103
  * @param query - Query to union with
2104
+
1694
2105
  * @returns New query builder instance with the set operation
2106
+
1695
2107
  */
1696
2108
  unionAll(query: SelectQueryBuilder<any, TableDef<any>> | SelectQueryNode): SelectQueryBuilder<T, TTable>;
1697
2109
  /**
2110
+
1698
2111
  * Combines this query with another using INTERSECT
2112
+
1699
2113
  * @param query - Query to intersect with
2114
+
1700
2115
  * @returns New query builder instance with the set operation
2116
+
1701
2117
  */
1702
2118
  intersect(query: SelectQueryBuilder<any, TableDef<any>> | SelectQueryNode): SelectQueryBuilder<T, TTable>;
1703
2119
  /**
2120
+
1704
2121
  * Combines this query with another using EXCEPT
2122
+
1705
2123
  * @param query - Query to subtract
2124
+
1706
2125
  * @returns New query builder instance with the set operation
2126
+
1707
2127
  */
1708
2128
  except(query: SelectQueryBuilder<any, TableDef<any>> | SelectQueryNode): SelectQueryBuilder<T, TTable>;
1709
2129
  /**
2130
+
1710
2131
  * Adds a WHERE EXISTS condition to the query
2132
+
1711
2133
  * @param subquery - Subquery to check for existence
2134
+
1712
2135
  * @returns New query builder instance with the WHERE EXISTS condition
2136
+
1713
2137
  */
1714
2138
  whereExists(subquery: SelectQueryBuilder<any, TableDef<any>> | SelectQueryNode): SelectQueryBuilder<T, TTable>;
1715
2139
  /**
2140
+
1716
2141
  * Adds a WHERE NOT EXISTS condition to the query
2142
+
1717
2143
  * @param subquery - Subquery to check for non-existence
2144
+
1718
2145
  * @returns New query builder instance with the WHERE NOT EXISTS condition
2146
+
1719
2147
  */
1720
2148
  whereNotExists(subquery: SelectQueryBuilder<any, TableDef<any>> | SelectQueryNode): SelectQueryBuilder<T, TTable>;
1721
2149
  /**
2150
+
1722
2151
  * Adds a WHERE EXISTS condition based on a relationship
2152
+
1723
2153
  * @param relationName - Name of the relationship to check
2154
+
1724
2155
  * @param callback - Optional callback to modify the relationship query
2156
+
1725
2157
  * @returns New query builder instance with the relationship existence check
2158
+
1726
2159
  */
1727
2160
  whereHas(relationName: string, callback?: <TChildTable extends TableDef>(qb: SelectQueryBuilder<any, TChildTable>) => SelectQueryBuilder<any, TChildTable>): SelectQueryBuilder<T, TTable>;
1728
2161
  /**
2162
+
1729
2163
  * Adds a WHERE NOT EXISTS condition based on a relationship
2164
+
1730
2165
  * @param relationName - Name of the relationship to check
2166
+
1731
2167
  * @param callback - Optional callback to modify the relationship query
2168
+
1732
2169
  * @returns New query builder instance with the relationship non-existence check
2170
+
1733
2171
  */
1734
2172
  whereHasNot(relationName: string, callback?: <TChildTable extends TableDef>(qb: SelectQueryBuilder<any, TChildTable>) => SelectQueryBuilder<any, TChildTable>): SelectQueryBuilder<T, TTable>;
1735
2173
  /**
2174
+
1736
2175
  * Compiles the query to SQL for a specific dialect
2176
+
1737
2177
  * @param dialect - Database dialect to compile for
2178
+
1738
2179
  * @returns Compiled query with SQL and parameters
2180
+
1739
2181
  */
1740
- compile(dialect: Dialect): CompiledQuery;
2182
+ compile(dialect: SelectDialectInput): CompiledQuery;
1741
2183
  /**
2184
+
1742
2185
  * Converts the query to SQL string for a specific dialect
2186
+
1743
2187
  * @param dialect - Database dialect to generate SQL for
2188
+
1744
2189
  * @returns SQL string representation of the query
2190
+
1745
2191
  */
1746
- toSql(dialect: Dialect): string;
2192
+ toSql(dialect: SelectDialectInput): string;
1747
2193
  /**
2194
+
1748
2195
  * Gets the hydration plan for the query
2196
+
1749
2197
  * @returns Hydration plan or undefined if none exists
2198
+
1750
2199
  */
1751
2200
  getHydrationPlan(): HydrationPlan | undefined;
1752
2201
  /**
2202
+
1753
2203
  * Gets the Abstract Syntax Tree (AST) representation of the query
2204
+
1754
2205
  * @returns Query AST with hydration applied
2206
+
1755
2207
  */
1756
2208
  getAST(): SelectQueryNode;
1757
2209
  }
1758
2210
  /**
2211
+
1759
2212
  * Creates a column node for use in expressions
2213
+
1760
2214
  * @param table - Table name
2215
+
1761
2216
  * @param name - Column name
2217
+
1762
2218
  * @returns ColumnNode with the specified table and name
2219
+
1763
2220
  */
1764
2221
  declare const createColumn: (table: string, name: string) => ColumnNode;
1765
2222
  /**
2223
+
1766
2224
  * Creates a literal value node for use in expressions
2225
+
1767
2226
  * @param val - Literal value (string or number)
2227
+
1768
2228
  * @returns LiteralNode with the specified value
2229
+
1769
2230
  */
1770
2231
  declare const createLiteral: (val: string | number) => LiteralNode;
1771
2232
 
1772
- export { type RelationType as $, type CheckConstraint as A, type BinaryExpressionNode as B, type ColumnDef as C, type DeleteQueryNode as D, type ExpressionNode as E, type FunctionNode as F, type TableOptions as G, type HydrationPlan as H, type InExpressionNode as I, type JsonPathNode as J, type TableHooks as K, type LogicalExpressionNode as L, type ManyToManyCollection as M, type NullExpressionNode as N, type OperandNode as O, defineTable as P, type ColumnType as Q, type RelationMap as R, type SelectQueryNode as S, type TableDef as T, type UpdateQueryNode as U, type ReferentialAction as V, type WindowFunctionNode as W, type RawDefaultValue as X, type DefaultValue as Y, col as Z, RelationKinds as _, type ColumnNode as a, type CascadeMode as a0, type RelationDef as a1, hasMany as a2, belongsTo as a3, belongsToMany as a4, type ColumnToTs as a5, type InferRow as a6, createColumn as a7, createLiteral as a8, isOperandNode as a9, isFunctionNode as aa, isCaseExpressionNode as ab, isWindowFunctionNode as ac, isExpressionSelectionNode as ad, addDomainEvent as ae, EntityStatus as af, type QueryResult as ag, type RelationKey as ah, type RelationChange as ai, type HasDomainEvents as aj, type OrmInterceptor as ak, type DomainEventHandler as al, type OrmContextOptions as am, type QueryLogEntry as an, type QueryLogger as ao, type LiteralNode as b, type BetweenExpressionNode as c, type CaseExpressionNode as d, type ExistsExpressionNode as e, type OrderDirection as f, type ScalarSubqueryNode as g, type InsertQueryNode as h, type InsertCompiler as i, type CompiledQuery as j, type UpdateCompiler as k, type DeleteCompiler as l, Dialect as m, type CompilerContext as n, type ForeignKeyReference as o, type IndexColumn as p, type IndexDef as q, type DbExecutor as r, OrmContext as s, type Entity as t, type HasManyRelation as u, type BelongsToRelation as v, type BelongsToManyRelation as w, type HasManyCollection as x, type BelongsToReference as y, SelectQueryBuilder as z };
2233
+ export { type TableHooks as $, type BelongsToRelation as A, type BinaryExpressionNode as B, type ColumnRef as C, Dialect as D, type ExpressionNode as E, type FunctionNode as F, type BelongsToManyRelation as G, type HydrationPlan as H, type InExpressionNode as I, type JsonPathNode as J, type HasManyCollection as K, type LogicalExpressionNode as L, type BelongsToReference as M, type NullExpressionNode as N, type OperandNode as O, type ManyToManyCollection as P, OrmSession as Q, type RelationMap as R, type SelectQueryNode as S, type TableRef as T, type UpdateQueryNode as U, SelectQueryBuilder as V, type WindowFunctionNode as W, type ExecutionContext as X, type HydrationContext as Y, type CheckConstraint as Z, type TableOptions as _, type ColumnNode as a, defineTable as a0, type ColumnType as a1, type ReferentialAction as a2, type RawDefaultValue as a3, type DefaultValue as a4, col as a5, RelationKinds as a6, type RelationType as a7, type CascadeMode as a8, type RelationDef as a9, EntityStatus as aA, type TrackedEntity as aB, type RelationKey as aC, type RelationChange as aD, type RelationChangeEntry as aE, type HasDomainEvents as aF, type QueryLogEntry as aG, type QueryLogger as aH, createQueryLoggingExecutor as aI, type QueryResult as aJ, rowsToQueryResult as aK, type SimpleQueryRunner as aL, createExecutorFromQueryRunner as aM, type EntityOrTableTargetResolver as aN, type EntityConstructor as aO, hasMany as aa, hasOne as ab, belongsTo as ac, belongsToMany as ad, type ColumnToTs as ae, type InferRow as af, type HasOneReference as ag, createColumn as ah, createLiteral as ai, isOperandNode as aj, isFunctionNode as ak, isCaseExpressionNode as al, isWindowFunctionNode as am, isExpressionSelectionNode as an, type HydrationPivotPlan as ao, type HydrationRelationPlan as ap, type HydrationMetadata as aq, type OrmInterceptor as ar, type OrmSessionOptions as as, type OrmOptions as at, type DbExecutorFactory as au, type ExternalTransaction as av, Orm as aw, type DomainEventHandler as ax, DomainEventBus as ay, addDomainEvent as az, type LiteralNode as b, type BetweenExpressionNode as c, type CaseExpressionNode as d, type ExistsExpressionNode as e, type OrderDirection as f, type ScalarSubqueryNode as g, type ColumnDef as h, type TableDef as i, type InsertQueryNode as j, type InsertCompiler as k, type CompiledQuery as l, type DialectKey as m, type UpdateCompiler as n, type DeleteQueryNode as o, type DeleteCompiler as p, type CompilerContext as q, type ForeignKeyReference as r, type IndexColumn as s, type IndexDef as t, type DbExecutor as u, type NamingStrategy as v, type EntityContext as w, type Entity as x, type HasManyRelation as y, type HasOneRelation as z };