-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuilder.go
63 lines (50 loc) · 1.38 KB
/
builder.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package torm
import (
"context"
"database/sql"
"time"
"github.com/jmoiron/sqlx"
)
type querier interface {
PrepareNamedContext(ctx context.Context, query string) (*sqlx.NamedStmt, error)
NamedExecContext(ctx context.Context, query string, arg interface{}) (sql.Result, error)
}
type handler interface {
GetContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error
SelectContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error
NamedExecContext(ctx context.Context, query string, arg interface{}) (sql.Result, error)
ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
Rebind(query string) string
PrepareNamedContext(ctx context.Context, query string) (*sqlx.NamedStmt, error)
}
type SQL struct {
Query string
Args []interface{}
}
type Builder struct {
h handler
ts *time.Time
}
func NewBuilder(h handler) *Builder {
return &Builder{
h: h,
}
}
func (t Builder) Querier() querier {
return t.h
}
func (t Builder) Select(f ...string) *selectBuilder {
return newSelect(t.h, f...)
}
func (t Builder) Insert(f ...string) *insertBuilder {
return newInsert(t.h, t.ts, f...)
}
func (t Builder) Update(f ...string) *updateBuilder {
return newUpdate(t.h, t.ts, f...)
}
func (t Builder) Delete() *deleteBuilder {
return newDelete(t.h)
}
func (t *Builder) SetTime(ts *time.Time) {
t.ts = ts
}