-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathtx.go
More file actions
40 lines (32 loc) · 699 Bytes
/
Copy pathtx.go
File metadata and controls
40 lines (32 loc) · 699 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
37
38
39
40
package csvq
import (
"context"
"database/sql/driver"
"github.com/mithrandie/csvq/lib/parser"
"github.com/mithrandie/csvq/lib/query"
)
type Tx struct {
proc *query.Processor
}
func NewTx(proc *query.Processor) (driver.Tx, error) {
proc.Tx.AutoCommit = false
return &Tx{
proc: proc,
}, nil
}
func (tx Tx) Commit() error {
expr := parser.TransactionControl{Token: parser.COMMIT}
err := tx.proc.Commit(context.Background(), expr)
if err == nil {
tx.proc.Tx.AutoCommit = true
}
return err
}
func (tx Tx) Rollback() error {
expr := parser.TransactionControl{Token: parser.ROLLBACK}
err := tx.proc.Rollback(expr)
if err == nil {
tx.proc.Tx.AutoCommit = true
}
return err
}