Use native esm
This commit is contained in:
parent
c4354a6600
commit
70bd12a4d6
37 changed files with 379 additions and 119 deletions
|
@ -1,36 +0,0 @@
|
|||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import Sequelize from 'sequelize';
|
||||
|
||||
import debugname from 'debug';
|
||||
|
||||
const debug = debugname('combine.fm:models');
|
||||
|
||||
const config = {
|
||||
dialect: 'postgres',
|
||||
protocol: 'postgres',
|
||||
quoteIdentifiers: true,
|
||||
logging: false,
|
||||
};
|
||||
|
||||
const sequelize = new Sequelize(process.env.DATABASE_URL, config);
|
||||
const db = {};
|
||||
|
||||
fs
|
||||
.readdirSync(__dirname)
|
||||
.filter(file => (file.indexOf('.') !== 0) && (file !== 'index.js'))
|
||||
.forEach((file) => {
|
||||
const model = sequelize.import(path.join(__dirname, file));
|
||||
db[model.name] = model;
|
||||
});
|
||||
|
||||
Object.keys(db).forEach((modelName) => {
|
||||
if ('associate' in db[modelName]) {
|
||||
db[modelName].associate(db);
|
||||
}
|
||||
});
|
||||
|
||||
db.sequelize = sequelize;
|
||||
db.Sequelize = Sequelize;
|
||||
|
||||
export default db;
|
Loading…
Add table
Add a link
Reference in a new issue