fixed match win/loss/ties

This commit is contained in:
2021-10-08 17:15:06 +02:00
parent 1fda101a35
commit 1816c5a2b5
28 changed files with 363 additions and 654 deletions

View File

@@ -30,6 +30,7 @@ type MatchQuery struct {
// eager-loading edges.
withStats *StatsQuery
withPlayers *PlayerQuery
modifiers []func(s *sql.Selector)
// intermediate query (i.e. traversal path).
sql *sql.Selector
path func(context.Context) (*sql.Selector, error)
@@ -134,8 +135,8 @@ func (mq *MatchQuery) FirstX(ctx context.Context) *Match {
// FirstID returns the first Match ID from the query.
// Returns a *NotFoundError when no Match ID was found.
func (mq *MatchQuery) FirstID(ctx context.Context) (id int, err error) {
var ids []int
func (mq *MatchQuery) FirstID(ctx context.Context) (id uint64, err error) {
var ids []uint64
if ids, err = mq.Limit(1).IDs(ctx); err != nil {
return
}
@@ -147,7 +148,7 @@ func (mq *MatchQuery) FirstID(ctx context.Context) (id int, err error) {
}
// FirstIDX is like FirstID, but panics if an error occurs.
func (mq *MatchQuery) FirstIDX(ctx context.Context) int {
func (mq *MatchQuery) FirstIDX(ctx context.Context) uint64 {
id, err := mq.FirstID(ctx)
if err != nil && !IsNotFound(err) {
panic(err)
@@ -185,8 +186,8 @@ func (mq *MatchQuery) OnlyX(ctx context.Context) *Match {
// OnlyID is like Only, but returns the only Match ID in the query.
// Returns a *NotSingularError when exactly one Match ID is not found.
// Returns a *NotFoundError when no entities are found.
func (mq *MatchQuery) OnlyID(ctx context.Context) (id int, err error) {
var ids []int
func (mq *MatchQuery) OnlyID(ctx context.Context) (id uint64, err error) {
var ids []uint64
if ids, err = mq.Limit(2).IDs(ctx); err != nil {
return
}
@@ -202,7 +203,7 @@ func (mq *MatchQuery) OnlyID(ctx context.Context) (id int, err error) {
}
// OnlyIDX is like OnlyID, but panics if an error occurs.
func (mq *MatchQuery) OnlyIDX(ctx context.Context) int {
func (mq *MatchQuery) OnlyIDX(ctx context.Context) uint64 {
id, err := mq.OnlyID(ctx)
if err != nil {
panic(err)
@@ -228,8 +229,8 @@ func (mq *MatchQuery) AllX(ctx context.Context) []*Match {
}
// IDs executes the query and returns a list of Match IDs.
func (mq *MatchQuery) IDs(ctx context.Context) ([]int, error) {
var ids []int
func (mq *MatchQuery) IDs(ctx context.Context) ([]uint64, error) {
var ids []uint64
if err := mq.Select(match.FieldID).Scan(ctx, &ids); err != nil {
return nil, err
}
@@ -237,7 +238,7 @@ func (mq *MatchQuery) IDs(ctx context.Context) ([]int, error) {
}
// IDsX is like IDs, but panics if an error occurs.
func (mq *MatchQuery) IDsX(ctx context.Context) []int {
func (mq *MatchQuery) IDsX(ctx context.Context) []uint64 {
ids, err := mq.IDs(ctx)
if err != nil {
panic(err)
@@ -327,12 +328,12 @@ func (mq *MatchQuery) WithPlayers(opts ...func(*PlayerQuery)) *MatchQuery {
// Example:
//
// var v []struct {
// MatchID uint64 `json:"match_id,string"`
// ShareCode string `json:"share_code,omitempty"`
// Count int `json:"count,omitempty"`
// }
//
// client.Match.Query().
// GroupBy(match.FieldMatchID).
// GroupBy(match.FieldShareCode).
// Aggregate(ent.Count()).
// Scan(ctx, &v)
//
@@ -354,11 +355,11 @@ func (mq *MatchQuery) GroupBy(field string, fields ...string) *MatchGroupBy {
// Example:
//
// var v []struct {
// MatchID uint64 `json:"match_id,string"`
// ShareCode string `json:"share_code,omitempty"`
// }
//
// client.Match.Query().
// Select(match.FieldMatchID).
// Select(match.FieldShareCode).
// Scan(ctx, &v)
//
func (mq *MatchQuery) Select(fields ...string) *MatchSelect {
@@ -404,6 +405,9 @@ func (mq *MatchQuery) sqlAll(ctx context.Context) ([]*Match, error) {
node.Edges.loadedTypes = loadedTypes
return node.assignValues(columns, values)
}
if len(mq.modifiers) > 0 {
_spec.Modifiers = mq.modifiers
}
if err := sqlgraph.QueryNodes(ctx, mq.driver, _spec); err != nil {
return nil, err
}
@@ -413,7 +417,7 @@ func (mq *MatchQuery) sqlAll(ctx context.Context) ([]*Match, error) {
if query := mq.withStats; query != nil {
fks := make([]driver.Value, 0, len(nodes))
nodeids := make(map[int]*Match)
nodeids := make(map[uint64]*Match)
for i := range nodes {
fks = append(fks, nodes[i].ID)
nodeids[nodes[i].ID] = nodes[i]
@@ -442,15 +446,15 @@ func (mq *MatchQuery) sqlAll(ctx context.Context) ([]*Match, error) {
if query := mq.withPlayers; query != nil {
fks := make([]driver.Value, 0, len(nodes))
ids := make(map[int]*Match, len(nodes))
ids := make(map[uint64]*Match, len(nodes))
for _, node := range nodes {
ids[node.ID] = node
fks = append(fks, node.ID)
node.Edges.Players = []*Player{}
}
var (
edgeids []int
edges = make(map[int][]*Match)
edgeids []uint64
edges = make(map[uint64][]*Match)
)
_spec := &sqlgraph.EdgeQuerySpec{
Edge: &sqlgraph.EdgeSpec{
@@ -473,8 +477,8 @@ func (mq *MatchQuery) sqlAll(ctx context.Context) ([]*Match, error) {
if !ok || ein == nil {
return fmt.Errorf("unexpected id value for edge-in")
}
outValue := int(eout.Int64)
inValue := int(ein.Int64)
outValue := uint64(eout.Int64)
inValue := uint64(ein.Int64)
node, ok := ids[outValue]
if !ok {
return fmt.Errorf("unexpected node id in edges: %v", outValue)
@@ -510,6 +514,9 @@ func (mq *MatchQuery) sqlAll(ctx context.Context) ([]*Match, error) {
func (mq *MatchQuery) sqlCount(ctx context.Context) (int, error) {
_spec := mq.querySpec()
if len(mq.modifiers) > 0 {
_spec.Modifiers = mq.modifiers
}
return sqlgraph.CountNodes(ctx, mq.driver, _spec)
}
@@ -527,7 +534,7 @@ func (mq *MatchQuery) querySpec() *sqlgraph.QuerySpec {
Table: match.Table,
Columns: match.Columns,
ID: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Type: field.TypeUint64,
Column: match.FieldID,
},
},
@@ -581,6 +588,9 @@ func (mq *MatchQuery) sqlQuery(ctx context.Context) *sql.Selector {
selector = mq.sql
selector.Select(selector.Columns(columns...)...)
}
for _, m := range mq.modifiers {
m(selector)
}
for _, p := range mq.predicates {
p(selector)
}
@@ -598,6 +608,12 @@ func (mq *MatchQuery) sqlQuery(ctx context.Context) *sql.Selector {
return selector
}
// Modify adds a query modifier for attaching custom logic to queries.
func (mq *MatchQuery) Modify(modifiers ...func(s *sql.Selector)) *MatchSelect {
mq.modifiers = append(mq.modifiers, modifiers...)
return mq.Select()
}
// MatchGroupBy is the group-by builder for Match entities.
type MatchGroupBy struct {
config
@@ -1087,3 +1103,9 @@ func (ms *MatchSelect) sqlScan(ctx context.Context, v interface{}) error {
defer rows.Close()
return sql.ScanSlice(rows, v)
}
// Modify adds a query modifier for attaching custom logic to queries.
func (ms *MatchSelect) Modify(modifiers ...func(s *sql.Selector)) *MatchSelect {
ms.modifiers = append(ms.modifiers, modifiers...)
return ms
}