Javascript Sequelize Model.increment返回[undefined,number],而不是受影响的行
我面临的问题是,Sequelize在调用Model.increment时不会返回受影响的行,它会进行更改,当我检查数据库时,我看到它工作正常,但我需要知道受影响的行是什么 我的代码如下所示:Javascript Sequelize Model.increment返回[undefined,number],而不是受影响的行,javascript,node.js,sequelize.js,Javascript,Node.js,Sequelize.js,我面临的问题是,Sequelize在调用Model.increment时不会返回受影响的行,它会进行更改,当我检查数据库时,我看到它工作正常,但我需要知道受影响的行是什么 我的代码如下所示: // DB file const SearchModel = sequelize.define( "SearchModel", { ID: { type: DataTypes.INTEGER, autoIncrement: true,
// 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
},
},
});
而不是得到[受影响的行数[],受影响的行数],而是得到[未定义,受影响的行数]
有什么帮助吗?也许这不是你的增量。 但是你的搜索。。。 而是使用Op.or(如果要使用数组) 使用Op.in 所以代码看起来像
where: {
Name: {
[Op.in]: ['a', 'b'], // array of strings
},
},
还是简单的版本
where: {
Name: ['a', 'b'] // array of key word
},
两种方法都试过了,结果还是一样的