-
Notifications
You must be signed in to change notification settings - Fork 5
/
list_helpers.go
42 lines (36 loc) · 910 Bytes
/
list_helpers.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
package dat
import (
"github.com/Janulka/dat/common"
)
var bufPool = common.NewBufferPool()
func writeIdentifiers(buf common.BufferWriter, columns []string, join string) {
for i, column := range columns {
if i > 0 {
buf.WriteString(join)
}
Dialect.WriteIdentifier(buf, column)
}
}
func writeIdentifier(buf common.BufferWriter, name string) {
Dialect.WriteIdentifier(buf, name)
}
func buildPlaceholders(buf common.BufferWriter, start, length int) {
// Build the placeholder like "($1,$2,$3)"
buf.WriteRune('(')
for i := start; i < start+length; i++ {
if i > start {
buf.WriteRune(',')
}
writePlaceholder(buf, i)
}
buf.WriteRune(')')
}
// joinPlaceholders returns $1, $2 ... , $n
func writePlaceholders(buf common.BufferWriter, length int, join string, offset int) {
for i := 0; i < length; i++ {
if i > 0 {
buf.WriteString(join)
}
writePlaceholder(buf, i+offset)
}
}