-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.js
More file actions
63 lines (55 loc) · 1.49 KB
/
database.js
File metadata and controls
63 lines (55 loc) · 1.49 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
const Sequelize = require('sequelize');
require('dotenv').config();
const db =
process.env.NODE_ENV === 'test'
? `${process.env.DB_TEST_DATABASE}`
: `${process.env.DB_DATABASE}`;
const user =
process.env.NODE_ENV === 'test'
? `${process.env.DB_TEST_USER}`
: `${process.env.DB_USER}`;
const pass =
process.env.NODE_ENV === 'test'
? `${process.env.DB_TEST_PASS}`
: `${process.env.DB_PASS}`;
const host =
process.env.NODE_ENV === 'test'
? `${process.env.DB_TEST_HOST}`
: `${process.env.DB_HOST}`;
const orm = new Sequelize(db, user, pass, {
host,
dialect: 'mysql'
});
orm
.authenticate()
.then(() => {
console.log('Connection to DB has been established successfully.');
})
.catch(err => {
console.error('Unable to connect to the database:', err);
});
/* ///////////////////// */
/* MODELS (alphabetized) */
/* ///////////////////// */
const MapChef = orm.define('MapChef', {
chefId: Sequelize.INTEGER,
description: Sequelize.TEXT,
// imageUrl: Sequelize.STRING,
name: Sequelize.STRING,
username: Sequelize.STRING,
streetAddress: Sequelize.TEXT,
city: Sequelize.TEXT,
stateName: Sequelize.TEXT,
zip: Sequelize.INTEGER,
lat: Sequelize.INTEGER,
lng: Sequelize.INTEGER
});
// // /* //////////////////////////// */
// // /* RELATIONSHIPS (alphabetized) */
// // /* //////////////////////////// */
// // /* ///////////// */
// // /* Create Tables */
// // /* ///////////// */
orm.sync();
exports.connection = orm;
exports.MapChef = MapChef;