BufPool SetParamNames

This commit is contained in:
Patrick O'brien 2016-08-13 23:59:02 +10:00
parent ce65125ade
commit 5922dc89bd

View file

@ -280,13 +280,17 @@ func Placeholders(count int, start int, group int) string {
// list of parameter names for a template statement SET clause. // list of parameter names for a template statement SET clause.
// eg: "col1"=$1, "col2"=$2, "col3"=$3 // eg: "col1"=$1, "col2"=$2, "col3"=$3
func SetParamNames(columns []string) string { func SetParamNames(columns []string) string {
names := make([]string, 0, len(columns)) buf := GetBuffer()
counter := 0 defer PutBuffer(buf)
for _, c := range columns {
counter++ for i, c := range columns {
names = append(names, fmt.Sprintf(`"%s"=$%d`, c, counter)) buf.WriteString(fmt.Sprintf(`"%s"=$%d`, c, i+1))
if i < len(columns)-1 {
buf.WriteString(", ")
}
} }
return strings.Join(names, ", ")
return buf.String()
} }
// WhereClause returns the where clause using start as the $ flag index // WhereClause returns the where clause using start as the $ flag index