summaryrefslogtreecommitdiff
path: root/model/object.go
blob: bcbba3ecbeb49a0d146f26e6685d338af9156128 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package model

import (
	"database/sql"
)

type Object interface {
	Create(tx *sql.Tx) error
	Read(tx *sql.Tx) error
	Update(tx *sql.Tx) error
	Delete(tx *sql.Tx) error
}

func SafeCrud(crud func(tx *sql.Tx) error) error {
	tx, err := NewTx()
	if err != nil {
		return err
	}

	err = crud(tx)
	if err != nil {
		Rollback(tx)
		return err
	}

	return tx.Commit()
}