forked from mgutz/dat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathissues_test.go
43 lines (34 loc) · 1.26 KB
/
issues_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 dat
import (
"testing"
"time"
"gopkg.in/stretchr/testify.v1/assert"
)
func TestIssue26(t *testing.T) {
type Model struct {
ID int64 `json:"id" db:"id"`
CreatedAt time.Time `json:"createdAt" db:"created_at"`
UpdatedAt time.Time `json:"updatedAt" db:"updated_at"`
}
type Customer struct {
Model
First string `json:"first" db:"first"`
Last string `json:"last" db:"last"`
}
customer := Customer{}
sql, args :=
Update("customers").
SetBlacklist(customer, "id", "created_at", "updated_at").
Where("id = $1", customer.ID).
Returning("updated_at").ToSQL()
assert.Equal(t, sql, `UPDATE "customers" SET "first" = $1, "last" = $2 WHERE (id = $3) RETURNING "updated_at"`)
assert.Exactly(t, args, []interface{}{"", "", int64(0)})
}
func TestIssue29(t *testing.T) {
sql, args := Select("a").From("people").Where("email = $1", "[email protected]").OrderBy("people.name <-> $1", "foo").ToSQL()
assert.Equal(t, sql, `SELECT a FROM people WHERE (email = $1) ORDER BY people.name <-> $2`)
assert.Exactly(t, args, []interface{}{"[email protected]", "foo"})
sql2, _, err := Interpolate(sql, args)
assert.NoError(t, err)
assert.Equal(t, stripWS(`SELECT a FROM people WHERE (email = '[email protected]') ORDER BY people.name <-> 'foo'`), stripWS(sql2))
}