-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathtx.go
More file actions
36 lines (31 loc) · 715 Bytes
/
tx.go
File metadata and controls
36 lines (31 loc) · 715 Bytes
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
package jet
import (
"database/sql"
)
// Tx represents a transaction instance.
// It can be created using Begin on the *Db object.
type Tx struct {
db *Db
tx *sql.Tx
qid string
}
// Query creates a prepared query that can be run with Rows or Run.
func (tx *Tx) Query(query string, args ...interface{}) Runnable {
q := newQuery(tx.tx, tx.db, query, args...)
q.id = tx.qid
return q
}
// Commit commits the transaction
func (tx *Tx) Commit() error {
if tx.db.LogFunc != nil {
tx.db.LogFunc(tx.qid, "COMMIT")
}
return tx.tx.Commit()
}
// Rollback rolls back the transaction
func (tx *Tx) Rollback() error {
if tx.db.LogFunc != nil {
tx.db.LogFunc(tx.qid, "ROLLBACK")
}
return tx.tx.Rollback()
}