-
Notifications
You must be signed in to change notification settings - Fork 3
/
data-model.js
43 lines (32 loc) · 939 Bytes
/
data-model.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
32
33
34
35
36
37
38
39
40
41
42
43
var Sequelize = require('sequelize');
var url = require("url");
if (process.env.ENVIRONMENT === 'heroku') {
var dbinfo = url.parse(process.env.CLEARDB_DATABASE_URL);
var user = dbinfo.auth.split(':')[0];
var pass = dbinfo.auth.split(':')[1];
var db = new Sequelize(dbinfo.pathname.substring(1), user, pass, {
host: dbinfo.host,
dialect: 'mysql'
})
} else {
var db = new Sequelize('bred', process.env.C9_USER, '', {
host: 'localhost',
dialect: 'mysql'
});
}
var Path = db.define('path', {
title: Sequelize.STRING
});
var Point = db.define('point', {
timestamp: Sequelize.DATE,
latitude: Sequelize.FLOAT,
longitude: Sequelize.FLOAT,
message: Sequelize.STRING
});
Path.hasMany(Point);
//db.sync({force:true}); // comment this line after the first run reboot: {force:true}
db.sync(); // comment this line after the first run
module.exports = {
Path: Path,
Point: Point
};