Konfi-Castle-Kasino/pkg/models/db.go

29 lines
581 B
Go
Raw Normal View History

2019-09-01 20:59:51 +00:00
package models
import (
"git.kolaente.de/konrad/Konfi-Castle-Kasino/pkg/config"
"github.com/go-xorm/xorm"
"github.com/labstack/gommon/log"
2019-09-05 19:35:07 +00:00
_ "github.com/mattn/go-sqlite3" // Needed for sqlite compatibility
2019-09-01 20:59:51 +00:00
"xorm.io/core"
)
var x *xorm.Engine
2019-09-05 19:35:07 +00:00
// DBinit creates the initial db connection and does migrations
2019-09-01 20:59:51 +00:00
func DBinit() {
var err error
x, err = xorm.NewEngine("sqlite3", config.GetDBFile())
if err != nil {
2019-09-02 20:33:11 +00:00
log.Fatal(err)
2019-09-01 20:59:51 +00:00
}
x.SetMapper(core.GonicMapper{})
2019-09-11 17:22:22 +00:00
x.ShowSQL(false)
2019-09-01 20:59:51 +00:00
x.Logger().SetLevel(core.LOG_DEBUG)
2019-09-14 17:15:41 +00:00
x.Sync(&Kofi{}, &Community{}, &Metric{})
2019-09-01 20:59:51 +00:00
return
}