refactor: better integration between db and persistence packages

Will address support for different DBs in the future (+1 squashed commit)
Squashed commits:
[a014757] refactor: better integration between `db` and `persistence` packages
This commit is contained in:
Deluan
2020-02-01 13:46:03 -05:00
committed by Deluan Quintão
parent 76ca8afc84
commit 7e65bb8f20
4 changed files with 30 additions and 27 deletions
+3 -18
View File
@@ -3,18 +3,16 @@ package persistence
import (
"context"
"reflect"
"strings"
"sync"
"github.com/astaxie/beego/orm"
"github.com/deluan/navidrome/conf"
"github.com/deluan/navidrome/db"
"github.com/deluan/navidrome/log"
"github.com/deluan/navidrome/model"
)
var (
once sync.Once
driver = "sqlite3"
once sync.Once
)
type SQLStore struct {
@@ -23,13 +21,7 @@ type SQLStore struct {
func New() model.DataStore {
once.Do(func() {
dbPath := conf.Server.DbPath
if dbPath == ":memory:" {
dbPath = "file::memory:?cache=shared"
}
log.Debug("Opening DataBase", "dbPath", dbPath, "driver", driver)
err := initORM(dbPath)
err := orm.RegisterDataBase("default", db.Driver, db.Path)
if err != nil {
panic(err)
}
@@ -147,10 +139,3 @@ func (db *SQLStore) getOrmer() orm.Ormer {
}
return db.orm
}
func initORM(dbPath string) error {
if strings.Contains(dbPath, "postgres") {
driver = "postgres"
}
return orm.RegisterDataBase("default", driver, dbPath)
}