-
Notifications
You must be signed in to change notification settings - Fork 5
/
schema.go
40 lines (33 loc) · 1.11 KB
/
schema.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
34
35
36
37
38
39
40
package schema
import (
"context"
"database/sql"
"errors"
)
// DefaultTableName defines the name of the database table which will
// hold the status of applied migrations
const DefaultTableName = "schema_migrations"
// ErrNilDB is thrown when the database pointer is nil
var ErrNilDB = errors.New("DB pointer is nil")
// DB defines the interface for a *sql.DB, which can be used to get a concrete
// connection to the database.
type DB interface {
Conn(ctx context.Context) (*sql.Conn, error)
}
// Connection defines the interface for a *sql.Conn, which can both start a new
// transaction and run queries.
type Connection interface {
Transactor
Queryer
}
// Queryer is something which can execute a Query (either a sql.DB
// or a sql.Tx)
type Queryer interface {
ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
}
// Transactor defines the interface for the Begin method from the *sql.DB
//
type Transactor interface {
BeginTx(ctx context.Context, opts *sql.TxOptions) (*sql.Tx, error)
}