Skip to content

Commit

Permalink
Make sure arguments end up in their place
Browse files Browse the repository at this point in the history
  • Loading branch information
xiam committed Feb 15, 2017
1 parent 03a584c commit e217b36
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions lib/sqlbuilder/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,19 @@ func TestSelect(t *testing.T) {
b.Select().Distinct(db.Raw(`ON ? col1`, []interface{}{db.Raw(`SELECT foo FROM bar`), db.Raw(`SELECT baz from qux`)})).Columns("col2", "col3").Distinct("col4", "col5").From("artist").String(),
)

assert.Equal(
`SELECT DISTINCT ON ((SELECT foo FROM bar, SELECT baz from qux)) col1, "col2", "col3", "col4", "col5" FROM "artist"`,
b.Select().Distinct(db.Raw(`ON (?) col1`, []db.RawValue{db.Raw(`SELECT foo FROM bar`), db.Raw(`SELECT baz from qux`)})).Columns("col2", "col3").Distinct("col4", "col5").From("artist").String(),
)
{
q := b.Select().Distinct(db.Raw(`ON (?) col1`, []db.RawValue{db.Raw(`SELECT foo FROM bar WHERE id = ?`, 1), db.Raw(`SELECT baz from qux WHERE id = 2`)})).Columns("col2", "col3").Distinct("col4", "col5").From("artist").
Where("id", 3)
assert.Equal(
`SELECT DISTINCT ON ((SELECT foo FROM bar WHERE id = $1, SELECT baz from qux WHERE id = 2)) col1, "col2", "col3", "col4", "col5" FROM "artist" WHERE ("id" = $2)`,
q.String(),
)

assert.Equal(
[]interface{}{1, 3},
q.Arguments(),
)
}

{
rawCase := db.Raw("CASE WHEN id IN ? THEN 0 ELSE 1 END", []int{1000, 2000})
Expand Down

0 comments on commit e217b36

Please sign in to comment.