github.com/pjdufour-truss/pop@v4.11.2-0.20190705085848-4c90b0ff4d5a+incompatible/tx.go (about) 1 package pop 2 3 import ( 4 "math/rand" 5 "time" 6 7 "github.com/jmoiron/sqlx" 8 "github.com/pkg/errors" 9 ) 10 11 func init() { 12 rand.Seed(time.Now().UnixNano()) 13 } 14 15 // Tx stores a transaction with an ID to keep track. 16 type Tx struct { 17 ID int 18 *sqlx.Tx 19 } 20 21 func newTX(db *dB) (*Tx, error) { 22 t := &Tx{ 23 ID: rand.Int(), 24 } 25 tx, err := db.Beginx() 26 t.Tx = tx 27 return t, errors.Wrap(err, "could not create new transaction") 28 } 29 30 // Transaction simply returns the current transaction, 31 // this is defined so it implements the `Store` interface. 32 func (tx *Tx) Transaction() (*Tx, error) { 33 return tx, nil 34 } 35 36 // Close does nothing. This is defined so it implements the `Store` interface. 37 func (tx *Tx) Close() error { 38 return nil 39 }