metal-orm 1.0.16 → 1.0.18
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 +37 -40
- package/dist/decorators/index.cjs +344 -69
- 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 +344 -69
- package/dist/decorators/index.js.map +1 -1
- package/dist/index.cjs +567 -181
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +66 -30
- package/dist/index.d.ts +66 -30
- package/dist/index.js +559 -181
- package/dist/index.js.map +1 -1
- package/dist/{select-BKZrMRCQ.d.cts → select-BuMpVcVt.d.cts} +265 -74
- package/dist/{select-BKZrMRCQ.d.ts → select-BuMpVcVt.d.ts} +265 -74
- package/package.json +5 -1
- package/src/codegen/naming-strategy.ts +15 -10
- package/src/core/ast/aggregate-functions.ts +50 -4
- package/src/core/ast/builders.ts +23 -3
- package/src/core/ast/expression-builders.ts +36 -16
- package/src/core/ast/expression-nodes.ts +17 -9
- package/src/core/ast/join-node.ts +5 -3
- package/src/core/ast/join.ts +16 -16
- package/src/core/ast/query.ts +44 -29
- package/src/core/ddl/dialects/mssql-schema-dialect.ts +18 -0
- package/src/core/ddl/dialects/mysql-schema-dialect.ts +11 -0
- package/src/core/ddl/dialects/postgres-schema-dialect.ts +9 -0
- package/src/core/ddl/dialects/sqlite-schema-dialect.ts +9 -0
- package/src/core/ddl/introspect/functions/postgres.ts +2 -6
- package/src/core/dialect/abstract.ts +12 -8
- package/src/core/dialect/base/sql-dialect.ts +58 -46
- package/src/core/dialect/mssql/functions.ts +24 -15
- package/src/core/dialect/mssql/index.ts +53 -28
- package/src/core/dialect/postgres/functions.ts +33 -24
- package/src/core/dialect/sqlite/functions.ts +19 -12
- package/src/core/dialect/sqlite/index.ts +22 -13
- package/src/core/functions/datetime.ts +2 -1
- package/src/core/functions/numeric.ts +2 -1
- package/src/core/functions/standard-strategy.ts +52 -12
- package/src/core/functions/text.ts +2 -1
- package/src/core/functions/types.ts +8 -8
- package/src/index.ts +5 -4
- package/src/orm/domain-event-bus.ts +43 -25
- package/src/orm/entity-meta.ts +40 -0
- package/src/orm/execution-context.ts +6 -0
- package/src/orm/hydration-context.ts +6 -4
- package/src/orm/orm-session.ts +35 -24
- package/src/orm/orm.ts +10 -10
- package/src/orm/query-logger.ts +15 -0
- package/src/orm/runtime-types.ts +60 -2
- package/src/orm/transaction-runner.ts +7 -0
- package/src/orm/unit-of-work.ts +1 -0
- package/src/query-builder/column-selector.ts +9 -7
- package/src/query-builder/insert-query-state.ts +13 -3
- package/src/query-builder/query-ast-service.ts +59 -38
- package/src/query-builder/relation-conditions.ts +38 -34
- package/src/query-builder/relation-manager.ts +8 -3
- package/src/query-builder/relation-service.ts +59 -46
- package/src/query-builder/select-helpers.ts +50 -0
- package/src/query-builder/select-query-state.ts +19 -7
- package/src/query-builder/select.ts +339 -167
- package/src/query-builder/update-query-state.ts +31 -9
- package/src/schema/column.ts +75 -39
- package/src/schema/types.ts +17 -6
package/dist/index.d.cts
CHANGED
|
@@ -1,13 +1,25 @@
|
|
|
1
|
-
import { O as OperandNode, C as ColumnRef, a as ColumnNode, B as BinaryExpressionNode, E as ExpressionNode,
|
|
2
|
-
export {
|
|
1
|
+
import { L as LiteralNode, O as OperandNode, C as ColumnRef, a as ColumnNode, B as BinaryExpressionNode, E as ExpressionNode, b as LogicalExpressionNode, N as NullExpressionNode, I as InExpressionNode, c as BetweenExpressionNode, J as JsonPathNode, d as CaseExpressionNode, S as SelectQueryNode, e as ExistsExpressionNode, W as WindowFunctionNode, f as OrderDirection, F as FunctionNode, g as ScalarSubqueryNode, h as ColumnDef, T as TableRef, i as TableDef, j as InsertQueryNode, k as InsertCompiler, l as CompiledQuery, D as Dialect, m as DialectKey, U as UpdateQueryNode, n as UpdateCompiler, o as DeleteQueryNode, p as DeleteCompiler, q as CompilerContext, r as FunctionTableNode, s as DerivedTableNode, t as TableSourceNode, u as ForeignKeyReference, v as IndexColumn, w as IndexDef, x as DbExecutor, H as HydrationPlan, y as NamingStrategy, R as RelationMap, z as EntityContext, A as Entity, G as HasManyRelation, K as HasOneRelation, M as BelongsToRelation, P as BelongsToManyRelation, Q as HasManyCollection, V as BelongsToReference, X as ManyToManyCollection, Y as OrmSession, Z as SelectQueryBuilder, _ as ExecutionContext, $ as HydrationContext } from './select-BuMpVcVt.cjs';
|
|
2
|
+
export { aL as AnyDomainEvent, ab as CascadeMode, a0 as CheckConstraint, ai as ColumnToTs, a4 as ColumnType, ay as DbExecutorFactory, a7 as DefaultValue, aK as DomainEvent, aD as DomainEventBus, aB as DomainEventHandler, aF as EntityStatus, az as ExternalTransaction, aN as HasDomainEvents, ak as HasOneReference, au as HydrationMetadata, as as HydrationPivotPlan, at as HydrationRelationPlan, aj as InferRow, aC as InitialHandlers, aA as Orm, aM as OrmDomainEvent, av as OrmInterceptor, ax as OrmOptions, aw as OrmSessionOptions, aO as QueryLogEntry, aP as QueryLogger, aR as QueryResult, a6 as RawDefaultValue, a5 as ReferentialAction, aI as RelationChange, aJ as RelationChangeEntry, ac as RelationDef, aH as RelationKey, a9 as RelationKinds, ah as RelationTargetTable, aa as RelationType, aT as SimpleQueryRunner, a2 as TableHooks, a1 as TableOptions, aG as TrackedEntity, aE as addDomainEvent, af as belongsTo, ag as belongsToMany, a8 as col, al as createColumn, aU as createExecutorFromQueryRunner, am as createLiteral, aQ as createQueryLoggingExecutor, a3 as defineTable, ad as hasMany, ae as hasOne, ap as isCaseExpressionNode, ar as isExpressionSelectionNode, ao as isFunctionNode, an as isOperandNode, aq as isWindowFunctionNode, aS as rowsToQueryResult } from './select-BuMpVcVt.cjs';
|
|
3
3
|
|
|
4
|
+
type LiteralValue = LiteralNode['value'];
|
|
5
|
+
type ValueOperandInput = OperandNode | LiteralValue;
|
|
4
6
|
/**
|
|
5
7
|
* Converts a primitive or existing operand into an operand node
|
|
6
8
|
* @param value - Value or operand to normalize
|
|
7
9
|
* @returns OperandNode representing the value
|
|
8
10
|
*/
|
|
9
|
-
declare const valueToOperand: (value:
|
|
11
|
+
declare const valueToOperand: (value: ValueOperandInput) => OperandNode;
|
|
12
|
+
declare const isValueOperandInput: (value: unknown) => value is ValueOperandInput;
|
|
10
13
|
declare const columnOperand: (col: ColumnRef | ColumnNode) => ColumnNode;
|
|
14
|
+
/**
|
|
15
|
+
* Marks a column reference as an outer-scope reference for correlated subqueries.
|
|
16
|
+
* Primarily semantic; SQL rendering still uses the provided table/alias name.
|
|
17
|
+
*/
|
|
18
|
+
declare const outerRef: (col: ColumnRef | ColumnNode) => ColumnNode;
|
|
19
|
+
/**
|
|
20
|
+
* Creates an outer-scoped column reference using a specific table or alias name.
|
|
21
|
+
*/
|
|
22
|
+
declare const correlateBy: (table: string, column: string) => ColumnNode;
|
|
11
23
|
/**
|
|
12
24
|
* Creates an equality expression (left = right)
|
|
13
25
|
* @param left - Left operand
|
|
@@ -221,6 +233,30 @@ declare const sum: (col: ColumnRef | ColumnNode) => FunctionNode;
|
|
|
221
233
|
* @returns Function node with AVG
|
|
222
234
|
*/
|
|
223
235
|
declare const avg: (col: ColumnRef | ColumnNode) => FunctionNode;
|
|
236
|
+
/**
|
|
237
|
+
* Creates a MIN function expression
|
|
238
|
+
* @param col - Column to take the minimum of
|
|
239
|
+
* @returns Function node with MIN
|
|
240
|
+
*/
|
|
241
|
+
declare const min: (col: ColumnRef | ColumnNode) => FunctionNode;
|
|
242
|
+
/**
|
|
243
|
+
* Creates a MAX function expression
|
|
244
|
+
* @param col - Column to take the maximum of
|
|
245
|
+
* @returns Function node with MAX
|
|
246
|
+
*/
|
|
247
|
+
declare const max: (col: ColumnRef | ColumnNode) => FunctionNode;
|
|
248
|
+
type GroupConcatOrderByInput = {
|
|
249
|
+
column: ColumnRef | ColumnNode;
|
|
250
|
+
direction?: OrderDirection;
|
|
251
|
+
};
|
|
252
|
+
type GroupConcatOptions = {
|
|
253
|
+
separator?: ValueOperandInput;
|
|
254
|
+
orderBy?: GroupConcatOrderByInput[];
|
|
255
|
+
};
|
|
256
|
+
/**
|
|
257
|
+
* Aggregates grouped strings into a single value.
|
|
258
|
+
*/
|
|
259
|
+
declare const groupConcat: (col: ColumnRef | ColumnNode, options?: GroupConcatOptions) => FunctionNode;
|
|
224
260
|
|
|
225
261
|
/**
|
|
226
262
|
* Visitor for expression nodes
|
|
@@ -286,6 +322,18 @@ declare const toColumnRef: (col: ColumnRef | ColumnDef) => ColumnRef;
|
|
|
286
322
|
*/
|
|
287
323
|
declare const toTableRef: (table: TableRef | TableDef) => TableRef;
|
|
288
324
|
|
|
325
|
+
/**
|
|
326
|
+
* Build a typed selection map from a TableDef.
|
|
327
|
+
*/
|
|
328
|
+
declare function sel<TTable extends TableDef, K extends keyof TTable['columns'] & string>(table: TTable, ...cols: K[]): Record<K, TTable['columns'][K]>;
|
|
329
|
+
type Ctor<T> = {
|
|
330
|
+
new (...args: any[]): T;
|
|
331
|
+
};
|
|
332
|
+
/**
|
|
333
|
+
* Build a typed selection map from an entity constructor.
|
|
334
|
+
*/
|
|
335
|
+
declare function esel<TEntity, K extends keyof TEntity & string>(entity: Ctor<TEntity>, ...props: K[]): Record<K, ColumnDef>;
|
|
336
|
+
|
|
289
337
|
/**
|
|
290
338
|
* Maintains immutable state for building INSERT queries
|
|
291
339
|
*/
|
|
@@ -375,27 +423,6 @@ declare class DeleteQueryBuilder<T> {
|
|
|
375
423
|
getAST(): DeleteQueryNode;
|
|
376
424
|
}
|
|
377
425
|
|
|
378
|
-
interface FunctionTableNode {
|
|
379
|
-
type: 'FunctionTable';
|
|
380
|
-
schema?: string;
|
|
381
|
-
name: string;
|
|
382
|
-
args?: unknown[];
|
|
383
|
-
lateral?: boolean;
|
|
384
|
-
withOrdinality?: boolean;
|
|
385
|
-
alias?: string;
|
|
386
|
-
columnAliases?: string[];
|
|
387
|
-
}
|
|
388
|
-
interface FunctionTableNode {
|
|
389
|
-
type: 'FunctionTable';
|
|
390
|
-
schema?: string;
|
|
391
|
-
name: string;
|
|
392
|
-
args?: unknown[];
|
|
393
|
-
lateral?: boolean;
|
|
394
|
-
withOrdinality?: boolean;
|
|
395
|
-
alias?: string;
|
|
396
|
-
columnAliases?: string[];
|
|
397
|
-
}
|
|
398
|
-
|
|
399
426
|
/**
|
|
400
427
|
* Strategy interface for compiling pagination clauses.
|
|
401
428
|
* Allows dialects to customize how pagination (LIMIT/OFFSET, ROWS FETCH, etc.) is generated.
|
|
@@ -451,6 +478,7 @@ declare abstract class SqlDialectBase extends Dialect {
|
|
|
451
478
|
protected compileSelectColumns(ast: SelectQueryNode, ctx: CompilerContext): string;
|
|
452
479
|
protected compileFrom(ast: SelectQueryNode['from'], ctx?: CompilerContext): string;
|
|
453
480
|
protected compileFunctionTable(fn: FunctionTableNode, ctx?: CompilerContext): string;
|
|
481
|
+
protected compileDerivedTable(table: DerivedTableNode, ctx?: CompilerContext): string;
|
|
454
482
|
protected compileTableSource(table: TableSourceNode): string;
|
|
455
483
|
protected compileTableName(table: {
|
|
456
484
|
name: string;
|
|
@@ -460,11 +488,6 @@ declare abstract class SqlDialectBase extends Dialect {
|
|
|
460
488
|
protected stripTrailingSemicolon(sql: string): string;
|
|
461
489
|
protected wrapSetOperand(sql: string): string;
|
|
462
490
|
}
|
|
463
|
-
interface TableSourceNode {
|
|
464
|
-
name: string;
|
|
465
|
-
schema?: string;
|
|
466
|
-
alias?: string;
|
|
467
|
-
}
|
|
468
491
|
|
|
469
492
|
/**
|
|
470
493
|
* MySQL dialect implementation
|
|
@@ -529,6 +552,8 @@ declare class SqlServerDialect extends Dialect {
|
|
|
529
552
|
private compileSelectCore;
|
|
530
553
|
private compileOrderBy;
|
|
531
554
|
private compilePagination;
|
|
555
|
+
private compileTableSource;
|
|
556
|
+
private compileDerivedTable;
|
|
532
557
|
private compileCtes;
|
|
533
558
|
private wrapSetOperand;
|
|
534
559
|
}
|
|
@@ -555,6 +580,7 @@ declare class SqliteDialect extends SqlDialectBase {
|
|
|
555
580
|
*/
|
|
556
581
|
protected compileJsonPath(node: JsonPathNode): string;
|
|
557
582
|
protected compileReturning(returning: ColumnNode[] | undefined, ctx: CompilerContext): string;
|
|
583
|
+
protected formatReturningColumns(returning: ColumnNode[]): string;
|
|
558
584
|
supportsReturning(): boolean;
|
|
559
585
|
}
|
|
560
586
|
|
|
@@ -1181,12 +1207,22 @@ declare const loadHasOneRelation: (ctx: EntityContext, rootTable: TableDef, _rel
|
|
|
1181
1207
|
declare const loadBelongsToRelation: (ctx: EntityContext, rootTable: TableDef, _relationName: string, relation: BelongsToRelation) => Promise<Map<string, Record<string, any>>>;
|
|
1182
1208
|
declare const loadBelongsToManyRelation: (ctx: EntityContext, rootTable: TableDef, _relationName: string, relation: BelongsToManyRelation) => Promise<Map<string, Rows$3>>;
|
|
1183
1209
|
|
|
1210
|
+
/**
|
|
1211
|
+
* Metadata stored on entity instances for ORM internal use
|
|
1212
|
+
* @typeParam TTable - Table definition type
|
|
1213
|
+
*/
|
|
1184
1214
|
interface EntityMeta<TTable extends TableDef> {
|
|
1215
|
+
/** Entity context */
|
|
1185
1216
|
ctx: EntityContext;
|
|
1217
|
+
/** Table definition */
|
|
1186
1218
|
table: TTable;
|
|
1219
|
+
/** Relations that should be loaded lazily */
|
|
1187
1220
|
lazyRelations: (keyof RelationMap<TTable>)[];
|
|
1221
|
+
/** Cache for relation promises */
|
|
1188
1222
|
relationCache: Map<string, Promise<any>>;
|
|
1223
|
+
/** Hydration data for relations */
|
|
1189
1224
|
relationHydration: Map<string, Map<string, any>>;
|
|
1225
|
+
/** Relation wrapper instances */
|
|
1190
1226
|
relationWrappers: Map<string, unknown>;
|
|
1191
1227
|
}
|
|
1192
1228
|
|
|
@@ -1303,4 +1339,4 @@ interface MssqlClientLike {
|
|
|
1303
1339
|
}
|
|
1304
1340
|
declare function createMssqlExecutor(client: MssqlClientLike): DbExecutor;
|
|
1305
1341
|
|
|
1306
|
-
export { AsyncLocalStorage, BelongsToManyRelation, BelongsToReference, BelongsToRelation, BetweenExpressionNode, BinaryExpressionNode, CaseExpressionNode, ColumnDef, type ColumnDiff, ColumnNode, ColumnRef, type DatabaseCheck, type DatabaseColumn, type DatabaseIndex, type DatabaseSchema, type DatabaseTable, DbExecutor, DefaultBelongsToReference, DefaultHasManyCollection, DefaultManyToManyCollection, DeleteQueryBuilder, type DialectName, Entity, EntityContext, ExecutionContext, ExistsExpressionNode, ExpressionNode, type ExpressionVisitor, ForeignKeyReference, FunctionNode, HasManyCollection, HasManyRelation, HasOneRelation, HydrationContext, HydrationPlan, InExpressionNode, IndexColumn, IndexDef, InsertQueryBuilder, type IntrospectOptions, JsonPathNode, LiteralNode, LogicalExpressionNode, ManyToManyCollection, type MssqlClientLike, MySqlDialect, type MysqlClientLike, NullExpressionNode, OperandNode, type OperandVisitor, OrmSession, type PostgresClientLike, PostgresDialect, RelationMap, type RenderColumnOptions, ScalarSubqueryNode, type SchemaChange, type SchemaChangeKind, type SchemaDiffOptions, type SchemaGenerateResult, type SchemaIntrospector, type SchemaPlan, SelectQueryBuilder, SqlServerDialect, type SqliteClientLike, SqliteDialect, type SynchronizeOptions, TableDef, TableRef, TypeScriptGenerator, UpdateQueryBuilder, WindowFunctionNode, abs, acos, and, ascii, asin, atan, atan2, avg, between, caseWhen, ceil, ceiling, char, charLength, clearExpressionDispatchers, clearOperandDispatchers, columnOperand, concat, concatWs, cos, cot, count, createEntityFromRow, createEntityProxy, createMssqlExecutor, createMysqlExecutor, createPostgresExecutor, createSqliteExecutor, currentDate, currentTime, dateAdd, dateDiff, dateFormat, dateSub, dateTrunc, day, dayOfWeek, degrees, denseRank, diffSchema, endOfMonth, eq, executeHydrated, executeHydratedWithContexts, exists, exp, extract, firstValue, floor, fromUnixTime, generateCreateTableSql, generateSchemaSql, getSchemaIntrospector, gt, gte, hydrateRows, inList, instr, introspectSchema, isNotNull, isNull, jsonPath, lag, lastValue, lead, left, length, like, ln, loadBelongsToManyRelation, loadBelongsToRelation, loadHasManyRelation, loadHasOneRelation, locate, log, log10, logBase, lower, lpad, lt, lte, ltrim, mod, month, neq, notBetween, notExists, notInList, notLike, now, ntile, or, pi, position, pow, power, radians, rand, random, rank, registerExpressionDispatcher, registerOperandDispatcher, registerSchemaIntrospector, renderColumnDefinition, repeat, replace, right, round, rowNumber, rpad, rtrim, sign, sin, space, sqrt, substr, sum, synchronizeSchema, tan, toColumnRef, toTableRef, trim, trunc, truncate, unixTimestamp, upper, utcNow, valueToOperand, visitExpression, visitOperand, weekOfYear, windowFunction, year };
|
|
1342
|
+
export { AsyncLocalStorage, BelongsToManyRelation, BelongsToReference, BelongsToRelation, BetweenExpressionNode, BinaryExpressionNode, CaseExpressionNode, ColumnDef, type ColumnDiff, ColumnNode, ColumnRef, type DatabaseCheck, type DatabaseColumn, type DatabaseIndex, type DatabaseSchema, type DatabaseTable, DbExecutor, DefaultBelongsToReference, DefaultHasManyCollection, DefaultManyToManyCollection, DeleteQueryBuilder, type DialectName, Entity, EntityContext, ExecutionContext, ExistsExpressionNode, ExpressionNode, type ExpressionVisitor, ForeignKeyReference, FunctionNode, type GroupConcatOptions, HasManyCollection, HasManyRelation, HasOneRelation, HydrationContext, HydrationPlan, InExpressionNode, IndexColumn, IndexDef, InsertQueryBuilder, type IntrospectOptions, JsonPathNode, LiteralNode, type LiteralValue, LogicalExpressionNode, ManyToManyCollection, type MssqlClientLike, MySqlDialect, type MysqlClientLike, NullExpressionNode, OperandNode, type OperandVisitor, OrmSession, type PostgresClientLike, PostgresDialect, RelationMap, type RenderColumnOptions, ScalarSubqueryNode, type SchemaChange, type SchemaChangeKind, type SchemaDiffOptions, type SchemaGenerateResult, type SchemaIntrospector, type SchemaPlan, SelectQueryBuilder, SqlServerDialect, type SqliteClientLike, SqliteDialect, type SynchronizeOptions, TableDef, TableRef, TypeScriptGenerator, UpdateQueryBuilder, type ValueOperandInput, WindowFunctionNode, abs, acos, and, ascii, asin, atan, atan2, avg, between, caseWhen, ceil, ceiling, char, charLength, clearExpressionDispatchers, clearOperandDispatchers, columnOperand, concat, concatWs, correlateBy, cos, cot, count, createEntityFromRow, createEntityProxy, createMssqlExecutor, createMysqlExecutor, createPostgresExecutor, createSqliteExecutor, currentDate, currentTime, dateAdd, dateDiff, dateFormat, dateSub, dateTrunc, day, dayOfWeek, degrees, denseRank, diffSchema, endOfMonth, eq, esel, executeHydrated, executeHydratedWithContexts, exists, exp, extract, firstValue, floor, fromUnixTime, generateCreateTableSql, generateSchemaSql, getSchemaIntrospector, groupConcat, gt, gte, hydrateRows, inList, instr, introspectSchema, isNotNull, isNull, isValueOperandInput, jsonPath, lag, lastValue, lead, left, length, like, ln, loadBelongsToManyRelation, loadBelongsToRelation, loadHasManyRelation, loadHasOneRelation, locate, log, log10, logBase, lower, lpad, lt, lte, ltrim, max, min, mod, month, neq, notBetween, notExists, notInList, notLike, now, ntile, or, outerRef, pi, position, pow, power, radians, rand, random, rank, registerExpressionDispatcher, registerOperandDispatcher, registerSchemaIntrospector, renderColumnDefinition, repeat, replace, right, round, rowNumber, rpad, rtrim, sel, sign, sin, space, sqrt, substr, sum, synchronizeSchema, tan, toColumnRef, toTableRef, trim, trunc, truncate, unixTimestamp, upper, utcNow, valueToOperand, visitExpression, visitOperand, weekOfYear, windowFunction, year };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,13 +1,25 @@
|
|
|
1
|
-
import { O as OperandNode, C as ColumnRef, a as ColumnNode, B as BinaryExpressionNode, E as ExpressionNode,
|
|
2
|
-
export {
|
|
1
|
+
import { L as LiteralNode, O as OperandNode, C as ColumnRef, a as ColumnNode, B as BinaryExpressionNode, E as ExpressionNode, b as LogicalExpressionNode, N as NullExpressionNode, I as InExpressionNode, c as BetweenExpressionNode, J as JsonPathNode, d as CaseExpressionNode, S as SelectQueryNode, e as ExistsExpressionNode, W as WindowFunctionNode, f as OrderDirection, F as FunctionNode, g as ScalarSubqueryNode, h as ColumnDef, T as TableRef, i as TableDef, j as InsertQueryNode, k as InsertCompiler, l as CompiledQuery, D as Dialect, m as DialectKey, U as UpdateQueryNode, n as UpdateCompiler, o as DeleteQueryNode, p as DeleteCompiler, q as CompilerContext, r as FunctionTableNode, s as DerivedTableNode, t as TableSourceNode, u as ForeignKeyReference, v as IndexColumn, w as IndexDef, x as DbExecutor, H as HydrationPlan, y as NamingStrategy, R as RelationMap, z as EntityContext, A as Entity, G as HasManyRelation, K as HasOneRelation, M as BelongsToRelation, P as BelongsToManyRelation, Q as HasManyCollection, V as BelongsToReference, X as ManyToManyCollection, Y as OrmSession, Z as SelectQueryBuilder, _ as ExecutionContext, $ as HydrationContext } from './select-BuMpVcVt.js';
|
|
2
|
+
export { aL as AnyDomainEvent, ab as CascadeMode, a0 as CheckConstraint, ai as ColumnToTs, a4 as ColumnType, ay as DbExecutorFactory, a7 as DefaultValue, aK as DomainEvent, aD as DomainEventBus, aB as DomainEventHandler, aF as EntityStatus, az as ExternalTransaction, aN as HasDomainEvents, ak as HasOneReference, au as HydrationMetadata, as as HydrationPivotPlan, at as HydrationRelationPlan, aj as InferRow, aC as InitialHandlers, aA as Orm, aM as OrmDomainEvent, av as OrmInterceptor, ax as OrmOptions, aw as OrmSessionOptions, aO as QueryLogEntry, aP as QueryLogger, aR as QueryResult, a6 as RawDefaultValue, a5 as ReferentialAction, aI as RelationChange, aJ as RelationChangeEntry, ac as RelationDef, aH as RelationKey, a9 as RelationKinds, ah as RelationTargetTable, aa as RelationType, aT as SimpleQueryRunner, a2 as TableHooks, a1 as TableOptions, aG as TrackedEntity, aE as addDomainEvent, af as belongsTo, ag as belongsToMany, a8 as col, al as createColumn, aU as createExecutorFromQueryRunner, am as createLiteral, aQ as createQueryLoggingExecutor, a3 as defineTable, ad as hasMany, ae as hasOne, ap as isCaseExpressionNode, ar as isExpressionSelectionNode, ao as isFunctionNode, an as isOperandNode, aq as isWindowFunctionNode, aS as rowsToQueryResult } from './select-BuMpVcVt.js';
|
|
3
3
|
|
|
4
|
+
type LiteralValue = LiteralNode['value'];
|
|
5
|
+
type ValueOperandInput = OperandNode | LiteralValue;
|
|
4
6
|
/**
|
|
5
7
|
* Converts a primitive or existing operand into an operand node
|
|
6
8
|
* @param value - Value or operand to normalize
|
|
7
9
|
* @returns OperandNode representing the value
|
|
8
10
|
*/
|
|
9
|
-
declare const valueToOperand: (value:
|
|
11
|
+
declare const valueToOperand: (value: ValueOperandInput) => OperandNode;
|
|
12
|
+
declare const isValueOperandInput: (value: unknown) => value is ValueOperandInput;
|
|
10
13
|
declare const columnOperand: (col: ColumnRef | ColumnNode) => ColumnNode;
|
|
14
|
+
/**
|
|
15
|
+
* Marks a column reference as an outer-scope reference for correlated subqueries.
|
|
16
|
+
* Primarily semantic; SQL rendering still uses the provided table/alias name.
|
|
17
|
+
*/
|
|
18
|
+
declare const outerRef: (col: ColumnRef | ColumnNode) => ColumnNode;
|
|
19
|
+
/**
|
|
20
|
+
* Creates an outer-scoped column reference using a specific table or alias name.
|
|
21
|
+
*/
|
|
22
|
+
declare const correlateBy: (table: string, column: string) => ColumnNode;
|
|
11
23
|
/**
|
|
12
24
|
* Creates an equality expression (left = right)
|
|
13
25
|
* @param left - Left operand
|
|
@@ -221,6 +233,30 @@ declare const sum: (col: ColumnRef | ColumnNode) => FunctionNode;
|
|
|
221
233
|
* @returns Function node with AVG
|
|
222
234
|
*/
|
|
223
235
|
declare const avg: (col: ColumnRef | ColumnNode) => FunctionNode;
|
|
236
|
+
/**
|
|
237
|
+
* Creates a MIN function expression
|
|
238
|
+
* @param col - Column to take the minimum of
|
|
239
|
+
* @returns Function node with MIN
|
|
240
|
+
*/
|
|
241
|
+
declare const min: (col: ColumnRef | ColumnNode) => FunctionNode;
|
|
242
|
+
/**
|
|
243
|
+
* Creates a MAX function expression
|
|
244
|
+
* @param col - Column to take the maximum of
|
|
245
|
+
* @returns Function node with MAX
|
|
246
|
+
*/
|
|
247
|
+
declare const max: (col: ColumnRef | ColumnNode) => FunctionNode;
|
|
248
|
+
type GroupConcatOrderByInput = {
|
|
249
|
+
column: ColumnRef | ColumnNode;
|
|
250
|
+
direction?: OrderDirection;
|
|
251
|
+
};
|
|
252
|
+
type GroupConcatOptions = {
|
|
253
|
+
separator?: ValueOperandInput;
|
|
254
|
+
orderBy?: GroupConcatOrderByInput[];
|
|
255
|
+
};
|
|
256
|
+
/**
|
|
257
|
+
* Aggregates grouped strings into a single value.
|
|
258
|
+
*/
|
|
259
|
+
declare const groupConcat: (col: ColumnRef | ColumnNode, options?: GroupConcatOptions) => FunctionNode;
|
|
224
260
|
|
|
225
261
|
/**
|
|
226
262
|
* Visitor for expression nodes
|
|
@@ -286,6 +322,18 @@ declare const toColumnRef: (col: ColumnRef | ColumnDef) => ColumnRef;
|
|
|
286
322
|
*/
|
|
287
323
|
declare const toTableRef: (table: TableRef | TableDef) => TableRef;
|
|
288
324
|
|
|
325
|
+
/**
|
|
326
|
+
* Build a typed selection map from a TableDef.
|
|
327
|
+
*/
|
|
328
|
+
declare function sel<TTable extends TableDef, K extends keyof TTable['columns'] & string>(table: TTable, ...cols: K[]): Record<K, TTable['columns'][K]>;
|
|
329
|
+
type Ctor<T> = {
|
|
330
|
+
new (...args: any[]): T;
|
|
331
|
+
};
|
|
332
|
+
/**
|
|
333
|
+
* Build a typed selection map from an entity constructor.
|
|
334
|
+
*/
|
|
335
|
+
declare function esel<TEntity, K extends keyof TEntity & string>(entity: Ctor<TEntity>, ...props: K[]): Record<K, ColumnDef>;
|
|
336
|
+
|
|
289
337
|
/**
|
|
290
338
|
* Maintains immutable state for building INSERT queries
|
|
291
339
|
*/
|
|
@@ -375,27 +423,6 @@ declare class DeleteQueryBuilder<T> {
|
|
|
375
423
|
getAST(): DeleteQueryNode;
|
|
376
424
|
}
|
|
377
425
|
|
|
378
|
-
interface FunctionTableNode {
|
|
379
|
-
type: 'FunctionTable';
|
|
380
|
-
schema?: string;
|
|
381
|
-
name: string;
|
|
382
|
-
args?: unknown[];
|
|
383
|
-
lateral?: boolean;
|
|
384
|
-
withOrdinality?: boolean;
|
|
385
|
-
alias?: string;
|
|
386
|
-
columnAliases?: string[];
|
|
387
|
-
}
|
|
388
|
-
interface FunctionTableNode {
|
|
389
|
-
type: 'FunctionTable';
|
|
390
|
-
schema?: string;
|
|
391
|
-
name: string;
|
|
392
|
-
args?: unknown[];
|
|
393
|
-
lateral?: boolean;
|
|
394
|
-
withOrdinality?: boolean;
|
|
395
|
-
alias?: string;
|
|
396
|
-
columnAliases?: string[];
|
|
397
|
-
}
|
|
398
|
-
|
|
399
426
|
/**
|
|
400
427
|
* Strategy interface for compiling pagination clauses.
|
|
401
428
|
* Allows dialects to customize how pagination (LIMIT/OFFSET, ROWS FETCH, etc.) is generated.
|
|
@@ -451,6 +478,7 @@ declare abstract class SqlDialectBase extends Dialect {
|
|
|
451
478
|
protected compileSelectColumns(ast: SelectQueryNode, ctx: CompilerContext): string;
|
|
452
479
|
protected compileFrom(ast: SelectQueryNode['from'], ctx?: CompilerContext): string;
|
|
453
480
|
protected compileFunctionTable(fn: FunctionTableNode, ctx?: CompilerContext): string;
|
|
481
|
+
protected compileDerivedTable(table: DerivedTableNode, ctx?: CompilerContext): string;
|
|
454
482
|
protected compileTableSource(table: TableSourceNode): string;
|
|
455
483
|
protected compileTableName(table: {
|
|
456
484
|
name: string;
|
|
@@ -460,11 +488,6 @@ declare abstract class SqlDialectBase extends Dialect {
|
|
|
460
488
|
protected stripTrailingSemicolon(sql: string): string;
|
|
461
489
|
protected wrapSetOperand(sql: string): string;
|
|
462
490
|
}
|
|
463
|
-
interface TableSourceNode {
|
|
464
|
-
name: string;
|
|
465
|
-
schema?: string;
|
|
466
|
-
alias?: string;
|
|
467
|
-
}
|
|
468
491
|
|
|
469
492
|
/**
|
|
470
493
|
* MySQL dialect implementation
|
|
@@ -529,6 +552,8 @@ declare class SqlServerDialect extends Dialect {
|
|
|
529
552
|
private compileSelectCore;
|
|
530
553
|
private compileOrderBy;
|
|
531
554
|
private compilePagination;
|
|
555
|
+
private compileTableSource;
|
|
556
|
+
private compileDerivedTable;
|
|
532
557
|
private compileCtes;
|
|
533
558
|
private wrapSetOperand;
|
|
534
559
|
}
|
|
@@ -555,6 +580,7 @@ declare class SqliteDialect extends SqlDialectBase {
|
|
|
555
580
|
*/
|
|
556
581
|
protected compileJsonPath(node: JsonPathNode): string;
|
|
557
582
|
protected compileReturning(returning: ColumnNode[] | undefined, ctx: CompilerContext): string;
|
|
583
|
+
protected formatReturningColumns(returning: ColumnNode[]): string;
|
|
558
584
|
supportsReturning(): boolean;
|
|
559
585
|
}
|
|
560
586
|
|
|
@@ -1181,12 +1207,22 @@ declare const loadHasOneRelation: (ctx: EntityContext, rootTable: TableDef, _rel
|
|
|
1181
1207
|
declare const loadBelongsToRelation: (ctx: EntityContext, rootTable: TableDef, _relationName: string, relation: BelongsToRelation) => Promise<Map<string, Record<string, any>>>;
|
|
1182
1208
|
declare const loadBelongsToManyRelation: (ctx: EntityContext, rootTable: TableDef, _relationName: string, relation: BelongsToManyRelation) => Promise<Map<string, Rows$3>>;
|
|
1183
1209
|
|
|
1210
|
+
/**
|
|
1211
|
+
* Metadata stored on entity instances for ORM internal use
|
|
1212
|
+
* @typeParam TTable - Table definition type
|
|
1213
|
+
*/
|
|
1184
1214
|
interface EntityMeta<TTable extends TableDef> {
|
|
1215
|
+
/** Entity context */
|
|
1185
1216
|
ctx: EntityContext;
|
|
1217
|
+
/** Table definition */
|
|
1186
1218
|
table: TTable;
|
|
1219
|
+
/** Relations that should be loaded lazily */
|
|
1187
1220
|
lazyRelations: (keyof RelationMap<TTable>)[];
|
|
1221
|
+
/** Cache for relation promises */
|
|
1188
1222
|
relationCache: Map<string, Promise<any>>;
|
|
1223
|
+
/** Hydration data for relations */
|
|
1189
1224
|
relationHydration: Map<string, Map<string, any>>;
|
|
1225
|
+
/** Relation wrapper instances */
|
|
1190
1226
|
relationWrappers: Map<string, unknown>;
|
|
1191
1227
|
}
|
|
1192
1228
|
|
|
@@ -1303,4 +1339,4 @@ interface MssqlClientLike {
|
|
|
1303
1339
|
}
|
|
1304
1340
|
declare function createMssqlExecutor(client: MssqlClientLike): DbExecutor;
|
|
1305
1341
|
|
|
1306
|
-
export { AsyncLocalStorage, BelongsToManyRelation, BelongsToReference, BelongsToRelation, BetweenExpressionNode, BinaryExpressionNode, CaseExpressionNode, ColumnDef, type ColumnDiff, ColumnNode, ColumnRef, type DatabaseCheck, type DatabaseColumn, type DatabaseIndex, type DatabaseSchema, type DatabaseTable, DbExecutor, DefaultBelongsToReference, DefaultHasManyCollection, DefaultManyToManyCollection, DeleteQueryBuilder, type DialectName, Entity, EntityContext, ExecutionContext, ExistsExpressionNode, ExpressionNode, type ExpressionVisitor, ForeignKeyReference, FunctionNode, HasManyCollection, HasManyRelation, HasOneRelation, HydrationContext, HydrationPlan, InExpressionNode, IndexColumn, IndexDef, InsertQueryBuilder, type IntrospectOptions, JsonPathNode, LiteralNode, LogicalExpressionNode, ManyToManyCollection, type MssqlClientLike, MySqlDialect, type MysqlClientLike, NullExpressionNode, OperandNode, type OperandVisitor, OrmSession, type PostgresClientLike, PostgresDialect, RelationMap, type RenderColumnOptions, ScalarSubqueryNode, type SchemaChange, type SchemaChangeKind, type SchemaDiffOptions, type SchemaGenerateResult, type SchemaIntrospector, type SchemaPlan, SelectQueryBuilder, SqlServerDialect, type SqliteClientLike, SqliteDialect, type SynchronizeOptions, TableDef, TableRef, TypeScriptGenerator, UpdateQueryBuilder, WindowFunctionNode, abs, acos, and, ascii, asin, atan, atan2, avg, between, caseWhen, ceil, ceiling, char, charLength, clearExpressionDispatchers, clearOperandDispatchers, columnOperand, concat, concatWs, cos, cot, count, createEntityFromRow, createEntityProxy, createMssqlExecutor, createMysqlExecutor, createPostgresExecutor, createSqliteExecutor, currentDate, currentTime, dateAdd, dateDiff, dateFormat, dateSub, dateTrunc, day, dayOfWeek, degrees, denseRank, diffSchema, endOfMonth, eq, executeHydrated, executeHydratedWithContexts, exists, exp, extract, firstValue, floor, fromUnixTime, generateCreateTableSql, generateSchemaSql, getSchemaIntrospector, gt, gte, hydrateRows, inList, instr, introspectSchema, isNotNull, isNull, jsonPath, lag, lastValue, lead, left, length, like, ln, loadBelongsToManyRelation, loadBelongsToRelation, loadHasManyRelation, loadHasOneRelation, locate, log, log10, logBase, lower, lpad, lt, lte, ltrim, mod, month, neq, notBetween, notExists, notInList, notLike, now, ntile, or, pi, position, pow, power, radians, rand, random, rank, registerExpressionDispatcher, registerOperandDispatcher, registerSchemaIntrospector, renderColumnDefinition, repeat, replace, right, round, rowNumber, rpad, rtrim, sign, sin, space, sqrt, substr, sum, synchronizeSchema, tan, toColumnRef, toTableRef, trim, trunc, truncate, unixTimestamp, upper, utcNow, valueToOperand, visitExpression, visitOperand, weekOfYear, windowFunction, year };
|
|
1342
|
+
export { AsyncLocalStorage, BelongsToManyRelation, BelongsToReference, BelongsToRelation, BetweenExpressionNode, BinaryExpressionNode, CaseExpressionNode, ColumnDef, type ColumnDiff, ColumnNode, ColumnRef, type DatabaseCheck, type DatabaseColumn, type DatabaseIndex, type DatabaseSchema, type DatabaseTable, DbExecutor, DefaultBelongsToReference, DefaultHasManyCollection, DefaultManyToManyCollection, DeleteQueryBuilder, type DialectName, Entity, EntityContext, ExecutionContext, ExistsExpressionNode, ExpressionNode, type ExpressionVisitor, ForeignKeyReference, FunctionNode, type GroupConcatOptions, HasManyCollection, HasManyRelation, HasOneRelation, HydrationContext, HydrationPlan, InExpressionNode, IndexColumn, IndexDef, InsertQueryBuilder, type IntrospectOptions, JsonPathNode, LiteralNode, type LiteralValue, LogicalExpressionNode, ManyToManyCollection, type MssqlClientLike, MySqlDialect, type MysqlClientLike, NullExpressionNode, OperandNode, type OperandVisitor, OrmSession, type PostgresClientLike, PostgresDialect, RelationMap, type RenderColumnOptions, ScalarSubqueryNode, type SchemaChange, type SchemaChangeKind, type SchemaDiffOptions, type SchemaGenerateResult, type SchemaIntrospector, type SchemaPlan, SelectQueryBuilder, SqlServerDialect, type SqliteClientLike, SqliteDialect, type SynchronizeOptions, TableDef, TableRef, TypeScriptGenerator, UpdateQueryBuilder, type ValueOperandInput, WindowFunctionNode, abs, acos, and, ascii, asin, atan, atan2, avg, between, caseWhen, ceil, ceiling, char, charLength, clearExpressionDispatchers, clearOperandDispatchers, columnOperand, concat, concatWs, correlateBy, cos, cot, count, createEntityFromRow, createEntityProxy, createMssqlExecutor, createMysqlExecutor, createPostgresExecutor, createSqliteExecutor, currentDate, currentTime, dateAdd, dateDiff, dateFormat, dateSub, dateTrunc, day, dayOfWeek, degrees, denseRank, diffSchema, endOfMonth, eq, esel, executeHydrated, executeHydratedWithContexts, exists, exp, extract, firstValue, floor, fromUnixTime, generateCreateTableSql, generateSchemaSql, getSchemaIntrospector, groupConcat, gt, gte, hydrateRows, inList, instr, introspectSchema, isNotNull, isNull, isValueOperandInput, jsonPath, lag, lastValue, lead, left, length, like, ln, loadBelongsToManyRelation, loadBelongsToRelation, loadHasManyRelation, loadHasOneRelation, locate, log, log10, logBase, lower, lpad, lt, lte, ltrim, max, min, mod, month, neq, notBetween, notExists, notInList, notLike, now, ntile, or, outerRef, pi, position, pow, power, radians, rand, random, rank, registerExpressionDispatcher, registerOperandDispatcher, registerSchemaIntrospector, renderColumnDefinition, repeat, replace, right, round, rowNumber, rpad, rtrim, sel, sign, sin, space, sqrt, substr, sum, synchronizeSchema, tan, toColumnRef, toTableRef, trim, trunc, truncate, unixTimestamp, upper, utcNow, valueToOperand, visitExpression, visitOperand, weekOfYear, windowFunction, year };
|