本文介绍了如何为Sequelize Postgres在连接时一次为所有模型设置架构?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我能够使用

sequelize.query(`
    SET SCHEMA 'schema_for_client_name'
`);

我也能够为单个模型设置架构

I'm also able to set schema for individual models

User.init(
    {
      userId: {
        type: DataTypes.INTEGER,
        autoIncrement: true,
        primaryKey: true,
      },
      email: {
        type: DataTypes.STRING,
        allowNull: false,
      },
      firstName: {
        type: DataTypes.STRING,
        allowNull: false,
      },
      lastName: {
        type: DataTypes.STRING,
        allowNull: false,
      },
      password: {
        type: DataTypes.STRING,
        allowNull: false,
      },
      salt: {
        type: DataTypes.STRING,
        allowNull: false,
      },
    },
    {
      sequelize,
      tableName: 'users',
      schema: 'schema_for_client_name',
      timestamps: false,
    }
);

是否可以在连接时一次为所有模型设置架构?

Is it possible to set schema for all models at once at connection time?

推荐答案

根据 续集构造子采用可选的默认模式选项:

According to the docs the Sequelize constructor takes an optional default schema option:

const sequelize = new Sequelize(database, username, password, {schema: 'schema_for_client_name'});

这篇关于如何为Sequelize Postgres在连接时一次为所有模型设置架构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 02:29