-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb.js
31 lines (26 loc) · 857 Bytes
/
db.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
var Sequelize = require('sequelize');
var env = process.env.NODE_ENV || 'development';
var sequelize;
if(env === 'production'){
sequelize = new Sequelize(process.env.DATABASE_URL, {
'dialect': 'postgres'
});
} else {
sequelize = new Sequelize(undefined, undefined, undefined, {
'dialect': 'sqlite',
'storage': __dirname + '/data/dev-todo-api.sqlite'
});
}
// var sequelize = new Sequelize(undefined, undefined, undefined, {
// 'dialect': 'sqlite',
// 'storage': __dirname + '/data/dev-todo-api.sqlite'
// });
var db = {};
db.todo = sequelize.import(__dirname + '/models/todo.js');
db.user = sequelize.import(__dirname + '/models/user.js');
db.token = sequelize.import(__dirname + '/models/token.js');
db.sequelize = sequelize;
db.Sequelize = Sequelize;
db.todo.belongsTo(db.user);
db.user.hasMany(db.todo);
module.exports = db;