47 lines
773 B
Go
47 lines
773 B
Go
package dbrepo
|
|
|
|
import (
|
|
"database/sql"
|
|
"go-udemy-web-1/internal/config"
|
|
"go-udemy-web-1/internal/repository"
|
|
"go-udemy-web-1/internal/repository/sqlc"
|
|
|
|
"github.com/jackc/pgx/v5"
|
|
)
|
|
|
|
type postgresDBRepo struct {
|
|
App *config.AppConfig
|
|
DB *sql.DB
|
|
}
|
|
|
|
type pgcDBRepo struct {
|
|
App *config.AppConfig
|
|
Q *sqlc.Queries
|
|
}
|
|
|
|
type testDBRepo struct {
|
|
App *config.AppConfig
|
|
DB *sql.DB
|
|
}
|
|
|
|
func NewPostgresRepo(conn *sql.DB, a *config.AppConfig) repository.DatabaseRepo {
|
|
return &postgresDBRepo{
|
|
App: a,
|
|
DB: conn,
|
|
}
|
|
}
|
|
|
|
func NewTestingRepo(a *config.AppConfig) repository.DatabaseRepo {
|
|
return &testDBRepo{
|
|
App: a,
|
|
}
|
|
}
|
|
|
|
func NewPgcRepo(conn *pgx.Conn, a *config.AppConfig) repository.DatabaseRepo {
|
|
q := sqlc.New(conn)
|
|
return &pgcDBRepo{
|
|
App: a,
|
|
Q: q,
|
|
}
|
|
}
|