不要怂,就是干,撸起袖子干!

Commit ba5192ce by Simon Schick Committed by GitHub

feat(typings): add some missing operators (#10846)

1 parent 5412adea
......@@ -125,9 +125,11 @@ export interface AnyOperator {
/** Undocumented? */
export interface AllOperator {
[Op.all]: (string | number)[];
[Op.all]: (string | number | Date | Literal)[];
}
export type Rangable = [number, number] | [Date, Date] | Literal;
/**
* Operators that can be used in WhereOptions
*
......@@ -193,21 +195,21 @@ export interface WhereOperators {
*
* Example: `[Op.overlap]: [1, 2]` becomes `&& [1, 2]`
*/
[Op.overlap]?: [number, number] | Literal;
[Op.overlap]?: Rangable;
/**
* PG array contains operator
*
* Example: `[Op.contains]: [1, 2]` becomes `@> [1, 2]`
*/
[Op.contains]?: [number, number] | [Date, Date] | Literal;
[Op.contains]?: Rangable;
/**
* PG array contained by operator
*
* Example: `[Op.contained]: [1, 2]` becomes `<@ [1, 2]`
*/
[Op.contained]?: [number, number] | [Date, Date] | Literal;
[Op.contained]?: Rangable;
/** Example: `[Op.gt]: 6,` becomes `> 6` */
[Op.gt]?: number | string | Date | Literal;
......@@ -273,6 +275,35 @@ export interface WhereOperators {
* Example: `[Op.notIRegexp]: '^[h|a|t]'` becomes `!~* '^[h|a|t]'`
*/
[Op.notIRegexp]?: string;
/**
* PG only
*
* Forces the operator to be strictly left eg. `<< [a, b)`
*/
[Op.strictLeft]?: Rangable;
/**
* PG only
*
* Forces the operator to be strictly right eg. `>> [a, b)`
*/
[Op.strictRight]?: Rangable;
/**
* PG only
*
* Forces the operator to not extend the left eg. `&> [1, 2)`
*/
[Op.noExtendLeft]?: Rangable;
/**
* PG only
*
* Forces the operator to not extend the left eg. `&< [1, 2)`
*/
[Op.noExtendRight]?: Rangable;
}
/** Example: `[Op.or]: [{a: 5}, {a: 6}]` becomes `(a = 5 OR a = 6)` */
......
......@@ -39,5 +39,6 @@ declare const Op: {
readonly strictLeft: unique symbol;
readonly strictRight: unique symbol;
readonly substring: unique symbol;
readonly values: unique symbol;
};
export = Op;
......@@ -170,7 +170,6 @@ MyModel.findAll({ lock: { level: Transaction.LOCK.KEY_SHARE, of: MyModel} }).the
MyModel.findAll({
where: {
// tslint:disable-next-line:no-object-literal-type-assertion
id: {
// casting here to check a missing operator is not accepted as field name
[Op.and]: { a: 5 }, // AND (a = 5)
......@@ -192,6 +191,12 @@ MyModel.findAll({
[Op.contains]: [1, 2], // @> [1, 2] (PG array contains operator)
[Op.contained]: [1, 2], // <@ [1, 2] (PG array contained by operator)
[Op.any]: [2, 3], // ANY ARRAY[2, 3]::INTEGER (PG only)
[Op.adjacent]: [1, 2],
[Op.strictLeft]: [1, 2],
[Op.strictRight]: [1, 2],
[Op.noExtendLeft]: [1, 2],
[Op.noExtendRight]: [1, 2],
[Op.values]: [1, 2],
} as WhereOperators,
status: {
[Op.not]: false, // status NOT FALSE
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!