使用Sequelize时,如何写按位(或)操作?
when using Sequelize, how to write bitwise(or) operatioin?
续集/Postgres
**列 reasoncodes 包含像这样的字符串值。
0,0,0,1,0,0,0,0,0,0,0,0,0**
我们的想法是获取这个值并替换它,使其变成位
然后将其与前端传递的值字符串进行比较 (0001000000000)
这适用于 Postgres。
select * from schema.table
where cast(cast(replace(reasoncodes, ',', '') as bit(13)) & cast('0001000000000' as bit(13)) as integer) > 0
and table.id = 1885
如何将这个where子句转换成Sequelize语法是个问题
您需要使用'Sequelize.literal',例如:
TableName.findAll({
where: {
[Op.and]: [
Sequelize.literal('cast(cast(replace(reasoncodes, ',', '') as bit(13)) & cast('0001000000000' as bit(13)) as integer) > 0')
]
}
})
续集/Postgres
**列 reasoncodes 包含像这样的字符串值。
0,0,0,1,0,0,0,0,0,0,0,0,0**
我们的想法是获取这个值并替换它,使其变成位 然后将其与前端传递的值字符串进行比较 (0001000000000)
这适用于 Postgres。
select * from schema.table
where cast(cast(replace(reasoncodes, ',', '') as bit(13)) & cast('0001000000000' as bit(13)) as integer) > 0
and table.id = 1885
如何将这个where子句转换成Sequelize语法是个问题
您需要使用'Sequelize.literal',例如:
TableName.findAll({
where: {
[Op.and]: [
Sequelize.literal('cast(cast(replace(reasoncodes, ',', '') as bit(13)) & cast('0001000000000' as bit(13)) as integer) > 0')
]
}
})