-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathmain.go
43 lines (39 loc) · 911 Bytes
/
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
package main
import (
"log"
"github.com/bashbunni/project-management/entry"
"github.com/bashbunni/project-management/project"
"github.com/bashbunni/project-management/tui"
"github.com/pkg/errors"
"gorm.io/driver/sqlite"
"gorm.io/gorm"
)
func openSqlite() *gorm.DB {
db, err := gorm.Open(sqlite.Open("new.db"), &gorm.Config{})
if err != nil {
log.Fatalf("unable to open database: %v", err)
}
err = db.AutoMigrate(&entry.Entry{}, &project.Project{})
if err != nil {
log.Fatal(err)
}
return db
}
func main() {
db := openSqlite()
pr := project.GormRepository{DB: db}
er := entry.GormRepository{DB: db}
projects, err := pr.GetAllProjects()
if err != nil {
log.Fatal(err)
}
if len(projects) < 1 {
name := project.NewProjectPrompt()
_, err := pr.CreateProject(name)
if err != nil {
log.Fatal(errors.Wrap(err, "error creating project"))
}
} else {
tui.StartTea(pr, er)
}
}