dialect/sql/sqlgraph: add support for query modifiers

This commit is contained in:
Ariel Mashraki
2021-07-20 13:02:50 +03:00
committed by Ariel Mashraki
parent dfc7a79f6d
commit 279d6c2a12
6 changed files with 34 additions and 2 deletions

View File

@@ -492,6 +492,7 @@ type QuerySpec struct {
Unique bool
Order func(*sql.Selector)
Predicate func(*sql.Selector)
Modifiers []func(*sql.Selector)
ScanValues func(columns []string) ([]interface{}, error)
Assign func(columns []string, values []interface{}) error
@@ -633,6 +634,9 @@ func (q *query) selector(ctx context.Context) (*sql.Selector, error) {
if q.Unique {
selector.Distinct()
}
for _, m := range q.Modifiers {
m(selector)
}
if err := selector.Err(); err != nil {
return nil, err
}