-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcall.go
37 lines (31 loc) · 942 Bytes
/
call.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
package dat
// CallBuilder is a store procedure call builder.
type CallBuilder struct {
Execer
args []interface{}
isInterpolated bool
sproc string
}
// NewCallBuilder creates a new CallBuilder for the given sproc name and args.
func NewCallBuilder(sproc string, args ...interface{}) *CallBuilder {
if sproc == "" {
logger.Error("Invalid sproc name", "name", sproc)
return nil
}
return &CallBuilder{sproc: sproc, args: args, isInterpolated: EnableInterpolation}
}
// ToSQL serializes CallBuilder to a SQL string returning
// valid SQL with placeholders an a slice of query arguments.
func (b *CallBuilder) ToSQL() (string, []interface{}) {
buf := bufPool.Get()
defer bufPool.Put(buf)
buf.WriteString("SELECT * FROM ")
buf.WriteString(b.sproc)
length := len(b.args)
if length > 0 {
buildPlaceholders(buf, 1, length)
return buf.String(), b.args
}
buf.WriteString("()")
return buf.String(), nil
}