@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,34 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
class ManyToManyUnrelateOperationBase extends UnrelateOperation {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
/* istanbul ignore next */
|
|
27
|
-
applyModifyFilterForJoinTable(builder) {
|
|
28
|
-
throw new Error('not implemented');
|
|
29
|
-
}
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ManyToManyUnrelateOperationBase = void 0;
|
|
4
|
+
const whereScopes_1 = require("../../../queryBuilder/whereScopes");
|
|
5
|
+
const UnrelateOperation_1 = require("../../../queryBuilder/operations/UnrelateOperation");
|
|
6
|
+
class ManyToManyUnrelateOperationBase extends UnrelateOperation_1.UnrelateOperation {
|
|
7
|
+
queryExecutor(builder) {
|
|
8
|
+
const unrelateQuery = this.relation
|
|
9
|
+
.getJoinModelClass(builder.knex())
|
|
10
|
+
.query()
|
|
11
|
+
.childQueryOf(builder)
|
|
12
|
+
.delete();
|
|
13
|
+
(0, whereScopes_1.withWhereScope)(unrelateQuery, () => {
|
|
14
|
+
this.applyModifyFilterForJoinTable(unrelateQuery);
|
|
15
|
+
});
|
|
16
|
+
return unrelateQuery.modify(this.relation.joinTableModify);
|
|
17
|
+
}
|
|
18
|
+
/* istanbul ignore next */
|
|
19
|
+
applyModifyFilterForRelatedTable(builder) {
|
|
20
|
+
throw new Error('not implemented');
|
|
21
|
+
}
|
|
22
|
+
/* istanbul ignore next */
|
|
23
|
+
applyModifyFilterForJoinTable(builder) {
|
|
24
|
+
throw new Error('not implemented');
|
|
25
|
+
}
|
|
30
26
|
}
|
|
31
|
-
|
|
32
|
-
module.exports = {
|
|
33
|
-
ManyToManyUnrelateOperationBase,
|
|
34
|
-
};
|
|
27
|
+
exports.ManyToManyUnrelateOperationBase = ManyToManyUnrelateOperationBase;
|
|
@@ -1,16 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
class ManyToManyUnrelateSqliteOperation extends ManyToManySqliteModifyMixin(
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
return false;
|
|
11
|
-
}
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ManyToManyUnrelateSqliteOperation = void 0;
|
|
4
|
+
const ManyToManyUnrelateOperationBase_1 = require("./ManyToManyUnrelateOperationBase");
|
|
5
|
+
const ManyToManySqliteModifyMixin_1 = require("../ManyToManySqliteModifyMixin");
|
|
6
|
+
class ManyToManyUnrelateSqliteOperation extends (0, ManyToManySqliteModifyMixin_1.ManyToManySqliteModifyMixin)(ManyToManyUnrelateOperationBase_1.ManyToManyUnrelateOperationBase) {
|
|
7
|
+
get modifyMainQuery() {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
12
10
|
}
|
|
13
|
-
|
|
14
|
-
module.exports = {
|
|
15
|
-
ManyToManyUnrelateSqliteOperation,
|
|
16
|
-
};
|
|
11
|
+
exports.ManyToManyUnrelateSqliteOperation = ManyToManyUnrelateSqliteOperation;
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
class ManyToManyUpdateOperation extends ManyToManyModifyMixin(ManyToManyUpdateOperationBase) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
ManyToManyUpdateOperation,
|
|
10
|
-
};
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ManyToManyUpdateOperation = void 0;
|
|
4
|
+
const ManyToManyUpdateOperationBase_1 = require("./ManyToManyUpdateOperationBase");
|
|
5
|
+
const ManyToManyModifyMixin_1 = require("../ManyToManyModifyMixin");
|
|
6
|
+
class ManyToManyUpdateOperation extends (0, ManyToManyModifyMixin_1.ManyToManyModifyMixin)(ManyToManyUpdateOperationBase_1.ManyToManyUpdateOperationBase) {
|
|
7
|
+
}
|
|
8
|
+
exports.ManyToManyUpdateOperation = ManyToManyUpdateOperation;
|
|
@@ -1,82 +1,65 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
class ManyToManyUpdateOperationBase extends UpdateOperation {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
this.joinTablePatch = {};
|
|
15
|
-
this.joinTablePatchFilterQuery = null;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
onAdd(builder, args) {
|
|
19
|
-
const obj = args[0];
|
|
20
|
-
|
|
21
|
-
// Copy all extra properties to the `joinTablePatch` object.
|
|
22
|
-
for (const extra of this.relation.joinTableExtras) {
|
|
23
|
-
if (extra.aliasProp in obj) {
|
|
24
|
-
this.hasExtraProps = true;
|
|
25
|
-
this.joinTablePatch[extra.joinTableProp] = obj[extra.aliasProp];
|
|
26
|
-
}
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ManyToManyUpdateOperationBase = void 0;
|
|
4
|
+
const whereScopes_1 = require("../../../queryBuilder/whereScopes");
|
|
5
|
+
const UpdateOperation_1 = require("../../../queryBuilder/operations/UpdateOperation");
|
|
6
|
+
class ManyToManyUpdateOperationBase extends UpdateOperation_1.UpdateOperation {
|
|
7
|
+
constructor(name, opt) {
|
|
8
|
+
super(name, opt);
|
|
9
|
+
this.relation = opt.relation;
|
|
10
|
+
this.owner = opt.owner;
|
|
11
|
+
this.hasExtraProps = false;
|
|
12
|
+
this.joinTablePatch = {};
|
|
13
|
+
this.joinTablePatchFilterQuery = null;
|
|
27
14
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
15
|
+
onAdd(builder, args) {
|
|
16
|
+
const obj = args[0];
|
|
17
|
+
// Copy all extra properties to the `joinTablePatch` object.
|
|
18
|
+
for (const extra of this.relation.joinTableExtras) {
|
|
19
|
+
if (extra.aliasProp in obj) {
|
|
20
|
+
this.hasExtraProps = true;
|
|
21
|
+
this.joinTablePatch[extra.joinTableProp] = obj[extra.aliasProp];
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
const res = super.onAdd(builder, args);
|
|
25
|
+
if (this.hasExtraProps) {
|
|
26
|
+
// Make sure we don't try to insert the extra properties
|
|
27
|
+
// to the target table.
|
|
28
|
+
this.relation.omitExtraProps([this.model]);
|
|
29
|
+
}
|
|
30
|
+
return res;
|
|
35
31
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
32
|
+
async onAfter1(builder, result) {
|
|
33
|
+
if (this.hasExtraProps) {
|
|
34
|
+
const joinTableUpdateQuery = this.relation
|
|
35
|
+
.getJoinModelClass(builder.knex())
|
|
36
|
+
.query()
|
|
37
|
+
.childQueryOf(builder)
|
|
38
|
+
.patch(this.joinTablePatch);
|
|
39
|
+
(0, whereScopes_1.withWhereScope)(joinTableUpdateQuery, () => {
|
|
40
|
+
this.applyModifyFilterForJoinTable(joinTableUpdateQuery);
|
|
41
|
+
});
|
|
42
|
+
await joinTableUpdateQuery.modify(this.relation.joinTableModify);
|
|
43
|
+
return result;
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
return result;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/* istanbul ignore next */
|
|
50
|
+
applyModifyFilterForRelatedTable(builder) {
|
|
51
|
+
throw new Error('not implemented');
|
|
52
|
+
}
|
|
53
|
+
/* istanbul ignore next */
|
|
54
|
+
applyModifyFilterForJoinTable(builder) {
|
|
55
|
+
throw new Error('not implemented');
|
|
56
|
+
}
|
|
57
|
+
clone() {
|
|
58
|
+
const clone = super.clone();
|
|
59
|
+
clone.hasExtraProps = this.hasExtraProps;
|
|
60
|
+
clone.joinTablePatch = this.joinTablePatch;
|
|
61
|
+
clone.joinTablePatchFilterQuery = this.joinTablePatchFilterQuery;
|
|
62
|
+
return clone;
|
|
56
63
|
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/* istanbul ignore next */
|
|
60
|
-
applyModifyFilterForRelatedTable(builder) {
|
|
61
|
-
throw new Error('not implemented');
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/* istanbul ignore next */
|
|
65
|
-
applyModifyFilterForJoinTable(builder) {
|
|
66
|
-
throw new Error('not implemented');
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
clone() {
|
|
70
|
-
const clone = super.clone();
|
|
71
|
-
|
|
72
|
-
clone.hasExtraProps = this.hasExtraProps;
|
|
73
|
-
clone.joinTablePatch = this.joinTablePatch;
|
|
74
|
-
clone.joinTablePatchFilterQuery = this.joinTablePatchFilterQuery;
|
|
75
|
-
|
|
76
|
-
return clone;
|
|
77
|
-
}
|
|
78
64
|
}
|
|
79
|
-
|
|
80
|
-
module.exports = {
|
|
81
|
-
ManyToManyUpdateOperationBase,
|
|
82
|
-
};
|
|
65
|
+
exports.ManyToManyUpdateOperationBase = ManyToManyUpdateOperationBase;
|
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
class ManyToManyUpdateSqliteOperation extends ManyToManySqliteModifyMixin(
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
module.exports = {
|
|
11
|
-
ManyToManyUpdateSqliteOperation,
|
|
12
|
-
};
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ManyToManyUpdateSqliteOperation = void 0;
|
|
4
|
+
const ManyToManyUpdateOperationBase_1 = require("./ManyToManyUpdateOperationBase");
|
|
5
|
+
const ManyToManySqliteModifyMixin_1 = require("../ManyToManySqliteModifyMixin");
|
|
6
|
+
class ManyToManyUpdateSqliteOperation extends (0, ManyToManySqliteModifyMixin_1.ManyToManySqliteModifyMixin)(ManyToManyUpdateOperationBase_1.ManyToManyUpdateOperationBase) {
|
|
7
|
+
}
|
|
8
|
+
exports.ManyToManyUpdateSqliteOperation = ManyToManyUpdateSqliteOperation;
|
package/lib/transaction.js
CHANGED
|
@@ -1,96 +1,66 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
|
|
3
2
|
const promiseUtils = require('./utils/promiseUtils');
|
|
4
3
|
const { isFunction } = require('./utils/objectUtils');
|
|
5
|
-
|
|
6
4
|
function transaction() {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
new Error(
|
|
11
|
-
'objection.transaction: provide at least one Model class to bind to the transaction or a knex instance',
|
|
12
|
-
),
|
|
13
|
-
);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
let args = Array.from(arguments);
|
|
17
|
-
|
|
18
|
-
if (!isModelClass(args[0]) && isFunction(args[0].transaction)) {
|
|
19
|
-
let knex = args[0];
|
|
20
|
-
args = args.slice(1);
|
|
21
|
-
|
|
22
|
-
return knex.transaction.apply(knex, args);
|
|
23
|
-
} else {
|
|
24
|
-
// The last argument should be the callback and all other Model subclasses.
|
|
25
|
-
let callback = args[args.length - 1];
|
|
26
|
-
let modelClasses = args.slice(0, args.length - 1);
|
|
27
|
-
let i;
|
|
28
|
-
|
|
29
|
-
for (i = 0; i < modelClasses.length; ++i) {
|
|
30
|
-
if (!isModelClass(modelClasses[i])) {
|
|
31
|
-
return Promise.reject(
|
|
32
|
-
new Error('objection.transaction: all but the last argument should be Model subclasses'),
|
|
33
|
-
);
|
|
34
|
-
}
|
|
5
|
+
// There must be at least one model class and the callback.
|
|
6
|
+
if (arguments.length < 2) {
|
|
7
|
+
return Promise.reject(new Error('objection.transaction: provide at least one Model class to bind to the transaction or a knex instance'));
|
|
35
8
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
return
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
9
|
+
let args = Array.from(arguments);
|
|
10
|
+
if (!isModelClass(args[0]) && isFunction(args[0].transaction)) {
|
|
11
|
+
const knex = args[0];
|
|
12
|
+
args = args.slice(1);
|
|
13
|
+
return knex.transaction.apply(knex, args);
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
// The last argument should be the callback and all other Model subclasses.
|
|
17
|
+
const callback = args[args.length - 1];
|
|
18
|
+
const modelClasses = args.slice(0, args.length - 1);
|
|
19
|
+
let i;
|
|
20
|
+
for (i = 0; i < modelClasses.length; ++i) {
|
|
21
|
+
if (!isModelClass(modelClasses[i])) {
|
|
22
|
+
return Promise.reject(new Error('objection.transaction: all but the last argument should be Model subclasses'));
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
const knex = modelClasses[0].knex();
|
|
26
|
+
for (i = 0; i < modelClasses.length; ++i) {
|
|
27
|
+
if (modelClasses[i].knex() !== knex) {
|
|
28
|
+
return Promise.reject(new Error('objection.transaction: all Model subclasses must be bound to the same database'));
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return knex.transaction((trx) => {
|
|
32
|
+
const args = new Array(modelClasses.length + 1);
|
|
33
|
+
for (let i = 0; i < modelClasses.length; ++i) {
|
|
34
|
+
args[i] = modelClasses[i].bindTransaction(trx);
|
|
35
|
+
}
|
|
36
|
+
args[args.length - 1] = trx;
|
|
37
|
+
return promiseUtils.try(() => {
|
|
38
|
+
return callback.apply(trx, args);
|
|
39
|
+
});
|
|
40
|
+
});
|
|
46
41
|
}
|
|
47
|
-
|
|
48
|
-
return knex.transaction((trx) => {
|
|
49
|
-
let args = new Array(modelClasses.length + 1);
|
|
50
|
-
|
|
51
|
-
for (let i = 0; i < modelClasses.length; ++i) {
|
|
52
|
-
args[i] = modelClasses[i].bindTransaction(trx);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
args[args.length - 1] = trx;
|
|
56
|
-
|
|
57
|
-
return promiseUtils.try(() => {
|
|
58
|
-
return callback.apply(trx, args);
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
42
|
}
|
|
63
|
-
|
|
64
43
|
transaction.start = function (modelClassOrKnex) {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
return Promise
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
.transaction((trx) => {
|
|
82
|
-
resolve(trx);
|
|
83
|
-
})
|
|
84
|
-
.catch((err) => {
|
|
85
|
-
reject(err);
|
|
86
|
-
});
|
|
87
|
-
});
|
|
44
|
+
let knex = modelClassOrKnex;
|
|
45
|
+
if (isModelClass(modelClassOrKnex)) {
|
|
46
|
+
knex = modelClassOrKnex.knex();
|
|
47
|
+
}
|
|
48
|
+
if (!knex || !isFunction(knex.transaction)) {
|
|
49
|
+
return Promise.reject(new Error('objection.transaction.start: first argument must be a model class or a knex instance'));
|
|
50
|
+
}
|
|
51
|
+
return new Promise((resolve, reject) => {
|
|
52
|
+
knex
|
|
53
|
+
.transaction((trx) => {
|
|
54
|
+
resolve(trx);
|
|
55
|
+
})
|
|
56
|
+
.catch((err) => {
|
|
57
|
+
reject(err);
|
|
58
|
+
});
|
|
59
|
+
});
|
|
88
60
|
};
|
|
89
|
-
|
|
90
61
|
function isModelClass(maybeModel) {
|
|
91
|
-
|
|
62
|
+
return isFunction(maybeModel) && maybeModel.isObjectionModelClass;
|
|
92
63
|
}
|
|
93
|
-
|
|
94
64
|
module.exports = {
|
|
95
|
-
|
|
65
|
+
transaction,
|
|
96
66
|
};
|
package/lib/utils/assert.js
CHANGED
|
@@ -1,25 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.assertHasId = assertHasId;
|
|
4
|
+
exports.assertIdNotUndefined = assertIdNotUndefined;
|
|
3
5
|
function assertHasId(model) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
`one of the identifier columns [${ids}] is null or undefined. Have you specified the correct identifier column for the model '${modelClass.name}' using the 'idColumn' property?`,
|
|
10
|
-
);
|
|
11
|
-
}
|
|
6
|
+
if (!model.$hasId()) {
|
|
7
|
+
const modelClass = model.constructor;
|
|
8
|
+
const ids = modelClass.getIdColumnArray().join(', ');
|
|
9
|
+
throw new Error(`one of the identifier columns [${ids}] is null or undefined. Have you specified the correct identifier column for the model '${modelClass.name}' using the 'idColumn' property?`);
|
|
10
|
+
}
|
|
12
11
|
}
|
|
13
|
-
|
|
14
12
|
function assertIdNotUndefined(id, message) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
13
|
+
if (Array.isArray(id)) {
|
|
14
|
+
id.forEach((id) => assertIdNotUndefined(id, message));
|
|
15
|
+
}
|
|
16
|
+
else if (id === undefined) {
|
|
17
|
+
throw Error(message);
|
|
18
|
+
}
|
|
20
19
|
}
|
|
21
|
-
|
|
22
|
-
module.exports = {
|
|
23
|
-
assertHasId,
|
|
24
|
-
assertIdNotUndefined,
|
|
25
|
-
};
|
package/lib/utils/buildUtils.js
CHANGED
|
@@ -1,21 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildArg = buildArg;
|
|
4
|
+
const objectUtils_1 = require("./objectUtils");
|
|
5
5
|
function buildArg(arg, builder) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
6
|
+
if (!(0, objectUtils_1.isObject)(arg)) {
|
|
7
|
+
return arg;
|
|
8
|
+
}
|
|
9
|
+
const buildable = arg;
|
|
10
|
+
if ((0, objectUtils_1.isFunction)(buildable.toKnexRaw)) {
|
|
11
|
+
return buildable.toKnexRaw(builder);
|
|
12
|
+
}
|
|
13
|
+
else if (buildable.isObjectionQueryBuilderBase === true) {
|
|
14
|
+
return buildable.subqueryOf(builder).toKnexQuery();
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
return arg;
|
|
18
|
+
}
|
|
17
19
|
}
|
|
18
|
-
|
|
19
|
-
module.exports = {
|
|
20
|
-
buildArg,
|
|
21
|
-
};
|
package/lib/utils/classUtils.js
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.inherit = inherit;
|
|
3
4
|
function inherit(Constructor, BaseConstructor) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
return Constructor;
|
|
5
|
+
Constructor.prototype = Object.create(BaseConstructor.prototype);
|
|
6
|
+
Constructor.prototype.constructor = BaseConstructor;
|
|
7
|
+
Object.setPrototypeOf(Constructor, BaseConstructor);
|
|
8
|
+
return Constructor;
|
|
9
9
|
}
|
|
10
|
-
|
|
11
|
-
module.exports = {
|
|
12
|
-
inherit,
|
|
13
|
-
};
|