orange-orm 5.0.0-beta.4 → 5.0.0-beta.5

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 CHANGED
@@ -669,7 +669,7 @@ async function getRows() {
669
669
  });
670
670
  }
671
671
  ```
672
- You can also use the alternative syntax for the `where` filter. This way, the filter can be constructed independently from the fetching strategy and passed in via the `where` clause.
672
+ You can also build the `where` filter separately and pass it in via the `where` clause. This keeps the filter independent of the fetching strategy and easier to reuse.
673
673
  ```javascript
674
674
  async function getRows() {
675
675
  const filter = db.order.lines.any(line => line.product.contains('i'))
@@ -692,7 +692,7 @@ const db = map.sqlite('demo.db');
692
692
  getRows();
693
693
 
694
694
  async function getRows() {
695
- const order = await db.order.getOne(undefined /* optional filter */, {
695
+ const order = await db.order.getOne({
696
696
  where: x => x.customer(customer => customer.isActive.eq(true)
697
697
  .and(customer.startsWith('Harr'))),
698
698
  customer: true,
@@ -701,15 +701,16 @@ async function getRows() {
701
701
  });
702
702
  }
703
703
  ```
704
- You can use also the alternative syntax for the `where-filter`. This way, the filter can be constructed independently from the fetching strategy.
705
- It is also possible to combine `where-filter` with the independent filter when using the `getOne` method.
704
+ You can also build the `where` filter independently and reuse it.
705
+ With `getOne`, you can combine the positional `where` filter with the `where` option to compose filters.
706
706
  ```javascript
707
707
  async function getRows() {
708
708
  const filter = db.order.customer(customer => customer.isActive.eq(true)
709
709
  .and(customer.startsWith('Harr')));
710
- //equivalent, but creates slighly different sql:
710
+ // equivalent, but creates slightly different SQL:
711
711
  // const filter = db.order.customer.isActive.eq(true).and(db.order.customer.startsWith('Harr'));
712
- const order = await db.order.getOne(filter, {
712
+ const order = await db.order.getOne({
713
+ where: filter,
713
714
  customer: true,
714
715
  deliveryAddress: true,
715
716
  lines: true
@@ -1171,6 +1172,7 @@ express().disable('x-powered-by')
1171
1172
  ```
1172
1173
 
1173
1174
  <sub>📄 browser.ts</sub>
1175
+
1174
1176
  ```ts
1175
1177
  import map from './map';
1176
1178
 
@@ -1179,7 +1181,7 @@ const db = map.http('http://localhost:3000/orange');
1179
1181
  updateRows();
1180
1182
 
1181
1183
  async function updateRows() {
1182
- const order = await db.order.getOne(undefined, {
1184
+ const order = await db.order.getOne({
1183
1185
  where: x => x.lines.any(line => line.product.startsWith('Magic wand'))
1184
1186
  .and(x.customer.name.startsWith('Harry'),
1185
1187
  lines: true
@@ -1264,7 +1266,7 @@ async function updateRows() {
1264
1266
  }
1265
1267
  );
1266
1268
 
1267
- const order = await db.order.getOne(undefined, {
1269
+ const order = await db.order.getOne({
1268
1270
  where: x => x.lines.any(line => line.product.startsWith('Magic wand'))
1269
1271
  .and(db.order.customer.name.startsWith('Harry')),
1270
1272
  lines: true
@@ -1076,6 +1076,10 @@ function requireUtils () {
1076
1076
  };
1077
1077
 
1078
1078
  c.and = function(context, other) {
1079
+ if (other === undefined) {
1080
+ other = context;
1081
+ context = null;
1082
+ }
1079
1083
  other = negotiateRawSqlFilter(context, other);
1080
1084
  var nextFilter = negotiateNextAndFilter(filter, other);
1081
1085
  var next = newBoolean(nextFilter);
@@ -1086,6 +1090,10 @@ function requireUtils () {
1086
1090
  };
1087
1091
 
1088
1092
  c.or = function(context, other) {
1093
+ if (other === undefined) {
1094
+ other = context;
1095
+ context = null;
1096
+ }
1089
1097
  other = negotiateRawSqlFilter(context, other);
1090
1098
  var nextFilter = negotiateNextOrFilter(filter, other);
1091
1099
  var next = newBoolean(nextFilter);
@@ -1201,6 +1209,10 @@ function requireEmptyFilter () {
1201
1209
  emptyFilter.parameters = parameterized.parameters;
1202
1210
 
1203
1211
  emptyFilter.and = function(context, other) {
1212
+ if (other === undefined) {
1213
+ other = context;
1214
+ context = null;
1215
+ }
1204
1216
  other = negotiateRawSqlFilter(context, other);
1205
1217
  for (var i = 2; i < arguments.length; i++) {
1206
1218
  other = other.and(context, arguments[i]);
@@ -1209,6 +1221,10 @@ function requireEmptyFilter () {
1209
1221
  };
1210
1222
 
1211
1223
  emptyFilter.or = function(context, other) {
1224
+ if (other === undefined) {
1225
+ other = context;
1226
+ context = null;
1227
+ }
1212
1228
  other = negotiateRawSqlFilter(context, other);
1213
1229
  for (var i = 2; i < arguments.length; i++) {
1214
1230
  other = other.or(context, arguments[i]);
@@ -1217,6 +1233,10 @@ function requireEmptyFilter () {
1217
1233
  };
1218
1234
 
1219
1235
  emptyFilter.not = function(context, other) {
1236
+ if (other === undefined) {
1237
+ other = context;
1238
+ context = null;
1239
+ }
1220
1240
  other = negotiateRawSqlFilter(context, other).not(context);
1221
1241
  for (var i = 2; i < arguments.length; i++) {
1222
1242
  other = other.and(context, arguments[i]);
@@ -4463,7 +4483,7 @@ function requireNewColumn () {
4463
4483
  alias = extractAlias(alias);
4464
4484
  from = c.greaterThanOrEqual(context, from, alias);
4465
4485
  to = c.lessThanOrEqual(context, to, alias);
4466
- return from.and(to);
4486
+ return from.and(context, to);
4467
4487
  };
4468
4488
 
4469
4489
  c.in = function(context, arg, alias) {
@@ -9024,6 +9044,7 @@ function requireGetRelatives$1 () {
9024
9044
 
9025
9045
  function getRelatives(context, parent, relation) {
9026
9046
  var queryContext = parent.queryContext;
9047
+ var ctx = context === undefined ? null : context;
9027
9048
  let strategy = queryContext && queryContext.strategy[relation.leftAlias];
9028
9049
  var filter = emptyFilter;
9029
9050
  if (relation.columns.length === 1)
@@ -9044,7 +9065,7 @@ function requireGetRelatives$1 () {
9044
9065
  }
9045
9066
 
9046
9067
  if (ids.length > 0)
9047
- filter = relation.childTable._primaryColumns[0].in(context, ids);
9068
+ filter = relation.childTable._primaryColumns[0].in(ctx, ids);
9048
9069
  }
9049
9070
 
9050
9071
  function createCompositeFilter() {
@@ -9052,7 +9073,7 @@ function requireGetRelatives$1 () {
9052
9073
  for (var i = 0; i < queryContext.rows.length; i++) {
9053
9074
  keyFilter = rowToPrimaryKeyFilter(context, queryContext.rows[i], relation);
9054
9075
  if (keyFilter)
9055
- filter = filter.or(context, keyFilter);
9076
+ filter = filter.or(ctx, keyFilter);
9056
9077
  }
9057
9078
  }
9058
9079
 
package/dist/index.mjs CHANGED
@@ -1077,6 +1077,10 @@ function requireUtils () {
1077
1077
  };
1078
1078
 
1079
1079
  c.and = function(context, other) {
1080
+ if (other === undefined) {
1081
+ other = context;
1082
+ context = null;
1083
+ }
1080
1084
  other = negotiateRawSqlFilter(context, other);
1081
1085
  var nextFilter = negotiateNextAndFilter(filter, other);
1082
1086
  var next = newBoolean(nextFilter);
@@ -1087,6 +1091,10 @@ function requireUtils () {
1087
1091
  };
1088
1092
 
1089
1093
  c.or = function(context, other) {
1094
+ if (other === undefined) {
1095
+ other = context;
1096
+ context = null;
1097
+ }
1090
1098
  other = negotiateRawSqlFilter(context, other);
1091
1099
  var nextFilter = negotiateNextOrFilter(filter, other);
1092
1100
  var next = newBoolean(nextFilter);
@@ -1202,6 +1210,10 @@ function requireEmptyFilter () {
1202
1210
  emptyFilter.parameters = parameterized.parameters;
1203
1211
 
1204
1212
  emptyFilter.and = function(context, other) {
1213
+ if (other === undefined) {
1214
+ other = context;
1215
+ context = null;
1216
+ }
1205
1217
  other = negotiateRawSqlFilter(context, other);
1206
1218
  for (var i = 2; i < arguments.length; i++) {
1207
1219
  other = other.and(context, arguments[i]);
@@ -1210,6 +1222,10 @@ function requireEmptyFilter () {
1210
1222
  };
1211
1223
 
1212
1224
  emptyFilter.or = function(context, other) {
1225
+ if (other === undefined) {
1226
+ other = context;
1227
+ context = null;
1228
+ }
1213
1229
  other = negotiateRawSqlFilter(context, other);
1214
1230
  for (var i = 2; i < arguments.length; i++) {
1215
1231
  other = other.or(context, arguments[i]);
@@ -1218,6 +1234,10 @@ function requireEmptyFilter () {
1218
1234
  };
1219
1235
 
1220
1236
  emptyFilter.not = function(context, other) {
1237
+ if (other === undefined) {
1238
+ other = context;
1239
+ context = null;
1240
+ }
1221
1241
  other = negotiateRawSqlFilter(context, other).not(context);
1222
1242
  for (var i = 2; i < arguments.length; i++) {
1223
1243
  other = other.and(context, arguments[i]);
@@ -4464,7 +4484,7 @@ function requireNewColumn () {
4464
4484
  alias = extractAlias(alias);
4465
4485
  from = c.greaterThanOrEqual(context, from, alias);
4466
4486
  to = c.lessThanOrEqual(context, to, alias);
4467
- return from.and(to);
4487
+ return from.and(context, to);
4468
4488
  };
4469
4489
 
4470
4490
  c.in = function(context, arg, alias) {
@@ -9025,6 +9045,7 @@ function requireGetRelatives$1 () {
9025
9045
 
9026
9046
  function getRelatives(context, parent, relation) {
9027
9047
  var queryContext = parent.queryContext;
9048
+ var ctx = context === undefined ? null : context;
9028
9049
  let strategy = queryContext && queryContext.strategy[relation.leftAlias];
9029
9050
  var filter = emptyFilter;
9030
9051
  if (relation.columns.length === 1)
@@ -9045,7 +9066,7 @@ function requireGetRelatives$1 () {
9045
9066
  }
9046
9067
 
9047
9068
  if (ids.length > 0)
9048
- filter = relation.childTable._primaryColumns[0].in(context, ids);
9069
+ filter = relation.childTable._primaryColumns[0].in(ctx, ids);
9049
9070
  }
9050
9071
 
9051
9072
  function createCompositeFilter() {
@@ -9053,7 +9074,7 @@ function requireGetRelatives$1 () {
9053
9074
  for (var i = 0; i < queryContext.rows.length; i++) {
9054
9075
  keyFilter = rowToPrimaryKeyFilter(context, queryContext.rows[i], relation);
9055
9076
  if (keyFilter)
9056
- filter = filter.or(context, keyFilter);
9077
+ filter = filter.or(ctx, keyFilter);
9057
9078
  }
9058
9079
  }
9059
9080
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "orange-orm",
3
- "version": "5.0.0-beta.4",
3
+ "version": "5.0.0-beta.5",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -8,6 +8,10 @@ emptyFilter.sql = parameterized.sql.bind(parameterized);
8
8
  emptyFilter.parameters = parameterized.parameters;
9
9
 
10
10
  emptyFilter.and = function(context, other) {
11
+ if (other === undefined) {
12
+ other = context;
13
+ context = null;
14
+ }
11
15
  other = negotiateRawSqlFilter(context, other);
12
16
  for (var i = 2; i < arguments.length; i++) {
13
17
  other = other.and(context, arguments[i]);
@@ -16,6 +20,10 @@ emptyFilter.and = function(context, other) {
16
20
  };
17
21
 
18
22
  emptyFilter.or = function(context, other) {
23
+ if (other === undefined) {
24
+ other = context;
25
+ context = null;
26
+ }
19
27
  other = negotiateRawSqlFilter(context, other);
20
28
  for (var i = 2; i < arguments.length; i++) {
21
29
  other = other.or(context, arguments[i]);
@@ -24,6 +32,10 @@ emptyFilter.or = function(context, other) {
24
32
  };
25
33
 
26
34
  emptyFilter.not = function(context, other) {
35
+ if (other === undefined) {
36
+ other = context;
37
+ context = null;
38
+ }
27
39
  other = negotiateRawSqlFilter(context, other).not(context);
28
40
  for (var i = 2; i < arguments.length; i++) {
29
41
  other = other.and(context, arguments[i]);
@@ -55,7 +55,7 @@ module.exports = function(table, name) {
55
55
  alias = extractAlias(alias);
56
56
  from = c.greaterThanOrEqual(context, from, alias);
57
57
  to = c.lessThanOrEqual(context, to, alias);
58
- return from.and(to);
58
+ return from.and(context, to);
59
59
  };
60
60
 
61
61
  c.in = function(context, arg, alias) {
@@ -102,4 +102,4 @@ module.exports = function(table, name) {
102
102
  }
103
103
 
104
104
  return c;
105
- };
105
+ };
@@ -18,6 +18,10 @@ function newBoolean(filter) {
18
18
  };
19
19
 
20
20
  c.and = function(context, other) {
21
+ if (other === undefined) {
22
+ other = context;
23
+ context = null;
24
+ }
21
25
  other = negotiateRawSqlFilter(context, other);
22
26
  var nextFilter = negotiateNextAndFilter(filter, other);
23
27
  var next = newBoolean(nextFilter);
@@ -28,6 +32,10 @@ function newBoolean(filter) {
28
32
  };
29
33
 
30
34
  c.or = function(context, other) {
35
+ if (other === undefined) {
36
+ other = context;
37
+ context = null;
38
+ }
31
39
  other = negotiateRawSqlFilter(context, other);
32
40
  var nextFilter = negotiateNextOrFilter(filter, other);
33
41
  var next = newBoolean(nextFilter);
@@ -4,6 +4,7 @@ var negotiateExpandInverse = require('../negotiateExpandInverse');
4
4
 
5
5
  function getRelatives(context, parent, relation) {
6
6
  var queryContext = parent.queryContext;
7
+ var ctx = context === undefined ? null : context;
7
8
  let strategy = queryContext && queryContext.strategy[relation.leftAlias];
8
9
  var filter = emptyFilter;
9
10
  if (relation.columns.length === 1)
@@ -24,7 +25,7 @@ function getRelatives(context, parent, relation) {
24
25
  }
25
26
 
26
27
  if (ids.length > 0)
27
- filter = relation.childTable._primaryColumns[0].in(context, ids);
28
+ filter = relation.childTable._primaryColumns[0].in(ctx, ids);
28
29
  }
29
30
 
30
31
  function createCompositeFilter() {
@@ -32,7 +33,7 @@ function getRelatives(context, parent, relation) {
32
33
  for (var i = 0; i < queryContext.rows.length; i++) {
33
34
  keyFilter = rowToPrimaryKeyFilter(context, queryContext.rows[i], relation);
34
35
  if (keyFilter)
35
- filter = filter.or(context, keyFilter);
36
+ filter = filter.or(ctx, keyFilter);
36
37
  }
37
38
  }
38
39
 
@@ -61,4 +62,4 @@ function isNullOrUndefined(item) {
61
62
  return item === null || item === undefined;
62
63
  }
63
64
 
64
- module.exports = getRelatives;
65
+ module.exports = getRelatives;