mirror of
https://github.com/hanzoai/sqlbuilder.git
synced 2026-10-01 00:37:42 +00:00
refs #164: new API SelectMore to add more cols to SELECT after calling Select()
This commit is contained in:
@@ -134,6 +134,13 @@ func (sb *SelectBuilder) Select(col ...string) *SelectBuilder {
|
||||
return sb
|
||||
}
|
||||
|
||||
// SelectMore adds more columns in SELECT.
|
||||
func (sb *SelectBuilder) SelectMore(col ...string) *SelectBuilder {
|
||||
sb.selectCols = append(sb.selectCols, col...)
|
||||
sb.marker = selectMarkerAfterSelect
|
||||
return sb
|
||||
}
|
||||
|
||||
// Distinct marks this SELECT as DISTINCT.
|
||||
func (sb *SelectBuilder) Distinct() *SelectBuilder {
|
||||
sb.distinct = true
|
||||
|
||||
@@ -6,6 +6,9 @@ package sqlbuilder
|
||||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/huandu/go-assert"
|
||||
)
|
||||
|
||||
func ExampleSelect() {
|
||||
@@ -364,3 +367,11 @@ func ExampleSelectBuilder_With() {
|
||||
// Output:
|
||||
// WITH users AS (SELECT id, name FROM users WHERE prime IS NOT NULL), orders AS (SELECT id, user_id FROM orders) SELECT orders.id FROM orders JOIN users ON orders.user_id = users.id LIMIT 10
|
||||
}
|
||||
|
||||
func TestSelectBuilderSelectMore(t *testing.T) {
|
||||
a := assert.New(t)
|
||||
sb := Select("id").SQL("/* first */").Where(
|
||||
"name IS NOT NULL",
|
||||
).SQL("/* second */").SelectMore("name").SQL("/* third */")
|
||||
a.Equal(sb.String(), "SELECT id, name /* first */ /* third */ WHERE name IS NOT NULL /* second */")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user