metal-orm 1.0.60 → 1.0.63

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/dist/index.d.cts CHANGED
@@ -1274,6 +1274,16 @@ declare const toColumnRef: (col: ColumnRef | ColumnDef) => ColumnRef;
1274
1274
  */
1275
1275
  declare const toTableRef: (table: TableRef | TableDef) => TableRef;
1276
1276
 
1277
+ /**
1278
+ * Expression AST nodes and builders.
1279
+ * Re-exports components for building and visiting SQL expression trees.
1280
+ */
1281
+
1282
+ type TypedExpression<T> = (FunctionNode | CaseExpressionNode | WindowFunctionNode) & {
1283
+ __tsType: T;
1284
+ };
1285
+ declare const asType: <T>(expr: FunctionNode | CaseExpressionNode | WindowFunctionNode) => TypedExpression<T>;
1286
+
1277
1287
  /**
1278
1288
  * AST node representing a JOIN clause
1279
1289
  */
@@ -3494,7 +3504,12 @@ type RelationCallback = <TChildTable extends TableDef>(qb: SelectQueryBuilder<un
3494
3504
 
3495
3505
  type SelectDialectInput = Dialect | DialectKey;
3496
3506
 
3497
- type ColumnSelectionValue = ColumnDef | FunctionNode | CaseExpressionNode | WindowFunctionNode;
3507
+ type ColumnSelectionValue = ColumnDef | FunctionNode | CaseExpressionNode | WindowFunctionNode | TypedExpression<unknown>;
3508
+ type SelectionValueType<TValue> = TValue extends TypedExpression<infer TRuntime> ? TRuntime : TValue extends ColumnDef ? ColumnToTs<TValue> : unknown;
3509
+ type SelectionResult<TSelection extends Record<string, ColumnSelectionValue>> = {
3510
+ [K in keyof TSelection]: SelectionValueType<TSelection[K]>;
3511
+ };
3512
+ type SelectionFromKeys<TTable extends TableDef, K extends keyof TTable['columns'] & string> = Pick<InferRow<TTable>, K>;
3498
3513
  type DeepSelectEntry<TTable extends TableDef> = {
3499
3514
  type: 'root';
3500
3515
  columns: (keyof TTable['columns'] & string)[];
@@ -3509,7 +3524,7 @@ type DeepSelectConfig<TTable extends TableDef> = DeepSelectEntry<TTable>[];
3509
3524
  * @typeParam T - Result type for projections (unused)
3510
3525
  * @typeParam TTable - Table definition being queried
3511
3526
  */
3512
- declare class SelectQueryBuilder<T = unknown, TTable extends TableDef = TableDef> {
3527
+ declare class SelectQueryBuilder<T = EntityInstance<TableDef>, TTable extends TableDef = TableDef> {
3513
3528
  private readonly env;
3514
3529
  private readonly context;
3515
3530
  private readonly columnSelector;
@@ -3522,6 +3537,7 @@ declare class SelectQueryBuilder<T = unknown, TTable extends TableDef = TableDef
3522
3537
  private readonly relationFacet;
3523
3538
  private readonly lazyRelations;
3524
3539
  private readonly lazyRelationOptions;
3540
+ private readonly entityConstructor?;
3525
3541
  /**
3526
3542
  * Creates a new SelectQueryBuilder instance
3527
3543
  * @param table - Table definition to query
@@ -3529,7 +3545,7 @@ declare class SelectQueryBuilder<T = unknown, TTable extends TableDef = TableDef
3529
3545
  * @param hydration - Optional hydration manager
3530
3546
  * @param dependencies - Optional query builder dependencies
3531
3547
  */
3532
- constructor(table: TTable, state?: SelectQueryState, hydration?: HydrationManager, dependencies?: Partial<SelectQueryBuilderDependencies>, lazyRelations?: Set<string>, lazyRelationOptions?: Map<string, RelationIncludeOptions>);
3548
+ constructor(table: TTable, state?: SelectQueryState, hydration?: HydrationManager, dependencies?: Partial<SelectQueryBuilderDependencies>, lazyRelations?: Set<string>, lazyRelationOptions?: Map<string, RelationIncludeOptions>, entityConstructor?: EntityConstructor);
3533
3549
  /**
3534
3550
  * Creates a new SelectQueryBuilder instance with updated context and lazy relations
3535
3551
  * @param context - Updated query context
@@ -3579,8 +3595,8 @@ declare class SelectQueryBuilder<T = unknown, TTable extends TableDef = TableDef
3579
3595
  * fullName: concat(userTable.columns.firstName, ' ', userTable.columns.lastName)
3580
3596
  * });
3581
3597
  */
3582
- select<K extends keyof TTable['columns'] & string>(...args: K[]): SelectQueryBuilder<T, TTable>;
3583
- select(columns: Record<string, ColumnSelectionValue>): SelectQueryBuilder<T, TTable>;
3598
+ select<K extends keyof TTable['columns'] & string>(...args: K[]): SelectQueryBuilder<T & SelectionFromKeys<TTable, K>, TTable>;
3599
+ select<TSelection extends Record<string, ColumnSelectionValue>>(columns: TSelection): SelectQueryBuilder<T & SelectionResult<TSelection>, TTable>;
3584
3600
  /**
3585
3601
  * Selects raw column expressions
3586
3602
  * @param cols - Column expressions as strings
@@ -3669,7 +3685,7 @@ declare class SelectQueryBuilder<T = unknown, TTable extends TableDef = TableDef
3669
3685
  * qb.select('id', 'name')
3670
3686
  * .selectSubquery('postCount', postCount);
3671
3687
  */
3672
- selectSubquery<TSub extends TableDef>(alias: string, sub: SelectQueryBuilder<unknown, TSub> | SelectQueryNode): SelectQueryBuilder<T, TTable>;
3688
+ selectSubquery<TValue = unknown, K extends string = string, TSub extends TableDef = TableDef>(alias: K, sub: SelectQueryBuilder<unknown, TSub> | SelectQueryNode): SelectQueryBuilder<T & Record<K, TValue>, TTable>;
3673
3689
  /**
3674
3690
  * Adds a JOIN against a derived table (subquery with alias)
3675
3691
  * @param subquery - Subquery to join
@@ -3831,15 +3847,49 @@ declare class SelectQueryBuilder<T = unknown, TTable extends TableDef = TableDef
3831
3847
  */
3832
3848
  getTable(): TTable;
3833
3849
  /**
3834
- * Executes the query and returns hydrated results
3850
+ * Ensures that if no columns are selected, all columns from the table are selected by default.
3851
+ */
3852
+ private ensureDefaultSelection;
3853
+ /**
3854
+ * Executes the query and returns hydrated results.
3855
+ * If the builder was created with an entity constructor (e.g. via selectFromEntity),
3856
+ * this will automatically return fully materialized entity instances.
3857
+ *
3835
3858
  * @param ctx - ORM session context
3836
- * @returns Promise of entity instances
3859
+ * @returns Promise of entity instances (or objects if generic T is not an entity)
3837
3860
  * @example
3838
- * const users = await qb.select('id', 'name')
3839
- * .where(eq(userTable.columns.active, true))
3840
- * .execute(session);
3861
+ * const users = await selectFromEntity(User).execute(session);
3862
+ * // users is User[]
3863
+ * users[0] instanceof User; // true
3864
+ */
3865
+ execute(ctx: OrmSession): Promise<T[]>;
3866
+ /**
3867
+ * Executes the query and returns plain row objects (POJOs), ignoring any entity materialization.
3868
+ * Use this if you want raw data even when using selectFromEntity.
3869
+ *
3870
+ * @param ctx - ORM session context
3871
+ * @returns Promise of plain entity instances
3872
+ * @example
3873
+ * const rows = await selectFromEntity(User).executePlain(session);
3874
+ * // rows is EntityInstance<UserTable>[] (plain objects)
3875
+ * rows[0] instanceof User; // false
3841
3876
  */
3842
- execute(ctx: OrmSession): Promise<EntityInstance<TTable>[]>;
3877
+ executePlain(ctx: OrmSession): Promise<EntityInstance<TTable>[]>;
3878
+ /**
3879
+ * Executes the query and returns results as real class instances.
3880
+ * Unlike execute(), this returns actual instances of the decorated entity class
3881
+ * with working methods and proper instanceof checks.
3882
+ * @param entityClass - The entity class constructor
3883
+ * @param ctx - ORM session context
3884
+ * @returns Promise of entity class instances
3885
+ * @example
3886
+ * const users = await selectFromEntity(User)
3887
+ * .include('posts')
3888
+ * .executeAs(User, session);
3889
+ * users[0] instanceof User; // true!
3890
+ * users[0].getFullName(); // works!
3891
+ */
3892
+ executeAs<TEntity extends object>(entityClass: EntityConstructor<TEntity>, ctx: OrmSession): Promise<TEntity[]>;
3843
3893
  /**
3844
3894
  * Executes a count query for the current builder without LIMIT/OFFSET clauses.
3845
3895
  *
@@ -3857,7 +3907,7 @@ declare class SelectQueryBuilder<T = unknown, TTable extends TableDef = TableDef
3857
3907
  page: number;
3858
3908
  pageSize: number;
3859
3909
  }): Promise<{
3860
- items: EntityInstance<TTable>[];
3910
+ items: T[];
3861
3911
  totalItems: number;
3862
3912
  }>;
3863
3913
  /**
@@ -3870,7 +3920,7 @@ declare class SelectQueryBuilder<T = unknown, TTable extends TableDef = TableDef
3870
3920
  * const hydCtx = new HydrationContext();
3871
3921
  * const users = await qb.executeWithContexts(execCtx, hydCtx);
3872
3922
  */
3873
- executeWithContexts(execCtx: ExecutionContext, hydCtx: HydrationContext): Promise<EntityInstance<TTable>[]>;
3923
+ executeWithContexts(execCtx: ExecutionContext, hydCtx: HydrationContext): Promise<T[]>;
3874
3924
  /**
3875
3925
  * Adds a WHERE condition to the query
3876
3926
  * @param expr - Expression for the WHERE clause
@@ -6060,6 +6110,14 @@ declare class DefaultManyToManyCollection<TTarget, TPivot extends object | undef
6060
6110
  * @returns Promise resolving to array of entity instances
6061
6111
  */
6062
6112
  declare function executeHydrated<TTable extends TableDef>(session: OrmSession, qb: SelectQueryBuilder<unknown, TTable>): Promise<EntityInstance<TTable>[]>;
6113
+ /**
6114
+ * Executes a hydrated query and returns plain row objects (no entity proxies).
6115
+ * @template TTable - The table type
6116
+ * @param session - The ORM session
6117
+ * @param qb - The select query builder
6118
+ * @returns Promise resolving to array of plain row objects
6119
+ */
6120
+ declare function executeHydratedPlain<TTable extends TableDef>(session: OrmSession, qb: SelectQueryBuilder<unknown, TTable>): Promise<Record<string, unknown>[]>;
6063
6121
  /**
6064
6122
  * Executes a hydrated query using execution and hydration contexts.
6065
6123
  * @template TTable - The table type
@@ -6069,6 +6127,14 @@ declare function executeHydrated<TTable extends TableDef>(session: OrmSession, q
6069
6127
  * @returns Promise resolving to array of entity instances
6070
6128
  */
6071
6129
  declare function executeHydratedWithContexts<TTable extends TableDef>(execCtx: ExecutionContext, hydCtx: HydrationContext, qb: SelectQueryBuilder<unknown, TTable>): Promise<EntityInstance<TTable>[]>;
6130
+ /**
6131
+ * Executes a hydrated query using execution context and returns plain row objects.
6132
+ * @template TTable - The table type
6133
+ * @param execCtx - The execution context
6134
+ * @param qb - The select query builder
6135
+ * @returns Promise resolving to array of plain row objects
6136
+ */
6137
+ declare function executeHydratedPlainWithContexts<TTable extends TableDef>(execCtx: ExecutionContext, qb: SelectQueryBuilder<unknown, TTable>): Promise<Record<string, unknown>[]>;
6072
6138
 
6073
6139
  type JsonifyScalar<T> = T extends Date ? string : T;
6074
6140
  /**
@@ -6218,7 +6284,8 @@ type EntityTable<TEntity extends object> = Omit<TableDef<{
6218
6284
  [K in RelationKeys<TEntity>]: NonNullable<TEntity[K]> extends HasManyCollection<infer TChild> ? HasManyRelation<EntityTable<NonNullable<TChild> & object>> : NonNullable<TEntity[K]> extends ManyToManyCollection<infer TTarget, infer TPivot> ? BelongsToManyRelation<EntityTable<NonNullable<TTarget> & object>, TPivot extends object ? EntityTable<NonNullable<TPivot> & object> : TableDef> : NonNullable<TEntity[K]> extends HasOneReference<infer TChild> ? HasOneRelation<EntityTable<NonNullable<TChild> & object>> : NonNullable<TEntity[K]> extends BelongsToReference<infer TParent> ? BelongsToRelation<EntityTable<NonNullable<TParent> & object>> : NonNullable<TEntity[K]> extends object ? BelongsToRelation<EntityTable<NonNullable<TEntity[K]> & object>> : never;
6219
6285
  };
6220
6286
  };
6221
- declare const selectFromEntity: <TEntity extends object>(ctor: EntityConstructor<TEntity>) => SelectQueryBuilder<unknown, EntityTable<TEntity>>;
6287
+ type DecoratedEntityInstance<TEntity extends object> = TEntity & EntityInstance<EntityTable<TEntity>>;
6288
+ declare const selectFromEntity: <TEntity extends object>(ctor: EntityConstructor<TEntity>) => SelectQueryBuilder<DecoratedEntityInstance<TEntity>, EntityTable<TEntity>>;
6222
6289
  /**
6223
6290
  * Public API: opt-in ergonomic entity reference (decorator-level).
6224
6291
  *
@@ -6247,6 +6314,86 @@ interface DecoratorMetadataBag {
6247
6314
  */
6248
6315
  declare const getDecoratorMetadata: (ctor: object) => DecoratorMetadataBag | undefined;
6249
6316
 
6317
+ /**
6318
+ * Strategy interface for materializing entity instances (Open/Closed Principle).
6319
+ */
6320
+ interface EntityMaterializationStrategy {
6321
+ /**
6322
+ * Creates an instance of the entity class and populates it with data.
6323
+ * @param ctor - The entity constructor
6324
+ * @param data - The raw data to populate
6325
+ * @returns The materialized entity instance
6326
+ */
6327
+ materialize<T>(ctor: EntityConstructor<T>, data: Record<string, unknown>): T;
6328
+ }
6329
+ /**
6330
+ * Default strategy: Uses Object.create() to create instance without calling constructor.
6331
+ * Safe for classes with required constructor parameters.
6332
+ */
6333
+ declare class PrototypeMaterializationStrategy implements EntityMaterializationStrategy {
6334
+ materialize<T>(ctor: EntityConstructor<T>, data: Record<string, unknown>): T;
6335
+ }
6336
+ /**
6337
+ * Alternative strategy: Calls default constructor then assigns properties.
6338
+ * Use when class constructor initializes important state.
6339
+ */
6340
+ declare class ConstructorMaterializationStrategy implements EntityMaterializationStrategy {
6341
+ materialize<T>(ctor: EntityConstructor<T>, data: Record<string, unknown>): T;
6342
+ }
6343
+ /**
6344
+ * Interface for materializing query results into real entity class instances.
6345
+ */
6346
+ interface EntityMaterializer {
6347
+ /**
6348
+ * Materializes a single row into a real entity instance.
6349
+ * @param entityClass - The entity constructor
6350
+ * @param row - The raw data row
6351
+ * @returns The materialized entity instance
6352
+ */
6353
+ materialize<T>(entityClass: EntityConstructor<T>, row: Record<string, unknown>): T;
6354
+ /**
6355
+ * Materializes multiple rows into real entity instances.
6356
+ * @param entityClass - The entity constructor
6357
+ * @param rows - The raw data rows
6358
+ * @returns Array of materialized entity instances
6359
+ */
6360
+ materializeMany<T>(entityClass: EntityConstructor<T>, rows: Record<string, unknown>[]): T[];
6361
+ }
6362
+ /**
6363
+ * Default implementation of EntityMaterializer.
6364
+ * Converts query results into actual class instances with working methods.
6365
+ *
6366
+ * @example
6367
+ * const materializer = new DefaultEntityMaterializer();
6368
+ * const users = materializer.materializeMany(User, queryResults);
6369
+ * users[0] instanceof User; // true
6370
+ * users[0].getFullName(); // works!
6371
+ */
6372
+ declare class DefaultEntityMaterializer implements EntityMaterializer {
6373
+ private readonly strategy;
6374
+ constructor(strategy?: EntityMaterializationStrategy);
6375
+ materialize<T>(ctor: EntityConstructor<T>, row: Record<string, unknown>): T;
6376
+ materializeMany<T>(ctor: EntityConstructor<T>, rows: Record<string, unknown>[]): T[];
6377
+ /**
6378
+ * Recursively materializes nested relation data.
6379
+ */
6380
+ private materializeRelations;
6381
+ /**
6382
+ * Simple heuristic to check if an object looks like an entity.
6383
+ */
6384
+ private isEntityLike;
6385
+ private materializeEntityProxy;
6386
+ }
6387
+ /**
6388
+ * Convenience function to materialize query results as real class instances.
6389
+ *
6390
+ * @example
6391
+ * const results = await selectFromEntity(User).execute(session);
6392
+ * const users = materializeAs(User, results);
6393
+ * users[0] instanceof User; // true!
6394
+ */
6395
+ declare const materializeAs: <TEntity extends object>(ctor: EntityConstructor<TEntity>, results: Record<string, unknown>[]) => TEntity[];
6396
+
6250
6397
  type PoolOptions = {
6251
6398
  /** Maximum number of live resources (idle + leased). */
6252
6399
  max: number;
@@ -6410,4 +6557,4 @@ type PooledExecutorFactoryOptions<TConn> = {
6410
6557
  */
6411
6558
  declare function createPooledExecutorFactory<TConn>(opts: PooledExecutorFactoryOptions<TConn>): DbExecutorFactory;
6412
6559
 
6413
- export { type AliasRefNode, type AnyDomainEvent, type ArithmeticExpressionNode, type TableRef as AstTableRef, AsyncLocalStorage, BelongsTo, BelongsToMany, type BelongsToManyOptions, type BelongsToManyRelation, type BelongsToOptions, type BelongsToReference, type BelongsToReferenceApi, type BelongsToRelation, type BetweenExpressionNode, type BinaryExpressionNode, type BitwiseExpressionNode, type CascadeMode, type CaseExpressionNode, type CastExpressionNode, type CheckConstraint, type CollateExpressionNode, Column, type ColumnDef, type ColumnDiff, type ColumnInput, type ColumnNode, type ColumnOptions, type ColumnRef, type ColumnToTs, type ColumnType, type CreateTediousClientOptions, type DatabaseCheck, type DatabaseColumn, type DatabaseIndex, type DatabaseSchema, type DatabaseTable, type DbExecutor, type DbExecutorFactory, DefaultBelongsToReference, DefaultHasManyCollection, DefaultManyToManyCollection, type DefaultValue, DeleteQueryBuilder, type DialectName, type DomainEvent, DomainEventBus, type DomainEventHandler, Entity, type EntityContext, type EntityInstance, type EntityOptions, EntityStatus, type ExecutionContext, type ExistsExpressionNode, type ExpressionNode, type ExpressionVisitor, type ForeignKeyReference, type FunctionNode, type GroupConcatOptions, type HasDomainEvents, HasMany, type HasManyCollection, type HasManyOptions, type HasManyRelation, HasOne, type HasOneOptions, type HasOneReference, type HasOneReferenceApi, type HasOneRelation, type HydrationContext, type HydrationMetadata, type HydrationPivotPlan, type HydrationPlan, type HydrationRelationPlan, type InExpressionNode, type InExpressionRight, type IndexColumn, type IndexDef, type InferRow, type InitialHandlers, InsertQueryBuilder, type IntrospectOptions, type JsonPathNode, type Jsonify, type JsonifyScalar, type LiteralNode, type LiteralValue, type LogicalExpressionNode, type ManyToManyCollection, type MssqlClientLike, MySqlDialect, type MysqlClientLike, type NullExpressionNode, type OperandNode, type OperandVisitor, Orm, type OrmDomainEvent, type OrmInterceptor, type OrmOptions, OrmSession, type OrmSessionOptions, Pool, type PoolAdapter, type PoolLease, type PoolOptions, type PooledConnectionAdapter, type PostgresClientLike, PostgresDialect, PrimaryKey, type Primitive, type QueryLogEntry, type QueryLogger, type QueryResult, type RawDefaultValue, type ReferentialAction, type RelationChange, type RelationChangeEntry, type RelationDef, type RelationKey$1 as RelationKey, RelationKinds, type RelationMap, type RelationTargetTable, type RelationType, type RenderColumnOptions, STANDARD_COLUMN_TYPES, type SaveGraphInputPayload, type SaveGraphInputScalar, type SaveGraphJsonScalar, type ScalarSubqueryNode, type SchemaChange, type SchemaChangeKind, type SchemaDiffOptions, type SchemaGenerateResult, type SchemaIntrospector, type SchemaPlan, SelectQueryBuilder, type SelectQueryInput, type SelectableKeys, type SimpleQueryRunner, SqlServerDialect, type SqliteClientLike, SqliteDialect, type StandardColumnType, type SynchronizeOptions, type TableDef, type TableHooks, type TableOptions, type TableRef$1 as TableRef, type TediousColumn, type TediousConnectionLike, type TediousModule, type TediousRequest, type TediousRequestCtor, type TediousTypes, type TrackedEntity, TypeScriptGenerator, UpdateQueryBuilder, type ValueOperandInput, type WindowFunctionNode, abs, acos, add, addDomainEvent, age, aliasRef, and, arrayAppend, ascii, asin, atan, atan2, avg, belongsTo, belongsToMany, between, bitAnd, bitLength, bitOr, bitXor, bootstrapEntities, caseWhen, cast, cbrt, ceil, ceiling, char, charLength, chr, clearExpressionDispatchers, clearOperandDispatchers, coalesce, col, collate, columnOperand, concat, concatWs, correlateBy, cos, cot, count, countAll, createEntityFromRow, createEntityProxy, createExecutorFromQueryRunner, createMssqlExecutor, createMysqlExecutor, createPooledExecutorFactory, createPostgresExecutor, createQueryLoggingExecutor, createSqliteExecutor, createTediousExecutor, createTediousMssqlClient, currentDate, currentTime, dateAdd, dateDiff, dateFormat, dateSub, dateTrunc, day, dayOfWeek, defineTable, degrees, deleteFrom, denseRank, diffSchema, div, endOfMonth, entityRef, eq, esel, executeHydrated, executeHydratedWithContexts, executeSchemaSql, executeSchemaSqlFor, exists, exp, extract, firstValue, floor, fromUnixTime, generateCreateTableSql, generateSchemaSql, generateSchemaSqlFor, getColumn, getDecoratorMetadata, getSchemaIntrospector, getTableDefFromEntity, greatest, groupConcat, gt, gte, hasMany, hasOne, hour, hydrateRows, ifNull, inList, inSubquery, initcap, insertInto, instr, introspectSchema, isCaseExpressionNode, isCastExpressionNode, isCollateExpressionNode, isExpressionSelectionNode, isFunctionNode, isNotNull, isNull, isOperandNode, isValueOperandInput, isWindowFunctionNode, jsonArrayAgg, jsonContains, jsonLength, jsonPath, jsonSet, jsonify, lag, lastValue, lead, least, left, length, like, ln, loadBelongsToManyRelation, loadBelongsToRelation, loadHasManyRelation, loadHasOneRelation, localTime, localTimestamp, locate, log, log10, log2, logBase, lower, lpad, lt, lte, ltrim, max, md5, min, minute, mod, month, mul, neq, normalizeColumnType, notBetween, notExists, notInList, notInSubquery, notLike, now, ntile, nullif, octetLength, or, outerRef, pi, position, pow, power, quarter, radians, rand, random, rank, registerExpressionDispatcher, registerOperandDispatcher, registerSchemaIntrospector, relationLoaderCache, renderColumnDefinition, renderTypeWithArgs, repeat, replace, reverse, right, round, rowNumber, rowsToQueryResult, rpad, rtrim, second, sel, selectFrom, selectFromEntity, setRelations, sha1, sha2, shiftLeft, shiftRight, sign, sin, space, sqrt, stddev, sub, substr, sum, synchronizeSchema, tableRef, tan, toColumnRef, toTableRef, trim, trunc, truncate, unixTimestamp, update, upper, utcNow, valueToOperand, variance, visitExpression, visitOperand, weekOfYear, windowFunction, year };
6560
+ export { type AliasRefNode, type AnyDomainEvent, type ArithmeticExpressionNode, type TableRef as AstTableRef, AsyncLocalStorage, BelongsTo, BelongsToMany, type BelongsToManyOptions, type BelongsToManyRelation, type BelongsToOptions, type BelongsToReference, type BelongsToReferenceApi, type BelongsToRelation, type BetweenExpressionNode, type BinaryExpressionNode, type BitwiseExpressionNode, type CascadeMode, type CaseExpressionNode, type CastExpressionNode, type CheckConstraint, type CollateExpressionNode, Column, type ColumnDef, type ColumnDiff, type ColumnInput, type ColumnNode, type ColumnOptions, type ColumnRef, type ColumnToTs, type ColumnType, ConstructorMaterializationStrategy, type CreateTediousClientOptions, type DatabaseCheck, type DatabaseColumn, type DatabaseIndex, type DatabaseSchema, type DatabaseTable, type DbExecutor, type DbExecutorFactory, type DecoratedEntityInstance, DefaultBelongsToReference, DefaultEntityMaterializer, DefaultHasManyCollection, DefaultManyToManyCollection, type DefaultValue, DeleteQueryBuilder, type DialectName, type DomainEvent, DomainEventBus, type DomainEventHandler, Entity, type EntityContext, type EntityInstance, type EntityMaterializationStrategy, type EntityMaterializer, type EntityOptions, EntityStatus, type ExecutionContext, type ExistsExpressionNode, type ExpressionNode, type ExpressionVisitor, type ForeignKeyReference, type FunctionNode, type GroupConcatOptions, type HasDomainEvents, HasMany, type HasManyCollection, type HasManyOptions, type HasManyRelation, HasOne, type HasOneOptions, type HasOneReference, type HasOneReferenceApi, type HasOneRelation, type HydrationContext, type HydrationMetadata, type HydrationPivotPlan, type HydrationPlan, type HydrationRelationPlan, type InExpressionNode, type InExpressionRight, type IndexColumn, type IndexDef, type InferRow, type InitialHandlers, InsertQueryBuilder, type IntrospectOptions, type JsonPathNode, type Jsonify, type JsonifyScalar, type LiteralNode, type LiteralValue, type LogicalExpressionNode, type ManyToManyCollection, type MssqlClientLike, MySqlDialect, type MysqlClientLike, type NullExpressionNode, type OperandNode, type OperandVisitor, Orm, type OrmDomainEvent, type OrmInterceptor, type OrmOptions, OrmSession, type OrmSessionOptions, Pool, type PoolAdapter, type PoolLease, type PoolOptions, type PooledConnectionAdapter, type PostgresClientLike, PostgresDialect, PrimaryKey, type Primitive, PrototypeMaterializationStrategy, type QueryLogEntry, type QueryLogger, type QueryResult, type RawDefaultValue, type ReferentialAction, type RelationChange, type RelationChangeEntry, type RelationDef, type RelationKey$1 as RelationKey, RelationKinds, type RelationMap, type RelationTargetTable, type RelationType, type RenderColumnOptions, STANDARD_COLUMN_TYPES, type SaveGraphInputPayload, type SaveGraphInputScalar, type SaveGraphJsonScalar, type ScalarSubqueryNode, type SchemaChange, type SchemaChangeKind, type SchemaDiffOptions, type SchemaGenerateResult, type SchemaIntrospector, type SchemaPlan, SelectQueryBuilder, type SelectQueryInput, type SelectableKeys, type SimpleQueryRunner, SqlServerDialect, type SqliteClientLike, SqliteDialect, type StandardColumnType, type SynchronizeOptions, type TableDef, type TableHooks, type TableOptions, type TableRef$1 as TableRef, type TediousColumn, type TediousConnectionLike, type TediousModule, type TediousRequest, type TediousRequestCtor, type TediousTypes, type TrackedEntity, TypeScriptGenerator, type TypedExpression, UpdateQueryBuilder, type ValueOperandInput, type WindowFunctionNode, abs, acos, add, addDomainEvent, age, aliasRef, and, arrayAppend, asType, ascii, asin, atan, atan2, avg, belongsTo, belongsToMany, between, bitAnd, bitLength, bitOr, bitXor, bootstrapEntities, caseWhen, cast, cbrt, ceil, ceiling, char, charLength, chr, clearExpressionDispatchers, clearOperandDispatchers, coalesce, col, collate, columnOperand, concat, concatWs, correlateBy, cos, cot, count, countAll, createEntityFromRow, createEntityProxy, createExecutorFromQueryRunner, createMssqlExecutor, createMysqlExecutor, createPooledExecutorFactory, createPostgresExecutor, createQueryLoggingExecutor, createSqliteExecutor, createTediousExecutor, createTediousMssqlClient, currentDate, currentTime, dateAdd, dateDiff, dateFormat, dateSub, dateTrunc, day, dayOfWeek, defineTable, degrees, deleteFrom, denseRank, diffSchema, div, endOfMonth, entityRef, eq, esel, executeHydrated, executeHydratedPlain, executeHydratedPlainWithContexts, executeHydratedWithContexts, executeSchemaSql, executeSchemaSqlFor, exists, exp, extract, firstValue, floor, fromUnixTime, generateCreateTableSql, generateSchemaSql, generateSchemaSqlFor, getColumn, getDecoratorMetadata, getSchemaIntrospector, getTableDefFromEntity, greatest, groupConcat, gt, gte, hasMany, hasOne, hour, hydrateRows, ifNull, inList, inSubquery, initcap, insertInto, instr, introspectSchema, isCaseExpressionNode, isCastExpressionNode, isCollateExpressionNode, isExpressionSelectionNode, isFunctionNode, isNotNull, isNull, isOperandNode, isValueOperandInput, isWindowFunctionNode, jsonArrayAgg, jsonContains, jsonLength, jsonPath, jsonSet, jsonify, lag, lastValue, lead, least, left, length, like, ln, loadBelongsToManyRelation, loadBelongsToRelation, loadHasManyRelation, loadHasOneRelation, localTime, localTimestamp, locate, log, log10, log2, logBase, lower, lpad, lt, lte, ltrim, materializeAs, max, md5, min, minute, mod, month, mul, neq, normalizeColumnType, notBetween, notExists, notInList, notInSubquery, notLike, now, ntile, nullif, octetLength, or, outerRef, pi, position, pow, power, quarter, radians, rand, random, rank, registerExpressionDispatcher, registerOperandDispatcher, registerSchemaIntrospector, relationLoaderCache, renderColumnDefinition, renderTypeWithArgs, repeat, replace, reverse, right, round, rowNumber, rowsToQueryResult, rpad, rtrim, second, sel, selectFrom, selectFromEntity, setRelations, sha1, sha2, shiftLeft, shiftRight, sign, sin, space, sqrt, stddev, sub, substr, sum, synchronizeSchema, tableRef, tan, toColumnRef, toTableRef, trim, trunc, truncate, unixTimestamp, update, upper, utcNow, valueToOperand, variance, visitExpression, visitOperand, weekOfYear, windowFunction, year };
package/dist/index.d.ts CHANGED
@@ -1274,6 +1274,16 @@ declare const toColumnRef: (col: ColumnRef | ColumnDef) => ColumnRef;
1274
1274
  */
1275
1275
  declare const toTableRef: (table: TableRef | TableDef) => TableRef;
1276
1276
 
1277
+ /**
1278
+ * Expression AST nodes and builders.
1279
+ * Re-exports components for building and visiting SQL expression trees.
1280
+ */
1281
+
1282
+ type TypedExpression<T> = (FunctionNode | CaseExpressionNode | WindowFunctionNode) & {
1283
+ __tsType: T;
1284
+ };
1285
+ declare const asType: <T>(expr: FunctionNode | CaseExpressionNode | WindowFunctionNode) => TypedExpression<T>;
1286
+
1277
1287
  /**
1278
1288
  * AST node representing a JOIN clause
1279
1289
  */
@@ -3494,7 +3504,12 @@ type RelationCallback = <TChildTable extends TableDef>(qb: SelectQueryBuilder<un
3494
3504
 
3495
3505
  type SelectDialectInput = Dialect | DialectKey;
3496
3506
 
3497
- type ColumnSelectionValue = ColumnDef | FunctionNode | CaseExpressionNode | WindowFunctionNode;
3507
+ type ColumnSelectionValue = ColumnDef | FunctionNode | CaseExpressionNode | WindowFunctionNode | TypedExpression<unknown>;
3508
+ type SelectionValueType<TValue> = TValue extends TypedExpression<infer TRuntime> ? TRuntime : TValue extends ColumnDef ? ColumnToTs<TValue> : unknown;
3509
+ type SelectionResult<TSelection extends Record<string, ColumnSelectionValue>> = {
3510
+ [K in keyof TSelection]: SelectionValueType<TSelection[K]>;
3511
+ };
3512
+ type SelectionFromKeys<TTable extends TableDef, K extends keyof TTable['columns'] & string> = Pick<InferRow<TTable>, K>;
3498
3513
  type DeepSelectEntry<TTable extends TableDef> = {
3499
3514
  type: 'root';
3500
3515
  columns: (keyof TTable['columns'] & string)[];
@@ -3509,7 +3524,7 @@ type DeepSelectConfig<TTable extends TableDef> = DeepSelectEntry<TTable>[];
3509
3524
  * @typeParam T - Result type for projections (unused)
3510
3525
  * @typeParam TTable - Table definition being queried
3511
3526
  */
3512
- declare class SelectQueryBuilder<T = unknown, TTable extends TableDef = TableDef> {
3527
+ declare class SelectQueryBuilder<T = EntityInstance<TableDef>, TTable extends TableDef = TableDef> {
3513
3528
  private readonly env;
3514
3529
  private readonly context;
3515
3530
  private readonly columnSelector;
@@ -3522,6 +3537,7 @@ declare class SelectQueryBuilder<T = unknown, TTable extends TableDef = TableDef
3522
3537
  private readonly relationFacet;
3523
3538
  private readonly lazyRelations;
3524
3539
  private readonly lazyRelationOptions;
3540
+ private readonly entityConstructor?;
3525
3541
  /**
3526
3542
  * Creates a new SelectQueryBuilder instance
3527
3543
  * @param table - Table definition to query
@@ -3529,7 +3545,7 @@ declare class SelectQueryBuilder<T = unknown, TTable extends TableDef = TableDef
3529
3545
  * @param hydration - Optional hydration manager
3530
3546
  * @param dependencies - Optional query builder dependencies
3531
3547
  */
3532
- constructor(table: TTable, state?: SelectQueryState, hydration?: HydrationManager, dependencies?: Partial<SelectQueryBuilderDependencies>, lazyRelations?: Set<string>, lazyRelationOptions?: Map<string, RelationIncludeOptions>);
3548
+ constructor(table: TTable, state?: SelectQueryState, hydration?: HydrationManager, dependencies?: Partial<SelectQueryBuilderDependencies>, lazyRelations?: Set<string>, lazyRelationOptions?: Map<string, RelationIncludeOptions>, entityConstructor?: EntityConstructor);
3533
3549
  /**
3534
3550
  * Creates a new SelectQueryBuilder instance with updated context and lazy relations
3535
3551
  * @param context - Updated query context
@@ -3579,8 +3595,8 @@ declare class SelectQueryBuilder<T = unknown, TTable extends TableDef = TableDef
3579
3595
  * fullName: concat(userTable.columns.firstName, ' ', userTable.columns.lastName)
3580
3596
  * });
3581
3597
  */
3582
- select<K extends keyof TTable['columns'] & string>(...args: K[]): SelectQueryBuilder<T, TTable>;
3583
- select(columns: Record<string, ColumnSelectionValue>): SelectQueryBuilder<T, TTable>;
3598
+ select<K extends keyof TTable['columns'] & string>(...args: K[]): SelectQueryBuilder<T & SelectionFromKeys<TTable, K>, TTable>;
3599
+ select<TSelection extends Record<string, ColumnSelectionValue>>(columns: TSelection): SelectQueryBuilder<T & SelectionResult<TSelection>, TTable>;
3584
3600
  /**
3585
3601
  * Selects raw column expressions
3586
3602
  * @param cols - Column expressions as strings
@@ -3669,7 +3685,7 @@ declare class SelectQueryBuilder<T = unknown, TTable extends TableDef = TableDef
3669
3685
  * qb.select('id', 'name')
3670
3686
  * .selectSubquery('postCount', postCount);
3671
3687
  */
3672
- selectSubquery<TSub extends TableDef>(alias: string, sub: SelectQueryBuilder<unknown, TSub> | SelectQueryNode): SelectQueryBuilder<T, TTable>;
3688
+ selectSubquery<TValue = unknown, K extends string = string, TSub extends TableDef = TableDef>(alias: K, sub: SelectQueryBuilder<unknown, TSub> | SelectQueryNode): SelectQueryBuilder<T & Record<K, TValue>, TTable>;
3673
3689
  /**
3674
3690
  * Adds a JOIN against a derived table (subquery with alias)
3675
3691
  * @param subquery - Subquery to join
@@ -3831,15 +3847,49 @@ declare class SelectQueryBuilder<T = unknown, TTable extends TableDef = TableDef
3831
3847
  */
3832
3848
  getTable(): TTable;
3833
3849
  /**
3834
- * Executes the query and returns hydrated results
3850
+ * Ensures that if no columns are selected, all columns from the table are selected by default.
3851
+ */
3852
+ private ensureDefaultSelection;
3853
+ /**
3854
+ * Executes the query and returns hydrated results.
3855
+ * If the builder was created with an entity constructor (e.g. via selectFromEntity),
3856
+ * this will automatically return fully materialized entity instances.
3857
+ *
3835
3858
  * @param ctx - ORM session context
3836
- * @returns Promise of entity instances
3859
+ * @returns Promise of entity instances (or objects if generic T is not an entity)
3837
3860
  * @example
3838
- * const users = await qb.select('id', 'name')
3839
- * .where(eq(userTable.columns.active, true))
3840
- * .execute(session);
3861
+ * const users = await selectFromEntity(User).execute(session);
3862
+ * // users is User[]
3863
+ * users[0] instanceof User; // true
3864
+ */
3865
+ execute(ctx: OrmSession): Promise<T[]>;
3866
+ /**
3867
+ * Executes the query and returns plain row objects (POJOs), ignoring any entity materialization.
3868
+ * Use this if you want raw data even when using selectFromEntity.
3869
+ *
3870
+ * @param ctx - ORM session context
3871
+ * @returns Promise of plain entity instances
3872
+ * @example
3873
+ * const rows = await selectFromEntity(User).executePlain(session);
3874
+ * // rows is EntityInstance<UserTable>[] (plain objects)
3875
+ * rows[0] instanceof User; // false
3841
3876
  */
3842
- execute(ctx: OrmSession): Promise<EntityInstance<TTable>[]>;
3877
+ executePlain(ctx: OrmSession): Promise<EntityInstance<TTable>[]>;
3878
+ /**
3879
+ * Executes the query and returns results as real class instances.
3880
+ * Unlike execute(), this returns actual instances of the decorated entity class
3881
+ * with working methods and proper instanceof checks.
3882
+ * @param entityClass - The entity class constructor
3883
+ * @param ctx - ORM session context
3884
+ * @returns Promise of entity class instances
3885
+ * @example
3886
+ * const users = await selectFromEntity(User)
3887
+ * .include('posts')
3888
+ * .executeAs(User, session);
3889
+ * users[0] instanceof User; // true!
3890
+ * users[0].getFullName(); // works!
3891
+ */
3892
+ executeAs<TEntity extends object>(entityClass: EntityConstructor<TEntity>, ctx: OrmSession): Promise<TEntity[]>;
3843
3893
  /**
3844
3894
  * Executes a count query for the current builder without LIMIT/OFFSET clauses.
3845
3895
  *
@@ -3857,7 +3907,7 @@ declare class SelectQueryBuilder<T = unknown, TTable extends TableDef = TableDef
3857
3907
  page: number;
3858
3908
  pageSize: number;
3859
3909
  }): Promise<{
3860
- items: EntityInstance<TTable>[];
3910
+ items: T[];
3861
3911
  totalItems: number;
3862
3912
  }>;
3863
3913
  /**
@@ -3870,7 +3920,7 @@ declare class SelectQueryBuilder<T = unknown, TTable extends TableDef = TableDef
3870
3920
  * const hydCtx = new HydrationContext();
3871
3921
  * const users = await qb.executeWithContexts(execCtx, hydCtx);
3872
3922
  */
3873
- executeWithContexts(execCtx: ExecutionContext, hydCtx: HydrationContext): Promise<EntityInstance<TTable>[]>;
3923
+ executeWithContexts(execCtx: ExecutionContext, hydCtx: HydrationContext): Promise<T[]>;
3874
3924
  /**
3875
3925
  * Adds a WHERE condition to the query
3876
3926
  * @param expr - Expression for the WHERE clause
@@ -6060,6 +6110,14 @@ declare class DefaultManyToManyCollection<TTarget, TPivot extends object | undef
6060
6110
  * @returns Promise resolving to array of entity instances
6061
6111
  */
6062
6112
  declare function executeHydrated<TTable extends TableDef>(session: OrmSession, qb: SelectQueryBuilder<unknown, TTable>): Promise<EntityInstance<TTable>[]>;
6113
+ /**
6114
+ * Executes a hydrated query and returns plain row objects (no entity proxies).
6115
+ * @template TTable - The table type
6116
+ * @param session - The ORM session
6117
+ * @param qb - The select query builder
6118
+ * @returns Promise resolving to array of plain row objects
6119
+ */
6120
+ declare function executeHydratedPlain<TTable extends TableDef>(session: OrmSession, qb: SelectQueryBuilder<unknown, TTable>): Promise<Record<string, unknown>[]>;
6063
6121
  /**
6064
6122
  * Executes a hydrated query using execution and hydration contexts.
6065
6123
  * @template TTable - The table type
@@ -6069,6 +6127,14 @@ declare function executeHydrated<TTable extends TableDef>(session: OrmSession, q
6069
6127
  * @returns Promise resolving to array of entity instances
6070
6128
  */
6071
6129
  declare function executeHydratedWithContexts<TTable extends TableDef>(execCtx: ExecutionContext, hydCtx: HydrationContext, qb: SelectQueryBuilder<unknown, TTable>): Promise<EntityInstance<TTable>[]>;
6130
+ /**
6131
+ * Executes a hydrated query using execution context and returns plain row objects.
6132
+ * @template TTable - The table type
6133
+ * @param execCtx - The execution context
6134
+ * @param qb - The select query builder
6135
+ * @returns Promise resolving to array of plain row objects
6136
+ */
6137
+ declare function executeHydratedPlainWithContexts<TTable extends TableDef>(execCtx: ExecutionContext, qb: SelectQueryBuilder<unknown, TTable>): Promise<Record<string, unknown>[]>;
6072
6138
 
6073
6139
  type JsonifyScalar<T> = T extends Date ? string : T;
6074
6140
  /**
@@ -6218,7 +6284,8 @@ type EntityTable<TEntity extends object> = Omit<TableDef<{
6218
6284
  [K in RelationKeys<TEntity>]: NonNullable<TEntity[K]> extends HasManyCollection<infer TChild> ? HasManyRelation<EntityTable<NonNullable<TChild> & object>> : NonNullable<TEntity[K]> extends ManyToManyCollection<infer TTarget, infer TPivot> ? BelongsToManyRelation<EntityTable<NonNullable<TTarget> & object>, TPivot extends object ? EntityTable<NonNullable<TPivot> & object> : TableDef> : NonNullable<TEntity[K]> extends HasOneReference<infer TChild> ? HasOneRelation<EntityTable<NonNullable<TChild> & object>> : NonNullable<TEntity[K]> extends BelongsToReference<infer TParent> ? BelongsToRelation<EntityTable<NonNullable<TParent> & object>> : NonNullable<TEntity[K]> extends object ? BelongsToRelation<EntityTable<NonNullable<TEntity[K]> & object>> : never;
6219
6285
  };
6220
6286
  };
6221
- declare const selectFromEntity: <TEntity extends object>(ctor: EntityConstructor<TEntity>) => SelectQueryBuilder<unknown, EntityTable<TEntity>>;
6287
+ type DecoratedEntityInstance<TEntity extends object> = TEntity & EntityInstance<EntityTable<TEntity>>;
6288
+ declare const selectFromEntity: <TEntity extends object>(ctor: EntityConstructor<TEntity>) => SelectQueryBuilder<DecoratedEntityInstance<TEntity>, EntityTable<TEntity>>;
6222
6289
  /**
6223
6290
  * Public API: opt-in ergonomic entity reference (decorator-level).
6224
6291
  *
@@ -6247,6 +6314,86 @@ interface DecoratorMetadataBag {
6247
6314
  */
6248
6315
  declare const getDecoratorMetadata: (ctor: object) => DecoratorMetadataBag | undefined;
6249
6316
 
6317
+ /**
6318
+ * Strategy interface for materializing entity instances (Open/Closed Principle).
6319
+ */
6320
+ interface EntityMaterializationStrategy {
6321
+ /**
6322
+ * Creates an instance of the entity class and populates it with data.
6323
+ * @param ctor - The entity constructor
6324
+ * @param data - The raw data to populate
6325
+ * @returns The materialized entity instance
6326
+ */
6327
+ materialize<T>(ctor: EntityConstructor<T>, data: Record<string, unknown>): T;
6328
+ }
6329
+ /**
6330
+ * Default strategy: Uses Object.create() to create instance without calling constructor.
6331
+ * Safe for classes with required constructor parameters.
6332
+ */
6333
+ declare class PrototypeMaterializationStrategy implements EntityMaterializationStrategy {
6334
+ materialize<T>(ctor: EntityConstructor<T>, data: Record<string, unknown>): T;
6335
+ }
6336
+ /**
6337
+ * Alternative strategy: Calls default constructor then assigns properties.
6338
+ * Use when class constructor initializes important state.
6339
+ */
6340
+ declare class ConstructorMaterializationStrategy implements EntityMaterializationStrategy {
6341
+ materialize<T>(ctor: EntityConstructor<T>, data: Record<string, unknown>): T;
6342
+ }
6343
+ /**
6344
+ * Interface for materializing query results into real entity class instances.
6345
+ */
6346
+ interface EntityMaterializer {
6347
+ /**
6348
+ * Materializes a single row into a real entity instance.
6349
+ * @param entityClass - The entity constructor
6350
+ * @param row - The raw data row
6351
+ * @returns The materialized entity instance
6352
+ */
6353
+ materialize<T>(entityClass: EntityConstructor<T>, row: Record<string, unknown>): T;
6354
+ /**
6355
+ * Materializes multiple rows into real entity instances.
6356
+ * @param entityClass - The entity constructor
6357
+ * @param rows - The raw data rows
6358
+ * @returns Array of materialized entity instances
6359
+ */
6360
+ materializeMany<T>(entityClass: EntityConstructor<T>, rows: Record<string, unknown>[]): T[];
6361
+ }
6362
+ /**
6363
+ * Default implementation of EntityMaterializer.
6364
+ * Converts query results into actual class instances with working methods.
6365
+ *
6366
+ * @example
6367
+ * const materializer = new DefaultEntityMaterializer();
6368
+ * const users = materializer.materializeMany(User, queryResults);
6369
+ * users[0] instanceof User; // true
6370
+ * users[0].getFullName(); // works!
6371
+ */
6372
+ declare class DefaultEntityMaterializer implements EntityMaterializer {
6373
+ private readonly strategy;
6374
+ constructor(strategy?: EntityMaterializationStrategy);
6375
+ materialize<T>(ctor: EntityConstructor<T>, row: Record<string, unknown>): T;
6376
+ materializeMany<T>(ctor: EntityConstructor<T>, rows: Record<string, unknown>[]): T[];
6377
+ /**
6378
+ * Recursively materializes nested relation data.
6379
+ */
6380
+ private materializeRelations;
6381
+ /**
6382
+ * Simple heuristic to check if an object looks like an entity.
6383
+ */
6384
+ private isEntityLike;
6385
+ private materializeEntityProxy;
6386
+ }
6387
+ /**
6388
+ * Convenience function to materialize query results as real class instances.
6389
+ *
6390
+ * @example
6391
+ * const results = await selectFromEntity(User).execute(session);
6392
+ * const users = materializeAs(User, results);
6393
+ * users[0] instanceof User; // true!
6394
+ */
6395
+ declare const materializeAs: <TEntity extends object>(ctor: EntityConstructor<TEntity>, results: Record<string, unknown>[]) => TEntity[];
6396
+
6250
6397
  type PoolOptions = {
6251
6398
  /** Maximum number of live resources (idle + leased). */
6252
6399
  max: number;
@@ -6410,4 +6557,4 @@ type PooledExecutorFactoryOptions<TConn> = {
6410
6557
  */
6411
6558
  declare function createPooledExecutorFactory<TConn>(opts: PooledExecutorFactoryOptions<TConn>): DbExecutorFactory;
6412
6559
 
6413
- export { type AliasRefNode, type AnyDomainEvent, type ArithmeticExpressionNode, type TableRef as AstTableRef, AsyncLocalStorage, BelongsTo, BelongsToMany, type BelongsToManyOptions, type BelongsToManyRelation, type BelongsToOptions, type BelongsToReference, type BelongsToReferenceApi, type BelongsToRelation, type BetweenExpressionNode, type BinaryExpressionNode, type BitwiseExpressionNode, type CascadeMode, type CaseExpressionNode, type CastExpressionNode, type CheckConstraint, type CollateExpressionNode, Column, type ColumnDef, type ColumnDiff, type ColumnInput, type ColumnNode, type ColumnOptions, type ColumnRef, type ColumnToTs, type ColumnType, type CreateTediousClientOptions, type DatabaseCheck, type DatabaseColumn, type DatabaseIndex, type DatabaseSchema, type DatabaseTable, type DbExecutor, type DbExecutorFactory, DefaultBelongsToReference, DefaultHasManyCollection, DefaultManyToManyCollection, type DefaultValue, DeleteQueryBuilder, type DialectName, type DomainEvent, DomainEventBus, type DomainEventHandler, Entity, type EntityContext, type EntityInstance, type EntityOptions, EntityStatus, type ExecutionContext, type ExistsExpressionNode, type ExpressionNode, type ExpressionVisitor, type ForeignKeyReference, type FunctionNode, type GroupConcatOptions, type HasDomainEvents, HasMany, type HasManyCollection, type HasManyOptions, type HasManyRelation, HasOne, type HasOneOptions, type HasOneReference, type HasOneReferenceApi, type HasOneRelation, type HydrationContext, type HydrationMetadata, type HydrationPivotPlan, type HydrationPlan, type HydrationRelationPlan, type InExpressionNode, type InExpressionRight, type IndexColumn, type IndexDef, type InferRow, type InitialHandlers, InsertQueryBuilder, type IntrospectOptions, type JsonPathNode, type Jsonify, type JsonifyScalar, type LiteralNode, type LiteralValue, type LogicalExpressionNode, type ManyToManyCollection, type MssqlClientLike, MySqlDialect, type MysqlClientLike, type NullExpressionNode, type OperandNode, type OperandVisitor, Orm, type OrmDomainEvent, type OrmInterceptor, type OrmOptions, OrmSession, type OrmSessionOptions, Pool, type PoolAdapter, type PoolLease, type PoolOptions, type PooledConnectionAdapter, type PostgresClientLike, PostgresDialect, PrimaryKey, type Primitive, type QueryLogEntry, type QueryLogger, type QueryResult, type RawDefaultValue, type ReferentialAction, type RelationChange, type RelationChangeEntry, type RelationDef, type RelationKey$1 as RelationKey, RelationKinds, type RelationMap, type RelationTargetTable, type RelationType, type RenderColumnOptions, STANDARD_COLUMN_TYPES, type SaveGraphInputPayload, type SaveGraphInputScalar, type SaveGraphJsonScalar, type ScalarSubqueryNode, type SchemaChange, type SchemaChangeKind, type SchemaDiffOptions, type SchemaGenerateResult, type SchemaIntrospector, type SchemaPlan, SelectQueryBuilder, type SelectQueryInput, type SelectableKeys, type SimpleQueryRunner, SqlServerDialect, type SqliteClientLike, SqliteDialect, type StandardColumnType, type SynchronizeOptions, type TableDef, type TableHooks, type TableOptions, type TableRef$1 as TableRef, type TediousColumn, type TediousConnectionLike, type TediousModule, type TediousRequest, type TediousRequestCtor, type TediousTypes, type TrackedEntity, TypeScriptGenerator, UpdateQueryBuilder, type ValueOperandInput, type WindowFunctionNode, abs, acos, add, addDomainEvent, age, aliasRef, and, arrayAppend, ascii, asin, atan, atan2, avg, belongsTo, belongsToMany, between, bitAnd, bitLength, bitOr, bitXor, bootstrapEntities, caseWhen, cast, cbrt, ceil, ceiling, char, charLength, chr, clearExpressionDispatchers, clearOperandDispatchers, coalesce, col, collate, columnOperand, concat, concatWs, correlateBy, cos, cot, count, countAll, createEntityFromRow, createEntityProxy, createExecutorFromQueryRunner, createMssqlExecutor, createMysqlExecutor, createPooledExecutorFactory, createPostgresExecutor, createQueryLoggingExecutor, createSqliteExecutor, createTediousExecutor, createTediousMssqlClient, currentDate, currentTime, dateAdd, dateDiff, dateFormat, dateSub, dateTrunc, day, dayOfWeek, defineTable, degrees, deleteFrom, denseRank, diffSchema, div, endOfMonth, entityRef, eq, esel, executeHydrated, executeHydratedWithContexts, executeSchemaSql, executeSchemaSqlFor, exists, exp, extract, firstValue, floor, fromUnixTime, generateCreateTableSql, generateSchemaSql, generateSchemaSqlFor, getColumn, getDecoratorMetadata, getSchemaIntrospector, getTableDefFromEntity, greatest, groupConcat, gt, gte, hasMany, hasOne, hour, hydrateRows, ifNull, inList, inSubquery, initcap, insertInto, instr, introspectSchema, isCaseExpressionNode, isCastExpressionNode, isCollateExpressionNode, isExpressionSelectionNode, isFunctionNode, isNotNull, isNull, isOperandNode, isValueOperandInput, isWindowFunctionNode, jsonArrayAgg, jsonContains, jsonLength, jsonPath, jsonSet, jsonify, lag, lastValue, lead, least, left, length, like, ln, loadBelongsToManyRelation, loadBelongsToRelation, loadHasManyRelation, loadHasOneRelation, localTime, localTimestamp, locate, log, log10, log2, logBase, lower, lpad, lt, lte, ltrim, max, md5, min, minute, mod, month, mul, neq, normalizeColumnType, notBetween, notExists, notInList, notInSubquery, notLike, now, ntile, nullif, octetLength, or, outerRef, pi, position, pow, power, quarter, radians, rand, random, rank, registerExpressionDispatcher, registerOperandDispatcher, registerSchemaIntrospector, relationLoaderCache, renderColumnDefinition, renderTypeWithArgs, repeat, replace, reverse, right, round, rowNumber, rowsToQueryResult, rpad, rtrim, second, sel, selectFrom, selectFromEntity, setRelations, sha1, sha2, shiftLeft, shiftRight, sign, sin, space, sqrt, stddev, sub, substr, sum, synchronizeSchema, tableRef, tan, toColumnRef, toTableRef, trim, trunc, truncate, unixTimestamp, update, upper, utcNow, valueToOperand, variance, visitExpression, visitOperand, weekOfYear, windowFunction, year };
6560
+ export { type AliasRefNode, type AnyDomainEvent, type ArithmeticExpressionNode, type TableRef as AstTableRef, AsyncLocalStorage, BelongsTo, BelongsToMany, type BelongsToManyOptions, type BelongsToManyRelation, type BelongsToOptions, type BelongsToReference, type BelongsToReferenceApi, type BelongsToRelation, type BetweenExpressionNode, type BinaryExpressionNode, type BitwiseExpressionNode, type CascadeMode, type CaseExpressionNode, type CastExpressionNode, type CheckConstraint, type CollateExpressionNode, Column, type ColumnDef, type ColumnDiff, type ColumnInput, type ColumnNode, type ColumnOptions, type ColumnRef, type ColumnToTs, type ColumnType, ConstructorMaterializationStrategy, type CreateTediousClientOptions, type DatabaseCheck, type DatabaseColumn, type DatabaseIndex, type DatabaseSchema, type DatabaseTable, type DbExecutor, type DbExecutorFactory, type DecoratedEntityInstance, DefaultBelongsToReference, DefaultEntityMaterializer, DefaultHasManyCollection, DefaultManyToManyCollection, type DefaultValue, DeleteQueryBuilder, type DialectName, type DomainEvent, DomainEventBus, type DomainEventHandler, Entity, type EntityContext, type EntityInstance, type EntityMaterializationStrategy, type EntityMaterializer, type EntityOptions, EntityStatus, type ExecutionContext, type ExistsExpressionNode, type ExpressionNode, type ExpressionVisitor, type ForeignKeyReference, type FunctionNode, type GroupConcatOptions, type HasDomainEvents, HasMany, type HasManyCollection, type HasManyOptions, type HasManyRelation, HasOne, type HasOneOptions, type HasOneReference, type HasOneReferenceApi, type HasOneRelation, type HydrationContext, type HydrationMetadata, type HydrationPivotPlan, type HydrationPlan, type HydrationRelationPlan, type InExpressionNode, type InExpressionRight, type IndexColumn, type IndexDef, type InferRow, type InitialHandlers, InsertQueryBuilder, type IntrospectOptions, type JsonPathNode, type Jsonify, type JsonifyScalar, type LiteralNode, type LiteralValue, type LogicalExpressionNode, type ManyToManyCollection, type MssqlClientLike, MySqlDialect, type MysqlClientLike, type NullExpressionNode, type OperandNode, type OperandVisitor, Orm, type OrmDomainEvent, type OrmInterceptor, type OrmOptions, OrmSession, type OrmSessionOptions, Pool, type PoolAdapter, type PoolLease, type PoolOptions, type PooledConnectionAdapter, type PostgresClientLike, PostgresDialect, PrimaryKey, type Primitive, PrototypeMaterializationStrategy, type QueryLogEntry, type QueryLogger, type QueryResult, type RawDefaultValue, type ReferentialAction, type RelationChange, type RelationChangeEntry, type RelationDef, type RelationKey$1 as RelationKey, RelationKinds, type RelationMap, type RelationTargetTable, type RelationType, type RenderColumnOptions, STANDARD_COLUMN_TYPES, type SaveGraphInputPayload, type SaveGraphInputScalar, type SaveGraphJsonScalar, type ScalarSubqueryNode, type SchemaChange, type SchemaChangeKind, type SchemaDiffOptions, type SchemaGenerateResult, type SchemaIntrospector, type SchemaPlan, SelectQueryBuilder, type SelectQueryInput, type SelectableKeys, type SimpleQueryRunner, SqlServerDialect, type SqliteClientLike, SqliteDialect, type StandardColumnType, type SynchronizeOptions, type TableDef, type TableHooks, type TableOptions, type TableRef$1 as TableRef, type TediousColumn, type TediousConnectionLike, type TediousModule, type TediousRequest, type TediousRequestCtor, type TediousTypes, type TrackedEntity, TypeScriptGenerator, type TypedExpression, UpdateQueryBuilder, type ValueOperandInput, type WindowFunctionNode, abs, acos, add, addDomainEvent, age, aliasRef, and, arrayAppend, asType, ascii, asin, atan, atan2, avg, belongsTo, belongsToMany, between, bitAnd, bitLength, bitOr, bitXor, bootstrapEntities, caseWhen, cast, cbrt, ceil, ceiling, char, charLength, chr, clearExpressionDispatchers, clearOperandDispatchers, coalesce, col, collate, columnOperand, concat, concatWs, correlateBy, cos, cot, count, countAll, createEntityFromRow, createEntityProxy, createExecutorFromQueryRunner, createMssqlExecutor, createMysqlExecutor, createPooledExecutorFactory, createPostgresExecutor, createQueryLoggingExecutor, createSqliteExecutor, createTediousExecutor, createTediousMssqlClient, currentDate, currentTime, dateAdd, dateDiff, dateFormat, dateSub, dateTrunc, day, dayOfWeek, defineTable, degrees, deleteFrom, denseRank, diffSchema, div, endOfMonth, entityRef, eq, esel, executeHydrated, executeHydratedPlain, executeHydratedPlainWithContexts, executeHydratedWithContexts, executeSchemaSql, executeSchemaSqlFor, exists, exp, extract, firstValue, floor, fromUnixTime, generateCreateTableSql, generateSchemaSql, generateSchemaSqlFor, getColumn, getDecoratorMetadata, getSchemaIntrospector, getTableDefFromEntity, greatest, groupConcat, gt, gte, hasMany, hasOne, hour, hydrateRows, ifNull, inList, inSubquery, initcap, insertInto, instr, introspectSchema, isCaseExpressionNode, isCastExpressionNode, isCollateExpressionNode, isExpressionSelectionNode, isFunctionNode, isNotNull, isNull, isOperandNode, isValueOperandInput, isWindowFunctionNode, jsonArrayAgg, jsonContains, jsonLength, jsonPath, jsonSet, jsonify, lag, lastValue, lead, least, left, length, like, ln, loadBelongsToManyRelation, loadBelongsToRelation, loadHasManyRelation, loadHasOneRelation, localTime, localTimestamp, locate, log, log10, log2, logBase, lower, lpad, lt, lte, ltrim, materializeAs, max, md5, min, minute, mod, month, mul, neq, normalizeColumnType, notBetween, notExists, notInList, notInSubquery, notLike, now, ntile, nullif, octetLength, or, outerRef, pi, position, pow, power, quarter, radians, rand, random, rank, registerExpressionDispatcher, registerOperandDispatcher, registerSchemaIntrospector, relationLoaderCache, renderColumnDefinition, renderTypeWithArgs, repeat, replace, reverse, right, round, rowNumber, rowsToQueryResult, rpad, rtrim, second, sel, selectFrom, selectFromEntity, setRelations, sha1, sha2, shiftLeft, shiftRight, sign, sin, space, sqrt, stddev, sub, substr, sum, synchronizeSchema, tableRef, tan, toColumnRef, toTableRef, trim, trunc, truncate, unixTimestamp, update, upper, utcNow, valueToOperand, variance, visitExpression, visitOperand, weekOfYear, windowFunction, year };