Node.js Sequelize框架之原始查询

查询参数替换:原始查询中有两种替换查询参数的方法,以:开头的参数的形式或以?替换。

sequelize.query('select * from projects where status = ?', {
	replacements : ['active'],//按顺序传入需要替换?的值
	type : Sequelize.QueryTypes.SELECT //指定查询类型
}).then(function(projects){
	//返回查询结果
	console.log(projects);
})
sequelize.query('select * from projects where status = :status', {
	replacements : {
		status : 'active' //按:后的标识名传入其替换成的值
	},
	type : Sequelize.QueryTypes.SELECT //指定查询类型
}).then(function(projects){
	//返回查询结果
	console.log(projeccts);
})

猜你喜欢

转载自blog.csdn.net/qq_25062671/article/details/111056291