support DISTINCT

This commit is contained in:
Huan Du
2017-12-28 01:39:42 +08:00
parent d6f157e3a4
commit be8a7cbb32
2 changed files with 6 additions and 1 deletions
+5
View File
@@ -123,6 +123,11 @@ func (sb *SelectBuilder) String() string {
func (sb *SelectBuilder) Build() (sql string, args []interface{}) {
buf := &bytes.Buffer{}
buf.WriteString("SELECT ")
if sb.distinct {
buf.WriteString("DISTINCT ")
}
buf.WriteString(strings.Join(sb.selectCols, ", "))
buf.WriteString(" FROM ")
buf.WriteString(strings.Join(sb.tables, ", "))
+1 -1
View File
@@ -29,6 +29,6 @@ func ExampleSelectBuilder() {
fmt.Println(args)
// Output:
// SELECT id, name, COUNT(*) AS t FROM demo.user WHERE id > ? AND name LIKE ? AND (id_card IS NULL OR status IN (?, ?, ?)) AND modified_at > created_at + ? GROUP BY status HAVING status NOT IN (?, ?) ORDER BY modified_at ASC LIMIT 10 OFFSET 5
// SELECT DISTINCT id, name, COUNT(*) AS t FROM demo.user WHERE id > ? AND name LIKE ? AND (id_card IS NULL OR status IN (?, ?, ?)) AND modified_at > created_at + ? GROUP BY status HAVING status NOT IN (?, ?) ORDER BY modified_at ASC LIMIT 10 OFFSET 5
// [1234 %Du 1 2 5 86400 4 5]
}