@rvoh/dream 0.45.0 → 0.45.1
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/cjs/src/Dream.js +118 -36
- package/dist/cjs/src/dream/DreamClassTransactionBuilder.js +92 -0
- package/dist/cjs/src/dream/DreamInstanceTransactionBuilder.js +98 -0
- package/dist/cjs/src/dream/LeftJoinLoadBuilder.js +52 -1
- package/dist/cjs/src/dream/LoadBuilder.js +49 -0
- package/dist/cjs/src/dream/Query.js +31 -57
- package/dist/cjs/src/dream/internal/convertDreamClassAndAssociationNameTupleArrayToPreloadArgs.js +18 -0
- package/dist/cjs/src/dream/internal/unaliasTableName.js +7 -0
- package/dist/esm/src/Dream.js +118 -36
- package/dist/esm/src/dream/DreamClassTransactionBuilder.js +92 -0
- package/dist/esm/src/dream/DreamInstanceTransactionBuilder.js +98 -0
- package/dist/esm/src/dream/LeftJoinLoadBuilder.js +52 -1
- package/dist/esm/src/dream/LoadBuilder.js +49 -0
- package/dist/esm/src/dream/Query.js +31 -57
- package/dist/esm/src/dream/internal/convertDreamClassAndAssociationNameTupleArrayToPreloadArgs.js +15 -0
- package/dist/esm/src/dream/internal/unaliasTableName.js +4 -0
- package/dist/types/src/Dream.d.ts +113 -49
- package/dist/types/src/dream/DreamClassTransactionBuilder.d.ts +108 -2
- package/dist/types/src/dream/DreamInstanceTransactionBuilder.d.ts +96 -2
- package/dist/types/src/dream/LeftJoinLoadBuilder.d.ts +48 -1
- package/dist/types/src/dream/LoadBuilder.d.ts +48 -1
- package/dist/types/src/dream/Query.d.ts +32 -59
- package/dist/types/src/dream/internal/convertDreamClassAndAssociationNameTupleArrayToPreloadArgs.d.ts +9 -0
- package/dist/types/src/dream/internal/unaliasTableName.d.ts +1 -0
- package/dist/types/src/types/query.d.ts +5 -0
- package/dist/types/src/types/query.ts +5 -0
- package/docs/assets/search.js +1 -1
- package/docs/classes/Benchmark.html +2 -2
- package/docs/classes/CalendarDate.html +2 -2
- package/docs/classes/CreateOrFindByFailedToCreateAndFind.html +3 -3
- package/docs/classes/Decorators.html +19 -19
- package/docs/classes/Dream.html +220 -186
- package/docs/classes/DreamApp.html +4 -4
- package/docs/classes/DreamBin.html +2 -2
- package/docs/classes/DreamCLI.html +4 -4
- package/docs/classes/DreamImporter.html +2 -2
- package/docs/classes/DreamLogos.html +2 -2
- package/docs/classes/DreamMigrationHelpers.html +7 -7
- package/docs/classes/DreamSerializerBuilder.html +8 -8
- package/docs/classes/DreamTransaction.html +2 -2
- package/docs/classes/Encrypt.html +2 -2
- package/docs/classes/Env.html +2 -2
- package/docs/classes/GlobalNameNotSet.html +3 -3
- package/docs/classes/NonLoadedAssociation.html +3 -3
- package/docs/classes/ObjectSerializerBuilder.html +8 -8
- package/docs/classes/Query.html +70 -66
- package/docs/classes/Range.html +2 -2
- package/docs/classes/RecordNotFound.html +3 -3
- package/docs/classes/ValidationError.html +3 -3
- package/docs/functions/DreamSerializer.html +1 -1
- package/docs/functions/ObjectSerializer.html +1 -1
- package/docs/functions/ReplicaSafe.html +1 -1
- package/docs/functions/STI.html +1 -1
- package/docs/functions/SoftDelete.html +1 -1
- package/docs/functions/camelize.html +1 -1
- package/docs/functions/capitalize.html +1 -1
- package/docs/functions/cloneDeepSafe.html +1 -1
- package/docs/functions/closeAllDbConnections.html +1 -1
- package/docs/functions/compact.html +1 -1
- package/docs/functions/dreamDbConnections.html +1 -1
- package/docs/functions/dreamPath.html +1 -1
- package/docs/functions/expandStiClasses.html +1 -1
- package/docs/functions/generateDream.html +1 -1
- package/docs/functions/globalClassNameFromFullyQualifiedModelName.html +1 -1
- package/docs/functions/groupBy.html +1 -1
- package/docs/functions/hyphenize.html +1 -1
- package/docs/functions/inferSerializerFromDreamOrViewModel.html +1 -1
- package/docs/functions/inferSerializersFromDreamClassOrViewModelClass.html +1 -1
- package/docs/functions/intersection.html +1 -1
- package/docs/functions/isDreamSerializer.html +1 -1
- package/docs/functions/isEmpty.html +1 -1
- package/docs/functions/loadRepl.html +1 -1
- package/docs/functions/lookupClassByGlobalName.html +1 -1
- package/docs/functions/normalizeUnicode.html +1 -1
- package/docs/functions/pascalize.html +1 -1
- package/docs/functions/pgErrorType.html +1 -1
- package/docs/functions/range-1.html +1 -1
- package/docs/functions/relativeDreamPath.html +1 -1
- package/docs/functions/round.html +1 -1
- package/docs/functions/serializerNameFromFullyQualifiedModelName.html +1 -1
- package/docs/functions/sharedPathPrefix.html +1 -1
- package/docs/functions/snakeify.html +1 -1
- package/docs/functions/sort.html +1 -1
- package/docs/functions/sortBy.html +1 -1
- package/docs/functions/sortObjectByKey.html +1 -1
- package/docs/functions/sortObjectByValue.html +1 -1
- package/docs/functions/standardizeFullyQualifiedModelName.html +1 -1
- package/docs/functions/uncapitalize.html +1 -1
- package/docs/functions/uniq.html +1 -1
- package/docs/functions/untypedDb.html +1 -1
- package/docs/functions/validateColumn.html +1 -1
- package/docs/functions/validateTable.html +1 -1
- package/docs/interfaces/BelongsToStatement.html +2 -2
- package/docs/interfaces/DecoratorContext.html +2 -2
- package/docs/interfaces/DreamAppInitOptions.html +2 -2
- package/docs/interfaces/DreamAppOpts.html +2 -2
- package/docs/interfaces/EncryptOptions.html +2 -2
- package/docs/interfaces/InternalAnyTypedSerializerRendersMany.html +2 -2
- package/docs/interfaces/InternalAnyTypedSerializerRendersOne.html +2 -2
- package/docs/interfaces/OpenapiDescription.html +2 -2
- package/docs/interfaces/OpenapiSchemaProperties.html +1 -1
- package/docs/interfaces/OpenapiSchemaPropertiesShorthand.html +1 -1
- package/docs/interfaces/OpenapiTypeFieldObject.html +1 -1
- package/docs/interfaces/SerializerRendererOpts.html +2 -2
- package/docs/types/Camelized.html +1 -1
- package/docs/types/CommonOpenapiSchemaObjectFields.html +1 -1
- package/docs/types/DateTime.html +1 -1
- package/docs/types/DbConnectionType.html +1 -1
- package/docs/types/DbTypes.html +1 -1
- package/docs/types/DreamAssociationMetadata.html +1 -1
- package/docs/types/DreamAttributes.html +1 -1
- package/docs/types/DreamClassAssociationAndStatement.html +1 -1
- package/docs/types/DreamClassColumn.html +1 -1
- package/docs/types/DreamColumn.html +1 -1
- package/docs/types/DreamColumnNames.html +1 -1
- package/docs/types/DreamLogLevel.html +1 -1
- package/docs/types/DreamLogger.html +1 -1
- package/docs/types/DreamModelSerializerType.html +1 -1
- package/docs/types/DreamOrViewModelClassSerializerKey.html +1 -1
- package/docs/types/DreamOrViewModelSerializerKey.html +1 -1
- package/docs/types/DreamParamSafeAttributes.html +1 -1
- package/docs/types/DreamParamSafeColumnNames.html +1 -1
- package/docs/types/DreamSerializable.html +1 -1
- package/docs/types/DreamSerializableArray.html +1 -1
- package/docs/types/DreamSerializerKey.html +1 -1
- package/docs/types/DreamSerializers.html +1 -1
- package/docs/types/DreamTableSchema.html +1 -1
- package/docs/types/DreamVirtualColumns.html +1 -1
- package/docs/types/EncryptAlgorithm.html +1 -1
- package/docs/types/HasManyStatement.html +1 -1
- package/docs/types/HasOneStatement.html +1 -1
- package/docs/types/Hyphenized.html +1 -1
- package/docs/types/IdType.html +1 -1
- package/docs/types/OpenapiAllTypes.html +1 -1
- package/docs/types/OpenapiFormats.html +1 -1
- package/docs/types/OpenapiNumberFormats.html +1 -1
- package/docs/types/OpenapiPrimitiveBaseTypes.html +1 -1
- package/docs/types/OpenapiPrimitiveTypes.html +1 -1
- package/docs/types/OpenapiSchemaArray.html +1 -1
- package/docs/types/OpenapiSchemaArrayShorthand.html +1 -1
- package/docs/types/OpenapiSchemaBase.html +1 -1
- package/docs/types/OpenapiSchemaBody.html +1 -1
- package/docs/types/OpenapiSchemaBodyShorthand.html +1 -1
- package/docs/types/OpenapiSchemaCommonFields.html +1 -1
- package/docs/types/OpenapiSchemaExpressionAllOf.html +1 -1
- package/docs/types/OpenapiSchemaExpressionAnyOf.html +1 -1
- package/docs/types/OpenapiSchemaExpressionOneOf.html +1 -1
- package/docs/types/OpenapiSchemaExpressionRef.html +1 -1
- package/docs/types/OpenapiSchemaExpressionRefSchemaShorthand.html +1 -1
- package/docs/types/OpenapiSchemaInteger.html +1 -1
- package/docs/types/OpenapiSchemaNull.html +1 -1
- package/docs/types/OpenapiSchemaNumber.html +1 -1
- package/docs/types/OpenapiSchemaObject.html +1 -1
- package/docs/types/OpenapiSchemaObjectAllOf.html +1 -1
- package/docs/types/OpenapiSchemaObjectAllOfShorthand.html +1 -1
- package/docs/types/OpenapiSchemaObjectAnyOf.html +1 -1
- package/docs/types/OpenapiSchemaObjectAnyOfShorthand.html +1 -1
- package/docs/types/OpenapiSchemaObjectBase.html +1 -1
- package/docs/types/OpenapiSchemaObjectBaseShorthand.html +1 -1
- package/docs/types/OpenapiSchemaObjectOneOf.html +1 -1
- package/docs/types/OpenapiSchemaObjectOneOfShorthand.html +1 -1
- package/docs/types/OpenapiSchemaObjectShorthand.html +1 -1
- package/docs/types/OpenapiSchemaPrimitiveGeneric.html +1 -1
- package/docs/types/OpenapiSchemaShorthandExpressionAllOf.html +1 -1
- package/docs/types/OpenapiSchemaShorthandExpressionAnyOf.html +1 -1
- package/docs/types/OpenapiSchemaShorthandExpressionOneOf.html +1 -1
- package/docs/types/OpenapiSchemaShorthandExpressionSerializableRef.html +1 -1
- package/docs/types/OpenapiSchemaShorthandExpressionSerializerRef.html +1 -1
- package/docs/types/OpenapiSchemaShorthandPrimitiveGeneric.html +1 -1
- package/docs/types/OpenapiSchemaString.html +1 -1
- package/docs/types/OpenapiShorthandAllTypes.html +1 -1
- package/docs/types/OpenapiShorthandPrimitiveBaseTypes.html +1 -1
- package/docs/types/OpenapiShorthandPrimitiveTypes.html +1 -1
- package/docs/types/OpenapiTypeField.html +1 -1
- package/docs/types/Pascalized.html +1 -1
- package/docs/types/PrimaryKeyType.html +1 -1
- package/docs/types/RoundingPrecision.html +1 -1
- package/docs/types/SerializerCasing.html +1 -1
- package/docs/types/SimpleObjectSerializerType.html +1 -1
- package/docs/types/Snakeified.html +1 -1
- package/docs/types/Timestamp.html +1 -1
- package/docs/types/UpdateableAssociationProperties.html +1 -1
- package/docs/types/UpdateableProperties.html +1 -1
- package/docs/types/ValidationType.html +1 -1
- package/docs/types/ViewModel.html +1 -1
- package/docs/types/ViewModelClass.html +1 -1
- package/docs/types/WhereStatementForDream.html +1 -1
- package/docs/types/WhereStatementForDreamClass.html +1 -1
- package/docs/variables/DateTime-1.html +1 -1
- package/docs/variables/DreamConst.html +1 -1
- package/docs/variables/TRIGRAM_OPERATORS.html +1 -1
- package/docs/variables/openapiPrimitiveTypes-1.html +1 -1
- package/docs/variables/openapiShorthandPrimitiveTypes-1.html +1 -1
- package/docs/variables/ops.html +1 -1
- package/docs/variables/primaryKeyTypes.html +1 -1
- package/package.json +1 -1
|
@@ -2,8 +2,8 @@ import { SelectArg, SelectExpression } from 'kysely';
|
|
|
2
2
|
import Dream from '../Dream.js';
|
|
3
3
|
import { PassthroughOnClause, WhereStatement } from '../types/associations/shared.js';
|
|
4
4
|
import { AssociationTableNames } from '../types/db.js';
|
|
5
|
-
import { CreateOrFindByExtraOpts, DefaultScopeName, DreamColumnNames, OrderDir, PassthroughColumnNames, PluckEachArgs, PrimaryKeyForFind, TableColumnNames, UpdateableProperties, UpdateablePropertiesForClass, UpdateOrCreateByExtraOpts } from '../types/dream.js';
|
|
6
|
-
import { BaseModelColumnTypes, FindEachOpts, PaginatedDreamQueryOptions, PaginatedDreamQueryResult, QueryWithJoinedAssociationsType, QueryWithJoinedAssociationsTypeAndNoPreload } from '../types/query.js';
|
|
5
|
+
import { CreateOrFindByExtraOpts, DefaultScopeName, DreamColumnNames, DreamSerializerKey, OrderDir, PassthroughColumnNames, PluckEachArgs, PrimaryKeyForFind, TableColumnNames, UpdateableProperties, UpdateablePropertiesForClass, UpdateOrCreateByExtraOpts } from '../types/dream.js';
|
|
6
|
+
import { BaseModelColumnTypes, FindEachOpts, LoadForModifierFn, PaginatedDreamQueryOptions, PaginatedDreamQueryResult, QueryWithJoinedAssociationsType, QueryWithJoinedAssociationsTypeAndNoPreload } from '../types/query.js';
|
|
7
7
|
import { JoinedAssociation, JoinedAssociationsTypeFromAssociations, VariadicJoinsArgs, VariadicLeftJoinLoadArgs, VariadicLoadArgs } from '../types/variadic.js';
|
|
8
8
|
import DreamTransaction from './DreamTransaction.js';
|
|
9
9
|
import Query from './Query.js';
|
|
@@ -337,6 +337,59 @@ export default class DreamClassTransactionBuilder<DreamClass extends typeof Drea
|
|
|
337
337
|
...Arr,
|
|
338
338
|
LastArg
|
|
339
339
|
]>, const JoinedAssociations extends readonly JoinedAssociation[] = JoinedAssociationsCandidate extends readonly JoinedAssociation[] ? JoinedAssociationsCandidate : never, RetQuery = QueryWithJoinedAssociationsTypeAndNoPreload<Query<DreamInstance>, JoinedAssociations>>(this: I, ...args: [...Arr, LastArg]): RetQuery;
|
|
340
|
+
/**
|
|
341
|
+
* Recursively left-join-preloads all Dream associations referenced by `rendersOne` and `rendersMany`
|
|
342
|
+
* in a DreamSerializer. This traverses the entire content tree of serializers to automatically
|
|
343
|
+
* load all necessary associations, eliminating N+1 query problems and removing the need to
|
|
344
|
+
* manually remember which associations to preload for serialization.
|
|
345
|
+
*
|
|
346
|
+
* This method decouples data loading code from data rendering code by having the serializer
|
|
347
|
+
* (rendering code) inform the query (loading code) about which associations are needed.
|
|
348
|
+
* As serializers evolve over time - adding new `rendersOne` and `rendersMany` calls or
|
|
349
|
+
* modifying existing ones - the loading code automatically adapts without requiring
|
|
350
|
+
* corresponding modifications to preload statements.
|
|
351
|
+
*
|
|
352
|
+
* This method analyzes the serializer (specified by `serializerKey` or 'default') and
|
|
353
|
+
* automatically preloads all associations that will be needed during serialization.
|
|
354
|
+
*
|
|
355
|
+
* ```ts
|
|
356
|
+
* // Instead of manually specifying all associations:
|
|
357
|
+
* await User.preload('posts', 'comments', 'replies').all()
|
|
358
|
+
*
|
|
359
|
+
* // Automatically preload everything needed for serialization:
|
|
360
|
+
* await User.preloadFor('summary').all()
|
|
361
|
+
*
|
|
362
|
+
* // Add where conditions to specific associations during preloading:
|
|
363
|
+
* await User.txn(txn).leftJoinPreloadFor('detailed', (dreamClass, associationName) => {
|
|
364
|
+
* if (dreamClass.typeof(Post) && associationName === 'comments') {
|
|
365
|
+
* return { and: { published: true } }
|
|
366
|
+
* }
|
|
367
|
+
* }).all()
|
|
368
|
+
*
|
|
369
|
+
* // Skip preloading specific associations to handle them manually:
|
|
370
|
+
* await User.txn(txn).leftJoinPreloadFor('summary', (dreamClass, associationName) => {
|
|
371
|
+
* if (dreamClass.typeof(User) && associationName === 'posts') {
|
|
372
|
+
* return 'omit' // Handle posts preloading separately with custom logic
|
|
373
|
+
* }
|
|
374
|
+
* })
|
|
375
|
+
* .preload('posts', { and: { featured: true } }) // Custom preloading
|
|
376
|
+
* .all()
|
|
377
|
+
* ```
|
|
378
|
+
*
|
|
379
|
+
* @param serializerKey - The serializer key to use for determining which associations to preload.
|
|
380
|
+
* @param modifierFn - Optional callback function to modify or omit specific associations during preloading. Called for each association with the Dream class and association name. Return an object with `and`, `andAny`, or `andNot` properties to add where conditions, return 'omit' to skip preloading that association (useful when you want to handle it manually), or return undefined to use default preloading
|
|
381
|
+
* @returns A Query with all serialization associations preloaded
|
|
382
|
+
*/
|
|
383
|
+
leftJoinPreloadFor<T extends DreamClassTransactionBuilder<DreamClass, DreamInstance>, SerializerKey extends DreamSerializerKey<DreamInstance>>(this: T, serializerKey: SerializerKey, modifierFn?: LoadForModifierFn): Query<DreamInstance, Readonly<{
|
|
384
|
+
joinedAssociations: readonly [];
|
|
385
|
+
rootTableName: DreamInstance["table"];
|
|
386
|
+
rootTableAlias: DreamInstance extends Dream ? DreamInstance["table"] : DreamInstance;
|
|
387
|
+
allowPreload: false;
|
|
388
|
+
allowLeftJoinPreload: true;
|
|
389
|
+
allowLimit: false;
|
|
390
|
+
allowOffset: false;
|
|
391
|
+
allowPaginate: false;
|
|
392
|
+
}>>;
|
|
340
393
|
/**
|
|
341
394
|
* Applies preload statement to a Query scoped to this model.
|
|
342
395
|
* Upon instantiating records of this model type,
|
|
@@ -368,6 +421,59 @@ export default class DreamClassTransactionBuilder<DreamClass extends typeof Drea
|
|
|
368
421
|
allowOffset: true;
|
|
369
422
|
allowPaginate: true;
|
|
370
423
|
}>>;
|
|
424
|
+
/**
|
|
425
|
+
* Recursively preloads all Dream associations referenced by `rendersOne` and `rendersMany`
|
|
426
|
+
* in a DreamSerializer. This traverses the entire content tree of serializers to automatically
|
|
427
|
+
* load all necessary associations, eliminating N+1 query problems and removing the need to
|
|
428
|
+
* manually remember which associations to preload for serialization.
|
|
429
|
+
*
|
|
430
|
+
* This method decouples data loading code from data rendering code by having the serializer
|
|
431
|
+
* (rendering code) inform the query (loading code) about which associations are needed.
|
|
432
|
+
* As serializers evolve over time - adding new `rendersOne` and `rendersMany` calls or
|
|
433
|
+
* modifying existing ones - the loading code automatically adapts without requiring
|
|
434
|
+
* corresponding modifications to preload statements.
|
|
435
|
+
*
|
|
436
|
+
* This method analyzes the serializer (specified by `serializerKey` or 'default') and
|
|
437
|
+
* automatically preloads all associations that will be needed during serialization.
|
|
438
|
+
*
|
|
439
|
+
* ```ts
|
|
440
|
+
* // Instead of manually specifying all associations:
|
|
441
|
+
* await User.preload('posts', 'comments', 'replies').all()
|
|
442
|
+
*
|
|
443
|
+
* // Automatically preload everything needed for serialization:
|
|
444
|
+
* await User.preloadFor('summary').all()
|
|
445
|
+
*
|
|
446
|
+
* // Add where conditions to specific associations during preloading:
|
|
447
|
+
* await User.txn(txn).preloadFor('detailed', (dreamClass, associationName) => {
|
|
448
|
+
* if (dreamClass.typeof(Post) && associationName === 'comments') {
|
|
449
|
+
* return { and: { published: true } }
|
|
450
|
+
* }
|
|
451
|
+
* }).all()
|
|
452
|
+
*
|
|
453
|
+
* // Skip preloading specific associations to handle them manually:
|
|
454
|
+
* await User.txn(txn).preloadFor('summary', (dreamClass, associationName) => {
|
|
455
|
+
* if (dreamClass.typeof(User) && associationName === 'posts') {
|
|
456
|
+
* return 'omit' // Handle posts preloading separately with custom logic
|
|
457
|
+
* }
|
|
458
|
+
* })
|
|
459
|
+
* .preload('posts', { and: { featured: true } }) // Custom preloading
|
|
460
|
+
* .all()
|
|
461
|
+
* ```
|
|
462
|
+
*
|
|
463
|
+
* @param serializerKey - The serializer key to use for determining which associations to preload.
|
|
464
|
+
* @param modifierFn - Optional callback function to modify or omit specific associations during preloading. Called for each association with the Dream class and association name. Return an object with `and`, `andAny`, or `andNot` properties to add where conditions, return 'omit' to skip preloading that association (useful when you want to handle it manually), or return undefined to use default preloading
|
|
465
|
+
* @returns A Query with all serialization associations preloaded
|
|
466
|
+
*/
|
|
467
|
+
preloadFor<T extends DreamClassTransactionBuilder<DreamClass, DreamInstance>, SerializerKey extends DreamSerializerKey<DreamInstance>>(this: T, serializerKey: SerializerKey, modifierFn?: LoadForModifierFn): Query<DreamInstance, Readonly<{
|
|
468
|
+
joinedAssociations: readonly [];
|
|
469
|
+
rootTableName: DreamInstance["table"];
|
|
470
|
+
rootTableAlias: DreamInstance extends Dream ? DreamInstance["table"] : DreamInstance;
|
|
471
|
+
allowPreload: true;
|
|
472
|
+
allowLeftJoinPreload: false;
|
|
473
|
+
allowLimit: true;
|
|
474
|
+
allowOffset: true;
|
|
475
|
+
allowPaginate: true;
|
|
476
|
+
}>>;
|
|
371
477
|
/**
|
|
372
478
|
* Returns a new Query instance with the provided
|
|
373
479
|
* inner join statement attached
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import Dream from '../Dream.js';
|
|
2
|
-
import { AllDefaultScopeNames, AssociationNameToDream, DreamAssociationNames, DreamAssociationNamesWithoutRequiredOnClauses, DreamAttributes, JoinAndStatements, UpdateableAssociationProperties, UpdateableProperties } from '../types/dream.js';
|
|
3
|
-
import { DefaultQueryTypeOptions, QueryWithJoinedAssociationsType } from '../types/query.js';
|
|
2
|
+
import { AllDefaultScopeNames, AssociationNameToDream, DreamAssociationNames, DreamAssociationNamesWithoutRequiredOnClauses, DreamAttributes, DreamSerializerKey, JoinAndStatements, UpdateableAssociationProperties, UpdateableProperties } from '../types/dream.js';
|
|
3
|
+
import { DefaultQueryTypeOptions, LoadForModifierFn, QueryWithJoinedAssociationsType } from '../types/query.js';
|
|
4
4
|
import { JoinedAssociation, JoinedAssociationsTypeFromAssociations, RequiredOnClauseKeys, VariadicJoinsArgs, VariadicLeftJoinLoadArgs, VariadicLoadArgs } from '../types/variadic.js';
|
|
5
5
|
import DreamTransaction from './DreamTransaction.js';
|
|
6
6
|
import { DestroyOptions } from './internal/destroyOptions.js';
|
|
@@ -40,6 +40,53 @@ export default class DreamInstanceTransactionBuilder<DreamInstance extends Dream
|
|
|
40
40
|
* @returns A chainable LoadBuilder instance
|
|
41
41
|
*/
|
|
42
42
|
load<I extends DreamInstanceTransactionBuilder<DreamInstance>, DB extends DreamInstance['DB'], TableName extends DreamInstance['table'], Schema extends DreamInstance['schema'], const Arr extends readonly unknown[]>(this: I, ...args: [...Arr, VariadicLoadArgs<DB, Schema, TableName, Arr>]): LoadBuilder<DreamInstance>;
|
|
43
|
+
/**
|
|
44
|
+
* Recursively loads all Dream associations referenced by `rendersOne` and `rendersMany`
|
|
45
|
+
* in a DreamSerializer. This traverses the entire content tree of serializers to automatically
|
|
46
|
+
* load all necessary associations, eliminating N+1 query problems and removing the need to
|
|
47
|
+
* manually remember which associations to preload for serialization.
|
|
48
|
+
*
|
|
49
|
+
* This method decouples data loading code from data rendering code by having the serializer
|
|
50
|
+
* (rendering code) inform the query (loading code) about which associations are needed.
|
|
51
|
+
* As serializers evolve over time - adding new `rendersOne` and `rendersMany` calls or
|
|
52
|
+
* modifying existing ones - the loading code automatically adapts without requiring
|
|
53
|
+
* corresponding modifications to preload statements.
|
|
54
|
+
*
|
|
55
|
+
* This method analyzes the serializer (specified by `serializerKey` or 'default') and
|
|
56
|
+
* automatically preloads all associations that will be needed during serialization.
|
|
57
|
+
*
|
|
58
|
+
* ```ts
|
|
59
|
+
* // Instead of manually specifying all associations:
|
|
60
|
+
* await User.preload('posts', 'comments', 'replies').all()
|
|
61
|
+
*
|
|
62
|
+
* // Automatically preload everything needed for serialization:
|
|
63
|
+
* await user.loadFor('summary').execute()
|
|
64
|
+
*
|
|
65
|
+
* // Add where conditions to specific associations during preloading:
|
|
66
|
+
* await user.txn(txn).loadFor('detailed', (dreamClass, associationName) => {
|
|
67
|
+
* if (dreamClass.typeof(Post) && associationName === 'comments') {
|
|
68
|
+
* return { and: { published: true } }
|
|
69
|
+
* }
|
|
70
|
+
* })
|
|
71
|
+
* .execute()
|
|
72
|
+
*
|
|
73
|
+
* // Skip preloading specific associations to handle them manually:
|
|
74
|
+
* await user
|
|
75
|
+
* .txn(txn)
|
|
76
|
+
* .loadFor('summary', (dreamClass, associationName) => {
|
|
77
|
+
* if (dreamClass.typeof(User) && associationName === 'posts') {
|
|
78
|
+
* return 'omit' // Handle posts preloading separately with custom logic
|
|
79
|
+
* }
|
|
80
|
+
* })
|
|
81
|
+
* .load('posts', { and: { featured: true } }) // Custom preloading
|
|
82
|
+
* .execute()
|
|
83
|
+
* ```
|
|
84
|
+
*
|
|
85
|
+
* @param serializerKey - The serializer key to use for determining which associations to preload.
|
|
86
|
+
* @param modifierFn - Optional callback function to modify or omit specific associations during preloading. Called for each association with the Dream class and association name. Return an object with `and`, `andAny`, or `andNot` properties to add where conditions, return 'omit' to skip preloading that association (useful when you want to handle it manually), or return undefined to use default preloading
|
|
87
|
+
* @returns A Query with all serialization associations preloaded
|
|
88
|
+
*/
|
|
89
|
+
loadFor<I extends DreamInstanceTransactionBuilder<DreamInstance>, SerializerKey extends DreamSerializerKey<DreamInstance>>(this: I, serializerKey: SerializerKey, modifierFn?: LoadForModifierFn): LoadBuilder<DreamInstance>;
|
|
43
90
|
/**
|
|
44
91
|
* Load each specified association using a single SQL query.
|
|
45
92
|
* See {@link #load} for loading in separate queries.
|
|
@@ -73,6 +120,53 @@ export default class DreamInstanceTransactionBuilder<DreamInstance extends Dream
|
|
|
73
120
|
* @returns A chainable LeftJoinLoadBuilder instance
|
|
74
121
|
*/
|
|
75
122
|
leftJoinLoad<I extends DreamInstanceTransactionBuilder<DreamInstance>, DB extends DreamInstance['DB'], TableName extends DreamInstance['table'], Schema extends DreamInstance['schema'], const Arr extends readonly unknown[]>(this: I, ...args: [...Arr, VariadicLeftJoinLoadArgs<DB, Schema, TableName, Arr>]): LeftJoinLoadBuilder<DreamInstance>;
|
|
123
|
+
/**
|
|
124
|
+
* Recursively loads all Dream associations referenced by `rendersOne` and `rendersMany`
|
|
125
|
+
* in a DreamSerializer. This traverses the entire content tree of serializers to automatically
|
|
126
|
+
* load all necessary associations, eliminating N+1 query problems and removing the need to
|
|
127
|
+
* manually remember which associations to preload for serialization.
|
|
128
|
+
*
|
|
129
|
+
* This method decouples data loading code from data rendering code by having the serializer
|
|
130
|
+
* (rendering code) inform the query (loading code) about which associations are needed.
|
|
131
|
+
* As serializers evolve over time - adding new `rendersOne` and `rendersMany` calls or
|
|
132
|
+
* modifying existing ones - the loading code automatically adapts without requiring
|
|
133
|
+
* corresponding modifications to preload statements.
|
|
134
|
+
*
|
|
135
|
+
* This method analyzes the serializer (specified by `serializerKey` or 'default') and
|
|
136
|
+
* automatically preloads all associations that will be needed during serialization.
|
|
137
|
+
*
|
|
138
|
+
* ```ts
|
|
139
|
+
* // Instead of manually specifying all associations:
|
|
140
|
+
* await User.preload('posts', 'comments', 'replies').all()
|
|
141
|
+
*
|
|
142
|
+
* // Automatically preload everything needed for serialization:
|
|
143
|
+
* await user.leftJoinLoadFor('summary').execute()
|
|
144
|
+
*
|
|
145
|
+
* // Add where conditions to specific associations during preloading:
|
|
146
|
+
* await user.txn(txn).leftJoinLoadFor('detailed', (dreamClass, associationName) => {
|
|
147
|
+
* if (dreamClass.typeof(Post) && associationName === 'comments') {
|
|
148
|
+
* return { and: { published: true } }
|
|
149
|
+
* }
|
|
150
|
+
* })
|
|
151
|
+
* .execute()
|
|
152
|
+
*
|
|
153
|
+
* // Skip preloading specific associations to handle them manually:
|
|
154
|
+
* await user
|
|
155
|
+
* .txn(txn)
|
|
156
|
+
* .leftJoinLoadFor('summary', (dreamClass, associationName) => {
|
|
157
|
+
* if (dreamClass.typeof(User) && associationName === 'posts') {
|
|
158
|
+
* return 'omit' // Handle posts preloading separately with custom logic
|
|
159
|
+
* }
|
|
160
|
+
* })
|
|
161
|
+
* .load('posts', { and: { featured: true } }) // Custom preloading
|
|
162
|
+
* .execute()
|
|
163
|
+
* ```
|
|
164
|
+
*
|
|
165
|
+
* @param serializerKey - The serializer key to use for determining which associations to preload.
|
|
166
|
+
* @param modifierFn - Optional callback function to modify or omit specific associations during preloading. Called for each association with the Dream class and association name. Return an object with `and`, `andAny`, or `andNot` properties to add where conditions, return 'omit' to skip preloading that association (useful when you want to handle it manually), or return undefined to use default preloading
|
|
167
|
+
* @returns A Query with all serialization associations preloaded
|
|
168
|
+
*/
|
|
169
|
+
leftJoinLoadFor<I extends DreamInstanceTransactionBuilder<DreamInstance>, SerializerKey extends DreamSerializerKey<DreamInstance>>(this: I, serializerKey: SerializerKey, modifierFn?: LoadForModifierFn): LeftJoinLoadBuilder<DreamInstance>;
|
|
76
170
|
/**
|
|
77
171
|
* Returns a new Query instance with the provided
|
|
78
172
|
* inner join statement attached
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import Dream from '../Dream.js';
|
|
2
2
|
import { PassthroughOnClause } from '../types/associations/shared.js';
|
|
3
|
-
import { PassthroughColumnNames } from '../types/dream.js';
|
|
3
|
+
import { DreamSerializerKey, PassthroughColumnNames } from '../types/dream.js';
|
|
4
|
+
import { LoadForModifierFn } from '../types/query.js';
|
|
4
5
|
import { VariadicLeftJoinLoadArgs } from '../types/variadic.js';
|
|
5
6
|
import DreamTransaction from './DreamTransaction.js';
|
|
6
7
|
export default class LeftJoinLoadBuilder<DreamInstance extends Dream> {
|
|
@@ -31,6 +32,52 @@ export default class LeftJoinLoadBuilder<DreamInstance extends Dream> {
|
|
|
31
32
|
* ```
|
|
32
33
|
*/
|
|
33
34
|
leftJoinLoad<I extends LeftJoinLoadBuilder<DreamInstance>, DB extends DreamInstance['DB'], TableName extends DreamInstance['table'], Schema extends DreamInstance['schema'], const Arr extends readonly unknown[], const LastArg extends VariadicLeftJoinLoadArgs<DB, Schema, TableName, Arr>>(this: I, ...args: [...Arr, LastArg]): I;
|
|
35
|
+
/**
|
|
36
|
+
* Recursively loads all Dream associations referenced by `rendersOne` and `rendersMany`
|
|
37
|
+
* in a DreamSerializer. This traverses the entire content tree of serializers to automatically
|
|
38
|
+
* load all necessary associations, eliminating N+1 query problems and removing the need to
|
|
39
|
+
* manually remember which associations to preload for serialization.
|
|
40
|
+
*
|
|
41
|
+
* This method decouples data loading code from data rendering code by having the serializer
|
|
42
|
+
* (rendering code) inform the query (loading code) about which associations are needed.
|
|
43
|
+
* As serializers evolve over time - adding new `rendersOne` and `rendersMany` calls or
|
|
44
|
+
* modifying existing ones - the loading code automatically adapts without requiring
|
|
45
|
+
* corresponding modifications to preload statements.
|
|
46
|
+
*
|
|
47
|
+
* This method analyzes the serializer (specified by `serializerKey` or 'default') and
|
|
48
|
+
* automatically preloads all associations that will be needed during serialization.
|
|
49
|
+
*
|
|
50
|
+
* ```ts
|
|
51
|
+
* // Instead of manually specifying all associations:
|
|
52
|
+
* await User.preload('posts', 'comments', 'replies').all()
|
|
53
|
+
*
|
|
54
|
+
* // Automatically preload everything needed for serialization:
|
|
55
|
+
* await user.leftJoinLoadFor('summary').execute()
|
|
56
|
+
*
|
|
57
|
+
* // Add where conditions to specific associations during preloading:
|
|
58
|
+
* await user.leftJoinLoadFor('detailed', (dreamClass, associationName) => {
|
|
59
|
+
* if (dreamClass.typeof(Post) && associationName === 'comments') {
|
|
60
|
+
* return { and: { published: true } }
|
|
61
|
+
* }
|
|
62
|
+
* })
|
|
63
|
+
* .execute()
|
|
64
|
+
*
|
|
65
|
+
* // Skip preloading specific associations to handle them manually:
|
|
66
|
+
* await user
|
|
67
|
+
* .leftJoinLoadFor('summary', (dreamClass, associationName) => {
|
|
68
|
+
* if (dreamClass.typeof(User) && associationName === 'posts') {
|
|
69
|
+
* return 'omit' // Handle posts preloading separately with custom logic
|
|
70
|
+
* }
|
|
71
|
+
* })
|
|
72
|
+
* .load('posts', { and: { featured: true } }) // Custom preloading
|
|
73
|
+
* .execute()
|
|
74
|
+
* ```
|
|
75
|
+
*
|
|
76
|
+
* @param serializerKey - The serializer key to use for determining which associations to preload.
|
|
77
|
+
* @param modifierFn - Optional callback function to modify or omit specific associations during preloading. Called for each association with the Dream class and association name. Return an object with `and`, `andAny`, or `andNot` properties to add where conditions, return 'omit' to skip preloading that association (useful when you want to handle it manually), or return undefined to use default preloading
|
|
78
|
+
* @returns A Query with all serialization associations preloaded
|
|
79
|
+
*/
|
|
80
|
+
leftJoinLoadFor<I extends LeftJoinLoadBuilder<DreamInstance>, SerializerKey extends DreamSerializerKey<DreamInstance>>(this: I, serializerKey: SerializerKey, modifierFn?: LoadForModifierFn): I;
|
|
34
81
|
/**
|
|
35
82
|
* executes a load builder query, binding
|
|
36
83
|
* all associations to their respective model
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import Dream from '../Dream.js';
|
|
2
2
|
import { PassthroughOnClause } from '../types/associations/shared.js';
|
|
3
|
-
import { PassthroughColumnNames } from '../types/dream.js';
|
|
3
|
+
import { DreamSerializerKey, PassthroughColumnNames } from '../types/dream.js';
|
|
4
|
+
import { LoadForModifierFn } from '../types/query.js';
|
|
4
5
|
import { VariadicLoadArgs } from '../types/variadic.js';
|
|
5
6
|
import DreamTransaction from './DreamTransaction.js';
|
|
6
7
|
export default class LoadBuilder<DreamInstance extends Dream> {
|
|
@@ -31,6 +32,52 @@ export default class LoadBuilder<DreamInstance extends Dream> {
|
|
|
31
32
|
* ```
|
|
32
33
|
*/
|
|
33
34
|
load<I extends LoadBuilder<DreamInstance>, DB extends DreamInstance['DB'], TableName extends DreamInstance['table'], Schema extends DreamInstance['schema'], const Arr extends readonly unknown[]>(this: I, ...args: [...Arr, VariadicLoadArgs<DB, Schema, TableName, Arr>]): I;
|
|
35
|
+
/**
|
|
36
|
+
* Recursively loads all Dream associations referenced by `rendersOne` and `rendersMany`
|
|
37
|
+
* in a DreamSerializer. This traverses the entire content tree of serializers to automatically
|
|
38
|
+
* load all necessary associations, eliminating N+1 query problems and removing the need to
|
|
39
|
+
* manually remember which associations to preload for serialization.
|
|
40
|
+
*
|
|
41
|
+
* This method decouples data loading code from data rendering code by having the serializer
|
|
42
|
+
* (rendering code) inform the query (loading code) about which associations are needed.
|
|
43
|
+
* As serializers evolve over time - adding new `rendersOne` and `rendersMany` calls or
|
|
44
|
+
* modifying existing ones - the loading code automatically adapts without requiring
|
|
45
|
+
* corresponding modifications to preload statements.
|
|
46
|
+
*
|
|
47
|
+
* This method analyzes the serializer (specified by `serializerKey` or 'default') and
|
|
48
|
+
* automatically preloads all associations that will be needed during serialization.
|
|
49
|
+
*
|
|
50
|
+
* ```ts
|
|
51
|
+
* // Instead of manually specifying all associations:
|
|
52
|
+
* await User.preload('posts', 'comments', 'replies').all()
|
|
53
|
+
*
|
|
54
|
+
* // Automatically preload everything needed for serialization:
|
|
55
|
+
* await user.loadFor('summary').execute()
|
|
56
|
+
*
|
|
57
|
+
* // Add where conditions to specific associations during preloading:
|
|
58
|
+
* await user.loadFor('detailed', (dreamClass, associationName) => {
|
|
59
|
+
* if (dreamClass.typeof(Post) && associationName === 'comments') {
|
|
60
|
+
* return { and: { published: true } }
|
|
61
|
+
* }
|
|
62
|
+
* })
|
|
63
|
+
* .execute()
|
|
64
|
+
*
|
|
65
|
+
* // Skip preloading specific associations to handle them manually:
|
|
66
|
+
* await user
|
|
67
|
+
* .loadFor('summary', (dreamClass, associationName) => {
|
|
68
|
+
* if (dreamClass.typeof(User) && associationName === 'posts') {
|
|
69
|
+
* return 'omit' // Handle posts preloading separately with custom logic
|
|
70
|
+
* }
|
|
71
|
+
* })
|
|
72
|
+
* .load('posts', { and: { featured: true } }) // Custom preloading
|
|
73
|
+
* .execute()
|
|
74
|
+
* ```
|
|
75
|
+
*
|
|
76
|
+
* @param serializerKey - The serializer key to use for determining which associations to preload.
|
|
77
|
+
* @param modifierFn - Optional callback function to modify or omit specific associations during preloading. Called for each association with the Dream class and association name. Return an object with `and`, `andAny`, or `andNot` properties to add where conditions, return 'omit' to skip preloading that association (useful when you want to handle it manually), or return undefined to use default preloading
|
|
78
|
+
* @returns A Query with all serialization associations preloaded
|
|
79
|
+
*/
|
|
80
|
+
loadFor<I extends LoadBuilder<DreamInstance>, SerializerKey extends DreamSerializerKey<DreamInstance>>(this: I, serializerKey: SerializerKey, modifierFn?: LoadForModifierFn): I;
|
|
34
81
|
/**
|
|
35
82
|
* executes a load builder query, binding
|
|
36
83
|
* all associations to their respective model
|
|
@@ -2,8 +2,8 @@ import { DeleteQueryBuilder, SelectQueryBuilder, UpdateQueryBuilder } from 'kyse
|
|
|
2
2
|
import Dream from '../Dream.js';
|
|
3
3
|
import { ColumnNamesAccountingForJoinedAssociations, LimitStatement, OffsetStatement, OrderQueryStatement, PassthroughOnClause, WhereStatement, WhereStatementForJoinedAssociation } from '../types/associations/shared.js';
|
|
4
4
|
import { DbConnectionType } from '../types/db.js';
|
|
5
|
-
import { AllDefaultScopeNames, DefaultScopeName,
|
|
6
|
-
import { DefaultQueryTypeOptions, ExtendQueryType, NamespacedOrBaseModelColumnTypes, PaginatedDreamQueryOptions, PaginatedDreamQueryResult, QueryToKyselyDBType, QueryToKyselyTableNamesType } from '../types/query.js';
|
|
5
|
+
import { AllDefaultScopeNames, DefaultScopeName, DreamColumnNames, DreamConstructorType, DreamSerializerKey, DreamTableSchema, OrderDir, PassthroughColumnNames, PluckEachArgs, PrimaryKeyForFind, RelaxedJoinAndStatement, RelaxedJoinStatement, RelaxedPreloadOnStatement, RelaxedPreloadStatement, TableColumnNames, TableOrAssociationName } from '../types/dream.js';
|
|
6
|
+
import { DefaultQueryTypeOptions, ExtendQueryType, LoadForModifierFn, NamespacedOrBaseModelColumnTypes, PaginatedDreamQueryOptions, PaginatedDreamQueryResult, QueryToKyselyDBType, QueryToKyselyTableNamesType } from '../types/query.js';
|
|
7
7
|
import { JoinedAssociation, JoinedAssociationsTypeFromAssociations, QueryTypeOptions, VariadicJoinsArgs, VariadicLeftJoinLoadArgs, VariadicLoadArgs } from '../types/variadic.js';
|
|
8
8
|
import DreamTransaction from './DreamTransaction.js';
|
|
9
9
|
import PostgresQueryDriver from './QueryDriver/Postgres.js';
|
|
@@ -361,46 +361,33 @@ export default class Query<DreamInstance extends Dream, QueryTypeOpts extends Re
|
|
|
361
361
|
* await User.preload('posts', 'comments', 'replies').all()
|
|
362
362
|
*
|
|
363
363
|
* // Automatically preload everything needed for serialization:
|
|
364
|
-
* await User.
|
|
364
|
+
* await User.preloadFor('summary').all()
|
|
365
365
|
*
|
|
366
366
|
* // Add where conditions to specific associations during preloading:
|
|
367
|
-
* await User.
|
|
368
|
-
*
|
|
369
|
-
*
|
|
370
|
-
* if (dreamClass.typeof(Post) && associationName === 'comments') {
|
|
371
|
-
* return { and: { published: true } }
|
|
372
|
-
* }
|
|
367
|
+
* await User.preloadFor('detailed', (dreamClass, associationName) => {
|
|
368
|
+
* if (dreamClass.typeof(Post) && associationName === 'comments') {
|
|
369
|
+
* return { and: { published: true } }
|
|
373
370
|
* }
|
|
374
|
-
* })
|
|
371
|
+
* })
|
|
372
|
+
* .all()
|
|
375
373
|
*
|
|
376
374
|
* // Skip preloading specific associations to handle them manually:
|
|
377
|
-
* await User.
|
|
378
|
-
*
|
|
379
|
-
*
|
|
380
|
-
* if (dreamClass.typeof(User) && associationName === 'posts') {
|
|
381
|
-
* return 'omit' // Handle posts preloading separately with custom logic
|
|
382
|
-
* }
|
|
375
|
+
* await User.preloadFor('summary', (dreamClass, associationName) => {
|
|
376
|
+
* if (dreamClass.typeof(User) && associationName === 'posts') {
|
|
377
|
+
* return 'omit' // Handle posts preloading separately with custom logic
|
|
383
378
|
* }
|
|
384
379
|
* })
|
|
385
|
-
*
|
|
386
|
-
*
|
|
380
|
+
* .preload('posts', { and: { featured: true } }) // Custom preloading
|
|
381
|
+
* .all()
|
|
387
382
|
* ```
|
|
388
383
|
*
|
|
389
|
-
* @param
|
|
390
|
-
* @param
|
|
391
|
-
* @param opts.modifierFn - Optional callback function to modify or omit specific associations during preloading. Called for each association with the Dream class and association name. Return an object with `and`, `andAny`, or `andNot` properties to add where conditions, return 'omit' to skip preloading that association (useful when you want to handle it manually), or return undefined to use default preloading
|
|
384
|
+
* @param serializerKey - The serializer key to use for determining which associations to preload.
|
|
385
|
+
* @param modifierFn - Optional callback function to modify or omit specific associations during preloading. Called for each association with the Dream class and association name. Return an object with `and`, `andAny`, or `andNot` properties to add where conditions, return 'omit' to skip preloading that association (useful when you want to handle it manually), or return undefined to use default preloading
|
|
392
386
|
* @returns A Query with all serialization associations preloaded
|
|
393
387
|
*/
|
|
394
|
-
|
|
388
|
+
preloadFor<Q extends Query<DreamInstance, any>, SerializerKey extends DreamSerializerKey<DreamInstance>, RetQuery = Query<DreamInstance, ExtendQueryType<QueryTypeOpts, Readonly<{
|
|
395
389
|
allowLeftJoinPreload: false;
|
|
396
|
-
}>>>>(this: Q,
|
|
397
|
-
serializerKey?: SerializerKey;
|
|
398
|
-
modifierFn?: <DreamClass extends typeof Dream, const AssociationName extends DreamAssociationNames<InstanceType<DreamClass>>>(dreamClass: DreamClass, associationName: AssociationName) => {
|
|
399
|
-
and?: object;
|
|
400
|
-
andAny?: object;
|
|
401
|
-
andNot?: object;
|
|
402
|
-
} | 'omit' | undefined;
|
|
403
|
-
}): RetQuery;
|
|
390
|
+
}>>>>(this: Q, serializerKey: SerializerKey, modifierFn?: LoadForModifierFn): RetQuery;
|
|
404
391
|
/**
|
|
405
392
|
* Recursively preloads all Dream associations referenced by `rendersOne` and `rendersMany`
|
|
406
393
|
* in a DreamSerializer using left join preloading. This traverses the entire content tree
|
|
@@ -425,50 +412,36 @@ export default class Query<DreamInstance extends Dream, QueryTypeOpts extends Re
|
|
|
425
412
|
* await User.leftJoinPreload('posts', 'comments', 'replies').all()
|
|
426
413
|
*
|
|
427
414
|
* // Automatically left join preload everything needed for serialization:
|
|
428
|
-
* await User.
|
|
415
|
+
* await User.leftJoinPreloadFor('summary').all()
|
|
429
416
|
*
|
|
430
417
|
* // Add where conditions to specific associations during left join preloading:
|
|
431
|
-
* await User.
|
|
432
|
-
*
|
|
433
|
-
*
|
|
434
|
-
* if (dreamClass.typeof(Post) && associationName === 'comments') {
|
|
435
|
-
* return { and: { published: true } }
|
|
436
|
-
* }
|
|
418
|
+
* await User.leftJoinPreloadFor('detailed', (dreamClass, associationName) => {
|
|
419
|
+
* if (dreamClass.typeof(Post) && associationName === 'comments') {
|
|
420
|
+
* return { and: { published: true } }
|
|
437
421
|
* }
|
|
438
|
-
* })
|
|
422
|
+
* })
|
|
423
|
+
* .all()
|
|
439
424
|
*
|
|
440
425
|
* // Skip left join preloading specific associations to handle them manually:
|
|
441
|
-
* await User.
|
|
442
|
-
*
|
|
443
|
-
*
|
|
444
|
-
* if (dreamClass.typeof(User) && associationName === 'posts') {
|
|
445
|
-
* return 'omit' // Handle posts preloading separately with custom logic
|
|
446
|
-
* }
|
|
426
|
+
* await User.leftJoinPreloadFor('summary', (dreamClass, associationName) => {
|
|
427
|
+
* if (dreamClass.typeof(User) && associationName === 'posts') {
|
|
428
|
+
* return 'omit' // Handle posts preloading separately with custom logic
|
|
447
429
|
* }
|
|
448
430
|
* })
|
|
449
|
-
*
|
|
450
|
-
*
|
|
431
|
+
* .preload('posts', { and: { featured: true } }) // Custom preloading instead
|
|
432
|
+
* .all()
|
|
451
433
|
* ```
|
|
452
434
|
*
|
|
453
|
-
* @param
|
|
454
|
-
* @param
|
|
455
|
-
* @param opts.modifierFn - Optional callback function to modify or omit specific associations during preloading. Called for each association with the Dream class and association name. Return an object with `and`, `andAny`, or `andNot` properties to add where conditions, return 'omit' to skip preloading that association (useful when you want to handle it manually), or return undefined to use default preloading
|
|
435
|
+
* @param serializerKey - The serializer key to use for determining which associations to preload.
|
|
436
|
+
* @param modifierFn - Optional callback function to modify or omit specific associations during preloading. Called for each association with the Dream class and association name. Return an object with `and`, `andAny`, or `andNot` properties to add where conditions, return 'omit' to skip preloading that association (useful when you want to handle it manually), or return undefined to use default preloading
|
|
456
437
|
* @returns A Query with all serialization associations left join preloaded
|
|
457
438
|
*/
|
|
458
|
-
|
|
439
|
+
leftJoinPreloadFor<Q extends Query<DreamInstance, any>, SerializerKey extends DreamSerializerKey<DreamInstance>, RetQuery = Query<DreamInstance, ExtendQueryType<QueryTypeOpts, Readonly<{
|
|
459
440
|
allowPreload: false;
|
|
460
441
|
allowLimit: false;
|
|
461
442
|
allowOffset: false;
|
|
462
443
|
allowPaginate: false;
|
|
463
|
-
}>>>>(this: Q,
|
|
464
|
-
serializerKey?: SerializerKey;
|
|
465
|
-
modifierFn?: <DreamClass extends typeof Dream, const AssociationName extends DreamAssociationNames<InstanceType<DreamClass>>>(dreamClass: DreamClass, associationName: AssociationName) => {
|
|
466
|
-
and?: object;
|
|
467
|
-
andAny?: object;
|
|
468
|
-
andNot?: object;
|
|
469
|
-
} | 'omit' | undefined;
|
|
470
|
-
}): RetQuery;
|
|
471
|
-
private convertDreamClassAndAssociationNameTupleArrayToPreloadArgs;
|
|
444
|
+
}>>>>(this: Q, serializerKey: SerializerKey, modifierFn?: LoadForModifierFn): RetQuery;
|
|
472
445
|
/**
|
|
473
446
|
* Returns a new Query instance, with the provided
|
|
474
447
|
* joins statement attached
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { LoadForModifierFn } from '../../types/query.js';
|
|
2
|
+
import { DreamClassAndAssociationNameTuple } from './extractNestedPaths.js';
|
|
3
|
+
export default function convertDreamClassAndAssociationNameTupleArrayToPreloadArgs(dreamClassAndAssociationNameTupleArray: DreamClassAndAssociationNameTuple[], modifierFn?: LoadForModifierFn, counter?: {
|
|
4
|
+
count: number;
|
|
5
|
+
}): (string | {
|
|
6
|
+
and?: object;
|
|
7
|
+
andAny?: object;
|
|
8
|
+
andNot?: object;
|
|
9
|
+
})[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function unaliasTableName(tableName: string): string;
|
|
@@ -88,4 +88,9 @@ export interface PaginatedDreamQueryResult<T extends Dream> {
|
|
|
88
88
|
*/
|
|
89
89
|
results: T[];
|
|
90
90
|
}
|
|
91
|
+
export type LoadForModifierFn = (dreamClass: typeof Dream, associationName: string) => {
|
|
92
|
+
and?: object;
|
|
93
|
+
andAny?: object;
|
|
94
|
+
andNot?: object;
|
|
95
|
+
} | 'omit' | undefined;
|
|
91
96
|
export {};
|
|
@@ -203,3 +203,8 @@ export interface PaginatedDreamQueryResult<T extends Dream> {
|
|
|
203
203
|
*/
|
|
204
204
|
results: T[]
|
|
205
205
|
}
|
|
206
|
+
|
|
207
|
+
export type LoadForModifierFn = (
|
|
208
|
+
dreamClass: typeof Dream,
|
|
209
|
+
associationName: string
|
|
210
|
+
) => { and?: object; andAny?: object; andNot?: object } | 'omit' | undefined
|