Skip to content

Commit d6f429c

Browse files
committed
refs #164: new API SelectMore to add more cols to SELECT after calling Select()
1 parent 01acaab commit d6f429c

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

select.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,13 @@ func (sb *SelectBuilder) Select(col ...string) *SelectBuilder {
134134
return sb
135135
}
136136

137+
// SelectMore adds more columns in SELECT.
138+
func (sb *SelectBuilder) SelectMore(col ...string) *SelectBuilder {
139+
sb.selectCols = append(sb.selectCols, col...)
140+
sb.marker = selectMarkerAfterSelect
141+
return sb
142+
}
143+
137144
// Distinct marks this SELECT as DISTINCT.
138145
func (sb *SelectBuilder) Distinct() *SelectBuilder {
139146
sb.distinct = true

select_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ package sqlbuilder
66
import (
77
"database/sql"
88
"fmt"
9+
"testing"
10+
11+
"github.com/huandu/go-assert"
912
)
1013

1114
func ExampleSelect() {
@@ -364,3 +367,11 @@ func ExampleSelectBuilder_With() {
364367
// Output:
365368
// 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
366369
}
370+
371+
func TestSelectBuilderSelectMore(t *testing.T) {
372+
a := assert.New(t)
373+
sb := Select("id").SQL("/* first */").Where(
374+
"name IS NOT NULL",
375+
).SQL("/* second */").SelectMore("name").SQL("/* third */")
376+
a.Equal(sb.String(), "SELECT id, name /* first */ /* third */ WHERE name IS NOT NULL /* second */")
377+
}

0 commit comments

Comments
 (0)