daily pastebin goal
37%
SHARE
TWEET

Untitled

a guest Jun 14th, 2018 52 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. "use strict";
  2.  
  3. var fs = require("fs");
  4. var path = require("path");
  5. var Sequelize = require("sequelize");
  6. var basename = path.basename(module.filename);
  7. var env = process.env.NODE_ENV || "development";
  8. var config = require(__dirname + "/../config/config.json")[env];
  9. var db = {};
  10.  
  11. if (config.use_env_variable) {
  12.   var sequelize = new Sequelize(process.env[config.use_env_variable]);
  13. } else {
  14.   var sequelize = new Sequelize(config.database, config.username, config.password, config);
  15. }
  16.  
  17. fs
  18.   .readdirSync(__dirname)
  19.   .filter(function(file) {
  20.     return (file.indexOf(".") !== 0) && (file !== basename) && (file.slice(-3) === ".js");
  21.   })
  22.   .forEach(function(file) {
  23.     var model = sequelize["import"](path.join(__dirname, file));
  24.     console.log(model);
  25.     db[model.name] = model;
  26.   });
  27.  
  28. Object.keys(db).forEach(function(modelName) {
  29.   if (db[modelName].associate) {
  30.     db[modelName].associate(db);
  31.   }
  32. });
  33.  
  34. db.sequelize = sequelize;
  35. db.Sequelize = Sequelize;
  36.  
  37. module.exports = db;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top