Skip to content
This repository was archived by the owner on Jun 14, 2019. It is now read-only.

Commit a4a881a

Browse files
committed
add test for sub query
1 parent b1ee4db commit a4a881a

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

builder_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import (
88
"fmt"
99
"reflect"
1010
"testing"
11+
12+
"github.com/stretchr/testify/assert"
1113
)
1214

1315
type MyInt int
@@ -201,3 +203,17 @@ func TestBuilderDelete(t *testing.T) {
201203
}
202204
fmt.Println(sql, args)
203205
}
206+
207+
func TestSubquery(t *testing.T) {
208+
subb := Select("id").From("table_b").Where(Eq{"b": "a"})
209+
b := Select("a, b").From("table_a").Where(
210+
Eq{
211+
"id": 23,
212+
"b_id": subb,
213+
},
214+
)
215+
sql, args, err := b.ToSQL()
216+
assert.NoError(t, err)
217+
assert.EqualValues(t, "SELECT a, b FROM table_a WHERE id=? AND b_id=(SELECT id FROM table_b WHERE b=?)", sql)
218+
assert.EqualValues(t, []interface{}{23, "a"}, args)
219+
}

0 commit comments

Comments
 (0)