Added: creating database, sql tx repository
This commit is contained in:
34
internal/db/repository.go
Normal file
34
internal/db/repository.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package db
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
)
|
||||
|
||||
type TxRepository struct {
|
||||
db *sql.DB
|
||||
}
|
||||
|
||||
func NewTxRepository(instance *sql.DB) ITxRepository {
|
||||
return &TxRepository{
|
||||
db: instance,
|
||||
}
|
||||
}
|
||||
|
||||
func (t TxRepository) Begin() (*sql.Tx, error) {
|
||||
tx, err := t.db.Begin()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return tx, nil
|
||||
}
|
||||
|
||||
func (TxRepository) RollbackOnError(tx *sql.Tx, errObserve *error) {
|
||||
if *errObserve != nil {
|
||||
tx.Rollback()
|
||||
}
|
||||
}
|
||||
|
||||
func (TxRepository) Commit(tx *sql.Tx) error {
|
||||
return tx.Commit()
|
||||
}
|
||||
Reference in New Issue
Block a user