mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-04 13:07:36 +03:00
35 lines
589 B
Go
35 lines
589 B
Go
package persistence
|
|
|
|
import (
|
|
"sync"
|
|
|
|
"github.com/cloudsonic/sonic-server/conf"
|
|
"github.com/siddontang/ledisdb/config"
|
|
"github.com/siddontang/ledisdb/ledis"
|
|
)
|
|
|
|
var (
|
|
_ledisInstance *ledis.Ledis
|
|
_dbInstance *ledis.DB
|
|
once sync.Once
|
|
)
|
|
|
|
func Db() *ledis.DB {
|
|
once.Do(func() {
|
|
config := config.NewConfigDefault()
|
|
config.DataDir = conf.Sonic.DbPath
|
|
l, _ := ledis.Open(config)
|
|
instance, err := l.Select(0)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
_ledisInstance = l
|
|
_dbInstance = instance
|
|
})
|
|
return _dbInstance
|
|
}
|
|
|
|
func dropDb() {
|
|
Db()
|
|
_ledisInstance.FlushAll()
|
|
}
|