Files
gralias/repos/main.go
Grail Finder 130ed3763b Fix: unittests
2025-07-02 19:00:39 +03:00

42 lines
660 B
Go

package repos
import (
"context"
"log/slog"
"os"
"github.com/jmoiron/sqlx"
_ "github.com/mattn/go-sqlite3"
)
type AllRepos interface {
RoomsRepo
ActionsRepo
PlayersRepo
SessionsRepo
}
type RepoProvider struct {
DB *sqlx.DB
}
func NewRepoProvider(pathToDB string) *RepoProvider {
db, err := sqlx.Connect("sqlite3", pathToDB)
if err != nil {
slog.Error("Unable to connect to database", "error", err)
os.Exit(1)
}
slog.Info("Successfully connected to database")
return &RepoProvider{
DB: db,
}
}
func getDB(ctx context.Context, db *sqlx.DB) sqlx.ExtContext {
if tx, ok := ctx.Value("tx").(*sqlx.Tx);
ok {
return tx
}
return db
}