midwayjs / midway

🍔 A Node.js Serverless Framework for front-end/full-stack developers. Build the application for next decade. Works on AWS, Alibaba Cloud, Tencent Cloud and traditional VM/Container. Super easy integrate with React and Vue. 🌈
https://www.midwayjs.org/
MIT License
7.37k stars 574 forks source link

如何将定义好的数据库模型同步到数据库中呢? #197

Closed tan1444 closed 5 years ago

tan1444 commented 5 years ago

微信截图_20190418204503 我按照例子定义好了user表,但如何把它同步到我的数据库中去呢?

czy88840616 commented 5 years ago

这个..没这个功能啊……

tan1444 commented 5 years ago

只能手码吗?项目里打一遍,再到数据库里手动创建一下?

czy88840616 commented 5 years ago

等等..sequelize有个sync 方法的,可以同步表结构的

tan1444 commented 5 years ago

在midway框架下如何实现呢,有没有demo?

zt123123 commented 5 years ago

sequeze是orm框架 orm简化了sql操作前提是,把实体类映射到数据库的表字段,你不自己定义Model,框架不知道怎么处理 。在Java中heberlate也是需要配置文件的,同时也要建立相应的bean,定义类的属性与方法,来映射到数据库。然后就可以用orm框架来简化sql语句,用对应的api来操作数据。

czy88840616 commented 5 years ago

这个属于 sequelize 的用法,具体看同步这页。。http://docs.sequelizejs.com/manual/models-definition.html#database-synchronization