go_import_excel_pg/internal/repository/db.go

56 lines
1.7 KiB
Go
Raw Permalink Normal View History

2024-02-22 10:43:39 +07:00
package repository
import (
"context"
"git.nochill.in/nochill/excel_import_playground/model"
"github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5/pgconn"
"github.com/jackc/pgx/v5/pgxpool"
)
type Querier interface {
FindLastPatientInCertainFasyankes(ctx context.Context, fasyankes_id int32) (model.Patient, error)
FindPatientByNoRm(ctx context.Context, noRm string) (model.Patient, error)
FindPatientByNik(ctx context.Context, nik string) (model.Patient, error)
FindPatientByBPJSCode(ctx context.Context, BPJSCode string) (model.Patient, error)
UpdatePatientNik(ctx context.Context, nik *string, patientId int32) error
UpdatePatient(ctx context.Context, arg UpdatePatientParams, patientId int32) (model.Patient, error)
// UpdatePatient(ctx context.Context, patientId int32, arg UpdatePatientParams) (model.Patient, error)
GenerateNoRm(ctx context.Context, fasyankesId int32) (string, error)
CreateKeluarga(ctx context.Context, arg model.Keluarga) (model.Keluarga, error)
CreateAlamat(ctx context.Context, arg model.Alamat) (model.Alamat, error)
FindWilayahByName(ctx context.Context, name string) (model.Wilayah, error)
}
type DBTX interface {
Exec(context.Context, string, ...interface{}) (pgconn.CommandTag, error)
Query(context.Context, string, ...interface{}) (pgx.Rows, error)
QueryRow(context.Context, string, ...interface{}) pgx.Row
}
type Queries struct {
db DBTX
}
type UpdateableField[T any] struct {
IsFilled bool `default:"false"`
Value T `default:"nil"`
}
func New(db DBTX) *Queries {
return &Queries{db: db}
}
func NewTx(db DBTX) *Queries {
return &Queries{db: db}
}
func (q *Queries) WithTx(tx pgx.Tx) *Queries {
return &Queries{
db: tx,
}
}
var DbPool *pgxpool.Pool