objection 3.9.0 → 4.0.0-rc.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/lib/dbErrors/LICENSE +21 -0
- package/lib/dbErrors/errorCodes/mssql.js +19 -0
- package/lib/dbErrors/errorCodes/mysql.js +805 -0
- package/lib/dbErrors/errorCodes/postgres.js +241 -0
- package/lib/dbErrors/errors/CheckViolationError.js +10 -0
- package/lib/dbErrors/errors/ConstraintViolationError.js +3 -0
- package/lib/dbErrors/errors/DBError.js +9 -0
- package/lib/dbErrors/errors/DataError.js +3 -0
- package/lib/dbErrors/errors/ForeignKeyViolationError.js +11 -0
- package/lib/dbErrors/errors/NotNullViolationError.js +12 -0
- package/lib/dbErrors/errors/UniqueViolationError.js +12 -0
- package/lib/dbErrors/index.js +59 -0
- package/lib/dbErrors/parsers/mssql/DBError/CheckViolationError/parser.js +28 -0
- package/lib/dbErrors/parsers/mssql/DBError/DataError/parser.js +25 -0
- package/lib/dbErrors/parsers/mssql/DBError/ForeignKeyViolationError/parser.js +39 -0
- package/lib/dbErrors/parsers/mssql/DBError/NotNullViolationError/parser.js +30 -0
- package/lib/dbErrors/parsers/mssql/DBError/UniqueViolationError/parser.js +53 -0
- package/lib/dbErrors/parsers/mssql/DBError/parser.js +51 -0
- package/lib/dbErrors/parsers/mssql/DBError/util.js +16 -0
- package/lib/dbErrors/parsers/mysql/DBError/ConstraintViolationError/ForeignKeyViolationError/parser.js +43 -0
- package/lib/dbErrors/parsers/mysql/DBError/ConstraintViolationError/NotNullViolationError/parser.js +29 -0
- package/lib/dbErrors/parsers/mysql/DBError/ConstraintViolationError/UniqueViolationError/parser.js +27 -0
- package/lib/dbErrors/parsers/mysql/DBError/ConstraintViolationError/parser.js +23 -0
- package/lib/dbErrors/parsers/mysql/DBError/DataError/parser.js +24 -0
- package/lib/dbErrors/parsers/mysql/DBError/parser.js +28 -0
- package/lib/dbErrors/parsers/postgres/DBError/ConstraintViolationError/CheckViolationError/parser.js +18 -0
- package/lib/dbErrors/parsers/postgres/DBError/ConstraintViolationError/ForeignKeyViolationError/parser.js +18 -0
- package/lib/dbErrors/parsers/postgres/DBError/ConstraintViolationError/NotNullViolationError/parser.js +18 -0
- package/lib/dbErrors/parsers/postgres/DBError/ConstraintViolationError/UniqueViolationError/parser.js +40 -0
- package/lib/dbErrors/parsers/postgres/DBError/ConstraintViolationError/parser.js +25 -0
- package/lib/dbErrors/parsers/postgres/DBError/DataError/parser.js +16 -0
- package/lib/dbErrors/parsers/postgres/DBError/parser.js +27 -0
- package/lib/dbErrors/parsers/sqlite/DBError/ConstraintViolationError/CheckViolationError/parser.js +20 -0
- package/lib/dbErrors/parsers/sqlite/DBError/ConstraintViolationError/ForeignKeyViolationError/parser.js +20 -0
- package/lib/dbErrors/parsers/sqlite/DBError/ConstraintViolationError/NotNullViolationError/parser.js +27 -0
- package/lib/dbErrors/parsers/sqlite/DBError/ConstraintViolationError/UniqueViolationError/parser.js +28 -0
- package/lib/dbErrors/parsers/sqlite/DBError/ConstraintViolationError/parser.js +24 -0
- package/lib/dbErrors/parsers/sqlite/DBError/parser.js +23 -0
- package/lib/dbErrors/utils/sqlState.js +3 -0
- package/lib/initialize.js +1 -7
- package/lib/model/AjvValidator.js +51 -117
- package/lib/model/Model.js +84 -59
- package/lib/model/ModifierNotFoundError.js +1 -7
- package/lib/model/NotFoundError.js +1 -7
- package/lib/model/RelationDoesNotExistError.js +1 -7
- package/lib/model/ValidationError.js +3 -10
- package/lib/model/Validator.js +1 -7
- package/lib/model/getModel.js +7 -6
- package/lib/model/inheritModel.js +1 -7
- package/lib/model/modelBindKnex.js +4 -10
- package/lib/model/modelClone.js +5 -11
- package/lib/model/modelColPropMap.js +3 -10
- package/lib/model/modelId.js +3 -10
- package/lib/model/modelJsonAttributes.js +35 -16
- package/lib/model/modelParseRelations.js +2 -8
- package/lib/model/modelQueryProps.js +43 -27
- package/lib/model/modelSet.js +89 -41
- package/lib/model/modelTableMetadata.js +4 -11
- package/lib/model/modelToJson.js +8 -23
- package/lib/model/modelUtils.js +14 -13
- package/lib/model/modelValidate.js +3 -9
- package/lib/model/modelValues.js +5 -14
- package/lib/model/modelVisitor.js +1 -7
- package/lib/objection.js +33 -71
- package/lib/queryBuilder/FunctionBuilder.js +4 -11
- package/lib/queryBuilder/InternalOptions.js +4 -9
- package/lib/queryBuilder/JoinBuilder.js +5 -8
- package/lib/queryBuilder/QueryBuilder.js +126 -95
- package/lib/queryBuilder/QueryBuilderBase.js +41 -123
- package/lib/queryBuilder/QueryBuilderContext.js +2 -8
- package/lib/queryBuilder/QueryBuilderContextBase.js +2 -8
- package/lib/queryBuilder/QueryBuilderOperationSupport.js +7 -21
- package/lib/queryBuilder/QueryBuilderUserContext.js +1 -7
- package/lib/queryBuilder/RawBuilder.js +5 -13
- package/lib/queryBuilder/ReferenceBuilder.js +20 -48
- package/lib/queryBuilder/RelationExpression.js +18 -16
- package/lib/queryBuilder/StaticHookArguments.js +74 -16
- package/lib/queryBuilder/ValueBuilder.js +11 -13
- package/lib/queryBuilder/getJoinBuilder.js +10 -0
- package/lib/queryBuilder/graph/GraphLoader.js +304 -0
- package/lib/queryBuilder/graph/GraphNode.js +235 -0
- package/lib/queryBuilder/graph/GraphOptions.js +55 -248
- package/lib/queryBuilder/graph/GraphPlan.js +395 -0
- package/lib/queryBuilder/graph/GraphUpsert.js +466 -410
- package/lib/queryBuilder/graph/GraphWriter.js +1263 -0
- package/lib/queryBuilder/join/JoinResultColumn.js +1 -7
- package/lib/queryBuilder/join/JoinResultParser.js +6 -11
- package/lib/queryBuilder/join/RelationJoiner.js +66 -84
- package/lib/queryBuilder/join/TableNode.js +2 -8
- package/lib/queryBuilder/join/TableTree.js +3 -9
- package/lib/queryBuilder/join/utils.js +5 -15
- package/lib/queryBuilder/jsonDialects/JsonDialect.js +51 -0
- package/lib/queryBuilder/jsonDialects/MySqlJsonDialect.js +81 -0
- package/lib/queryBuilder/jsonDialects/PostgresJsonDialect.js +45 -0
- package/lib/queryBuilder/jsonDialects/SqliteJsonDialect.js +67 -0
- package/lib/queryBuilder/jsonDialects/index.js +44 -0
- package/lib/queryBuilder/operations/DelegateOperation.js +2 -8
- package/lib/queryBuilder/operations/DeleteOperation.js +13 -35
- package/lib/queryBuilder/operations/FindByIdOperation.js +7 -12
- package/lib/queryBuilder/operations/FindByIdsOperation.js +4 -8
- package/lib/queryBuilder/operations/FindOperation.js +14 -34
- package/lib/queryBuilder/operations/FirstOperation.js +6 -10
- package/lib/queryBuilder/operations/FromOperation.js +3 -9
- package/lib/queryBuilder/operations/InsertAndFetchOperation.js +13 -12
- package/lib/queryBuilder/operations/InsertGraphAndFetchOperation.js +4 -10
- package/lib/queryBuilder/operations/InsertGraphOperation.js +7 -18
- package/lib/queryBuilder/operations/InsertOperation.js +118 -43
- package/lib/queryBuilder/operations/InstanceDeleteOperation.js +5 -12
- package/lib/queryBuilder/operations/InstanceFindOperation.js +4 -11
- package/lib/queryBuilder/operations/InstanceInsertOperation.js +2 -8
- package/lib/queryBuilder/operations/InstanceUpdateOperation.js +7 -14
- package/lib/queryBuilder/operations/JoinRelatedOperation.js +5 -11
- package/lib/queryBuilder/operations/KnexOperation.js +2 -8
- package/lib/queryBuilder/operations/LimitPerParentOperation.js +7 -69
- package/lib/queryBuilder/operations/MergeOperation.js +5 -11
- package/lib/queryBuilder/operations/NoneOperation.js +2 -8
- package/lib/queryBuilder/operations/ObjectionToKnexConvertingOperation.js +20 -49
- package/lib/queryBuilder/operations/OnBuildKnexOperation.js +2 -8
- package/lib/queryBuilder/operations/OnBuildOperation.js +2 -8
- package/lib/queryBuilder/operations/OnErrorOperation.js +2 -8
- package/lib/queryBuilder/operations/QueryBuilderOperation.js +1 -7
- package/lib/queryBuilder/operations/RangeOperation.js +11 -26
- package/lib/queryBuilder/operations/RelateOperation.js +2 -8
- package/lib/queryBuilder/operations/ReturningOperation.js +3 -9
- package/lib/queryBuilder/operations/RunAfterOperation.js +2 -12
- package/lib/queryBuilder/operations/RunBeforeOperation.js +2 -8
- package/lib/queryBuilder/operations/UnrelateOperation.js +2 -8
- package/lib/queryBuilder/operations/UpdateAndFetchOperation.js +14 -17
- package/lib/queryBuilder/operations/UpdateOperation.js +39 -125
- package/lib/queryBuilder/operations/UpsertGraphAndFetchOperation.js +8 -11
- package/lib/queryBuilder/operations/UpsertGraphOperation.js +6 -12
- package/lib/queryBuilder/operations/WhereCompositeOperation.js +3 -9
- package/lib/queryBuilder/operations/WhereGroupOperation.js +2 -8
- package/lib/queryBuilder/operations/eager/EagerOperation.js +3 -9
- package/lib/queryBuilder/operations/eager/JoinEagerOperation.js +72 -10
- package/lib/queryBuilder/operations/eager/NaiveEagerOperation.js +2 -8
- package/lib/queryBuilder/operations/eager/WhereInEagerOperation.js +23 -44
- package/lib/queryBuilder/operations/fieldExpressions.js +122 -0
- package/lib/queryBuilder/operations/jsonApi/WhereJsonHasOperation.js +20 -0
- package/lib/queryBuilder/operations/jsonApi/WhereJsonOperation.js +44 -0
- package/lib/queryBuilder/operations/jsonApi/WhereJsonTypeOperation.js +14 -0
- package/lib/queryBuilder/operations/select/SelectOperation.js +11 -21
- package/lib/queryBuilder/operations/select/Selection.js +19 -17
- package/lib/queryBuilder/operations/whereInComposite/WhereInCompositeMsSqlOperation.js +4 -10
- package/lib/queryBuilder/operations/whereInComposite/WhereInCompositeOperation.js +4 -10
- package/lib/queryBuilder/operations/whereInComposite/WhereInCompositeSqliteOperation.js +4 -10
- package/lib/queryBuilder/operations/windowOrder.js +56 -0
- package/lib/queryBuilder/parsers/jsonFieldExpressionParser.js +3 -7
- package/lib/queryBuilder/parsers/relationExpressionParser.js +42 -43
- package/lib/queryBuilder/parsers/relationExpressionParser.pegjs +39 -36
- package/lib/queryBuilder/transformations/CompositeQueryTransformation.js +2 -8
- package/lib/queryBuilder/transformations/QueryTransformation.js +1 -7
- package/lib/queryBuilder/transformations/WrapMysqlModifySubqueryTransformation.js +3 -9
- package/lib/queryBuilder/transformations/index.js +3 -11
- package/lib/queryBuilder/whereGroups.js +9 -24
- package/lib/queryBuilder/withoutOrder.js +4 -11
- package/lib/relations/Relation.js +47 -28
- package/lib/relations/RelationDeleteOperation.js +4 -14
- package/lib/relations/RelationFindOperation.js +119 -90
- package/lib/relations/RelationInsertOperation.js +2 -8
- package/lib/relations/RelationOwner.js +5 -11
- package/lib/relations/RelationProperty.js +4 -10
- package/lib/relations/RelationUpdateOperation.js +4 -14
- package/lib/relations/RelationWriteResultOperation.js +15 -0
- package/lib/relations/belongsToMany/BelongsToManyDeleteOperation.js +23 -0
- package/lib/relations/belongsToMany/BelongsToManyFindOperation.js +35 -0
- package/lib/relations/belongsToMany/BelongsToManyInsertOperation.js +28 -0
- package/lib/relations/belongsToMany/BelongsToManyRelateOperation.js +16 -0
- package/lib/relations/belongsToMany/BelongsToManyRelation.js +276 -0
- package/lib/relations/belongsToMany/BelongsToManyUnrelateOperation.js +11 -0
- package/lib/relations/belongsToOne/BelongsToOneDeleteOperation.js +2 -8
- package/lib/relations/belongsToOne/BelongsToOneInsertOperation.js +6 -11
- package/lib/relations/belongsToOne/BelongsToOneRelateOperation.js +3 -9
- package/lib/relations/belongsToOne/BelongsToOneRelation.js +8 -19
- package/lib/relations/belongsToOne/BelongsToOneUnrelateOperation.js +53 -27
- package/lib/relations/hasMany/HasManyInsertOperation.js +8 -9
- package/lib/relations/hasMany/HasManyRelateOperation.js +5 -11
- package/lib/relations/hasMany/HasManyRelation.js +9 -11
- package/lib/relations/hasMany/HasManyUnrelateOperation.js +3 -9
- package/lib/relations/hasOne/HasOneRelation.js +2 -8
- package/lib/relations/hasOneThrough/HasOneThroughRelation.js +2 -8
- package/lib/relations/manyToMany/ManyToManyModifyMixin.js +10 -15
- package/lib/relations/manyToMany/ManyToManyMySqlModifyMixin.js +2 -8
- package/lib/relations/manyToMany/ManyToManyRelation.js +82 -50
- package/lib/relations/manyToMany/ManyToManySqliteModifyMixin.js +2 -8
- package/lib/relations/manyToMany/delete/ManyToManyDeleteOperation.js +5 -9
- package/lib/relations/manyToMany/delete/ManyToManyDeleteOperationBase.js +2 -8
- package/lib/relations/manyToMany/delete/ManyToManyDeleteSqliteOperation.js +3 -9
- package/lib/relations/manyToMany/find/ManyToManyFindOperation.js +20 -59
- package/lib/relations/manyToMany/insert/ManyToManyInsertOperation.js +6 -11
- package/lib/relations/manyToMany/relate/ManyToManyRelateOperation.js +4 -10
- package/lib/relations/manyToMany/unrelate/ManyToManyUnrelateMySqlOperation.js +3 -9
- package/lib/relations/manyToMany/unrelate/ManyToManyUnrelateOperation.js +5 -9
- package/lib/relations/manyToMany/unrelate/ManyToManyUnrelateOperationBase.js +3 -9
- package/lib/relations/manyToMany/unrelate/ManyToManyUnrelateSqliteOperation.js +3 -9
- package/lib/relations/manyToMany/update/ManyToManyUpdateMySqlOperation.js +3 -9
- package/lib/relations/manyToMany/update/ManyToManyUpdateOperation.js +5 -9
- package/lib/relations/manyToMany/update/ManyToManyUpdateOperationBase.js +79 -64
- package/lib/relations/manyToMany/update/ManyToManyUpdateSqliteOperation.js +3 -9
- package/lib/transaction.js +3 -9
- package/lib/utils/assert.js +3 -11
- package/lib/utils/buildUtils.js +2 -8
- package/lib/utils/classUtils.js +1 -7
- package/lib/utils/createModifier.js +2 -8
- package/lib/utils/identifierMapping.js +23 -27
- package/lib/utils/internalPropUtils.js +1 -7
- package/lib/utils/knexUtils.js +84 -40
- package/lib/utils/mixin.js +3 -10
- package/lib/utils/normalizeIds.js +2 -8
- package/lib/utils/objectUtils.js +41 -60
- package/lib/utils/parseFieldExpression.js +29 -14
- package/lib/utils/promiseUtils/after.js +2 -8
- package/lib/utils/promiseUtils/afterReturn.js +2 -8
- package/lib/utils/promiseUtils/index.js +7 -16
- package/lib/utils/promiseUtils/isPromise.js +2 -8
- package/lib/utils/promiseUtils/map.js +25 -14
- package/lib/utils/promiseUtils/mapAfterAllReturn.js +2 -8
- package/lib/utils/promiseUtils/try.js +2 -8
- package/lib/utils/resolveModel.js +10 -17
- package/lib/utils/tmpColumnUtils.js +2 -9
- package/lib/utils/warnings.js +2 -14
- package/package.json +25 -17
- package/typings/objection/index.d.ts +3217 -2179
- package/lib/.eslintrc.json +0 -8
- package/lib/model/graph/ModelGraph.js +0 -80
- package/lib/model/graph/ModelGraphBuilder.js +0 -241
- package/lib/model/graph/ModelGraphEdge.js +0 -52
- package/lib/model/graph/ModelGraphNode.js +0 -253
- package/lib/queryBuilder/graph/GraphAction.js +0 -69
- package/lib/queryBuilder/graph/GraphData.js +0 -53
- package/lib/queryBuilder/graph/GraphFetcher.js +0 -199
- package/lib/queryBuilder/graph/GraphNodeDbExistence.js +0 -184
- package/lib/queryBuilder/graph/GraphOperation.js +0 -27
- package/lib/queryBuilder/graph/delete/GraphDelete.js +0 -73
- package/lib/queryBuilder/graph/delete/GraphDeleteAction.js +0 -88
- package/lib/queryBuilder/graph/insert/DeferredRelationGraphInsertAction.js +0 -57
- package/lib/queryBuilder/graph/insert/GraphInsert.js +0 -257
- package/lib/queryBuilder/graph/insert/GraphInsertAction.js +0 -238
- package/lib/queryBuilder/graph/insert/JoinRowGraphInsertAction.js +0 -92
- package/lib/queryBuilder/graph/patch/GraphPatch.js +0 -20
- package/lib/queryBuilder/graph/patch/GraphPatchAction.js +0 -277
- package/lib/queryBuilder/graph/recursiveUpsert/GraphRecursiveUpsert.js +0 -31
- package/lib/queryBuilder/graph/recursiveUpsert/GraphRecursiveUpsertAction.js +0 -126
- package/lib/queryBuilder/operations/jsonApi/WhereJsonHasPostgresOperation.js +0 -30
- package/lib/queryBuilder/operations/jsonApi/WhereJsonNotObjectPostgresOperation.js +0 -37
- package/lib/queryBuilder/operations/jsonApi/WhereJsonPostgresOperation.js +0 -62
- package/lib/queryBuilder/operations/jsonApi/postgresJsonApi.js +0 -192
- package/lib/utils/wrapDbError.js +0 -50
|
@@ -1,19 +1,37 @@
|
|
|
1
|
-
{{
|
|
2
|
-
const { warnOnce } = require('../../utils/warnings');
|
|
3
|
-
}}
|
|
4
|
-
|
|
5
1
|
{
|
|
6
|
-
function
|
|
2
|
+
function addChild(node, expr) {
|
|
3
|
+
if (isToken(expr.$relation)) {
|
|
4
|
+
throwMisplacedToken(expr.$relation);
|
|
5
|
+
}
|
|
6
|
+
|
|
7
7
|
if (Object.prototype.hasOwnProperty.call(node, expr.$name)) {
|
|
8
|
-
|
|
8
|
+
const err = new Error();
|
|
9
|
+
err.duplicateRelationName = expr.$name;
|
|
10
|
+
throw err;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
node[expr.$name] = expr;
|
|
14
|
+
node.$childNames.push(expr.$name);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// `*` and `^` end a relation path, without modifiers, aliases or relations
|
|
18
|
+
// after them.
|
|
19
|
+
function isToken(name) {
|
|
20
|
+
return /^(\*|\^\d*)$/.test(name);
|
|
21
|
+
}
|
|
9
22
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
// throw err;
|
|
23
|
+
function assertPlainToken(expr) {
|
|
24
|
+
if (expr.$childNames.length > 0 || expr.$modify.length > 0 || expr.$name !== expr.$relation) {
|
|
25
|
+
throwMisplacedToken(expr.$relation);
|
|
14
26
|
}
|
|
15
27
|
}
|
|
16
28
|
|
|
29
|
+
function throwMisplacedToken(token) {
|
|
30
|
+
const err = new Error();
|
|
31
|
+
err.misplacedToken = token;
|
|
32
|
+
throw err;
|
|
33
|
+
}
|
|
34
|
+
|
|
17
35
|
function newNode() {
|
|
18
36
|
return {
|
|
19
37
|
$name: null,
|
|
@@ -30,12 +48,11 @@ start =
|
|
|
30
48
|
expr:expression {
|
|
31
49
|
const node = newNode()
|
|
32
50
|
|
|
33
|
-
if (expr.$
|
|
51
|
+
if (expr.$relation === '*') {
|
|
52
|
+
assertPlainToken(expr);
|
|
34
53
|
node.$allRecursive = true;
|
|
35
54
|
} else {
|
|
36
|
-
|
|
37
|
-
node[expr.$name] = expr;
|
|
38
|
-
node.$childNames.push(expr.$name)
|
|
55
|
+
addChild(node, expr);
|
|
39
56
|
}
|
|
40
57
|
|
|
41
58
|
return node;
|
|
@@ -44,11 +61,7 @@ start =
|
|
|
44
61
|
list:listExpression {
|
|
45
62
|
const node = newNode()
|
|
46
63
|
|
|
47
|
-
list.forEach(expr =>
|
|
48
|
-
assertDuplicateRelation(node, expr);
|
|
49
|
-
node[expr.$name] = expr;
|
|
50
|
-
node.$childNames.push(expr.$name)
|
|
51
|
-
});
|
|
64
|
+
list.forEach(expr => addChild(node, expr));
|
|
52
65
|
|
|
53
66
|
return node;
|
|
54
67
|
}
|
|
@@ -61,11 +74,7 @@ expression =
|
|
|
61
74
|
node.$relation = name;
|
|
62
75
|
node.$modify = args || [];
|
|
63
76
|
|
|
64
|
-
list.forEach(expr =>
|
|
65
|
-
assertDuplicateRelation(node, expr);
|
|
66
|
-
node[expr.$name] = expr;
|
|
67
|
-
node.$childNames.push(expr.$name)
|
|
68
|
-
});
|
|
77
|
+
list.forEach(expr => addChild(node, expr));
|
|
69
78
|
|
|
70
79
|
return node;
|
|
71
80
|
}
|
|
@@ -78,20 +87,14 @@ expression =
|
|
|
78
87
|
node.$modify = args || [];
|
|
79
88
|
|
|
80
89
|
if (expr) {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
if (match) {
|
|
84
|
-
if (match[1]) {
|
|
85
|
-
node.$recursive = parseInt(match[1], 10);
|
|
86
|
-
} else {
|
|
87
|
-
node.$recursive = true;
|
|
88
|
-
}
|
|
89
|
-
} else if (expr.$name === '*') {
|
|
90
|
+
if (expr.$relation === '*') {
|
|
91
|
+
assertPlainToken(expr);
|
|
90
92
|
node.$allRecursive = true;
|
|
93
|
+
} else if (isToken(expr.$relation)) {
|
|
94
|
+
assertPlainToken(expr);
|
|
95
|
+
node.$recursive = expr.$relation === '^' ? true : parseInt(expr.$relation.slice(1), 10);
|
|
91
96
|
} else {
|
|
92
|
-
|
|
93
|
-
node[expr.$name] = expr;
|
|
94
|
-
node.$childNames.push(expr.$name)
|
|
97
|
+
addChild(node, expr);
|
|
95
98
|
}
|
|
96
99
|
}
|
|
97
100
|
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import { QueryTransformation } from './QueryTransformation.js';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
class CompositeQueryTransformation extends QueryTransformation {
|
|
3
|
+
export class CompositeQueryTransformation extends QueryTransformation {
|
|
6
4
|
constructor(transformations) {
|
|
7
5
|
super();
|
|
8
6
|
this.transformations = transformations;
|
|
@@ -16,7 +14,3 @@ class CompositeQueryTransformation extends QueryTransformation {
|
|
|
16
14
|
return item;
|
|
17
15
|
}
|
|
18
16
|
}
|
|
19
|
-
|
|
20
|
-
module.exports = {
|
|
21
|
-
CompositeQueryTransformation,
|
|
22
|
-
};
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const { QueryTransformation } = require('./QueryTransformation');
|
|
4
|
-
const { isMySql } = require('../../utils/knexUtils');
|
|
1
|
+
import { QueryTransformation } from './QueryTransformation.js';
|
|
2
|
+
import { isMySql } from '../../utils/knexUtils.js';
|
|
5
3
|
|
|
6
4
|
/**
|
|
7
5
|
* Mysql doesn't allow queries like this:
|
|
@@ -15,7 +13,7 @@ const { isMySql } = require('../../utils/knexUtils');
|
|
|
15
13
|
*
|
|
16
14
|
* update foo set bar = 1 where id in (select * from (select id from foo))
|
|
17
15
|
*/
|
|
18
|
-
class WrapMysqlModifySubqueryTransformation extends QueryTransformation {
|
|
16
|
+
export class WrapMysqlModifySubqueryTransformation extends QueryTransformation {
|
|
19
17
|
onConvertQueryBuilderBase(query, parentQuery) {
|
|
20
18
|
const knex = parentQuery.unsafeKnex();
|
|
21
19
|
|
|
@@ -66,7 +64,3 @@ function hasJoinsToTable(query, tableName) {
|
|
|
66
64
|
|
|
67
65
|
return found;
|
|
68
66
|
}
|
|
69
|
-
|
|
70
|
-
module.exports = {
|
|
71
|
-
WrapMysqlModifySubqueryTransformation,
|
|
72
|
-
};
|
|
@@ -1,15 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import { CompositeQueryTransformation } from './CompositeQueryTransformation.js';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
import { WrapMysqlModifySubqueryTransformation } from './WrapMysqlModifySubqueryTransformation.js';
|
|
4
4
|
|
|
5
|
-
const
|
|
6
|
-
WrapMysqlModifySubqueryTransformation,
|
|
7
|
-
} = require('./WrapMysqlModifySubqueryTransformation');
|
|
8
|
-
|
|
9
|
-
const transformation = new CompositeQueryTransformation([
|
|
5
|
+
export const transformation = new CompositeQueryTransformation([
|
|
10
6
|
new WrapMysqlModifySubqueryTransformation(),
|
|
11
7
|
]);
|
|
12
|
-
|
|
13
|
-
module.exports = {
|
|
14
|
-
transformation,
|
|
15
|
-
};
|
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const { isObject, isFunction } = require('../utils/objectUtils');
|
|
5
|
-
const { isKnexRaw } = require('../utils/knexUtils');
|
|
1
|
+
import { WhereGroupOperation } from './operations/WhereGroupOperation.js';
|
|
2
|
+
import { isObject, isFunction } from '../utils/objectUtils.js';
|
|
3
|
+
import { isKnexRaw } from '../utils/knexUtils.js';
|
|
6
4
|
|
|
7
5
|
// Where operations of a query can come from different sources: the user, a
|
|
8
6
|
// relation's owner condition, the relation's `modify`/`filter`, the id
|
|
9
|
-
// condition of `
|
|
10
|
-
// forms its own "where group". All operations the user adds
|
|
11
|
-
// default group, and `addWhereGroup` assigns the operations added
|
|
12
|
-
// callback to a new, separate group.
|
|
7
|
+
// condition of `findById()`, `findByIds()` and `$query()` and so on. Each
|
|
8
|
+
// source forms its own "where group". All other operations the user adds
|
|
9
|
+
// belong to the default group, and `addWhereGroup` assigns the operations added
|
|
10
|
+
// inside its callback to a new, separate group.
|
|
13
11
|
//
|
|
14
12
|
// Knex simply joins all where clauses with their `and` or `or` boolean. Since
|
|
15
13
|
// `and` binds tighter than `or`, a user's `orWhere` would escape the relation's
|
|
@@ -22,7 +20,7 @@ const { isKnexRaw } = require('../utils/knexUtils');
|
|
|
22
20
|
// always ANDed together: `where "ownerId" in (1) and (a or b)`. Groups without
|
|
23
21
|
// an `or` are left alone so that their SQL doesn't change. The operations
|
|
24
22
|
// aren't moved, so that a built query can be cloned and built again.
|
|
25
|
-
function addWhereGroup(builder, callback) {
|
|
23
|
+
export function addWhereGroup(builder, callback) {
|
|
26
24
|
const parentWhereGroup = builder._whereGroup;
|
|
27
25
|
builder._whereGroup = {};
|
|
28
26
|
|
|
@@ -33,17 +31,10 @@ function addWhereGroup(builder, callback) {
|
|
|
33
31
|
}
|
|
34
32
|
}
|
|
35
33
|
|
|
36
|
-
// Assign an operation that isn't added through a builder, like the result of
|
|
37
|
-
// `toFindOperation()`, to a new, separate group.
|
|
38
|
-
function assignWhereGroup(operation) {
|
|
39
|
-
operation.whereGroup = {};
|
|
40
|
-
return operation;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
34
|
// Return a map from each where operation that needs to be wrapped in
|
|
44
35
|
// parentheses to the `WhereGroupOperation` that builds its group in place of
|
|
45
36
|
// the group's first operation, or to null for the group's other operations.
|
|
46
|
-
function getWhereGroupOperations(builder) {
|
|
37
|
+
export function getWhereGroupOperations(builder) {
|
|
47
38
|
const WhereSelector = builder.constructor.WhereSelector;
|
|
48
39
|
const whereOps = new Set();
|
|
49
40
|
const groups = new Map();
|
|
@@ -112,9 +103,3 @@ function mayContainTopLevelOr(op) {
|
|
|
112
103
|
function isRaw(arg) {
|
|
113
104
|
return isKnexRaw(arg) || (isObject(arg) && isFunction(arg.toKnexRaw));
|
|
114
105
|
}
|
|
115
|
-
|
|
116
|
-
module.exports = {
|
|
117
|
-
addWhereGroup,
|
|
118
|
-
assignWhereGroup,
|
|
119
|
-
getWhereGroupOperations,
|
|
120
|
-
};
|
|
@@ -1,19 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const { FirstOperation } = require('./operations/FirstOperation');
|
|
4
|
-
const { isMsSql } = require('../utils/knexUtils');
|
|
1
|
+
import { FirstOperation } from './operations/FirstOperation.js';
|
|
2
|
+
import { isMsSql } from '../utils/knexUtils.js';
|
|
5
3
|
|
|
6
4
|
// Removes the order of a subquery that only selects or joins rows. The order
|
|
7
5
|
// can come from a relation's `modify` or an `onBuild` hook of the context, so
|
|
8
6
|
// it's removed when the subquery is built.
|
|
9
|
-
function withoutOrder(subquery) {
|
|
7
|
+
export function withoutOrder(subquery) {
|
|
10
8
|
return subquery.onBuild(clearUnsupportedOrder);
|
|
11
9
|
}
|
|
12
10
|
|
|
13
11
|
// Without a limit, an order doesn't matter in subqueries and updates, and SQL
|
|
14
12
|
// Server rejects it there. With a limit it decides the rows, so we keep it, and
|
|
15
13
|
// SQL Server rejects an update rather than updating arbitrary rows.
|
|
16
|
-
function clearUnsupportedOrder(builder) {
|
|
14
|
+
export function clearUnsupportedOrder(builder) {
|
|
17
15
|
if (isMsSql(builder.knex()) && !hasLimit(builder)) {
|
|
18
16
|
builder.clearOrder();
|
|
19
17
|
}
|
|
@@ -26,8 +24,3 @@ function hasLimit(builder) {
|
|
|
26
24
|
builder.findOperation(FirstOperation)?.shouldLimit(builder)
|
|
27
25
|
);
|
|
28
26
|
}
|
|
29
|
-
|
|
30
|
-
module.exports = {
|
|
31
|
-
withoutOrder,
|
|
32
|
-
clearUnsupportedOrder,
|
|
33
|
-
};
|
|
@@ -1,19 +1,17 @@
|
|
|
1
|
-
|
|
1
|
+
import { RelationProperty } from './RelationProperty.js';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
import { RelationFindOperation } from './RelationFindOperation.js';
|
|
4
|
+
import { RelationUpdateOperation } from './RelationUpdateOperation.js';
|
|
5
|
+
import { RelationDeleteOperation } from './RelationDeleteOperation.js';
|
|
4
6
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
import { resolveModel } from '../utils/resolveModel.js';
|
|
8
|
+
import { get, isFunction } from '../utils/objectUtils.js';
|
|
9
|
+
import { mapAfterAllReturn } from '../utils/promiseUtils/index.js';
|
|
10
|
+
import { createModifier } from '../utils/createModifier.js';
|
|
11
|
+
import { addWhereGroup } from '../queryBuilder/whereGroups.js';
|
|
12
|
+
import { withoutOrder } from '../queryBuilder/withoutOrder.js';
|
|
8
13
|
|
|
9
|
-
|
|
10
|
-
const { get, isFunction } = require('../utils/objectUtils');
|
|
11
|
-
const { mapAfterAllReturn } = require('../utils/promiseUtils');
|
|
12
|
-
const { createModifier } = require('../utils/createModifier');
|
|
13
|
-
const { addWhereGroup } = require('../queryBuilder/whereGroups');
|
|
14
|
-
const { withoutOrder } = require('../queryBuilder/withoutOrder');
|
|
15
|
-
|
|
16
|
-
class Relation {
|
|
14
|
+
export class Relation {
|
|
17
15
|
constructor(relationName, OwnerClass) {
|
|
18
16
|
this.name = relationName;
|
|
19
17
|
this.ownerModelClass = OwnerClass;
|
|
@@ -84,10 +82,11 @@ class Relation {
|
|
|
84
82
|
return false;
|
|
85
83
|
}
|
|
86
84
|
|
|
87
|
-
//
|
|
88
|
-
// `
|
|
89
|
-
|
|
90
|
-
|
|
85
|
+
// Where the keys that connect owners and related models are stored: in the
|
|
86
|
+
// `'owner'` rows, the `'related'` rows or the rows of a `'join'` table. Owners
|
|
87
|
+
// of relations that aren't one-to-one hold arrays of keys.
|
|
88
|
+
get keySide() {
|
|
89
|
+
throw new Error('not implemented');
|
|
91
90
|
}
|
|
92
91
|
|
|
93
92
|
clone() {
|
|
@@ -151,6 +150,7 @@ class Relation {
|
|
|
151
150
|
relatedJoinSelectQuery = this.relatedModelClass.query().childQueryOf(builder),
|
|
152
151
|
relatedTable = builder.tableNameFor(this.relatedModelClass),
|
|
153
152
|
ownerTable = builder.tableRefFor(this.ownerModelClass),
|
|
153
|
+
modifyJoin,
|
|
154
154
|
} = {},
|
|
155
155
|
) {
|
|
156
156
|
let relatedJoinSelect = this.applyModify(relatedJoinSelectQuery).as(relatedTableAlias);
|
|
@@ -163,18 +163,41 @@ class Relation {
|
|
|
163
163
|
}
|
|
164
164
|
|
|
165
165
|
return builder[joinOperation](relatedJoinSelect, (join) => {
|
|
166
|
-
|
|
167
|
-
const ownerProp = this.ownerProp;
|
|
166
|
+
this.joinOn(builder, join, { relatedTableAlias, ownerTable });
|
|
168
167
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
168
|
+
if (modifyJoin) {
|
|
169
|
+
this._applyModifyJoin(join, modifyJoin, { owner: ownerTable, related: relatedTableAlias });
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
}
|
|
172
173
|
|
|
173
|
-
|
|
174
|
-
|
|
174
|
+
// @overridable
|
|
175
|
+
joinOn(builder, join, { relatedTableAlias, ownerTable }) {
|
|
176
|
+
const relatedProp = this.relatedProp;
|
|
177
|
+
const ownerProp = this.ownerProp;
|
|
178
|
+
|
|
179
|
+
relatedProp.forEach((i) => {
|
|
180
|
+
const relatedRef = relatedProp.ref(builder, i).table(relatedTableAlias);
|
|
181
|
+
const ownerRef = ownerProp.ref(builder, i).table(ownerTable);
|
|
182
|
+
|
|
183
|
+
join.on(relatedRef, ownerRef);
|
|
175
184
|
});
|
|
176
185
|
}
|
|
177
186
|
|
|
187
|
+
// Group the conditions of `modifyJoin()`, so that an `orOn` in them can't
|
|
188
|
+
// escape the key conditions of the relation. Knex renders an empty group as
|
|
189
|
+
// a dangling `and`, so we only add it if there are conditions.
|
|
190
|
+
_applyModifyJoin(join, modifyJoin, aliases) {
|
|
191
|
+
const group = join.clone().clear(true);
|
|
192
|
+
modifyJoin(group, aliases);
|
|
193
|
+
|
|
194
|
+
if (group.has(true)) {
|
|
195
|
+
join.andOn(function () {
|
|
196
|
+
this.copyFrom(group, true);
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
178
201
|
find(_, owner) {
|
|
179
202
|
return new RelationFindOperation('find', {
|
|
180
203
|
relation: this,
|
|
@@ -406,7 +429,3 @@ function aliasedTableName(tableName, alias) {
|
|
|
406
429
|
return `${tableName} as ${alias}`;
|
|
407
430
|
}
|
|
408
431
|
}
|
|
409
|
-
|
|
410
|
-
module.exports = {
|
|
411
|
-
Relation,
|
|
412
|
-
};
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import { DeleteOperation } from '../queryBuilder/operations/DeleteOperation.js';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
const { RelationFindOperation } = require('./RelationFindOperation');
|
|
5
|
-
|
|
6
|
-
class RelationDeleteOperation extends DeleteOperation {
|
|
3
|
+
export class RelationDeleteOperation extends DeleteOperation {
|
|
7
4
|
constructor(name, opt) {
|
|
8
5
|
super(name, opt);
|
|
9
6
|
|
|
@@ -16,14 +13,7 @@ class RelationDeleteOperation extends DeleteOperation {
|
|
|
16
13
|
this.relation.findQuery(builder, this.owner);
|
|
17
14
|
}
|
|
18
15
|
|
|
19
|
-
toFindOperation() {
|
|
20
|
-
return
|
|
21
|
-
relation: this.relation,
|
|
22
|
-
owner: this.owner,
|
|
23
|
-
});
|
|
16
|
+
toFindOperation(builder) {
|
|
17
|
+
return this.relation.find(builder, this.owner);
|
|
24
18
|
}
|
|
25
19
|
}
|
|
26
|
-
|
|
27
|
-
module.exports = {
|
|
28
|
-
RelationDeleteOperation,
|
|
29
|
-
};
|