Node.js:在 Sequelize 中定义 Postgres 模式

编程入门 行业动态 更新时间:2024-10-27 04:28:56
本文介绍了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 模式

本文发布于:2023-10-19 00:05:13,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1505823.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:定义   模式   js   Node   Postgres

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!