Skip to content

Commit

Permalink
Merge pull request #506 from uptrace/feat/apply-query-builder
Browse files Browse the repository at this point in the history
feat: add ApplyQueryBuilder
  • Loading branch information
vmihailenco authored Apr 5, 2022
2 parents 98d111b + 582eca0 commit 2e4d130
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
8 changes: 7 additions & 1 deletion query_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,11 +293,17 @@ func (q *DeleteQuery) QueryBuilder() QueryBuilder {
return &deleteQueryBuilder{q}
}

func (q *DeleteQuery) ApplyQueryBuilder(fn func(QueryBuilder) QueryBuilder) *DeleteQuery {
return fn(q.QueryBuilder()).Unwrap().(*DeleteQuery)
}

type deleteQueryBuilder struct {
*DeleteQuery
}

func (q *deleteQueryBuilder) WhereGroup(sep string, fn func(QueryBuilder) QueryBuilder) QueryBuilder {
func (q *deleteQueryBuilder) WhereGroup(
sep string, fn func(QueryBuilder) QueryBuilder,
) QueryBuilder {
q.DeleteQuery = q.DeleteQuery.WhereGroup(sep, func(qs *DeleteQuery) *DeleteQuery {
return fn(q).(*deleteQueryBuilder).DeleteQuery
})
Expand Down
4 changes: 4 additions & 0 deletions query_select.go
Original file line number Diff line number Diff line change
Expand Up @@ -926,6 +926,10 @@ func (q *SelectQuery) QueryBuilder() QueryBuilder {
return &selectQueryBuilder{q}
}

func (q *SelectQuery) ApplyQueryBuilder(fn func(QueryBuilder) QueryBuilder) *SelectQuery {
return fn(q.QueryBuilder()).Unwrap().(*SelectQuery)
}

type selectQueryBuilder struct {
*SelectQuery
}
Expand Down
8 changes: 7 additions & 1 deletion query_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -493,11 +493,17 @@ func (q *UpdateQuery) QueryBuilder() QueryBuilder {
return &updateQueryBuilder{q}
}

func (q *UpdateQuery) ApplyQueryBuilder(fn func(QueryBuilder) QueryBuilder) *UpdateQuery {
return fn(q.QueryBuilder()).Unwrap().(*UpdateQuery)
}

type updateQueryBuilder struct {
*UpdateQuery
}

func (q *updateQueryBuilder) WhereGroup(sep string, fn func(QueryBuilder) QueryBuilder) QueryBuilder {
func (q *updateQueryBuilder) WhereGroup(
sep string, fn func(QueryBuilder) QueryBuilder,
) QueryBuilder {
q.UpdateQuery = q.UpdateQuery.WhereGroup(sep, func(qs *UpdateQuery) *UpdateQuery {
return fn(q).(*updateQueryBuilder).UpdateQuery
})
Expand Down

0 comments on commit 2e4d130

Please sign in to comment.