This repository was archived by the owner on Oct 18, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdatabase.go
More file actions
105 lines (92 loc) · 4.12 KB
/
database.go
File metadata and controls
105 lines (92 loc) · 4.12 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
package main
import (
"database/sql"
"log"
"time"
"github.com/go-sql-driver/mysql"
"gopkg.in/gorp.v2"
)
type Giveaway struct {
Id int `db:"id, primarykey, autoincrement"`
StartTime time.Time `db:"start_time"`
EndTime mysql.NullTime `db:"end_time"`
GuildId string `db:"guild_id,size:255"`
GuildName string `db:"guild_name,size:255"`
WinnerId sql.NullString `db:"winner_id,size:255"`
WinnerName sql.NullString `db:"winner_name,size:255"`
InfoMessageId sql.NullString `db:"info_message_id,size:255"`
Code sql.NullString `db:"code,size:255"`
}
type Participant struct {
Id int `db:"id, primarykey, autoincrement"`
UserName string `db:"user_name,size:255"`
UserId string `db:"user_id,size:255"`
GiveawayId int `db:"giveaway_id"`
CreateTime time.Time `db:"create_time"`
GuildName string `db:"guild_name,size:255"`
GuildId string `db:"guild_id,size:255"`
MessageId string `db:"message_id,size:255"`
ChannelId string `db:"channel_id,size:255"`
IsAccepted sql.NullBool `db:"is_accepted"`
AcceptTime mysql.NullTime `db:"accept_time"`
AcceptUser sql.NullString `db:"accept_user,size:255"`
AcceptUserId sql.NullString `db:"accept_user_id,size:255"`
}
type ParticipantCandidate struct {
Id int `db:"id, primarykey, autoincrement"`
CandidateId string `db:"candidate_id,size:255"`
CandidateName string `db:"candidate_name,size:255"`
CandidateApproverId string `db:"candidate_approver_id,size:255"`
CandidateApproverName string `db:"candidate_approver_name,size:255"`
GuildId string `db:"guild_id,size:255"`
GuildName string `db:"guild_name,size:255"`
MessageId string `db:"message_id,size:255"`
ChannelId string `db:"channel_id,size:255"`
IsAccepted sql.NullBool `db:"is_accepted"`
AcceptTime mysql.NullTime `db:"accept_time"`
}
type Blacklist struct {
Id int `db:"id,primarykey,autoincrement"`
GuildId string `db:"guild_id,size:255"`
UserId string `db:"user_id,size:255"`
BlacklisterId string `db:"blacklister_id,size:255"`
}
type ServerConfig struct {
Id int `db:"id,primarykey,autoincrement"`
GuildId string `db:"guild_id,size:255"`
AdminRole string `db:"admin_role,size:255"`
MainChannel string `db:"main_channel,size:255"`
ThxInfoChannel string `db:"thx_info_channel,size:255"`
HelperRoleName string `db:"helper_role_name,size:255"`
HelperRoleThxesNeeded int `db:"helper_role_thxes_needed"`
}
type MemberRole struct {
Id int `db:"id,primarykey,autoincrement"`
GuildId string `db:"guild_id,size:255"`
MemberId string `db:"member_id,size:255"`
RoleId string `db:"role_id,size:255"`
}
type ThxNotification struct {
Id int `db:"id,primarykey,autoincrement"`
MessageId string `db:"message_id,size:255"`
ThxNotificationMessageId string `db:"thx_notification_message_id,size:255"`
}
var DbMap gorp.DbMap
func InitDB() {
db, err := sql.Open("mysql", config.MysqlString)
if err != nil {
log.Panic("InitDB sql.Open(\"mysql\", " + config.MysqlString + ") " + err.Error())
}
DbMap = gorp.DbMap{Db: db, Dialect: gorp.MySQLDialect{"InnoDB", "UTF8MB4"}}
DbMap.AddTableWithName(Giveaway{}, "Giveaways").SetKeys(true, "id")
DbMap.AddTableWithName(Participant{}, "Participants").SetKeys(true, "id")
DbMap.AddTableWithName(ParticipantCandidate{}, "ParticipantCandidates").SetKeys(true, "id")
DbMap.AddTableWithName(Blacklist{}, "Blacklists").SetKeys(true, "id")
DbMap.AddTableWithName(ServerConfig{}, "ServerConfig").SetKeys(true, "id")
DbMap.AddTableWithName(MemberRole{}, "MemberRoles").SetKeys(true, "id")
DbMap.AddTableWithName(ThxNotification{}, "ThxNotifications").SetKeys(true, "id")
err = DbMap.CreateTablesIfNotExists()
if err != nil {
log.Panic("InitDB DbMap.CreateTablesIfNotExists() " + err.Error())
}
}