@abedmurrar/objection 4.0.0-beta.0 → 4.0.0-beta.10
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 +1 -1
- package/lib/initialize.js +4 -5
- package/lib/model/AjvValidator.js +24 -21
- package/lib/model/Model.js +116 -114
- package/lib/model/ModifierNotFoundError.js +4 -4
- package/lib/model/NotFoundError.js +4 -4
- package/lib/model/RelationDoesNotExistError.js +4 -4
- package/lib/model/ValidationError.js +8 -8
- package/lib/model/Validator.js +7 -6
- package/lib/model/getModel.js +4 -4
- package/lib/model/graph/ModelGraph.js +9 -7
- package/lib/model/graph/ModelGraphBuilder.js +24 -24
- package/lib/model/graph/ModelGraphEdge.js +4 -4
- package/lib/model/graph/ModelGraphNode.js +17 -11
- package/lib/model/inheritModel.js +3 -4
- package/lib/model/modelBindKnex.js +12 -13
- package/lib/model/modelClone.js +15 -16
- package/lib/model/modelColPropMap.js +7 -8
- package/lib/model/modelConcurrency.js +6 -7
- package/lib/model/modelId.js +4 -5
- package/lib/model/modelJsonAttributes.js +10 -11
- package/lib/model/modelParseRelations.js +5 -6
- package/lib/model/modelQueryProps.js +12 -13
- package/lib/model/modelSet.js +17 -18
- package/lib/model/modelTableMetadata.js +9 -10
- package/lib/model/modelToJson.js +13 -14
- package/lib/model/modelUtils.js +7 -7
- package/lib/model/modelValidate.js +5 -6
- package/lib/model/modelValues.js +10 -10
- package/lib/model/modelVisitor.js +3 -4
- package/lib/objection.js +4 -26
- package/lib/queryBuilder/FunctionBuilder.js +35 -31
- package/lib/queryBuilder/InternalOptions.js +4 -4
- package/lib/queryBuilder/JoinBuilder.js +46 -45
- 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/RawBuilder.js +15 -13
- package/lib/queryBuilder/ReferenceBuilder.js +25 -23
- package/lib/queryBuilder/RelationExpression.js +29 -20
- package/lib/queryBuilder/StaticHookArguments.js +11 -11
- package/lib/queryBuilder/ValueBuilder.js +20 -19
- package/lib/queryBuilder/expressions.js +8 -18
- package/lib/queryBuilder/functions/mysql.js +18 -42
- 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/join/JoinResultColumn.js +6 -4
- package/lib/queryBuilder/join/JoinResultParser.js +10 -8
- package/lib/queryBuilder/join/RelationJoiner.js +40 -35
- package/lib/queryBuilder/join/TableNode.js +7 -5
- package/lib/queryBuilder/join/TableTree.js +13 -9
- package/lib/queryBuilder/join/utils.js +8 -8
- package/lib/queryBuilder/operations/DelegateOperation.js +6 -6
- package/lib/queryBuilder/operations/DeleteOperation.js +11 -11
- package/lib/queryBuilder/operations/FindByIdOperation.js +8 -8
- package/lib/queryBuilder/operations/FindByIdsOperation.js +6 -6
- package/lib/queryBuilder/operations/FindOperation.js +23 -23
- package/lib/queryBuilder/operations/FirstOperation.js +6 -6
- package/lib/queryBuilder/operations/FromOperation.js +13 -13
- package/lib/queryBuilder/operations/InsertAndFetchOperation.js +12 -12
- package/lib/queryBuilder/operations/InsertGraphAndFetchOperation.js +10 -10
- package/lib/queryBuilder/operations/InsertGraphOperation.js +11 -11
- package/lib/queryBuilder/operations/InsertOperation.js +23 -22
- package/lib/queryBuilder/operations/InstanceDeleteOperation.js +12 -12
- package/lib/queryBuilder/operations/InstanceFindOperation.js +10 -10
- package/lib/queryBuilder/operations/InstanceInsertOperation.js +6 -6
- package/lib/queryBuilder/operations/InstanceUpdateOperation.js +14 -14
- package/lib/queryBuilder/operations/JoinRelatedOperation.js +13 -13
- package/lib/queryBuilder/operations/KnexOperation.js +6 -6
- package/lib/queryBuilder/operations/MergeOperation.js +11 -11
- package/lib/queryBuilder/operations/ObjectionToKnexConvertingOperation.js +26 -22
- package/lib/queryBuilder/operations/OnBuildKnexOperation.js +6 -6
- package/lib/queryBuilder/operations/OnBuildOperation.js +6 -6
- package/lib/queryBuilder/operations/OnErrorOperation.js +6 -6
- package/lib/queryBuilder/operations/QueryBuilderOperation.js +6 -4
- package/lib/queryBuilder/operations/RangeOperation.js +7 -6
- package/lib/queryBuilder/operations/RelateOperation.js +6 -6
- package/lib/queryBuilder/operations/ReturningOperation.js +8 -8
- package/lib/queryBuilder/operations/RunAfterOperation.js +6 -6
- package/lib/queryBuilder/operations/RunBeforeOperation.js +6 -6
- package/lib/queryBuilder/operations/UnrelateOperation.js +6 -6
- package/lib/queryBuilder/operations/UpdateAndFetchOperation.js +12 -12
- package/lib/queryBuilder/operations/UpdateOperation.js +24 -24
- package/lib/queryBuilder/operations/UpsertGraphAndFetchOperation.js +10 -10
- package/lib/queryBuilder/operations/UpsertGraphOperation.js +10 -10
- package/lib/queryBuilder/operations/WhereCompositeOperation.js +8 -8
- package/lib/queryBuilder/operations/WhereInOperation.js +11 -9
- package/lib/queryBuilder/operations/eager/EagerOperation.js +11 -9
- package/lib/queryBuilder/operations/eager/JoinEagerOperation.js +10 -12
- package/lib/queryBuilder/operations/eager/NaiveEagerOperation.js +6 -6
- package/lib/queryBuilder/operations/eager/WhereInEagerOperation.js +64 -28
- package/lib/queryBuilder/operations/jsonApi/WhereJsonHasOperation.js +45 -12
- package/lib/queryBuilder/operations/jsonApi/WhereJsonNotObjectOperation.js +45 -12
- package/lib/queryBuilder/operations/jsonApi/WhereJsonOperation.js +45 -12
- package/lib/queryBuilder/operations/jsonApi/WhereJsonOverlapsOperation.js +46 -13
- package/lib/queryBuilder/operations/jsonApi/mysqlJsonApi.js +22 -27
- package/lib/queryBuilder/operations/jsonApi/postgresJsonApi.js +51 -17
- package/lib/queryBuilder/operations/select/SelectOperation.js +12 -12
- package/lib/queryBuilder/operations/select/Selection.js +23 -19
- package/lib/queryBuilder/operations/types.js +8 -0
- package/lib/queryBuilder/operations/whereInComposite/WhereInCompositeMsSqlOperation.js +13 -12
- package/lib/queryBuilder/operations/whereInComposite/WhereInCompositeOperation.js +11 -11
- package/lib/queryBuilder/operations/whereInComposite/WhereInCompositeSqliteOperation.js +10 -10
- 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/lib/relations/Relation.js +31 -29
- package/lib/relations/RelationDeleteOperation.js +8 -8
- package/lib/relations/RelationFindOperation.js +8 -6
- package/lib/relations/RelationInsertOperation.js +6 -6
- package/lib/relations/RelationOwner.js +16 -13
- package/lib/relations/RelationProperty.js +18 -15
- package/lib/relations/RelationUpdateOperation.js +8 -8
- package/lib/relations/belongsToOne/BelongsToOneDeleteOperation.js +6 -6
- package/lib/relations/belongsToOne/BelongsToOneInsertOperation.js +8 -8
- package/lib/relations/belongsToOne/BelongsToOneRelateOperation.js +8 -8
- package/lib/relations/belongsToOne/BelongsToOneRelation.js +14 -14
- package/lib/relations/belongsToOne/BelongsToOneUnrelateOperation.js +6 -6
- package/lib/relations/hasMany/HasManyInsertOperation.js +6 -6
- package/lib/relations/hasMany/HasManyRelateOperation.js +11 -11
- package/lib/relations/hasMany/HasManyRelation.js +12 -12
- package/lib/relations/hasMany/HasManyUnrelateOperation.js +9 -9
- package/lib/relations/hasOne/HasOneRelation.js +6 -6
- package/lib/relations/hasOneThrough/HasOneThroughRelation.js +6 -6
- package/lib/relations/manyToMany/ManyToManyModifyMixin.js +9 -8
- package/lib/relations/manyToMany/ManyToManyRelation.js +52 -49
- package/lib/relations/manyToMany/ManyToManySqliteModifyMixin.js +6 -6
- package/lib/relations/manyToMany/delete/ManyToManyDeleteOperation.js +7 -7
- package/lib/relations/manyToMany/delete/ManyToManyDeleteOperationBase.js +6 -6
- package/lib/relations/manyToMany/delete/ManyToManyDeleteSqliteOperation.js +7 -7
- package/lib/relations/manyToMany/find/ManyToManyFindOperation.js +8 -8
- package/lib/relations/manyToMany/insert/ManyToManyInsertOperation.js +8 -8
- package/lib/relations/manyToMany/relate/ManyToManyRelateOperation.js +11 -10
- package/lib/relations/manyToMany/unrelate/ManyToManyUnrelateOperation.js +7 -7
- package/lib/relations/manyToMany/unrelate/ManyToManyUnrelateOperationBase.js +8 -8
- package/lib/relations/manyToMany/unrelate/ManyToManyUnrelateSqliteOperation.js +7 -7
- package/lib/relations/manyToMany/update/ManyToManyUpdateOperation.js +7 -7
- package/lib/relations/manyToMany/update/ManyToManyUpdateOperationBase.js +8 -8
- package/lib/relations/manyToMany/update/ManyToManyUpdateSqliteOperation.js +7 -7
- package/lib/transaction.js +44 -12
- package/lib/utils/objectUtils.js +6 -1
- package/lib/utils/parseFieldExpression.js +4 -35
- package/lib/utils/promiseUtils/index.js +19 -9
- package/package.json +1 -1
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UpsertGraphOperation = void 0;
|
|
4
|
+
const QueryBuilderOperation_1 = require("./QueryBuilderOperation");
|
|
5
|
+
const GraphUpsert_1 = require("../graph/GraphUpsert");
|
|
6
|
+
const RelationFindOperation_1 = require("../../relations/RelationFindOperation");
|
|
7
|
+
class UpsertGraphOperation extends QueryBuilderOperation_1.QueryBuilderOperation {
|
|
6
8
|
constructor(name, opt) {
|
|
7
9
|
super(name, Object.assign({}, opt, {
|
|
8
10
|
upsertOptions: {},
|
|
@@ -18,7 +20,7 @@ class UpsertGraphOperation extends QueryBuilderOperation {
|
|
|
18
20
|
}
|
|
19
21
|
onAdd(builder, args) {
|
|
20
22
|
const [objects] = args;
|
|
21
|
-
this.upsert = new GraphUpsert({
|
|
23
|
+
this.upsert = new GraphUpsert_1.GraphUpsert({
|
|
22
24
|
objects,
|
|
23
25
|
rootModelClass: builder.modelClass(),
|
|
24
26
|
upsertOptions: this.upsertOptions,
|
|
@@ -39,9 +41,7 @@ class UpsertGraphOperation extends QueryBuilderOperation {
|
|
|
39
41
|
return clone;
|
|
40
42
|
}
|
|
41
43
|
}
|
|
44
|
+
exports.UpsertGraphOperation = UpsertGraphOperation;
|
|
42
45
|
function hasOtherSqlModifyingQueryBuilderCalls(builder) {
|
|
43
|
-
return builder.has(/where/) || builder.has(RelationFindOperation);
|
|
46
|
+
return builder.has(/where/) || builder.has(RelationFindOperation_1.RelationFindOperation);
|
|
44
47
|
}
|
|
45
|
-
module.exports = {
|
|
46
|
-
UpsertGraphOperation,
|
|
47
|
-
};
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WhereCompositeOperation = void 0;
|
|
4
|
+
const ObjectionToKnexConvertingOperation_1 = require("./ObjectionToKnexConvertingOperation");
|
|
5
|
+
const objectUtils_1 = require("../../utils/objectUtils");
|
|
6
|
+
class WhereCompositeOperation extends ObjectionToKnexConvertingOperation_1.ObjectionToKnexConvertingOperation {
|
|
5
7
|
onBuildKnex(knexBuilder, builder) {
|
|
6
8
|
const args = this.getKnexArgs(builder);
|
|
7
9
|
if (args.length === 2) {
|
|
@@ -14,6 +16,7 @@ class WhereCompositeOperation extends ObjectionToKnexConvertingOperation {
|
|
|
14
16
|
return knexBuilder.where(...buildWhereArgs(...args));
|
|
15
17
|
}
|
|
16
18
|
}
|
|
19
|
+
exports.WhereCompositeOperation = WhereCompositeOperation;
|
|
17
20
|
function buildWhereArgs(cols, op, values) {
|
|
18
21
|
if (isNormalWhere(cols, values)) {
|
|
19
22
|
return buildNormalWhereArgs(cols, op, values);
|
|
@@ -29,7 +32,7 @@ function isNormalWhere(cols, values) {
|
|
|
29
32
|
return ((!Array.isArray(cols) || cols.length === 1) && (!Array.isArray(values) || values.length === 1));
|
|
30
33
|
}
|
|
31
34
|
function buildNormalWhereArgs(cols, op, values) {
|
|
32
|
-
return [asSingle(cols), op, asSingle(values)];
|
|
35
|
+
return [(0, objectUtils_1.asSingle)(cols), op, (0, objectUtils_1.asSingle)(values)];
|
|
33
36
|
}
|
|
34
37
|
function isCompositeWhere(cols, values) {
|
|
35
38
|
return Array.isArray(cols) && Array.isArray(values) && cols.length === values.length;
|
|
@@ -43,6 +46,3 @@ function buildCompositeWhereArgs(cols, op, values) {
|
|
|
43
46
|
},
|
|
44
47
|
];
|
|
45
48
|
}
|
|
46
|
-
module.exports = {
|
|
47
|
-
WhereCompositeOperation,
|
|
48
|
-
};
|
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WhereInOperation = void 0;
|
|
4
|
+
const ObjectionToKnexConvertingOperation_1 = require("./ObjectionToKnexConvertingOperation");
|
|
5
|
+
const knexUtils_1 = require("../../utils/knexUtils");
|
|
4
6
|
// `onIn`, `onNotIn` etc. of join callbacks. knex compiles the values before the
|
|
5
7
|
// column, so the bindings of a raw column (like `ref('data:a').castInt()` on
|
|
6
8
|
// MySQL or `fn.lower(ref('a'))`) end up after the values and the query uses the
|
|
7
9
|
// wrong bindings. In that case the condition is built as raw sql with the
|
|
8
10
|
// bindings in the right order. knex 3.2 fixed this for `whereIn` but not for
|
|
9
11
|
// `onIn`.
|
|
10
|
-
class WhereInOperation extends ObjectionToKnexConvertingOperation {
|
|
12
|
+
class WhereInOperation extends ObjectionToKnexConvertingOperation_1.ObjectionToKnexConvertingOperation {
|
|
11
13
|
onBuildKnex(knexBuilder, builder) {
|
|
12
14
|
const args = this.getKnexArgs(builder);
|
|
13
15
|
const [column, values] = args;
|
|
@@ -22,7 +24,7 @@ class WhereInOperation extends ObjectionToKnexConvertingOperation {
|
|
|
22
24
|
sql = `? ${not}in (${values.map(() => '?').join(', ')})`;
|
|
23
25
|
bindings = [column, ...values];
|
|
24
26
|
}
|
|
25
|
-
else if (isKnexRaw(values)) {
|
|
27
|
+
else if ((0, knexUtils_1.isKnexRaw)(values)) {
|
|
26
28
|
// knex doesn't wrap raw bindings in parentheses.
|
|
27
29
|
sql = `? ${not}in (?)`;
|
|
28
30
|
bindings = [column, values];
|
|
@@ -35,12 +37,12 @@ class WhereInOperation extends ObjectionToKnexConvertingOperation {
|
|
|
35
37
|
return knexBuilder[this.opt.rawMethod](knex.raw(sql, bindings));
|
|
36
38
|
}
|
|
37
39
|
}
|
|
40
|
+
exports.WhereInOperation = WhereInOperation;
|
|
41
|
+
// A knex raw with bindings.
|
|
38
42
|
function hasBindings(column) {
|
|
39
|
-
|
|
43
|
+
const raw = column;
|
|
44
|
+
return (0, knexUtils_1.isKnexRaw)(raw) && Array.isArray(raw.bindings) && raw.bindings.length > 0;
|
|
40
45
|
}
|
|
41
46
|
function isEmptyArray(values) {
|
|
42
47
|
return Array.isArray(values) && values.length === 0;
|
|
43
48
|
}
|
|
44
|
-
module.exports = {
|
|
45
|
-
WhereInOperation,
|
|
46
|
-
};
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EagerOperation = void 0;
|
|
4
|
+
const QueryBuilderOperation_1 = require("../QueryBuilderOperation");
|
|
5
|
+
const RelationExpression_1 = require("../../RelationExpression");
|
|
6
|
+
class EagerOperation extends QueryBuilderOperation_1.QueryBuilderOperation {
|
|
5
7
|
constructor(name, opt) {
|
|
6
8
|
super(name, opt);
|
|
7
|
-
this.expression = RelationExpression.create();
|
|
9
|
+
this.expression = RelationExpression_1.RelationExpression.create();
|
|
8
10
|
this.modifiersAtPath = [];
|
|
9
11
|
this.graphOptions = this.opt.defaultGraphOptions;
|
|
10
12
|
}
|
|
@@ -12,7 +14,9 @@ class EagerOperation extends QueryBuilderOperation {
|
|
|
12
14
|
const expression = this.expression.clone();
|
|
13
15
|
this.modifiersAtPath.forEach((modifier, i) => {
|
|
14
16
|
const modifierName = getModifierName(i);
|
|
15
|
-
expression
|
|
17
|
+
expression
|
|
18
|
+
.expressionsAtPath(modifier.path)
|
|
19
|
+
.forEach((expr) => {
|
|
16
20
|
expr.node.$modify.push(modifierName);
|
|
17
21
|
});
|
|
18
22
|
});
|
|
@@ -38,9 +42,7 @@ class EagerOperation extends QueryBuilderOperation {
|
|
|
38
42
|
return clone;
|
|
39
43
|
}
|
|
40
44
|
}
|
|
45
|
+
exports.EagerOperation = EagerOperation;
|
|
41
46
|
function getModifierName(index) {
|
|
42
47
|
return `_f${index}_`;
|
|
43
48
|
}
|
|
44
|
-
module.exports = {
|
|
45
|
-
EagerOperation,
|
|
46
|
-
};
|
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.JoinEagerOperation = void 0;
|
|
4
|
+
const EagerOperation_1 = require("./EagerOperation");
|
|
5
|
+
const RelationJoiner_1 = require("../../join/RelationJoiner");
|
|
6
|
+
class JoinEagerOperation extends EagerOperation_1.EagerOperation {
|
|
5
7
|
constructor(name, opt) {
|
|
6
8
|
super(name, opt);
|
|
7
9
|
this.joiner = null;
|
|
8
10
|
}
|
|
9
11
|
onAdd(builder) {
|
|
10
12
|
builder.findOptions({ callAfterFindDeeply: true });
|
|
11
|
-
this.joiner = new RelationJoiner({
|
|
13
|
+
this.joiner = new RelationJoiner_1.RelationJoiner({
|
|
12
14
|
modelClass: builder.modelClass(),
|
|
13
15
|
});
|
|
14
16
|
return true;
|
|
15
17
|
}
|
|
16
18
|
onBefore3(builder) {
|
|
17
|
-
return this.joiner
|
|
18
|
-
.setExpression(this.buildFinalExpression())
|
|
19
|
+
return this.joiner.setExpression(this.buildFinalExpression())
|
|
19
20
|
.setModifiers(this.buildFinalModifiers(builder))
|
|
20
21
|
.setOptions(this.graphOptions)
|
|
21
22
|
.fetchColumnInfo(builder);
|
|
22
23
|
}
|
|
23
24
|
onBuild(builder) {
|
|
24
|
-
this.joiner
|
|
25
|
-
.setExpression(this.buildFinalExpression())
|
|
25
|
+
this.joiner.setExpression(this.buildFinalExpression())
|
|
26
26
|
.setModifiers(this.buildFinalModifiers(builder))
|
|
27
27
|
.setOptions(this.graphOptions)
|
|
28
28
|
.build(builder);
|
|
@@ -36,6 +36,4 @@ class JoinEagerOperation extends EagerOperation {
|
|
|
36
36
|
return clone;
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
|
-
|
|
40
|
-
JoinEagerOperation,
|
|
41
|
-
};
|
|
39
|
+
exports.JoinEagerOperation = JoinEagerOperation;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NaiveEagerOperation = void 0;
|
|
4
|
+
const WhereInEagerOperation_1 = require("./WhereInEagerOperation");
|
|
5
|
+
class NaiveEagerOperation extends WhereInEagerOperation_1.WhereInEagerOperation {
|
|
4
6
|
batchSize() {
|
|
5
7
|
return 1;
|
|
6
8
|
}
|
|
7
9
|
}
|
|
8
|
-
|
|
9
|
-
NaiveEagerOperation,
|
|
10
|
-
};
|
|
10
|
+
exports.NaiveEagerOperation = NaiveEagerOperation;
|
|
@@ -1,14 +1,49 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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.WhereInEagerOperation = void 0;
|
|
37
|
+
const promiseUtils = __importStar(require("../../../utils/promiseUtils"));
|
|
38
|
+
const EagerOperation_1 = require("./EagerOperation");
|
|
39
|
+
const knexUtils_1 = require("../../../utils/knexUtils");
|
|
40
|
+
const objectUtils_1 = require("../../../utils/objectUtils");
|
|
41
|
+
const ValidationError_1 = require("../../../model/ValidationError");
|
|
42
|
+
const createModifier_1 = require("../../../utils/createModifier");
|
|
43
|
+
const RelationDoesNotExistError_1 = require("../../../model/RelationDoesNotExistError");
|
|
44
|
+
const RelationOwner_1 = require("../../../relations/RelationOwner");
|
|
45
|
+
const modelConcurrency_1 = require("../../../model/modelConcurrency");
|
|
46
|
+
class WhereInEagerOperation extends EagerOperation_1.EagerOperation {
|
|
12
47
|
constructor(name, opt) {
|
|
13
48
|
super(name, opt);
|
|
14
49
|
this.relationsToFetch = [];
|
|
@@ -18,16 +53,16 @@ class WhereInEagerOperation extends EagerOperation {
|
|
|
18
53
|
if (this.graphOptions.maxBatchSize) {
|
|
19
54
|
return this.graphOptions.maxBatchSize;
|
|
20
55
|
}
|
|
21
|
-
else if (isMsSql(knex)) {
|
|
56
|
+
else if ((0, knexUtils_1.isMsSql)(knex)) {
|
|
22
57
|
// On MSSQL the parameter limit is actually 2100, but since I couldn't figure out
|
|
23
58
|
// if the limit is for all parameters in a query or for individual clauses, we set
|
|
24
59
|
// the limit to 2000 to leave 100 parameters for where clauses etc.
|
|
25
60
|
return 2000;
|
|
26
61
|
}
|
|
27
|
-
else if (isOracle(knex)) {
|
|
62
|
+
else if ((0, knexUtils_1.isOracle)(knex)) {
|
|
28
63
|
return 1000;
|
|
29
64
|
}
|
|
30
|
-
else if (isSqlite(knex)) {
|
|
65
|
+
else if ((0, knexUtils_1.isSqlite)(knex)) {
|
|
31
66
|
// SQLITE_MAX_VARIABLE_NUMBER is 999 by default
|
|
32
67
|
return 999;
|
|
33
68
|
}
|
|
@@ -46,17 +81,19 @@ class WhereInEagerOperation extends EagerOperation {
|
|
|
46
81
|
this.relationsToFetch = relationsToFetch;
|
|
47
82
|
this.omitProps = selectedProps;
|
|
48
83
|
}
|
|
84
|
+
// `result` is whatever the query returned: models, a model, or something else
|
|
85
|
+
// like a `count` result.
|
|
49
86
|
async onAfter2(builder, result) {
|
|
50
87
|
const modelClass = builder.resultModelClass();
|
|
51
88
|
if (!result) {
|
|
52
89
|
return result;
|
|
53
90
|
}
|
|
54
|
-
const models = asArray(result);
|
|
91
|
+
const models = (0, objectUtils_1.asArray)(result);
|
|
55
92
|
// Check models to be actual objects, to filter out `count` results (#2397).
|
|
56
|
-
if (!models.length || !isObject(models[0])) {
|
|
93
|
+
if (!models.length || !(0, objectUtils_1.isObject)(models[0])) {
|
|
57
94
|
return result;
|
|
58
95
|
}
|
|
59
|
-
await promiseUtils.map(this.relationsToFetch, (it) => this.fetchRelation(builder, models, it.relation, it.childExpression), { concurrency: getReadConcurrency(modelClass, builder.unsafeKnex()) });
|
|
96
|
+
await promiseUtils.map(this.relationsToFetch, (it) => this.fetchRelation(builder, models, it.relation, it.childExpression), { concurrency: (0, modelConcurrency_1.getReadConcurrency)(modelClass, builder.unsafeKnex()) });
|
|
60
97
|
const intOpt = builder.internalOptions();
|
|
61
98
|
if (!this.omitProps.length || intOpt.keepImplicitJoinProps) {
|
|
62
99
|
return result;
|
|
@@ -74,24 +111,25 @@ class WhereInEagerOperation extends EagerOperation {
|
|
|
74
111
|
async fetchRelation(builder, models, relation, expr) {
|
|
75
112
|
const modelClass = builder.resultModelClass();
|
|
76
113
|
const batchSize = this.batchSize(builder.knex());
|
|
77
|
-
const modelBatches = chunk(models, batchSize);
|
|
114
|
+
const modelBatches = (0, objectUtils_1.chunk)(models, batchSize);
|
|
78
115
|
const result = await promiseUtils.map(modelBatches, (batch) => this.fetchRelationBatch(builder, batch, relation, expr), {
|
|
79
|
-
concurrency: getReadConcurrency(modelClass, builder.unsafeKnex()),
|
|
116
|
+
concurrency: (0, modelConcurrency_1.getReadConcurrency)(modelClass, builder.unsafeKnex()),
|
|
80
117
|
});
|
|
81
|
-
return flatten(result);
|
|
118
|
+
return (0, objectUtils_1.flatten)(result);
|
|
82
119
|
}
|
|
83
120
|
fetchRelationBatch(builder, models, relation, expr) {
|
|
84
121
|
if (this.shouldSkipFetched(models, relation, expr)) {
|
|
85
122
|
return this.createSkippedQuery(builder, models, relation, expr);
|
|
86
123
|
}
|
|
87
124
|
const queryBuilder = this.createRelationQuery(builder, relation, expr);
|
|
88
|
-
|
|
125
|
+
// `Relation` types the operations it creates as `RelationOperation`.
|
|
126
|
+
const findOperation = relation.find(queryBuilder, RelationOwner_1.RelationOwner.create(models));
|
|
89
127
|
findOperation.alwaysReturnArray = true;
|
|
90
128
|
findOperation.assignResultToOwner = true;
|
|
91
129
|
findOperation.relationProperty = expr.node.$name;
|
|
92
130
|
queryBuilder.addOperation(findOperation, []);
|
|
93
131
|
for (const modifierName of expr.node.$modify) {
|
|
94
|
-
const modifier = createModifier({
|
|
132
|
+
const modifier = (0, createModifier_1.createModifier)({
|
|
95
133
|
modifier: modifierName,
|
|
96
134
|
modelClass: relation.relatedModelClass,
|
|
97
135
|
modifiers: this.buildFinalModifiers(builder),
|
|
@@ -103,7 +141,7 @@ class WhereInEagerOperation extends EagerOperation {
|
|
|
103
141
|
const modelClass = builder.modelClass();
|
|
104
142
|
if (err instanceof modelClass.ModifierNotFoundError) {
|
|
105
143
|
throw modelClass.createValidationError({
|
|
106
|
-
type: ValidationErrorType.RelationExpression,
|
|
144
|
+
type: ValidationError_1.ValidationErrorType.RelationExpression,
|
|
107
145
|
message: `could not find modifier "${modifierName}" for relation "${relation.name}"`,
|
|
108
146
|
});
|
|
109
147
|
}
|
|
@@ -162,6 +200,7 @@ class WhereInEagerOperation extends EagerOperation {
|
|
|
162
200
|
return clone;
|
|
163
201
|
}
|
|
164
202
|
}
|
|
203
|
+
exports.WhereInEagerOperation = WhereInEagerOperation;
|
|
165
204
|
function findRelationsToFetch(modelClass, eagerExpression) {
|
|
166
205
|
const relationsToFetch = [];
|
|
167
206
|
try {
|
|
@@ -173,9 +212,9 @@ function findRelationsToFetch(modelClass, eagerExpression) {
|
|
|
173
212
|
});
|
|
174
213
|
}
|
|
175
214
|
catch (err) {
|
|
176
|
-
if (err instanceof RelationDoesNotExistError) {
|
|
215
|
+
if (err instanceof RelationDoesNotExistError_1.RelationDoesNotExistError) {
|
|
177
216
|
throw modelClass.createValidationError({
|
|
178
|
-
type: ValidationErrorType.RelationExpression,
|
|
217
|
+
type: ValidationError_1.ValidationErrorType.RelationExpression,
|
|
179
218
|
message: `unknown relation "${err.relationName}" in an eager expression`,
|
|
180
219
|
});
|
|
181
220
|
}
|
|
@@ -222,6 +261,3 @@ function getRelatedModels(models, expr) {
|
|
|
222
261
|
}
|
|
223
262
|
return allRelated;
|
|
224
263
|
}
|
|
225
|
-
module.exports = {
|
|
226
|
-
WhereInEagerOperation,
|
|
227
|
-
};
|
|
@@ -1,19 +1,54 @@
|
|
|
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.WhereJsonHasOperation = void 0;
|
|
37
|
+
const postgresJsonApi = __importStar(require("./postgresJsonApi"));
|
|
38
|
+
const mysqlJsonApi = __importStar(require("./mysqlJsonApi"));
|
|
39
|
+
const postgresJsonPath_1 = require("../../../utils/postgresJsonPath");
|
|
40
|
+
const mysqlJsonPath_1 = require("../../../utils/mysqlJsonPath");
|
|
41
|
+
const ObjectionToKnexConvertingOperation_1 = require("../ObjectionToKnexConvertingOperation");
|
|
7
42
|
// `whereJsonHasAny` and `whereJsonHasAll`.
|
|
8
|
-
class WhereJsonHasOperation extends ObjectionToKnexConvertingOperation {
|
|
43
|
+
class WhereJsonHasOperation extends ObjectionToKnexConvertingOperation_1.ObjectionToKnexConvertingOperation {
|
|
9
44
|
onBuildKnex(knexBuilder, builder) {
|
|
10
|
-
const dialect = getJsonDialect(builder.unsafeKnex(), this.name);
|
|
45
|
+
const dialect = (0, postgresJsonPath_1.getJsonDialect)(builder.unsafeKnex(), this.name);
|
|
11
46
|
const args = this.getKnexArgs(builder);
|
|
12
47
|
let [sql, bindings] = dialect === 'mysql'
|
|
13
48
|
? mysqlJsonApi.whereJsonHas(args[0], this.opt.operator, args[1], builder.unsafeKnex())
|
|
14
49
|
: postgresJsonApi.whereJsonFieldRightStringArrayOnLeftQuery(builder.knex(), args[0], this.opt.operator, args[1]);
|
|
15
50
|
if (dialect === 'mysql') {
|
|
16
|
-
sql = jsonCastsForDialect(sql, builder.unsafeKnex());
|
|
51
|
+
sql = (0, mysqlJsonPath_1.jsonCastsForDialect)(sql, builder.unsafeKnex());
|
|
17
52
|
}
|
|
18
53
|
if (this.opt.bool === 'or') {
|
|
19
54
|
knexBuilder = knexBuilder.orWhereRaw(sql, bindings);
|
|
@@ -24,6 +59,4 @@ class WhereJsonHasOperation extends ObjectionToKnexConvertingOperation {
|
|
|
24
59
|
return knexBuilder;
|
|
25
60
|
}
|
|
26
61
|
}
|
|
27
|
-
|
|
28
|
-
WhereJsonHasOperation,
|
|
29
|
-
};
|
|
62
|
+
exports.WhereJsonHasOperation = WhereJsonHasOperation;
|
|
@@ -1,17 +1,52 @@
|
|
|
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.WhereJsonNotObjectOperation = void 0;
|
|
37
|
+
const jsonApi = __importStar(require("./postgresJsonApi"));
|
|
38
|
+
const mysqlJsonApi = __importStar(require("./mysqlJsonApi"));
|
|
39
|
+
const postgresJsonPath_1 = require("../../../utils/postgresJsonPath");
|
|
40
|
+
const mysqlJsonPath_1 = require("../../../utils/mysqlJsonPath");
|
|
41
|
+
const ObjectionToKnexConvertingOperation_1 = require("../ObjectionToKnexConvertingOperation");
|
|
7
42
|
// `whereJsonNotArray` and `whereJsonNotObject`.
|
|
8
|
-
class WhereJsonNotObjectOperation extends ObjectionToKnexConvertingOperation {
|
|
43
|
+
class WhereJsonNotObjectOperation extends ObjectionToKnexConvertingOperation_1.ObjectionToKnexConvertingOperation {
|
|
9
44
|
onBuildKnex(knexBuilder, builder) {
|
|
10
|
-
const dialect = getJsonDialect(builder.unsafeKnex(), this.name);
|
|
45
|
+
const dialect = (0, postgresJsonPath_1.getJsonDialect)(builder.unsafeKnex(), this.name);
|
|
11
46
|
const fieldExpression = this.getKnexArgs(builder)[0];
|
|
12
47
|
if (dialect === 'mysql') {
|
|
13
48
|
const [rawSql, bindings] = mysqlJsonApi.whereJsonNotContains(fieldExpression, this.opt.compareValue);
|
|
14
|
-
const sql = jsonCastsForDialect(rawSql, builder.unsafeKnex());
|
|
49
|
+
const sql = (0, mysqlJsonPath_1.jsonCastsForDialect)(rawSql, builder.unsafeKnex());
|
|
15
50
|
return this.opt.bool === 'or'
|
|
16
51
|
? knexBuilder.orWhereRaw(sql, bindings)
|
|
17
52
|
: knexBuilder.whereRaw(sql, bindings);
|
|
@@ -32,6 +67,4 @@ class WhereJsonNotObjectOperation extends ObjectionToKnexConvertingOperation {
|
|
|
32
67
|
return knexBuilder;
|
|
33
68
|
}
|
|
34
69
|
}
|
|
35
|
-
|
|
36
|
-
WhereJsonNotObjectOperation,
|
|
37
|
-
};
|
|
70
|
+
exports.WhereJsonNotObjectOperation = WhereJsonNotObjectOperation;
|
|
@@ -1,20 +1,55 @@
|
|
|
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.WhereJsonOperation = void 0;
|
|
37
|
+
const postgresJsonApi = __importStar(require("./postgresJsonApi"));
|
|
38
|
+
const mysqlJsonApi = __importStar(require("./mysqlJsonApi"));
|
|
39
|
+
const postgresJsonPath_1 = require("../../../utils/postgresJsonPath");
|
|
40
|
+
const mysqlJsonPath_1 = require("../../../utils/mysqlJsonPath");
|
|
41
|
+
const ObjectionToKnexConvertingOperation_1 = require("../ObjectionToKnexConvertingOperation");
|
|
7
42
|
// `whereJsonSupersetOf`, `whereJsonSubsetOf` and their variants.
|
|
8
|
-
class WhereJsonOperation extends ObjectionToKnexConvertingOperation {
|
|
43
|
+
class WhereJsonOperation extends ObjectionToKnexConvertingOperation_1.ObjectionToKnexConvertingOperation {
|
|
9
44
|
onBuildKnex(knexBuilder, builder) {
|
|
10
|
-
const dialect = getJsonDialect(builder.unsafeKnex(), this.name);
|
|
45
|
+
const dialect = (0, postgresJsonPath_1.getJsonDialect)(builder.unsafeKnex(), this.name);
|
|
11
46
|
const args = this.getKnexArgs(builder);
|
|
12
47
|
const jsonApi = dialect === 'mysql'
|
|
13
48
|
? mysqlJsonApi.whereJsonContains
|
|
14
49
|
: postgresJsonApi.whereJsonbRefOnLeftJsonbValOrRefOnRightRawQueryParams;
|
|
15
50
|
const rawArgs = jsonApi(args[0], this.opt.operator, args[1], this.opt.prefix);
|
|
16
51
|
if (dialect === 'mysql') {
|
|
17
|
-
rawArgs[0] = jsonCastsForDialect(rawArgs[0], builder.unsafeKnex());
|
|
52
|
+
rawArgs[0] = (0, mysqlJsonPath_1.jsonCastsForDialect)(rawArgs[0], builder.unsafeKnex());
|
|
18
53
|
}
|
|
19
54
|
if (this.opt.bool === 'or') {
|
|
20
55
|
knexBuilder = knexBuilder.orWhereRaw.apply(knexBuilder, rawArgs);
|
|
@@ -25,6 +60,4 @@ class WhereJsonOperation extends ObjectionToKnexConvertingOperation {
|
|
|
25
60
|
return knexBuilder;
|
|
26
61
|
}
|
|
27
62
|
}
|
|
28
|
-
|
|
29
|
-
WhereJsonOperation,
|
|
30
|
-
};
|
|
63
|
+
exports.WhereJsonOperation = WhereJsonOperation;
|