Skip to content

Commit 98d3fe5

Browse files
committed
feat: append column method
1 parent 30e7053 commit 98d3fe5

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

orm/query.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,30 @@ func (q *Query) ExcludeColumn(columns ...string) *Query {
360360
return q
361361
}
362362

363+
// AppendColumn appends column to the list of default columns if they weren't set,
364+
// while Column method overrides defaults
365+
func (q *Query) AppendColumn(columns ...string) *Query {
366+
t := q.tableModel.Table()
367+
if q.columns == nil {
368+
for _, f := range t.Fields {
369+
q.columns = append(q.columns, SafeQuery("?.?", t.Alias, f.Column))
370+
}
371+
}
372+
return q.Column(columns...)
373+
}
374+
375+
// AppendColumnExpr appends column expression to the list of default columns if they weren't set,
376+
// while ColumnExpr method overrides defaults
377+
func (q *Query) AppendColumnExpr(expr string, params ...interface{}) *Query {
378+
t := q.tableModel.Table()
379+
if q.columns == nil {
380+
for _, f := range t.Fields {
381+
q.columns = append(q.columns, SafeQuery("?.?", t.Alias, f.Column))
382+
}
383+
}
384+
return q.ColumnExpr(expr, params...)
385+
}
386+
363387
func (q *Query) excludeColumn(column string) bool {
364388
for i := 0; i < len(q.columns); i++ {
365389
app, ok := q.columns[i].(fieldAppender)

0 commit comments

Comments
 (0)