forked from Zane2453/Voting
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb_model.js
More file actions
112 lines (109 loc) · 2.04 KB
/
db_model.js
File metadata and controls
112 lines (109 loc) · 2.04 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/**
* Created by kuan on 2018/8/25.
*/
// http://docs.sequelizejs.com/manual/tutorial/querying.html
let config = require("./config"),
Sequelize = require("sequelize"),
sequelize;
if (config.db === "sqlite") {
sequelize = new Sequelize("questionnaire", null, null, {
define: {
charset: "utf8",
dialectOptions: {
collate: "utf8_general_ci",
},
},
logging: false,
host: "localhost",
dialect: "sqlite",
pool: {
max: 100,
min: 10,
acquire: 30000,
idle: 10000,
},
// SQLite only
storage: "./questionnaire.sqlite",
});
} else if (config.db === "mysql") {
sequelize = new Sequelize("questionnaire", config.dbUser, config.dbPassword, {
define: {
charset: "utf8",
dialectOptions: {
collate: "utf8_general_ci",
},
},
logging: false,
host: config.dbHost,
dialect: "mysql",
pool: {
max: 5,
min: 0,
acquire: 30000,
idle: 10000,
},
});
}
const question = sequelize.define("question", {
id: {
type: Sequelize.INTEGER,
primaryKey: true,
autoIncrement: true,
},
uuid: {
type: Sequelize.STRING,
},
description: {
type: Sequelize.STRING,
},
anonymous: {
type: Sequelize.BOOLEAN,
},
image: {
type: Sequelize.STRING,
},
});
const answer = sequelize.define("answer", {
option: {
type: Sequelize.STRING,
},
count: {
type: Sequelize.INTEGER,
},
color: {
type: Sequelize.STRING,
},
});
const user = sequelize.define("user", {
id: {
type: Sequelize.STRING,
primaryKey: true,
},
name: {
type: Sequelize.STRING,
},
photo: {
type: Sequelize.STRING,
},
provider: {
type: Sequelize.STRING,
},
});
const vote = sequelize.define("vote", {
id: {
type: Sequelize.INTEGER,
primaryKey: true,
},
});
question.hasMany(answer);
vote.belongsTo(user);
vote.belongsTo(question);
vote.belongsTo(answer);
let models = {
orm: sequelize,
question: question,
answer: answer,
user: user,
vote: vote,
};
exports.models = models;