'use strict';

var fs        = require('fs');
var path      = require('path');
var Sequelize = require('sequelize');
var basename  = path.basename(__filename);
var env       = process.env.NODE_ENV || 'development';
var config    = require(<%= configFile %>)[env];
var db        = {};

if (config.use_env_variable) {
  var sequelize = new Sequelize(process.env[config.use_env_variable], config);
} else {
  var sequelize = new Sequelize(config.database, config.username, config.password, config);
}

fs
  .readdirSync(__dirname)
  .filter(file => {
    return (file.indexOf('.') !== 0) && (file !== basename) && (file.slice(-3) === '.js');
  })
  .forEach(file => {
    var 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;

@@ -12,21 +12,16 @@
 ';%0A%0A
-var fs       
+const fs
  = r
@@ -38,22 +38,19 @@
 ');%0A
-var
+const
  path 
-     
 = re
@@ -64,19 +64,21 @@
 path');%0A
-var
+const
  Sequeli
@@ -104,19 +104,21 @@
 lize');%0A
-var
+const
  basenam
@@ -119,17 +119,16 @@
 asename 
- 
 = path.b
@@ -152,21 +152,17 @@
 e);%0A
-var env      
+const env
  = p
@@ -203,19 +203,21 @@
 t';%0A
-var
+const
  config 
    =
@@ -212,19 +212,16 @@
  config 
-   
 = requir
@@ -251,28 +251,38 @@
 v%5D;%0A
-var db        = %7B%7D;%0A
+const db = %7B%7D;%0A%0Alet sequelize;
 %0Aif 
@@ -307,28 +307,24 @@
 riable) %7B%0A  
-var 
 sequelize = 
@@ -395,20 +395,16 @@
 lse %7B%0A  
-var 
 sequeliz
@@ -654,19 +654,21 @@
 %3E %7B%0A    
-var
+const
  model =

use const in index.js (#661)