@@ -287,8 +287,8 @@ func (kq *KeysQuery) GroupBy(field string, fields ...string) *KeysGroupBy {
|
||||
// Select(keys.FieldVerificationKeys).
|
||||
// Scan(ctx, &v)
|
||||
//
|
||||
func (kq *KeysQuery) Select(field string, fields ...string) *KeysSelect {
|
||||
kq.fields = append([]string{field}, fields...)
|
||||
func (kq *KeysQuery) Select(fields ...string) *KeysSelect {
|
||||
kq.fields = append(kq.fields, fields...)
|
||||
return &KeysSelect{KeysQuery: kq}
|
||||
}
|
||||
|
||||
@@ -398,10 +398,14 @@ func (kq *KeysQuery) querySpec() *sqlgraph.QuerySpec {
|
||||
func (kq *KeysQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
||||
builder := sql.Dialect(kq.driver.Dialect())
|
||||
t1 := builder.Table(keys.Table)
|
||||
selector := builder.Select(t1.Columns(keys.Columns...)...).From(t1)
|
||||
columns := kq.fields
|
||||
if len(columns) == 0 {
|
||||
columns = keys.Columns
|
||||
}
|
||||
selector := builder.Select(t1.Columns(columns...)...).From(t1)
|
||||
if kq.sql != nil {
|
||||
selector = kq.sql
|
||||
selector.Select(selector.Columns(keys.Columns...)...)
|
||||
selector.Select(selector.Columns(columns...)...)
|
||||
}
|
||||
for _, p := range kq.predicates {
|
||||
p(selector)
|
||||
@@ -669,13 +673,24 @@ func (kgb *KeysGroupBy) sqlScan(ctx context.Context, v interface{}) error {
|
||||
}
|
||||
|
||||
func (kgb *KeysGroupBy) sqlQuery() *sql.Selector {
|
||||
selector := kgb.sql
|
||||
columns := make([]string, 0, len(kgb.fields)+len(kgb.fns))
|
||||
columns = append(columns, kgb.fields...)
|
||||
selector := kgb.sql.Select()
|
||||
aggregation := make([]string, 0, len(kgb.fns))
|
||||
for _, fn := range kgb.fns {
|
||||
columns = append(columns, fn(selector))
|
||||
aggregation = append(aggregation, fn(selector))
|
||||
}
|
||||
return selector.Select(columns...).GroupBy(kgb.fields...)
|
||||
// If no columns were selected in a custom aggregation function, the default
|
||||
// selection is the fields used for "group-by", and the aggregation functions.
|
||||
if len(selector.SelectedColumns()) == 0 {
|
||||
columns := make([]string, 0, len(kgb.fields)+len(kgb.fns))
|
||||
for _, f := range kgb.fields {
|
||||
columns = append(columns, selector.C(f))
|
||||
}
|
||||
for _, c := range aggregation {
|
||||
columns = append(columns, c)
|
||||
}
|
||||
selector.Select(columns...)
|
||||
}
|
||||
return selector.GroupBy(selector.Columns(kgb.fields...)...)
|
||||
}
|
||||
|
||||
// KeysSelect is the builder for selecting fields of Keys entities.
|
||||
@@ -891,16 +906,10 @@ func (ks *KeysSelect) BoolX(ctx context.Context) bool {
|
||||
|
||||
func (ks *KeysSelect) sqlScan(ctx context.Context, v interface{}) error {
|
||||
rows := &sql.Rows{}
|
||||
query, args := ks.sqlQuery().Query()
|
||||
query, args := ks.sql.Query()
|
||||
if err := ks.driver.Query(ctx, query, args, rows); err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
return sql.ScanSlice(rows, v)
|
||||
}
|
||||
|
||||
func (ks *KeysSelect) sqlQuery() sql.Querier {
|
||||
selector := ks.sql
|
||||
selector.Select(selector.Columns(ks.fields...)...)
|
||||
return selector
|
||||
}
|
||||
|
Reference in New Issue
Block a user