Skip to content

Commit

Permalink
feat: append column method
Browse files Browse the repository at this point in the history
  • Loading branch information
bohdand-weka committed Jul 8, 2024
1 parent 30e7053 commit 98d3fe5
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions orm/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,30 @@ func (q *Query) ExcludeColumn(columns ...string) *Query {
return q
}

// AppendColumn appends column to the list of default columns if they weren't set,
// while Column method overrides defaults
func (q *Query) AppendColumn(columns ...string) *Query {
t := q.tableModel.Table()
if q.columns == nil {
for _, f := range t.Fields {
q.columns = append(q.columns, SafeQuery("?.?", t.Alias, f.Column))
}
}
return q.Column(columns...)
}

// AppendColumnExpr appends column expression to the list of default columns if they weren't set,
// while ColumnExpr method overrides defaults
func (q *Query) AppendColumnExpr(expr string, params ...interface{}) *Query {
t := q.tableModel.Table()
if q.columns == nil {
for _, f := range t.Fields {
q.columns = append(q.columns, SafeQuery("?.?", t.Alias, f.Column))
}
}
return q.ColumnExpr(expr, params...)
}

func (q *Query) excludeColumn(column string) bool {
for i := 0; i < len(q.columns); i++ {
app, ok := q.columns[i].(fieldAppender)
Expand Down

0 comments on commit 98d3fe5

Please sign in to comment.