metal-orm 1.0.14 → 1.0.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +40 -45
- package/dist/decorators/index.cjs +1600 -27
- package/dist/decorators/index.cjs.map +1 -1
- package/dist/decorators/index.d.cts +6 -2
- package/dist/decorators/index.d.ts +6 -2
- package/dist/decorators/index.js +1599 -27
- package/dist/decorators/index.js.map +1 -1
- package/dist/index.cjs +4608 -3429
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +511 -159
- package/dist/index.d.ts +511 -159
- package/dist/index.js +4526 -3415
- package/dist/index.js.map +1 -1
- package/dist/{select-CCp1oz9p.d.cts → select-Bkv8g8u_.d.cts} +193 -67
- package/dist/{select-CCp1oz9p.d.ts → select-Bkv8g8u_.d.ts} +193 -67
- package/package.json +1 -1
- package/src/codegen/typescript.ts +38 -35
- package/src/core/ast/adapters.ts +21 -0
- package/src/core/ast/aggregate-functions.ts +13 -13
- package/src/core/ast/builders.ts +56 -43
- package/src/core/ast/expression-builders.ts +34 -34
- package/src/core/ast/expression-nodes.ts +18 -16
- package/src/core/ast/expression-visitor.ts +122 -69
- package/src/core/ast/expression.ts +6 -4
- package/src/core/ast/join-metadata.ts +15 -0
- package/src/core/ast/join-node.ts +22 -20
- package/src/core/ast/join.ts +5 -5
- package/src/core/ast/query.ts +52 -88
- package/src/core/ast/types.ts +20 -0
- package/src/core/ast/window-functions.ts +55 -55
- package/src/core/ddl/dialects/base-schema-dialect.ts +20 -6
- package/src/core/ddl/dialects/mssql-schema-dialect.ts +32 -8
- package/src/core/ddl/dialects/mysql-schema-dialect.ts +21 -10
- package/src/core/ddl/dialects/postgres-schema-dialect.ts +52 -7
- package/src/core/ddl/dialects/sqlite-schema-dialect.ts +23 -9
- package/src/core/ddl/introspect/catalogs/index.ts +1 -0
- package/src/core/ddl/introspect/catalogs/postgres.ts +143 -0
- package/src/core/ddl/introspect/context.ts +9 -0
- package/src/core/ddl/introspect/functions/postgres.ts +26 -0
- package/src/core/ddl/introspect/mssql.ts +149 -149
- package/src/core/ddl/introspect/mysql.ts +99 -99
- package/src/core/ddl/introspect/postgres.ts +245 -154
- package/src/core/ddl/introspect/registry.ts +26 -0
- package/src/core/ddl/introspect/run-select.ts +25 -0
- package/src/core/ddl/introspect/sqlite.ts +7 -7
- package/src/core/ddl/introspect/types.ts +23 -19
- package/src/core/ddl/introspect/utils.ts +1 -1
- package/src/core/ddl/naming-strategy.ts +10 -0
- package/src/core/ddl/schema-dialect.ts +41 -0
- package/src/core/ddl/schema-diff.ts +211 -179
- package/src/core/ddl/schema-generator.ts +16 -90
- package/src/core/ddl/schema-introspect.ts +25 -32
- package/src/core/ddl/schema-plan-executor.ts +17 -0
- package/src/core/ddl/schema-types.ts +46 -39
- package/src/core/ddl/sql-writing.ts +170 -0
- package/src/core/dialect/abstract.ts +144 -126
- package/src/core/dialect/base/cte-compiler.ts +33 -0
- package/src/core/dialect/base/function-table-formatter.ts +132 -0
- package/src/core/dialect/base/groupby-compiler.ts +21 -0
- package/src/core/dialect/base/join-compiler.ts +26 -0
- package/src/core/dialect/base/orderby-compiler.ts +21 -0
- package/src/core/dialect/base/pagination-strategy.ts +32 -0
- package/src/core/dialect/base/returning-strategy.ts +56 -0
- package/src/core/dialect/base/sql-dialect.ts +181 -204
- package/src/core/dialect/dialect-factory.ts +91 -0
- package/src/core/dialect/mssql/functions.ts +101 -0
- package/src/core/dialect/mssql/index.ts +128 -126
- package/src/core/dialect/mysql/functions.ts +101 -0
- package/src/core/dialect/mysql/index.ts +20 -18
- package/src/core/dialect/postgres/functions.ts +95 -0
- package/src/core/dialect/postgres/index.ts +30 -28
- package/src/core/dialect/sqlite/functions.ts +115 -0
- package/src/core/dialect/sqlite/index.ts +30 -28
- package/src/core/driver/database-driver.ts +11 -0
- package/src/core/driver/mssql-driver.ts +20 -0
- package/src/core/driver/mysql-driver.ts +20 -0
- package/src/core/driver/postgres-driver.ts +20 -0
- package/src/core/driver/sqlite-driver.ts +20 -0
- package/src/core/execution/db-executor.ts +63 -0
- package/src/core/execution/executors/mssql-executor.ts +39 -0
- package/src/core/execution/executors/mysql-executor.ts +47 -0
- package/src/core/execution/executors/postgres-executor.ts +32 -0
- package/src/core/execution/executors/sqlite-executor.ts +31 -0
- package/src/core/functions/datetime.ts +132 -0
- package/src/core/functions/numeric.ts +179 -0
- package/src/core/functions/standard-strategy.ts +47 -0
- package/src/core/functions/text.ts +147 -0
- package/src/core/functions/types.ts +18 -0
- package/src/core/hydration/types.ts +57 -0
- package/src/decorators/bootstrap.ts +10 -0
- package/src/decorators/relations.ts +15 -0
- package/src/index.ts +30 -19
- package/src/orm/entity-metadata.ts +7 -0
- package/src/orm/entity.ts +58 -27
- package/src/orm/hydration.ts +25 -17
- package/src/orm/lazy-batch.ts +46 -2
- package/src/orm/orm-context.ts +60 -60
- package/src/orm/query-logger.ts +1 -1
- package/src/orm/relation-change-processor.ts +43 -2
- package/src/orm/relations/has-one.ts +139 -0
- package/src/orm/transaction-runner.ts +1 -1
- package/src/orm/unit-of-work.ts +60 -60
- package/src/query-builder/delete.ts +22 -5
- package/src/query-builder/hydration-manager.ts +2 -1
- package/src/query-builder/hydration-planner.ts +8 -7
- package/src/query-builder/insert.ts +22 -5
- package/src/query-builder/relation-conditions.ts +9 -8
- package/src/query-builder/relation-service.ts +3 -2
- package/src/query-builder/select.ts +66 -61
- package/src/query-builder/update.ts +22 -5
- package/src/schema/column.ts +246 -246
- package/src/schema/relation.ts +35 -1
- package/src/schema/table.ts +28 -28
- package/src/schema/types.ts +41 -31
- package/src/orm/db-executor.ts +0 -11
|
@@ -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:
|
|
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:
|
|
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
|
|
633
|
-
|
|
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?:
|
|
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,8 @@ 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
|
|
1024
|
+
protected readonly functionStrategy: FunctionStrategy;
|
|
1025
|
+
protected constructor(functionStrategy?: FunctionStrategy);
|
|
925
1026
|
/**
|
|
926
1027
|
* Registers an expression compiler for a specific node type
|
|
927
1028
|
* @param type - Expression node type
|
|
@@ -951,8 +1052,14 @@ declare abstract class Dialect implements SelectCompiler, InsertCompiler, Update
|
|
|
951
1052
|
private registerDefaultExpressionCompilers;
|
|
952
1053
|
private registerDefaultOperandCompilers;
|
|
953
1054
|
protected compileJsonPath(node: JsonPathNode): string;
|
|
1055
|
+
/**
|
|
1056
|
+
* Compiles a function operand, using the dialect's function strategy.
|
|
1057
|
+
*/
|
|
1058
|
+
protected compileFunctionOperand(fnNode: FunctionNode, ctx: CompilerContext): string;
|
|
954
1059
|
}
|
|
955
1060
|
|
|
1061
|
+
type DialectKey = 'postgres' | 'mysql' | 'sqlite' | 'mssql' | (string & {});
|
|
1062
|
+
|
|
956
1063
|
/**
|
|
957
1064
|
* Node types that can be used in query projections
|
|
958
1065
|
*/
|
|
@@ -1452,6 +1559,23 @@ interface DbExecutor {
|
|
|
1452
1559
|
commitTransaction?(): Promise<void>;
|
|
1453
1560
|
rollbackTransaction?(): Promise<void>;
|
|
1454
1561
|
}
|
|
1562
|
+
/**
|
|
1563
|
+
* Convert an array of row objects into a QueryResult.
|
|
1564
|
+
*/
|
|
1565
|
+
declare function rowsToQueryResult(rows: Array<Record<string, unknown>>): QueryResult;
|
|
1566
|
+
/**
|
|
1567
|
+
* Minimal contract that most SQL clients can implement.
|
|
1568
|
+
*/
|
|
1569
|
+
interface SimpleQueryRunner {
|
|
1570
|
+
query(sql: string, params?: unknown[]): Promise<Array<Record<string, unknown>>>;
|
|
1571
|
+
beginTransaction?(): Promise<void>;
|
|
1572
|
+
commitTransaction?(): Promise<void>;
|
|
1573
|
+
rollbackTransaction?(): Promise<void>;
|
|
1574
|
+
}
|
|
1575
|
+
/**
|
|
1576
|
+
* Generic factory: turn any SimpleQueryRunner into a DbExecutor.
|
|
1577
|
+
*/
|
|
1578
|
+
declare function createExecutorFromQueryRunner(runner: SimpleQueryRunner): DbExecutor;
|
|
1455
1579
|
|
|
1456
1580
|
declare enum EntityStatus {
|
|
1457
1581
|
New = "new",
|
|
@@ -1532,6 +1656,8 @@ declare class OrmContext {
|
|
|
1532
1656
|
getEntitiesForTable(table: TableDef): TrackedEntity[];
|
|
1533
1657
|
}
|
|
1534
1658
|
|
|
1659
|
+
type SelectDialectInput = Dialect | DialectKey;
|
|
1660
|
+
|
|
1535
1661
|
/**
|
|
1536
1662
|
* Main query builder class for constructing SQL SELECT queries
|
|
1537
1663
|
* @typeParam T - Result type for projections (unused)
|
|
@@ -1737,13 +1863,13 @@ declare class SelectQueryBuilder<T = any, TTable extends TableDef = TableDef> {
|
|
|
1737
1863
|
* @param dialect - Database dialect to compile for
|
|
1738
1864
|
* @returns Compiled query with SQL and parameters
|
|
1739
1865
|
*/
|
|
1740
|
-
compile(dialect:
|
|
1866
|
+
compile(dialect: SelectDialectInput): CompiledQuery;
|
|
1741
1867
|
/**
|
|
1742
1868
|
* Converts the query to SQL string for a specific dialect
|
|
1743
1869
|
* @param dialect - Database dialect to generate SQL for
|
|
1744
1870
|
* @returns SQL string representation of the query
|
|
1745
1871
|
*/
|
|
1746
|
-
toSql(dialect:
|
|
1872
|
+
toSql(dialect: SelectDialectInput): string;
|
|
1747
1873
|
/**
|
|
1748
1874
|
* Gets the hydration plan for the query
|
|
1749
1875
|
* @returns Hydration plan or undefined if none exists
|
|
@@ -1769,4 +1895,4 @@ declare const createColumn: (table: string, name: string) => ColumnNode;
|
|
|
1769
1895
|
*/
|
|
1770
1896
|
declare const createLiteral: (val: string | number) => LiteralNode;
|
|
1771
1897
|
|
|
1772
|
-
export { type
|
|
1898
|
+
export { type RawDefaultValue as $, type BelongsToManyRelation as A, type BinaryExpressionNode as B, type ColumnRef as C, Dialect as D, type ExpressionNode as E, type FunctionNode as F, type HasManyCollection as G, type HydrationPlan as H, type InExpressionNode as I, type JsonPathNode as J, type BelongsToReference as K, type LogicalExpressionNode as L, type ManyToManyCollection as M, type NullExpressionNode as N, type OperandNode as O, SelectQueryBuilder as P, type CheckConstraint as Q, type RelationMap as R, type SelectQueryNode as S, type TableRef as T, type UpdateQueryNode as U, type TableOptions as V, type WindowFunctionNode as W, type TableHooks as X, defineTable as Y, type ColumnType as Z, type ReferentialAction as _, type ColumnNode as a, type DefaultValue as a0, col as a1, RelationKinds as a2, type RelationType as a3, type CascadeMode as a4, type RelationDef as a5, hasMany as a6, hasOne as a7, belongsTo as a8, belongsToMany as a9, createExecutorFromQueryRunner as aA, type ColumnToTs as aa, type InferRow as ab, type HasOneReference as ac, createColumn as ad, createLiteral as ae, isOperandNode as af, isFunctionNode as ag, isCaseExpressionNode as ah, isWindowFunctionNode as ai, isExpressionSelectionNode as aj, type HydrationPivotPlan as ak, type HydrationRelationPlan as al, type HydrationMetadata as am, addDomainEvent as an, EntityStatus as ao, type QueryResult as ap, type RelationKey as aq, type RelationChange as ar, type HasDomainEvents as as, type OrmInterceptor as at, type DomainEventHandler as au, type OrmContextOptions as av, type QueryLogEntry as aw, type QueryLogger as ax, rowsToQueryResult as ay, type SimpleQueryRunner 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, OrmContext as v, type Entity as w, type HasManyRelation as x, type HasOneRelation as y, type BelongsToRelation as z };
|