Node.js:在 Sequelize 中定义 Postgres 模式 [英] Node.js: Defining Postgres Schemas in Sequelize

查看:17
本文介绍了Node.js:在 Sequelize 中定义 Postgres 模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

官方文档没有明确解释如何为数据库定义模式通过他们自己.我假设 Sequelize 与 MySql 比 Postgres 更相关(其中模式是强制性的).

The Official Documentation doesn't explains clearly how define schemas for database by themselves. I'm assuming that Sequelize is more related to MySql than Postgres (where schemas are mandatory).

如果我已经在 Postgres 中创建了一些模式,如何将它们与 Sequelize 同步?

If I've already created some schemas in Postgres, how I could sync them with Sequelize?

推荐答案

您可以使用 model.schema 设置带有模式的模型,例如:

You can set the model with the schema using model.schema, something like:

var City = sequelize.define('City', {
    id: {
        type: sequelize.Sequelize.INTEGER,
        primaryKey: true,
        autoIncrement: true,
        field: 'id'
    },
    name: {
        type: sequelize.Sequelize.STRING,
        field: 'name'   
    }
  }, {
    timestamps: false,
    tableName: 'cities'
    });
City.schema("public");

这篇关于Node.js:在 Sequelize 中定义 Postgres 模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