forked from l3uddz/wantarr
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdb.go
36 lines (29 loc) · 710 Bytes
/
db.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
package database
import (
"github.com/jinzhu/gorm"
_ "github.com/jinzhu/gorm/dialects/sqlite"
"github.com/migz93/wantarr/logger"
stringutils "github.com/migz93/wantarr/utils/strings"
)
var (
db *gorm.DB
log = logger.GetLogger("db")
)
func Init(databaseFilePath string) error {
// show log
log.Infof("Using %s = %q", stringutils.StringLeftJust("DATABASE", " ", 10), databaseFilePath)
// open database
if dtb, err := gorm.Open("sqlite3", databaseFilePath); err != nil {
return err
} else {
db = dtb
}
// migrate schema
db.AutoMigrate(&MediaItem{})
return nil
}
func Close() {
if err := db.Close(); err != nil {
log.WithError(err).Error("Failed closing database gracefully...")
}
}