/
main.go
49 lines (35 loc) · 1.06 KB
/
main.go
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
package data
import (
"context"
"github.com/ritsec/ops-bot-iii/ent"
"github.com/sirupsen/logrus"
_ "github.com/mattn/go-sqlite3"
)
var (
// Client is the ent client
Client *ent.Client
// Ctx is the context for the ent client
Ctx context.Context = context.Background()
// User is the struct references user
User *user_s = &user_s{}
// Signin is the struct references signin
Signin *signin_s = &signin_s{}
// Vote is the struct references vote
Vote *vote_s = &vote_s{}
// VoteResult is the struct reference vote_result
VoteResult *vote_result_s = &vote_result_s{}
// Shitposts is the struct reference shitposts
Shitposts *shitpost_s = &shitpost_s{}
// Birthday is the struct reference birthday
Birthday *birthday_s = &birthday_s{}
)
func init() {
client, err := ent.Open("sqlite3", "file:data.sqlite?_loc=auto&cache=shared&_fk=1")
if err != nil {
logrus.WithError(err).Fatal("Failed to open database connection")
}
Client = client
if err := client.Schema.Create(Ctx); err != nil {
logrus.WithError(err).Fatal("Failed to create schema")
}
}