forked from Masterminds/squirrel
-
Notifications
You must be signed in to change notification settings - Fork 38
/
placeholder_test.go
43 lines (35 loc) · 1.02 KB
/
placeholder_test.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
43
package sqrl
import (
"strings"
"testing"
"github.com/stretchr/testify/assert"
)
func TestQuestion(t *testing.T) {
sql := "x = ? AND y = ?"
s, _ := Question.ReplacePlaceholders(sql)
assert.Equal(t, sql, s)
}
func TestDollar(t *testing.T) {
sql := "x = ? AND y = ?"
s, _ := Dollar.ReplacePlaceholders(sql)
assert.Equal(t, "x = $1 AND y = $2", s)
}
func TestPlaceholders(t *testing.T) {
assert.Equal(t, Placeholders(2), "?,?")
}
func TestEscape(t *testing.T) {
sql := "SELECT uuid, \"data\" #> '{tags}' AS tags FROM nodes WHERE \"data\" -> 'tags' ??| array['?'] AND enabled = ?"
s, _ := Dollar.ReplacePlaceholders(sql)
assert.Equal(t, "SELECT uuid, \"data\" #> '{tags}' AS tags FROM nodes WHERE \"data\" -> 'tags' ?| array['$1'] AND enabled = $2", s)
}
func BenchmarkPlaceholdersArray(b *testing.B) {
var count = b.N
placeholders := make([]string, count)
for i := 0; i < count; i++ {
placeholders[i] = "?"
}
var _ = strings.Join(placeholders, ",")
}
func BenchmarkPlaceholdersStrings(b *testing.B) {
Placeholders(b.N)
}