@ruiapp/rapid-core 0.8.18 → 0.8.19

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.
@@ -2,7 +2,7 @@ export type DataAccessPgColumnTypes = "int4" | "int8" | "float4" | "float8" | "d
2
2
  export type RowFilterRelationalOperators = "eq" | "ne" | "lt" | "lte" | "gt" | "gte" | "matches" | "matchesCS" | "contains" | "notContains" | "containsCS" | "notContainsCS" | "startsWith" | "notStartsWith" | "endsWith" | "notEndsWith";
3
3
  export type RowFilterArrayOperators = "arrayContains" | "arrayOverlap";
4
4
  export type RowFilterSetOperators = "in" | "notIn";
5
- export type RowFilterRangeOperators = "between";
5
+ export type RowFilterRangeOperators = "between" | "range";
6
6
  export type RowFilterLogicalOperators = "or" | "and";
7
7
  export type RowFilterUnaryOperators = "null" | "notNull";
8
8
  export type RowFilterExistenceOperators = "exists" | "notExists";
package/dist/index.js CHANGED
@@ -519,7 +519,7 @@ function buildFilterQuery(level, ctx, filter) {
519
519
  else if (operator === "in" || operator === "notIn") {
520
520
  return buildInFilterQuery(ctx, filter);
521
521
  }
522
- else if (operator === "between") {
522
+ else if (operator === "between" || operator === "range") {
523
523
  return buildRangeFilterQuery(ctx, filter);
524
524
  }
525
525
  else if (operator === "matches") {
@@ -607,11 +607,12 @@ function buildInFilterQuery(ctx, filter) {
607
607
  return command;
608
608
  }
609
609
  function buildRangeFilterQuery(ctx, filter) {
610
- let command = ctx.builder.quoteColumn(ctx.model, filter.field, ctx.emitTableAlias);
610
+ let command = "";
611
+ if (filter.value.length != 2) {
612
+ throw new Error(`Filter operator '${filter.operator}' need two values.`);
613
+ }
611
614
  if (filter.operator === "between") {
612
- if (filter.value.length != 2) {
613
- throw new Error(`Filter operator '${filter.operator}' need two values.`);
614
- }
615
+ command += ctx.builder.quoteColumn(ctx.model, filter.field, ctx.emitTableAlias);
615
616
  command += " BETWEEN ";
616
617
  ctx.params.push(filter.value[0]);
617
618
  command += `$${ctx.params.length}`;
@@ -619,6 +620,13 @@ function buildRangeFilterQuery(ctx, filter) {
619
620
  ctx.params.push(filter.value[1]);
620
621
  command += `$${ctx.params.length}`;
621
622
  }
623
+ else if (filter.operator === "range") {
624
+ ctx.params.push(filter.value[0]);
625
+ command += `(${ctx.builder.quoteColumn(ctx.model, filter.field, ctx.emitTableAlias)} >= $${ctx.params.length}`;
626
+ command += " AND ";
627
+ ctx.params.push(filter.value[1]);
628
+ command += `${ctx.builder.quoteColumn(ctx.model, filter.field, ctx.emitTableAlias)} < $${ctx.params.length})`;
629
+ }
622
630
  else {
623
631
  throw new Error(`Filter operator '${filter.operator}' is not supported.`);
624
632
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ruiapp/rapid-core",
3
- "version": "0.8.18",
3
+ "version": "0.8.19",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -34,7 +34,7 @@ export type RowFilterArrayOperators = "arrayContains" | "arrayOverlap";
34
34
 
35
35
  export type RowFilterSetOperators = "in" | "notIn";
36
36
 
37
- export type RowFilterRangeOperators = "between";
37
+ export type RowFilterRangeOperators = "between" | "range";
38
38
 
39
39
  export type RowFilterLogicalOperators = "or" | "and";
40
40
 
@@ -418,7 +418,7 @@ function buildFilterQuery(level: number, ctx: BuildQueryContext, filter: RowFilt
418
418
  return buildUnaryFilterQuery(ctx, filter);
419
419
  } else if (operator === "in" || operator === "notIn") {
420
420
  return buildInFilterQuery(ctx, filter);
421
- } else if (operator === "between") {
421
+ } else if (operator === "between" || operator === "range") {
422
422
  return buildRangeFilterQuery(ctx, filter);
423
423
  } else if (operator === "matches") {
424
424
  return buildMatchesFilterQuery(ctx, filter);
@@ -498,12 +498,14 @@ function buildInFilterQuery(ctx: BuildQueryContext, filter: FindRowSetFilterOpti
498
498
  }
499
499
 
500
500
  function buildRangeFilterQuery(ctx: BuildQueryContext, filter: FindRowRangeFilterOptions) {
501
- let command = ctx.builder.quoteColumn(ctx.model, filter.field, ctx.emitTableAlias);
501
+ let command = "";
502
+
503
+ if (filter.value.length != 2) {
504
+ throw new Error(`Filter operator '${filter.operator}' need two values.`);
505
+ }
502
506
 
503
507
  if (filter.operator === "between") {
504
- if (filter.value.length != 2) {
505
- throw new Error(`Filter operator '${filter.operator}' need two values.`);
506
- }
508
+ command += ctx.builder.quoteColumn(ctx.model, filter.field, ctx.emitTableAlias);
507
509
 
508
510
  command += " BETWEEN ";
509
511
 
@@ -514,6 +516,14 @@ function buildRangeFilterQuery(ctx: BuildQueryContext, filter: FindRowRangeFilte
514
516
 
515
517
  ctx.params.push(filter.value[1]);
516
518
  command += `$${ctx.params.length}`;
519
+ } else if (filter.operator === "range") {
520
+ ctx.params.push(filter.value[0]);
521
+ command += `(${ctx.builder.quoteColumn(ctx.model, filter.field, ctx.emitTableAlias)} >= $${ctx.params.length}`;
522
+
523
+ command += " AND ";
524
+
525
+ ctx.params.push(filter.value[1]);
526
+ command += `${ctx.builder.quoteColumn(ctx.model, filter.field, ctx.emitTableAlias)} < $${ctx.params.length})`;
517
527
  } else {
518
528
  throw new Error(`Filter operator '${filter.operator}' is not supported.`);
519
529
  }