metal-orm 1.0.58 → 1.0.59
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 +34 -31
- package/dist/index.cjs +1463 -1003
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +148 -129
- package/dist/index.d.ts +148 -129
- package/dist/index.js +1459 -1003
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/core/ddl/schema-generator.ts +44 -1
- package/src/decorators/bootstrap.ts +183 -146
- package/src/decorators/column-decorator.ts +8 -49
- package/src/decorators/decorator-metadata.ts +10 -46
- package/src/decorators/entity.ts +30 -40
- package/src/decorators/relations.ts +30 -56
- package/src/orm/entity-hydration.ts +72 -0
- package/src/orm/entity-meta.ts +13 -11
- package/src/orm/entity-metadata.ts +240 -238
- package/src/orm/entity-relation-cache.ts +39 -0
- package/src/orm/entity-relations.ts +207 -0
- package/src/orm/entity.ts +124 -410
- package/src/orm/execute.ts +4 -4
- package/src/orm/lazy-batch/belongs-to-many.ts +134 -0
- package/src/orm/lazy-batch/belongs-to.ts +108 -0
- package/src/orm/lazy-batch/has-many.ts +69 -0
- package/src/orm/lazy-batch/has-one.ts +68 -0
- package/src/orm/lazy-batch/shared.ts +125 -0
- package/src/orm/lazy-batch.ts +4 -492
- package/src/orm/relations/many-to-many.ts +2 -1
- package/src/query-builder/relation-cte-builder.ts +63 -0
- package/src/query-builder/relation-filter-utils.ts +159 -0
- package/src/query-builder/relation-include-strategies.ts +177 -0
- package/src/query-builder/relation-join-planner.ts +80 -0
- package/src/query-builder/relation-service.ts +119 -479
- package/src/query-builder/relation-types.ts +41 -10
- package/src/query-builder/select/projection-facet.ts +23 -23
- package/src/query-builder/select/select-operations.ts +145 -0
- package/src/query-builder/select.ts +351 -422
- package/src/schema/relation.ts +22 -18
- package/src/schema/table.ts +22 -9
- package/src/schema/types.ts +14 -12
package/dist/index.d.cts
CHANGED
|
@@ -251,10 +251,10 @@ interface BelongsToRelation<TTarget extends TableDef = TableDef> {
|
|
|
251
251
|
/**
|
|
252
252
|
* Many-to-many relationship definition with rich pivot metadata
|
|
253
253
|
*/
|
|
254
|
-
interface BelongsToManyRelation<TTarget extends TableDef = TableDef> {
|
|
254
|
+
interface BelongsToManyRelation<TTarget extends TableDef = TableDef, TPivot extends TableDef = TableDef> {
|
|
255
255
|
type: typeof RelationKinds.BelongsToMany;
|
|
256
256
|
target: TTarget;
|
|
257
|
-
pivotTable:
|
|
257
|
+
pivotTable: TPivot;
|
|
258
258
|
pivotForeignKeyToRoot: string;
|
|
259
259
|
pivotForeignKeyToTarget: string;
|
|
260
260
|
localKey?: string;
|
|
@@ -308,7 +308,7 @@ declare const belongsTo: <TTarget extends TableDef>(target: TTarget, foreignKey:
|
|
|
308
308
|
* @param options - Pivot metadata configuration
|
|
309
309
|
* @returns BelongsToManyRelation definition
|
|
310
310
|
*/
|
|
311
|
-
declare const belongsToMany: <TTarget extends TableDef>(target: TTarget, pivotTable:
|
|
311
|
+
declare const belongsToMany: <TTarget extends TableDef, TPivot extends TableDef = TableDef>(target: TTarget, pivotTable: TPivot, options: {
|
|
312
312
|
pivotForeignKeyToRoot: string;
|
|
313
313
|
pivotForeignKeyToTarget: string;
|
|
314
314
|
localKey?: string;
|
|
@@ -316,7 +316,7 @@ declare const belongsToMany: <TTarget extends TableDef>(target: TTarget, pivotTa
|
|
|
316
316
|
pivotPrimaryKey?: string;
|
|
317
317
|
defaultPivotColumns?: string[];
|
|
318
318
|
cascade?: CascadeMode;
|
|
319
|
-
}) => BelongsToManyRelation<TTarget>;
|
|
319
|
+
}) => BelongsToManyRelation<TTarget, TPivot>;
|
|
320
320
|
|
|
321
321
|
interface IndexColumn {
|
|
322
322
|
column: string;
|
|
@@ -397,6 +397,12 @@ interface TableDef<T extends Record<string, ColumnDef> = Record<string, ColumnDe
|
|
|
397
397
|
* ```
|
|
398
398
|
*/
|
|
399
399
|
declare const defineTable: <T extends Record<string, ColumnDef>>(name: string, columns: T, relations?: Record<string, RelationDef>, hooks?: TableHooks, options?: TableOptions) => TableDef<T>;
|
|
400
|
+
/**
|
|
401
|
+
* Assigns relations to a table definition while preserving literal typing.
|
|
402
|
+
*/
|
|
403
|
+
declare function setRelations<TTable extends TableDef, TRelations extends Record<string, RelationDef>>(table: TTable, relations: TRelations): asserts table is TTable & {
|
|
404
|
+
relations: TRelations;
|
|
405
|
+
};
|
|
400
406
|
type DirectColumnKeys<T extends TableDef> = Exclude<keyof T["columns"] & string, keyof T | "$">;
|
|
401
407
|
type TableRef$1<T extends TableDef> = T & {
|
|
402
408
|
[K in DirectColumnKeys<T>]: T["columns"][K];
|
|
@@ -438,7 +444,7 @@ declare function getColumn<T extends TableDef>(table: T, key: string): ColumnDef
|
|
|
438
444
|
/**
|
|
439
445
|
* Resolves a relation definition to its target table type.
|
|
440
446
|
*/
|
|
441
|
-
type RelationTargetTable<TRel extends RelationDef> = TRel extends HasManyRelation<infer TTarget> ? TTarget : TRel extends HasOneRelation<infer TTarget> ? TTarget : TRel extends BelongsToRelation<infer TTarget> ? TTarget : TRel extends BelongsToManyRelation<infer TTarget> ? TTarget : never;
|
|
447
|
+
type RelationTargetTable<TRel extends RelationDef> = TRel extends HasManyRelation<infer TTarget> ? TTarget : TRel extends HasOneRelation<infer TTarget> ? TTarget : TRel extends BelongsToRelation<infer TTarget> ? TTarget : TRel extends BelongsToManyRelation<infer TTarget, TableDef> ? TTarget : never;
|
|
442
448
|
type NormalizedColumnType<T extends ColumnDef> = Lowercase<T['type'] & string>;
|
|
443
449
|
/**
|
|
444
450
|
* Maps a ColumnDef to its TypeScript type representation
|
|
@@ -452,7 +458,7 @@ type ColumnToTs<T extends ColumnDef> = [
|
|
|
452
458
|
type InferRow<TTable extends TableDef> = {
|
|
453
459
|
[K in keyof TTable['columns']]: ColumnToTs<TTable['columns'][K]>;
|
|
454
460
|
};
|
|
455
|
-
type RelationResult$1<T extends RelationDef> = T extends HasManyRelation<infer TTarget> ? InferRow<TTarget>[] : T extends HasOneRelation<infer TTarget> ? InferRow<TTarget> | null : T extends BelongsToRelation<infer TTarget> ? InferRow<TTarget> | null : T extends BelongsToManyRelation<infer TTarget> ? (InferRow<TTarget> & {
|
|
461
|
+
type RelationResult$1<T extends RelationDef> = T extends HasManyRelation<infer TTarget> ? InferRow<TTarget>[] : T extends HasOneRelation<infer TTarget> ? InferRow<TTarget> | null : T extends BelongsToRelation<infer TTarget> ? InferRow<TTarget> | null : T extends BelongsToManyRelation<infer TTarget, TableDef> ? (InferRow<TTarget> & {
|
|
456
462
|
_pivot?: Record<string, unknown>;
|
|
457
463
|
})[] : never;
|
|
458
464
|
/**
|
|
@@ -488,7 +494,7 @@ interface HasOneReferenceApi<TChild extends object = object> {
|
|
|
488
494
|
set(data: Partial<TChild> | TChild | null): TChild | null;
|
|
489
495
|
}
|
|
490
496
|
type HasOneReference<TChild extends object = object> = HasOneReferenceApi<TChild> & Partial<TChild>;
|
|
491
|
-
interface ManyToManyCollection<TTarget> {
|
|
497
|
+
interface ManyToManyCollection<TTarget, TPivot extends object | undefined = undefined> {
|
|
492
498
|
length: number;
|
|
493
499
|
[Symbol.iterator](): Iterator<TTarget>;
|
|
494
500
|
load(): Promise<TTarget[]>;
|
|
@@ -496,6 +502,8 @@ interface ManyToManyCollection<TTarget> {
|
|
|
496
502
|
attach(target: TTarget | number | string): void;
|
|
497
503
|
detach(target: TTarget | number | string): void;
|
|
498
504
|
syncByIds(ids: (number | string)[]): Promise<void>;
|
|
505
|
+
/** @internal Type-level marker for the related pivot entity */
|
|
506
|
+
readonly __pivotType?: TPivot;
|
|
499
507
|
}
|
|
500
508
|
type EntityInstance<TTable extends TableDef, TRow = InferRow<TTable>> = TRow & {
|
|
501
509
|
[K in keyof RelationMap<TTable>]: RelationWrapper$1<TTable['relations'][K]>;
|
|
@@ -2157,10 +2165,25 @@ interface RelationIncludeOptions {
|
|
|
2157
2165
|
filter?: ExpressionNode;
|
|
2158
2166
|
joinKind?: RelationIncludeJoinKind;
|
|
2159
2167
|
pivot?: {
|
|
2160
|
-
columns?: string[];
|
|
2168
|
+
columns?: readonly string[];
|
|
2161
2169
|
aliasPrefix?: string;
|
|
2162
2170
|
};
|
|
2163
2171
|
}
|
|
2172
|
+
type ColumnKeys$1<T> = T extends {
|
|
2173
|
+
columns: infer Columns;
|
|
2174
|
+
} ? keyof Columns & string : string;
|
|
2175
|
+
type PivotColumnKeys<TPivot> = ColumnKeys$1<TPivot> extends never ? string : ColumnKeys$1<TPivot>;
|
|
2176
|
+
type RelationTargetColumns<TRel extends RelationDef> = ColumnKeys$1<RelationTargetTable<TRel>>;
|
|
2177
|
+
type BelongsToManyPivotColumns<TRel extends RelationDef> = TRel extends BelongsToManyRelation<TableDef, infer TPivot> ? PivotColumnKeys<TPivot> : never;
|
|
2178
|
+
type TypedRelationIncludeOptions<TRel extends RelationDef> = TRel extends BelongsToManyRelation ? Omit<RelationIncludeOptions, 'columns' | 'pivot'> & {
|
|
2179
|
+
columns?: readonly RelationTargetColumns<TRel>[];
|
|
2180
|
+
pivot?: {
|
|
2181
|
+
columns?: readonly BelongsToManyPivotColumns<TRel>[];
|
|
2182
|
+
aliasPrefix?: string;
|
|
2183
|
+
};
|
|
2184
|
+
} : Omit<RelationIncludeOptions, 'columns' | 'pivot'> & {
|
|
2185
|
+
columns?: readonly RelationTargetColumns<TRel>[];
|
|
2186
|
+
};
|
|
2164
2187
|
|
|
2165
2188
|
/**
|
|
2166
2189
|
* Service for handling relation operations (joins, includes, etc.)
|
|
@@ -2171,6 +2194,8 @@ declare class RelationService {
|
|
|
2171
2194
|
private readonly hydration;
|
|
2172
2195
|
private readonly createQueryAstService;
|
|
2173
2196
|
private readonly projectionHelper;
|
|
2197
|
+
private readonly joinPlanner;
|
|
2198
|
+
private readonly cteBuilder;
|
|
2174
2199
|
/**
|
|
2175
2200
|
* Creates a new RelationService instance
|
|
2176
2201
|
* @param table - Table definition
|
|
@@ -2207,15 +2232,6 @@ declare class RelationService {
|
|
|
2207
2232
|
* @returns Modified query AST with relation correlation
|
|
2208
2233
|
*/
|
|
2209
2234
|
applyRelationCorrelation(relationName: string, ast: SelectQueryNode, additionalCorrelation?: ExpressionNode): SelectQueryNode;
|
|
2210
|
-
/**
|
|
2211
|
-
* Creates a join node for a relation
|
|
2212
|
-
* @param state - Current query state
|
|
2213
|
-
* @param relationName - Name of the relation
|
|
2214
|
-
* @param joinKind - Type of join to use
|
|
2215
|
-
* @param extraCondition - Additional join condition
|
|
2216
|
-
* @returns Updated query state with join
|
|
2217
|
-
*/
|
|
2218
|
-
private withJoin;
|
|
2219
2235
|
/**
|
|
2220
2236
|
* Selects columns for a relation
|
|
2221
2237
|
* @param state - Current query state
|
|
@@ -2225,16 +2241,6 @@ declare class RelationService {
|
|
|
2225
2241
|
*/
|
|
2226
2242
|
private selectColumns;
|
|
2227
2243
|
private combineWithAnd;
|
|
2228
|
-
private splitFilterExpressions;
|
|
2229
|
-
private flattenAnd;
|
|
2230
|
-
private isExpressionSelfContained;
|
|
2231
|
-
private collectReferencedTables;
|
|
2232
|
-
private collectFromExpression;
|
|
2233
|
-
private collectFromOperand;
|
|
2234
|
-
private collectFromOrderingTerm;
|
|
2235
|
-
private createFilteredRelationCte;
|
|
2236
|
-
private generateUniqueCteName;
|
|
2237
|
-
private resolveTargetTableName;
|
|
2238
2244
|
/**
|
|
2239
2245
|
* Gets a relation definition by name
|
|
2240
2246
|
* @param relationName - Name of the relation
|
|
@@ -2474,8 +2480,9 @@ type EntityConstructor<T = object> = new (...args: never[]) => T;
|
|
|
2474
2480
|
type EntityOrTableTarget = EntityConstructor | TableDef;
|
|
2475
2481
|
/**
|
|
2476
2482
|
* Resolver for entity or table target, can be direct or function.
|
|
2483
|
+
* @typeParam T - Specific target type that should be resolved
|
|
2477
2484
|
*/
|
|
2478
|
-
type EntityOrTableTargetResolver = EntityOrTableTarget | (() =>
|
|
2485
|
+
type EntityOrTableTargetResolver<T extends EntityOrTableTarget = EntityOrTableTarget> = T | (() => T);
|
|
2479
2486
|
/**
|
|
2480
2487
|
* Simplified column definition structure used during metadata registration.
|
|
2481
2488
|
* @template T - Concrete column definition type being extended
|
|
@@ -2499,7 +2506,7 @@ interface HasManyRelationMetadata extends BaseRelationMetadata {
|
|
|
2499
2506
|
/** The relation kind */
|
|
2500
2507
|
kind: typeof RelationKinds.HasMany;
|
|
2501
2508
|
/** The foreign key */
|
|
2502
|
-
foreignKey
|
|
2509
|
+
foreignKey?: string;
|
|
2503
2510
|
/** Optional local key */
|
|
2504
2511
|
localKey?: string;
|
|
2505
2512
|
}
|
|
@@ -2510,7 +2517,7 @@ interface HasOneRelationMetadata extends BaseRelationMetadata {
|
|
|
2510
2517
|
/** The relation kind */
|
|
2511
2518
|
kind: typeof RelationKinds.HasOne;
|
|
2512
2519
|
/** The foreign key */
|
|
2513
|
-
foreignKey
|
|
2520
|
+
foreignKey?: string;
|
|
2514
2521
|
/** Optional local key */
|
|
2515
2522
|
localKey?: string;
|
|
2516
2523
|
}
|
|
@@ -2534,9 +2541,9 @@ interface BelongsToManyRelationMetadata extends BaseRelationMetadata {
|
|
|
2534
2541
|
/** The pivot table */
|
|
2535
2542
|
pivotTable: EntityOrTableTargetResolver;
|
|
2536
2543
|
/** The pivot foreign key to root */
|
|
2537
|
-
pivotForeignKeyToRoot
|
|
2544
|
+
pivotForeignKeyToRoot?: string;
|
|
2538
2545
|
/** The pivot foreign key to target */
|
|
2539
|
-
pivotForeignKeyToTarget
|
|
2546
|
+
pivotForeignKeyToTarget?: string;
|
|
2540
2547
|
/** Optional local key */
|
|
2541
2548
|
localKey?: string;
|
|
2542
2549
|
/** Optional target key */
|
|
@@ -2584,7 +2591,7 @@ interface TrackedEntity {
|
|
|
2584
2591
|
/**
|
|
2585
2592
|
* Type representing a key for relation navigation
|
|
2586
2593
|
*/
|
|
2587
|
-
type RelationKey = string;
|
|
2594
|
+
type RelationKey$1 = string;
|
|
2588
2595
|
/**
|
|
2589
2596
|
* Represents a change operation on a relation
|
|
2590
2597
|
* @typeParam T - Type of the related entity
|
|
@@ -2609,7 +2616,7 @@ interface RelationChangeEntry {
|
|
|
2609
2616
|
/** Root entity that owns the relation */
|
|
2610
2617
|
root: unknown;
|
|
2611
2618
|
/** Key of the relation being changed */
|
|
2612
|
-
relationKey: RelationKey;
|
|
2619
|
+
relationKey: RelationKey$1;
|
|
2613
2620
|
/** Table definition of the root entity */
|
|
2614
2621
|
rootTable: TableDef;
|
|
2615
2622
|
/** Name of the relation */
|
|
@@ -3197,7 +3204,7 @@ interface EntityContext {
|
|
|
3197
3204
|
* @param relation - The relation definition
|
|
3198
3205
|
* @param change - The relation change
|
|
3199
3206
|
*/
|
|
3200
|
-
registerRelationChange(root: unknown, relationKey: RelationKey, rootTable: TableDef, relationName: string, relation: RelationDef, change: RelationChange<unknown>): void;
|
|
3207
|
+
registerRelationChange(root: unknown, relationKey: RelationKey$1, rootTable: TableDef, relationName: string, relation: RelationDef, change: RelationChange<unknown>): void;
|
|
3201
3208
|
}
|
|
3202
3209
|
|
|
3203
3210
|
/**
|
|
@@ -3380,7 +3387,7 @@ declare class OrmSession<E extends DomainEvent = OrmDomainEvent> implements Enti
|
|
|
3380
3387
|
* @param relation - The relation definition
|
|
3381
3388
|
* @param change - The relation change
|
|
3382
3389
|
*/
|
|
3383
|
-
registerRelationChange: (root: unknown, relationKey: RelationKey, rootTable: TableDef, relationName: string, relation: RelationDef, change: RelationChange<unknown>) => void;
|
|
3390
|
+
registerRelationChange: (root: unknown, relationKey: RelationKey$1, rootTable: TableDef, relationName: string, relation: RelationDef, change: RelationChange<unknown>) => void;
|
|
3384
3391
|
/**
|
|
3385
3392
|
* Gets all tracked entities for a specific table.
|
|
3386
3393
|
* @param table - The table definition
|
|
@@ -3480,6 +3487,11 @@ declare class OrmSession<E extends DomainEvent = OrmDomainEvent> implements Enti
|
|
|
3480
3487
|
getHydrationContext(): HydrationContext<E>;
|
|
3481
3488
|
}
|
|
3482
3489
|
|
|
3490
|
+
type WhereHasOptions = {
|
|
3491
|
+
correlate?: ExpressionNode;
|
|
3492
|
+
};
|
|
3493
|
+
type RelationCallback = <TChildTable extends TableDef>(qb: SelectQueryBuilder<unknown, TChildTable>) => SelectQueryBuilder<unknown, TChildTable>;
|
|
3494
|
+
|
|
3483
3495
|
type SelectDialectInput = Dialect | DialectKey;
|
|
3484
3496
|
|
|
3485
3497
|
type ColumnSelectionValue = ColumnDef | FunctionNode | CaseExpressionNode | WindowFunctionNode;
|
|
@@ -3492,10 +3504,6 @@ type DeepSelectEntry<TTable extends TableDef> = {
|
|
|
3492
3504
|
columns: string[];
|
|
3493
3505
|
};
|
|
3494
3506
|
type DeepSelectConfig<TTable extends TableDef> = DeepSelectEntry<TTable>[];
|
|
3495
|
-
type WhereHasOptions = {
|
|
3496
|
-
correlate?: ExpressionNode;
|
|
3497
|
-
};
|
|
3498
|
-
type RelationCallback = <TChildTable extends TableDef>(qb: SelectQueryBuilder<unknown, TChildTable>) => SelectQueryBuilder<unknown, TChildTable>;
|
|
3499
3507
|
/**
|
|
3500
3508
|
* Main query builder class for constructing SQL SELECT queries
|
|
3501
3509
|
* @typeParam T - Result type for projections (unused)
|
|
@@ -3505,7 +3513,13 @@ declare class SelectQueryBuilder<T = unknown, TTable extends TableDef = TableDef
|
|
|
3505
3513
|
private readonly env;
|
|
3506
3514
|
private readonly context;
|
|
3507
3515
|
private readonly columnSelector;
|
|
3508
|
-
private readonly
|
|
3516
|
+
private readonly fromFacet;
|
|
3517
|
+
private readonly joinFacet;
|
|
3518
|
+
private readonly projectionFacet;
|
|
3519
|
+
private readonly predicateFacet;
|
|
3520
|
+
private readonly cteFacet;
|
|
3521
|
+
private readonly setOpFacet;
|
|
3522
|
+
private readonly relationFacet;
|
|
3509
3523
|
private readonly lazyRelations;
|
|
3510
3524
|
private readonly lazyRelationOptions;
|
|
3511
3525
|
/**
|
|
@@ -3541,22 +3555,6 @@ declare class SelectQueryBuilder<T = unknown, TTable extends TableDef = TableDef
|
|
|
3541
3555
|
* @returns New SelectQueryBuilder instance for the child table
|
|
3542
3556
|
*/
|
|
3543
3557
|
private createChildBuilder;
|
|
3544
|
-
/**
|
|
3545
|
-
* Applies an AST mutation using the query AST service
|
|
3546
|
-
* @param context - Current query context
|
|
3547
|
-
* @param mutator - Function that mutates the AST
|
|
3548
|
-
* @returns Updated query context
|
|
3549
|
-
*/
|
|
3550
|
-
private applyAst;
|
|
3551
|
-
/**
|
|
3552
|
-
* Applies a join to the query context
|
|
3553
|
-
* @param context - Current query context
|
|
3554
|
-
* @param table - Table to join
|
|
3555
|
-
* @param condition - Join condition
|
|
3556
|
-
* @param kind - Join kind
|
|
3557
|
-
* @returns Updated query context with join applied
|
|
3558
|
-
*/
|
|
3559
|
-
private applyJoin;
|
|
3560
3558
|
/**
|
|
3561
3559
|
* Applies a set operation to the query
|
|
3562
3560
|
* @param operator - Set operation kind
|
|
@@ -3689,18 +3687,18 @@ declare class SelectQueryBuilder<T = unknown, TTable extends TableDef = TableDef
|
|
|
3689
3687
|
* @param options - Optional include options
|
|
3690
3688
|
* @returns New query builder instance with the relationship inclusion
|
|
3691
3689
|
*/
|
|
3692
|
-
include<K extends keyof TTable['relations'] & string>(relationName: K, options?:
|
|
3690
|
+
include<K extends keyof TTable['relations'] & string>(relationName: K, options?: TypedRelationIncludeOptions<TTable['relations'][K]>): SelectQueryBuilder<T, TTable>;
|
|
3693
3691
|
/**
|
|
3694
3692
|
* Includes a relation lazily in the query results
|
|
3695
3693
|
* @param relationName - Name of the relation to include lazily
|
|
3696
3694
|
* @param options - Optional include options for lazy loading
|
|
3697
3695
|
* @returns New query builder instance with lazy relation inclusion
|
|
3698
3696
|
*/
|
|
3699
|
-
includeLazy<K extends keyof RelationMap<TTable>>(relationName: K, options?:
|
|
3697
|
+
includeLazy<K extends keyof RelationMap<TTable>>(relationName: K, options?: TypedRelationIncludeOptions<TTable['relations'][K]>): SelectQueryBuilder<T, TTable>;
|
|
3700
3698
|
/**
|
|
3701
3699
|
* Convenience alias for including only specific columns from a relation.
|
|
3702
3700
|
*/
|
|
3703
|
-
includePick<K extends keyof TTable['relations'] & string,
|
|
3701
|
+
includePick<K extends keyof TTable['relations'] & string, C extends RelationTargetColumns<TTable['relations'][K]>>(relationName: K, cols: C[]): SelectQueryBuilder<T, TTable>;
|
|
3704
3702
|
/**
|
|
3705
3703
|
* Selects columns for the root table and relations from an array of entries
|
|
3706
3704
|
* @param config - Configuration array for deep column selection
|
|
@@ -3728,8 +3726,19 @@ declare class SelectQueryBuilder<T = unknown, TTable extends TableDef = TableDef
|
|
|
3728
3726
|
* @returns Promise of entity instances
|
|
3729
3727
|
*/
|
|
3730
3728
|
execute(ctx: OrmSession): Promise<EntityInstance<TTable>[]>;
|
|
3731
|
-
|
|
3729
|
+
/**
|
|
3730
|
+
* Executes a count query for the current builder without LIMIT/OFFSET clauses.
|
|
3731
|
+
*
|
|
3732
|
+
* @example
|
|
3733
|
+
* const total = await qb.count(session);
|
|
3734
|
+
*/
|
|
3732
3735
|
count(session: OrmSession): Promise<number>;
|
|
3736
|
+
/**
|
|
3737
|
+
* Executes the query and returns both the paged items and the total.
|
|
3738
|
+
*
|
|
3739
|
+
* @example
|
|
3740
|
+
* const { items, totalItems } = await qb.executePaged(session, { page: 1, pageSize: 20 });
|
|
3741
|
+
*/
|
|
3733
3742
|
executePaged(session: OrmSession, options: {
|
|
3734
3743
|
page: number;
|
|
3735
3744
|
pageSize: number;
|
|
@@ -3767,6 +3776,9 @@ declare class SelectQueryBuilder<T = unknown, TTable extends TableDef = TableDef
|
|
|
3767
3776
|
* @param term - Column definition or ordering term to order by
|
|
3768
3777
|
* @param directionOrOptions - Order direction or options (defaults to ASC)
|
|
3769
3778
|
* @returns New query builder instance with the ORDER BY clause
|
|
3779
|
+
*
|
|
3780
|
+
* @example
|
|
3781
|
+
* qb.orderBy(userTable.columns.createdAt, 'DESC');
|
|
3770
3782
|
*/
|
|
3771
3783
|
orderBy(term: ColumnDef | OrderingTerm, directionOrOptions?: OrderDirection | {
|
|
3772
3784
|
direction?: OrderDirection;
|
|
@@ -3832,6 +3844,9 @@ declare class SelectQueryBuilder<T = unknown, TTable extends TableDef = TableDef
|
|
|
3832
3844
|
* @param relationName - Name of the relationship to check
|
|
3833
3845
|
* @param callback - Optional callback to modify the relationship query
|
|
3834
3846
|
* @returns New query builder instance with the relationship existence check
|
|
3847
|
+
*
|
|
3848
|
+
* @example
|
|
3849
|
+
* qb.whereHas('posts', postQb => postQb.where(eq(postTable.columns.published, true)));
|
|
3835
3850
|
*/
|
|
3836
3851
|
whereHas<K extends keyof TTable['relations'] & string>(relationName: K, callbackOrOptions?: RelationCallback | WhereHasOptions, maybeOptions?: WhereHasOptions): SelectQueryBuilder<T, TTable>;
|
|
3837
3852
|
/**
|
|
@@ -3839,6 +3854,9 @@ declare class SelectQueryBuilder<T = unknown, TTable extends TableDef = TableDef
|
|
|
3839
3854
|
* @param relationName - Name of the relationship to check
|
|
3840
3855
|
* @param callback - Optional callback to modify the relationship query
|
|
3841
3856
|
* @returns New query builder instance with the relationship non-existence check
|
|
3857
|
+
*
|
|
3858
|
+
* @example
|
|
3859
|
+
* qb.whereHasNot('posts', postQb => postQb.where(eq(postTable.columns.published, true)));
|
|
3842
3860
|
*/
|
|
3843
3861
|
whereHasNot<K extends keyof TTable['relations'] & string>(relationName: K, callbackOrOptions?: RelationCallback | WhereHasOptions, maybeOptions?: WhereHasOptions): SelectQueryBuilder<T, TTable>;
|
|
3844
3862
|
/**
|
|
@@ -4579,6 +4597,26 @@ declare const generateCreateTableSql: (table: TableDef, dialect: SchemaDialect)
|
|
|
4579
4597
|
* @returns The SQL statements.
|
|
4580
4598
|
*/
|
|
4581
4599
|
declare const generateSchemaSql: (tables: TableDef[], dialect: SchemaDialect) => string[];
|
|
4600
|
+
/**
|
|
4601
|
+
* Convenience wrapper for generateSchemaSql with rest args.
|
|
4602
|
+
* @param dialect - The schema dialect used to render SQL.
|
|
4603
|
+
* @param tables - The table definitions to create.
|
|
4604
|
+
*/
|
|
4605
|
+
declare const generateSchemaSqlFor: (dialect: SchemaDialect, ...tables: TableDef[]) => string[];
|
|
4606
|
+
/**
|
|
4607
|
+
* Generates and executes schema SQL for the provided tables.
|
|
4608
|
+
* @param executor - The database executor to run statements with.
|
|
4609
|
+
* @param tables - The table definitions to create.
|
|
4610
|
+
* @param dialect - The schema dialect used to render SQL.
|
|
4611
|
+
*/
|
|
4612
|
+
declare const executeSchemaSql: (executor: DbExecutor, tables: TableDef[], dialect: SchemaDialect) => Promise<void>;
|
|
4613
|
+
/**
|
|
4614
|
+
* Convenience wrapper for executeSchemaSql with rest args.
|
|
4615
|
+
* @param executor - The database executor to run statements with.
|
|
4616
|
+
* @param dialect - The schema dialect used to render SQL.
|
|
4617
|
+
* @param tables - The table definitions to create.
|
|
4618
|
+
*/
|
|
4619
|
+
declare const executeSchemaSqlFor: (executor: DbExecutor, dialect: SchemaDialect, ...tables: TableDef[]) => Promise<void>;
|
|
4582
4620
|
|
|
4583
4621
|
/** The kind of schema change. */
|
|
4584
4622
|
type SchemaChangeKind = 'createTable' | 'dropTable' | 'addColumn' | 'dropColumn' | 'alterColumn' | 'addIndex' | 'dropIndex';
|
|
@@ -5468,6 +5506,7 @@ declare class TypeScriptGenerator implements ExpressionVisitor<string>, OperandV
|
|
|
5468
5506
|
private mapOp;
|
|
5469
5507
|
}
|
|
5470
5508
|
|
|
5509
|
+
type RelationKey<TTable extends TableDef> = Extract<keyof RelationMap<TTable>, string>;
|
|
5471
5510
|
/**
|
|
5472
5511
|
* Metadata stored on entity instances for ORM internal use
|
|
5473
5512
|
* @typeParam TTable - Table definition type
|
|
@@ -5478,7 +5517,7 @@ interface EntityMeta<TTable extends TableDef> {
|
|
|
5478
5517
|
/** Table definition */
|
|
5479
5518
|
table: TTable;
|
|
5480
5519
|
/** Relations that should be loaded lazily */
|
|
5481
|
-
lazyRelations:
|
|
5520
|
+
lazyRelations: RelationKey<TTable>[];
|
|
5482
5521
|
/** Include options for lazy relations */
|
|
5483
5522
|
lazyRelationOptions: Map<string, RelationIncludeOptions>;
|
|
5484
5523
|
/** Cache for relation promises */
|
|
@@ -5497,7 +5536,8 @@ interface EntityMeta<TTable extends TableDef> {
|
|
|
5497
5536
|
* @param factory - The factory function to create the cache
|
|
5498
5537
|
* @returns Promise with the cached relation data
|
|
5499
5538
|
*/
|
|
5500
|
-
declare const relationLoaderCache: <T extends Map<string, unknown>>(meta: EntityMeta<
|
|
5539
|
+
declare const relationLoaderCache: <TTable extends TableDef, T extends Map<string, unknown>>(meta: EntityMeta<TTable>, relationName: string, factory: () => Promise<T>) => Promise<T>;
|
|
5540
|
+
|
|
5501
5541
|
/**
|
|
5502
5542
|
* Creates an entity proxy with lazy loading capabilities.
|
|
5503
5543
|
* @template TTable - The table type
|
|
@@ -5508,7 +5548,7 @@ declare const relationLoaderCache: <T extends Map<string, unknown>>(meta: Entity
|
|
|
5508
5548
|
* @param lazyRelations - Optional lazy relations
|
|
5509
5549
|
* @returns The entity instance
|
|
5510
5550
|
*/
|
|
5511
|
-
declare const createEntityProxy: <TTable extends TableDef, TLazy extends
|
|
5551
|
+
declare const createEntityProxy: <TTable extends TableDef, TLazy extends RelationKey<TTable> = RelationKey<TTable>>(ctx: EntityContext, table: TTable, row: Record<string, unknown>, lazyRelations?: TLazy[], lazyRelationOptions?: Map<string, RelationIncludeOptions>) => EntityInstance<TTable>;
|
|
5512
5552
|
/**
|
|
5513
5553
|
* Creates an entity instance from a database row.
|
|
5514
5554
|
* @template TTable - The table type
|
|
@@ -5519,12 +5559,13 @@ declare const createEntityProxy: <TTable extends TableDef, TLazy extends keyof R
|
|
|
5519
5559
|
* @param lazyRelations - Optional lazy relations
|
|
5520
5560
|
* @returns The entity instance
|
|
5521
5561
|
*/
|
|
5522
|
-
declare const createEntityFromRow: <TTable extends TableDef, TResult extends EntityInstance<TTable> = EntityInstance<TTable>>(ctx: EntityContext, table: TTable, row: Record<string, unknown>, lazyRelations?:
|
|
5562
|
+
declare const createEntityFromRow: <TTable extends TableDef, TResult extends EntityInstance<TTable> = EntityInstance<TTable>>(ctx: EntityContext, table: TTable, row: Record<string, unknown>, lazyRelations?: RelationKey<TTable>[], lazyRelationOptions?: Map<string, RelationIncludeOptions>) => TResult;
|
|
5523
5563
|
|
|
5524
5564
|
/**
|
|
5525
5565
|
* An array of database rows, each represented as a record of string keys to unknown values.
|
|
5526
5566
|
*/
|
|
5527
5567
|
type Rows$3 = Record<string, unknown>[];
|
|
5568
|
+
|
|
5528
5569
|
/**
|
|
5529
5570
|
* Loads related entities for a has-many relation in batch.
|
|
5530
5571
|
* @param ctx - The entity context.
|
|
@@ -5534,6 +5575,7 @@ type Rows$3 = Record<string, unknown>[];
|
|
|
5534
5575
|
* @returns A promise resolving to a map of root keys to arrays of related rows.
|
|
5535
5576
|
*/
|
|
5536
5577
|
declare const loadHasManyRelation: (ctx: EntityContext, rootTable: TableDef, relationName: string, relation: HasManyRelation, options?: RelationIncludeOptions) => Promise<Map<string, Rows$3>>;
|
|
5578
|
+
|
|
5537
5579
|
/**
|
|
5538
5580
|
* Loads related entities for a has-one relation in batch.
|
|
5539
5581
|
* @param ctx - The entity context.
|
|
@@ -5543,6 +5585,7 @@ declare const loadHasManyRelation: (ctx: EntityContext, rootTable: TableDef, rel
|
|
|
5543
5585
|
* @returns A promise resolving to a map of root keys to single related rows.
|
|
5544
5586
|
*/
|
|
5545
5587
|
declare const loadHasOneRelation: (ctx: EntityContext, rootTable: TableDef, relationName: string, relation: HasOneRelation, options?: RelationIncludeOptions) => Promise<Map<string, Record<string, unknown>>>;
|
|
5588
|
+
|
|
5546
5589
|
/**
|
|
5547
5590
|
* Loads related entities for a belongs-to relation in batch.
|
|
5548
5591
|
* @param ctx - The entity context.
|
|
@@ -5552,6 +5595,7 @@ declare const loadHasOneRelation: (ctx: EntityContext, rootTable: TableDef, rela
|
|
|
5552
5595
|
* @returns A promise resolving to a map of foreign keys to single related rows.
|
|
5553
5596
|
*/
|
|
5554
5597
|
declare const loadBelongsToRelation: (ctx: EntityContext, rootTable: TableDef, relationName: string, relation: BelongsToRelation, options?: RelationIncludeOptions) => Promise<Map<string, Record<string, unknown>>>;
|
|
5598
|
+
|
|
5555
5599
|
/**
|
|
5556
5600
|
* Loads related entities for a belongs-to-many relation in batch, including pivot data.
|
|
5557
5601
|
* @param ctx - The entity context.
|
|
@@ -5688,7 +5732,7 @@ type Rows = Record<string, unknown>[];
|
|
|
5688
5732
|
*
|
|
5689
5733
|
* @template TTarget The type of the target entities in the collection.
|
|
5690
5734
|
*/
|
|
5691
|
-
declare class DefaultManyToManyCollection<TTarget> implements ManyToManyCollection<TTarget> {
|
|
5735
|
+
declare class DefaultManyToManyCollection<TTarget, TPivot extends object | undefined = undefined> implements ManyToManyCollection<TTarget, TPivot> {
|
|
5692
5736
|
private readonly ctx;
|
|
5693
5737
|
private readonly meta;
|
|
5694
5738
|
private readonly root;
|
|
@@ -5789,51 +5833,6 @@ type Jsonify<T> = {
|
|
|
5789
5833
|
*/
|
|
5790
5834
|
declare const jsonify: <T extends object>(value: T) => Jsonify<T>;
|
|
5791
5835
|
|
|
5792
|
-
/**
|
|
5793
|
-
* Context object provided by standard decorators in newer TypeScript versions.
|
|
5794
|
-
*/
|
|
5795
|
-
interface StandardDecoratorContext {
|
|
5796
|
-
kind: string;
|
|
5797
|
-
name?: string | symbol;
|
|
5798
|
-
metadata?: Record<PropertyKey, unknown>;
|
|
5799
|
-
static?: boolean;
|
|
5800
|
-
private?: boolean;
|
|
5801
|
-
}
|
|
5802
|
-
/**
|
|
5803
|
-
* Dual-mode property decorator that supports both legacy and standard decorator syntax.
|
|
5804
|
-
*/
|
|
5805
|
-
interface DualModePropertyDecorator {
|
|
5806
|
-
(target: object, propertyKey: string | symbol): void;
|
|
5807
|
-
(value: unknown, context: StandardDecoratorContext): void;
|
|
5808
|
-
}
|
|
5809
|
-
/**
|
|
5810
|
-
* Dual-mode class decorator that supports both legacy and standard decorator syntax.
|
|
5811
|
-
*/
|
|
5812
|
-
interface DualModeClassDecorator {
|
|
5813
|
-
<TFunction extends Function>(value: TFunction): void | TFunction;
|
|
5814
|
-
<TFunction extends Function>(value: TFunction, context: StandardDecoratorContext): void | TFunction;
|
|
5815
|
-
}
|
|
5816
|
-
/**
|
|
5817
|
-
* Bag for storing decorator metadata during the decoration phase.
|
|
5818
|
-
*/
|
|
5819
|
-
interface DecoratorMetadataBag {
|
|
5820
|
-
columns: Array<{
|
|
5821
|
-
propertyName: string;
|
|
5822
|
-
column: ColumnDefLike;
|
|
5823
|
-
}>;
|
|
5824
|
-
relations: Array<{
|
|
5825
|
-
propertyName: string;
|
|
5826
|
-
relation: RelationMetadata;
|
|
5827
|
-
}>;
|
|
5828
|
-
}
|
|
5829
|
-
/**
|
|
5830
|
-
* Public helper to read decorator metadata from a class constructor.
|
|
5831
|
-
* Standard decorators only; legacy metadata is intentionally ignored.
|
|
5832
|
-
* @param ctor - The entity constructor.
|
|
5833
|
-
* @returns The metadata bag if present.
|
|
5834
|
-
*/
|
|
5835
|
-
declare const getDecoratorMetadata: (ctor: object) => DecoratorMetadataBag | undefined;
|
|
5836
|
-
|
|
5837
5836
|
/**
|
|
5838
5837
|
* Options for defining an entity.
|
|
5839
5838
|
*/
|
|
@@ -5846,7 +5845,7 @@ interface EntityOptions {
|
|
|
5846
5845
|
* @param options - Configuration options for the entity.
|
|
5847
5846
|
* @returns A class decorator that registers the entity metadata.
|
|
5848
5847
|
*/
|
|
5849
|
-
declare function Entity(options?: EntityOptions):
|
|
5848
|
+
declare function Entity(options?: EntityOptions): <T extends EntityConstructor>(value: T, context: ClassDecoratorContext) => T;
|
|
5850
5849
|
|
|
5851
5850
|
/**
|
|
5852
5851
|
* Options for defining a column in an entity.
|
|
@@ -5868,14 +5867,14 @@ type ColumnInput = ColumnOptions | ColumnDef;
|
|
|
5868
5867
|
* @param definition - The column definition or options.
|
|
5869
5868
|
* @returns A property decorator that registers the column metadata.
|
|
5870
5869
|
*/
|
|
5871
|
-
declare function Column(definition: ColumnInput):
|
|
5870
|
+
declare function Column(definition: ColumnInput): (_value: unknown, context: ClassFieldDecoratorContext) => void;
|
|
5872
5871
|
/**
|
|
5873
5872
|
* Decorator to define a primary key column on an entity property.
|
|
5874
5873
|
* Sets the primary flag to true and delegates to Column decorator.
|
|
5875
5874
|
* @param definition - The column definition or options.
|
|
5876
5875
|
* @returns A property decorator that registers the primary key column metadata.
|
|
5877
5876
|
*/
|
|
5878
|
-
declare function PrimaryKey(definition: ColumnInput):
|
|
5877
|
+
declare function PrimaryKey(definition: ColumnInput): (_value: unknown, context: ClassFieldDecoratorContext) => void;
|
|
5879
5878
|
|
|
5880
5879
|
interface BaseRelationOptions {
|
|
5881
5880
|
target: EntityOrTableTargetResolver;
|
|
@@ -5886,28 +5885,28 @@ interface BaseRelationOptions {
|
|
|
5886
5885
|
* Options for HasMany relation.
|
|
5887
5886
|
*/
|
|
5888
5887
|
interface HasManyOptions extends BaseRelationOptions {
|
|
5889
|
-
foreignKey
|
|
5888
|
+
foreignKey?: string;
|
|
5890
5889
|
}
|
|
5891
5890
|
/**
|
|
5892
5891
|
* Options for HasOne relation.
|
|
5893
5892
|
*/
|
|
5894
5893
|
interface HasOneOptions extends BaseRelationOptions {
|
|
5895
|
-
foreignKey
|
|
5894
|
+
foreignKey?: string;
|
|
5896
5895
|
}
|
|
5897
5896
|
/**
|
|
5898
5897
|
* Options for BelongsTo relation.
|
|
5899
5898
|
*/
|
|
5900
5899
|
interface BelongsToOptions extends BaseRelationOptions {
|
|
5901
|
-
foreignKey
|
|
5900
|
+
foreignKey?: string;
|
|
5902
5901
|
}
|
|
5903
5902
|
/**
|
|
5904
5903
|
* Options for BelongsToMany relation.
|
|
5905
5904
|
*/
|
|
5906
|
-
interface BelongsToManyOptions {
|
|
5907
|
-
target: EntityOrTableTargetResolver
|
|
5908
|
-
pivotTable: EntityOrTableTargetResolver
|
|
5909
|
-
pivotForeignKeyToRoot
|
|
5910
|
-
pivotForeignKeyToTarget
|
|
5905
|
+
interface BelongsToManyOptions<TTarget extends EntityOrTableTarget = EntityOrTableTarget, TPivot extends EntityOrTableTarget = EntityOrTableTarget> {
|
|
5906
|
+
target: EntityOrTableTargetResolver<TTarget>;
|
|
5907
|
+
pivotTable: EntityOrTableTargetResolver<TPivot>;
|
|
5908
|
+
pivotForeignKeyToRoot?: string;
|
|
5909
|
+
pivotForeignKeyToTarget?: string;
|
|
5911
5910
|
localKey?: string;
|
|
5912
5911
|
targetKey?: string;
|
|
5913
5912
|
pivotPrimaryKey?: string;
|
|
@@ -5919,25 +5918,25 @@ interface BelongsToManyOptions {
|
|
|
5919
5918
|
* @param options - The relation options.
|
|
5920
5919
|
* @returns A property decorator that registers the relation metadata.
|
|
5921
5920
|
*/
|
|
5922
|
-
declare function HasMany(options: HasManyOptions):
|
|
5921
|
+
declare function HasMany(options: HasManyOptions): (_value: unknown, context: ClassFieldDecoratorContext) => void;
|
|
5923
5922
|
/**
|
|
5924
5923
|
* Decorator to define a HasOne relation on an entity property.
|
|
5925
5924
|
* @param options - The relation options.
|
|
5926
5925
|
* @returns A property decorator that registers the relation metadata.
|
|
5927
5926
|
*/
|
|
5928
|
-
declare function HasOne(options: HasOneOptions):
|
|
5927
|
+
declare function HasOne(options: HasOneOptions): (_value: unknown, context: ClassFieldDecoratorContext) => void;
|
|
5929
5928
|
/**
|
|
5930
5929
|
* Decorator to define a BelongsTo relation on an entity property.
|
|
5931
5930
|
* @param options - The relation options.
|
|
5932
5931
|
* @returns A property decorator that registers the relation metadata.
|
|
5933
5932
|
*/
|
|
5934
|
-
declare function BelongsTo(options: BelongsToOptions):
|
|
5933
|
+
declare function BelongsTo(options: BelongsToOptions): (_value: unknown, context: ClassFieldDecoratorContext) => void;
|
|
5935
5934
|
/**
|
|
5936
5935
|
* Decorator to define a BelongsToMany relation on an entity property.
|
|
5937
5936
|
* @param options - The relation options.
|
|
5938
5937
|
* @returns A property decorator that registers the relation metadata.
|
|
5939
5938
|
*/
|
|
5940
|
-
declare function BelongsToMany(options: BelongsToManyOptions):
|
|
5939
|
+
declare function BelongsToMany<TTarget extends EntityOrTableTarget = EntityOrTableTarget, TPivot extends EntityOrTableTarget = EntityOrTableTarget>(options: BelongsToManyOptions<TTarget, TPivot>): (_value: unknown, context: ClassFieldDecoratorContext) => void;
|
|
5941
5940
|
|
|
5942
5941
|
/**
|
|
5943
5942
|
* Bootstraps all entities by building their table definitions and relations.
|
|
@@ -5964,7 +5963,7 @@ type EntityTable<TEntity extends object> = Omit<TableDef<{
|
|
|
5964
5963
|
[K in SelectableKeys<TEntity>]: ColumnDef;
|
|
5965
5964
|
}>, 'relations'> & {
|
|
5966
5965
|
relations: {
|
|
5967
|
-
[K in RelationKeys<TEntity>]: NonNullable<TEntity[K]> extends HasManyCollection<infer TChild> ? HasManyRelation<EntityTable<NonNullable<TChild> & object>> : NonNullable<TEntity[K]> extends ManyToManyCollection<infer TTarget> ? BelongsToManyRelation<EntityTable<NonNullable<TTarget> & object
|
|
5966
|
+
[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;
|
|
5968
5967
|
};
|
|
5969
5968
|
};
|
|
5970
5969
|
declare const selectFromEntity: <TEntity extends object>(ctor: EntityConstructor<TEntity>) => SelectQueryBuilder<unknown, EntityTable<TEntity>>;
|
|
@@ -5974,7 +5973,27 @@ declare const selectFromEntity: <TEntity extends object>(ctor: EntityConstructor
|
|
|
5974
5973
|
* Lazily bootstraps entity metadata (via getTableDefFromEntity) and returns a
|
|
5975
5974
|
* `tableRef(...)`-style proxy so users can write `u.id` instead of `u.columns.id`.
|
|
5976
5975
|
*/
|
|
5977
|
-
declare const entityRef: <
|
|
5976
|
+
declare const entityRef: <TEntity extends object>(ctor: EntityConstructor<TEntity>) => TableRef$1<EntityTable<TEntity>>;
|
|
5977
|
+
|
|
5978
|
+
/**
|
|
5979
|
+
* Bag for storing decorator metadata during the decoration phase.
|
|
5980
|
+
*/
|
|
5981
|
+
interface DecoratorMetadataBag {
|
|
5982
|
+
columns: Array<{
|
|
5983
|
+
propertyName: string;
|
|
5984
|
+
column: ColumnDefLike;
|
|
5985
|
+
}>;
|
|
5986
|
+
relations: Array<{
|
|
5987
|
+
propertyName: string;
|
|
5988
|
+
relation: RelationMetadata;
|
|
5989
|
+
}>;
|
|
5990
|
+
}
|
|
5991
|
+
/**
|
|
5992
|
+
* Public helper to read decorator metadata from a class constructor.
|
|
5993
|
+
* @param ctor - The entity constructor.
|
|
5994
|
+
* @returns The metadata bag if present.
|
|
5995
|
+
*/
|
|
5996
|
+
declare const getDecoratorMetadata: (ctor: object) => DecoratorMetadataBag | undefined;
|
|
5978
5997
|
|
|
5979
5998
|
type PoolOptions = {
|
|
5980
5999
|
/** Maximum number of live resources (idle + leased). */
|
|
@@ -6139,4 +6158,4 @@ type PooledExecutorFactoryOptions<TConn> = {
|
|
|
6139
6158
|
*/
|
|
6140
6159
|
declare function createPooledExecutorFactory<TConn>(opts: PooledExecutorFactoryOptions<TConn>): DbExecutorFactory;
|
|
6141
6160
|
|
|
6142
|
-
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, 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, denseRank, diffSchema, div, endOfMonth, entityRef, eq, esel, executeHydrated, executeHydratedWithContexts, exists, exp, extract, firstValue, floor, fromUnixTime, generateCreateTableSql, generateSchemaSql, getColumn, getDecoratorMetadata, getSchemaIntrospector, getTableDefFromEntity, greatest, groupConcat, gt, gte, hasMany, hasOne, hour, hydrateRows, ifNull, inList, inSubquery, initcap, 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, selectFromEntity, sha1, sha2, shiftLeft, shiftRight, sign, sin, space, sqrt, stddev, sub, substr, sum, synchronizeSchema, tableRef, tan, toColumnRef, toTableRef, trim, trunc, truncate, unixTimestamp, upper, utcNow, valueToOperand, variance, visitExpression, visitOperand, weekOfYear, windowFunction, year };
|
|
6161
|
+
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, 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, 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, selectFromEntity, setRelations, sha1, sha2, shiftLeft, shiftRight, sign, sin, space, sqrt, stddev, sub, substr, sum, synchronizeSchema, tableRef, tan, toColumnRef, toTableRef, trim, trunc, truncate, unixTimestamp, upper, utcNow, valueToOperand, variance, visitExpression, visitOperand, weekOfYear, windowFunction, year };
|