Sequelize Model.increment返回[defined,number],而不是受影响的行



我面临的问题是,Sequelize在调用Model.increment时不会返回受影响的行,而是进行更改,当我检查数据库时,我发现它工作正常,但我需要知道受影响的是什么行。

我的代码如下:

// DB file
const SearchModel = sequelize.define(
"SearchModel",
{
ID: {
type: DataTypes.INTEGER,
autoIncrement: true,
allowNull: false,
primaryKey: true
},
Name: {
type: DataTypes.STRING,
allowNull: false,
unique: true,
},
SearchesCounter: {
type: DataTypes.INTEGER,
defaultValue: 1,
},
},
{ tableName: "SearchHistory" }
);
// then I do the search in another file after exporting sequelize 
await database.sync();
const searchModel = database.model("SearchModel");
let DBResults = await searchModel.increment("SearchesCounter", {
returning: true,
where: {
Name: {
[Op.or]: searches, // searches is array of strings
},
},
});

我得到的不是[Affected_Rows[],受影响的行数],而是未定义的,受影响行数]。

有什么帮助吗?

也许这不是您的增量。但是你的搜索。。。而是使用Op.or(如果您想使用array(在中使用Op.in

所以代码看起来像

where: {
Name: {
[Op.in]: ['a', 'b'], // array of strings
},
},

或简单版本

where: {
Name: ['a', 'b'] // array of key word
},

最新更新