作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个模型,它将列 keywords
定义为字符串数组。现在我不想查询 keywords
列中不包含特殊关键字的所有条目。我的方法并不像预期的那样有效。
模型:
export default function (sequelize, DataTypes) {
return sequelize.define('transaction', {
id: {
primaryKey: true,
type: DataTypes.INTEGER,
autoIncrement: true
},
keywords: {
type: DataTypes.ARRAY(DataTypes.TEXT),
defaultValue: []
},
createdAt: DataTypes.DATE,
updatedAt: DataTypes.DATE
});
}
查询:
const transactions = await db.transaction.findAll({
where: {keywords: {[Op.notLike]: '%MyKey%'}}
}).catch(e => log.error(e));
// Throws error: TypeError: values.map is not a function
依赖关系:
"pg": "6.4.1",
"pg-hstore": "^2.3.2",
"sequelize": "^4.28.8",
最佳答案
我不确定在 Postgresql 中是否真的有一个数组函数/运算符来执行此操作。我只能看到包含
https://www.postgresql.org/docs/9.1/static/functions-array.html
关于node.js - 如何在 Sequelize 中对 postgres 数组执行 where 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48188992/
我是一名优秀的程序员,十分优秀!