@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.
Files changed (192) hide show
  1. package/README.md +103 -67
  2. package/lib/index.mjs +6 -0
  3. package/lib/initialize.js +6 -9
  4. package/lib/model/AjvValidator.js +235 -282
  5. package/lib/model/Model.js +653 -823
  6. package/lib/model/ModifierNotFoundError.js +5 -7
  7. package/lib/model/NotFoundError.js +14 -18
  8. package/lib/model/RelationDoesNotExistError.js +6 -9
  9. package/lib/model/ValidationError.js +33 -41
  10. package/lib/model/Validator.js +15 -21
  11. package/lib/model/getModel.js +1 -3
  12. package/lib/model/graph/ModelGraph.js +44 -64
  13. package/lib/model/graph/ModelGraphBuilder.js +164 -217
  14. package/lib/model/graph/ModelGraphEdge.js +31 -43
  15. package/lib/model/graph/ModelGraphNode.js +192 -231
  16. package/lib/model/inheritModel.js +9 -18
  17. package/lib/model/modelBindKnex.js +48 -62
  18. package/lib/model/modelClone.js +79 -98
  19. package/lib/model/modelColPropMap.js +16 -26
  20. package/lib/model/modelConcurrency.js +24 -0
  21. package/lib/model/modelId.js +44 -49
  22. package/lib/model/modelJsonAttributes.js +56 -76
  23. package/lib/model/modelParseRelations.js +68 -67
  24. package/lib/model/modelQueryProps.js +76 -107
  25. package/lib/model/modelSet.js +92 -112
  26. package/lib/model/modelTableMetadata.js +60 -72
  27. package/lib/model/modelToJson.js +120 -150
  28. package/lib/model/modelUtils.js +30 -37
  29. package/lib/model/modelValidate.js +34 -42
  30. package/lib/model/modelValues.js +78 -91
  31. package/lib/model/modelVisitor.js +22 -29
  32. package/lib/objection.js +42 -67
  33. package/lib/queryBuilder/FunctionBuilder.js +231 -279
  34. package/lib/queryBuilder/InternalOptions.js +19 -24
  35. package/lib/queryBuilder/JoinBuilder.js +116 -149
  36. package/lib/queryBuilder/QueryBuilder.js +1009 -1271
  37. package/lib/queryBuilder/QueryBuilderBase.js +647 -865
  38. package/lib/queryBuilder/QueryBuilderContext.js +14 -21
  39. package/lib/queryBuilder/QueryBuilderContextBase.js +20 -29
  40. package/lib/queryBuilder/QueryBuilderOperationSupport.js +462 -536
  41. package/lib/queryBuilder/QueryBuilderUserContext.js +19 -25
  42. package/lib/queryBuilder/RawBuilder.js +58 -73
  43. package/lib/queryBuilder/ReferenceBuilder.js +232 -270
  44. package/lib/queryBuilder/RelationExpression.js +322 -380
  45. package/lib/queryBuilder/StaticHookArguments.js +94 -106
  46. package/lib/queryBuilder/ValueBuilder.js +100 -112
  47. package/lib/queryBuilder/expressions.js +86 -116
  48. package/lib/queryBuilder/functions/mysql.js +642 -697
  49. package/lib/queryBuilder/graph/GraphAction.js +44 -59
  50. package/lib/queryBuilder/graph/GraphData.js +7 -9
  51. package/lib/queryBuilder/graph/GraphFetcher.js +115 -151
  52. package/lib/queryBuilder/graph/GraphNodeDbExistence.js +114 -152
  53. package/lib/queryBuilder/graph/GraphOperation.js +16 -22
  54. package/lib/queryBuilder/graph/GraphOptions.js +143 -185
  55. package/lib/queryBuilder/graph/GraphUpsert.js +167 -241
  56. package/lib/queryBuilder/graph/delete/GraphDelete.js +8 -13
  57. package/lib/queryBuilder/graph/delete/GraphDeleteAction.js +44 -62
  58. package/lib/queryBuilder/graph/insert/GraphInsert.js +99 -128
  59. package/lib/queryBuilder/graph/insert/GraphInsertAction.js +151 -193
  60. package/lib/queryBuilder/graph/insert/JoinRowGraphInsertAction.js +57 -79
  61. package/lib/queryBuilder/graph/patch/GraphPatch.js +8 -13
  62. package/lib/queryBuilder/graph/patch/GraphPatchAction.js +181 -234
  63. package/lib/queryBuilder/graph/recursiveUpsert/GraphRecursiveUpsert.js +16 -21
  64. package/lib/queryBuilder/graph/recursiveUpsert/GraphRecursiveUpsertAction.js +80 -110
  65. package/lib/queryBuilder/join/JoinResultColumn.js +14 -18
  66. package/lib/queryBuilder/join/JoinResultParser.js +88 -101
  67. package/lib/queryBuilder/join/RelationJoiner.js +205 -288
  68. package/lib/queryBuilder/join/TableNode.js +117 -144
  69. package/lib/queryBuilder/join/TableTree.js +60 -76
  70. package/lib/queryBuilder/join/utils.js +10 -16
  71. package/lib/queryBuilder/operations/DelegateOperation.js +93 -133
  72. package/lib/queryBuilder/operations/DeleteOperation.js +33 -37
  73. package/lib/queryBuilder/operations/FindByIdOperation.js +20 -28
  74. package/lib/queryBuilder/operations/FindByIdsOperation.js +17 -23
  75. package/lib/queryBuilder/operations/FindOperation.js +114 -131
  76. package/lib/queryBuilder/operations/FirstOperation.js +14 -19
  77. package/lib/queryBuilder/operations/FromOperation.js +69 -88
  78. package/lib/queryBuilder/operations/InsertAndFetchOperation.js +28 -39
  79. package/lib/queryBuilder/operations/InsertGraphAndFetchOperation.js +25 -35
  80. package/lib/queryBuilder/operations/InsertGraphOperation.js +77 -98
  81. package/lib/queryBuilder/operations/InsertOperation.js +132 -165
  82. package/lib/queryBuilder/operations/InstanceDeleteOperation.js +27 -36
  83. package/lib/queryBuilder/operations/InstanceFindOperation.js +9 -13
  84. package/lib/queryBuilder/operations/InstanceInsertOperation.js +13 -17
  85. package/lib/queryBuilder/operations/InstanceUpdateOperation.js +32 -46
  86. package/lib/queryBuilder/operations/JoinRelatedOperation.js +66 -86
  87. package/lib/queryBuilder/operations/KnexOperation.js +4 -7
  88. package/lib/queryBuilder/operations/MergeOperation.js +32 -45
  89. package/lib/queryBuilder/operations/ObjectionToKnexConvertingOperation.js +131 -150
  90. package/lib/queryBuilder/operations/OnBuildKnexOperation.js +17 -23
  91. package/lib/queryBuilder/operations/OnBuildOperation.js +17 -23
  92. package/lib/queryBuilder/operations/OnErrorOperation.js +17 -23
  93. package/lib/queryBuilder/operations/QueryBuilderOperation.js +231 -270
  94. package/lib/queryBuilder/operations/RangeOperation.js +30 -40
  95. package/lib/queryBuilder/operations/RelateOperation.js +14 -21
  96. package/lib/queryBuilder/operations/ReturningOperation.js +12 -18
  97. package/lib/queryBuilder/operations/RunAfterOperation.js +17 -23
  98. package/lib/queryBuilder/operations/RunBeforeOperation.js +17 -23
  99. package/lib/queryBuilder/operations/UnrelateOperation.js +12 -17
  100. package/lib/queryBuilder/operations/UpdateAndFetchOperation.js +48 -65
  101. package/lib/queryBuilder/operations/UpdateOperation.js +104 -129
  102. package/lib/queryBuilder/operations/UpsertGraphAndFetchOperation.js +25 -35
  103. package/lib/queryBuilder/operations/UpsertGraphOperation.js +36 -55
  104. package/lib/queryBuilder/operations/WhereCompositeOperation.js +30 -39
  105. package/lib/queryBuilder/operations/WhereInOperation.js +34 -36
  106. package/lib/queryBuilder/operations/eager/EagerOperation.js +37 -52
  107. package/lib/queryBuilder/operations/eager/JoinEagerOperation.js +34 -44
  108. package/lib/queryBuilder/operations/eager/NaiveEagerOperation.js +4 -7
  109. package/lib/queryBuilder/operations/eager/WhereInEagerOperation.js +193 -251
  110. package/lib/queryBuilder/operations/jsonApi/WhereJsonHasOperation.js +18 -25
  111. package/lib/queryBuilder/operations/jsonApi/WhereJsonNotObjectOperation.js +25 -41
  112. package/lib/queryBuilder/operations/jsonApi/WhereJsonOperation.js +19 -20
  113. package/lib/queryBuilder/operations/jsonApi/WhereJsonOverlapsOperation.js +23 -21
  114. package/lib/queryBuilder/operations/jsonApi/mysqlJsonApi.js +106 -118
  115. package/lib/queryBuilder/operations/jsonApi/postgresJsonApi.js +79 -108
  116. package/lib/queryBuilder/operations/select/SelectOperation.js +37 -53
  117. package/lib/queryBuilder/operations/select/Selection.js +94 -105
  118. package/lib/queryBuilder/operations/whereInComposite/WhereInCompositeMsSqlOperation.js +68 -101
  119. package/lib/queryBuilder/operations/whereInComposite/WhereInCompositeOperation.js +65 -75
  120. package/lib/queryBuilder/operations/whereInComposite/WhereInCompositeSqliteOperation.js +75 -84
  121. package/lib/queryBuilder/parsers/jsonFieldExpressionParser.js +760 -859
  122. package/lib/queryBuilder/parsers/relationExpressionParser.js +840 -952
  123. package/lib/queryBuilder/transformations/CompositeQueryTransformation.js +10 -15
  124. package/lib/queryBuilder/transformations/QueryTransformation.js +4 -6
  125. package/lib/queryBuilder/transformations/WrapMysqlModifySubqueryTransformation.js +35 -49
  126. package/lib/queryBuilder/transformations/index.js +3 -9
  127. package/lib/queryBuilder/whereScopes.js +158 -186
  128. package/lib/relations/Relation.js +293 -375
  129. package/lib/relations/RelationDeleteOperation.js +24 -28
  130. package/lib/relations/RelationFindOperation.js +108 -138
  131. package/lib/relations/RelationInsertOperation.js +24 -32
  132. package/lib/relations/RelationOwner.js +175 -209
  133. package/lib/relations/RelationProperty.js +186 -223
  134. package/lib/relations/RelationUpdateOperation.js +23 -29
  135. package/lib/relations/belongsToOne/BelongsToOneDeleteOperation.js +16 -21
  136. package/lib/relations/belongsToOne/BelongsToOneInsertOperation.js +30 -41
  137. package/lib/relations/belongsToOne/BelongsToOneRelateOperation.js +36 -47
  138. package/lib/relations/belongsToOne/BelongsToOneRelation.js +42 -50
  139. package/lib/relations/belongsToOne/BelongsToOneUnrelateOperation.js +43 -58
  140. package/lib/relations/hasMany/HasManyInsertOperation.js +40 -56
  141. package/lib/relations/hasMany/HasManyRelateOperation.js +45 -61
  142. package/lib/relations/hasMany/HasManyRelation.js +38 -46
  143. package/lib/relations/hasMany/HasManyUnrelateOperation.js +25 -32
  144. package/lib/relations/hasOne/HasOneRelation.js +9 -12
  145. package/lib/relations/hasOneThrough/HasOneThroughRelation.js +9 -12
  146. package/lib/relations/manyToMany/ManyToManyModifyMixin.js +73 -95
  147. package/lib/relations/manyToMany/ManyToManyRelation.js +374 -473
  148. package/lib/relations/manyToMany/ManyToManySqliteModifyMixin.js +23 -30
  149. package/lib/relations/manyToMany/delete/ManyToManyDeleteOperation.js +8 -10
  150. package/lib/relations/manyToMany/delete/ManyToManyDeleteOperationBase.js +20 -25
  151. package/lib/relations/manyToMany/delete/ManyToManyDeleteSqliteOperation.js +8 -12
  152. package/lib/relations/manyToMany/find/ManyToManyFindOperation.js +77 -100
  153. package/lib/relations/manyToMany/insert/ManyToManyInsertOperation.js +37 -49
  154. package/lib/relations/manyToMany/relate/ManyToManyRelateOperation.js +58 -74
  155. package/lib/relations/manyToMany/unrelate/ManyToManyUnrelateOperation.js +10 -13
  156. package/lib/relations/manyToMany/unrelate/ManyToManyUnrelateOperationBase.js +26 -33
  157. package/lib/relations/manyToMany/unrelate/ManyToManyUnrelateSqliteOperation.js +10 -15
  158. package/lib/relations/manyToMany/update/ManyToManyUpdateOperation.js +8 -10
  159. package/lib/relations/manyToMany/update/ManyToManyUpdateOperationBase.js +61 -78
  160. package/lib/relations/manyToMany/update/ManyToManyUpdateSqliteOperation.js +8 -12
  161. package/lib/transaction.js +53 -83
  162. package/lib/utils/assert.js +15 -21
  163. package/lib/utils/buildUtils.js +17 -19
  164. package/lib/utils/classUtils.js +7 -11
  165. package/lib/utils/cloneDeep.js +365 -0
  166. package/lib/utils/createModifier.js +36 -41
  167. package/lib/utils/deprecate.js +8 -12
  168. package/lib/utils/identifierMapping.js +153 -192
  169. package/lib/utils/internalPropUtils.js +4 -8
  170. package/lib/utils/knexUtils.js +61 -56
  171. package/lib/utils/mixin.js +16 -23
  172. package/lib/utils/mysqlJsonPath.js +55 -40
  173. package/lib/utils/normalizeIds.js +110 -127
  174. package/lib/utils/objectUtils.js +236 -338
  175. package/lib/utils/parseFieldExpression.js +66 -44
  176. package/lib/utils/postgresJsonPath.js +48 -62
  177. package/lib/utils/promiseUtils/after.js +10 -13
  178. package/lib/utils/promiseUtils/afterReturn.js +10 -13
  179. package/lib/utils/promiseUtils/index.js +15 -17
  180. package/lib/utils/promiseUtils/isPromise.js +6 -9
  181. package/lib/utils/promiseUtils/map.js +75 -89
  182. package/lib/utils/promiseUtils/mapAfterAllReturn.js +17 -23
  183. package/lib/utils/promiseUtils/try.js +15 -18
  184. package/lib/utils/resolveModel.js +91 -94
  185. package/lib/utils/tmpColumnUtils.js +4 -13
  186. package/package.json +50 -23
  187. package/typings/objection/index.d.mts +362 -0
  188. package/typings/objection/index.d.ts +36 -9
  189. package/lib/.eslintrc.json +0 -8
  190. package/lib/queryBuilder/parsers/jsonFieldExpressionParser.pegjs +0 -97
  191. package/lib/queryBuilder/parsers/relationExpressionParser.pegjs +0 -141
  192. package/lib/utils/clone.js +0 -2329
