postgresSQL
Today, we will be refactoring our mongodb books api to work with postgresSQL DB
DBMS has been around since 60s
click here for more history
SQLite is a lightweight db
MariaDB is forked from mySQL
Sequelize is a promise-based Node.js ORM for postgres, etc
(That means it converts our mongodb books api to SQL queries)
ER diagrams
An Entity Relationship (ER) Diagram is a type of flowchart that illustrates how “entities” such as people, objects or concepts relate to each other within a system.
ER
Crow’s Foot
Crow’s Foot/Martin/Information Engineering style
|
|
|
|
|
|
|
|
|
Steps for sequelize:
Create the model schema in sequelize.define()
export all your models to index.js in models folder
module.exports = (sequelize, type) => {}
in index.js, import sequelize, and create an instance
const sequelize = new Sequelize(“books-api”, “username”, “password”, {dialect:”postgres”});
Object.keys(models).forEach(key => {if (“associate”inmodels[key]) {models[key].associate(models);}});
then sync it in your server
//Wrap sequelize sync around the app.listen (force: true drops the tables if exists, so only use in dev )sequelize.sync({ force: true }).then(() => {createAuthorsAndBooks();//your app.listen here});