@rvoh/dream 2.34.0 → 2.36.0
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 +2 -2
- package/dist/cjs/src/Dream.js +270 -69
- package/dist/cjs/src/bin/index.js +13 -0
- package/dist/cjs/src/cli/index.js +28 -17
- package/dist/cjs/src/db/migration-helpers/DreamMigrationHelpers.js +23 -21
- package/dist/cjs/src/decorators/Decorators.js +26 -4
- package/dist/cjs/src/decorators/field/Encrypted.js +30 -6
- package/dist/cjs/src/dream/DreamClassTransactionBuilder.js +6 -6
- package/dist/cjs/src/dream/DreamInstanceTransactionBuilder.js +63 -27
- package/dist/cjs/src/dream/LeftJoinLoadBuilder.js +3 -3
- package/dist/cjs/src/dream/LoadBuilder.js +1 -1
- package/dist/cjs/src/dream/Query.js +542 -167
- package/dist/cjs/src/dream/QueryDriver/Base.js +72 -0
- package/dist/cjs/src/dream/QueryDriver/Kysely.js +216 -50
- package/dist/cjs/src/dream/internal/associations/assertRecognizedAssociationConditionKeys.js +48 -0
- package/dist/cjs/src/dream/internal/associations/associationQuery.js +4 -0
- package/dist/cjs/src/dream/internal/reload.js +6 -1
- package/dist/cjs/src/dream/internal/saveDream.js +8 -2
- package/dist/cjs/src/dream/internal/sqlResultToDreamInstance.js +2 -0
- package/dist/cjs/src/dream/internal/undestroyDream.js +1 -1
- package/dist/cjs/src/dream-app/index.js +38 -0
- package/dist/cjs/src/encrypt/InternalEncrypt.js +49 -4
- package/dist/cjs/src/encrypt/defaultEncryptedColumnName.js +10 -0
- package/dist/cjs/src/encrypt/index.js +76 -9
- package/dist/cjs/src/errors/DoNotSetEncryptedFieldsDirectly.js +4 -0
- package/dist/cjs/src/errors/associations/UnrecognizedAssociationConditionKeys.js +25 -0
- package/dist/cjs/src/helpers/Env.js +28 -0
- package/dist/cjs/src/helpers/cli/generateDreamContent.js +2 -1
- package/dist/cjs/src/helpers/cli/generateFactoryContent.js +1 -1
- package/dist/cjs/src/helpers/cli/generateMigrationContent.js +9 -9
- package/dist/cjs/src/helpers/cli/generateSerializerContent.js +21 -8
- package/dist/cjs/src/serializer/SerializerRenderer.js +65 -13
- package/dist/cjs/src/serializer/builders/DreamSerializerBuilder.js +54 -38
- package/dist/cjs/src/serializer/builders/ObjectSerializerBuilder.js +34 -14
- package/dist/cjs/src/serializer/helpers/serializersForAssociatedClass.js +43 -0
- package/dist/esm/src/Dream.js +270 -69
- package/dist/esm/src/bin/index.js +13 -0
- package/dist/esm/src/cli/index.js +28 -17
- package/dist/esm/src/db/migration-helpers/DreamMigrationHelpers.js +23 -21
- package/dist/esm/src/decorators/Decorators.js +26 -4
- package/dist/esm/src/decorators/field/Encrypted.js +30 -6
- package/dist/esm/src/dream/DreamClassTransactionBuilder.js +6 -6
- package/dist/esm/src/dream/DreamInstanceTransactionBuilder.js +63 -27
- package/dist/esm/src/dream/LeftJoinLoadBuilder.js +3 -3
- package/dist/esm/src/dream/LoadBuilder.js +1 -1
- package/dist/esm/src/dream/Query.js +542 -167
- package/dist/esm/src/dream/QueryDriver/Base.js +72 -0
- package/dist/esm/src/dream/QueryDriver/Kysely.js +216 -50
- package/dist/esm/src/dream/internal/associations/assertRecognizedAssociationConditionKeys.js +48 -0
- package/dist/esm/src/dream/internal/associations/associationQuery.js +4 -0
- package/dist/esm/src/dream/internal/reload.js +6 -1
- package/dist/esm/src/dream/internal/saveDream.js +8 -2
- package/dist/esm/src/dream/internal/sqlResultToDreamInstance.js +2 -0
- package/dist/esm/src/dream/internal/undestroyDream.js +1 -1
- package/dist/esm/src/dream-app/index.js +38 -0
- package/dist/esm/src/encrypt/InternalEncrypt.js +49 -4
- package/dist/esm/src/encrypt/defaultEncryptedColumnName.js +10 -0
- package/dist/esm/src/encrypt/index.js +76 -9
- package/dist/esm/src/errors/DoNotSetEncryptedFieldsDirectly.js +4 -0
- package/dist/esm/src/errors/associations/UnrecognizedAssociationConditionKeys.js +25 -0
- package/dist/esm/src/helpers/Env.js +28 -0
- package/dist/esm/src/helpers/cli/generateDreamContent.js +2 -1
- package/dist/esm/src/helpers/cli/generateFactoryContent.js +1 -1
- package/dist/esm/src/helpers/cli/generateMigrationContent.js +9 -9
- package/dist/esm/src/helpers/cli/generateSerializerContent.js +21 -8
- package/dist/esm/src/serializer/SerializerRenderer.js +65 -13
- package/dist/esm/src/serializer/builders/DreamSerializerBuilder.js +54 -38
- package/dist/esm/src/serializer/builders/ObjectSerializerBuilder.js +34 -14
- package/dist/esm/src/serializer/helpers/serializersForAssociatedClass.js +43 -0
- package/dist/types/src/Dream.d.ts +217 -55
- package/dist/types/src/bin/index.d.ts +7 -1
- package/dist/types/src/cli/index.d.ts +13 -0
- package/dist/types/src/db/migration-helpers/DreamMigrationHelpers.d.ts +2 -2
- package/dist/types/src/decorators/Decorators.d.ts +26 -3
- package/dist/types/src/decorators/field/Encrypted.d.ts +6 -1
- package/dist/types/src/dream/DreamClassTransactionBuilder.d.ts +9 -9
- package/dist/types/src/dream/DreamInstanceTransactionBuilder.d.ts +52 -25
- package/dist/types/src/dream/LeftJoinLoadBuilder.d.ts +4 -4
- package/dist/types/src/dream/LoadBuilder.d.ts +1 -1
- package/dist/types/src/dream/Query.d.ts +272 -33
- package/dist/types/src/dream/QueryDriver/Base.d.ts +63 -1
- package/dist/types/src/dream/QueryDriver/Kysely.d.ts +85 -1
- package/dist/types/src/dream/internal/associations/assertRecognizedAssociationConditionKeys.d.ts +29 -0
- package/dist/types/src/dream-app/index.d.ts +56 -2
- package/dist/types/src/encrypt/InternalEncrypt.d.ts +20 -1
- package/dist/types/src/encrypt/defaultEncryptedColumnName.d.ts +7 -0
- package/dist/types/src/encrypt/index.d.ts +75 -6
- package/dist/types/src/errors/associations/UnrecognizedAssociationConditionKeys.d.ts +8 -0
- package/dist/types/src/helpers/Env.d.ts +28 -0
- package/dist/types/src/package-exports/openapi.d.ts +1 -1
- package/dist/types/src/package-exports/types.d.ts +2 -2
- package/dist/types/src/serializer/SerializerRenderer.d.ts +13 -0
- package/dist/types/src/serializer/builders/DreamSerializerBuilder.d.ts +59 -55
- package/dist/types/src/serializer/builders/ObjectSerializerBuilder.d.ts +40 -19
- package/dist/types/src/serializer/helpers/serializersForAssociatedClass.d.ts +17 -0
- package/dist/types/src/types/lifecycle.d.ts +6 -0
- package/dist/types/src/types/openapi.d.ts +52 -29
- package/dist/types/src/types/serializer.d.ts +43 -2
- package/dist/types/src/types/types/lifecycle.ts +6 -0
- package/dist/types/src/types/types/openapi.ts +51 -37
- package/dist/types/src/types/types/serializer.ts +62 -2
- package/dist/types/src/types/types/variadic.ts +99 -43
- package/dist/types/src/types/variadic.d.ts +29 -3
- package/docs/assets/hierarchy.js +1 -1
- package/docs/assets/highlight.css +4 -11
- package/docs/assets/navigation.js +1 -1
- package/docs/assets/search.js +1 -1
- package/docs/classes/db.DreamMigrationHelpers.html +13 -13
- package/docs/classes/db.KyselyQueryDriver.html +85 -46
- package/docs/classes/db.PostgresQueryDriver.html +86 -47
- package/docs/classes/db.QueryDriverBase.html +84 -45
- package/docs/classes/errors.CannotSaveMissingDream.html +2 -2
- package/docs/classes/errors.CheckConstraintViolation.html +3 -3
- package/docs/classes/errors.ColumnOverflow.html +3 -3
- package/docs/classes/errors.CreateOrFindByFailedToCreateAndFind.html +3 -3
- package/docs/classes/errors.DataIncompatibleWithDatabaseField.html +3 -3
- package/docs/classes/errors.DataTypeColumnTypeMismatch.html +3 -3
- package/docs/classes/errors.DecryptionError.html +2 -2
- package/docs/classes/errors.DecryptionParseError.html +2 -2
- package/docs/classes/errors.DecryptionRotationError.html +3 -3
- package/docs/classes/errors.GlobalNameNotSet.html +3 -3
- package/docs/classes/errors.InvalidCalendarDate.html +2 -2
- package/docs/classes/errors.InvalidClockTime.html +2 -2
- package/docs/classes/errors.InvalidClockTimeTz.html +2 -2
- package/docs/classes/errors.InvalidDateTime.html +2 -2
- package/docs/classes/errors.MissingSerializersDefinition.html +3 -3
- package/docs/classes/errors.NonLoadedAssociation.html +3 -3
- package/docs/classes/errors.NotNullViolation.html +3 -3
- package/docs/classes/errors.RecordNotFound.html +3 -3
- package/docs/classes/errors.SortableScopeDidNotStabilize.html +3 -3
- package/docs/classes/errors.SortableScopeLockWaitTimedOut.html +3 -3
- package/docs/classes/errors.ValidationError.html +3 -3
- package/docs/classes/index.CalendarDate.html +33 -33
- package/docs/classes/index.ClockTime.html +32 -32
- package/docs/classes/index.ClockTimeTz.html +35 -35
- package/docs/classes/index.DateTime.html +86 -86
- package/docs/classes/index.Decorators.html +37 -23
- package/docs/classes/index.Dream.html +281 -155
- package/docs/classes/index.DreamApp.html +40 -10
- package/docs/classes/index.DreamTransaction.html +3 -3
- package/docs/classes/index.Env.html +16 -2
- package/docs/classes/index.Query.html +331 -129
- package/docs/classes/system.CliFileWriter.html +4 -4
- package/docs/classes/system.DreamBin.html +6 -2
- package/docs/classes/system.DreamCLI.html +7 -7
- package/docs/classes/system.DreamImporter.html +2 -2
- package/docs/classes/system.DreamLogos.html +2 -2
- package/docs/classes/system.DreamSerializerBuilder.html +52 -34
- package/docs/classes/system.ObjectSerializerBuilder.html +41 -22
- package/docs/classes/system.PathHelpers.html +4 -4
- package/docs/classes/utils.Encrypt.html +54 -10
- package/docs/classes/utils.Range.html +2 -2
- package/docs/functions/db.closeAllDbConnections.html +1 -1
- package/docs/functions/db.dreamDbConnections.html +1 -1
- package/docs/functions/db.untypedDb.html +1 -1
- package/docs/functions/db.validateColumn.html +1 -1
- package/docs/functions/db.validateTable.html +1 -1
- package/docs/functions/errors.pgErrorType.html +1 -1
- package/docs/functions/index.DreamSerializer.html +1 -1
- package/docs/functions/index.ObjectSerializer.html +1 -1
- package/docs/functions/index.ReplicaSafe.html +1 -1
- package/docs/functions/index.STI.html +1 -1
- package/docs/functions/index.SoftDelete.html +1 -1
- package/docs/functions/utils.camelize.html +1 -1
- package/docs/functions/utils.capitalize.html +1 -1
- package/docs/functions/utils.cloneDeepSafe.html +1 -1
- package/docs/functions/utils.compact.html +1 -1
- package/docs/functions/utils.groupBy.html +1 -1
- package/docs/functions/utils.hyphenize.html +1 -1
- package/docs/functions/utils.intersection.html +1 -1
- package/docs/functions/utils.isEmpty.html +1 -1
- package/docs/functions/utils.normalizeUnicode.html +1 -1
- package/docs/functions/utils.pascalize.html +1 -1
- package/docs/functions/utils.percent.html +1 -1
- package/docs/functions/utils.range.html +1 -1
- package/docs/functions/utils.round.html +1 -1
- package/docs/functions/utils.sanitizeString.html +1 -1
- package/docs/functions/utils.snakeify.html +1 -1
- package/docs/functions/utils.sort.html +1 -1
- package/docs/functions/utils.sortBy.html +1 -1
- package/docs/functions/utils.sortObjectByKey.html +1 -1
- package/docs/functions/utils.sortObjectByValue.html +1 -1
- package/docs/functions/utils.uncapitalize.html +1 -1
- package/docs/functions/utils.uniq.html +1 -1
- package/docs/hierarchy.html +1 -1
- package/docs/index.html +1 -1
- package/docs/interfaces/openapi.OpenapiDescription.html +2 -2
- package/docs/interfaces/openapi.OpenapiSchemaProperties.html +1 -1
- package/docs/interfaces/openapi.OpenapiSchemaPropertiesShorthand.html +1 -1
- package/docs/interfaces/openapi.OpenapiTypeFieldObject.html +1 -1
- package/docs/interfaces/types.BelongsToStatement.html +2 -2
- package/docs/interfaces/types.DecoratorContext.html +2 -2
- package/docs/interfaces/types.DecryptCallbacks.html +6 -0
- package/docs/interfaces/types.DreamAppInitOptions.html +2 -2
- package/docs/interfaces/types.DreamAppOpts.html +2 -2
- package/docs/interfaces/types.DreamDbConfig.html +6 -6
- package/docs/interfaces/types.DurationObject.html +2 -2
- package/docs/interfaces/types.EncryptOptions.html +2 -2
- package/docs/interfaces/types.EncryptionLegacyKeyUsedEvent.html +10 -0
- package/docs/interfaces/types.InternalAnyTypedSerializerRendersMany.html +2 -2
- package/docs/interfaces/types.InternalAnyTypedSerializerRendersOne.html +2 -2
- package/docs/interfaces/types.SerializerRendererOpts.html +2 -2
- package/docs/modules/openapi.html +1 -1
- package/docs/modules/types.html +1 -1
- package/docs/types/openapi.CommonOpenapiSchemaObjectFields.html +1 -1
- package/docs/types/openapi.OpenapiAllTypes.html +1 -1
- package/docs/types/openapi.OpenapiFormats.html +1 -1
- package/docs/types/openapi.OpenapiNumberFormats.html +1 -1
- package/docs/types/openapi.OpenapiPrimitiveBaseTypes.html +1 -1
- package/docs/types/openapi.OpenapiPrimitiveTypes.html +1 -1
- package/docs/types/openapi.OpenapiSchemaArray.html +1 -1
- package/docs/types/openapi.OpenapiSchemaArrayShorthand.html +1 -1
- package/docs/types/openapi.OpenapiSchemaBase.html +1 -1
- package/docs/types/openapi.OpenapiSchemaBody.html +1 -1
- package/docs/types/openapi.OpenapiSchemaBodyShorthand.html +1 -1
- package/docs/types/openapi.OpenapiSchemaCombinatorFields.html +4 -0
- package/docs/types/openapi.OpenapiSchemaCommonFields.html +5 -1
- package/docs/types/openapi.OpenapiSchemaExpressionAllOf.html +1 -2
- package/docs/types/openapi.OpenapiSchemaExpressionAnyOf.html +1 -2
- package/docs/types/openapi.OpenapiSchemaExpressionOneOf.html +1 -2
- package/docs/types/openapi.OpenapiSchemaExpressionRef.html +2 -2
- package/docs/types/openapi.OpenapiSchemaExpressionRefSchemaShorthand.html +2 -2
- package/docs/types/openapi.OpenapiSchemaInteger.html +1 -1
- package/docs/types/openapi.OpenapiSchemaNull.html +4 -2
- package/docs/types/openapi.OpenapiSchemaNumber.html +1 -1
- package/docs/types/openapi.OpenapiSchemaObject.html +1 -1
- package/docs/types/openapi.OpenapiSchemaObjectAllOf.html +5 -1
- package/docs/types/openapi.OpenapiSchemaObjectAllOfShorthand.html +2 -1
- package/docs/types/openapi.OpenapiSchemaObjectBase.html +1 -1
- package/docs/types/openapi.OpenapiSchemaObjectBaseShorthand.html +1 -1
- package/docs/types/openapi.OpenapiSchemaObjectShorthand.html +1 -1
- package/docs/types/openapi.OpenapiSchemaPrimitiveGeneric.html +1 -1
- package/docs/types/openapi.OpenapiSchemaShorthandExpressionAllOf.html +1 -2
- package/docs/types/openapi.OpenapiSchemaShorthandExpressionAnyOf.html +1 -2
- package/docs/types/openapi.OpenapiSchemaShorthandExpressionOneOf.html +1 -2
- package/docs/types/openapi.OpenapiSchemaShorthandExpressionSerializableRef.html +2 -2
- package/docs/types/openapi.OpenapiSchemaShorthandExpressionSerializerRef.html +2 -2
- package/docs/types/openapi.OpenapiSchemaShorthandPrimitiveGeneric.html +1 -1
- package/docs/types/openapi.OpenapiSchemaString.html +1 -1
- package/docs/types/openapi.OpenapiShorthandAllTypes.html +1 -1
- package/docs/types/openapi.OpenapiShorthandPrimitiveBaseTypes.html +1 -1
- package/docs/types/openapi.OpenapiShorthandPrimitiveTypes.html +1 -1
- package/docs/types/openapi.OpenapiTypeField.html +1 -1
- package/docs/types/system.DreamAppAllowedPackageManagersEnum.html +1 -1
- package/docs/types/types.CalendarDateDurationUnit.html +1 -1
- package/docs/types/types.CalendarDateObject.html +1 -1
- package/docs/types/types.Camelized.html +1 -1
- package/docs/types/types.ClockTimeObject.html +1 -1
- package/docs/types/types.DbConnectionType.html +1 -1
- package/docs/types/types.DbTypes.html +1 -1
- package/docs/types/types.DreamAssociationMetadata.html +1 -1
- package/docs/types/types.DreamAttributes.html +1 -1
- package/docs/types/types.DreamClassAssociationAndStatement.html +1 -1
- package/docs/types/types.DreamClassColumn.html +1 -1
- package/docs/types/types.DreamColumn.html +1 -1
- package/docs/types/types.DreamColumnNames.html +1 -1
- package/docs/types/types.DreamLogLevel.html +1 -1
- package/docs/types/types.DreamLogger.html +2 -2
- package/docs/types/types.DreamModelSerializerType.html +1 -1
- package/docs/types/types.DreamOrViewModelClassSerializerKey.html +1 -1
- package/docs/types/types.DreamOrViewModelSerializerKey.html +1 -1
- package/docs/types/types.DreamParamSafeAttributes.html +1 -1
- package/docs/types/types.DreamParamSafeColumnNames.html +1 -1
- package/docs/types/types.DreamSerializable.html +1 -1
- package/docs/types/types.DreamSerializableArray.html +1 -1
- package/docs/types/types.DreamSerializerKey.html +1 -1
- package/docs/types/types.DreamSerializers.html +1 -1
- package/docs/types/types.DreamVirtualColumns.html +1 -1
- package/docs/types/types.DurationUnit.html +1 -1
- package/docs/types/types.EncryptAlgorithm.html +1 -1
- package/docs/types/types.HasManyStatement.html +1 -1
- package/docs/types/types.HasOneStatement.html +1 -1
- package/docs/types/types.Hyphenized.html +1 -1
- package/docs/types/types.Pascalized.html +1 -1
- package/docs/types/types.PrimaryKeyType.html +1 -1
- package/docs/types/types.RoundingPrecision.html +1 -1
- package/docs/types/types.SerializerCasing.html +1 -1
- package/docs/types/types.SimpleObjectSerializerType.html +1 -1
- package/docs/types/types.Snakeified.html +1 -1
- package/docs/types/types.StrictInterface.html +1 -1
- package/docs/types/types.UpdateableAssociationProperties.html +1 -1
- package/docs/types/types.UpdateableProperties.html +1 -1
- package/docs/types/types.ValidationType.html +1 -1
- package/docs/types/types.ViewModel.html +2 -2
- package/docs/types/types.ViewModelClass.html +1 -1
- package/docs/types/types.WeekdayName.html +1 -1
- package/docs/types/types.WhereStatementForDream.html +1 -1
- package/docs/types/types.WhereStatementForDreamClass.html +1 -1
- package/docs/variables/index.DreamConst.html +1 -1
- package/docs/variables/index.ops.html +1 -1
- package/docs/variables/openapi.openapiPrimitiveTypes.html +1 -1
- package/docs/variables/openapi.openapiShorthandPrimitiveTypes.html +1 -1
- package/docs/variables/system.DreamAppAllowedPackageManagersEnumValues.html +1 -1
- package/docs/variables/system.primaryKeyTypes.html +1 -1
- package/package.json +1 -1
- package/dist/cjs/src/serializer/helpers/serializerForAssociatedClass.js +0 -37
- package/dist/esm/src/serializer/helpers/serializerForAssociatedClass.js +0 -37
- package/dist/types/src/serializer/helpers/serializerForAssociatedClass.d.ts +0 -9
- package/docs/types/openapi.OpenapiSchemaObjectAnyOf.html +0 -1
- package/docs/types/openapi.OpenapiSchemaObjectAnyOfShorthand.html +0 -1
- package/docs/types/openapi.OpenapiSchemaObjectOneOf.html +0 -1
- package/docs/types/openapi.OpenapiSchemaObjectOneOfShorthand.html +0 -1
|
@@ -3,6 +3,7 @@ import CannotCreateAssociationOnUnpersistedDream from '../errors/associations/Ca
|
|
|
3
3
|
import CannotDestroyAssociationOnUnpersistedDream from '../errors/associations/CannotDestroyAssociationOnUnpersistedDream.js';
|
|
4
4
|
import CannotUpdateAssociationOnUnpersistedDream from '../errors/associations/CannotUpdateAssociationOnUnpersistedDream.js';
|
|
5
5
|
import RecordNotFound from '../errors/RecordNotFound.js';
|
|
6
|
+
import assertRecognizedAssociationConditionKeys, { DESTROY_ASSOCIATION_OPTION_KEYS, UPDATE_ASSOCIATION_OPTION_KEYS, } from './internal/associations/assertRecognizedAssociationConditionKeys.js';
|
|
6
7
|
import associationQuery from './internal/associations/associationQuery.js';
|
|
7
8
|
import associationUpdateQuery from './internal/associations/associationUpdateQuery.js';
|
|
8
9
|
import createAssociation from './internal/associations/createAssociation.js';
|
|
@@ -33,26 +34,29 @@ export default class DreamInstanceTransactionBuilder {
|
|
|
33
34
|
/**
|
|
34
35
|
* Loads the requested associations upon execution
|
|
35
36
|
*
|
|
37
|
+
* **IMPORTANT:** `load().execute()` returns a **new clone** of the model with the
|
|
38
|
+
* associations loaded. It does NOT modify the original instance.
|
|
39
|
+
*
|
|
36
40
|
* NOTE: {@link Dream#preload} is often a preferrable way of achieving the
|
|
37
41
|
* same goal.
|
|
38
42
|
*
|
|
39
43
|
* ```ts
|
|
40
44
|
* await ApplicationModel.transaction(async txn => {
|
|
41
|
-
* await user
|
|
45
|
+
* const loadedUser = await user
|
|
42
46
|
* .txn(txn)
|
|
43
|
-
* .load('posts', { body: ops.ilike('%hello world%') }, 'comments', 'replies')
|
|
47
|
+
* .load('posts', { and: { body: ops.ilike('%hello world%') } }, 'comments', 'replies')
|
|
44
48
|
* .load('images')
|
|
45
49
|
* .execute()
|
|
46
50
|
*
|
|
47
|
-
*
|
|
51
|
+
* loadedUser.posts[0].comments[0].replies[0]
|
|
48
52
|
* // Reply{}
|
|
49
53
|
*
|
|
50
|
-
*
|
|
54
|
+
* loadedUser.images[0]
|
|
51
55
|
* // Image{}
|
|
52
56
|
* })
|
|
53
57
|
* ```
|
|
54
58
|
*
|
|
55
|
-
* @param args - A
|
|
59
|
+
* @param args - A chain of association names and and/andNot/andAny clauses
|
|
56
60
|
* @returns A chainable LoadBuilder instance
|
|
57
61
|
*/
|
|
58
62
|
load(...args) {
|
|
@@ -112,32 +116,34 @@ export default class DreamInstanceTransactionBuilder {
|
|
|
112
116
|
* Load each specified association using a single SQL query.
|
|
113
117
|
* See {@link #load} for loading in separate queries.
|
|
114
118
|
*
|
|
115
|
-
*
|
|
116
|
-
*
|
|
119
|
+
* **IMPORTANT:** Like `load()`, `leftJoinLoad().execute()` returns a **new clone** of the
|
|
120
|
+
* model with associations loaded. It does NOT modify the original instance.
|
|
121
|
+
*
|
|
122
|
+
* Note: since leftJoinLoad loads via single query, it has
|
|
123
|
+
* some downsides that may be avoided using {@link #load}:
|
|
117
124
|
* 1. `limit` and `offset` will be automatically removed
|
|
118
125
|
* 2. `through` associations will bring additional namespaces into the query that can conflict with through associations from other associations, creating an invalid query
|
|
119
|
-
* 3. each nested association will result in an additional record which duplicates data from the outer record. E.g., given `.
|
|
126
|
+
* 3. each nested association will result in an additional record which duplicates data from the outer record. E.g., given `.leftJoinLoad('a', 'b', 'c')`, if each `a` has 10 `b` and each `b` has 10 `c`, then for one `a`, 100 records will be returned, each of which has all of the columns of `a`. `.load('a', 'b', 'c')` would perform three separate SQL queries, but the data for a single `a` would only be returned once.
|
|
120
127
|
* 4. the individual query becomes more complex the more associations are included
|
|
121
128
|
* 5. associations loading associations loading associations could result in exponential amounts of data; in those cases, `.load(...).findEach(...)` avoids instantiating massive amounts of data at once
|
|
122
|
-
* Loads the requested associations upon execution
|
|
123
|
-
*
|
|
124
|
-
* NOTE: {@link Dream#leftJoinPreload} is often a preferrable way of achieving the
|
|
125
|
-
* same goal.
|
|
126
129
|
*
|
|
127
130
|
* ```ts
|
|
128
|
-
* await
|
|
129
|
-
*
|
|
130
|
-
*
|
|
131
|
-
*
|
|
131
|
+
* await ApplicationModel.transaction(async txn => {
|
|
132
|
+
* const loadedUser = await user
|
|
133
|
+
* .txn(txn)
|
|
134
|
+
* .leftJoinLoad('posts', { and: { body: ops.ilike('%hello world%') } }, 'comments', 'replies')
|
|
135
|
+
* .leftJoinLoad('images')
|
|
136
|
+
* .execute()
|
|
132
137
|
*
|
|
133
|
-
*
|
|
134
|
-
*
|
|
138
|
+
* loadedUser.posts[0].comments[0].replies[0]
|
|
139
|
+
* // Reply{}
|
|
135
140
|
*
|
|
136
|
-
*
|
|
137
|
-
*
|
|
141
|
+
* loadedUser.images[0]
|
|
142
|
+
* // Image{}
|
|
143
|
+
* })
|
|
138
144
|
* ```
|
|
139
145
|
*
|
|
140
|
-
* @param args - A
|
|
146
|
+
* @param args - A chain of association names and and/andNot/andAny clauses
|
|
141
147
|
* @returns A chainable LeftJoinLoadBuilder instance
|
|
142
148
|
*/
|
|
143
149
|
leftJoinLoad(...args) {
|
|
@@ -153,7 +159,7 @@ export default class DreamInstanceTransactionBuilder {
|
|
|
153
159
|
* })
|
|
154
160
|
* ```
|
|
155
161
|
*
|
|
156
|
-
* @param args - A chain of association names and
|
|
162
|
+
* @param args - A chain of association names and and/andNot/andAny clauses
|
|
157
163
|
* @returns A Query for this model with the inner join clause applied
|
|
158
164
|
*/
|
|
159
165
|
innerJoin(...args) {
|
|
@@ -169,7 +175,7 @@ export default class DreamInstanceTransactionBuilder {
|
|
|
169
175
|
* })
|
|
170
176
|
* ```
|
|
171
177
|
*
|
|
172
|
-
* @param args - A chain of association names and
|
|
178
|
+
* @param args - A chain of association names and and/andNot/andAny clauses
|
|
173
179
|
* @returns A Query for this model with the left join clause applied
|
|
174
180
|
*/
|
|
175
181
|
leftJoin(...args) {
|
|
@@ -252,6 +258,12 @@ export default class DreamInstanceTransactionBuilder {
|
|
|
252
258
|
* See {@link Dream.save | save} for details on
|
|
253
259
|
* the side effects of saving.
|
|
254
260
|
*
|
|
261
|
+
* A column whose value is still `undefined` after setters run is
|
|
262
|
+
* skipped, not written (see {@link Dream.save | save}), with two
|
|
263
|
+
* `@Encrypted` exceptions: `undefined` for an encrypted property (e.g.
|
|
264
|
+
* `secret`) is encrypted to `null`, so it clears the column, and
|
|
265
|
+
* `undefined` for its backing column (e.g. `encryptedSecret`) throws.
|
|
266
|
+
*
|
|
255
267
|
* NOTE:
|
|
256
268
|
* To bypass custom-defined setters, use {@link Dream.updateAttributes | updateAttributes} instead.
|
|
257
269
|
*
|
|
@@ -279,6 +291,18 @@ export default class DreamInstanceTransactionBuilder {
|
|
|
279
291
|
* See {@link Dream.save | save} for details on
|
|
280
292
|
* the side effects of saving.
|
|
281
293
|
*
|
|
294
|
+
* An encrypted property (e.g. `secret`) is still encrypted. Its
|
|
295
|
+
* `@Encrypted` backing column (e.g. `encryptedSecret`) accepts only
|
|
296
|
+
* ciphertext that decrypts with this app's column encryption keys, or
|
|
297
|
+
* `null`; anything else throws before anything is saved (see
|
|
298
|
+
* {@link Dream.setAttribute | setAttribute}).
|
|
299
|
+
*
|
|
300
|
+
* A column whose value is still `undefined` after setters run is
|
|
301
|
+
* skipped, not written (see {@link Dream.save | save}), with two
|
|
302
|
+
* `@Encrypted` exceptions: `undefined` for an encrypted property (e.g.
|
|
303
|
+
* `secret`) is encrypted to `null`, so it clears the column, and
|
|
304
|
+
* `undefined` for its backing column (e.g. `encryptedSecret`) throws.
|
|
305
|
+
*
|
|
282
306
|
* NOTE:
|
|
283
307
|
* To update the values without bypassing any custom-defined
|
|
284
308
|
* setters, use {@link Dream.update | update} instead.
|
|
@@ -329,6 +353,10 @@ export default class DreamInstanceTransactionBuilder {
|
|
|
329
353
|
* Upon updating an instance, the update timestamp (if defined)
|
|
330
354
|
* will be updated on the model.
|
|
331
355
|
*
|
|
356
|
+
* A column whose value is `undefined` is skipped, not written: a new
|
|
357
|
+
* record gets the column's database default, and a persisted record
|
|
358
|
+
* keeps the value stored for it. Set a column to `null` to clear it.
|
|
359
|
+
*
|
|
332
360
|
* ```ts
|
|
333
361
|
* const user = User.new({ email: 'how@yadoin' })
|
|
334
362
|
*
|
|
@@ -386,8 +414,8 @@ export default class DreamInstanceTransactionBuilder {
|
|
|
386
414
|
}
|
|
387
415
|
/**
|
|
388
416
|
* Updates all records matching the association with
|
|
389
|
-
* the provided attributes. If
|
|
390
|
-
*
|
|
417
|
+
* the provided attributes. If an and, andNot or andAny
|
|
418
|
+
* statement is passed, it will be applied to the query
|
|
391
419
|
* before updating.
|
|
392
420
|
*
|
|
393
421
|
* ```ts
|
|
@@ -402,13 +430,16 @@ export default class DreamInstanceTransactionBuilder {
|
|
|
402
430
|
* @param associationName - The name of the association to update
|
|
403
431
|
* @param attributes - The attributes to update on the association
|
|
404
432
|
* @param updateAssociationOptions - Options for updating the association
|
|
405
|
-
* @param updateAssociationOptions.
|
|
433
|
+
* @param updateAssociationOptions.and - Optional and statement to apply to query before updating
|
|
434
|
+
* @param updateAssociationOptions.andNot - Optional andNot statement to apply to query before updating
|
|
435
|
+
* @param updateAssociationOptions.andAny - Optional andAny statement to apply to query before updating
|
|
406
436
|
* @param updateAssociationOptions.bypassAllDefaultScopes - If true, bypasses user-removable default scopes when updating the association; an STI child's reserved discriminator remains enforced, including when associations are loaded. Defaults to false
|
|
407
437
|
* @param updateAssociationOptions.defaultScopesToBypass - An array of default scope names to bypass when updating the association. Defaults to an empty array
|
|
408
438
|
* @param updateAssociationOptions.skipHooks - If true, skips applying model hooks during the update operation. Defaults to false
|
|
409
439
|
* @returns The number of updated records
|
|
410
440
|
*/
|
|
411
441
|
async updateAssociation(associationName, attributes, updateAssociationOptions) {
|
|
442
|
+
assertRecognizedAssociationConditionKeys(updateAssociationOptions, UPDATE_ASSOCIATION_OPTION_KEYS, associationName, 'updateAssociation');
|
|
412
443
|
if (this.dreamInstance.isNewRecord)
|
|
413
444
|
throw new CannotUpdateAssociationOnUnpersistedDream(this.dreamInstance, associationName);
|
|
414
445
|
return await associationUpdateQuery(this.dreamInstance, this.dreamTransaction, associationName, {
|
|
@@ -465,6 +496,7 @@ export default class DreamInstanceTransactionBuilder {
|
|
|
465
496
|
* @returns The number of records deleted
|
|
466
497
|
*/
|
|
467
498
|
async destroyAssociation(associationName, options) {
|
|
499
|
+
assertRecognizedAssociationConditionKeys(options, DESTROY_ASSOCIATION_OPTION_KEYS, associationName, 'destroyAssociation');
|
|
468
500
|
if (this.dreamInstance.isNewRecord)
|
|
469
501
|
throw new CannotDestroyAssociationOnUnpersistedDream(this.dreamInstance, associationName);
|
|
470
502
|
return await destroyAssociation(this.dreamInstance, this.dreamTransaction, associationName, {
|
|
@@ -503,6 +535,7 @@ export default class DreamInstanceTransactionBuilder {
|
|
|
503
535
|
* @returns The number of records deleted
|
|
504
536
|
*/
|
|
505
537
|
async reallyDestroyAssociation(associationName, options) {
|
|
538
|
+
assertRecognizedAssociationConditionKeys(options, DESTROY_ASSOCIATION_OPTION_KEYS, associationName, 'reallyDestroyAssociation');
|
|
506
539
|
if (this.dreamInstance.isNewRecord)
|
|
507
540
|
throw new CannotDestroyAssociationOnUnpersistedDream(this.dreamInstance, associationName);
|
|
508
541
|
return await destroyAssociation(this.dreamInstance, this.dreamTransaction, associationName, {
|
|
@@ -521,7 +554,9 @@ export default class DreamInstanceTransactionBuilder {
|
|
|
521
554
|
* will also be undeleted.
|
|
522
555
|
*
|
|
523
556
|
* ```ts
|
|
524
|
-
* await
|
|
557
|
+
* await ApplicationModel.transaction(async txn => {
|
|
558
|
+
* await user.txn(txn).undestroyAssociation('posts', { and: { body: 'hello world' } })
|
|
559
|
+
* })
|
|
525
560
|
* ```
|
|
526
561
|
*
|
|
527
562
|
* @param associationName - The name of the association to undestroy
|
|
@@ -536,6 +571,7 @@ export default class DreamInstanceTransactionBuilder {
|
|
|
536
571
|
* @returns The number of records undestroyed
|
|
537
572
|
*/
|
|
538
573
|
async undestroyAssociation(associationName, options) {
|
|
574
|
+
assertRecognizedAssociationConditionKeys(options, DESTROY_ASSOCIATION_OPTION_KEYS, associationName, 'undestroyAssociation');
|
|
539
575
|
return await undestroyAssociation(this.dreamInstance, this.dreamTransaction, associationName, {
|
|
540
576
|
...undestroyOptions(options),
|
|
541
577
|
joinAndStatements: {
|
|
@@ -28,13 +28,13 @@ export default class LeftJoinLoadBuilder {
|
|
|
28
28
|
return this;
|
|
29
29
|
}
|
|
30
30
|
/**
|
|
31
|
-
* Attaches a
|
|
31
|
+
* Attaches a leftJoinLoad statement to the load builder
|
|
32
32
|
*
|
|
33
33
|
* ```ts
|
|
34
34
|
* const user = await User.firstOrFail()
|
|
35
35
|
* await user
|
|
36
|
-
* .
|
|
37
|
-
* .
|
|
36
|
+
* .leftJoinLoad('settings')
|
|
37
|
+
* .leftJoinLoad('posts', 'comments', 'replies', ['image', 'localizedText'])
|
|
38
38
|
* .execute()
|
|
39
39
|
* ```
|
|
40
40
|
*/
|
|
@@ -93,7 +93,7 @@ export default class LoadBuilder {
|
|
|
93
93
|
* .execute()
|
|
94
94
|
* ```
|
|
95
95
|
*
|
|
96
|
-
* @param args - A
|
|
96
|
+
* @param args - A chain of association names and and/andNot/andAny clauses to load
|
|
97
97
|
* @returns A chainable LoadBuilder instance
|
|
98
98
|
*/
|
|
99
99
|
load(...args) {
|