-
Notifications
You must be signed in to change notification settings - Fork 0
/
raw_query.go
57 lines (49 loc) · 1.04 KB
/
raw_query.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
package morm
import "context"
var _ Querier[any] = &RawQuerier[any]{}
type RawQuerier[T any] struct {
core
sess session
sql string
args []any
}
func (r *RawQuerier[T]) Build() (*Query, error) {
return &Query{
SQL: r.sql,
Args: r.args,
}, nil
}
func (r *RawQuerier[T]) Exec(ctx context.Context) Result {
return exec(ctx, r.sess, r.core, &QueryContext{
Builder: r,
Type: "RAW",
})
}
func (r *RawQuerier[T]) Get(ctx context.Context) (*T, error) {
res := get[T](ctx, r.core, r.sess, &QueryContext{
Builder: r,
Type: "RAW",
})
if res.Result != nil {
return res.Result.(*T), res.Err
}
return nil, res.Err
}
func (r *RawQuerier[T]) GetMulti(ctx context.Context) ([]*T, error) {
res := getMulti[T](ctx, r.core, r.sess, &QueryContext{
Builder: r,
Type: "RAW",
})
if res.Result != nil {
return res.Result.([]*T), res.Err
}
return nil, res.Err
}
func RawQuery[T any](sess session, sql string, args ...any) *RawQuerier[T] {
return &RawQuerier[T]{
sql: sql,
args: args,
core: sess.getCore(),
sess: sess,
}
}