blob: 7ee0f2a0a68e4a123304205924928a7bb489db20 (
plain)
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
|
package pgx
import (
"strconv"
)
// QueryArgs is a container for arguments to an SQL query. It is helpful when
// building SQL statements where the number of arguments is variable.
type QueryArgs []interface{}
var placeholders []string
func init() {
placeholders = make([]string, 64)
for i := 1; i < 64; i++ {
placeholders[i] = "$" + strconv.Itoa(i)
}
}
// Append adds a value to qa and returns the placeholder value for the
// argument. e.g. $1, $2, etc.
func (qa *QueryArgs) Append(v interface{}) string {
*qa = append(*qa, v)
if len(*qa) < len(placeholders) {
return placeholders[len(*qa)]
}
return "$" + strconv.Itoa(len(*qa))
}
|