【发布时间】:2020-08-03 02:24:29
【问题描述】:
我必须连接到 Node.js 中的 Postgres 数据库,并且我想使用 Sequelize 库动态切换模式。
这是我的表模型和控制器代码。
module.exports = function (sequelize, DataTypes) {
const customer = sequelize.define(
'customer',
{
id: {
autoIncrement: true,
primaryKey: true,
type: DataTypes.INTEGER,
},
schema_name: {
type: DataTypes.STRING,
allowNull: false,
},
created_on: {
type: DataTypes.DATE,
allowNull: false,
defaultValue: DataTypes.NOW(),
},
},
{
schema: 'public',
}
)
return customer
}
和控制器代码
exports.login = async (req, res, next) => {
const { email, password, domain } = req.body
const domainData = await customer.findOne({
where: { schema_name: domain },
})
console.log('Log: exports.login -> domainData', domainData)
}
收到回复后,我必须根据上述结果动态切换架构。
请大家帮帮我
【问题讨论】:
标签: sql node.js postgresql schema