@abedmurrar/objection 4.0.0-alpha.0 → 4.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +103 -67
- package/lib/index.mjs +6 -0
- package/lib/initialize.js +6 -9
- package/lib/model/AjvValidator.js +235 -282
- package/lib/model/Model.js +653 -823
- package/lib/model/ModifierNotFoundError.js +5 -7
- package/lib/model/NotFoundError.js +14 -18
- package/lib/model/RelationDoesNotExistError.js +6 -9
- package/lib/model/ValidationError.js +33 -41
- package/lib/model/Validator.js +15 -21
- package/lib/model/getModel.js +1 -3
- package/lib/model/graph/ModelGraph.js +44 -64
- package/lib/model/graph/ModelGraphBuilder.js +164 -217
- package/lib/model/graph/ModelGraphEdge.js +31 -43
- package/lib/model/graph/ModelGraphNode.js +192 -231
- package/lib/model/inheritModel.js +9 -18
- package/lib/model/modelBindKnex.js +48 -62
- package/lib/model/modelClone.js +79 -98
- package/lib/model/modelColPropMap.js +16 -26
- package/lib/model/modelConcurrency.js +24 -0
- package/lib/model/modelId.js +44 -49
- package/lib/model/modelJsonAttributes.js +56 -76
- package/lib/model/modelParseRelations.js +68 -67
- package/lib/model/modelQueryProps.js +76 -107
- package/lib/model/modelSet.js +92 -112
- package/lib/model/modelTableMetadata.js +60 -72
- package/lib/model/modelToJson.js +120 -150
- package/lib/model/modelUtils.js +30 -37
- package/lib/model/modelValidate.js +34 -42
- package/lib/model/modelValues.js +78 -91
- package/lib/model/modelVisitor.js +22 -29
- package/lib/objection.js +42 -67
- package/lib/queryBuilder/FunctionBuilder.js +231 -279
- package/lib/queryBuilder/InternalOptions.js +19 -24
- package/lib/queryBuilder/JoinBuilder.js +116 -149
- package/lib/queryBuilder/QueryBuilder.js +1009 -1271
- package/lib/queryBuilder/QueryBuilderBase.js +647 -865
- package/lib/queryBuilder/QueryBuilderContext.js +14 -21
- package/lib/queryBuilder/QueryBuilderContextBase.js +20 -29
- package/lib/queryBuilder/QueryBuilderOperationSupport.js +462 -536
- package/lib/queryBuilder/QueryBuilderUserContext.js +19 -25
- package/lib/queryBuilder/RawBuilder.js +58 -73
- package/lib/queryBuilder/ReferenceBuilder.js +232 -270
- package/lib/queryBuilder/RelationExpression.js +322 -380
- package/lib/queryBuilder/StaticHookArguments.js +94 -106
- package/lib/queryBuilder/ValueBuilder.js +100 -112
- package/lib/queryBuilder/expressions.js +86 -116
- package/lib/queryBuilder/functions/mysql.js +642 -697
- package/lib/queryBuilder/graph/GraphAction.js +44 -59
- package/lib/queryBuilder/graph/GraphData.js +7 -9
- package/lib/queryBuilder/graph/GraphFetcher.js +115 -151
- package/lib/queryBuilder/graph/GraphNodeDbExistence.js +114 -152
- package/lib/queryBuilder/graph/GraphOperation.js +16 -22
- package/lib/queryBuilder/graph/GraphOptions.js +143 -185
- package/lib/queryBuilder/graph/GraphUpsert.js +167 -241
- package/lib/queryBuilder/graph/delete/GraphDelete.js +8 -13
- package/lib/queryBuilder/graph/delete/GraphDeleteAction.js +44 -62
- package/lib/queryBuilder/graph/insert/GraphInsert.js +99 -128
- package/lib/queryBuilder/graph/insert/GraphInsertAction.js +151 -193
- package/lib/queryBuilder/graph/insert/JoinRowGraphInsertAction.js +57 -79
- package/lib/queryBuilder/graph/patch/GraphPatch.js +8 -13
- package/lib/queryBuilder/graph/patch/GraphPatchAction.js +181 -234
- package/lib/queryBuilder/graph/recursiveUpsert/GraphRecursiveUpsert.js +16 -21
- package/lib/queryBuilder/graph/recursiveUpsert/GraphRecursiveUpsertAction.js +80 -110
- package/lib/queryBuilder/join/JoinResultColumn.js +14 -18
- package/lib/queryBuilder/join/JoinResultParser.js +88 -101
- package/lib/queryBuilder/join/RelationJoiner.js +205 -288
- package/lib/queryBuilder/join/TableNode.js +117 -144
- package/lib/queryBuilder/join/TableTree.js +60 -76
- package/lib/queryBuilder/join/utils.js +10 -16
- package/lib/queryBuilder/operations/DelegateOperation.js +93 -133
- package/lib/queryBuilder/operations/DeleteOperation.js +33 -37
- package/lib/queryBuilder/operations/FindByIdOperation.js +20 -28
- package/lib/queryBuilder/operations/FindByIdsOperation.js +17 -23
- package/lib/queryBuilder/operations/FindOperation.js +114 -131
- package/lib/queryBuilder/operations/FirstOperation.js +14 -19
- package/lib/queryBuilder/operations/FromOperation.js +69 -88
- package/lib/queryBuilder/operations/InsertAndFetchOperation.js +28 -39
- package/lib/queryBuilder/operations/InsertGraphAndFetchOperation.js +25 -35
- package/lib/queryBuilder/operations/InsertGraphOperation.js +77 -98
- package/lib/queryBuilder/operations/InsertOperation.js +132 -165
- package/lib/queryBuilder/operations/InstanceDeleteOperation.js +27 -36
- package/lib/queryBuilder/operations/InstanceFindOperation.js +9 -13
- package/lib/queryBuilder/operations/InstanceInsertOperation.js +13 -17
- package/lib/queryBuilder/operations/InstanceUpdateOperation.js +32 -46
- package/lib/queryBuilder/operations/JoinRelatedOperation.js +66 -86
- package/lib/queryBuilder/operations/KnexOperation.js +4 -7
- package/lib/queryBuilder/operations/MergeOperation.js +32 -45
- package/lib/queryBuilder/operations/ObjectionToKnexConvertingOperation.js +131 -150
- package/lib/queryBuilder/operations/OnBuildKnexOperation.js +17 -23
- package/lib/queryBuilder/operations/OnBuildOperation.js +17 -23
- package/lib/queryBuilder/operations/OnErrorOperation.js +17 -23
- package/lib/queryBuilder/operations/QueryBuilderOperation.js +231 -270
- package/lib/queryBuilder/operations/RangeOperation.js +30 -40
- package/lib/queryBuilder/operations/RelateOperation.js +14 -21
- package/lib/queryBuilder/operations/ReturningOperation.js +12 -18
- package/lib/queryBuilder/operations/RunAfterOperation.js +17 -23
- package/lib/queryBuilder/operations/RunBeforeOperation.js +17 -23
- package/lib/queryBuilder/operations/UnrelateOperation.js +12 -17
- package/lib/queryBuilder/operations/UpdateAndFetchOperation.js +48 -65
- package/lib/queryBuilder/operations/UpdateOperation.js +104 -129
- package/lib/queryBuilder/operations/UpsertGraphAndFetchOperation.js +25 -35
- package/lib/queryBuilder/operations/UpsertGraphOperation.js +36 -55
- package/lib/queryBuilder/operations/WhereCompositeOperation.js +30 -39
- package/lib/queryBuilder/operations/WhereInOperation.js +34 -36
- package/lib/queryBuilder/operations/eager/EagerOperation.js +37 -52
- package/lib/queryBuilder/operations/eager/JoinEagerOperation.js +34 -44
- package/lib/queryBuilder/operations/eager/NaiveEagerOperation.js +4 -7
- package/lib/queryBuilder/operations/eager/WhereInEagerOperation.js +193 -251
- package/lib/queryBuilder/operations/jsonApi/WhereJsonHasOperation.js +18 -25
- package/lib/queryBuilder/operations/jsonApi/WhereJsonNotObjectOperation.js +25 -41
- package/lib/queryBuilder/operations/jsonApi/WhereJsonOperation.js +19 -20
- package/lib/queryBuilder/operations/jsonApi/WhereJsonOverlapsOperation.js +23 -21
- package/lib/queryBuilder/operations/jsonApi/mysqlJsonApi.js +106 -118
- package/lib/queryBuilder/operations/jsonApi/postgresJsonApi.js +79 -108
- package/lib/queryBuilder/operations/select/SelectOperation.js +37 -53
- package/lib/queryBuilder/operations/select/Selection.js +94 -105
- package/lib/queryBuilder/operations/whereInComposite/WhereInCompositeMsSqlOperation.js +68 -101
- package/lib/queryBuilder/operations/whereInComposite/WhereInCompositeOperation.js +65 -75
- package/lib/queryBuilder/operations/whereInComposite/WhereInCompositeSqliteOperation.js +75 -84
- package/lib/queryBuilder/parsers/jsonFieldExpressionParser.js +760 -859
- package/lib/queryBuilder/parsers/relationExpressionParser.js +840 -952
- package/lib/queryBuilder/transformations/CompositeQueryTransformation.js +10 -15
- package/lib/queryBuilder/transformations/QueryTransformation.js +4 -6
- package/lib/queryBuilder/transformations/WrapMysqlModifySubqueryTransformation.js +35 -49
- package/lib/queryBuilder/transformations/index.js +3 -9
- package/lib/queryBuilder/whereScopes.js +158 -186
- package/lib/relations/Relation.js +293 -375
- package/lib/relations/RelationDeleteOperation.js +24 -28
- package/lib/relations/RelationFindOperation.js +108 -138
- package/lib/relations/RelationInsertOperation.js +24 -32
- package/lib/relations/RelationOwner.js +175 -209
- package/lib/relations/RelationProperty.js +186 -223
- package/lib/relations/RelationUpdateOperation.js +23 -29
- package/lib/relations/belongsToOne/BelongsToOneDeleteOperation.js +16 -21
- package/lib/relations/belongsToOne/BelongsToOneInsertOperation.js +30 -41
- package/lib/relations/belongsToOne/BelongsToOneRelateOperation.js +36 -47
- package/lib/relations/belongsToOne/BelongsToOneRelation.js +42 -50
- package/lib/relations/belongsToOne/BelongsToOneUnrelateOperation.js +43 -58
- package/lib/relations/hasMany/HasManyInsertOperation.js +40 -56
- package/lib/relations/hasMany/HasManyRelateOperation.js +45 -61
- package/lib/relations/hasMany/HasManyRelation.js +38 -46
- package/lib/relations/hasMany/HasManyUnrelateOperation.js +25 -32
- package/lib/relations/hasOne/HasOneRelation.js +9 -12
- package/lib/relations/hasOneThrough/HasOneThroughRelation.js +9 -12
- package/lib/relations/manyToMany/ManyToManyModifyMixin.js +73 -95
- package/lib/relations/manyToMany/ManyToManyRelation.js +374 -473
- package/lib/relations/manyToMany/ManyToManySqliteModifyMixin.js +23 -30
- package/lib/relations/manyToMany/delete/ManyToManyDeleteOperation.js +8 -10
- package/lib/relations/manyToMany/delete/ManyToManyDeleteOperationBase.js +20 -25
- package/lib/relations/manyToMany/delete/ManyToManyDeleteSqliteOperation.js +8 -12
- package/lib/relations/manyToMany/find/ManyToManyFindOperation.js +77 -100
- package/lib/relations/manyToMany/insert/ManyToManyInsertOperation.js +37 -49
- package/lib/relations/manyToMany/relate/ManyToManyRelateOperation.js +58 -74
- package/lib/relations/manyToMany/unrelate/ManyToManyUnrelateOperation.js +10 -13
- package/lib/relations/manyToMany/unrelate/ManyToManyUnrelateOperationBase.js +26 -33
- package/lib/relations/manyToMany/unrelate/ManyToManyUnrelateSqliteOperation.js +10 -15
- package/lib/relations/manyToMany/update/ManyToManyUpdateOperation.js +8 -10
- package/lib/relations/manyToMany/update/ManyToManyUpdateOperationBase.js +61 -78
- package/lib/relations/manyToMany/update/ManyToManyUpdateSqliteOperation.js +8 -12
- package/lib/transaction.js +53 -83
- package/lib/utils/assert.js +15 -21
- package/lib/utils/buildUtils.js +17 -19
- package/lib/utils/classUtils.js +7 -11
- package/lib/utils/cloneDeep.js +365 -0
- package/lib/utils/createModifier.js +36 -41
- package/lib/utils/deprecate.js +8 -12
- package/lib/utils/identifierMapping.js +153 -192
- package/lib/utils/internalPropUtils.js +4 -8
- package/lib/utils/knexUtils.js +61 -56
- package/lib/utils/mixin.js +16 -23
- package/lib/utils/mysqlJsonPath.js +55 -40
- package/lib/utils/normalizeIds.js +110 -127
- package/lib/utils/objectUtils.js +236 -338
- package/lib/utils/parseFieldExpression.js +66 -44
- package/lib/utils/postgresJsonPath.js +48 -62
- package/lib/utils/promiseUtils/after.js +10 -13
- package/lib/utils/promiseUtils/afterReturn.js +10 -13
- package/lib/utils/promiseUtils/index.js +15 -17
- package/lib/utils/promiseUtils/isPromise.js +6 -9
- package/lib/utils/promiseUtils/map.js +75 -89
- package/lib/utils/promiseUtils/mapAfterAllReturn.js +17 -23
- package/lib/utils/promiseUtils/try.js +15 -18
- package/lib/utils/resolveModel.js +91 -94
- package/lib/utils/tmpColumnUtils.js +4 -13
- package/package.json +50 -23
- package/typings/objection/index.d.mts +362 -0
- package/typings/objection/index.d.ts +36 -9
- package/lib/.eslintrc.json +0 -8
- package/lib/queryBuilder/parsers/jsonFieldExpressionParser.pegjs +0 -97
- package/lib/queryBuilder/parsers/relationExpressionParser.pegjs +0 -141
- package/lib/utils/clone.js +0 -2329
|
@@ -1,163 +1,136 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
|
|
3
2
|
class TableNode {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
this.idGetter = this._createIdGetter();
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
static create(args) {
|
|
17
|
-
const node = new TableNode(args);
|
|
18
|
-
|
|
19
|
-
if (node.parentNode) {
|
|
20
|
-
node.parentNode.childNodes.push(node);
|
|
3
|
+
constructor({ tableTree, modelClass, expression, parentNode = null, relation = null }) {
|
|
4
|
+
this.tableTree = tableTree;
|
|
5
|
+
this.modelClass = modelClass;
|
|
6
|
+
this.parentNode = parentNode;
|
|
7
|
+
this.relation = relation;
|
|
8
|
+
this.expression = expression;
|
|
9
|
+
this.childNodes = [];
|
|
10
|
+
this.alias = this._calculateAlias();
|
|
11
|
+
this.idGetter = this._createIdGetter();
|
|
21
12
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
get relationProperty() {
|
|
31
|
-
return this.expression.node.$name;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
getReferenceForColumn(column) {
|
|
35
|
-
return `${this.alias}.${column}`;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
getColumnAliasForColumn(column) {
|
|
39
|
-
if (this.parentNode) {
|
|
40
|
-
return `${this.alias}${this.options.separator}${column}`;
|
|
41
|
-
} else {
|
|
42
|
-
return column;
|
|
13
|
+
static create(args) {
|
|
14
|
+
const node = new TableNode(args);
|
|
15
|
+
if (node.parentNode) {
|
|
16
|
+
node.parentNode.childNodes.push(node);
|
|
17
|
+
}
|
|
18
|
+
return node;
|
|
43
19
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
getColumnForColumnAlias(columnAlias) {
|
|
47
|
-
const lastSepIndex = columnAlias.lastIndexOf(this.options.separator);
|
|
48
|
-
|
|
49
|
-
if (lastSepIndex === -1) {
|
|
50
|
-
return columnAlias;
|
|
51
|
-
} else {
|
|
52
|
-
return columnAlias.slice(lastSepIndex + this.options.separator.length);
|
|
20
|
+
get options() {
|
|
21
|
+
return this.tableTree.options;
|
|
53
22
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
getIdFromFlatRow(flatRow) {
|
|
57
|
-
return this.idGetter(flatRow);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
getJoinTableAlias(builder) {
|
|
61
|
-
if (this.relation.isObjectionManyToManyRelation) {
|
|
62
|
-
return (
|
|
63
|
-
builder.aliasFor(this.relation.joinTableModelClass) ||
|
|
64
|
-
this.modelClass.joinTableAlias(this.alias)
|
|
65
|
-
);
|
|
66
|
-
} else {
|
|
67
|
-
return undefined;
|
|
23
|
+
get relationProperty() {
|
|
24
|
+
return this.expression.node.$name;
|
|
68
25
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
_calculateAlias() {
|
|
72
|
-
if (this.parentNode) {
|
|
73
|
-
const relationName = this.expression.node.$name;
|
|
74
|
-
const alias = this.options.aliases[relationName] || relationName;
|
|
75
|
-
|
|
76
|
-
if (this.options.minimize) {
|
|
77
|
-
return `_t${this.tableTree.createNextUid()}`;
|
|
78
|
-
} else if (this.parentNode.parentNode) {
|
|
79
|
-
return `${this.parentNode.alias}${this.options.separator}${alias}`;
|
|
80
|
-
} else {
|
|
81
|
-
return alias;
|
|
82
|
-
}
|
|
83
|
-
} else {
|
|
84
|
-
return this.tableTree.rootTableAlias;
|
|
26
|
+
getReferenceForColumn(column) {
|
|
27
|
+
return `${this.alias}.${column}`;
|
|
85
28
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
29
|
+
getColumnAliasForColumn(column) {
|
|
30
|
+
if (this.parentNode) {
|
|
31
|
+
return `${this.alias}${this.options.separator}${column}`;
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
return column;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
getColumnForColumnAlias(columnAlias) {
|
|
38
|
+
const lastSepIndex = columnAlias.lastIndexOf(this.options.separator);
|
|
39
|
+
if (lastSepIndex === -1) {
|
|
40
|
+
return columnAlias;
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
return columnAlias.slice(lastSepIndex + this.options.separator.length);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
getIdFromFlatRow(flatRow) {
|
|
47
|
+
return this.idGetter(flatRow);
|
|
48
|
+
}
|
|
49
|
+
getJoinTableAlias(builder) {
|
|
50
|
+
if (this.relation.isObjectionManyToManyRelation) {
|
|
51
|
+
return (builder.aliasFor(this.relation.joinTableModelClass) ||
|
|
52
|
+
this.modelClass.joinTableAlias(this.alias));
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
return undefined;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
_calculateAlias() {
|
|
59
|
+
if (this.parentNode) {
|
|
60
|
+
const relationName = this.expression.node.$name;
|
|
61
|
+
const alias = this.options.aliases[relationName] || relationName;
|
|
62
|
+
if (this.options.minimize) {
|
|
63
|
+
return `_t${this.tableTree.createNextUid()}`;
|
|
64
|
+
}
|
|
65
|
+
else if (this.parentNode.parentNode) {
|
|
66
|
+
return `${this.parentNode.alias}${this.options.separator}${alias}`;
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
return alias;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
return this.tableTree.rootTableAlias;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
_createIdGetter() {
|
|
77
|
+
const idColumns = this.modelClass.getIdColumnArray();
|
|
78
|
+
const columnAliases = idColumns.map((column) => this.getColumnAliasForColumn(column));
|
|
79
|
+
if (idColumns.length === 1) {
|
|
80
|
+
return createIdGetter(columnAliases);
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
return createCompositeIdGetter(columnAliases);
|
|
84
|
+
}
|
|
96
85
|
}
|
|
97
|
-
}
|
|
98
86
|
}
|
|
99
|
-
|
|
100
87
|
function createIdGetter(columnAliases) {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
return `${id}`;
|
|
111
|
-
};
|
|
88
|
+
const columnAlias = columnAliases[0];
|
|
89
|
+
return (flatRow) => {
|
|
90
|
+
const id = flatRow[columnAlias];
|
|
91
|
+
if (id === null) {
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
return `${id}`;
|
|
95
|
+
};
|
|
112
96
|
}
|
|
113
|
-
|
|
114
97
|
function createCompositeIdGetter(columnAliases) {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
98
|
+
if (columnAliases.length === 2) {
|
|
99
|
+
return createTwoIdGetter(columnAliases);
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
return createMultiIdGetter(columnAliases);
|
|
103
|
+
}
|
|
120
104
|
}
|
|
121
|
-
|
|
122
105
|
function createTwoIdGetter(columnAliases) {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
return `${id1},${id2}`;
|
|
135
|
-
};
|
|
106
|
+
const columnAlias1 = columnAliases[0];
|
|
107
|
+
const columnAlias2 = columnAliases[1];
|
|
108
|
+
return (flatRow) => {
|
|
109
|
+
const id1 = flatRow[columnAlias1];
|
|
110
|
+
const id2 = flatRow[columnAlias2];
|
|
111
|
+
if (id1 === null || id2 === null) {
|
|
112
|
+
return null;
|
|
113
|
+
}
|
|
114
|
+
return `${id1},${id2}`;
|
|
115
|
+
};
|
|
136
116
|
}
|
|
137
|
-
|
|
138
117
|
function createMultiIdGetter(columnAliases) {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
return idStr;
|
|
158
|
-
};
|
|
118
|
+
return (flatRow) => {
|
|
119
|
+
let idStr = '';
|
|
120
|
+
for (let i = 0, l = columnAliases.length; i < l; ++i) {
|
|
121
|
+
const columnAlias = columnAliases[i];
|
|
122
|
+
const id = flatRow[columnAlias];
|
|
123
|
+
if (id === null) {
|
|
124
|
+
return null;
|
|
125
|
+
}
|
|
126
|
+
idStr += id;
|
|
127
|
+
if (i !== l - 1) {
|
|
128
|
+
idStr += ',';
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return idStr;
|
|
132
|
+
};
|
|
159
133
|
}
|
|
160
|
-
|
|
161
134
|
module.exports = {
|
|
162
|
-
|
|
135
|
+
TableNode,
|
|
163
136
|
};
|
|
@@ -1,85 +1,69 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
|
|
3
2
|
const { forEachChildExpression } = require('./utils');
|
|
4
3
|
const { TableNode } = require('./TableNode');
|
|
5
|
-
|
|
6
4
|
class TableTree {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
this._createNodes({ expression, modelClass: rootModelClass });
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
static create(args) {
|
|
19
|
-
return new TableTree(args);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
get rootNode() {
|
|
23
|
-
return this.nodes[0];
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
getNodeForColumnAlias(columnAlias) {
|
|
27
|
-
const lastSepIndex = columnAlias.lastIndexOf(this.options.separator);
|
|
28
|
-
|
|
29
|
-
if (lastSepIndex === -1) {
|
|
30
|
-
return this.rootNode;
|
|
31
|
-
} else {
|
|
32
|
-
const tableAlias = columnAlias.slice(0, lastSepIndex);
|
|
33
|
-
return this.nodesByAlias.get(tableAlias);
|
|
5
|
+
constructor({ expression, rootModelClass, rootTableAlias, options }) {
|
|
6
|
+
this.options = options;
|
|
7
|
+
this.rootModelClass = rootModelClass;
|
|
8
|
+
this.rootTableAlias = rootTableAlias;
|
|
9
|
+
this.nodes = [];
|
|
10
|
+
this.nodesByAlias = new Map();
|
|
11
|
+
this.uidCounter = 0;
|
|
12
|
+
this._createNodes({ expression, modelClass: rootModelClass });
|
|
34
13
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
14
|
+
static create(args) {
|
|
15
|
+
return new TableTree(args);
|
|
16
|
+
}
|
|
17
|
+
get rootNode() {
|
|
18
|
+
return this.nodes[0];
|
|
19
|
+
}
|
|
20
|
+
getNodeForColumnAlias(columnAlias) {
|
|
21
|
+
const lastSepIndex = columnAlias.lastIndexOf(this.options.separator);
|
|
22
|
+
if (lastSepIndex === -1) {
|
|
23
|
+
return this.rootNode;
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
const tableAlias = columnAlias.slice(0, lastSepIndex);
|
|
27
|
+
return this.nodesByAlias.get(tableAlias);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
createNextUid() {
|
|
31
|
+
return this.uidCounter++;
|
|
32
|
+
}
|
|
33
|
+
_createNodes({ expression, modelClass }) {
|
|
34
|
+
const rootNode = this._createRootNode({ expression, modelClass });
|
|
35
|
+
this._createChildNodes({ expression, modelClass, parentNode: rootNode });
|
|
36
|
+
for (const node of this.nodes) {
|
|
37
|
+
this.nodesByAlias.set(node.alias, node);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
_createRootNode({ expression, modelClass }) {
|
|
41
|
+
const node = TableNode.create({
|
|
42
|
+
tableTree: this,
|
|
43
|
+
modelClass,
|
|
44
|
+
expression,
|
|
45
|
+
});
|
|
46
|
+
this.nodes.push(node);
|
|
47
|
+
return node;
|
|
48
|
+
}
|
|
49
|
+
_createChildNodes({ expression, modelClass, parentNode }) {
|
|
50
|
+
forEachChildExpression(expression, modelClass, (childExpr, relation) => {
|
|
51
|
+
const node = TableNode.create({
|
|
52
|
+
tableTree: this,
|
|
53
|
+
modelClass: relation.relatedModelClass,
|
|
54
|
+
expression: childExpr,
|
|
55
|
+
parentNode,
|
|
56
|
+
relation,
|
|
57
|
+
});
|
|
58
|
+
this.nodes.push(node);
|
|
59
|
+
this._createChildNodes({
|
|
60
|
+
expression: childExpr,
|
|
61
|
+
modelClass: relation.relatedModelClass,
|
|
62
|
+
parentNode: node,
|
|
63
|
+
});
|
|
64
|
+
});
|
|
47
65
|
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
_createRootNode({ expression, modelClass }) {
|
|
51
|
-
const node = TableNode.create({
|
|
52
|
-
tableTree: this,
|
|
53
|
-
modelClass,
|
|
54
|
-
expression,
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
this.nodes.push(node);
|
|
58
|
-
return node;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
_createChildNodes({ expression, modelClass, parentNode }) {
|
|
62
|
-
forEachChildExpression(expression, modelClass, (childExpr, relation) => {
|
|
63
|
-
const node = TableNode.create({
|
|
64
|
-
tableTree: this,
|
|
65
|
-
modelClass: relation.relatedModelClass,
|
|
66
|
-
expression: childExpr,
|
|
67
|
-
|
|
68
|
-
parentNode,
|
|
69
|
-
relation,
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
this.nodes.push(node);
|
|
73
|
-
|
|
74
|
-
this._createChildNodes({
|
|
75
|
-
expression: childExpr,
|
|
76
|
-
modelClass: relation.relatedModelClass,
|
|
77
|
-
parentNode: node,
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
66
|
}
|
|
82
|
-
|
|
83
67
|
module.exports = {
|
|
84
|
-
|
|
68
|
+
TableTree,
|
|
85
69
|
};
|
|
@@ -1,25 +1,19 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
|
|
3
2
|
const { ValidationErrorType } = require('../../model/ValidationError');
|
|
4
|
-
|
|
5
3
|
const ID_LENGTH_LIMIT = 63;
|
|
6
4
|
const RELATION_RECURSION_LIMIT = 64;
|
|
7
|
-
|
|
8
5
|
// Given a relation expression, goes through all first level children.
|
|
9
6
|
function forEachChildExpression(expr, modelClass, callback) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
expr.forEachChildExpression(modelClass, callback);
|
|
7
|
+
if (expr.node.$allRecursive || expr.maxRecursionDepth > RELATION_RECURSION_LIMIT) {
|
|
8
|
+
throw modelClass.createValidationError({
|
|
9
|
+
type: ValidationErrorType.RelationExpression,
|
|
10
|
+
message: `recursion depth of eager expression ${expr.toString()} too big for JoinEagerAlgorithm`,
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
expr.forEachChildExpression(modelClass, callback);
|
|
18
14
|
}
|
|
19
|
-
|
|
20
15
|
module.exports = {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
forEachChildExpression,
|
|
16
|
+
ID_LENGTH_LIMIT,
|
|
17
|
+
RELATION_RECURSION_LIMIT,
|
|
18
|
+
forEachChildExpression,
|
|
25
19
|
};
|