Last active
December 7, 2020 00:17
-
-
Save soonsam123/223d1bf661e51164d2e2e64bc7bc930d to your computer and use it in GitHub Desktop.
NodeJS API-Part 6 / Adding Sequelize and MySQL Database
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { Sequelize } = require("sequelize"); | |
const Dojos = require("../models/dojos"); | |
module.exports = { | |
async getAll(req, res) { | |
const sequelize = new Sequelize( | |
"martial_arts", | |
"root", | |
"password", | |
{ | |
host: "127.0.0.1", | |
dialect: "mysql", | |
} | |
); | |
try { | |
const dojos = await Dojos(sequelize, Sequelize.DataTypes).findAll(); | |
res.status(200).send(dojos || {}); | |
} catch (error) { | |
// TODO: Errors | |
} finally { | |
sequelize.close(); | |
} | |
}, | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment