Sequelize
Sequelize is a promise-based Node.js ORM for Postgres, MySQL, MariaDB, SQLite and Microsoft SQL Server. It features solid transaction support, relations, eager and lazy loading, read replication and more.
npm install --save sequelize
Installing the CLI
To install the Sequelize CLI:
npm install --save-dev sequelize-cli
Project bootstrapping
To create an empty project you will need to execute init command:
npx sequelize-cli init
Before continuing further we will need to tell the CLI how to connect to the database.
기본적으로 development, test, production 환경 중에 development에 비번 설정
created table in database -> it is urls.
{
"development": {
"username": "root",
"password": 비번설정,
"database": "database_development",
"host": "127.0.0.1",
"dialect": "mysql"
},
"test": {
"username": "root",
"password": null,
"database": "database_test",
"host": "127.0.0.1",
"dialect": "mysql"
},
"production": {
"username": "root",
"password": null,
"database": "database_production",
"host": "127.0.0.1",
"dialect": "mysql"
}
}
Creating the first Model (and Migration)
npx sequelize-cli model:generate --name url --attributes url:string,title:string,visits:integer
reference video : https://www.youtube.com/watch?v=3qlnR9hK-lQ&t=135s