@snowtop/ent 0.1.0-alpha155 → 0.1.0-alpha156

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/core/clause.d.ts CHANGED
@@ -15,6 +15,7 @@ export declare class inClause<T extends Data, K = keyof T> implements Clause<T,
15
15
  private col;
16
16
  private value;
17
17
  private type;
18
+ protected op: string;
18
19
  static getPostgresInClauseValuesThreshold(): number;
19
20
  constructor(col: K, value: any[], type?: string);
20
21
  clause(idx: number): string;
@@ -23,6 +24,9 @@ export declare class inClause<T extends Data, K = keyof T> implements Clause<T,
23
24
  logValues(): any[];
24
25
  instanceKey(): string;
25
26
  }
27
+ export declare class notInClause<T extends Data, K = keyof T> extends inClause<T, K> {
28
+ protected op: string;
29
+ }
26
30
  /**
27
31
  * creates a clause to determine if the given value is contained in the array stored in the column in the db
28
32
  * only works with postgres gin indexes
@@ -89,6 +93,10 @@ export declare function UuidIn<T extends Data, K = keyof T>(col: K, values: ID[]
89
93
  export declare function IntegerIn<T extends Data, K = keyof T>(col: K, values: number[]): Clause<T, K>;
90
94
  export declare function TextIn<T extends Data, K = keyof T>(col: K, values: any[]): Clause<T, K>;
91
95
  export declare function DBTypeIn<T extends Data, K = keyof T>(col: K, values: any[], typ: string): Clause<T, K>;
96
+ export declare function UuidNotIn<T extends Data, K = keyof T>(col: K, values: ID[]): Clause<T, K>;
97
+ export declare function IntegerNotIn<T extends Data, K = keyof T>(col: K, values: number[]): Clause<T, K>;
98
+ export declare function TextNotIn<T extends Data, K = keyof T>(col: K, values: any[]): Clause<T, K>;
99
+ export declare function DBTypeNotIn<T extends Data, K = keyof T>(col: K, values: any[], typ: string): Clause<T, K>;
92
100
  interface TsQuery {
93
101
  language: "english" | "french" | "german" | "simple";
94
102
  value: string;
package/core/clause.js CHANGED
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.getCombinedClause = exports.Modulo = exports.Divide = exports.Multiply = exports.Subtract = exports.Add = exports.PaginationMultipleColsSubQuery = exports.JSONPathValuePredicate = exports.JSONObjectFieldKeyAsText = exports.JSONObjectFieldKeyASJSON = exports.sensitiveValue = exports.TsVectorWebsearchToTsQuery = exports.TsVectorPhraseToTsQuery = exports.TsVectorPlainToTsQuery = exports.TsVectorColTsQuery = exports.WebsearchToTsQuery = exports.PhraseToTsQuery = exports.PlainToTsQuery = exports.TsQuery = exports.DBTypeIn = exports.TextIn = exports.IntegerIn = exports.UuidIn = exports.In = exports.OrOptional = exports.Or = exports.AndOptional = exports.And = exports.LessEq = exports.GreaterEq = exports.Less = exports.Greater = exports.NotEq = exports.Eq = exports.ArrayNotEq = exports.ArrayEq = exports.PostgresArrayNotOverlaps = exports.PostgresArrayOverlaps = exports.PostgresArrayNotContains = exports.PostgresArrayNotContainsValue = exports.PostgresArrayContains = exports.PostgresArrayContainsValue = exports.inClause = void 0;
26
+ exports.getCombinedClause = exports.Modulo = exports.Divide = exports.Multiply = exports.Subtract = exports.Add = exports.PaginationMultipleColsSubQuery = exports.JSONPathValuePredicate = exports.JSONObjectFieldKeyAsText = exports.JSONObjectFieldKeyASJSON = exports.sensitiveValue = exports.TsVectorWebsearchToTsQuery = exports.TsVectorPhraseToTsQuery = exports.TsVectorPlainToTsQuery = exports.TsVectorColTsQuery = exports.WebsearchToTsQuery = exports.PhraseToTsQuery = exports.PlainToTsQuery = exports.TsQuery = exports.DBTypeNotIn = exports.TextNotIn = exports.IntegerNotIn = exports.UuidNotIn = exports.DBTypeIn = exports.TextIn = exports.IntegerIn = exports.UuidIn = exports.In = exports.OrOptional = exports.Or = exports.AndOptional = exports.And = exports.LessEq = exports.GreaterEq = exports.Less = exports.Greater = exports.NotEq = exports.Eq = exports.ArrayNotEq = exports.ArrayEq = exports.PostgresArrayNotOverlaps = exports.PostgresArrayOverlaps = exports.PostgresArrayNotContains = exports.PostgresArrayNotContainsValue = exports.PostgresArrayContains = exports.PostgresArrayContainsValue = exports.notInClause = exports.inClause = void 0;
27
27
  const db_1 = __importStar(require("./db"));
28
28
  function isSensitive(val) {
29
29
  return (val !== null &&
@@ -236,6 +236,7 @@ class inClause {
236
236
  this.col = col;
237
237
  this.value = value;
238
238
  this.type = type;
239
+ this.op = "IN";
239
240
  }
240
241
  clause(idx) {
241
242
  // do a simple = when only one item
@@ -272,7 +273,7 @@ class inClause {
272
273
  if (postgresValuesList) {
273
274
  inValue = `VALUES${inValue}`;
274
275
  }
275
- return `${this.col} IN (${inValue})`;
276
+ return `${this.col} ${this.op} (${inValue})`;
276
277
  // TODO we need to return idx at end to query builder...
277
278
  // or anything that's doing a composite query so next clause knows where to start
278
279
  // or change to a sqlx.Rebind format
@@ -296,10 +297,17 @@ class inClause {
296
297
  return result;
297
298
  }
298
299
  instanceKey() {
299
- return `in:${this.col}:${this.values().join(",")}`;
300
+ return `${this.op.toLowerCase()}:${this.col}:${this.values().join(",")}`;
300
301
  }
301
302
  }
302
303
  exports.inClause = inClause;
304
+ class notInClause extends inClause {
305
+ constructor() {
306
+ super(...arguments);
307
+ this.op = "NOT IN";
308
+ }
309
+ }
310
+ exports.notInClause = notInClause;
303
311
  class compositeClause {
304
312
  constructor(clauses, sep) {
305
313
  this.clauses = clauses;
@@ -570,6 +578,26 @@ function DBTypeIn(col, values, typ) {
570
578
  return new inClause(col, values, typ);
571
579
  }
572
580
  exports.DBTypeIn = DBTypeIn;
581
+ function UuidNotIn(col, values) {
582
+ return new notInClause(col, values, "uuid");
583
+ }
584
+ exports.UuidNotIn = UuidNotIn;
585
+ function IntegerNotIn(col, values) {
586
+ return new notInClause(col, values, "integer");
587
+ }
588
+ exports.IntegerNotIn = IntegerNotIn;
589
+ function TextNotIn(col, values) {
590
+ return new notInClause(col, values, "text");
591
+ }
592
+ exports.TextNotIn = TextNotIn;
593
+ /*
594
+ * if not uuid or text, pass the db type that can be used to cast this query
595
+ * if we end up with a large list of ids
596
+ */
597
+ function DBTypeNotIn(col, values, typ) {
598
+ return new notInClause(col, values, typ);
599
+ }
600
+ exports.DBTypeNotIn = DBTypeNotIn;
573
601
  // if string defaults to english
