/**
* @param {String} field
* @param {String} expression
* @param {String | RegExp | Function} condition
* @param {String} relation {and(default) | or}
*/
query.where(field, expression, condition, relation)
// array group
query.where([[field, expression, condition, relation], [field, expression, condition, relation]])
expression |
description |
example |
eq / = |
等于(=== ) |
where('age', 'eq', 18) |
neq / <> |
不等于(!== ) |
where('sex', 'neq', 'male') |
gt / > |
大于(> ) |
where('price', 'gt', 17) |
gte / >= |
大于等于 (>= ) |
where('price', 'gte', 17) |
lt / < |
小于(< ) |
where('price', '<', 17) |
lte / <= |
小于等于(<= ) |
where('price', '<=', 17) |
like |
模糊查询 |
where('title', 'like', 'javascript') |
in |
in查询 |
where('tag', 'in', ['javascript', 'vue']) |
nin |
不再in查询 |
where('tag', 'nin', ['javascript', 'vue']) |
exists |
字段是否存在 |
where('author', 'exists') |
// author === 'smohan' && views > 500
query
.where('author', 'eq', 'smohan')
.where('views', '>', 500)
// author === 'smohan' || views > 500
query
.where('author', 'eq', 'smohan')
.where('views', '>', 500, 'or')
// author === 'smohan' && (title like javascript || tags like javascript) && comments >= 0
query
.where('author', 'eq', 'smohan')
.where([['title', 'like', 'javascript'], ['tags', 'like', 'javascript', 'or'] ])
.where('comments', 'gt', 0)
query
.where('comments', 'eq', function (value) {
return value >= 3 && views <= 100
})
// regExp.test(email value)
query
.where('email', 'eq', /^\w+@\w+\.\w+$/)