-
Notifications
You must be signed in to change notification settings - Fork 0
/
mutationset_test.go
52 lines (47 loc) · 1.91 KB
/
mutationset_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
44
45
46
47
48
49
50
51
52
package pgtalk
import "testing"
func TestMutationSet_Insert(t *testing.T) {
m := MakeMutationSet[poly](polyTable, polyColumns, MutationInsert)
if got, want := oneliner(SQL(m)), "INSERT INTO public.polies (ftime,ffloat) VALUES ($1,$2)"; got != want {
t.Errorf("got [%v:%T] want [%v:%T]", got, got, want, want)
}
{
m := MakeMutationSet[poly](polyTable, polyColumns, MutationDelete)
if got, want := oneliner(SQL(m)), "DELETE FROM public.polies p1"; got != want {
t.Errorf("got [%v:%T] want [%v:%T]", got, got, want, want)
}
}
{
m := MakeMutationSet[poly](polyTable, polyColumns, MutationDelete)
m = m.Where(polyFFloat.Equals(42.0))
if got, want := oneliner(SQL(m)), "DELETE FROM public.polies p1 WHERE (p1.ffloat = 42)"; got != want {
t.Errorf("got [%v:%T] want [%v:%T]", got, got, want, want)
}
}
{
toUpdate := []ColumnAccessor{}
toUpdate = append(toUpdate, polyFFloat.Set(42.0))
m := MakeMutationSet[poly](polyTable, toUpdate, MutationUpdate)
if got, want := oneliner(SQL(m)), "UPDATE public.polies p1 SET ffloat = $1"; got != want {
t.Errorf("got [%v:%T] want [%v:%T]", got, got, want, want)
}
}
{
toUpdate := []ColumnAccessor{}
toUpdate = append(toUpdate, polyFFloat.Set(42.0))
m := MakeMutationSet[poly](polyTable, toUpdate, MutationUpdate)
m = m.Where(polyFFloat.Equals(12.0))
if got, want := oneliner(SQL(m)), "UPDATE public.polies p1 SET ffloat = $1 WHERE (p1.ffloat = 12)"; got != want {
t.Errorf("got [%v:%T] want [%v:%T]", got, got, want, want)
}
}
}
func TestInsertWithQueryArgument(t *testing.T) {
toUpdate := []ColumnAccessor{}
toUpdate = append(toUpdate, polyFFloat.Set(42.0))
v12 := NewParameter(12.0)
m := MakeMutationSet[poly](polyTable, toUpdate, MutationUpdate).Where(polyFFloat.Equals(v12))
if got, want := oneliner(SQL(m)), "UPDATE public.polies p1 SET ffloat = $1 WHERE (p1.ffloat = ?)"; got != want {
t.Errorf("got [%v:%T] want [%v:%T]", got, got, want, want)
}
}