@abedmurrar/objection 4.0.0-alpha.0 → 4.0.0-beta.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/README.md +103 -67
- package/lib/index.mjs +6 -0
- package/lib/initialize.js +6 -9
- package/lib/model/AjvValidator.js +235 -282
- package/lib/model/Model.js +653 -823
- package/lib/model/ModifierNotFoundError.js +5 -7
- package/lib/model/NotFoundError.js +14 -18
- package/lib/model/RelationDoesNotExistError.js +6 -9
- package/lib/model/ValidationError.js +33 -41
- package/lib/model/Validator.js +15 -21
- package/lib/model/getModel.js +1 -3
- package/lib/model/graph/ModelGraph.js +44 -64
- package/lib/model/graph/ModelGraphBuilder.js +164 -217
- package/lib/model/graph/ModelGraphEdge.js +31 -43
- package/lib/model/graph/ModelGraphNode.js +192 -231
- package/lib/model/inheritModel.js +9 -18
- package/lib/model/modelBindKnex.js +48 -62
- package/lib/model/modelClone.js +79 -98
- package/lib/model/modelColPropMap.js +16 -26
- package/lib/model/modelConcurrency.js +24 -0
- package/lib/model/modelId.js +44 -49
- package/lib/model/modelJsonAttributes.js +56 -76
- package/lib/model/modelParseRelations.js +68 -67
- package/lib/model/modelQueryProps.js +76 -107
- package/lib/model/modelSet.js +92 -112
- package/lib/model/modelTableMetadata.js +60 -72
- package/lib/model/modelToJson.js +120 -150
- package/lib/model/modelUtils.js +30 -37
- package/lib/model/modelValidate.js +34 -42
- package/lib/model/modelValues.js +78 -91
- package/lib/model/modelVisitor.js +22 -29
- package/lib/objection.js +42 -67
- package/lib/queryBuilder/FunctionBuilder.js +231 -279
- package/lib/queryBuilder/InternalOptions.js +19 -24
- package/lib/queryBuilder/JoinBuilder.js +116 -149
- package/lib/queryBuilder/QueryBuilder.js +1009 -1271
- package/lib/queryBuilder/QueryBuilderBase.js +647 -865
- package/lib/queryBuilder/QueryBuilderContext.js +14 -21
- package/lib/queryBuilder/QueryBuilderContextBase.js +20 -29
- package/lib/queryBuilder/QueryBuilderOperationSupport.js +462 -536
- package/lib/queryBuilder/QueryBuilderUserContext.js +19 -25
- package/lib/queryBuilder/RawBuilder.js +58 -73
- package/lib/queryBuilder/ReferenceBuilder.js +232 -270
- package/lib/queryBuilder/RelationExpression.js +322 -380
- package/lib/queryBuilder/StaticHookArguments.js +94 -106
- package/lib/queryBuilder/ValueBuilder.js +100 -112
- package/lib/queryBuilder/expressions.js +86 -116
- package/lib/queryBuilder/functions/mysql.js +642 -697
- package/lib/queryBuilder/graph/GraphAction.js +44 -59
- package/lib/queryBuilder/graph/GraphData.js +7 -9
- package/lib/queryBuilder/graph/GraphFetcher.js +115 -151
- package/lib/queryBuilder/graph/GraphNodeDbExistence.js +114 -152
- package/lib/queryBuilder/graph/GraphOperation.js +16 -22
- package/lib/queryBuilder/graph/GraphOptions.js +143 -185
- package/lib/queryBuilder/graph/GraphUpsert.js +167 -241
- package/lib/queryBuilder/graph/delete/GraphDelete.js +8 -13
- package/lib/queryBuilder/graph/delete/GraphDeleteAction.js +44 -62
- package/lib/queryBuilder/graph/insert/GraphInsert.js +99 -128
- package/lib/queryBuilder/graph/insert/GraphInsertAction.js +151 -193
- package/lib/queryBuilder/graph/insert/JoinRowGraphInsertAction.js +57 -79
- package/lib/queryBuilder/graph/patch/GraphPatch.js +8 -13
- package/lib/queryBuilder/graph/patch/GraphPatchAction.js +181 -234
- package/lib/queryBuilder/graph/recursiveUpsert/GraphRecursiveUpsert.js +16 -21
- package/lib/queryBuilder/graph/recursiveUpsert/GraphRecursiveUpsertAction.js +80 -110
- package/lib/queryBuilder/join/JoinResultColumn.js +14 -18
- package/lib/queryBuilder/join/JoinResultParser.js +88 -101
- package/lib/queryBuilder/join/RelationJoiner.js +205 -288
- package/lib/queryBuilder/join/TableNode.js +117 -144
- package/lib/queryBuilder/join/TableTree.js +60 -76
- package/lib/queryBuilder/join/utils.js +10 -16
- package/lib/queryBuilder/operations/DelegateOperation.js +93 -133
- package/lib/queryBuilder/operations/DeleteOperation.js +33 -37
- package/lib/queryBuilder/operations/FindByIdOperation.js +20 -28
- package/lib/queryBuilder/operations/FindByIdsOperation.js +17 -23
- package/lib/queryBuilder/operations/FindOperation.js +114 -131
- package/lib/queryBuilder/operations/FirstOperation.js +14 -19
- package/lib/queryBuilder/operations/FromOperation.js +69 -88
- package/lib/queryBuilder/operations/InsertAndFetchOperation.js +28 -39
- package/lib/queryBuilder/operations/InsertGraphAndFetchOperation.js +25 -35
- package/lib/queryBuilder/operations/InsertGraphOperation.js +77 -98
- package/lib/queryBuilder/operations/InsertOperation.js +132 -165
- package/lib/queryBuilder/operations/InstanceDeleteOperation.js +27 -36
- package/lib/queryBuilder/operations/InstanceFindOperation.js +9 -13
- package/lib/queryBuilder/operations/InstanceInsertOperation.js +13 -17
- package/lib/queryBuilder/operations/InstanceUpdateOperation.js +32 -46
- package/lib/queryBuilder/operations/JoinRelatedOperation.js +66 -86
- package/lib/queryBuilder/operations/KnexOperation.js +4 -7
- package/lib/queryBuilder/operations/MergeOperation.js +32 -45
- package/lib/queryBuilder/operations/ObjectionToKnexConvertingOperation.js +131 -150
- package/lib/queryBuilder/operations/OnBuildKnexOperation.js +17 -23
- package/lib/queryBuilder/operations/OnBuildOperation.js +17 -23
- package/lib/queryBuilder/operations/OnErrorOperation.js +17 -23
- package/lib/queryBuilder/operations/QueryBuilderOperation.js +231 -270
- package/lib/queryBuilder/operations/RangeOperation.js +30 -40
- package/lib/queryBuilder/operations/RelateOperation.js +14 -21
- package/lib/queryBuilder/operations/ReturningOperation.js +12 -18
- package/lib/queryBuilder/operations/RunAfterOperation.js +17 -23
- package/lib/queryBuilder/operations/RunBeforeOperation.js +17 -23
- package/lib/queryBuilder/operations/UnrelateOperation.js +12 -17
- package/lib/queryBuilder/operations/UpdateAndFetchOperation.js +48 -65
- package/lib/queryBuilder/operations/UpdateOperation.js +104 -129
- package/lib/queryBuilder/operations/UpsertGraphAndFetchOperation.js +25 -35
- package/lib/queryBuilder/operations/UpsertGraphOperation.js +36 -55
- package/lib/queryBuilder/operations/WhereCompositeOperation.js +30 -39
- package/lib/queryBuilder/operations/WhereInOperation.js +34 -36
- package/lib/queryBuilder/operations/eager/EagerOperation.js +37 -52
- package/lib/queryBuilder/operations/eager/JoinEagerOperation.js +34 -44
- package/lib/queryBuilder/operations/eager/NaiveEagerOperation.js +4 -7
- package/lib/queryBuilder/operations/eager/WhereInEagerOperation.js +193 -251
- package/lib/queryBuilder/operations/jsonApi/WhereJsonHasOperation.js +18 -25
- package/lib/queryBuilder/operations/jsonApi/WhereJsonNotObjectOperation.js +25 -41
- package/lib/queryBuilder/operations/jsonApi/WhereJsonOperation.js +19 -20
- package/lib/queryBuilder/operations/jsonApi/WhereJsonOverlapsOperation.js +23 -21
- package/lib/queryBuilder/operations/jsonApi/mysqlJsonApi.js +106 -118
- package/lib/queryBuilder/operations/jsonApi/postgresJsonApi.js +79 -108
- package/lib/queryBuilder/operations/select/SelectOperation.js +37 -53
- package/lib/queryBuilder/operations/select/Selection.js +94 -105
- package/lib/queryBuilder/operations/whereInComposite/WhereInCompositeMsSqlOperation.js +68 -101
- package/lib/queryBuilder/operations/whereInComposite/WhereInCompositeOperation.js +65 -75
- package/lib/queryBuilder/operations/whereInComposite/WhereInCompositeSqliteOperation.js +75 -84
- package/lib/queryBuilder/parsers/jsonFieldExpressionParser.js +760 -859
- package/lib/queryBuilder/parsers/relationExpressionParser.js +840 -952
- package/lib/queryBuilder/transformations/CompositeQueryTransformation.js +10 -15
- package/lib/queryBuilder/transformations/QueryTransformation.js +4 -6
- package/lib/queryBuilder/transformations/WrapMysqlModifySubqueryTransformation.js +35 -49
- package/lib/queryBuilder/transformations/index.js +3 -9
- package/lib/queryBuilder/whereScopes.js +158 -186
- package/lib/relations/Relation.js +293 -375
- package/lib/relations/RelationDeleteOperation.js +24 -28
- package/lib/relations/RelationFindOperation.js +108 -138
- package/lib/relations/RelationInsertOperation.js +24 -32
- package/lib/relations/RelationOwner.js +175 -209
- package/lib/relations/RelationProperty.js +186 -223
- package/lib/relations/RelationUpdateOperation.js +23 -29
- package/lib/relations/belongsToOne/BelongsToOneDeleteOperation.js +16 -21
- package/lib/relations/belongsToOne/BelongsToOneInsertOperation.js +30 -41
- package/lib/relations/belongsToOne/BelongsToOneRelateOperation.js +36 -47
- package/lib/relations/belongsToOne/BelongsToOneRelation.js +42 -50
- package/lib/relations/belongsToOne/BelongsToOneUnrelateOperation.js +43 -58
- package/lib/relations/hasMany/HasManyInsertOperation.js +40 -56
- package/lib/relations/hasMany/HasManyRelateOperation.js +45 -61
- package/lib/relations/hasMany/HasManyRelation.js +38 -46
- package/lib/relations/hasMany/HasManyUnrelateOperation.js +25 -32
- package/lib/relations/hasOne/HasOneRelation.js +9 -12
- package/lib/relations/hasOneThrough/HasOneThroughRelation.js +9 -12
- package/lib/relations/manyToMany/ManyToManyModifyMixin.js +73 -95
- package/lib/relations/manyToMany/ManyToManyRelation.js +374 -473
- package/lib/relations/manyToMany/ManyToManySqliteModifyMixin.js +23 -30
- package/lib/relations/manyToMany/delete/ManyToManyDeleteOperation.js +8 -10
- package/lib/relations/manyToMany/delete/ManyToManyDeleteOperationBase.js +20 -25
- package/lib/relations/manyToMany/delete/ManyToManyDeleteSqliteOperation.js +8 -12
- package/lib/relations/manyToMany/find/ManyToManyFindOperation.js +77 -100
- package/lib/relations/manyToMany/insert/ManyToManyInsertOperation.js +37 -49
- package/lib/relations/manyToMany/relate/ManyToManyRelateOperation.js +58 -74
- package/lib/relations/manyToMany/unrelate/ManyToManyUnrelateOperation.js +10 -13
- package/lib/relations/manyToMany/unrelate/ManyToManyUnrelateOperationBase.js +26 -33
- package/lib/relations/manyToMany/unrelate/ManyToManyUnrelateSqliteOperation.js +10 -15
- package/lib/relations/manyToMany/update/ManyToManyUpdateOperation.js +8 -10
- package/lib/relations/manyToMany/update/ManyToManyUpdateOperationBase.js +61 -78
- package/lib/relations/manyToMany/update/ManyToManyUpdateSqliteOperation.js +8 -12
- package/lib/transaction.js +53 -83
- package/lib/utils/assert.js +15 -21
- package/lib/utils/buildUtils.js +17 -19
- package/lib/utils/classUtils.js +7 -11
- package/lib/utils/cloneDeep.js +365 -0
- package/lib/utils/createModifier.js +36 -41
- package/lib/utils/deprecate.js +8 -12
- package/lib/utils/identifierMapping.js +153 -192
- package/lib/utils/internalPropUtils.js +4 -8
- package/lib/utils/knexUtils.js +61 -56
- package/lib/utils/mixin.js +16 -23
- package/lib/utils/mysqlJsonPath.js +55 -40
- package/lib/utils/normalizeIds.js +110 -127
- package/lib/utils/objectUtils.js +236 -338
- package/lib/utils/parseFieldExpression.js +66 -44
- package/lib/utils/postgresJsonPath.js +48 -62
- package/lib/utils/promiseUtils/after.js +10 -13
- package/lib/utils/promiseUtils/afterReturn.js +10 -13
- package/lib/utils/promiseUtils/index.js +15 -17
- package/lib/utils/promiseUtils/isPromise.js +6 -9
- package/lib/utils/promiseUtils/map.js +75 -89
- package/lib/utils/promiseUtils/mapAfterAllReturn.js +17 -23
- package/lib/utils/promiseUtils/try.js +15 -18
- package/lib/utils/resolveModel.js +91 -94
- package/lib/utils/tmpColumnUtils.js +4 -13
- package/package.json +50 -23
- package/typings/objection/index.d.mts +362 -0
- package/typings/objection/index.d.ts +36 -9
- package/lib/.eslintrc.json +0 -8
- package/lib/queryBuilder/parsers/jsonFieldExpressionParser.pegjs +0 -97
- package/lib/queryBuilder/parsers/relationExpressionParser.pegjs +0 -141
- package/lib/utils/clone.js +0 -2329
|
@@ -1,50 +1,39 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
class BelongsToOneRelateOperation extends RelateOperation {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
return this.relation.ownerModelClass
|
|
35
|
-
.query()
|
|
36
|
-
.childQueryOf(builder)
|
|
37
|
-
.patch(patch)
|
|
38
|
-
.whereInComposite(ownerIdProp.refs(builder), ownerIds);
|
|
39
|
-
}
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BelongsToOneRelateOperation = void 0;
|
|
4
|
+
const normalizeIds_1 = require("../../utils/normalizeIds");
|
|
5
|
+
const RelateOperation_1 = require("../../queryBuilder/operations/RelateOperation");
|
|
6
|
+
class BelongsToOneRelateOperation extends RelateOperation_1.RelateOperation {
|
|
7
|
+
onAdd(_, args) {
|
|
8
|
+
this.input = args[0];
|
|
9
|
+
this.ids = (0, normalizeIds_1.normalizeIds)(args[0], this.relation.relatedProp, { arrayOutput: true });
|
|
10
|
+
assertOneId(this.ids);
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
queryExecutor(builder) {
|
|
14
|
+
const patch = {};
|
|
15
|
+
const ownerProp = this.relation.ownerProp;
|
|
16
|
+
ownerProp.forEach((i) => {
|
|
17
|
+
const relatedValue = this.ids[0][i];
|
|
18
|
+
if (this.owner.isModels) {
|
|
19
|
+
for (const owner of this.owner.modelArray) {
|
|
20
|
+
ownerProp.setProp(owner, i, relatedValue);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
ownerProp.patch(patch, i, relatedValue);
|
|
24
|
+
});
|
|
25
|
+
const ownerIdProp = this.relation.ownerModelClass.getIdRelationProperty();
|
|
26
|
+
const ownerIds = this.owner.getProps(this.relation, ownerIdProp);
|
|
27
|
+
return this.relation.ownerModelClass
|
|
28
|
+
.query()
|
|
29
|
+
.childQueryOf(builder)
|
|
30
|
+
.patch(patch)
|
|
31
|
+
.whereInComposite(ownerIdProp.refs(builder), ownerIds);
|
|
32
|
+
}
|
|
40
33
|
}
|
|
41
|
-
|
|
34
|
+
exports.BelongsToOneRelateOperation = BelongsToOneRelateOperation;
|
|
42
35
|
function assertOneId(ids) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
36
|
+
if (ids.length > 1) {
|
|
37
|
+
throw new Error('can only relate one model to a BelongsToOneRelation');
|
|
38
|
+
}
|
|
46
39
|
}
|
|
47
|
-
|
|
48
|
-
module.exports = {
|
|
49
|
-
BelongsToOneRelateOperation,
|
|
50
|
-
};
|
|
@@ -1,53 +1,45 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
class BelongsToOneRelation extends Relation {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
relation: this,
|
|
38
|
-
owner,
|
|
39
|
-
});
|
|
40
|
-
}
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BelongsToOneRelation = void 0;
|
|
4
|
+
const Relation_1 = require("../Relation");
|
|
5
|
+
const BelongsToOneInsertOperation_1 = require("./BelongsToOneInsertOperation");
|
|
6
|
+
const BelongsToOneDeleteOperation_1 = require("./BelongsToOneDeleteOperation");
|
|
7
|
+
const BelongsToOneRelateOperation_1 = require("./BelongsToOneRelateOperation");
|
|
8
|
+
const BelongsToOneUnrelateOperation_1 = require("./BelongsToOneUnrelateOperation");
|
|
9
|
+
class BelongsToOneRelation extends Relation_1.Relation {
|
|
10
|
+
isOneToOne() {
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
insert(_, owner) {
|
|
14
|
+
return new BelongsToOneInsertOperation_1.BelongsToOneInsertOperation('insert', {
|
|
15
|
+
relation: this,
|
|
16
|
+
owner,
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
delete(_, owner) {
|
|
20
|
+
return new BelongsToOneDeleteOperation_1.BelongsToOneDeleteOperation('delete', {
|
|
21
|
+
relation: this,
|
|
22
|
+
owner,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
relate(_, owner) {
|
|
26
|
+
return new BelongsToOneRelateOperation_1.BelongsToOneRelateOperation('relate', {
|
|
27
|
+
relation: this,
|
|
28
|
+
owner,
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
unrelate(_, owner) {
|
|
32
|
+
return new BelongsToOneUnrelateOperation_1.BelongsToOneUnrelateOperation('unrelate', {
|
|
33
|
+
relation: this,
|
|
34
|
+
owner,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
41
37
|
}
|
|
42
|
-
|
|
38
|
+
exports.BelongsToOneRelation = BelongsToOneRelation;
|
|
43
39
|
Object.defineProperties(BelongsToOneRelation.prototype, {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
40
|
+
isObjectionBelongsToOneRelation: {
|
|
41
|
+
enumerable: false,
|
|
42
|
+
writable: false,
|
|
43
|
+
value: true,
|
|
44
|
+
},
|
|
49
45
|
});
|
|
50
|
-
|
|
51
|
-
module.exports = {
|
|
52
|
-
BelongsToOneRelation,
|
|
53
|
-
};
|
|
@@ -1,61 +1,46 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
class BelongsToOneUnrelateOperation extends UnrelateOperation {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BelongsToOneUnrelateOperation = void 0;
|
|
4
|
+
const UnrelateOperation_1 = require("../../queryBuilder/operations/UnrelateOperation");
|
|
5
|
+
class BelongsToOneUnrelateOperation extends UnrelateOperation_1.UnrelateOperation {
|
|
6
|
+
onAdd() {
|
|
7
|
+
const ids = new Array(this.relation.ownerProp.size);
|
|
8
|
+
this.relation.ownerProp.forEach((i) => {
|
|
9
|
+
ids[i] = null;
|
|
10
|
+
});
|
|
11
|
+
this.ids = [ids];
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
queryExecutor(builder) {
|
|
15
|
+
const patch = {};
|
|
16
|
+
const ownerProp = this.relation.ownerProp;
|
|
17
|
+
ownerProp.forEach((i) => {
|
|
18
|
+
const relatedValue = this.ids[0][i];
|
|
19
|
+
if (this.owner.isModels) {
|
|
20
|
+
for (const owner of this.owner.modelArray) {
|
|
21
|
+
ownerProp.setProp(owner, i, relatedValue);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
ownerProp.patch(patch, i, relatedValue);
|
|
25
|
+
});
|
|
26
|
+
const ownerIdProp = this.relation.ownerModelClass.getIdRelationProperty();
|
|
27
|
+
const ownerRefs = ownerIdProp.refs(builder);
|
|
28
|
+
const ownerIds = this.owner.getProps(this.relation, ownerIdProp);
|
|
29
|
+
const query = this.relation.ownerModelClass
|
|
30
|
+
.query()
|
|
31
|
+
.childQueryOf(builder)
|
|
32
|
+
.patch(patch)
|
|
33
|
+
.whereInComposite(ownerRefs, ownerIds);
|
|
34
|
+
// We are creating a query to the related items. So any `where` statements
|
|
35
|
+
// must filter the *related* items, not the root query above, which is actually
|
|
36
|
+
// for the owners.
|
|
37
|
+
if (builder.has(builder.constructor.WhereSelector)) {
|
|
38
|
+
query.whereExists(this.relation.ownerModelClass
|
|
39
|
+
.relatedQuery(this.relation.name)
|
|
40
|
+
.copyFrom(builder, builder.constructor.JoinSelector)
|
|
41
|
+
.copyFrom(builder, builder.constructor.WhereSelector));
|
|
27
42
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
ownerProp.patch(patch, i, relatedValue);
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
const ownerIdProp = this.relation.ownerModelClass.getIdRelationProperty();
|
|
34
|
-
const ownerRefs = ownerIdProp.refs(builder);
|
|
35
|
-
const ownerIds = this.owner.getProps(this.relation, ownerIdProp);
|
|
36
|
-
|
|
37
|
-
const query = this.relation.ownerModelClass
|
|
38
|
-
.query()
|
|
39
|
-
.childQueryOf(builder)
|
|
40
|
-
.patch(patch)
|
|
41
|
-
.whereInComposite(ownerRefs, ownerIds);
|
|
42
|
-
|
|
43
|
-
// We are creating a query to the related items. So any `where` statements
|
|
44
|
-
// must filter the *related* items, not the root query above, which is actually
|
|
45
|
-
// for the owners.
|
|
46
|
-
if (builder.has(builder.constructor.WhereSelector)) {
|
|
47
|
-
query.whereExists(
|
|
48
|
-
this.relation.ownerModelClass
|
|
49
|
-
.relatedQuery(this.relation.name)
|
|
50
|
-
.copyFrom(builder, builder.constructor.JoinSelector)
|
|
51
|
-
.copyFrom(builder, builder.constructor.WhereSelector),
|
|
52
|
-
);
|
|
43
|
+
return query;
|
|
53
44
|
}
|
|
54
|
-
|
|
55
|
-
return query;
|
|
56
|
-
}
|
|
57
45
|
}
|
|
58
|
-
|
|
59
|
-
module.exports = {
|
|
60
|
-
BelongsToOneUnrelateOperation,
|
|
61
|
-
};
|
|
46
|
+
exports.BelongsToOneUnrelateOperation = BelongsToOneUnrelateOperation;
|
|
@@ -1,61 +1,45 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
class HasManyInsertOperation extends RelationInsertOperation {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HasManyInsertOperation = void 0;
|
|
4
|
+
const RelationInsertOperation_1 = require("../RelationInsertOperation");
|
|
5
|
+
class HasManyInsertOperation extends RelationInsertOperation_1.RelationInsertOperation {
|
|
6
|
+
onAdd(builder, args) {
|
|
7
|
+
const retVal = super.onAdd(builder, args);
|
|
8
|
+
assertOwnerIsSingleItem(this.owner, this.relation);
|
|
9
|
+
const ownerValues = this.owner.getSplitProps(builder, this.relation);
|
|
10
|
+
const relatedProp = this.relation.relatedProp;
|
|
11
|
+
for (const model of this.models) {
|
|
12
|
+
for (let j = 0, lp = relatedProp.size; j < lp; ++j) {
|
|
13
|
+
relatedProp.setProp(model, j, ownerValues[0][j]);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return retVal;
|
|
17
17
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
18
|
+
async onAfter1(builder, ret) {
|
|
19
|
+
const inserted = await super.onAfter1(builder, ret);
|
|
20
|
+
if (!this.assignResultToOwner) {
|
|
21
|
+
return inserted;
|
|
22
|
+
}
|
|
23
|
+
if (this.owner.isModels) {
|
|
24
|
+
for (const owner of this.owner.modelArray) {
|
|
25
|
+
owner.$appendRelated(this.relation, inserted);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return inserted;
|
|
27
29
|
}
|
|
28
|
-
|
|
29
|
-
if (this.owner.isModels) {
|
|
30
|
-
for (const owner of this.owner.modelArray) {
|
|
31
|
-
owner.$appendRelated(this.relation, inserted);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return inserted;
|
|
36
|
-
}
|
|
37
30
|
}
|
|
38
|
-
|
|
31
|
+
exports.HasManyInsertOperation = HasManyInsertOperation;
|
|
39
32
|
function assertOwnerIsSingleItem(owner, relation) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
'
|
|
51
|
-
|
|
52
|
-
'If you need to insert items for multiple parents, simply loop through them.',
|
|
53
|
-
`That's the most performant way.`,
|
|
54
|
-
].join(' '),
|
|
55
|
-
);
|
|
56
|
-
}
|
|
33
|
+
const { isModels, isIdentifiers, isQueryBuilder } = owner;
|
|
34
|
+
const { ownerProp } = relation;
|
|
35
|
+
const singleModel = isModels && owner.modelArray.length === 1;
|
|
36
|
+
const singleId = isIdentifiers && owner.getNormalizedIdentifiers(ownerProp).length === 1;
|
|
37
|
+
if (!singleModel && !singleId && !isQueryBuilder) {
|
|
38
|
+
throw new Error([
|
|
39
|
+
'Can only insert items for one parent at a time in case of HasManyRelation.',
|
|
40
|
+
'Otherwise multiple insert queries would need to be created.',
|
|
41
|
+
'If you need to insert items for multiple parents, simply loop through them.',
|
|
42
|
+
`That's the most performant way.`,
|
|
43
|
+
].join(' '));
|
|
44
|
+
}
|
|
57
45
|
}
|
|
58
|
-
|
|
59
|
-
module.exports = {
|
|
60
|
-
HasManyInsertOperation,
|
|
61
|
-
};
|
|
@@ -1,64 +1,48 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
class HasManyRelateOperation extends RelateOperation {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
.copyFrom(builder, builder.constructor.WhereSelector);
|
|
34
|
-
|
|
35
|
-
withWhereScope(query, () => query.findByIds(this.ids));
|
|
36
|
-
withWhereScope(query, () => query.modify(this.relation.modify));
|
|
37
|
-
|
|
38
|
-
return query;
|
|
39
|
-
}
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HasManyRelateOperation = void 0;
|
|
4
|
+
const whereScopes_1 = require("../../queryBuilder/whereScopes");
|
|
5
|
+
const normalizeIds_1 = require("../../utils/normalizeIds");
|
|
6
|
+
const RelateOperation_1 = require("../../queryBuilder/operations/RelateOperation");
|
|
7
|
+
class HasManyRelateOperation extends RelateOperation_1.RelateOperation {
|
|
8
|
+
onAdd(_, args) {
|
|
9
|
+
this.input = args[0];
|
|
10
|
+
this.ids = (0, normalizeIds_1.normalizeIds)(args[0], this.relation.relatedModelClass.getIdRelationProperty(), {
|
|
11
|
+
arrayOutput: true,
|
|
12
|
+
});
|
|
13
|
+
assertOwnerIsSingleItem(this.owner, this.relation);
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
queryExecutor(builder) {
|
|
17
|
+
const patch = {};
|
|
18
|
+
const relatedProp = this.relation.relatedProp;
|
|
19
|
+
const ownerValues = this.owner.getSplitProps(builder, this.relation);
|
|
20
|
+
relatedProp.forEach((i) => {
|
|
21
|
+
relatedProp.patch(patch, i, ownerValues[0][i]);
|
|
22
|
+
});
|
|
23
|
+
const query = this.relation.relatedModelClass
|
|
24
|
+
.query()
|
|
25
|
+
.childQueryOf(builder)
|
|
26
|
+
.patch(patch)
|
|
27
|
+
.copyFrom(builder, builder.constructor.JoinSelector)
|
|
28
|
+
.copyFrom(builder, builder.constructor.WhereSelector);
|
|
29
|
+
(0, whereScopes_1.withWhereScope)(query, () => query.findByIds(this.ids));
|
|
30
|
+
(0, whereScopes_1.withWhereScope)(query, () => query.modify(this.relation.modify));
|
|
31
|
+
return query;
|
|
32
|
+
}
|
|
40
33
|
}
|
|
41
|
-
|
|
34
|
+
exports.HasManyRelateOperation = HasManyRelateOperation;
|
|
42
35
|
function assertOwnerIsSingleItem(owner, relation) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
'
|
|
54
|
-
|
|
55
|
-
'If you need to relate items for multiple parents, simply loop through them.',
|
|
56
|
-
`That's the most performant way.`,
|
|
57
|
-
].join(' '),
|
|
58
|
-
);
|
|
59
|
-
}
|
|
36
|
+
const { isModels, isIdentifiers, isQueryBuilder } = owner;
|
|
37
|
+
const { ownerProp } = relation;
|
|
38
|
+
const singleModel = isModels && owner.modelArray.length === 1;
|
|
39
|
+
const singleId = isIdentifiers && owner.getNormalizedIdentifiers(ownerProp).length === 1;
|
|
40
|
+
if (!singleModel && !singleId && !isQueryBuilder) {
|
|
41
|
+
throw new Error([
|
|
42
|
+
'Can only relate items for one parent at a time in case of HasManyRelation.',
|
|
43
|
+
'Otherwise multiple update queries would need to be created.',
|
|
44
|
+
'If you need to relate items for multiple parents, simply loop through them.',
|
|
45
|
+
`That's the most performant way.`,
|
|
46
|
+
].join(' '));
|
|
47
|
+
}
|
|
60
48
|
}
|
|
61
|
-
|
|
62
|
-
module.exports = {
|
|
63
|
-
HasManyRelateOperation,
|
|
64
|
-
};
|
|
@@ -1,49 +1,41 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
class HasManyRelation extends Relation {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
setRelateProp(model, values) {
|
|
35
|
-
model.$id(values);
|
|
36
|
-
}
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HasManyRelation = void 0;
|
|
4
|
+
const Relation_1 = require("../Relation");
|
|
5
|
+
const HasManyInsertOperation_1 = require("./HasManyInsertOperation");
|
|
6
|
+
const HasManyRelateOperation_1 = require("./HasManyRelateOperation");
|
|
7
|
+
const HasManyUnrelateOperation_1 = require("./HasManyUnrelateOperation");
|
|
8
|
+
class HasManyRelation extends Relation_1.Relation {
|
|
9
|
+
insert(_, owner) {
|
|
10
|
+
return new HasManyInsertOperation_1.HasManyInsertOperation('insert', {
|
|
11
|
+
relation: this,
|
|
12
|
+
owner: owner,
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
relate(_, owner) {
|
|
16
|
+
return new HasManyRelateOperation_1.HasManyRelateOperation('relate', {
|
|
17
|
+
relation: this,
|
|
18
|
+
owner: owner,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
unrelate(_, owner) {
|
|
22
|
+
return new HasManyUnrelateOperation_1.HasManyUnrelateOperation('unrelate', {
|
|
23
|
+
relation: this,
|
|
24
|
+
owner: owner,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
hasRelateProp(model) {
|
|
28
|
+
return model.$hasId();
|
|
29
|
+
}
|
|
30
|
+
setRelateProp(model, values) {
|
|
31
|
+
model.$id(values);
|
|
32
|
+
}
|
|
37
33
|
}
|
|
38
|
-
|
|
34
|
+
exports.HasManyRelation = HasManyRelation;
|
|
39
35
|
Object.defineProperties(HasManyRelation.prototype, {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
36
|
+
isObjectionHasManyRelation: {
|
|
37
|
+
enumerable: false,
|
|
38
|
+
writable: false,
|
|
39
|
+
value: true,
|
|
40
|
+
},
|
|
45
41
|
});
|
|
46
|
-
|
|
47
|
-
module.exports = {
|
|
48
|
-
HasManyRelation,
|
|
49
|
-
};
|
|
@@ -1,33 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
class HasManyUnrelateOperation extends UnrelateOperation {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
withWhereScope(query, () => query.modify(this.relation.modify));
|
|
26
|
-
|
|
27
|
-
return query;
|
|
28
|
-
}
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HasManyUnrelateOperation = void 0;
|
|
4
|
+
const whereScopes_1 = require("../../queryBuilder/whereScopes");
|
|
5
|
+
const UnrelateOperation_1 = require("../../queryBuilder/operations/UnrelateOperation");
|
|
6
|
+
class HasManyUnrelateOperation extends UnrelateOperation_1.UnrelateOperation {
|
|
7
|
+
queryExecutor(builder) {
|
|
8
|
+
const patch = {};
|
|
9
|
+
const relatedProp = this.relation.relatedProp;
|
|
10
|
+
const ownerValues = this.owner.getProps(this.relation);
|
|
11
|
+
const relatedRefs = relatedProp.refs(builder);
|
|
12
|
+
relatedProp.forEach((i) => {
|
|
13
|
+
relatedProp.patch(patch, i, null);
|
|
14
|
+
});
|
|
15
|
+
const query = this.relation.relatedModelClass
|
|
16
|
+
.query()
|
|
17
|
+
.childQueryOf(builder)
|
|
18
|
+
.patch(patch)
|
|
19
|
+
.copyFrom(builder, builder.constructor.JoinSelector)
|
|
20
|
+
.copyFrom(builder, builder.constructor.WhereSelector);
|
|
21
|
+
(0, whereScopes_1.withWhereScope)(query, () => query.whereInComposite(relatedRefs, ownerValues));
|
|
22
|
+
(0, whereScopes_1.withWhereScope)(query, () => query.modify(this.relation.modify));
|
|
23
|
+
return query;
|
|
24
|
+
}
|
|
29
25
|
}
|
|
30
|
-
|
|
31
|
-
module.exports = {
|
|
32
|
-
HasManyUnrelateOperation,
|
|
33
|
-
};
|
|
26
|
+
exports.HasManyUnrelateOperation = HasManyUnrelateOperation;
|