@@ -1,66 +1,47 @@
1
1
  'use strict';
2
-
3
2
  const { QueryBuilderOperation } = require('./QueryBuilderOperation');
4
3
  const { GraphUpsert } = require('../graph/GraphUpsert');
5
4
  const { RelationFindOperation } = require('../../relations/RelationFindOperation');
6
-
7
5
  class UpsertGraphOperation extends QueryBuilderOperation {
8
- constructor(name, opt) {
9
- super(
10
- name,
11
- Object.assign({}, opt, {
12
- upsertOptions: {},
13
- }),
14
- );
15
-
16
- this.upsertOptions = opt.upsertOptions || {};
17
- this.upsert = null;
18
- }
19
-
20
- get models() {
21
- return this.upsert.objects;
22
- }
23
-
24
- get isArray() {
25
- return this.upsert.isArray;
26
- }
27
-
28
- onAdd(builder, args) {
29
- const [objects] = args;
30
-
31
- this.upsert = new GraphUpsert({
32
- objects,
33
- rootModelClass: builder.modelClass(),
34
- upsertOptions: this.upsertOptions,
35
- });
36
-
37
- // Never execute this builder.
38
- builder.resolve([]);
39
-
40
- return true;
41
- }
42
-
43
- onAfter1(builder) {
44
- if (hasOtherSqlModifyingQueryBuilderCalls(builder)) {
45
- throw new Error(
46
- 'upsertGraph query should contain no other query builder calls like `findById`, `where` or `$relatedQuery` that would affect the SQL. They have no effect.',
47
- );
6
+ constructor(name, opt) {
7
+ super(name, Object.assign({}, opt, {
8
+ upsertOptions: {},
9
+ }));
10
+ this.upsertOptions = opt.upsertOptions || {};
11
+ this.upsert = null;
12
+ }
13
+ get models() {
14
+ return this.upsert.objects;
15
+ }
16
+ get isArray() {
17
+ return this.upsert.isArray;
18
+ }
19
+ onAdd(builder, args) {
20
+ const [objects] = args;
21
+ this.upsert = new GraphUpsert({
22
+ objects,
23
+ rootModelClass: builder.modelClass(),
24
+ upsertOptions: this.upsertOptions,
25
+ });
26
+ // Never execute this builder.
27
+ builder.resolve([]);
28
+ return true;
29
+ }
30
+ onAfter1(builder) {
31
+ if (hasOtherSqlModifyingQueryBuilderCalls(builder)) {
32
+ throw new Error('upsertGraph query should contain no other query builder calls like `findById`, `where` or `$relatedQuery` that would affect the SQL. They have no effect.');
33
+ }
34
+ return this.upsert.run(builder);
35
+ }
36
+ clone() {
37
+ const clone = super.clone();
38
+ clone.upsert = this.upsert;
39
+ return clone;
48
40
  }
49
-
50
- return this.upsert.run(builder);
51
- }
52
-
53
- clone() {
54
- const clone = super.clone();
55
- clone.upsert = this.upsert;
56
- return clone;
57
- }
58
41
  }
59
-
60
42
  function hasOtherSqlModifyingQueryBuilderCalls(builder) {
61
- return builder.has(/where/) || builder.has(RelationFindOperation);
43
+ return builder.has(/where/) || builder.has(RelationFindOperation);
62
44
  }
63
-
64
45
  module.exports = {
65
- UpsertGraphOperation,
46
+ UpsertGraphOperation,
66
47
  };
@@ -1,57 +1,48 @@
1
1
  'use strict';
2
-
3
2
  const { ObjectionToKnexConvertingOperation } = require('./ObjectionToKnexConvertingOperation');
4
3
  const { asSingle } = require('../../utils/objectUtils');
5
-
6
4
  class WhereCompositeOperation extends ObjectionToKnexConvertingOperation {
7
- onBuildKnex(knexBuilder, builder) {
8
- const args = this.getKnexArgs(builder);
9
-
10
- if (args.length === 2) {
11
- // Convert whereComposite('foo', 1) into whereComposite('foo', '=', 1)
12
- args.splice(1, 0, '=');
13
- } else if (args.length !== 3) {
14
- throw new Error(`invalid number of arguments ${args.length}`);
5
+ onBuildKnex(knexBuilder, builder) {
6
+ const args = this.getKnexArgs(builder);
7
+ if (args.length === 2) {
8
+ // Convert whereComposite('foo', 1) into whereComposite('foo', '=', 1)
9
+ args.splice(1, 0, '=');
10
+ }
11
+ else if (args.length !== 3) {
12
+ throw new Error(`invalid number of arguments ${args.length}`);
13
+ }
14
+ return knexBuilder.where(...buildWhereArgs(...args));
15
15
  }
16
-
17
- return knexBuilder.where(...buildWhereArgs(...args));
18
- }
19
16
  }
20
-
21
17
  function buildWhereArgs(cols, op, values) {
22
- if (isNormalWhere(cols, values)) {
23
- return buildNormalWhereArgs(cols, op, values);
24
- } else if (isCompositeWhere(cols, values)) {
25
- return buildCompositeWhereArgs(cols, op, values);
26
- } else {
27
- throw new Error(`both cols and values must have same dimensions`);
28
- }
18
+ if (isNormalWhere(cols, values)) {
19
+ return buildNormalWhereArgs(cols, op, values);
20
+ }
21
+ else if (isCompositeWhere(cols, values)) {
22
+ return buildCompositeWhereArgs(cols, op, values);
23
+ }
24
+ else {
25
+ throw new Error(`both cols and values must have same dimensions`);
26
+ }
29
27
  }
30
-
31
28
  function isNormalWhere(cols, values) {
32
- return (
33
- (!Array.isArray(cols) || cols.length === 1) && (!Array.isArray(values) || values.length === 1)
34
- );
29
+ return ((!Array.isArray(cols) || cols.length === 1) && (!Array.isArray(values) || values.length === 1));
35
30
  }
36
-
37
31
  function buildNormalWhereArgs(cols, op, values) {
38
- return [asSingle(cols), op, asSingle(values)];
32
+ return [asSingle(cols), op, asSingle(values)];
39
33
  }
40
-
41
34
  function isCompositeWhere(cols, values) {
42
- return Array.isArray(cols) && Array.isArray(values) && cols.length === values.length;
35
+ return Array.isArray(cols) && Array.isArray(values) && cols.length === values.length;
43
36
  }
44
-
45
37
  function buildCompositeWhereArgs(cols, op, values) {
46
- return [
47
- (builder) => {
48
- for (let i = 0, l = cols.length; i < l; ++i) {
49
- builder.where(cols[i], op, values[i]);
50
- }
51
- },
52
- ];
38
+ return [
39
+ (builder) => {
40
+ for (let i = 0, l = cols.length; i < l; ++i) {
41
+ builder.where(cols[i], op, values[i]);
42
+ }
43
+ },
44
+ ];
53
45
  }
54
-
55
46
  module.exports = {
56
- WhereCompositeOperation,
47
+ WhereCompositeOperation,
57
48
  };
@@ -1,48 +1,46 @@
1
1
  'use strict';
2
-
3
2
  const { ObjectionToKnexConvertingOperation } = require('./ObjectionToKnexConvertingOperation');
4
3
  const { isKnexRaw } = require('../../utils/knexUtils');
5
-
6
- // `whereIn`, `whereNotIn`, `onIn` etc. knex compiles the values before the column,
7
- // so the bindings of a raw column (like `ref('data:a').castInt()` on MySQL or
8
- // `fn.lower(ref('a'))`) end up after the values and the query uses the wrong
9
- // bindings. In that case the condition is built as raw sql with the bindings in
10
- // the right order.
4
+ // `onIn`, `onNotIn` etc. of join callbacks. knex compiles the values before the
5
+ // column, so the bindings of a raw column (like `ref('data:a').castInt()` on
6
+ // MySQL or `fn.lower(ref('a'))`) end up after the values and the query uses the
7
+ // wrong bindings. In that case the condition is built as raw sql with the
8
+ // bindings in the right order. knex 3.2 fixed this for `whereIn` but not for
9
+ // `onIn`.
11
10
  class WhereInOperation extends ObjectionToKnexConvertingOperation {
12
- onBuildKnex(knexBuilder, builder) {
13
- const args = this.getKnexArgs(builder);
14
- const [column, values] = args;
15
-
16
- if (args.length !== 2 || !hasBindings(column) || isEmptyArray(values)) {
17
- return knexBuilder[this.name].apply(knexBuilder, args);
11
+ onBuildKnex(knexBuilder, builder) {
12
+ const args = this.getKnexArgs(builder);
13
+ const [column, values] = args;
14
+ if (args.length !== 2 || !hasBindings(column) || isEmptyArray(values)) {
15
+ return knexBuilder[this.name].apply(knexBuilder, args);
16
+ }
17
+ const knex = builder.knex();
18
+ const not = this.opt.not ? 'not ' : '';
19
+ let sql;
20
+ let bindings;
21
+ if (Array.isArray(values)) {
22
+ sql = `? ${not}in (${values.map(() => '?').join(', ')})`;
23
+ bindings = [column, ...values];
24
+ }
25
+ else if (isKnexRaw(values)) {
26
+ // knex doesn't wrap raw bindings in parentheses.
27
+ sql = `? ${not}in (?)`;
28
+ bindings = [column, values];
29
+ }
30
+ else {
31
+ // A subquery, which knex wraps in parentheses.
32
+ sql = `? ${not}in ?`;
33
+ bindings = [column, values];
34
+ }
35
+ return knexBuilder[this.opt.rawMethod](knex.raw(sql, bindings));
18
36
  }
19
-
20
- const knex = builder.knex();
21
- const not = this.opt.not ? 'not ' : '';
22
- let sql;
23
- let bindings;
24
-
25
- if (Array.isArray(values)) {
26
- sql = `? ${not}in (${values.map(() => '?').join(', ')})`;
27
- bindings = [column, ...values];
28
- } else {
29
- // A subquery.
30
- sql = `? ${not}in ?`;
31
- bindings = [column, values];
32
- }
33
-
34
- return knexBuilder[this.opt.rawMethod](knex.raw(sql, bindings));
35
- }
36
37
  }
37
-
38
38
  function hasBindings(column) {
39
- return isKnexRaw(column) && Array.isArray(column.bindings) && column.bindings.length > 0;
39
+ return isKnexRaw(column) && Array.isArray(column.bindings) && column.bindings.length > 0;
40
40
  }
41
-
42
41
  function isEmptyArray(values) {
43
- return Array.isArray(values) && values.length === 0;
42
+ return Array.isArray(values) && values.length === 0;
44
43
  }
45
-
46
44
  module.exports = {
47
- WhereInOperation,
45
+ WhereInOperation,
48
46
  };
@@ -1,61 +1,46 @@
1
1
  'use strict';
2
-
3
2
  const { QueryBuilderOperation } = require('../QueryBuilderOperation');
4
3
  const { RelationExpression } = require('../../RelationExpression');
5
-
6
4
  class EagerOperation extends QueryBuilderOperation {
7
- constructor(name, opt) {
8
- super(name, opt);
9
-
10
- this.expression = RelationExpression.create();
11
- this.modifiersAtPath = [];
12
- this.graphOptions = this.opt.defaultGraphOptions;
13
- }
14
-
15
- buildFinalExpression() {
16
- const expression = this.expression.clone();
17
-
18
- this.modifiersAtPath.forEach((modifier, i) => {
19
- const modifierName = getModifierName(i);
20
-
21
- expression.expressionsAtPath(modifier.path).forEach((expr) => {
22
- expr.node.$modify.push(modifierName);
23
- });
24
- });
25
-
26
- return expression;
27
- }
28
-
29
- buildFinalModifiers(builder) {
30
- // `modifiers()` returns a clone so we can modify it.
31
- const modifiers = builder.modifiers();
32
-
33
- this.modifiersAtPath.forEach((modifier, i) => {
34
- const modifierName = getModifierName(i);
35
-
36
- modifiers[modifierName] = modifier.modifier;
37
- });
38
-
39
- return modifiers;
40
- }
41
-
42
- cloneFrom(eagerOp) {
43
- this.expression = eagerOp.expression.clone();
44
- this.modifiersAtPath = eagerOp.modifiersAtPath.slice();
45
- this.graphOptions = Object.assign({}, eagerOp.graphOptions);
46
- }
47
-
48
- clone() {
49
- const clone = super.clone();
50
- clone.cloneFrom(this);
51
- return clone;
52
- }
5
+ constructor(name, opt) {
6
+ super(name, opt);
7
+ this.expression = RelationExpression.create();
8
+ this.modifiersAtPath = [];
9
+ this.graphOptions = this.opt.defaultGraphOptions;
10
+ }
11
+ buildFinalExpression() {
12
+ const expression = this.expression.clone();
13
+ this.modifiersAtPath.forEach((modifier, i) => {
14
+ const modifierName = getModifierName(i);
15
+ expression.expressionsAtPath(modifier.path).forEach((expr) => {
16
+ expr.node.$modify.push(modifierName);
17
+ });
18
+ });
19
+ return expression;
20
+ }
21
+ buildFinalModifiers(builder) {
22
+ // `modifiers()` returns a clone so we can modify it.
23
+ const modifiers = builder.modifiers();
24
+ this.modifiersAtPath.forEach((modifier, i) => {
25
+ const modifierName = getModifierName(i);
26
+ modifiers[modifierName] = modifier.modifier;
27
+ });
28
+ return modifiers;
29
+ }
30
+ cloneFrom(eagerOp) {
31
+ this.expression = eagerOp.expression.clone();
32
+ this.modifiersAtPath = eagerOp.modifiersAtPath.slice();
33
+ this.graphOptions = Object.assign({}, eagerOp.graphOptions);
34
+ }
35
+ clone() {
36
+ const clone = super.clone();
37
+ clone.cloneFrom(this);
38
+ return clone;
39
+ }
53
40
  }
54
-
55
41
  function getModifierName(index) {
56
- return `_f${index}_`;
42
+ return `_f${index}_`;
57
43
  }
58
-
59
44
  module.exports = {
60
- EagerOperation,
45
+ EagerOperation,
61
46
  };
@@ -1,51 +1,41 @@
1
1
  'use strict';
2
-
3
2
  const { EagerOperation } = require('./EagerOperation');
4
3
  const { RelationJoiner } = require('../../join/RelationJoiner');
5
-
6
4
  class JoinEagerOperation extends EagerOperation {
7
- constructor(name, opt) {
8
- super(name, opt);
9
- this.joiner = null;
10
- }
11
-
12
- onAdd(builder) {
13
- builder.findOptions({ callAfterFindDeeply: true });
14
-
15
- this.joiner = new RelationJoiner({
16
- modelClass: builder.modelClass(),
17
- });
18
-
19
- return true;
20
- }
21
-
22
- onBefore3(builder) {
23
- return this.joiner
24
- .setExpression(this.buildFinalExpression())
25
- .setModifiers(this.buildFinalModifiers(builder))
26
- .setOptions(this.graphOptions)
27
- .fetchColumnInfo(builder);
28
- }
29
-
30
- onBuild(builder) {
31
- this.joiner
32
- .setExpression(this.buildFinalExpression())
33
- .setModifiers(this.buildFinalModifiers(builder))
34
- .setOptions(this.graphOptions)
35
- .build(builder);
36
- }
37
-
38
- onRawResult(builder, rows) {
39
- return this.joiner.parseResult(builder, rows);
40
- }
41
-
42
- clone() {
43
- const clone = super.clone();
44
- clone.joiner = this.joiner;
45
- return clone;
46
- }
5
+ constructor(name, opt) {
6
+ super(name, opt);
7
+ this.joiner = null;
8
+ }
9
+ onAdd(builder) {
10
+ builder.findOptions({ callAfterFindDeeply: true });
11
+ this.joiner = new RelationJoiner({
12
+ modelClass: builder.modelClass(),
13
+ });
14
+ return true;
15
+ }
16
+ onBefore3(builder) {
17
+ return this.joiner
18
+ .setExpression(this.buildFinalExpression())
19
+ .setModifiers(this.buildFinalModifiers(builder))
20
+ .setOptions(this.graphOptions)
21
+ .fetchColumnInfo(builder);
22
+ }
23
+ onBuild(builder) {
24
+ this.joiner
25
+ .setExpression(this.buildFinalExpression())
26
+ .setModifiers(this.buildFinalModifiers(builder))
27
+ .setOptions(this.graphOptions)
28
+ .build(builder);
29
+ }
30
+ onRawResult(builder, rows) {
31
+ return this.joiner.parseResult(builder, rows);
32
+ }
33
+ clone() {
34
+ const clone = super.clone();
35
+ clone.joiner = this.joiner;
36
+ return clone;
37
+ }
47
38
  }
48
-
49
39
  module.exports = {
50
- JoinEagerOperation,
40
+ JoinEagerOperation,
51
41
  };
@@ -1,13 +1,10 @@
1
1
  'use strict';
2
-
3
2
  const { WhereInEagerOperation } = require('./WhereInEagerOperation');
4
-
5
3
  class NaiveEagerOperation extends WhereInEagerOperation {
6
- batchSize() {
7
- return 1;
8
- }
4
+ batchSize() {
5
+ return 1;
6
+ }
9
7
  }
10
-
11
8
  module.exports = {
12
- NaiveEagerOperation,
9
+ NaiveEagerOperation,
13
10
  };