@simplehealth/filterql
Advanced tools
Comparing version 0.2.3 to 0.3.0
@@ -0,1 +1,10 @@ | ||
# v0.3.0 | ||
- Add new SQLConditions: | ||
- `NEQ(field, value)` (to complement `EQ`) | ||
- `LOOSE_EQ`, `LOOSE_NEQ` (to access default (null-unsafe) `=` and `!=` operators) | ||
- `STRICT_EQ`, `STRICT_NEQ` (what `EQ` and `NEQ` are aliases of) | ||
- `GT`, `LT`, `LTE` (to complement `GTE`) | ||
- `IMPLIES(p, q)` (boolean logical implication) | ||
# v0.2.3 | ||
@@ -2,0 +11,0 @@ |
54
index.js
@@ -24,36 +24,36 @@ "use strict"; | ||
}); | ||
Object.defineProperty(exports, "RAW", { | ||
Object.defineProperty(exports, "AND", { | ||
enumerable: true, | ||
get: function get() { | ||
return _SQLCondition.RAW; | ||
return _SQLCondition.AND; | ||
} | ||
}); | ||
Object.defineProperty(exports, "TRUE", { | ||
Object.defineProperty(exports, "EQ", { | ||
enumerable: true, | ||
get: function get() { | ||
return _SQLCondition.TRUE; | ||
return _SQLCondition.EQ; | ||
} | ||
}); | ||
Object.defineProperty(exports, "FALSE", { | ||
Object.defineProperty(exports, "EXISTS", { | ||
enumerable: true, | ||
get: function get() { | ||
return _SQLCondition.FALSE; | ||
return _SQLCondition.EXISTS; | ||
} | ||
}); | ||
Object.defineProperty(exports, "IS_NULL", { | ||
Object.defineProperty(exports, "FALSE", { | ||
enumerable: true, | ||
get: function get() { | ||
return _SQLCondition.IS_NULL; | ||
return _SQLCondition.FALSE; | ||
} | ||
}); | ||
Object.defineProperty(exports, "NOT_NULL", { | ||
Object.defineProperty(exports, "GTE", { | ||
enumerable: true, | ||
get: function get() { | ||
return _SQLCondition.NOT_NULL; | ||
return _SQLCondition.GTE; | ||
} | ||
}); | ||
Object.defineProperty(exports, "EQ", { | ||
Object.defineProperty(exports, "IMPLIES", { | ||
enumerable: true, | ||
get: function get() { | ||
return _SQLCondition.EQ; | ||
return _SQLCondition.IMPLIES; | ||
} | ||
@@ -67,20 +67,14 @@ }); | ||
}); | ||
Object.defineProperty(exports, "GTE", { | ||
Object.defineProperty(exports, "INSTR", { | ||
enumerable: true, | ||
get: function get() { | ||
return _SQLCondition.GTE; | ||
return _SQLCondition.INSTR; | ||
} | ||
}); | ||
Object.defineProperty(exports, "EXISTS", { | ||
Object.defineProperty(exports, "IS_NULL", { | ||
enumerable: true, | ||
get: function get() { | ||
return _SQLCondition.EXISTS; | ||
return _SQLCondition.IS_NULL; | ||
} | ||
}); | ||
Object.defineProperty(exports, "INSTR", { | ||
enumerable: true, | ||
get: function get() { | ||
return _SQLCondition.INSTR; | ||
} | ||
}); | ||
Object.defineProperty(exports, "NOT", { | ||
@@ -92,6 +86,6 @@ enumerable: true, | ||
}); | ||
Object.defineProperty(exports, "AND", { | ||
Object.defineProperty(exports, "NOT_NULL", { | ||
enumerable: true, | ||
get: function get() { | ||
return _SQLCondition.AND; | ||
return _SQLCondition.NOT_NULL; | ||
} | ||
@@ -105,2 +99,14 @@ }); | ||
}); | ||
Object.defineProperty(exports, "RAW", { | ||
enumerable: true, | ||
get: function get() { | ||
return _SQLCondition.RAW; | ||
} | ||
}); | ||
Object.defineProperty(exports, "TRUE", { | ||
enumerable: true, | ||
get: function get() { | ||
return _SQLCondition.TRUE; | ||
} | ||
}); | ||
@@ -107,0 +113,0 @@ var _Q = require("./Q"); |
{ | ||
"name": "@simplehealth/filterql", | ||
"version": "0.2.3", | ||
"version": "0.3.0", | ||
"description": "The FilterQL mini-language.", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -7,12 +7,21 @@ "use strict"; | ||
exports.RAW = RAW; | ||
exports.AND = AND; | ||
exports.OR = OR; | ||
exports.NOT = NOT; | ||
exports.IMPLIES = IMPLIES; | ||
exports.IS_NULL = IS_NULL; | ||
exports.NOT_NULL = NOT_NULL; | ||
exports.STRICT_EQ = STRICT_EQ; | ||
exports.LOOSE_EQ = LOOSE_EQ; | ||
exports.EQ = EQ; | ||
exports.STRICT_NEQ = STRICT_NEQ; | ||
exports.LOOSE_NEQ = LOOSE_NEQ; | ||
exports.NEQ = NEQ; | ||
exports.IN = IN; | ||
exports.GT = GT; | ||
exports.GTE = GTE; | ||
exports.LT = LT; | ||
exports.LTE = LTE; | ||
exports.EXISTS = EXISTS; | ||
exports.INSTR = INSTR; | ||
exports.NOT = NOT; | ||
exports.AND = AND; | ||
exports.OR = OR; | ||
exports.FALSE = exports.TRUE = void 0; | ||
@@ -62,57 +71,2 @@ | ||
function IS_NULL(field) { | ||
return { | ||
sqlExpr: '?? IS NULL', | ||
params: [field] | ||
}; | ||
} | ||
function NOT_NULL(field) { | ||
return { | ||
sqlExpr: '?? IS NOT NULL', | ||
params: [field] | ||
}; | ||
} | ||
function EQ(field, value) { | ||
return RAW( // NOTE: We're using MySQL's `<=>` (strict-equals) operator here. Read | ||
// this as a normal `=`, but this will behave more sanely around cases | ||
// where field is `NULL`, meaning this can be inverted with a boolean | ||
// NOT safely. | ||
'?? <=> ?', [field, value]); | ||
} | ||
function IN(field, values) { | ||
return values.length > 0 ? RAW('?? IN (?)', [field, values]) : FALSE; | ||
} | ||
function GTE(field, value) { | ||
return RAW('?? >= ?', [field, value]); | ||
} | ||
function EXISTS(sqlExpr, params) { | ||
return { | ||
sqlExpr: "EXISTS (".concat(sqlExpr, ")"), | ||
params: params | ||
}; | ||
} | ||
/** | ||
* This is similar to using LIKE '%[...]%' clause, except that it doesn't accept | ||
* SQL wildcards such as '%' and '_'. | ||
*/ | ||
function INSTR(field, value) { | ||
return RAW('INSTR(??, ?)', [field, value]); | ||
} | ||
function NOT(condition) { | ||
var sqlExpr = condition.sqlExpr, | ||
params = condition.params; | ||
return { | ||
sqlExpr: "NOT (".concat(sqlExpr, ")"), | ||
params: params | ||
}; | ||
} | ||
function AND() { | ||
@@ -162,2 +116,122 @@ for (var _len = arguments.length, conditions = new Array(_len), _key = 0; _key < _len; _key++) { | ||
} | ||
} | ||
function NOT(condition) { | ||
var sqlExpr = condition.sqlExpr, | ||
params = condition.params; | ||
return { | ||
sqlExpr: "NOT (".concat(sqlExpr, ")"), | ||
params: params | ||
}; | ||
} | ||
/** | ||
* Boolean-if expression, aka logical implication. | ||
* | ||
* P → Q | ||
* | ||
* If P, then Q must also hold. (When P is not true, Q is irrelevant and this | ||
* entire expression returns true.) | ||
* | ||
* Will be translated using DeMorgan to: | ||
* | ||
* ¬P ∨ Q | ||
*/ | ||
function IMPLIES(p, q) { | ||
return OR(NOT(p), q); | ||
} | ||
function IS_NULL(field) { | ||
return { | ||
sqlExpr: '?? IS NULL', | ||
params: [field] | ||
}; | ||
} | ||
function NOT_NULL(field) { | ||
return { | ||
sqlExpr: '?? IS NOT NULL', | ||
params: [field] | ||
}; | ||
} | ||
function STRICT_EQ(field, value) { | ||
return RAW( // NOTE: We're using MySQL's `<=>` (strict-equals) operator here. Read | ||
// this as a normal `=`, but this will behave more sanely around cases | ||
// where field is `NULL`, meaning this can be inverted with a boolean | ||
// NOT safely. | ||
'?? <=> ?', [field, value]); | ||
} | ||
/** | ||
* MySQL's default `=` operator, which isn't safe around `NULL` values. | ||
*/ | ||
function LOOSE_EQ(field, value) { | ||
return RAW('?? = ?', [field, value]); | ||
} | ||
/** | ||
* EQ is an alias of STRICT_EQ. | ||
*/ | ||
function EQ(field, value) { | ||
return STRICT_EQ(field, value); | ||
} | ||
function STRICT_NEQ(field, value) { | ||
return NOT(STRICT_EQ(field, value)); | ||
} | ||
/** | ||
* MySQL's default `!=` operator, which isn't safe around `NULL` values. | ||
*/ | ||
function LOOSE_NEQ(field, value) { | ||
return RAW('?? != ?', [field, value]); | ||
} | ||
/** | ||
* NEQ is an alias of STRICT_NEQ. | ||
*/ | ||
function NEQ(field, value) { | ||
return STRICT_NEQ(field, value); | ||
} | ||
function IN(field, values) { | ||
return values.length > 0 ? RAW('?? IN (?)', [field, values]) : FALSE; | ||
} | ||
function GT(field, value) { | ||
return RAW('?? > ?', [field, value]); | ||
} | ||
function GTE(field, value) { | ||
return RAW('?? >= ?', [field, value]); | ||
} | ||
function LT(field, value) { | ||
return RAW('?? < ?', [field, value]); | ||
} | ||
function LTE(field, value) { | ||
return RAW('?? <= ?', [field, value]); | ||
} | ||
function EXISTS(sqlExpr, params) { | ||
return { | ||
sqlExpr: "EXISTS (".concat(sqlExpr, ")"), | ||
params: params | ||
}; | ||
} | ||
/** | ||
* This is similar to using LIKE '%[...]%' clause, except that it doesn't accept | ||
* SQL wildcards such as '%' and '_'. | ||
*/ | ||
function INSTR(field, value) { | ||
return RAW('INSTR(??, ?)', [field, value]); | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
55312
914