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