sqlboiler/boil/db.go

34 lines
708 B
Go
Raw Normal View History

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
}
2016-07-09 18:31:50 +02:00
// Beginner begins transactions.
type Beginner interface {
Begin() (*sql.Tx, error)
}
// Begin a transaction
func Begin() (Transactor, error) {
2016-07-09 18:31:50 +02:00
creator, ok := currentDB.(Beginner)
if !ok {
2016-07-09 18:31:50 +02:00
panic("database does not support transactions")
}
return creator.Begin()
}