1
0
mirror of https://github.com/jackc/pgx.git synced 2025-04-28 05:37:41 +00:00
Jack Christensen 72f584d993 Add QueryArgs
2014-05-21 08:17:24 -05:00

30 lines
683 B
Go

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.FormatInt(int64(i), 10)
}
}
// 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.FormatInt(int64(len(*qa)), 10)
}