voucher/internal/data/db.go

27 lines
313 B
Go

package data
import (
"context"
"gorm.io/gorm"
)
type Db struct {
db *GormDb
}
func NewDb(db *GormDb) *Db {
return &Db{
db: db,
}
}
type contextTxKey struct{}
func (d *Db) DB(ctx context.Context) *gorm.DB {
tx, ok := ctx.Value(contextTxKey{}).(*gorm.DB)
if ok {
return tx
}
return d.db.Client
}