nodejs学习五:sequelize数据库查询的Op方法
// 查找users表数据nameconst op = models.Sequelize.Op;let {age} = req.query;let user = await models.User.findAll({where: {age: {[op.between]: [0, 24] // 查询年龄在0-24岁的}...
// 查找users表数据name
const op = models.Sequelize.Op;
let {age} = req.query;
let user = await models.User.findAll({
where: {
age: {
[op.between]: [0, 24] // 查询年龄在0-24岁的
}
}
})
op方法:
adjacent: 邻近的
[Op.adjacent]: [1, 2]
all:所有[Op.gt]: { [Op.all]: literal('SELECT 1') }
and:并且[Op.and]: {a: 5}
any:任意[Op.any]: [2,3]
between:之间[Op.between]: [10, 20]
col:
contained:
contains:
endsWith:以结束[Op.endsWith]: 'm'
eq:= 等于[Op.eq]: 12
gt:> 大于[Op.gt]: 6
gte:>= 大于等于[Op.gte]: 6
iLike:
in:查询包含的状态[Op.in]: [12, 25]
iRegexp:
is:是否,判断类[Op.is]: null
like:模糊匹配,包含[Op.like]: '%m%'
lt:< 小于[Op.lt]: 23
lte:<= 小于等于[Op.lte]: 10
ne:!= 不等于[Op.ne]: 23
noExtendLeft:
noExtendRight:
not:非查询[Op.not]: null
notBetween:不在xx和xx之间的[Op.notBetween]: [11, 23]
notILike:
notIn:查询不包含的状态[Op.notIn]: [12, 25]
notIRegexp:
notLike:模糊匹配,不包含[Op.notLike]: '%m%'
notRegexp:正则,不以开始[Op.notRegexp]: '^[h|a|t]'
or:或者where:{ [Op.or]:[ {parent_id:id}, {id:id} ] }
overlap:重叠部分[Op.overlap]: [1, 2]
placeholder:占位符
regexp:正则,以开始[Op.regexp]: '^[h|a|t]'
startsWith:字符串,以*开始[Op.startsWith]: 'j'
strictLeft:
strictRight:
substring:模糊匹配[Op.substring]: 'oh'
values:
文中部分没有注释的还没有搞明白,或者是自测有问题,有想法的可以留言交流哈。
更多推荐


所有评论(0)