forked from volatiletech/sqlboiler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
db.go
33 lines (26 loc) · 708 Bytes
/
db.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
package boil
import "database/sql"
// Executor can perform SQL queries.
type Executor interface {
Exec(query string, args ...interface{}) (sql.Result, error)
Query(query string, args ...interface{}) (*sql.Rows, error)
QueryRow(query string, args ...interface{}) *sql.Row
}
// Transactor can commit and rollback, on top of being able to execute queries.
type Transactor interface {
Commit() error
Rollback() error
Executor
}
// Beginner begins transactions.
type Beginner interface {
Begin() (*sql.Tx, error)
}
// Begin a transaction
func Begin() (Transactor, error) {
creator, ok := currentDB.(Beginner)
if !ok {
panic("database does not support transactions")
}
return creator.Begin()
}