Enha: timer package

This commit is contained in:
Grail Finder
2025-07-07 15:01:15 +03:00
parent 75651d7f76
commit 22ddc88d82
5 changed files with 153 additions and 126 deletions

View File

@ -2,6 +2,7 @@ package repos
import (
"context"
"gralias/config"
"log/slog"
"os"
"sync"
@ -20,6 +21,7 @@ type AllRepos interface {
SettingsRepo
CardMarksRepo
PlayerStatsRepo
JournalRepo
InitTx(ctx context.Context) (context.Context, *sqlx.Tx, error)
Close()
}
@ -32,9 +34,14 @@ type RepoProvider struct {
var RP AllRepos
func init() {
cfg := config.LoadConfigOrDefault("")
// sqlite3 has lock on write, so we need to have only one connection per whole app
// https://github.com/mattn/go-sqlite3/issues/274#issuecomment-232942571
RP = NewRepoProvider(cfg.DBPath)
}
func NewRepoProvider(pathToDB string) *RepoProvider {
func NewRepoProvider(pathToDB string) AllRepos {
db, err := sqlx.Connect("sqlite3", pathToDB)
if err != nil {
slog.Error("Unable to connect to database", "error", err)