updated deps; switched sitemap lib; ent regen
This commit is contained in:
@@ -20,11 +20,9 @@ import (
|
||||
// PlayerQuery is the builder for querying Player entities.
|
||||
type PlayerQuery struct {
|
||||
config
|
||||
limit *int
|
||||
offset *int
|
||||
unique *bool
|
||||
ctx *QueryContext
|
||||
order []OrderFunc
|
||||
fields []string
|
||||
inters []Interceptor
|
||||
predicates []predicate.Player
|
||||
withStats *MatchPlayerQuery
|
||||
withMatches *MatchQuery
|
||||
@@ -40,26 +38,26 @@ func (pq *PlayerQuery) Where(ps ...predicate.Player) *PlayerQuery {
|
||||
return pq
|
||||
}
|
||||
|
||||
// Limit adds a limit step to the query.
|
||||
// Limit the number of records to be returned by this query.
|
||||
func (pq *PlayerQuery) Limit(limit int) *PlayerQuery {
|
||||
pq.limit = &limit
|
||||
pq.ctx.Limit = &limit
|
||||
return pq
|
||||
}
|
||||
|
||||
// Offset adds an offset step to the query.
|
||||
// Offset to start from.
|
||||
func (pq *PlayerQuery) Offset(offset int) *PlayerQuery {
|
||||
pq.offset = &offset
|
||||
pq.ctx.Offset = &offset
|
||||
return pq
|
||||
}
|
||||
|
||||
// Unique configures the query builder to filter duplicate records on query.
|
||||
// By default, unique is set to true, and can be disabled using this method.
|
||||
func (pq *PlayerQuery) Unique(unique bool) *PlayerQuery {
|
||||
pq.unique = &unique
|
||||
pq.ctx.Unique = &unique
|
||||
return pq
|
||||
}
|
||||
|
||||
// Order adds an order step to the query.
|
||||
// Order specifies how the records should be ordered.
|
||||
func (pq *PlayerQuery) Order(o ...OrderFunc) *PlayerQuery {
|
||||
pq.order = append(pq.order, o...)
|
||||
return pq
|
||||
@@ -67,7 +65,7 @@ func (pq *PlayerQuery) Order(o ...OrderFunc) *PlayerQuery {
|
||||
|
||||
// QueryStats chains the current query on the "stats" edge.
|
||||
func (pq *PlayerQuery) QueryStats() *MatchPlayerQuery {
|
||||
query := &MatchPlayerQuery{config: pq.config}
|
||||
query := (&MatchPlayerClient{config: pq.config}).Query()
|
||||
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||||
if err := pq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
@@ -89,7 +87,7 @@ func (pq *PlayerQuery) QueryStats() *MatchPlayerQuery {
|
||||
|
||||
// QueryMatches chains the current query on the "matches" edge.
|
||||
func (pq *PlayerQuery) QueryMatches() *MatchQuery {
|
||||
query := &MatchQuery{config: pq.config}
|
||||
query := (&MatchClient{config: pq.config}).Query()
|
||||
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||||
if err := pq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
@@ -112,7 +110,7 @@ func (pq *PlayerQuery) QueryMatches() *MatchQuery {
|
||||
// First returns the first Player entity from the query.
|
||||
// Returns a *NotFoundError when no Player was found.
|
||||
func (pq *PlayerQuery) First(ctx context.Context) (*Player, error) {
|
||||
nodes, err := pq.Limit(1).All(ctx)
|
||||
nodes, err := pq.Limit(1).All(setContextOp(ctx, pq.ctx, "First"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -135,7 +133,7 @@ func (pq *PlayerQuery) FirstX(ctx context.Context) *Player {
|
||||
// Returns a *NotFoundError when no Player ID was found.
|
||||
func (pq *PlayerQuery) FirstID(ctx context.Context) (id uint64, err error) {
|
||||
var ids []uint64
|
||||
if ids, err = pq.Limit(1).IDs(ctx); err != nil {
|
||||
if ids, err = pq.Limit(1).IDs(setContextOp(ctx, pq.ctx, "FirstID")); err != nil {
|
||||
return
|
||||
}
|
||||
if len(ids) == 0 {
|
||||
@@ -158,7 +156,7 @@ func (pq *PlayerQuery) FirstIDX(ctx context.Context) uint64 {
|
||||
// Returns a *NotSingularError when more than one Player entity is found.
|
||||
// Returns a *NotFoundError when no Player entities are found.
|
||||
func (pq *PlayerQuery) Only(ctx context.Context) (*Player, error) {
|
||||
nodes, err := pq.Limit(2).All(ctx)
|
||||
nodes, err := pq.Limit(2).All(setContextOp(ctx, pq.ctx, "Only"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -186,7 +184,7 @@ func (pq *PlayerQuery) OnlyX(ctx context.Context) *Player {
|
||||
// Returns a *NotFoundError when no entities are found.
|
||||
func (pq *PlayerQuery) OnlyID(ctx context.Context) (id uint64, err error) {
|
||||
var ids []uint64
|
||||
if ids, err = pq.Limit(2).IDs(ctx); err != nil {
|
||||
if ids, err = pq.Limit(2).IDs(setContextOp(ctx, pq.ctx, "OnlyID")); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(ids) {
|
||||
@@ -211,10 +209,12 @@ func (pq *PlayerQuery) OnlyIDX(ctx context.Context) uint64 {
|
||||
|
||||
// All executes the query and returns a list of Players.
|
||||
func (pq *PlayerQuery) All(ctx context.Context) ([]*Player, error) {
|
||||
ctx = setContextOp(ctx, pq.ctx, "All")
|
||||
if err := pq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return pq.sqlAll(ctx)
|
||||
qr := querierAll[[]*Player, *PlayerQuery]()
|
||||
return withInterceptors[[]*Player](ctx, pq, qr, pq.inters)
|
||||
}
|
||||
|
||||
// AllX is like All, but panics if an error occurs.
|
||||
@@ -227,9 +227,12 @@ func (pq *PlayerQuery) AllX(ctx context.Context) []*Player {
|
||||
}
|
||||
|
||||
// IDs executes the query and returns a list of Player IDs.
|
||||
func (pq *PlayerQuery) IDs(ctx context.Context) ([]uint64, error) {
|
||||
var ids []uint64
|
||||
if err := pq.Select(player.FieldID).Scan(ctx, &ids); err != nil {
|
||||
func (pq *PlayerQuery) IDs(ctx context.Context) (ids []uint64, err error) {
|
||||
if pq.ctx.Unique == nil && pq.path != nil {
|
||||
pq.Unique(true)
|
||||
}
|
||||
ctx = setContextOp(ctx, pq.ctx, "IDs")
|
||||
if err = pq.Select(player.FieldID).Scan(ctx, &ids); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ids, nil
|
||||
@@ -246,10 +249,11 @@ func (pq *PlayerQuery) IDsX(ctx context.Context) []uint64 {
|
||||
|
||||
// Count returns the count of the given query.
|
||||
func (pq *PlayerQuery) Count(ctx context.Context) (int, error) {
|
||||
ctx = setContextOp(ctx, pq.ctx, "Count")
|
||||
if err := pq.prepareQuery(ctx); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return pq.sqlCount(ctx)
|
||||
return withInterceptors[int](ctx, pq, querierCount[*PlayerQuery](), pq.inters)
|
||||
}
|
||||
|
||||
// CountX is like Count, but panics if an error occurs.
|
||||
@@ -263,10 +267,15 @@ func (pq *PlayerQuery) CountX(ctx context.Context) int {
|
||||
|
||||
// Exist returns true if the query has elements in the graph.
|
||||
func (pq *PlayerQuery) Exist(ctx context.Context) (bool, error) {
|
||||
if err := pq.prepareQuery(ctx); err != nil {
|
||||
return false, err
|
||||
ctx = setContextOp(ctx, pq.ctx, "Exist")
|
||||
switch _, err := pq.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 pq.sqlExist(ctx)
|
||||
}
|
||||
|
||||
// ExistX is like Exist, but panics if an error occurs.
|
||||
@@ -286,23 +295,22 @@ func (pq *PlayerQuery) Clone() *PlayerQuery {
|
||||
}
|
||||
return &PlayerQuery{
|
||||
config: pq.config,
|
||||
limit: pq.limit,
|
||||
offset: pq.offset,
|
||||
ctx: pq.ctx.Clone(),
|
||||
order: append([]OrderFunc{}, pq.order...),
|
||||
inters: append([]Interceptor{}, pq.inters...),
|
||||
predicates: append([]predicate.Player{}, pq.predicates...),
|
||||
withStats: pq.withStats.Clone(),
|
||||
withMatches: pq.withMatches.Clone(),
|
||||
// clone intermediate query.
|
||||
sql: pq.sql.Clone(),
|
||||
path: pq.path,
|
||||
unique: pq.unique,
|
||||
sql: pq.sql.Clone(),
|
||||
path: pq.path,
|
||||
}
|
||||
}
|
||||
|
||||
// WithStats tells the query-builder to eager-load the nodes that are connected to
|
||||
// the "stats" edge. The optional arguments are used to configure the query builder of the edge.
|
||||
func (pq *PlayerQuery) WithStats(opts ...func(*MatchPlayerQuery)) *PlayerQuery {
|
||||
query := &MatchPlayerQuery{config: pq.config}
|
||||
query := (&MatchPlayerClient{config: pq.config}).Query()
|
||||
for _, opt := range opts {
|
||||
opt(query)
|
||||
}
|
||||
@@ -313,7 +321,7 @@ func (pq *PlayerQuery) WithStats(opts ...func(*MatchPlayerQuery)) *PlayerQuery {
|
||||
// WithMatches tells the query-builder to eager-load the nodes that are connected to
|
||||
// the "matches" edge. The optional arguments are used to configure the query builder of the edge.
|
||||
func (pq *PlayerQuery) WithMatches(opts ...func(*MatchQuery)) *PlayerQuery {
|
||||
query := &MatchQuery{config: pq.config}
|
||||
query := (&MatchClient{config: pq.config}).Query()
|
||||
for _, opt := range opts {
|
||||
opt(query)
|
||||
}
|
||||
@@ -336,16 +344,11 @@ func (pq *PlayerQuery) WithMatches(opts ...func(*MatchQuery)) *PlayerQuery {
|
||||
// Aggregate(ent.Count()).
|
||||
// Scan(ctx, &v)
|
||||
func (pq *PlayerQuery) GroupBy(field string, fields ...string) *PlayerGroupBy {
|
||||
grbuild := &PlayerGroupBy{config: pq.config}
|
||||
grbuild.fields = append([]string{field}, fields...)
|
||||
grbuild.path = func(ctx context.Context) (prev *sql.Selector, err error) {
|
||||
if err := pq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return pq.sqlQuery(ctx), nil
|
||||
}
|
||||
pq.ctx.Fields = append([]string{field}, fields...)
|
||||
grbuild := &PlayerGroupBy{build: pq}
|
||||
grbuild.flds = &pq.ctx.Fields
|
||||
grbuild.label = player.Label
|
||||
grbuild.flds, grbuild.scan = &grbuild.fields, grbuild.Scan
|
||||
grbuild.scan = grbuild.Scan
|
||||
return grbuild
|
||||
}
|
||||
|
||||
@@ -362,11 +365,11 @@ func (pq *PlayerQuery) GroupBy(field string, fields ...string) *PlayerGroupBy {
|
||||
// Select(player.FieldName).
|
||||
// Scan(ctx, &v)
|
||||
func (pq *PlayerQuery) Select(fields ...string) *PlayerSelect {
|
||||
pq.fields = append(pq.fields, fields...)
|
||||
selbuild := &PlayerSelect{PlayerQuery: pq}
|
||||
selbuild.label = player.Label
|
||||
selbuild.flds, selbuild.scan = &pq.fields, selbuild.Scan
|
||||
return selbuild
|
||||
pq.ctx.Fields = append(pq.ctx.Fields, fields...)
|
||||
sbuild := &PlayerSelect{PlayerQuery: pq}
|
||||
sbuild.label = player.Label
|
||||
sbuild.flds, sbuild.scan = &pq.ctx.Fields, sbuild.Scan
|
||||
return sbuild
|
||||
}
|
||||
|
||||
// Aggregate returns a PlayerSelect configured with the given aggregations.
|
||||
@@ -375,7 +378,17 @@ func (pq *PlayerQuery) Aggregate(fns ...AggregateFunc) *PlayerSelect {
|
||||
}
|
||||
|
||||
func (pq *PlayerQuery) prepareQuery(ctx context.Context) error {
|
||||
for _, f := range pq.fields {
|
||||
for _, inter := range pq.inters {
|
||||
if inter == nil {
|
||||
return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)")
|
||||
}
|
||||
if trv, ok := inter.(Traverser); ok {
|
||||
if err := trv.Traverse(ctx, pq); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, f := range pq.ctx.Fields {
|
||||
if !player.ValidColumn(f) {
|
||||
return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||
}
|
||||
@@ -487,27 +500,30 @@ func (pq *PlayerQuery) loadMatches(ctx context.Context, query *MatchQuery, nodes
|
||||
if err := query.prepareQuery(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
neighbors, err := query.sqlAll(ctx, func(_ context.Context, spec *sqlgraph.QuerySpec) {
|
||||
assign := spec.Assign
|
||||
values := spec.ScanValues
|
||||
spec.ScanValues = func(columns []string) ([]any, error) {
|
||||
values, err := values(columns[1:])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
qr := QuerierFunc(func(ctx context.Context, q Query) (Value, error) {
|
||||
return query.sqlAll(ctx, func(_ context.Context, spec *sqlgraph.QuerySpec) {
|
||||
assign := spec.Assign
|
||||
values := spec.ScanValues
|
||||
spec.ScanValues = func(columns []string) ([]any, error) {
|
||||
values, err := values(columns[1:])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return append([]any{new(sql.NullInt64)}, values...), nil
|
||||
}
|
||||
return append([]any{new(sql.NullInt64)}, values...), nil
|
||||
}
|
||||
spec.Assign = func(columns []string, values []any) error {
|
||||
outValue := uint64(values[0].(*sql.NullInt64).Int64)
|
||||
inValue := uint64(values[1].(*sql.NullInt64).Int64)
|
||||
if nids[inValue] == nil {
|
||||
nids[inValue] = map[*Player]struct{}{byID[outValue]: {}}
|
||||
return assign(columns[1:], values[1:])
|
||||
spec.Assign = func(columns []string, values []any) error {
|
||||
outValue := uint64(values[0].(*sql.NullInt64).Int64)
|
||||
inValue := uint64(values[1].(*sql.NullInt64).Int64)
|
||||
if nids[inValue] == nil {
|
||||
nids[inValue] = map[*Player]struct{}{byID[outValue]: {}}
|
||||
return assign(columns[1:], values[1:])
|
||||
}
|
||||
nids[inValue][byID[outValue]] = struct{}{}
|
||||
return nil
|
||||
}
|
||||
nids[inValue][byID[outValue]] = struct{}{}
|
||||
return nil
|
||||
}
|
||||
})
|
||||
})
|
||||
neighbors, err := withInterceptors[[]*Match](ctx, query, qr, query.inters)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -528,41 +544,22 @@ func (pq *PlayerQuery) sqlCount(ctx context.Context) (int, error) {
|
||||
if len(pq.modifiers) > 0 {
|
||||
_spec.Modifiers = pq.modifiers
|
||||
}
|
||||
_spec.Node.Columns = pq.fields
|
||||
if len(pq.fields) > 0 {
|
||||
_spec.Unique = pq.unique != nil && *pq.unique
|
||||
_spec.Node.Columns = pq.ctx.Fields
|
||||
if len(pq.ctx.Fields) > 0 {
|
||||
_spec.Unique = pq.ctx.Unique != nil && *pq.ctx.Unique
|
||||
}
|
||||
return sqlgraph.CountNodes(ctx, pq.driver, _spec)
|
||||
}
|
||||
|
||||
func (pq *PlayerQuery) sqlExist(ctx context.Context) (bool, error) {
|
||||
switch _, err := pq.FirstID(ctx); {
|
||||
case IsNotFound(err):
|
||||
return false, nil
|
||||
case err != nil:
|
||||
return false, fmt.Errorf("ent: check existence: %w", err)
|
||||
default:
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
|
||||
func (pq *PlayerQuery) querySpec() *sqlgraph.QuerySpec {
|
||||
_spec := &sqlgraph.QuerySpec{
|
||||
Node: &sqlgraph.NodeSpec{
|
||||
Table: player.Table,
|
||||
Columns: player.Columns,
|
||||
ID: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeUint64,
|
||||
Column: player.FieldID,
|
||||
},
|
||||
},
|
||||
From: pq.sql,
|
||||
Unique: true,
|
||||
}
|
||||
if unique := pq.unique; unique != nil {
|
||||
_spec := sqlgraph.NewQuerySpec(player.Table, player.Columns, sqlgraph.NewFieldSpec(player.FieldID, field.TypeUint64))
|
||||
_spec.From = pq.sql
|
||||
if unique := pq.ctx.Unique; unique != nil {
|
||||
_spec.Unique = *unique
|
||||
} else if pq.path != nil {
|
||||
_spec.Unique = true
|
||||
}
|
||||
if fields := pq.fields; len(fields) > 0 {
|
||||
if fields := pq.ctx.Fields; len(fields) > 0 {
|
||||
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, player.FieldID)
|
||||
for i := range fields {
|
||||
@@ -578,10 +575,10 @@ func (pq *PlayerQuery) querySpec() *sqlgraph.QuerySpec {
|
||||
}
|
||||
}
|
||||
}
|
||||
if limit := pq.limit; limit != nil {
|
||||
if limit := pq.ctx.Limit; limit != nil {
|
||||
_spec.Limit = *limit
|
||||
}
|
||||
if offset := pq.offset; offset != nil {
|
||||
if offset := pq.ctx.Offset; offset != nil {
|
||||
_spec.Offset = *offset
|
||||
}
|
||||
if ps := pq.order; len(ps) > 0 {
|
||||
@@ -597,7 +594,7 @@ func (pq *PlayerQuery) querySpec() *sqlgraph.QuerySpec {
|
||||
func (pq *PlayerQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
||||
builder := sql.Dialect(pq.driver.Dialect())
|
||||
t1 := builder.Table(player.Table)
|
||||
columns := pq.fields
|
||||
columns := pq.ctx.Fields
|
||||
if len(columns) == 0 {
|
||||
columns = player.Columns
|
||||
}
|
||||
@@ -606,7 +603,7 @@ func (pq *PlayerQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
||||
selector = pq.sql
|
||||
selector.Select(selector.Columns(columns...)...)
|
||||
}
|
||||
if pq.unique != nil && *pq.unique {
|
||||
if pq.ctx.Unique != nil && *pq.ctx.Unique {
|
||||
selector.Distinct()
|
||||
}
|
||||
for _, m := range pq.modifiers {
|
||||
@@ -618,12 +615,12 @@ func (pq *PlayerQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
||||
for _, p := range pq.order {
|
||||
p(selector)
|
||||
}
|
||||
if offset := pq.offset; offset != nil {
|
||||
if offset := pq.ctx.Offset; offset != nil {
|
||||
// limit is mandatory for offset clause. We start
|
||||
// with default value, and override it below if needed.
|
||||
selector.Offset(*offset).Limit(math.MaxInt32)
|
||||
}
|
||||
if limit := pq.limit; limit != nil {
|
||||
if limit := pq.ctx.Limit; limit != nil {
|
||||
selector.Limit(*limit)
|
||||
}
|
||||
return selector
|
||||
@@ -637,13 +634,8 @@ func (pq *PlayerQuery) Modify(modifiers ...func(s *sql.Selector)) *PlayerSelect
|
||||
|
||||
// PlayerGroupBy is the group-by builder for Player entities.
|
||||
type PlayerGroupBy struct {
|
||||
config
|
||||
selector
|
||||
fields []string
|
||||
fns []AggregateFunc
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
build *PlayerQuery
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the group-by query.
|
||||
@@ -652,58 +644,46 @@ func (pgb *PlayerGroupBy) Aggregate(fns ...AggregateFunc) *PlayerGroupBy {
|
||||
return pgb
|
||||
}
|
||||
|
||||
// Scan applies the group-by query and scans the result into the given value.
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (pgb *PlayerGroupBy) Scan(ctx context.Context, v any) error {
|
||||
query, err := pgb.path(ctx)
|
||||
if err != nil {
|
||||
ctx = setContextOp(ctx, pgb.build.ctx, "GroupBy")
|
||||
if err := pgb.build.prepareQuery(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
pgb.sql = query
|
||||
return pgb.sqlScan(ctx, v)
|
||||
return scanWithInterceptors[*PlayerQuery, *PlayerGroupBy](ctx, pgb.build, pgb, pgb.build.inters, v)
|
||||
}
|
||||
|
||||
func (pgb *PlayerGroupBy) sqlScan(ctx context.Context, v any) error {
|
||||
for _, f := range pgb.fields {
|
||||
if !player.ValidColumn(f) {
|
||||
return &ValidationError{Name: f, err: fmt.Errorf("invalid field %q for group-by", f)}
|
||||
}
|
||||
func (pgb *PlayerGroupBy) sqlScan(ctx context.Context, root *PlayerQuery, v any) error {
|
||||
selector := root.sqlQuery(ctx).Select()
|
||||
aggregation := make([]string, 0, len(pgb.fns))
|
||||
for _, fn := range pgb.fns {
|
||||
aggregation = append(aggregation, fn(selector))
|
||||
}
|
||||
selector := pgb.sqlQuery()
|
||||
if len(selector.SelectedColumns()) == 0 {
|
||||
columns := make([]string, 0, len(*pgb.flds)+len(pgb.fns))
|
||||
for _, f := range *pgb.flds {
|
||||
columns = append(columns, selector.C(f))
|
||||
}
|
||||
columns = append(columns, aggregation...)
|
||||
selector.Select(columns...)
|
||||
}
|
||||
selector.GroupBy(selector.Columns(*pgb.flds...)...)
|
||||
if err := selector.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
rows := &sql.Rows{}
|
||||
query, args := selector.Query()
|
||||
if err := pgb.driver.Query(ctx, query, args, rows); err != nil {
|
||||
if err := pgb.build.driver.Query(ctx, query, args, rows); err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
return sql.ScanSlice(rows, v)
|
||||
}
|
||||
|
||||
func (pgb *PlayerGroupBy) sqlQuery() *sql.Selector {
|
||||
selector := pgb.sql.Select()
|
||||
aggregation := make([]string, 0, len(pgb.fns))
|
||||
for _, fn := range pgb.fns {
|
||||
aggregation = append(aggregation, fn(selector))
|
||||
}
|
||||
if len(selector.SelectedColumns()) == 0 {
|
||||
columns := make([]string, 0, len(pgb.fields)+len(pgb.fns))
|
||||
for _, f := range pgb.fields {
|
||||
columns = append(columns, selector.C(f))
|
||||
}
|
||||
columns = append(columns, aggregation...)
|
||||
selector.Select(columns...)
|
||||
}
|
||||
return selector.GroupBy(selector.Columns(pgb.fields...)...)
|
||||
}
|
||||
|
||||
// PlayerSelect is the builder for selecting fields of Player entities.
|
||||
type PlayerSelect struct {
|
||||
*PlayerQuery
|
||||
selector
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the selector query.
|
||||
@@ -714,26 +694,27 @@ func (ps *PlayerSelect) Aggregate(fns ...AggregateFunc) *PlayerSelect {
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (ps *PlayerSelect) Scan(ctx context.Context, v any) error {
|
||||
ctx = setContextOp(ctx, ps.ctx, "Select")
|
||||
if err := ps.prepareQuery(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
ps.sql = ps.PlayerQuery.sqlQuery(ctx)
|
||||
return ps.sqlScan(ctx, v)
|
||||
return scanWithInterceptors[*PlayerQuery, *PlayerSelect](ctx, ps.PlayerQuery, ps, ps.inters, v)
|
||||
}
|
||||
|
||||
func (ps *PlayerSelect) sqlScan(ctx context.Context, v any) error {
|
||||
func (ps *PlayerSelect) sqlScan(ctx context.Context, root *PlayerQuery, v any) error {
|
||||
selector := root.sqlQuery(ctx)
|
||||
aggregation := make([]string, 0, len(ps.fns))
|
||||
for _, fn := range ps.fns {
|
||||
aggregation = append(aggregation, fn(ps.sql))
|
||||
aggregation = append(aggregation, fn(selector))
|
||||
}
|
||||
switch n := len(*ps.selector.flds); {
|
||||
case n == 0 && len(aggregation) > 0:
|
||||
ps.sql.Select(aggregation...)
|
||||
selector.Select(aggregation...)
|
||||
case n != 0 && len(aggregation) > 0:
|
||||
ps.sql.AppendSelect(aggregation...)
|
||||
selector.AppendSelect(aggregation...)
|
||||
}
|
||||
rows := &sql.Rows{}
|
||||
query, args := ps.sql.Query()
|
||||
query, args := selector.Query()
|
||||
if err := ps.driver.Query(ctx, query, args, rows); err != nil {
|
||||
return err
|
||||
}
|
||||
|
Reference in New Issue
Block a user