Replace panics with log.Fatals

This commit is contained in:
Deluan 2024-05-21 17:48:46 -04:00
parent 55bff343cd
commit f88d3f82da
2 changed files with 8 additions and 11 deletions

View File

@ -68,17 +68,20 @@ func Db() DB {
}
log.Debug("Opening DataBase", "dbPath", Path, "driver", Driver)
// Create a read database connection
rdb, err := sql.Open(Driver+"_custom", Path)
if err != nil {
panic(err)
log.Fatal("Error opening read database", err)
}
rdb.SetMaxOpenConns(max(4, runtime.NumCPU()))
// Create a write database connection
wdb, err := sql.Open(Driver+"_custom", Path)
if err != nil {
panic(err)
log.Fatal("Error opening write database", err)
}
wdb.SetMaxOpenConns(1)
return &db{
readDB: rdb,
writeDB: wdb,

View File

@ -29,18 +29,12 @@ update media_file set updated_at = '0001-01-01';
return err
}
var (
once sync.Once
initialized bool
)
func isDBInitialized(tx *sql.Tx) bool {
once.Do(func() {
return sync.OnceValue(func() bool {
rows, err := tx.Query("select count(*) from property where id=?", consts.InitialSetupFlagKey)
checkErr(err)
initialized = checkCount(rows) > 0
})
return initialized
return checkCount(rows) > 0
})()
}
func checkCount(rows *sql.Rows) (count int) {