updated deps; regen ent
This commit is contained in:
@@ -333,6 +333,11 @@ func (sq *SprayQuery) Select(fields ...string) *SpraySelect {
|
||||
return selbuild
|
||||
}
|
||||
|
||||
// Aggregate returns a SpraySelect configured with the given aggregations.
|
||||
func (sq *SprayQuery) Aggregate(fns ...AggregateFunc) *SpraySelect {
|
||||
return sq.Select().Aggregate(fns...)
|
||||
}
|
||||
|
||||
func (sq *SprayQuery) prepareQuery(ctx context.Context) error {
|
||||
for _, f := range sq.fields {
|
||||
if !spray.ValidColumn(f) {
|
||||
@@ -364,10 +369,10 @@ func (sq *SprayQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Spray,
|
||||
if withFKs {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, spray.ForeignKeys...)
|
||||
}
|
||||
_spec.ScanValues = func(columns []string) ([]interface{}, error) {
|
||||
_spec.ScanValues = func(columns []string) ([]any, error) {
|
||||
return (*Spray).scanValues(nil, columns)
|
||||
}
|
||||
_spec.Assign = func(columns []string, values []interface{}) error {
|
||||
_spec.Assign = func(columns []string, values []any) error {
|
||||
node := &Spray{config: sq.config}
|
||||
nodes = append(nodes, node)
|
||||
node.Edges.loadedTypes = loadedTypes
|
||||
@@ -437,11 +442,14 @@ func (sq *SprayQuery) sqlCount(ctx context.Context) (int, error) {
|
||||
}
|
||||
|
||||
func (sq *SprayQuery) sqlExist(ctx context.Context) (bool, error) {
|
||||
n, err := sq.sqlCount(ctx)
|
||||
if err != nil {
|
||||
switch _, err := sq.FirstID(ctx); {
|
||||
case IsNotFound(err):
|
||||
return false, nil
|
||||
case err != nil:
|
||||
return false, fmt.Errorf("ent: check existence: %w", err)
|
||||
default:
|
||||
return true, nil
|
||||
}
|
||||
return n > 0, nil
|
||||
}
|
||||
|
||||
func (sq *SprayQuery) querySpec() *sqlgraph.QuerySpec {
|
||||
@@ -551,7 +559,7 @@ func (sgb *SprayGroupBy) Aggregate(fns ...AggregateFunc) *SprayGroupBy {
|
||||
}
|
||||
|
||||
// Scan applies the group-by query and scans the result into the given value.
|
||||
func (sgb *SprayGroupBy) Scan(ctx context.Context, v interface{}) error {
|
||||
func (sgb *SprayGroupBy) Scan(ctx context.Context, v any) error {
|
||||
query, err := sgb.path(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -560,7 +568,7 @@ func (sgb *SprayGroupBy) Scan(ctx context.Context, v interface{}) error {
|
||||
return sgb.sqlScan(ctx, v)
|
||||
}
|
||||
|
||||
func (sgb *SprayGroupBy) sqlScan(ctx context.Context, v interface{}) error {
|
||||
func (sgb *SprayGroupBy) sqlScan(ctx context.Context, v any) error {
|
||||
for _, f := range sgb.fields {
|
||||
if !spray.ValidColumn(f) {
|
||||
return &ValidationError{Name: f, err: fmt.Errorf("invalid field %q for group-by", f)}
|
||||
@@ -585,8 +593,6 @@ func (sgb *SprayGroupBy) sqlQuery() *sql.Selector {
|
||||
for _, fn := range sgb.fns {
|
||||
aggregation = append(aggregation, fn(selector))
|
||||
}
|
||||
// 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(sgb.fields)+len(sgb.fns))
|
||||
for _, f := range sgb.fields {
|
||||
@@ -606,8 +612,14 @@ type SpraySelect struct {
|
||||
sql *sql.Selector
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the selector query.
|
||||
func (ss *SpraySelect) Aggregate(fns ...AggregateFunc) *SpraySelect {
|
||||
ss.fns = append(ss.fns, fns...)
|
||||
return ss
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (ss *SpraySelect) Scan(ctx context.Context, v interface{}) error {
|
||||
func (ss *SpraySelect) Scan(ctx context.Context, v any) error {
|
||||
if err := ss.prepareQuery(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -615,7 +627,17 @@ func (ss *SpraySelect) Scan(ctx context.Context, v interface{}) error {
|
||||
return ss.sqlScan(ctx, v)
|
||||
}
|
||||
|
||||
func (ss *SpraySelect) sqlScan(ctx context.Context, v interface{}) error {
|
||||
func (ss *SpraySelect) sqlScan(ctx context.Context, v any) error {
|
||||
aggregation := make([]string, 0, len(ss.fns))
|
||||
for _, fn := range ss.fns {
|
||||
aggregation = append(aggregation, fn(ss.sql))
|
||||
}
|
||||
switch n := len(*ss.selector.flds); {
|
||||
case n == 0 && len(aggregation) > 0:
|
||||
ss.sql.Select(aggregation...)
|
||||
case n != 0 && len(aggregation) > 0:
|
||||
ss.sql.AppendSelect(aggregation...)
|
||||
}
|
||||
rows := &sql.Rows{}
|
||||
query, args := ss.sql.Query()
|
||||
if err := ss.driver.Query(ctx, query, args, rows); err != nil {
|
||||
|
Reference in New Issue
Block a user