metal-orm 1.0.11 → 1.0.13
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 +21 -18
- package/dist/decorators/index.cjs +317 -34
- package/dist/decorators/index.cjs.map +1 -1
- package/dist/decorators/index.d.cts +1 -1
- package/dist/decorators/index.d.ts +1 -1
- package/dist/decorators/index.js +317 -34
- package/dist/decorators/index.js.map +1 -1
- package/dist/index.cjs +1965 -267
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +273 -23
- package/dist/index.d.ts +273 -23
- package/dist/index.js +1947 -267
- package/dist/index.js.map +1 -1
- package/dist/{select-654m4qy8.d.cts → select-CCp1oz9p.d.cts} +254 -4
- package/dist/{select-654m4qy8.d.ts → select-CCp1oz9p.d.ts} +254 -4
- package/package.json +3 -2
- package/src/core/ast/query.ts +40 -22
- package/src/core/ddl/dialects/base-schema-dialect.ts +48 -0
- package/src/core/ddl/dialects/index.ts +5 -0
- package/src/core/ddl/dialects/mssql-schema-dialect.ts +97 -0
- package/src/core/ddl/dialects/mysql-schema-dialect.ts +109 -0
- package/src/core/ddl/dialects/postgres-schema-dialect.ts +99 -0
- package/src/core/ddl/dialects/sqlite-schema-dialect.ts +103 -0
- package/src/core/ddl/introspect/mssql.ts +149 -0
- package/src/core/ddl/introspect/mysql.ts +99 -0
- package/src/core/ddl/introspect/postgres.ts +154 -0
- package/src/core/ddl/introspect/sqlite.ts +66 -0
- package/src/core/ddl/introspect/types.ts +19 -0
- package/src/core/ddl/introspect/utils.ts +27 -0
- package/src/core/ddl/schema-diff.ts +179 -0
- package/src/core/ddl/schema-generator.ts +229 -0
- package/src/core/ddl/schema-introspect.ts +32 -0
- package/src/core/ddl/schema-types.ts +39 -0
- package/src/core/dialect/abstract.ts +122 -37
- package/src/core/dialect/base/sql-dialect.ts +204 -0
- package/src/core/dialect/mssql/index.ts +125 -80
- package/src/core/dialect/mysql/index.ts +18 -112
- package/src/core/dialect/postgres/index.ts +29 -126
- package/src/core/dialect/sqlite/index.ts +28 -129
- package/src/index.ts +4 -0
- package/src/orm/execute.ts +25 -16
- package/src/orm/orm-context.ts +60 -55
- package/src/orm/query-logger.ts +38 -0
- package/src/orm/relations/belongs-to.ts +42 -26
- package/src/orm/relations/has-many.ts +41 -25
- package/src/orm/relations/many-to-many.ts +43 -27
- package/src/orm/unit-of-work.ts +60 -23
- package/src/query-builder/hydration-manager.ts +229 -25
- package/src/query-builder/query-ast-service.ts +27 -12
- package/src/query-builder/select-query-state.ts +24 -12
- package/src/query-builder/select.ts +58 -14
- package/src/schema/column.ts +206 -27
- package/src/schema/table.ts +89 -32
- package/src/schema/types.ts +8 -5
|
@@ -1,7 +1,26 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Supported column data types for database schema definitions
|
|
3
3
|
*/
|
|
4
|
-
type ColumnType = 'INT' | 'INTEGER' | 'VARCHAR' | 'TEXT' | 'JSON' | 'ENUM' | 'BOOLEAN' | 'int' | 'integer' | 'varchar' | 'text' | 'json' | 'enum' | 'boolean';
|
|
4
|
+
type ColumnType = 'INT' | 'INTEGER' | 'BIGINT' | 'VARCHAR' | 'TEXT' | 'JSON' | 'ENUM' | 'DECIMAL' | 'FLOAT' | 'DOUBLE' | 'UUID' | 'DATE' | 'DATETIME' | 'TIMESTAMP' | 'TIMESTAMPTZ' | 'BOOLEAN' | 'int' | 'integer' | 'bigint' | 'varchar' | 'text' | 'json' | 'enum' | 'decimal' | 'float' | 'double' | 'uuid' | 'date' | 'datetime' | 'timestamp' | 'timestamptz' | 'boolean';
|
|
5
|
+
type ReferentialAction = 'NO ACTION' | 'RESTRICT' | 'CASCADE' | 'SET NULL' | 'SET DEFAULT';
|
|
6
|
+
interface RawDefaultValue {
|
|
7
|
+
raw: string;
|
|
8
|
+
}
|
|
9
|
+
type DefaultValue = unknown | RawDefaultValue;
|
|
10
|
+
interface ForeignKeyReference {
|
|
11
|
+
/** Target table name */
|
|
12
|
+
table: string;
|
|
13
|
+
/** Target column name */
|
|
14
|
+
column: string;
|
|
15
|
+
/** Optional constraint name */
|
|
16
|
+
name?: string;
|
|
17
|
+
/** ON DELETE action */
|
|
18
|
+
onDelete?: ReferentialAction;
|
|
19
|
+
/** ON UPDATE action */
|
|
20
|
+
onUpdate?: ReferentialAction;
|
|
21
|
+
/** Whether the constraint is deferrable (Postgres) */
|
|
22
|
+
deferrable?: boolean;
|
|
23
|
+
}
|
|
5
24
|
/**
|
|
6
25
|
* Definition of a database column
|
|
7
26
|
*/
|
|
@@ -14,6 +33,20 @@ interface ColumnDef<T extends ColumnType = ColumnType> {
|
|
|
14
33
|
primary?: boolean;
|
|
15
34
|
/** Whether this column cannot be null */
|
|
16
35
|
notNull?: boolean;
|
|
36
|
+
/** Whether this column must be unique (or name of the unique constraint) */
|
|
37
|
+
unique?: boolean | string;
|
|
38
|
+
/** Default value for the column */
|
|
39
|
+
default?: DefaultValue;
|
|
40
|
+
/** Whether the column auto-increments / identity */
|
|
41
|
+
autoIncrement?: boolean;
|
|
42
|
+
/** Identity strategy where supported */
|
|
43
|
+
generated?: 'always' | 'byDefault';
|
|
44
|
+
/** Inline check constraint expression */
|
|
45
|
+
check?: string;
|
|
46
|
+
/** Foreign key reference */
|
|
47
|
+
references?: ForeignKeyReference;
|
|
48
|
+
/** Column comment/description */
|
|
49
|
+
comment?: string;
|
|
17
50
|
/** Additional arguments for the column type (e.g., VARCHAR length) */
|
|
18
51
|
args?: any[];
|
|
19
52
|
/** Table name this column belongs to (filled at runtime by defineTable) */
|
|
@@ -28,12 +61,44 @@ declare const col: {
|
|
|
28
61
|
* @returns ColumnDef with INT type
|
|
29
62
|
*/
|
|
30
63
|
int: () => ColumnDef<"INT">;
|
|
64
|
+
/**
|
|
65
|
+
* Creates a big integer column definition
|
|
66
|
+
*/
|
|
67
|
+
bigint: () => ColumnDef<"BIGINT">;
|
|
31
68
|
/**
|
|
32
69
|
* Creates a variable character column definition
|
|
33
70
|
* @param length - Maximum length of the string
|
|
34
71
|
* @returns ColumnDef with VARCHAR type
|
|
35
72
|
*/
|
|
36
73
|
varchar: (length: number) => ColumnDef<"VARCHAR">;
|
|
74
|
+
/**
|
|
75
|
+
* Creates a fixed precision decimal column definition
|
|
76
|
+
*/
|
|
77
|
+
decimal: (precision: number, scale?: number) => ColumnDef<"DECIMAL">;
|
|
78
|
+
/**
|
|
79
|
+
* Creates a floating point column definition
|
|
80
|
+
*/
|
|
81
|
+
float: (precision?: number) => ColumnDef<"FLOAT">;
|
|
82
|
+
/**
|
|
83
|
+
* Creates a UUID column definition
|
|
84
|
+
*/
|
|
85
|
+
uuid: () => ColumnDef<"UUID">;
|
|
86
|
+
/**
|
|
87
|
+
* Creates a timestamp column definition
|
|
88
|
+
*/
|
|
89
|
+
timestamp: () => ColumnDef<"TIMESTAMP">;
|
|
90
|
+
/**
|
|
91
|
+
* Creates a timestamptz column definition
|
|
92
|
+
*/
|
|
93
|
+
timestamptz: () => ColumnDef<"TIMESTAMPTZ">;
|
|
94
|
+
/**
|
|
95
|
+
* Creates a date column definition
|
|
96
|
+
*/
|
|
97
|
+
date: () => ColumnDef<"DATE">;
|
|
98
|
+
/**
|
|
99
|
+
* Creates a datetime column definition
|
|
100
|
+
*/
|
|
101
|
+
datetime: () => ColumnDef<"DATETIME">;
|
|
37
102
|
/**
|
|
38
103
|
* Creates a JSON column definition
|
|
39
104
|
* @returns ColumnDef with JSON type
|
|
@@ -44,12 +109,45 @@ declare const col: {
|
|
|
44
109
|
* @returns ColumnDef with BOOLEAN type
|
|
45
110
|
*/
|
|
46
111
|
boolean: () => ColumnDef<"BOOLEAN">;
|
|
112
|
+
/**
|
|
113
|
+
* Creates an enum column definition
|
|
114
|
+
* @param values - Enum values
|
|
115
|
+
*/
|
|
116
|
+
enum: (values: string[]) => ColumnDef<"ENUM">;
|
|
47
117
|
/**
|
|
48
118
|
* Marks a column definition as a primary key
|
|
49
119
|
* @param def - Column definition to modify
|
|
50
120
|
* @returns Modified ColumnDef with primary: true
|
|
51
121
|
*/
|
|
52
122
|
primaryKey: <T extends ColumnType>(def: ColumnDef<T>) => ColumnDef<T>;
|
|
123
|
+
/**
|
|
124
|
+
* Marks a column as NOT NULL
|
|
125
|
+
*/
|
|
126
|
+
notNull: <T extends ColumnType>(def: ColumnDef<T>) => ColumnDef<T>;
|
|
127
|
+
/**
|
|
128
|
+
* Marks a column as UNIQUE
|
|
129
|
+
*/
|
|
130
|
+
unique: <T extends ColumnType>(def: ColumnDef<T>, name?: string) => ColumnDef<T>;
|
|
131
|
+
/**
|
|
132
|
+
* Sets a default value for the column
|
|
133
|
+
*/
|
|
134
|
+
default: <T extends ColumnType>(def: ColumnDef<T>, value: unknown) => ColumnDef<T>;
|
|
135
|
+
/**
|
|
136
|
+
* Sets a raw SQL default value for the column
|
|
137
|
+
*/
|
|
138
|
+
defaultRaw: <T extends ColumnType>(def: ColumnDef<T>, expression: string) => ColumnDef<T>;
|
|
139
|
+
/**
|
|
140
|
+
* Marks a column as auto-increment / identity
|
|
141
|
+
*/
|
|
142
|
+
autoIncrement: <T extends ColumnType>(def: ColumnDef<T>, strategy?: ColumnDef["generated"]) => ColumnDef<T>;
|
|
143
|
+
/**
|
|
144
|
+
* Adds a foreign key reference
|
|
145
|
+
*/
|
|
146
|
+
references: <T extends ColumnType>(def: ColumnDef<T>, ref: ForeignKeyReference) => ColumnDef<T>;
|
|
147
|
+
/**
|
|
148
|
+
* Adds a check constraint to the column
|
|
149
|
+
*/
|
|
150
|
+
check: <T extends ColumnType>(def: ColumnDef<T>, expression: string) => ColumnDef<T>;
|
|
53
151
|
};
|
|
54
152
|
|
|
55
153
|
/**
|
|
@@ -150,6 +248,31 @@ declare const belongsToMany: <TTarget extends TableDef>(target: TTarget, pivotTa
|
|
|
150
248
|
cascade?: CascadeMode;
|
|
151
249
|
}) => BelongsToManyRelation<TTarget>;
|
|
152
250
|
|
|
251
|
+
interface IndexColumn {
|
|
252
|
+
column: string;
|
|
253
|
+
order?: 'ASC' | 'DESC';
|
|
254
|
+
nulls?: 'FIRST' | 'LAST';
|
|
255
|
+
}
|
|
256
|
+
interface IndexDef {
|
|
257
|
+
name?: string;
|
|
258
|
+
columns: (string | IndexColumn)[];
|
|
259
|
+
unique?: boolean;
|
|
260
|
+
where?: string;
|
|
261
|
+
}
|
|
262
|
+
interface CheckConstraint {
|
|
263
|
+
name?: string;
|
|
264
|
+
expression: string;
|
|
265
|
+
}
|
|
266
|
+
interface TableOptions {
|
|
267
|
+
schema?: string;
|
|
268
|
+
primaryKey?: string[];
|
|
269
|
+
indexes?: IndexDef[];
|
|
270
|
+
checks?: CheckConstraint[];
|
|
271
|
+
comment?: string;
|
|
272
|
+
engine?: string;
|
|
273
|
+
charset?: string;
|
|
274
|
+
collation?: string;
|
|
275
|
+
}
|
|
153
276
|
interface TableHooks {
|
|
154
277
|
beforeInsert?(ctx: unknown, entity: any): Promise<void> | void;
|
|
155
278
|
afterInsert?(ctx: unknown, entity: any): Promise<void> | void;
|
|
@@ -165,12 +288,26 @@ interface TableHooks {
|
|
|
165
288
|
interface TableDef<T extends Record<string, ColumnDef> = Record<string, ColumnDef>> {
|
|
166
289
|
/** Name of the table */
|
|
167
290
|
name: string;
|
|
291
|
+
/** Optional schema/catalog name */
|
|
292
|
+
schema?: string;
|
|
168
293
|
/** Record of column definitions keyed by column name */
|
|
169
294
|
columns: T;
|
|
170
295
|
/** Record of relationship definitions keyed by relation name */
|
|
171
296
|
relations: Record<string, RelationDef>;
|
|
172
297
|
/** Optional lifecycle hooks */
|
|
173
298
|
hooks?: TableHooks;
|
|
299
|
+
/** Composite primary key definition (falls back to column.primary flags) */
|
|
300
|
+
primaryKey?: string[];
|
|
301
|
+
/** Secondary indexes */
|
|
302
|
+
indexes?: IndexDef[];
|
|
303
|
+
/** Table-level check constraints */
|
|
304
|
+
checks?: CheckConstraint[];
|
|
305
|
+
/** Table comment/description */
|
|
306
|
+
comment?: string;
|
|
307
|
+
/** Dialect-specific options */
|
|
308
|
+
engine?: string;
|
|
309
|
+
charset?: string;
|
|
310
|
+
collation?: string;
|
|
174
311
|
}
|
|
175
312
|
/**
|
|
176
313
|
* Creates a table definition with columns and relationships
|
|
@@ -189,12 +326,12 @@ interface TableDef<T extends Record<string, ColumnDef> = Record<string, ColumnDe
|
|
|
189
326
|
* });
|
|
190
327
|
* ```
|
|
191
328
|
*/
|
|
192
|
-
declare const defineTable: <T extends Record<string, ColumnDef>>(name: string, columns: T, relations?: Record<string, RelationDef>, hooks?: TableHooks) => TableDef<T>;
|
|
329
|
+
declare const defineTable: <T extends Record<string, ColumnDef>>(name: string, columns: T, relations?: Record<string, RelationDef>, hooks?: TableHooks, options?: TableOptions) => TableDef<T>;
|
|
193
330
|
|
|
194
331
|
/**
|
|
195
332
|
* Maps a ColumnDef to its TypeScript type representation
|
|
196
333
|
*/
|
|
197
|
-
type ColumnToTs<T extends ColumnDef> = T['type'] extends 'INT' | 'INTEGER' | 'int' | 'integer' ? number : T['type'] extends 'BOOLEAN' | 'boolean' ? boolean : T['type'] extends 'JSON' | 'json' ? unknown : string;
|
|
334
|
+
type ColumnToTs<T extends ColumnDef> = T['type'] extends 'INT' | 'INTEGER' | 'int' | 'integer' ? number : T['type'] extends 'BIGINT' | 'bigint' ? number | bigint : T['type'] extends 'DECIMAL' | 'decimal' | 'FLOAT' | 'float' | 'DOUBLE' | 'double' ? number : T['type'] extends 'BOOLEAN' | 'boolean' ? boolean : T['type'] extends 'JSON' | 'json' ? unknown : T['type'] extends 'DATE' | 'date' | 'DATETIME' | 'datetime' | 'TIMESTAMP' | 'timestamp' | 'TIMESTAMPTZ' | 'timestamptz' ? string : string;
|
|
198
335
|
/**
|
|
199
336
|
* Infers a row shape from a table definition
|
|
200
337
|
*/
|
|
@@ -584,6 +721,20 @@ interface CommonTableExpressionNode {
|
|
|
584
721
|
/** Whether the CTE is recursive */
|
|
585
722
|
recursive: boolean;
|
|
586
723
|
}
|
|
724
|
+
/**
|
|
725
|
+
* Supported set operation kinds for compound SELECT queries
|
|
726
|
+
*/
|
|
727
|
+
type SetOperationKind = 'UNION' | 'UNION ALL' | 'INTERSECT' | 'EXCEPT';
|
|
728
|
+
/**
|
|
729
|
+
* AST node representing a set operation (UNION, INTERSECT, etc.)
|
|
730
|
+
*/
|
|
731
|
+
interface SetOperationNode {
|
|
732
|
+
type: 'SetOperation';
|
|
733
|
+
/** Operator to combine queries */
|
|
734
|
+
operator: SetOperationKind;
|
|
735
|
+
/** Right-hand query in the compound expression */
|
|
736
|
+
query: SelectQueryNode;
|
|
737
|
+
}
|
|
587
738
|
/**
|
|
588
739
|
* AST node representing a complete SELECT query
|
|
589
740
|
*/
|
|
@@ -613,6 +764,8 @@ interface SelectQueryNode {
|
|
|
613
764
|
meta?: QueryMetadata;
|
|
614
765
|
/** Optional DISTINCT clause */
|
|
615
766
|
distinct?: ColumnNode[];
|
|
767
|
+
/** Optional set operations chaining this query with others */
|
|
768
|
+
setOps?: SetOperationNode[];
|
|
616
769
|
}
|
|
617
770
|
interface InsertQueryNode {
|
|
618
771
|
type: 'InsertQuery';
|
|
@@ -695,6 +848,7 @@ declare abstract class Dialect implements SelectCompiler, InsertCompiler, Update
|
|
|
695
848
|
compileInsert(ast: InsertQueryNode): CompiledQuery;
|
|
696
849
|
compileUpdate(ast: UpdateQueryNode): CompiledQuery;
|
|
697
850
|
compileDelete(ast: DeleteQueryNode): CompiledQuery;
|
|
851
|
+
supportsReturning(): boolean;
|
|
698
852
|
/**
|
|
699
853
|
* Compiles SELECT query AST to SQL (to be implemented by concrete dialects)
|
|
700
854
|
* @param ast - Query AST
|
|
@@ -740,6 +894,31 @@ declare abstract class Dialect implements SelectCompiler, InsertCompiler, Update
|
|
|
740
894
|
* @returns Formatted placeholder string
|
|
741
895
|
*/
|
|
742
896
|
protected formatPlaceholder(index: number): string;
|
|
897
|
+
/**
|
|
898
|
+
* Whether the current dialect supports a given set operation.
|
|
899
|
+
* Override in concrete dialects to restrict support.
|
|
900
|
+
*/
|
|
901
|
+
protected supportsSetOperation(kind: SetOperationKind): boolean;
|
|
902
|
+
/**
|
|
903
|
+
* Validates set-operation semantics:
|
|
904
|
+
* - Ensures the dialect supports requested operators.
|
|
905
|
+
* - Enforces that only the outermost compound query may have ORDER/LIMIT/OFFSET.
|
|
906
|
+
* @param ast - Query to validate
|
|
907
|
+
* @param isOutermost - Whether this node is the outermost compound query
|
|
908
|
+
*/
|
|
909
|
+
protected validateSetOperations(ast: SelectQueryNode, isOutermost?: boolean): void;
|
|
910
|
+
/**
|
|
911
|
+
* Hoists CTEs from set-operation operands to the outermost query so WITH appears once.
|
|
912
|
+
* @param ast - Query AST
|
|
913
|
+
* @returns Normalized AST without inner CTEs and a list of hoisted CTEs
|
|
914
|
+
*/
|
|
915
|
+
private hoistCtes;
|
|
916
|
+
/**
|
|
917
|
+
* Normalizes a SELECT AST before compilation (validation + CTE hoisting).
|
|
918
|
+
* @param ast - Query AST
|
|
919
|
+
* @returns Normalized query AST
|
|
920
|
+
*/
|
|
921
|
+
protected normalizeSelectAst(ast: SelectQueryNode): SelectQueryNode;
|
|
743
922
|
private readonly expressionCompilers;
|
|
744
923
|
private readonly operandCompilers;
|
|
745
924
|
protected constructor();
|
|
@@ -862,6 +1041,12 @@ declare class SelectQueryState {
|
|
|
862
1041
|
* @returns New SelectQueryState with CTE
|
|
863
1042
|
*/
|
|
864
1043
|
withCte(cte: CommonTableExpressionNode): SelectQueryState;
|
|
1044
|
+
/**
|
|
1045
|
+
* Adds a set operation (UNION/INTERSECT/EXCEPT) to the query
|
|
1046
|
+
* @param op - Set operation node to add
|
|
1047
|
+
* @returns New SelectQueryState with set operation
|
|
1048
|
+
*/
|
|
1049
|
+
withSetOperation(op: SetOperationNode): SelectQueryState;
|
|
865
1050
|
}
|
|
866
1051
|
|
|
867
1052
|
/**
|
|
@@ -964,6 +1149,31 @@ declare class HydrationManager {
|
|
|
964
1149
|
* @returns Hydration plan or undefined if none exists
|
|
965
1150
|
*/
|
|
966
1151
|
getPlan(): HydrationPlan | undefined;
|
|
1152
|
+
/**
|
|
1153
|
+
* Attaches hydration metadata to a query AST node.
|
|
1154
|
+
*/
|
|
1155
|
+
private attachHydrationMeta;
|
|
1156
|
+
/**
|
|
1157
|
+
* Determines whether the query needs pagination rewriting to keep LIMIT/OFFSET
|
|
1158
|
+
* applied to parent rows when eager-loading multiplicative relations.
|
|
1159
|
+
*/
|
|
1160
|
+
private requiresParentPagination;
|
|
1161
|
+
private hasMultiplyingRelations;
|
|
1162
|
+
/**
|
|
1163
|
+
* Rewrites the query using CTEs so LIMIT/OFFSET target distinct parent rows
|
|
1164
|
+
* instead of the joined result set.
|
|
1165
|
+
*
|
|
1166
|
+
* The strategy:
|
|
1167
|
+
* - Hoist the original query (minus limit/offset) into a base CTE.
|
|
1168
|
+
* - Select distinct parent ids from that base CTE with the original ordering and pagination.
|
|
1169
|
+
* - Join the base CTE against the paged ids to retrieve the joined rows for just that page.
|
|
1170
|
+
*/
|
|
1171
|
+
private wrapForParentPagination;
|
|
1172
|
+
private nextCteName;
|
|
1173
|
+
private getProjectionNames;
|
|
1174
|
+
private buildProjectionAliasMap;
|
|
1175
|
+
private mapOrderBy;
|
|
1176
|
+
private buildPagingColumns;
|
|
967
1177
|
}
|
|
968
1178
|
|
|
969
1179
|
/**
|
|
@@ -1012,6 +1222,13 @@ declare class QueryAstService {
|
|
|
1012
1222
|
* @returns Updated query state with CTE
|
|
1013
1223
|
*/
|
|
1014
1224
|
withCte(name: string, query: SelectQueryNode, columns?: string[], recursive?: boolean): SelectQueryState;
|
|
1225
|
+
/**
|
|
1226
|
+
* Adds a set operation (UNION/UNION ALL/INTERSECT/EXCEPT) to the query
|
|
1227
|
+
* @param operator - Set operator
|
|
1228
|
+
* @param query - Right-hand side query
|
|
1229
|
+
* @returns Updated query state with set operation
|
|
1230
|
+
*/
|
|
1231
|
+
withSetOperation(operator: SetOperationKind, query: SelectQueryNode): SelectQueryState;
|
|
1015
1232
|
/**
|
|
1016
1233
|
* Selects a subquery as a column
|
|
1017
1234
|
* @param alias - Alias for the subquery
|
|
@@ -1271,6 +1488,12 @@ interface HasDomainEvents {
|
|
|
1271
1488
|
type DomainEventHandler$1<Context> = (event: any, ctx: Context) => Promise<void> | void;
|
|
1272
1489
|
declare const addDomainEvent: (entity: HasDomainEvents, event: any) => void;
|
|
1273
1490
|
|
|
1491
|
+
interface QueryLogEntry {
|
|
1492
|
+
sql: string;
|
|
1493
|
+
params?: unknown[];
|
|
1494
|
+
}
|
|
1495
|
+
type QueryLogger = (entry: QueryLogEntry) => void;
|
|
1496
|
+
|
|
1274
1497
|
interface OrmInterceptor {
|
|
1275
1498
|
beforeFlush?(ctx: OrmContext): Promise<void> | void;
|
|
1276
1499
|
afterFlush?(ctx: OrmContext): Promise<void> | void;
|
|
@@ -1281,10 +1504,12 @@ interface OrmContextOptions {
|
|
|
1281
1504
|
executor: DbExecutor;
|
|
1282
1505
|
interceptors?: OrmInterceptor[];
|
|
1283
1506
|
domainEventHandlers?: Record<string, DomainEventHandler[]>;
|
|
1507
|
+
queryLogger?: QueryLogger;
|
|
1284
1508
|
}
|
|
1285
1509
|
declare class OrmContext {
|
|
1286
1510
|
private readonly options;
|
|
1287
1511
|
private readonly identityMap;
|
|
1512
|
+
private readonly executorWithLogging;
|
|
1288
1513
|
private readonly unitOfWork;
|
|
1289
1514
|
private readonly relationChanges;
|
|
1290
1515
|
private readonly interceptors;
|
|
@@ -1331,6 +1556,7 @@ declare class SelectQueryBuilder<T = any, TTable extends TableDef = TableDef> {
|
|
|
1331
1556
|
private createChildBuilder;
|
|
1332
1557
|
private applyAst;
|
|
1333
1558
|
private applyJoin;
|
|
1559
|
+
private applySetOperation;
|
|
1334
1560
|
/**
|
|
1335
1561
|
* Selects specific columns for the query
|
|
1336
1562
|
* @param columns - Record of column definitions, function nodes, case expressions, or window functions
|
|
@@ -1456,6 +1682,30 @@ declare class SelectQueryBuilder<T = any, TTable extends TableDef = TableDef> {
|
|
|
1456
1682
|
* @returns New query builder instance with the OFFSET clause
|
|
1457
1683
|
*/
|
|
1458
1684
|
offset(n: number): SelectQueryBuilder<T, TTable>;
|
|
1685
|
+
/**
|
|
1686
|
+
* Combines this query with another using UNION
|
|
1687
|
+
* @param query - Query to union with
|
|
1688
|
+
* @returns New query builder instance with the set operation
|
|
1689
|
+
*/
|
|
1690
|
+
union(query: SelectQueryBuilder<any, TableDef<any>> | SelectQueryNode): SelectQueryBuilder<T, TTable>;
|
|
1691
|
+
/**
|
|
1692
|
+
* Combines this query with another using UNION ALL
|
|
1693
|
+
* @param query - Query to union with
|
|
1694
|
+
* @returns New query builder instance with the set operation
|
|
1695
|
+
*/
|
|
1696
|
+
unionAll(query: SelectQueryBuilder<any, TableDef<any>> | SelectQueryNode): SelectQueryBuilder<T, TTable>;
|
|
1697
|
+
/**
|
|
1698
|
+
* Combines this query with another using INTERSECT
|
|
1699
|
+
* @param query - Query to intersect with
|
|
1700
|
+
* @returns New query builder instance with the set operation
|
|
1701
|
+
*/
|
|
1702
|
+
intersect(query: SelectQueryBuilder<any, TableDef<any>> | SelectQueryNode): SelectQueryBuilder<T, TTable>;
|
|
1703
|
+
/**
|
|
1704
|
+
* Combines this query with another using EXCEPT
|
|
1705
|
+
* @param query - Query to subtract
|
|
1706
|
+
* @returns New query builder instance with the set operation
|
|
1707
|
+
*/
|
|
1708
|
+
except(query: SelectQueryBuilder<any, TableDef<any>> | SelectQueryNode): SelectQueryBuilder<T, TTable>;
|
|
1459
1709
|
/**
|
|
1460
1710
|
* Adds a WHERE EXISTS condition to the query
|
|
1461
1711
|
* @param subquery - Subquery to check for existence
|
|
@@ -1519,4 +1769,4 @@ declare const createColumn: (table: string, name: string) => ColumnNode;
|
|
|
1519
1769
|
*/
|
|
1520
1770
|
declare const createLiteral: (val: string | number) => LiteralNode;
|
|
1521
1771
|
|
|
1522
|
-
export {
|
|
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 };
|