Sequelize-sequelize-auto
自動產生資料庫關聯模型
1. install sequelize-auto
1 | npm install -g sequelize-auto |
2. install mysql
1 | npm install -g mysql |
3. Run sequelize-auto
1 | sequelize-auto -o "./models" -d tablename -h localhost -u my_username -p 5432 -x my_password -e mysql |
4. User.js
這時候就會產生一個跟資料庫對應的模型(/model/User.js)
如果欄位自動號碼的話記得加上 (autoIncrement: true)
1 |
|
5. sequelize.js
1 | const Sequelize = require('sequelize'); |
6. index.js
1 | const Sequelize = require('sequelize'); |