574
602
  // https://www.postgresql.org/docs/current/textsearch-controls.html#TEXTSEARCH-PARSING-QUERIES
575
603
  // to_tsquery
package/index.d.ts CHANGED
@@ -23,6 +23,10 @@ declare const query: {
23
23
  IntegerIn: typeof q.IntegerIn;
24
24
  TextIn: typeof q.TextIn;
25
25
  DBTypeIn: typeof q.DBTypeIn;
26
+ UuidNotIn: typeof q.UuidNotIn;
27
+ IntegerNotIn: typeof q.IntegerNotIn;
28
+ TextNotIn: typeof q.TextNotIn;
29
+ DBTypeNotIn: typeof q.DBTypeNotIn;
26
30
  Greater: typeof q.Greater;
27
31
  Less: typeof q.Less;
28
32
  GreaterEq: typeof q.GreaterEq;
package/index.js CHANGED
@@ -126,6 +126,10 @@ const query = {
126
126
  IntegerIn: q.IntegerIn,
127
127
  TextIn: q.TextIn,
128
128
  DBTypeIn: q.DBTypeIn,
129
+ UuidNotIn: q.UuidNotIn,
130
+ IntegerNotIn: q.IntegerNotIn,
131
+ TextNotIn: q.TextNotIn,
132
+ DBTypeNotIn: q.DBTypeNotIn,
129
133
  Greater: q.Greater,
130
134
  Less: q.Less,
131
135
  GreaterEq: q.GreaterEq,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@snowtop/ent",
3
- "version": "0.1.0-alpha155",
3
+ "version": "0.1.0-alpha156",
4
4
  "description": "snowtop ent framework",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",