信息管理系统
$ express --ejs --git ims
$ cd ims
$ npm install
$ npm install --save nodemon
packeage.json 新增开发选项
"scripts": {
"start": "node ./bin/www",
"dev": "nodemon ./bin/www"
},
保存并启动项目
$ git init
$ git checkout -b dev
$ git add .
$ git commit -m "Init project"
$ npm run dev
安装数据库
$ npm install --save sequelize
$ npm install --save mysql2 # 如果使用 MySQL
$ npm install -g sequelize-cli
$ sequelize init
config.json 常用配置
{
"development": {
"username": "root",
"password": "root",
"database": "ims_database_development",
"host": "127.0.0.1",
"port": "8889",
"dialect": "mysql",
"timezone": "+08:00"
},
"test": {
"username": "root",
"password": null,
"database": "ims_database_test",
"host": "127.0.0.1",
"dialect": "mysql"
},
"production": {
"username": "root",
"password": null,
"database": "ims_database_production",
"host": "127.0.0.1",
"dialect": "mysql"
}
}
通过命令创建模型和迁移文件
$ sequelize model:generate --name Article --attributes title:string,content:text
迁移操作
$ sequelize db:migrate
种子数据
$ sequelize seed:generate --name article
// 模拟数据
$ sequelize db:seed --seed 20241024092856-article
$ git add .
$ git commmit -m "use db"







网友评论