@abedmurrar/objection 4.0.0-beta.5 → 4.0.0-beta.6
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/lib/queryBuilder/InternalOptions.js +4 -4
- package/lib/queryBuilder/QueryBuilder.js +161 -135
- package/lib/queryBuilder/QueryBuilderBase.js +203 -203
- package/lib/queryBuilder/QueryBuilderContext.js +6 -6
- package/lib/queryBuilder/QueryBuilderContextBase.js +12 -8
- package/lib/queryBuilder/QueryBuilderOperationSupport.js +30 -25
- package/lib/queryBuilder/QueryBuilderUserContext.js +4 -4
- package/lib/queryBuilder/StaticHookArguments.js +11 -11
- package/lib/queryBuilder/graph/GraphAction.js +7 -7
- package/lib/queryBuilder/graph/GraphData.js +4 -4
- package/lib/queryBuilder/graph/GraphFetcher.js +18 -17
- package/lib/queryBuilder/graph/GraphNodeDbExistence.js +45 -12
- package/lib/queryBuilder/graph/GraphOperation.js +4 -4
- package/lib/queryBuilder/graph/GraphOptions.js +5 -5
- package/lib/queryBuilder/graph/GraphUpsert.js +36 -36
- package/lib/queryBuilder/graph/delete/GraphDelete.js +8 -8
- package/lib/queryBuilder/graph/delete/GraphDeleteAction.js +46 -11
- package/lib/queryBuilder/graph/insert/GraphInsert.js +12 -12
- package/lib/queryBuilder/graph/insert/GraphInsertAction.js +59 -21
- package/lib/queryBuilder/graph/insert/JoinRowGraphInsertAction.js +49 -11
- package/lib/queryBuilder/graph/patch/GraphPatch.js +8 -8
- package/lib/queryBuilder/graph/patch/GraphPatchAction.js +52 -19
- package/lib/queryBuilder/graph/recursiveUpsert/GraphRecursiveUpsert.js +8 -8
- package/lib/queryBuilder/graph/recursiveUpsert/GraphRecursiveUpsertAction.js +54 -18
- package/lib/queryBuilder/operations/types.js +2 -2
- package/lib/queryBuilder/transformations/CompositeQueryTransformation.js +6 -6
- package/lib/queryBuilder/transformations/QueryTransformation.js +4 -4
- package/lib/queryBuilder/transformations/WrapMysqlModifySubqueryTransformation.js +11 -8
- package/lib/queryBuilder/transformations/index.js +8 -8
- package/lib/queryBuilder/whereScopes.js +15 -21
- package/package.json +1 -1
|
@@ -1,10 +1,45 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.GraphPatchAction = void 0;
|
|
37
|
+
const getModel_1 = require("../../../model/getModel");
|
|
38
|
+
const GraphAction_1 = require("../GraphAction");
|
|
39
|
+
const internalPropUtils_1 = require("../../../utils/internalPropUtils");
|
|
40
|
+
const objectUtils_1 = require("../../../utils/objectUtils");
|
|
41
|
+
const promiseUtils = __importStar(require("../../../utils/promiseUtils"));
|
|
42
|
+
class GraphPatchAction extends GraphAction_1.GraphAction {
|
|
8
43
|
constructor(graphData, { nodes }) {
|
|
9
44
|
super(graphData);
|
|
10
45
|
// Nodes to patch.
|
|
@@ -27,7 +62,7 @@ class GraphPatchAction extends GraphAction {
|
|
|
27
62
|
const handleUpdate = () => {
|
|
28
63
|
const { changedProps, unchangedProps } = this._findChanges(node);
|
|
29
64
|
const allProps = [...changedProps, ...unchangedProps];
|
|
30
|
-
const propsToUpdate = difference(shouldPatch || shouldUpdate
|
|
65
|
+
const propsToUpdate = (0, objectUtils_1.difference)(shouldPatch || shouldUpdate
|
|
31
66
|
? changedProps
|
|
32
67
|
: [...changedPropsBecauseOfBelongsToOneInsert, ...changePropsBecauseOfBelongsToOneDelete],
|
|
33
68
|
// Remove id properties from the props to update. With upsertGraph
|
|
@@ -36,12 +71,12 @@ class GraphPatchAction extends GraphAction {
|
|
|
36
71
|
const update = propsToUpdate.length > 0;
|
|
37
72
|
if (update) {
|
|
38
73
|
// Don't update the fields that we know not to change.
|
|
39
|
-
node.obj.$omitFromDatabaseJson(difference(allProps, propsToUpdate));
|
|
74
|
+
node.obj.$omitFromDatabaseJson((0, objectUtils_1.difference)(allProps, propsToUpdate));
|
|
40
75
|
node.userData.updated = true;
|
|
41
76
|
}
|
|
42
77
|
return update;
|
|
43
78
|
};
|
|
44
|
-
const Model = getModel();
|
|
79
|
+
const Model = (0, getModel_1.getModel)();
|
|
45
80
|
// See if the model defines a beforeUpdate or $beforeUpdate hook. If it does
|
|
46
81
|
// not, we can check for updated properties now and drop out immediately if
|
|
47
82
|
// there is nothing to update. Otherwise, we need to wait for the hook to be
|
|
@@ -62,7 +97,7 @@ class GraphPatchAction extends GraphAction {
|
|
|
62
97
|
});
|
|
63
98
|
const updateBuilder = this._createBuilder(node)
|
|
64
99
|
.childQueryOf(builder, childQueryOptions())
|
|
65
|
-
.copyFrom(builder, GraphAction.ReturningAllSelector);
|
|
100
|
+
.copyFrom(builder, GraphAction_1.GraphAction.ReturningAllSelector);
|
|
66
101
|
if (hasBeforeUpdate) {
|
|
67
102
|
updateBuilder.internalContext().runBefore.push((result, builder) => {
|
|
68
103
|
// Call handleUpdate in the runBefore hook which runs after the
|
|
@@ -81,7 +116,7 @@ class GraphPatchAction extends GraphAction {
|
|
|
81
116
|
updateBuilder.update(node.obj);
|
|
82
117
|
}
|
|
83
118
|
return updateBuilder.execute().then((result) => {
|
|
84
|
-
if (isObject(result) && result.$isObjectionModel) {
|
|
119
|
+
if ((0, objectUtils_1.isObject)(result) && result.$isObjectionModel) {
|
|
85
120
|
// Handle returning('*').
|
|
86
121
|
node.obj.$set(result);
|
|
87
122
|
}
|
|
@@ -140,7 +175,7 @@ class GraphPatchAction extends GraphAction {
|
|
|
140
175
|
const unchangedProps = [];
|
|
141
176
|
const changedProps = [];
|
|
142
177
|
for (const prop of Object.keys(obj)) {
|
|
143
|
-
if (isInternalProp(prop) || relationNames.includes(prop)) {
|
|
178
|
+
if ((0, internalPropUtils_1.isInternalProp)(prop) || relationNames.includes(prop)) {
|
|
144
179
|
continue;
|
|
145
180
|
}
|
|
146
181
|
const value = obj[prop];
|
|
@@ -178,8 +213,8 @@ class GraphPatchAction extends GraphAction {
|
|
|
178
213
|
}
|
|
179
214
|
}
|
|
180
215
|
_createRelatedBuilder(node) {
|
|
181
|
-
return node
|
|
182
|
-
.$relatedQuery(node.parentEdge.relation.name)
|
|
216
|
+
return node
|
|
217
|
+
.parentNode.obj.$relatedQuery(node.parentEdge.relation.name)
|
|
183
218
|
.findById(node.obj.$id());
|
|
184
219
|
}
|
|
185
220
|
_createRootBuilder(node) {
|
|
@@ -188,6 +223,7 @@ class GraphPatchAction extends GraphAction {
|
|
|
188
223
|
return currentObj ? currentObj.$query() : node.obj.$query();
|
|
189
224
|
}
|
|
190
225
|
}
|
|
226
|
+
exports.GraphPatchAction = GraphPatchAction;
|
|
191
227
|
function childQueryOptions() {
|
|
192
228
|
return {
|
|
193
229
|
fork: true,
|
|
@@ -198,8 +234,5 @@ function nonStrictEquals(val1, val2) {
|
|
|
198
234
|
if (val1 == val2) {
|
|
199
235
|
return true;
|
|
200
236
|
}
|
|
201
|
-
return jsonEquals(val1, val2);
|
|
237
|
+
return (0, objectUtils_1.jsonEquals)(val1, val2);
|
|
202
238
|
}
|
|
203
|
-
module.exports = {
|
|
204
|
-
GraphPatchAction,
|
|
205
|
-
};
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GraphRecursiveUpsert = void 0;
|
|
4
|
+
const GraphOperation_1 = require("../GraphOperation");
|
|
5
|
+
const GraphRecursiveUpsertAction_1 = require("./GraphRecursiveUpsertAction");
|
|
6
|
+
class GraphRecursiveUpsert extends GraphOperation_1.GraphOperation {
|
|
5
7
|
createActions() {
|
|
6
8
|
return [
|
|
7
|
-
new GraphRecursiveUpsertAction(this.graphData, {
|
|
9
|
+
new GraphRecursiveUpsertAction_1.GraphRecursiveUpsertAction(this.graphData, {
|
|
8
10
|
nodes: this.graph.nodes.filter((node) => {
|
|
9
11
|
const shouldRelate = this.graphOptions.shouldRelate(node, this.graphData);
|
|
10
12
|
return shouldRelate && hasRelations(node.obj);
|
|
@@ -13,6 +15,7 @@ class GraphRecursiveUpsert extends GraphOperation {
|
|
|
13
15
|
];
|
|
14
16
|
}
|
|
15
17
|
}
|
|
18
|
+
exports.GraphRecursiveUpsert = GraphRecursiveUpsert;
|
|
16
19
|
function hasRelations(obj) {
|
|
17
20
|
for (const relationName of obj.constructor.getRelationNames()) {
|
|
18
21
|
if (obj[relationName] !== undefined) {
|
|
@@ -21,6 +24,3 @@ function hasRelations(obj) {
|
|
|
21
24
|
}
|
|
22
25
|
return false;
|
|
23
26
|
}
|
|
24
|
-
module.exports = {
|
|
25
|
-
GraphRecursiveUpsert,
|
|
26
|
-
};
|
|
@@ -1,9 +1,44 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.GraphRecursiveUpsertAction = void 0;
|
|
37
|
+
const GraphAction_1 = require("../GraphAction");
|
|
38
|
+
const objectUtils_1 = require("../../../utils/objectUtils");
|
|
39
|
+
const ModelGraphBuilder_1 = require("../../../model/graph/ModelGraphBuilder");
|
|
40
|
+
const promiseUtils = __importStar(require("../../../utils/promiseUtils"));
|
|
41
|
+
class GraphRecursiveUpsertAction extends GraphAction_1.GraphAction {
|
|
7
42
|
constructor(graphData, { nodes }) {
|
|
8
43
|
super(graphData);
|
|
9
44
|
// Nodes to upsert.
|
|
@@ -16,10 +51,10 @@ class GraphRecursiveUpsertAction extends GraphAction {
|
|
|
16
51
|
});
|
|
17
52
|
}
|
|
18
53
|
_createUpsertBuilders(parentBuilder, nodesToUpsert) {
|
|
19
|
-
const nodesByRelation = groupBy(nodesToUpsert, getRelation);
|
|
54
|
+
const nodesByRelation = (0, objectUtils_1.groupBy)(nodesToUpsert, getRelation);
|
|
20
55
|
const builders = [];
|
|
21
56
|
nodesByRelation.forEach((nodes) => {
|
|
22
|
-
const nodesByParent = groupBy(nodes, getParent);
|
|
57
|
+
const nodesByParent = (0, objectUtils_1.groupBy)(nodes, getParent);
|
|
23
58
|
nodesByParent.forEach((nodes) => {
|
|
24
59
|
for (const node of nodes) {
|
|
25
60
|
this._resolveReferences(node);
|
|
@@ -28,8 +63,10 @@ class GraphRecursiveUpsertAction extends GraphAction {
|
|
|
28
63
|
builders.push(nodes[0].modelClass
|
|
29
64
|
.query()
|
|
30
65
|
.childQueryOf(parentBuilder)
|
|
31
|
-
.copyFrom(parentBuilder, GraphAction.ReturningAllSelector)
|
|
32
|
-
.upsertGraph(nodes.map((node) => node.obj),
|
|
66
|
+
.copyFrom(parentBuilder, GraphAction_1.GraphAction.ReturningAllSelector)
|
|
67
|
+
.upsertGraph(nodes.map((node) => node.obj),
|
|
68
|
+
// `GraphOptions` also takes a `GraphOptions` as its options.
|
|
69
|
+
this.graphOptions.rebasedOptions(nodes[0])));
|
|
33
70
|
});
|
|
34
71
|
});
|
|
35
72
|
return builders;
|
|
@@ -69,28 +106,27 @@ class GraphRecursiveUpsertAction extends GraphAction {
|
|
|
69
106
|
delete obj[modelClass.uidRefProp];
|
|
70
107
|
}
|
|
71
108
|
_resolvePropertyReferences(obj) {
|
|
72
|
-
forEachPropertyReference(obj, ({ path, refMatch, ref, refPath }) => {
|
|
109
|
+
(0, ModelGraphBuilder_1.forEachPropertyReference)(obj, ({ path, refMatch, ref, refPath, }) => {
|
|
73
110
|
const referencedNode = this.graph.nodes.find((it) => it.uid === ref);
|
|
74
111
|
if (!referencedNode) {
|
|
75
112
|
return;
|
|
76
113
|
}
|
|
77
|
-
const referencedValue = get(referencedNode.obj, refPath);
|
|
78
|
-
const value = get(obj, path);
|
|
114
|
+
const referencedValue = (0, objectUtils_1.get)(referencedNode.obj, refPath);
|
|
115
|
+
const value = (0, objectUtils_1.get)(obj, path);
|
|
79
116
|
if (value === refMatch) {
|
|
80
|
-
set(obj, path, referencedValue);
|
|
117
|
+
(0, objectUtils_1.set)(obj, path, referencedValue);
|
|
81
118
|
}
|
|
82
119
|
else {
|
|
83
|
-
|
|
120
|
+
// The reference is a part of a string: `replace()` converts the value to a string.
|
|
121
|
+
(0, objectUtils_1.set)(obj, path, value.replace(refMatch, referencedValue));
|
|
84
122
|
}
|
|
85
123
|
});
|
|
86
124
|
}
|
|
87
125
|
}
|
|
126
|
+
exports.GraphRecursiveUpsertAction = GraphRecursiveUpsertAction;
|
|
88
127
|
function getRelation(node) {
|
|
89
128
|
return node.parentEdge.relation;
|
|
90
129
|
}
|
|
91
130
|
function getParent(node) {
|
|
92
131
|
return node.parentNode;
|
|
93
132
|
}
|
|
94
|
-
module.exports = {
|
|
95
|
-
GraphRecursiveUpsertAction,
|
|
96
|
-
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// Internal types for the query builder operations.
|
|
3
3
|
//
|
|
4
|
-
// The
|
|
5
|
-
//
|
|
4
|
+
// The model classes are still JavaScript, so these interfaces only describe
|
|
5
|
+
// the parts of them that the operations use. The query builder and the
|
|
6
6
|
// relations are TypeScript, and their types are used here. The public types
|
|
7
7
|
// are the hand-written ones in `typings/`.
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CompositeQueryTransformation = void 0;
|
|
4
|
+
const QueryTransformation_1 = require("./QueryTransformation");
|
|
5
|
+
class CompositeQueryTransformation extends QueryTransformation_1.QueryTransformation {
|
|
4
6
|
constructor(transformations) {
|
|
5
7
|
super();
|
|
6
8
|
this.transformations = transformations;
|
|
@@ -12,6 +14,4 @@ class CompositeQueryTransformation extends QueryTransformation {
|
|
|
12
14
|
return item;
|
|
13
15
|
}
|
|
14
16
|
}
|
|
15
|
-
|
|
16
|
-
CompositeQueryTransformation,
|
|
17
|
-
};
|
|
17
|
+
exports.CompositeQueryTransformation = CompositeQueryTransformation;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.QueryTransformation = void 0;
|
|
2
4
|
class QueryTransformation {
|
|
3
5
|
onConvertQueryBuilderBase(item, builder) {
|
|
4
6
|
return item;
|
|
5
7
|
}
|
|
6
8
|
}
|
|
7
|
-
|
|
8
|
-
QueryTransformation,
|
|
9
|
-
};
|
|
9
|
+
exports.QueryTransformation = QueryTransformation;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WrapMysqlModifySubqueryTransformation = void 0;
|
|
4
|
+
const QueryTransformation_1 = require("./QueryTransformation");
|
|
5
|
+
const knexUtils_1 = require("../../utils/knexUtils");
|
|
4
6
|
/**
|
|
5
7
|
* Mysql doesn't allow queries like this:
|
|
6
8
|
*
|
|
@@ -13,7 +15,8 @@ const { isMySql } = require('../../utils/knexUtils');
|
|
|
13
15
|
*
|
|
14
16
|
* update foo set bar = 1 where id in (select * from (select id from foo))
|
|
15
17
|
*/
|
|
16
|
-
class WrapMysqlModifySubqueryTransformation extends QueryTransformation {
|
|
18
|
+
class WrapMysqlModifySubqueryTransformation extends QueryTransformation_1.QueryTransformation {
|
|
19
|
+
// In a join callback `parentQuery` is a `JoinBuilder`, which the loop below walks past.
|
|
17
20
|
onConvertQueryBuilderBase(query, parentQuery) {
|
|
18
21
|
const knex = parentQuery.unsafeKnex();
|
|
19
22
|
// Cannot detect anything if, for whatever reason, a knex instance
|
|
@@ -22,11 +25,12 @@ class WrapMysqlModifySubqueryTransformation extends QueryTransformation {
|
|
|
22
25
|
return query;
|
|
23
26
|
}
|
|
24
27
|
// This transformation only applies to MySQL.
|
|
25
|
-
if (!isMySql(knex)) {
|
|
28
|
+
if (!(0, knexUtils_1.isMySql)(knex)) {
|
|
26
29
|
return query;
|
|
27
30
|
}
|
|
28
31
|
// A subquery in a join callback belongs to the query of the join.
|
|
29
32
|
while (parentQuery && typeof parentQuery.isUpdate !== 'function') {
|
|
33
|
+
// The loop stops at the first parent query that is a `QueryBuilder`.
|
|
30
34
|
parentQuery = parentQuery.parentQuery();
|
|
31
35
|
}
|
|
32
36
|
// This transformation only applies to update and delete queries.
|
|
@@ -42,9 +46,11 @@ class WrapMysqlModifySubqueryTransformation extends QueryTransformation {
|
|
|
42
46
|
return query.modelClass().query().from(query.as('mysql_subquery_fix'));
|
|
43
47
|
}
|
|
44
48
|
}
|
|
49
|
+
exports.WrapMysqlModifySubqueryTransformation = WrapMysqlModifySubqueryTransformation;
|
|
45
50
|
function hasJoinsToTable(query, tableName) {
|
|
46
51
|
let found = false;
|
|
47
52
|
query.forEachOperation(query.constructor.JoinSelector, (op) => {
|
|
53
|
+
// The join operations are `KnexOperation`s, which have `args`.
|
|
48
54
|
if (op.args[0] === tableName) {
|
|
49
55
|
found = true;
|
|
50
56
|
return false;
|
|
@@ -52,6 +58,3 @@ function hasJoinsToTable(query, tableName) {
|
|
|
52
58
|
});
|
|
53
59
|
return found;
|
|
54
60
|
}
|
|
55
|
-
module.exports = {
|
|
56
|
-
WrapMysqlModifySubqueryTransformation,
|
|
57
|
-
};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transformation = void 0;
|
|
4
|
+
const CompositeQueryTransformation_1 = require("./CompositeQueryTransformation");
|
|
5
|
+
const WrapMysqlModifySubqueryTransformation_1 = require("./WrapMysqlModifySubqueryTransformation");
|
|
6
|
+
const transformation = new CompositeQueryTransformation_1.CompositeQueryTransformation([
|
|
7
|
+
new WrapMysqlModifySubqueryTransformation_1.WrapMysqlModifySubqueryTransformation(),
|
|
6
8
|
]);
|
|
7
|
-
|
|
8
|
-
transformation,
|
|
9
|
-
};
|
|
9
|
+
exports.transformation = transformation;
|
|
@@ -1,15 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
// conditions of the others. Without this, `$relatedQuery('pets').where(a).orWhere(b)`
|
|
9
|
-
// would produce `owner and a or b` and match other owners' pets.
|
|
10
|
-
//
|
|
11
|
-
// The scopes are only used when the knex query is built. The operation tree is
|
|
12
|
-
// never modified.
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.withWhereScope = withWhereScope;
|
|
4
|
+
exports.effectiveWhereScope = effectiveWhereScope;
|
|
5
|
+
exports.createWhereGrouping = createWhereGrouping;
|
|
6
|
+
const objectUtils_1 = require("../utils/objectUtils");
|
|
7
|
+
const knexUtils_1 = require("../utils/knexUtils");
|
|
13
8
|
const WhereSelector = /^(where|orWhere|andWhere|find\w+)/;
|
|
14
9
|
// Where operations that only ever produce a single predicate or predicates
|
|
15
10
|
// joined with `and`. A scope that only contains these (and no raw arguments)
|
|
@@ -63,6 +58,7 @@ function withWhereScope(builder, callback) {
|
|
|
63
58
|
builder._whereScope = previous;
|
|
64
59
|
}
|
|
65
60
|
}
|
|
61
|
+
// Returns the where scope token, or null.
|
|
66
62
|
function effectiveWhereScope(op) {
|
|
67
63
|
while (op) {
|
|
68
64
|
if (op.whereScope !== null) {
|
|
@@ -139,6 +135,7 @@ function buildOperationTree(builder, op, knexBuilder) {
|
|
|
139
135
|
}
|
|
140
136
|
function hasWhereAncestor(op) {
|
|
141
137
|
for (let parent = op.parentOperation; parent; parent = parent.parentOperation) {
|
|
138
|
+
// A null name is tested as 'null', as `test()` converts it to a string.
|
|
142
139
|
if (WhereSelector.test(parent.name)) {
|
|
143
140
|
return true;
|
|
144
141
|
}
|
|
@@ -159,13 +156,15 @@ function isAndOnlyTree(op) {
|
|
|
159
156
|
return andOnly;
|
|
160
157
|
}
|
|
161
158
|
function isAndOnly(op) {
|
|
162
|
-
|
|
159
|
+
// The operations that convert their arguments for knex have `args`.
|
|
160
|
+
return (AND_ONLY_OPERATIONS.has(op.name) && !containsRaw(op.args));
|
|
163
161
|
}
|
|
162
|
+
// `value` is a user value of any shape: operation arguments.
|
|
164
163
|
function containsRaw(value) {
|
|
165
164
|
if (Array.isArray(value)) {
|
|
166
165
|
return value.some(containsRaw);
|
|
167
166
|
}
|
|
168
|
-
else if (!isObject(value)) {
|
|
167
|
+
else if (!(0, objectUtils_1.isObject)(value)) {
|
|
169
168
|
return false;
|
|
170
169
|
}
|
|
171
170
|
else if (value.isObjectionReferenceBuilder) {
|
|
@@ -177,11 +176,11 @@ function containsRaw(value) {
|
|
|
177
176
|
// so only their arguments can contain anything.
|
|
178
177
|
return containsRaw(value._args);
|
|
179
178
|
}
|
|
180
|
-
else if (isKnexRaw(value) || isFunction(value.toKnexRaw)) {
|
|
179
|
+
else if ((0, knexUtils_1.isKnexRaw)(value) || (0, objectUtils_1.isFunction)(value.toKnexRaw)) {
|
|
181
180
|
// Raw sql (and anything that is converted into it) can contain anything.
|
|
182
181
|
return true;
|
|
183
182
|
}
|
|
184
|
-
else if (value.isObjectionQueryBuilderBase || isFunction(value.toSQL)) {
|
|
183
|
+
else if (value.isObjectionQueryBuilderBase || (0, objectUtils_1.isFunction)(value.toSQL)) {
|
|
185
184
|
// Subqueries are always wrapped in parentheses.
|
|
186
185
|
return false;
|
|
187
186
|
}
|
|
@@ -192,8 +191,3 @@ function containsRaw(value) {
|
|
|
192
191
|
return false;
|
|
193
192
|
}
|
|
194
193
|
}
|
|
195
|
-
module.exports = {
|
|
196
|
-
withWhereScope,
|
|
197
|
-
effectiveWhereScope,
|
|
198
|
-
createWhereGrouping,
|
|
199
|
-
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@abedmurrar/objection",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
3
|
+
"version": "4.0.0-beta.6",
|
|
4
4
|
"description": "An SQL-friendly ORM for Node.js. A fork of objection.js with strict TypeScript types and MySQL support.",
|
|
5
5
|
"main": "lib/objection.js",
|
|
6
6
|
"type": "commonjs",
|