forked from gobuffalo/pop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtx.go
39 lines (32 loc) · 708 Bytes
/
tx.go
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
28
29
30
31
32
33
34
35
36
37
38
39
package pop
import (
"math/rand"
"time"
"github.com/jmoiron/sqlx"
"github.com/pkg/errors"
)
func init() {
rand.Seed(time.Now().UnixNano())
}
// Tx stores a transaction with an ID to keep track.
type Tx struct {
ID int
*sqlx.Tx
}
func newTX(db *dB) (*Tx, error) {
t := &Tx{
ID: rand.Int(),
}
tx, err := db.Beginx()
t.Tx = tx
return t, errors.Wrap(err, "could not create new transaction")
}
// Transaction simply returns the current transaction,
// this is defined so it implements the `Store` interface.
func (tx *Tx) Transaction() (*Tx, error) {
return tx, nil
}
// Close does nothing. This is defined so it implements the `Store` interface.
func (tx *Tx) Close() error {
return nil
}