@abedmurrar/objection 4.0.0-alpha.0 → 4.0.0-beta.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 +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 +279 -363
- package/lib/relations/RelationDeleteOperation.js +16 -22
- package/lib/relations/RelationFindOperation.js +100 -133
- package/lib/relations/RelationInsertOperation.js +19 -27
- package/lib/relations/RelationOwner.js +167 -204
- package/lib/relations/RelationProperty.js +177 -217
- package/lib/relations/RelationUpdateOperation.js +16 -23
- package/lib/relations/belongsToOne/BelongsToOneDeleteOperation.js +11 -16
- package/lib/relations/belongsToOne/BelongsToOneInsertOperation.js +24 -35
- package/lib/relations/belongsToOne/BelongsToOneRelateOperation.js +30 -41
- package/lib/relations/belongsToOne/BelongsToOneRelation.js +33 -41
- package/lib/relations/belongsToOne/BelongsToOneUnrelateOperation.js +38 -53
- package/lib/relations/hasMany/HasManyInsertOperation.js +35 -51
- package/lib/relations/hasMany/HasManyRelateOperation.js +38 -54
- package/lib/relations/hasMany/HasManyRelation.js +30 -38
- package/lib/relations/hasMany/HasManyUnrelateOperation.js +19 -26
- package/lib/relations/hasOne/HasOneRelation.js +4 -7
- package/lib/relations/hasOneThrough/HasOneThroughRelation.js +4 -7
- package/lib/relations/manyToMany/ManyToManyModifyMixin.js +67 -90
- package/lib/relations/manyToMany/ManyToManyRelation.js +349 -451
- package/lib/relations/manyToMany/ManyToManySqliteModifyMixin.js +19 -26
- package/lib/relations/manyToMany/delete/ManyToManyDeleteOperation.js +3 -5
- package/lib/relations/manyToMany/delete/ManyToManyDeleteOperationBase.js +14 -20
- package/lib/relations/manyToMany/delete/ManyToManyDeleteSqliteOperation.js +3 -7
- package/lib/relations/manyToMany/find/ManyToManyFindOperation.js +71 -94
- package/lib/relations/manyToMany/insert/ManyToManyInsertOperation.js +31 -43
- package/lib/relations/manyToMany/relate/ManyToManyRelateOperation.js +50 -67
- package/lib/relations/manyToMany/unrelate/ManyToManyUnrelateOperation.js +4 -7
- package/lib/relations/manyToMany/unrelate/ManyToManyUnrelateOperationBase.js +20 -27
- package/lib/relations/manyToMany/unrelate/ManyToManyUnrelateSqliteOperation.js +5 -10
- package/lib/relations/manyToMany/update/ManyToManyUpdateOperation.js +3 -5
- package/lib/relations/manyToMany/update/ManyToManyUpdateOperationBase.js +55 -72
- package/lib/relations/manyToMany/update/ManyToManyUpdateSqliteOperation.js +3 -7
- 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,192 +1,173 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
|
|
3
2
|
const { QueryBuilderOperation } = require('./QueryBuilderOperation');
|
|
4
3
|
const { isPlainObject, isObject, isFunction, once } = require('../../utils/objectUtils');
|
|
5
4
|
const { isKnexQueryBuilder, isKnexJoinBuilder } = require('../../utils/knexUtils');
|
|
6
5
|
const { transformation } = require('../transformations');
|
|
7
6
|
const { isModelClass } = require('../../utils/resolveModel');
|
|
8
7
|
const getJoinBuilder = once(() => require('../JoinBuilder').JoinBuilder);
|
|
9
|
-
|
|
10
8
|
// An abstract operation base class that converts all arguments from objection types
|
|
11
9
|
// to knex types. For example objection query builders are converted into knex query
|
|
12
10
|
// builders and objection RawBuilder instances are converted into knex Raw instances.
|
|
13
11
|
class ObjectionToKnexConvertingOperation extends QueryBuilderOperation {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return clone;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
12
|
+
constructor(name, opt) {
|
|
13
|
+
super(name, opt);
|
|
14
|
+
this.args = null;
|
|
15
|
+
}
|
|
16
|
+
getKnexArgs(builder) {
|
|
17
|
+
return convertArgs(this.name, builder, this.args);
|
|
18
|
+
}
|
|
19
|
+
onAdd(builder, args) {
|
|
20
|
+
this.args = Array.from(args);
|
|
21
|
+
return shouldBeAdded(this.name, builder, this.args);
|
|
22
|
+
}
|
|
23
|
+
clone() {
|
|
24
|
+
const clone = super.clone();
|
|
25
|
+
clone.args = this.args;
|
|
26
|
+
return clone;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
35
29
|
function shouldBeAdded(opName, builder, args) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
);
|
|
48
|
-
}
|
|
30
|
+
const skipUndefined = builder.internalOptions().skipUndefined;
|
|
31
|
+
for (let i = 0, l = args.length; i < l; ++i) {
|
|
32
|
+
const arg = args[i];
|
|
33
|
+
if (isUndefined(arg)) {
|
|
34
|
+
if (skipUndefined) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
throw new Error(`undefined passed as argument #${i} for '${opName}' operation. Call skipUndefined() method to ignore the undefined values.`);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
49
41
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
return true;
|
|
42
|
+
return true;
|
|
53
43
|
}
|
|
54
|
-
|
|
55
44
|
function convertArgs(opName, builder, args) {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
45
|
+
const skipUndefined = builder.internalOptions().skipUndefined;
|
|
46
|
+
return args.map((arg, i) => {
|
|
47
|
+
if (hasToKnexRawMethod(arg)) {
|
|
48
|
+
return convertToKnexRaw(arg, builder);
|
|
49
|
+
}
|
|
50
|
+
else if (isObjectionQueryBuilderBase(arg)) {
|
|
51
|
+
return convertQueryBuilderBase(arg, builder);
|
|
52
|
+
}
|
|
53
|
+
else if (isArray(arg)) {
|
|
54
|
+
return convertArray(arg, builder, i, opName, skipUndefined);
|
|
55
|
+
}
|
|
56
|
+
else if (isModelClass(arg)) {
|
|
57
|
+
// Model classes can be used in place of their table names, for example
|
|
58
|
+
// `join(Pet, ...)`. They are functions, so this check must come first.
|
|
59
|
+
return arg.getTableName();
|
|
60
|
+
}
|
|
61
|
+
else if (isFunction(arg)) {
|
|
62
|
+
return convertFunction(arg, builder);
|
|
63
|
+
}
|
|
64
|
+
else if (isModel(arg)) {
|
|
65
|
+
return convertModel(arg);
|
|
66
|
+
}
|
|
67
|
+
else if (isPlainObject(arg)) {
|
|
68
|
+
return convertPlainObject(arg, builder, i, opName, skipUndefined);
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
return arg;
|
|
72
|
+
}
|
|
73
|
+
});
|
|
79
74
|
}
|
|
80
|
-
|
|
81
75
|
function isUndefined(item) {
|
|
82
|
-
|
|
76
|
+
return item === undefined;
|
|
83
77
|
}
|
|
84
|
-
|
|
85
78
|
function hasToKnexRawMethod(item) {
|
|
86
|
-
|
|
79
|
+
return isObject(item) && isFunction(item.toKnexRaw);
|
|
87
80
|
}
|
|
88
|
-
|
|
89
81
|
function convertToKnexRaw(item, builder) {
|
|
90
|
-
|
|
82
|
+
return item.toKnexRaw(builder);
|
|
91
83
|
}
|
|
92
|
-
|
|
93
84
|
function isObjectionQueryBuilderBase(item) {
|
|
94
|
-
|
|
85
|
+
return isObject(item) && item.isObjectionQueryBuilderBase === true;
|
|
95
86
|
}
|
|
96
|
-
|
|
97
87
|
function convertQueryBuilderBase(item, builder) {
|
|
98
|
-
|
|
99
|
-
|
|
88
|
+
item = transformation.onConvertQueryBuilderBase(item, builder);
|
|
89
|
+
return item.subqueryOf(builder).toKnexQuery();
|
|
100
90
|
}
|
|
101
|
-
|
|
102
91
|
function isArray(item) {
|
|
103
|
-
|
|
92
|
+
return Array.isArray(item);
|
|
104
93
|
}
|
|
105
|
-
|
|
106
94
|
function convertArray(arr, builder, i, opName, skipUndefined) {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
95
|
+
return arr.map((item) => {
|
|
96
|
+
if (item === undefined) {
|
|
97
|
+
if (!skipUndefined) {
|
|
98
|
+
throw new Error(`undefined passed as an item in argument #${i} for '${opName}' operation. Call skipUndefined() method to ignore the undefined values.`);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
else if (hasToKnexRawMethod(item)) {
|
|
102
|
+
return convertToKnexRaw(item, builder);
|
|
103
|
+
}
|
|
104
|
+
else if (isObjectionQueryBuilderBase(item)) {
|
|
105
|
+
return convertQueryBuilderBase(item, builder);
|
|
106
|
+
}
|
|
107
|
+
else if (isModelClass(item)) {
|
|
108
|
+
return item.getTableName();
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
return item;
|
|
112
|
+
}
|
|
113
|
+
});
|
|
124
114
|
}
|
|
125
|
-
|
|
126
115
|
function convertFunction(func, builder) {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
116
|
+
return function convertedKnexArgumentFunction(...args) {
|
|
117
|
+
if (isKnexQueryBuilder(this)) {
|
|
118
|
+
convertQueryBuilderFunction(this, func, builder);
|
|
119
|
+
}
|
|
120
|
+
else if (isKnexJoinBuilder(this)) {
|
|
121
|
+
convertJoinBuilderFunction(this, func, builder);
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
return func.apply(this, args);
|
|
125
|
+
}
|
|
126
|
+
};
|
|
136
127
|
}
|
|
137
|
-
|
|
138
128
|
function convertQueryBuilderFunction(knexQueryBuilder, func, builder) {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
convertedQueryBuilder.toKnexQuery(knexQueryBuilder);
|
|
145
|
-
}
|
|
146
|
-
|
|
129
|
+
const convertedQueryBuilder = builder.constructor.forClass(builder.modelClass());
|
|
130
|
+
convertedQueryBuilder.isPartial(true).subqueryOf(builder);
|
|
131
|
+
func.call(convertedQueryBuilder, convertedQueryBuilder);
|
|
132
|
+
convertedQueryBuilder.toKnexQuery(knexQueryBuilder);
|
|
133
|
+
}
|
|
147
134
|
function convertJoinBuilderFunction(knexJoinBuilder, func, builder) {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
joinClauseBuilder.toKnexQuery(knexJoinBuilder);
|
|
155
|
-
}
|
|
156
|
-
|
|
135
|
+
const JoinBuilder = getJoinBuilder();
|
|
136
|
+
const joinClauseBuilder = JoinBuilder.forClass(builder.modelClass());
|
|
137
|
+
joinClauseBuilder.isPartial(true).subqueryOf(builder);
|
|
138
|
+
func.call(joinClauseBuilder, joinClauseBuilder);
|
|
139
|
+
joinClauseBuilder.toKnexQuery(knexJoinBuilder);
|
|
140
|
+
}
|
|
157
141
|
function isModel(item) {
|
|
158
|
-
|
|
142
|
+
return isObject(item) && item.$isObjectionModel;
|
|
159
143
|
}
|
|
160
|
-
|
|
161
144
|
function convertModel(model) {
|
|
162
|
-
|
|
145
|
+
return model.$toDatabaseJson();
|
|
163
146
|
}
|
|
164
|
-
|
|
165
147
|
function convertPlainObject(obj, builder, i, opName, skipUndefined) {
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
)
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
148
|
+
return Object.keys(obj).reduce((out, key) => {
|
|
149
|
+
const item = obj[key];
|
|
150
|
+
if (item === undefined) {
|
|
151
|
+
if (!skipUndefined) {
|
|
152
|
+
throw new Error(`undefined passed as a property in argument #${i} for '${opName}' operation. Call skipUndefined() method to ignore the undefined values.`);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
else if (hasToKnexRawMethod(item)) {
|
|
156
|
+
out[key] = convertToKnexRaw(item, builder);
|
|
157
|
+
}
|
|
158
|
+
else if (isObjectionQueryBuilderBase(item)) {
|
|
159
|
+
out[key] = convertQueryBuilderBase(item, builder);
|
|
160
|
+
}
|
|
161
|
+
else if (isModelClass(item)) {
|
|
162
|
+
// `{ alias: ModelClass }`.
|
|
163
|
+
out[key] = item.getTableName();
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
out[key] = item;
|
|
167
|
+
}
|
|
168
|
+
return out;
|
|
169
|
+
}, {});
|
|
188
170
|
}
|
|
189
|
-
|
|
190
171
|
module.exports = {
|
|
191
|
-
|
|
172
|
+
ObjectionToKnexConvertingOperation,
|
|
192
173
|
};
|
|
@@ -1,29 +1,23 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
|
|
3
2
|
const { QueryBuilderOperation } = require('./QueryBuilderOperation');
|
|
4
|
-
|
|
5
3
|
class OnBuildKnexOperation extends QueryBuilderOperation {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
clone.func = this.func;
|
|
23
|
-
return clone;
|
|
24
|
-
}
|
|
4
|
+
constructor(name, opt) {
|
|
5
|
+
super(name, opt);
|
|
6
|
+
this.func = null;
|
|
7
|
+
}
|
|
8
|
+
onAdd(_, args) {
|
|
9
|
+
this.func = args[0];
|
|
10
|
+
return true;
|
|
11
|
+
}
|
|
12
|
+
onBuildKnex(knexBuilder, builder) {
|
|
13
|
+
return this.func.call(knexBuilder, knexBuilder, builder);
|
|
14
|
+
}
|
|
15
|
+
clone() {
|
|
16
|
+
const clone = super.clone();
|
|
17
|
+
clone.func = this.func;
|
|
18
|
+
return clone;
|
|
19
|
+
}
|
|
25
20
|
}
|
|
26
|
-
|
|
27
21
|
module.exports = {
|
|
28
|
-
|
|
22
|
+
OnBuildKnexOperation,
|
|
29
23
|
};
|
|
@@ -1,29 +1,23 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
|
|
3
2
|
const { QueryBuilderOperation } = require('./QueryBuilderOperation');
|
|
4
|
-
|
|
5
3
|
class OnBuildOperation extends QueryBuilderOperation {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
clone.func = this.func;
|
|
23
|
-
return clone;
|
|
24
|
-
}
|
|
4
|
+
constructor(name, opt) {
|
|
5
|
+
super(name, opt);
|
|
6
|
+
this.func = null;
|
|
7
|
+
}
|
|
8
|
+
onAdd(_, args) {
|
|
9
|
+
this.func = args[0];
|
|
10
|
+
return true;
|
|
11
|
+
}
|
|
12
|
+
onBuild(builder) {
|
|
13
|
+
return this.func.call(builder, builder);
|
|
14
|
+
}
|
|
15
|
+
clone() {
|
|
16
|
+
const clone = super.clone();
|
|
17
|
+
clone.func = this.func;
|
|
18
|
+
return clone;
|
|
19
|
+
}
|
|
25
20
|
}
|
|
26
|
-
|
|
27
21
|
module.exports = {
|
|
28
|
-
|
|
22
|
+
OnBuildOperation,
|
|
29
23
|
};
|
|
@@ -1,29 +1,23 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
|
|
3
2
|
const { QueryBuilderOperation } = require('./QueryBuilderOperation');
|
|
4
|
-
|
|
5
3
|
class OnErrorOperation extends QueryBuilderOperation {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
clone.func = this.func;
|
|
23
|
-
return clone;
|
|
24
|
-
}
|
|
4
|
+
constructor(name, opt) {
|
|
5
|
+
super(name, opt);
|
|
6
|
+
this.func = null;
|
|
7
|
+
}
|
|
8
|
+
onAdd(_, args) {
|
|
9
|
+
this.func = args[0];
|
|
10
|
+
return true;
|
|
11
|
+
}
|
|
12
|
+
onError(builder, error) {
|
|
13
|
+
return this.func.call(builder, error, builder);
|
|
14
|
+
}
|
|
15
|
+
clone() {
|
|
16
|
+
const clone = super.clone();
|
|
17
|
+
clone.func = this.func;
|
|
18
|
+
return clone;
|
|
19
|
+
}
|
|
25
20
|
}
|
|
26
|
-
|
|
27
21
|
module.exports = {
|
|
28
|
-
|
|
22
|
+
OnErrorOperation,
|
|
29
23
|
};
|