Enha: sqlx instead of pgx
This commit is contained in:
@ -1,11 +1,11 @@
|
||||
package repos
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log/slog"
|
||||
"os"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
"github.com/jmoiron/sqlx"
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
)
|
||||
|
||||
type AllRepos interface {
|
||||
@ -15,17 +15,17 @@ type AllRepos interface {
|
||||
}
|
||||
|
||||
type RepoProvider struct {
|
||||
DB *pgxpool.Pool
|
||||
DB *sqlx.DB
|
||||
}
|
||||
|
||||
func NewRepoProvider(pathToDB string) *RepoProvider {
|
||||
dbpool, err := pgxpool.New(context.Background(), pathToDB)
|
||||
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: dbpool,
|
||||
DB: db,
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user