Answers for "Programação web com Node e Express Beneficiando-se da stack JavaScript"

0

Programação web com Node e Express Beneficiando-se da stack JavaScript

const fs = require('fs');
const path = require('path');
const Sequelize = require('sequelize');
const config = require('../../config/database.js');

const db = {};
const sequelize = new Sequelize(config);

fs
  .readdirSync(__dirname)
  .filter(file => (file.indexOf('.') !== 0) && (file !== path.basename(__filename)) && (file.slice(-3) === '.js'))
  .forEach((file) => {
    const model = sequelize.import(path.join(__dirname, file));
    db[model.name] = model;
  });

Object.keys(db).forEach((modelName) => {
  if (db[modelName].associate) {
    db[modelName].associate(db);
  }
});

db.sequelize = sequelize;
db.Sequelize = Sequelize;

module.exports = db;
Posted by: Guest on May-07-2020

Code answers related to "Programação web com Node e Express Beneficiando-se da stack JavaScript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language