added chat messages
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"context"
|
||||
"csgowtfd/ent/match"
|
||||
"csgowtfd/ent/matchplayer"
|
||||
"csgowtfd/ent/messages"
|
||||
"csgowtfd/ent/player"
|
||||
"csgowtfd/ent/predicate"
|
||||
"csgowtfd/ent/roundstats"
|
||||
@@ -36,6 +37,7 @@ type MatchPlayerQuery struct {
|
||||
withWeaponStats *WeaponQuery
|
||||
withRoundStats *RoundStatsQuery
|
||||
withSpray *SprayQuery
|
||||
withMessages *MessagesQuery
|
||||
modifiers []func(s *sql.Selector)
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
@@ -183,6 +185,28 @@ func (mpq *MatchPlayerQuery) QuerySpray() *SprayQuery {
|
||||
return query
|
||||
}
|
||||
|
||||
// QueryMessages chains the current query on the "messages" edge.
|
||||
func (mpq *MatchPlayerQuery) QueryMessages() *MessagesQuery {
|
||||
query := &MessagesQuery{config: mpq.config}
|
||||
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||||
if err := mpq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
selector := mpq.sqlQuery(ctx)
|
||||
if err := selector.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(matchplayer.Table, matchplayer.FieldID, selector),
|
||||
sqlgraph.To(messages.Table, messages.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2M, false, matchplayer.MessagesTable, matchplayer.MessagesColumn),
|
||||
)
|
||||
fromU = sqlgraph.SetNeighbors(mpq.driver.Dialect(), step)
|
||||
return fromU, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// First returns the first MatchPlayer entity from the query.
|
||||
// Returns a *NotFoundError when no MatchPlayer was found.
|
||||
func (mpq *MatchPlayerQuery) First(ctx context.Context) (*MatchPlayer, error) {
|
||||
@@ -369,6 +393,7 @@ func (mpq *MatchPlayerQuery) Clone() *MatchPlayerQuery {
|
||||
withWeaponStats: mpq.withWeaponStats.Clone(),
|
||||
withRoundStats: mpq.withRoundStats.Clone(),
|
||||
withSpray: mpq.withSpray.Clone(),
|
||||
withMessages: mpq.withMessages.Clone(),
|
||||
// clone intermediate query.
|
||||
sql: mpq.sql.Clone(),
|
||||
path: mpq.path,
|
||||
@@ -430,6 +455,17 @@ func (mpq *MatchPlayerQuery) WithSpray(opts ...func(*SprayQuery)) *MatchPlayerQu
|
||||
return mpq
|
||||
}
|
||||
|
||||
// WithMessages tells the query-builder to eager-load the nodes that are connected to
|
||||
// the "messages" edge. The optional arguments are used to configure the query builder of the edge.
|
||||
func (mpq *MatchPlayerQuery) WithMessages(opts ...func(*MessagesQuery)) *MatchPlayerQuery {
|
||||
query := &MessagesQuery{config: mpq.config}
|
||||
for _, opt := range opts {
|
||||
opt(query)
|
||||
}
|
||||
mpq.withMessages = query
|
||||
return mpq
|
||||
}
|
||||
|
||||
// GroupBy is used to group vertices by one or more fields/columns.
|
||||
// It is often used with aggregate functions, like: count, max, mean, min, sum.
|
||||
//
|
||||
@@ -495,12 +531,13 @@ func (mpq *MatchPlayerQuery) sqlAll(ctx context.Context) ([]*MatchPlayer, error)
|
||||
var (
|
||||
nodes = []*MatchPlayer{}
|
||||
_spec = mpq.querySpec()
|
||||
loadedTypes = [5]bool{
|
||||
loadedTypes = [6]bool{
|
||||
mpq.withMatches != nil,
|
||||
mpq.withPlayers != nil,
|
||||
mpq.withWeaponStats != nil,
|
||||
mpq.withRoundStats != nil,
|
||||
mpq.withSpray != nil,
|
||||
mpq.withMessages != nil,
|
||||
}
|
||||
)
|
||||
_spec.ScanValues = func(columns []string) ([]interface{}, error) {
|
||||
@@ -665,6 +702,35 @@ func (mpq *MatchPlayerQuery) sqlAll(ctx context.Context) ([]*MatchPlayer, error)
|
||||
}
|
||||
}
|
||||
|
||||
if query := mpq.withMessages; query != nil {
|
||||
fks := make([]driver.Value, 0, len(nodes))
|
||||
nodeids := make(map[int]*MatchPlayer)
|
||||
for i := range nodes {
|
||||
fks = append(fks, nodes[i].ID)
|
||||
nodeids[nodes[i].ID] = nodes[i]
|
||||
nodes[i].Edges.Messages = []*Messages{}
|
||||
}
|
||||
query.withFKs = true
|
||||
query.Where(predicate.Messages(func(s *sql.Selector) {
|
||||
s.Where(sql.InValues(matchplayer.MessagesColumn, fks...))
|
||||
}))
|
||||
neighbors, err := query.All(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, n := range neighbors {
|
||||
fk := n.match_player_messages
|
||||
if fk == nil {
|
||||
return nil, fmt.Errorf(`foreign-key "match_player_messages" is nil for node %v`, n.ID)
|
||||
}
|
||||
node, ok := nodeids[*fk]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf(`unexpected foreign-key "match_player_messages" returned %v for node %v`, *fk, n.ID)
|
||||
}
|
||||
node.Edges.Messages = append(node.Edges.Messages, n)
|
||||
}
|
||||
}
|
||||
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
@@ -673,6 +739,10 @@ func (mpq *MatchPlayerQuery) sqlCount(ctx context.Context) (int, error) {
|
||||
if len(mpq.modifiers) > 0 {
|
||||
_spec.Modifiers = mpq.modifiers
|
||||
}
|
||||
_spec.Node.Columns = mpq.fields
|
||||
if len(mpq.fields) > 0 {
|
||||
_spec.Unique = mpq.unique != nil && *mpq.unique
|
||||
}
|
||||
return sqlgraph.CountNodes(ctx, mpq.driver, _spec)
|
||||
}
|
||||
|
||||
@@ -744,6 +814,9 @@ func (mpq *MatchPlayerQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
||||
selector = mpq.sql
|
||||
selector.Select(selector.Columns(columns...)...)
|
||||
}
|
||||
if mpq.unique != nil && *mpq.unique {
|
||||
selector.Distinct()
|
||||
}
|
||||
for _, m := range mpq.modifiers {
|
||||
m(selector)
|
||||
}
|
||||
@@ -1031,9 +1104,7 @@ func (mpgb *MatchPlayerGroupBy) sqlQuery() *sql.Selector {
|
||||
for _, f := range mpgb.fields {
|
||||
columns = append(columns, selector.C(f))
|
||||
}
|
||||
for _, c := range aggregation {
|
||||
columns = append(columns, c)
|
||||
}
|
||||
columns = append(columns, aggregation...)
|
||||
selector.Select(columns...)
|
||||
}
|
||||
return selector.GroupBy(selector.Columns(mpgb.fields...)...)
|
||||
|
Reference in New Issue
Block a user