updated deps; switched sitemap lib; ent regen

This commit is contained in:
2023-03-03 20:10:31 +01:00
parent e9a5daa9e3
commit 727d530378
52 changed files with 2626 additions and 5665 deletions

View File

@@ -18,11 +18,9 @@ import (
// SprayQuery is the builder for querying Spray entities.
type SprayQuery struct {
config
limit *int
offset *int
unique *bool
ctx *QueryContext
order []OrderFunc
fields []string
inters []Interceptor
predicates []predicate.Spray
withMatchPlayers *MatchPlayerQuery
withFKs bool
@@ -38,26 +36,26 @@ func (sq *SprayQuery) Where(ps ...predicate.Spray) *SprayQuery {
return sq
}
// Limit adds a limit step to the query.
// Limit the number of records to be returned by this query.
func (sq *SprayQuery) Limit(limit int) *SprayQuery {
sq.limit = &limit
sq.ctx.Limit = &limit
return sq
}
// Offset adds an offset step to the query.
// Offset to start from.
func (sq *SprayQuery) Offset(offset int) *SprayQuery {
sq.offset = &offset
sq.ctx.Offset = &offset
return sq
}
// 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 (sq *SprayQuery) Unique(unique bool) *SprayQuery {
sq.unique = &unique
sq.ctx.Unique = &unique
return sq
}
// Order adds an order step to the query.
// Order specifies how the records should be ordered.
func (sq *SprayQuery) Order(o ...OrderFunc) *SprayQuery {
sq.order = append(sq.order, o...)
return sq
@@ -65,7 +63,7 @@ func (sq *SprayQuery) Order(o ...OrderFunc) *SprayQuery {
// QueryMatchPlayers chains the current query on the "match_players" edge.
func (sq *SprayQuery) QueryMatchPlayers() *MatchPlayerQuery {
query := &MatchPlayerQuery{config: sq.config}
query := (&MatchPlayerClient{config: sq.config}).Query()
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
if err := sq.prepareQuery(ctx); err != nil {
return nil, err
@@ -88,7 +86,7 @@ func (sq *SprayQuery) QueryMatchPlayers() *MatchPlayerQuery {
// First returns the first Spray entity from the query.
// Returns a *NotFoundError when no Spray was found.
func (sq *SprayQuery) First(ctx context.Context) (*Spray, error) {
nodes, err := sq.Limit(1).All(ctx)
nodes, err := sq.Limit(1).All(setContextOp(ctx, sq.ctx, "First"))
if err != nil {
return nil, err
}
@@ -111,7 +109,7 @@ func (sq *SprayQuery) FirstX(ctx context.Context) *Spray {
// Returns a *NotFoundError when no Spray ID was found.
func (sq *SprayQuery) FirstID(ctx context.Context) (id int, err error) {
var ids []int
if ids, err = sq.Limit(1).IDs(ctx); err != nil {
if ids, err = sq.Limit(1).IDs(setContextOp(ctx, sq.ctx, "FirstID")); err != nil {
return
}
if len(ids) == 0 {
@@ -134,7 +132,7 @@ func (sq *SprayQuery) FirstIDX(ctx context.Context) int {
// Returns a *NotSingularError when more than one Spray entity is found.
// Returns a *NotFoundError when no Spray entities are found.
func (sq *SprayQuery) Only(ctx context.Context) (*Spray, error) {
nodes, err := sq.Limit(2).All(ctx)
nodes, err := sq.Limit(2).All(setContextOp(ctx, sq.ctx, "Only"))
if err != nil {
return nil, err
}
@@ -162,7 +160,7 @@ func (sq *SprayQuery) OnlyX(ctx context.Context) *Spray {
// Returns a *NotFoundError when no entities are found.
func (sq *SprayQuery) OnlyID(ctx context.Context) (id int, err error) {
var ids []int
if ids, err = sq.Limit(2).IDs(ctx); err != nil {
if ids, err = sq.Limit(2).IDs(setContextOp(ctx, sq.ctx, "OnlyID")); err != nil {
return
}
switch len(ids) {
@@ -187,10 +185,12 @@ func (sq *SprayQuery) OnlyIDX(ctx context.Context) int {
// All executes the query and returns a list of Sprays.
func (sq *SprayQuery) All(ctx context.Context) ([]*Spray, error) {
ctx = setContextOp(ctx, sq.ctx, "All")
if err := sq.prepareQuery(ctx); err != nil {
return nil, err
}
return sq.sqlAll(ctx)
qr := querierAll[[]*Spray, *SprayQuery]()
return withInterceptors[[]*Spray](ctx, sq, qr, sq.inters)
}
// AllX is like All, but panics if an error occurs.
@@ -203,9 +203,12 @@ func (sq *SprayQuery) AllX(ctx context.Context) []*Spray {
}
// IDs executes the query and returns a list of Spray IDs.
func (sq *SprayQuery) IDs(ctx context.Context) ([]int, error) {
var ids []int
if err := sq.Select(spray.FieldID).Scan(ctx, &ids); err != nil {
func (sq *SprayQuery) IDs(ctx context.Context) (ids []int, err error) {
if sq.ctx.Unique == nil && sq.path != nil {
sq.Unique(true)
}
ctx = setContextOp(ctx, sq.ctx, "IDs")
if err = sq.Select(spray.FieldID).Scan(ctx, &ids); err != nil {
return nil, err
}
return ids, nil
@@ -222,10 +225,11 @@ func (sq *SprayQuery) IDsX(ctx context.Context) []int {
// Count returns the count of the given query.
func (sq *SprayQuery) Count(ctx context.Context) (int, error) {
ctx = setContextOp(ctx, sq.ctx, "Count")
if err := sq.prepareQuery(ctx); err != nil {
return 0, err
}
return sq.sqlCount(ctx)
return withInterceptors[int](ctx, sq, querierCount[*SprayQuery](), sq.inters)
}
// CountX is like Count, but panics if an error occurs.
@@ -239,10 +243,15 @@ func (sq *SprayQuery) CountX(ctx context.Context) int {
// Exist returns true if the query has elements in the graph.
func (sq *SprayQuery) Exist(ctx context.Context) (bool, error) {
if err := sq.prepareQuery(ctx); err != nil {
return false, err
ctx = setContextOp(ctx, sq.ctx, "Exist")
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 sq.sqlExist(ctx)
}
// ExistX is like Exist, but panics if an error occurs.
@@ -262,22 +271,21 @@ func (sq *SprayQuery) Clone() *SprayQuery {
}
return &SprayQuery{
config: sq.config,
limit: sq.limit,
offset: sq.offset,
ctx: sq.ctx.Clone(),
order: append([]OrderFunc{}, sq.order...),
inters: append([]Interceptor{}, sq.inters...),
predicates: append([]predicate.Spray{}, sq.predicates...),
withMatchPlayers: sq.withMatchPlayers.Clone(),
// clone intermediate query.
sql: sq.sql.Clone(),
path: sq.path,
unique: sq.unique,
sql: sq.sql.Clone(),
path: sq.path,
}
}
// WithMatchPlayers tells the query-builder to eager-load the nodes that are connected to
// the "match_players" edge. The optional arguments are used to configure the query builder of the edge.
func (sq *SprayQuery) WithMatchPlayers(opts ...func(*MatchPlayerQuery)) *SprayQuery {
query := &MatchPlayerQuery{config: sq.config}
query := (&MatchPlayerClient{config: sq.config}).Query()
for _, opt := range opts {
opt(query)
}
@@ -300,16 +308,11 @@ func (sq *SprayQuery) WithMatchPlayers(opts ...func(*MatchPlayerQuery)) *SprayQu
// Aggregate(ent.Count()).
// Scan(ctx, &v)
func (sq *SprayQuery) GroupBy(field string, fields ...string) *SprayGroupBy {
grbuild := &SprayGroupBy{config: sq.config}
grbuild.fields = append([]string{field}, fields...)
grbuild.path = func(ctx context.Context) (prev *sql.Selector, err error) {
if err := sq.prepareQuery(ctx); err != nil {
return nil, err
}
return sq.sqlQuery(ctx), nil
}
sq.ctx.Fields = append([]string{field}, fields...)
grbuild := &SprayGroupBy{build: sq}
grbuild.flds = &sq.ctx.Fields
grbuild.label = spray.Label
grbuild.flds, grbuild.scan = &grbuild.fields, grbuild.Scan
grbuild.scan = grbuild.Scan
return grbuild
}
@@ -326,11 +329,11 @@ func (sq *SprayQuery) GroupBy(field string, fields ...string) *SprayGroupBy {
// Select(spray.FieldWeapon).
// Scan(ctx, &v)
func (sq *SprayQuery) Select(fields ...string) *SpraySelect {
sq.fields = append(sq.fields, fields...)
selbuild := &SpraySelect{SprayQuery: sq}
selbuild.label = spray.Label
selbuild.flds, selbuild.scan = &sq.fields, selbuild.Scan
return selbuild
sq.ctx.Fields = append(sq.ctx.Fields, fields...)
sbuild := &SpraySelect{SprayQuery: sq}
sbuild.label = spray.Label
sbuild.flds, sbuild.scan = &sq.ctx.Fields, sbuild.Scan
return sbuild
}
// Aggregate returns a SpraySelect configured with the given aggregations.
@@ -339,7 +342,17 @@ func (sq *SprayQuery) Aggregate(fns ...AggregateFunc) *SpraySelect {
}
func (sq *SprayQuery) prepareQuery(ctx context.Context) error {
for _, f := range sq.fields {
for _, inter := range sq.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, sq); err != nil {
return err
}
}
}
for _, f := range sq.ctx.Fields {
if !spray.ValidColumn(f) {
return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
}
@@ -412,6 +425,9 @@ func (sq *SprayQuery) loadMatchPlayers(ctx context.Context, query *MatchPlayerQu
}
nodeids[fk] = append(nodeids[fk], nodes[i])
}
if len(ids) == 0 {
return nil
}
query.Where(matchplayer.IDIn(ids...))
neighbors, err := query.All(ctx)
if err != nil {
@@ -434,41 +450,22 @@ func (sq *SprayQuery) sqlCount(ctx context.Context) (int, error) {
if len(sq.modifiers) > 0 {
_spec.Modifiers = sq.modifiers
}
_spec.Node.Columns = sq.fields
if len(sq.fields) > 0 {
_spec.Unique = sq.unique != nil && *sq.unique
_spec.Node.Columns = sq.ctx.Fields
if len(sq.ctx.Fields) > 0 {
_spec.Unique = sq.ctx.Unique != nil && *sq.ctx.Unique
}
return sqlgraph.CountNodes(ctx, sq.driver, _spec)
}
func (sq *SprayQuery) sqlExist(ctx context.Context) (bool, error) {
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
}
}
func (sq *SprayQuery) querySpec() *sqlgraph.QuerySpec {
_spec := &sqlgraph.QuerySpec{
Node: &sqlgraph.NodeSpec{
Table: spray.Table,
Columns: spray.Columns,
ID: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: spray.FieldID,
},
},
From: sq.sql,
Unique: true,
}
if unique := sq.unique; unique != nil {
_spec := sqlgraph.NewQuerySpec(spray.Table, spray.Columns, sqlgraph.NewFieldSpec(spray.FieldID, field.TypeInt))
_spec.From = sq.sql
if unique := sq.ctx.Unique; unique != nil {
_spec.Unique = *unique
} else if sq.path != nil {
_spec.Unique = true
}
if fields := sq.fields; len(fields) > 0 {
if fields := sq.ctx.Fields; len(fields) > 0 {
_spec.Node.Columns = make([]string, 0, len(fields))
_spec.Node.Columns = append(_spec.Node.Columns, spray.FieldID)
for i := range fields {
@@ -484,10 +481,10 @@ func (sq *SprayQuery) querySpec() *sqlgraph.QuerySpec {
}
}
}
if limit := sq.limit; limit != nil {
if limit := sq.ctx.Limit; limit != nil {
_spec.Limit = *limit
}
if offset := sq.offset; offset != nil {
if offset := sq.ctx.Offset; offset != nil {
_spec.Offset = *offset
}
if ps := sq.order; len(ps) > 0 {
@@ -503,7 +500,7 @@ func (sq *SprayQuery) querySpec() *sqlgraph.QuerySpec {
func (sq *SprayQuery) sqlQuery(ctx context.Context) *sql.Selector {
builder := sql.Dialect(sq.driver.Dialect())
t1 := builder.Table(spray.Table)
columns := sq.fields
columns := sq.ctx.Fields
if len(columns) == 0 {
columns = spray.Columns
}
@@ -512,7 +509,7 @@ func (sq *SprayQuery) sqlQuery(ctx context.Context) *sql.Selector {
selector = sq.sql
selector.Select(selector.Columns(columns...)...)
}
if sq.unique != nil && *sq.unique {
if sq.ctx.Unique != nil && *sq.ctx.Unique {
selector.Distinct()
}
for _, m := range sq.modifiers {
@@ -524,12 +521,12 @@ func (sq *SprayQuery) sqlQuery(ctx context.Context) *sql.Selector {
for _, p := range sq.order {
p(selector)
}
if offset := sq.offset; offset != nil {
if offset := sq.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 := sq.limit; limit != nil {
if limit := sq.ctx.Limit; limit != nil {
selector.Limit(*limit)
}
return selector
@@ -543,13 +540,8 @@ func (sq *SprayQuery) Modify(modifiers ...func(s *sql.Selector)) *SpraySelect {
// SprayGroupBy is the group-by builder for Spray entities.
type SprayGroupBy struct {
config
selector
fields []string
fns []AggregateFunc
// intermediate query (i.e. traversal path).
sql *sql.Selector
path func(context.Context) (*sql.Selector, error)
build *SprayQuery
}
// Aggregate adds the given aggregation functions to the group-by query.
@@ -558,58 +550,46 @@ func (sgb *SprayGroupBy) Aggregate(fns ...AggregateFunc) *SprayGroupBy {
return sgb
}
// 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 (sgb *SprayGroupBy) Scan(ctx context.Context, v any) error {
query, err := sgb.path(ctx)
if err != nil {
ctx = setContextOp(ctx, sgb.build.ctx, "GroupBy")
if err := sgb.build.prepareQuery(ctx); err != nil {
return err
}
sgb.sql = query
return sgb.sqlScan(ctx, v)
return scanWithInterceptors[*SprayQuery, *SprayGroupBy](ctx, sgb.build, sgb, sgb.build.inters, v)
}
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)}
}
func (sgb *SprayGroupBy) sqlScan(ctx context.Context, root *SprayQuery, v any) error {
selector := root.sqlQuery(ctx).Select()
aggregation := make([]string, 0, len(sgb.fns))
for _, fn := range sgb.fns {
aggregation = append(aggregation, fn(selector))
}
selector := sgb.sqlQuery()
if len(selector.SelectedColumns()) == 0 {
columns := make([]string, 0, len(*sgb.flds)+len(sgb.fns))
for _, f := range *sgb.flds {
columns = append(columns, selector.C(f))
}
columns = append(columns, aggregation...)
selector.Select(columns...)
}
selector.GroupBy(selector.Columns(*sgb.flds...)...)
if err := selector.Err(); err != nil {
return err
}
rows := &sql.Rows{}
query, args := selector.Query()
if err := sgb.driver.Query(ctx, query, args, rows); err != nil {
if err := sgb.build.driver.Query(ctx, query, args, rows); err != nil {
return err
}
defer rows.Close()
return sql.ScanSlice(rows, v)
}
func (sgb *SprayGroupBy) sqlQuery() *sql.Selector {
selector := sgb.sql.Select()
aggregation := make([]string, 0, len(sgb.fns))
for _, fn := range sgb.fns {
aggregation = append(aggregation, fn(selector))
}
if len(selector.SelectedColumns()) == 0 {
columns := make([]string, 0, len(sgb.fields)+len(sgb.fns))
for _, f := range sgb.fields {
columns = append(columns, selector.C(f))
}
columns = append(columns, aggregation...)
selector.Select(columns...)
}
return selector.GroupBy(selector.Columns(sgb.fields...)...)
}
// SpraySelect is the builder for selecting fields of Spray entities.
type SpraySelect struct {
*SprayQuery
selector
// intermediate query (i.e. traversal path).
sql *sql.Selector
}
// Aggregate adds the given aggregation functions to the selector query.
@@ -620,26 +600,27 @@ func (ss *SpraySelect) Aggregate(fns ...AggregateFunc) *SpraySelect {
// Scan applies the selector query and scans the result into the given value.
func (ss *SpraySelect) Scan(ctx context.Context, v any) error {
ctx = setContextOp(ctx, ss.ctx, "Select")
if err := ss.prepareQuery(ctx); err != nil {
return err
}
ss.sql = ss.SprayQuery.sqlQuery(ctx)
return ss.sqlScan(ctx, v)
return scanWithInterceptors[*SprayQuery, *SpraySelect](ctx, ss.SprayQuery, ss, ss.inters, v)
}
func (ss *SpraySelect) sqlScan(ctx context.Context, v any) error {
func (ss *SpraySelect) sqlScan(ctx context.Context, root *SprayQuery, v any) error {
selector := root.sqlQuery(ctx)
aggregation := make([]string, 0, len(ss.fns))
for _, fn := range ss.fns {
aggregation = append(aggregation, fn(ss.sql))
aggregation = append(aggregation, fn(selector))
}
switch n := len(*ss.selector.flds); {
case n == 0 && len(aggregation) > 0:
ss.sql.Select(aggregation...)
selector.Select(aggregation...)
case n != 0 && len(aggregation) > 0:
ss.sql.AppendSelect(aggregation...)
selector.AppendSelect(aggregation...)
}
rows := &sql.Rows{}
query, args := ss.sql.Query()
query, args := selector.Query()
if err := ss.driver.Query(ctx, query, args, rows); err != nil {
return err
}