Skip to content

Instantly share code, notes, and snippets.

@soonsam123
Last active December 7, 2020 00:17
Show Gist options
  • Save soonsam123/223d1bf661e51164d2e2e64bc7bc930d to your computer and use it in GitHub Desktop.
Save soonsam123/223d1bf661e51164d2e2e64bc7bc930d to your computer and use it in GitHub Desktop.
NodeJS API-Part 6 / Adding Sequelize and MySQL Database
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