forked from tietang/dbx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
runner.go
44 lines (37 loc) · 764 Bytes
/
runner.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
41
42
43
44
package dbx
import (
"database/sql"
"database/sql/driver"
"github.com/tietang/dbx/mapping"
)
type Mapper func(model interface{}, rows *sql.Rows) (interface{}, error)
type RowsMapper func(rows *sql.Rows) (interface{}, error)
type RowMapper func(row *sql.Row) (interface{}, error)
type TxRunner struct {
*Runner
driver.Tx
}
var (
_ mapperExecutor = new(Runner)
_ sqlExecutor = new(Runner)
)
type Runner struct {
sqlExecutor
mapperExecutor
mapping.EntityMapper
ILogger
LoggerSettings
}
func NewTxRunner(tx *sql.Tx) *TxRunner {
r := &TxRunner{}
r.Runner = &Runner{}
r.sqlExecutor = tx
r.Tx = tx
return r
}
func NewRunner(se sqlExecutor, em mapping.EntityMapper) *Runner {
r := &Runner{}
r.sqlExecutor = se
r.EntityMapper = em
return r
}