File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -262,6 +262,13 @@ func (b SelectBuilder) Columns(columns ...string) SelectBuilder {
262262 return builder .Extend (b , "Columns" , parts ).(SelectBuilder )
263263}
264264
265+ // RemoveColumns remove all columns from query.
266+ // Must add a new column with Column or Columns methods, otherwise
267+ // return a error.
268+ func (b SelectBuilder ) RemoveColumns () SelectBuilder {
269+ return builder .Delete (b , "Columns" ).(SelectBuilder )
270+ }
271+
265272// Column adds a result column to the query.
266273// Unlike Columns, Column accepts args which will be bound to placeholders in
267274// the columns string, for example:
Original file line number Diff line number Diff line change @@ -451,3 +451,13 @@ func ExampleSelectBuilder_ToSql() {
451451 // scan...
452452 }
453453}
454+
455+ func TestRemoveColumns (t * testing.T ) {
456+ query := Select ("id" ).
457+ From ("users" ).
458+ RemoveColumns ()
459+ query = query .Columns ("name" )
460+ sql , _ , err := query .ToSql ()
461+ assert .NoError (t , err )
462+ assert .Equal (t , "SELECT name FROM users" , sql )
463+ }
You can’t perform that action at this time.
0 commit comments