mirror of
https://github.com/hanzoai/sqlbuilder.git
synced 2026-10-01 00:37:42 +00:00
support DISTINCT
This commit is contained in:
@@ -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
@@ -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]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user