From b036275665c0e5b0618ac70c424c3229b696b4be Mon Sep 17 00:00:00 2001 From: Giovanni Harting <539@idlegandalf.com> Date: Sat, 29 Jan 2022 19:32:13 +0100 Subject: [PATCH] added chat messages --- csgo/demo_loader.go | 5 + csgo/demo_parser.go | 33 +- ent/client.go | 130 ++++ ent/config.go | 1 + ent/ent.go | 4 +- ent/hook/hook.go | 13 + ent/match.go | 12 + ent/match/match.go | 3 + ent/match/where.go | 97 +++ ent/match_create.go | 34 +- ent/match_query.go | 11 +- ent/match_update.go | 53 +- ent/matchplayer.go | 18 +- ent/matchplayer/matchplayer.go | 9 + ent/matchplayer/where.go | 28 + ent/matchplayer_create.go | 51 +- ent/matchplayer_query.go | 79 ++- ent/matchplayer_update.go | 248 ++++++- ent/messages.go | 153 ++++ ent/messages/messages.go | 53 ++ ent/messages/where.go | 292 ++++++++ ent/messages_create.go | 277 ++++++++ ent/messages_delete.go | 111 +++ ent/messages_query.go | 1021 +++++++++++++++++++++++++++ ent/messages_update.go | 412 +++++++++++ ent/migrate/migrate.go | 3 +- ent/migrate/schema.go | 24 + ent/mutation.go | 1187 +++++++++++++++++++++++++------- ent/player_create.go | 2 +- ent/player_query.go | 11 +- ent/player_update.go | 3 +- ent/predicate/predicate.go | 3 + ent/roundstats_create.go | 8 +- ent/roundstats_query.go | 11 +- ent/roundstats_update.go | 19 +- ent/runtime/runtime.go | 4 +- ent/schema/match.go | 1 + ent/schema/matchplayer.go | 1 + ent/schema/messages.go | 27 + ent/spray_create.go | 4 +- ent/spray_query.go | 11 +- ent/spray_update.go | 3 +- ent/tx.go | 11 +- ent/weapon_create.go | 8 +- ent/weapon_query.go | 11 +- ent/weapon_update.go | 11 +- go.mod | 2 + go.sum | 7 +- 48 files changed, 4167 insertions(+), 353 deletions(-) create mode 100644 ent/messages.go create mode 100644 ent/messages/messages.go create mode 100644 ent/messages/where.go create mode 100644 ent/messages_create.go create mode 100644 ent/messages_delete.go create mode 100644 ent/messages_query.go create mode 100644 ent/messages_update.go create mode 100644 ent/schema/messages.go diff --git a/csgo/demo_loader.go b/csgo/demo_loader.go index 5e1447f..b0672c1 100644 --- a/csgo/demo_loader.go +++ b/csgo/demo_loader.go @@ -16,6 +16,8 @@ import ( "google.golang.org/protobuf/proto" "io/ioutil" "os" + "strconv" + "strings" "sync" "time" ) @@ -350,6 +352,7 @@ func (d *DemoMatchLoader) gcWorker(apiKey string, rl ratelimit.Limiter) { log.Infof("[DL] Match %d is loaded, but not parsed. Try parsing.", iMatch.ID) demo.MatchId = matchId demo.Url = iMatch.ReplayURL + demo.DecryptionKey = iMatch.DecryptionKey err := d.dp.ParseDemo(demo) if err != nil { log.Warningf("[DL] Parsing demo from match %d failed: %v", demo.MatchId, err) @@ -396,6 +399,7 @@ func (d *DemoMatchLoader) gcWorker(apiKey string, rl ratelimit.Limiter) { demo.Url = lastRound.GetMap() demo.MatchId = matchZero.GetMatchid() + demo.DecryptionKey = []byte(strings.ToUpper(strconv.FormatUint(matchZero.GetWatchablematchinfo().GetClDecryptdataKeyPub(), 16))) tMatch, err := d.db.Match.Create(). SetID(matchZero.GetMatchid()). @@ -408,6 +412,7 @@ func (d *DemoMatchLoader) gcWorker(apiKey string, rl ratelimit.Limiter) { SetScoreTeamA(int(lastRound.GetTeamScores()[0])). SetScoreTeamB(int(lastRound.GetTeamScores()[1])). SetMatchResult(int(lastRound.GetMatchResult())). + SetDecryptionKey(demo.DecryptionKey). Save(context.Background()) if err != nil { log.Warningf("[DL] Unable to create match %d: %v", matchZero.GetMatchid(), err) diff --git a/csgo/demo_parser.go b/csgo/demo_parser.go index 85b6e99..9ea472d 100644 --- a/csgo/demo_parser.go +++ b/csgo/demo_parser.go @@ -21,9 +21,10 @@ import ( ) type Demo struct { - ShareCode string - MatchId uint64 - Url string + ShareCode string + MatchId uint64 + Url string + DecryptionKey []byte } type DemoParser struct { @@ -244,8 +245,25 @@ func (p *DemoParser) parseWorker() { }, 0) encounters := make([]*Encounter, 0) spays := make([]*Sprays, 0) + + cfg := demoinfocs.DefaultParserConfig + cfg.NetMessageDecryptionKey = demo.DecryptionKey demoParser := demoinfocs.NewParser(fDemo) + // onChatMessage + demoParser.RegisterEventHandler(func(e events.ChatMessage) { + tAttacker, err := p.MatchPlayerBySteamID(tStats, e.Sender.SteamID64) + if err != nil { + log.Warningf("[DP] Unable to get player for id %d: %v", e.Sender.SteamID64, err) + return + } + + tAttacker.Edges.Messages = append(tAttacker.Edges.Messages, &ent.Messages{ + Message: e.Text, + AllChat: e.IsChatAll, + }) + }) + // onPlayerSpotted demoParser.RegisterEventHandler(func(e events.PlayerSpottersChanged) { gs := demoParser.GameState() @@ -492,6 +510,15 @@ func (p *DemoParser) parseWorker() { } } } + + bulk := make([]*ent.MessagesCreate, len(tMatchPlayer.Edges.Messages)) + for _, msg := range tMatchPlayer.Edges.Messages { + bulk = append(bulk, p.db.Messages.Create().SetMessage(msg.Message).SetAllChat(msg.AllChat).SetMatchPlayer(tMatchPlayer)) + } + err = p.db.Messages.CreateBulk(bulk...).Exec(context.Background()) + if err != nil { + log.Warningf("[DP] Failure adding messages to database: %v", err) + } } log.Infof("[DP] parsed match %d (took %s/%s)", demo.MatchId, downloadTime, time.Since(startTime)) diff --git a/ent/client.go b/ent/client.go index dc2edbb..cd9769e 100644 --- a/ent/client.go +++ b/ent/client.go @@ -11,6 +11,7 @@ import ( "csgowtfd/ent/match" "csgowtfd/ent/matchplayer" + "csgowtfd/ent/messages" "csgowtfd/ent/player" "csgowtfd/ent/roundstats" "csgowtfd/ent/spray" @@ -30,6 +31,8 @@ type Client struct { Match *MatchClient // MatchPlayer is the client for interacting with the MatchPlayer builders. MatchPlayer *MatchPlayerClient + // Messages is the client for interacting with the Messages builders. + Messages *MessagesClient // Player is the client for interacting with the Player builders. Player *PlayerClient // RoundStats is the client for interacting with the RoundStats builders. @@ -53,6 +56,7 @@ func (c *Client) init() { c.Schema = migrate.NewSchema(c.driver) c.Match = NewMatchClient(c.config) c.MatchPlayer = NewMatchPlayerClient(c.config) + c.Messages = NewMessagesClient(c.config) c.Player = NewPlayerClient(c.config) c.RoundStats = NewRoundStatsClient(c.config) c.Spray = NewSprayClient(c.config) @@ -92,6 +96,7 @@ func (c *Client) Tx(ctx context.Context) (*Tx, error) { config: cfg, Match: NewMatchClient(cfg), MatchPlayer: NewMatchPlayerClient(cfg), + Messages: NewMessagesClient(cfg), Player: NewPlayerClient(cfg), RoundStats: NewRoundStatsClient(cfg), Spray: NewSprayClient(cfg), @@ -113,9 +118,11 @@ func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error) cfg := c.config cfg.driver = &txDriver{tx: tx, drv: c.driver} return &Tx{ + ctx: ctx, config: cfg, Match: NewMatchClient(cfg), MatchPlayer: NewMatchPlayerClient(cfg), + Messages: NewMessagesClient(cfg), Player: NewPlayerClient(cfg), RoundStats: NewRoundStatsClient(cfg), Spray: NewSprayClient(cfg), @@ -151,6 +158,7 @@ func (c *Client) Close() error { func (c *Client) Use(hooks ...Hook) { c.Match.Use(hooks...) c.MatchPlayer.Use(hooks...) + c.Messages.Use(hooks...) c.Player.Use(hooks...) c.RoundStats.Use(hooks...) c.Spray.Use(hooks...) @@ -444,11 +452,133 @@ func (c *MatchPlayerClient) QuerySpray(mp *MatchPlayer) *SprayQuery { return query } +// QueryMessages queries the messages edge of a MatchPlayer. +func (c *MatchPlayerClient) QueryMessages(mp *MatchPlayer) *MessagesQuery { + query := &MessagesQuery{config: c.config} + query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) { + id := mp.ID + step := sqlgraph.NewStep( + sqlgraph.From(matchplayer.Table, matchplayer.FieldID, id), + sqlgraph.To(messages.Table, messages.FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, matchplayer.MessagesTable, matchplayer.MessagesColumn), + ) + fromV = sqlgraph.Neighbors(mp.driver.Dialect(), step) + return fromV, nil + } + return query +} + // Hooks returns the client hooks. func (c *MatchPlayerClient) Hooks() []Hook { return c.hooks.MatchPlayer } +// MessagesClient is a client for the Messages schema. +type MessagesClient struct { + config +} + +// NewMessagesClient returns a client for the Messages from the given config. +func NewMessagesClient(c config) *MessagesClient { + return &MessagesClient{config: c} +} + +// Use adds a list of mutation hooks to the hooks stack. +// A call to `Use(f, g, h)` equals to `messages.Hooks(f(g(h())))`. +func (c *MessagesClient) Use(hooks ...Hook) { + c.hooks.Messages = append(c.hooks.Messages, hooks...) +} + +// Create returns a create builder for Messages. +func (c *MessagesClient) Create() *MessagesCreate { + mutation := newMessagesMutation(c.config, OpCreate) + return &MessagesCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// CreateBulk returns a builder for creating a bulk of Messages entities. +func (c *MessagesClient) CreateBulk(builders ...*MessagesCreate) *MessagesCreateBulk { + return &MessagesCreateBulk{config: c.config, builders: builders} +} + +// Update returns an update builder for Messages. +func (c *MessagesClient) Update() *MessagesUpdate { + mutation := newMessagesMutation(c.config, OpUpdate) + return &MessagesUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOne returns an update builder for the given entity. +func (c *MessagesClient) UpdateOne(m *Messages) *MessagesUpdateOne { + mutation := newMessagesMutation(c.config, OpUpdateOne, withMessages(m)) + return &MessagesUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOneID returns an update builder for the given id. +func (c *MessagesClient) UpdateOneID(id int) *MessagesUpdateOne { + mutation := newMessagesMutation(c.config, OpUpdateOne, withMessagesID(id)) + return &MessagesUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// Delete returns a delete builder for Messages. +func (c *MessagesClient) Delete() *MessagesDelete { + mutation := newMessagesMutation(c.config, OpDelete) + return &MessagesDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// DeleteOne returns a delete builder for the given entity. +func (c *MessagesClient) DeleteOne(m *Messages) *MessagesDeleteOne { + return c.DeleteOneID(m.ID) +} + +// DeleteOneID returns a delete builder for the given id. +func (c *MessagesClient) DeleteOneID(id int) *MessagesDeleteOne { + builder := c.Delete().Where(messages.ID(id)) + builder.mutation.id = &id + builder.mutation.op = OpDeleteOne + return &MessagesDeleteOne{builder} +} + +// Query returns a query builder for Messages. +func (c *MessagesClient) Query() *MessagesQuery { + return &MessagesQuery{ + config: c.config, + } +} + +// Get returns a Messages entity by its id. +func (c *MessagesClient) Get(ctx context.Context, id int) (*Messages, error) { + return c.Query().Where(messages.ID(id)).Only(ctx) +} + +// GetX is like Get, but panics if an error occurs. +func (c *MessagesClient) GetX(ctx context.Context, id int) *Messages { + obj, err := c.Get(ctx, id) + if err != nil { + panic(err) + } + return obj +} + +// QueryMatchPlayer queries the match_player edge of a Messages. +func (c *MessagesClient) QueryMatchPlayer(m *Messages) *MatchPlayerQuery { + query := &MatchPlayerQuery{config: c.config} + query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) { + id := m.ID + step := sqlgraph.NewStep( + sqlgraph.From(messages.Table, messages.FieldID, id), + sqlgraph.To(matchplayer.Table, matchplayer.FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, messages.MatchPlayerTable, messages.MatchPlayerColumn), + ) + fromV = sqlgraph.Neighbors(m.driver.Dialect(), step) + return fromV, nil + } + return query +} + +// Hooks returns the client hooks. +func (c *MessagesClient) Hooks() []Hook { + return c.hooks.Messages +} + // PlayerClient is a client for the Player schema. type PlayerClient struct { config diff --git a/ent/config.go b/ent/config.go index 9a94c69..7958ab0 100644 --- a/ent/config.go +++ b/ent/config.go @@ -26,6 +26,7 @@ type config struct { type hooks struct { Match []ent.Hook MatchPlayer []ent.Hook + Messages []ent.Hook Player []ent.Hook RoundStats []ent.Hook Spray []ent.Hook diff --git a/ent/ent.go b/ent/ent.go index 5a5291c..5e09a9a 100644 --- a/ent/ent.go +++ b/ent/ent.go @@ -5,6 +5,7 @@ package ent import ( "csgowtfd/ent/match" "csgowtfd/ent/matchplayer" + "csgowtfd/ent/messages" "csgowtfd/ent/player" "csgowtfd/ent/roundstats" "csgowtfd/ent/spray" @@ -36,6 +37,7 @@ func columnChecker(table string) func(string) error { checks := map[string]func(string) bool{ match.Table: match.ValidColumn, matchplayer.Table: matchplayer.ValidColumn, + messages.Table: messages.ValidColumn, player.Table: player.ValidColumn, roundstats.Table: roundstats.ValidColumn, spray.Table: spray.ValidColumn, @@ -151,7 +153,7 @@ func Sum(field string) AggregateFunc { } } -// ValidationError returns when validating a field fails. +// ValidationError returns when validating a field or edge fails. type ValidationError struct { Name string // Field or edge name. err error diff --git a/ent/hook/hook.go b/ent/hook/hook.go index f61fd96..963ce67 100644 --- a/ent/hook/hook.go +++ b/ent/hook/hook.go @@ -34,6 +34,19 @@ func (f MatchPlayerFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, return f(ctx, mv) } +// The MessagesFunc type is an adapter to allow the use of ordinary +// function as Messages mutator. +type MessagesFunc func(context.Context, *ent.MessagesMutation) (ent.Value, error) + +// Mutate calls f(ctx, m). +func (f MessagesFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { + mv, ok := m.(*ent.MessagesMutation) + if !ok { + return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.MessagesMutation", m) + } + return f(ctx, mv) +} + // The PlayerFunc type is an adapter to allow the use of ordinary // function as Player mutator. type PlayerFunc func(context.Context, *ent.PlayerMutation) (ent.Value, error) diff --git a/ent/match.go b/ent/match.go index 7da5a87..1619a3b 100644 --- a/ent/match.go +++ b/ent/match.go @@ -40,6 +40,8 @@ type Match struct { VacPresent bool `json:"vac_present,omitempty"` // GamebanPresent holds the value of the "gameban_present" field. GamebanPresent bool `json:"gameban_present,omitempty"` + // DecryptionKey holds the value of the "decryption_key" field. + DecryptionKey []byte `json:"decryption_key,omitempty"` // Edges holds the relations/edges for other nodes in the graph. // The values are being populated by the MatchQuery when eager-loading is set. Edges MatchEdges `json:"edges"` @@ -79,6 +81,8 @@ func (*Match) scanValues(columns []string) ([]interface{}, error) { values := make([]interface{}, len(columns)) for i := range columns { switch columns[i] { + case match.FieldDecryptionKey: + values[i] = new([]byte) case match.FieldDemoParsed, match.FieldVacPresent, match.FieldGamebanPresent: values[i] = new(sql.NullBool) case match.FieldID, match.FieldScoreTeamA, match.FieldScoreTeamB, match.FieldDuration, match.FieldMatchResult, match.FieldMaxRounds: @@ -180,6 +184,12 @@ func (m *Match) assignValues(columns []string, values []interface{}) error { } else if value.Valid { m.GamebanPresent = value.Bool } + case match.FieldDecryptionKey: + if value, ok := values[i].(*[]byte); !ok { + return fmt.Errorf("unexpected type %T for field decryption_key", values[i]) + } else if value != nil { + m.DecryptionKey = *value + } } } return nil @@ -242,6 +252,8 @@ func (m *Match) String() string { builder.WriteString(fmt.Sprintf("%v", m.VacPresent)) builder.WriteString(", gameban_present=") builder.WriteString(fmt.Sprintf("%v", m.GamebanPresent)) + builder.WriteString(", decryption_key=") + builder.WriteString(fmt.Sprintf("%v", m.DecryptionKey)) builder.WriteByte(')') return builder.String() } diff --git a/ent/match/match.go b/ent/match/match.go index bcae620..2fbafbf 100644 --- a/ent/match/match.go +++ b/ent/match/match.go @@ -31,6 +31,8 @@ const ( FieldVacPresent = "vac_present" // FieldGamebanPresent holds the string denoting the gameban_present field in the database. FieldGamebanPresent = "gameban_present" + // FieldDecryptionKey holds the string denoting the decryption_key field in the database. + FieldDecryptionKey = "decryption_key" // EdgeStats holds the string denoting the stats edge name in mutations. EdgeStats = "stats" // EdgePlayers holds the string denoting the players edge name in mutations. @@ -66,6 +68,7 @@ var Columns = []string{ FieldDemoParsed, FieldVacPresent, FieldGamebanPresent, + FieldDecryptionKey, } var ( diff --git a/ent/match/where.go b/ent/match/where.go index 6b374ba..a84579a 100644 --- a/ent/match/where.go +++ b/ent/match/where.go @@ -177,6 +177,13 @@ func GamebanPresent(v bool) predicate.Match { }) } +// DecryptionKey applies equality check predicate on the "decryption_key" field. It's identical to DecryptionKeyEQ. +func DecryptionKey(v []byte) predicate.Match { + return predicate.Match(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldDecryptionKey), v)) + }) +} + // ShareCodeEQ applies the EQ predicate on the "share_code" field. func ShareCodeEQ(v string) predicate.Match { return predicate.Match(func(s *sql.Selector) { @@ -1036,6 +1043,96 @@ func GamebanPresentNEQ(v bool) predicate.Match { }) } +// DecryptionKeyEQ applies the EQ predicate on the "decryption_key" field. +func DecryptionKeyEQ(v []byte) predicate.Match { + return predicate.Match(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldDecryptionKey), v)) + }) +} + +// DecryptionKeyNEQ applies the NEQ predicate on the "decryption_key" field. +func DecryptionKeyNEQ(v []byte) predicate.Match { + return predicate.Match(func(s *sql.Selector) { + s.Where(sql.NEQ(s.C(FieldDecryptionKey), v)) + }) +} + +// DecryptionKeyIn applies the In predicate on the "decryption_key" field. +func DecryptionKeyIn(vs ...[]byte) predicate.Match { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.Match(func(s *sql.Selector) { + // if not arguments were provided, append the FALSE constants, + // since we can't apply "IN ()". This will make this predicate falsy. + if len(v) == 0 { + s.Where(sql.False()) + return + } + s.Where(sql.In(s.C(FieldDecryptionKey), v...)) + }) +} + +// DecryptionKeyNotIn applies the NotIn predicate on the "decryption_key" field. +func DecryptionKeyNotIn(vs ...[]byte) predicate.Match { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.Match(func(s *sql.Selector) { + // if not arguments were provided, append the FALSE constants, + // since we can't apply "IN ()". This will make this predicate falsy. + if len(v) == 0 { + s.Where(sql.False()) + return + } + s.Where(sql.NotIn(s.C(FieldDecryptionKey), v...)) + }) +} + +// DecryptionKeyGT applies the GT predicate on the "decryption_key" field. +func DecryptionKeyGT(v []byte) predicate.Match { + return predicate.Match(func(s *sql.Selector) { + s.Where(sql.GT(s.C(FieldDecryptionKey), v)) + }) +} + +// DecryptionKeyGTE applies the GTE predicate on the "decryption_key" field. +func DecryptionKeyGTE(v []byte) predicate.Match { + return predicate.Match(func(s *sql.Selector) { + s.Where(sql.GTE(s.C(FieldDecryptionKey), v)) + }) +} + +// DecryptionKeyLT applies the LT predicate on the "decryption_key" field. +func DecryptionKeyLT(v []byte) predicate.Match { + return predicate.Match(func(s *sql.Selector) { + s.Where(sql.LT(s.C(FieldDecryptionKey), v)) + }) +} + +// DecryptionKeyLTE applies the LTE predicate on the "decryption_key" field. +func DecryptionKeyLTE(v []byte) predicate.Match { + return predicate.Match(func(s *sql.Selector) { + s.Where(sql.LTE(s.C(FieldDecryptionKey), v)) + }) +} + +// DecryptionKeyIsNil applies the IsNil predicate on the "decryption_key" field. +func DecryptionKeyIsNil() predicate.Match { + return predicate.Match(func(s *sql.Selector) { + s.Where(sql.IsNull(s.C(FieldDecryptionKey))) + }) +} + +// DecryptionKeyNotNil applies the NotNil predicate on the "decryption_key" field. +func DecryptionKeyNotNil() predicate.Match { + return predicate.Match(func(s *sql.Selector) { + s.Where(sql.NotNull(s.C(FieldDecryptionKey))) + }) +} + // HasStats applies the HasEdge predicate on the "stats" edge. func HasStats() predicate.Match { return predicate.Match(func(s *sql.Selector) { diff --git a/ent/match_create.go b/ent/match_create.go index 5d4a4ed..ad78d22 100644 --- a/ent/match_create.go +++ b/ent/match_create.go @@ -134,6 +134,12 @@ func (mc *MatchCreate) SetNillableGamebanPresent(b *bool) *MatchCreate { return mc } +// SetDecryptionKey sets the "decryption_key" field. +func (mc *MatchCreate) SetDecryptionKey(b []byte) *MatchCreate { + mc.mutation.SetDecryptionKey(b) + return mc +} + // SetID sets the "id" field. func (mc *MatchCreate) SetID(u uint64) *MatchCreate { mc.mutation.SetID(u) @@ -258,34 +264,34 @@ func (mc *MatchCreate) defaults() { // check runs all checks and user-defined validators on the builder. func (mc *MatchCreate) check() error { if _, ok := mc.mutation.ShareCode(); !ok { - return &ValidationError{Name: "share_code", err: errors.New(`ent: missing required field "share_code"`)} + return &ValidationError{Name: "share_code", err: errors.New(`ent: missing required field "Match.share_code"`)} } if _, ok := mc.mutation.Date(); !ok { - return &ValidationError{Name: "date", err: errors.New(`ent: missing required field "date"`)} + return &ValidationError{Name: "date", err: errors.New(`ent: missing required field "Match.date"`)} } if _, ok := mc.mutation.ScoreTeamA(); !ok { - return &ValidationError{Name: "score_team_a", err: errors.New(`ent: missing required field "score_team_a"`)} + return &ValidationError{Name: "score_team_a", err: errors.New(`ent: missing required field "Match.score_team_a"`)} } if _, ok := mc.mutation.ScoreTeamB(); !ok { - return &ValidationError{Name: "score_team_b", err: errors.New(`ent: missing required field "score_team_b"`)} + return &ValidationError{Name: "score_team_b", err: errors.New(`ent: missing required field "Match.score_team_b"`)} } if _, ok := mc.mutation.Duration(); !ok { - return &ValidationError{Name: "duration", err: errors.New(`ent: missing required field "duration"`)} + return &ValidationError{Name: "duration", err: errors.New(`ent: missing required field "Match.duration"`)} } if _, ok := mc.mutation.MatchResult(); !ok { - return &ValidationError{Name: "match_result", err: errors.New(`ent: missing required field "match_result"`)} + return &ValidationError{Name: "match_result", err: errors.New(`ent: missing required field "Match.match_result"`)} } if _, ok := mc.mutation.MaxRounds(); !ok { - return &ValidationError{Name: "max_rounds", err: errors.New(`ent: missing required field "max_rounds"`)} + return &ValidationError{Name: "max_rounds", err: errors.New(`ent: missing required field "Match.max_rounds"`)} } if _, ok := mc.mutation.DemoParsed(); !ok { - return &ValidationError{Name: "demo_parsed", err: errors.New(`ent: missing required field "demo_parsed"`)} + return &ValidationError{Name: "demo_parsed", err: errors.New(`ent: missing required field "Match.demo_parsed"`)} } if _, ok := mc.mutation.VacPresent(); !ok { - return &ValidationError{Name: "vac_present", err: errors.New(`ent: missing required field "vac_present"`)} + return &ValidationError{Name: "vac_present", err: errors.New(`ent: missing required field "Match.vac_present"`)} } if _, ok := mc.mutation.GamebanPresent(); !ok { - return &ValidationError{Name: "gameban_present", err: errors.New(`ent: missing required field "gameban_present"`)} + return &ValidationError{Name: "gameban_present", err: errors.New(`ent: missing required field "Match.gameban_present"`)} } return nil } @@ -416,6 +422,14 @@ func (mc *MatchCreate) createSpec() (*Match, *sqlgraph.CreateSpec) { }) _node.GamebanPresent = value } + if value, ok := mc.mutation.DecryptionKey(); ok { + _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ + Type: field.TypeBytes, + Value: value, + Column: match.FieldDecryptionKey, + }) + _node.DecryptionKey = value + } if nodes := mc.mutation.StatsIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, diff --git a/ent/match_query.go b/ent/match_query.go index af83f58..ce2ec35 100644 --- a/ent/match_query.go +++ b/ent/match_query.go @@ -513,6 +513,10 @@ func (mq *MatchQuery) sqlCount(ctx context.Context) (int, error) { if len(mq.modifiers) > 0 { _spec.Modifiers = mq.modifiers } + _spec.Node.Columns = mq.fields + if len(mq.fields) > 0 { + _spec.Unique = mq.unique != nil && *mq.unique + } return sqlgraph.CountNodes(ctx, mq.driver, _spec) } @@ -584,6 +588,9 @@ func (mq *MatchQuery) sqlQuery(ctx context.Context) *sql.Selector { selector = mq.sql selector.Select(selector.Columns(columns...)...) } + if mq.unique != nil && *mq.unique { + selector.Distinct() + } for _, m := range mq.modifiers { m(selector) } @@ -871,9 +878,7 @@ func (mgb *MatchGroupBy) sqlQuery() *sql.Selector { for _, f := range mgb.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(mgb.fields...)...) diff --git a/ent/match_update.go b/ent/match_update.go index cf1f9ec..f025aea 100644 --- a/ent/match_update.go +++ b/ent/match_update.go @@ -8,6 +8,7 @@ import ( "csgowtfd/ent/matchplayer" "csgowtfd/ent/player" "csgowtfd/ent/predicate" + "errors" "fmt" "time" @@ -188,6 +189,18 @@ func (mu *MatchUpdate) SetNillableGamebanPresent(b *bool) *MatchUpdate { return mu } +// SetDecryptionKey sets the "decryption_key" field. +func (mu *MatchUpdate) SetDecryptionKey(b []byte) *MatchUpdate { + mu.mutation.SetDecryptionKey(b) + return mu +} + +// ClearDecryptionKey clears the value of the "decryption_key" field. +func (mu *MatchUpdate) ClearDecryptionKey() *MatchUpdate { + mu.mutation.ClearDecryptionKey() + return mu +} + // AddStatIDs adds the "stats" edge to the MatchPlayer entity by IDs. func (mu *MatchUpdate) AddStatIDs(ids ...int) *MatchUpdate { mu.mutation.AddStatIDs(ids...) @@ -468,6 +481,19 @@ func (mu *MatchUpdate) sqlSave(ctx context.Context) (n int, err error) { Column: match.FieldGamebanPresent, }) } + if value, ok := mu.mutation.DecryptionKey(); ok { + _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ + Type: field.TypeBytes, + Value: value, + Column: match.FieldDecryptionKey, + }) + } + if mu.mutation.DecryptionKeyCleared() { + _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ + Type: field.TypeBytes, + Column: match.FieldDecryptionKey, + }) + } if mu.mutation.StatsCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, @@ -754,6 +780,18 @@ func (muo *MatchUpdateOne) SetNillableGamebanPresent(b *bool) *MatchUpdateOne { return muo } +// SetDecryptionKey sets the "decryption_key" field. +func (muo *MatchUpdateOne) SetDecryptionKey(b []byte) *MatchUpdateOne { + muo.mutation.SetDecryptionKey(b) + return muo +} + +// ClearDecryptionKey clears the value of the "decryption_key" field. +func (muo *MatchUpdateOne) ClearDecryptionKey() *MatchUpdateOne { + muo.mutation.ClearDecryptionKey() + return muo +} + // AddStatIDs adds the "stats" edge to the MatchPlayer entity by IDs. func (muo *MatchUpdateOne) AddStatIDs(ids ...int) *MatchUpdateOne { muo.mutation.AddStatIDs(ids...) @@ -905,7 +943,7 @@ func (muo *MatchUpdateOne) sqlSave(ctx context.Context) (_node *Match, err error } id, ok := muo.mutation.ID() if !ok { - return nil, &ValidationError{Name: "ID", err: fmt.Errorf("missing Match.ID for update")} + return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Match.id" for update`)} } _spec.Node.ID.Value = id if fields := muo.fields; len(fields) > 0 { @@ -1058,6 +1096,19 @@ func (muo *MatchUpdateOne) sqlSave(ctx context.Context) (_node *Match, err error Column: match.FieldGamebanPresent, }) } + if value, ok := muo.mutation.DecryptionKey(); ok { + _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ + Type: field.TypeBytes, + Value: value, + Column: match.FieldDecryptionKey, + }) + } + if muo.mutation.DecryptionKeyCleared() { + _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ + Type: field.TypeBytes, + Column: match.FieldDecryptionKey, + }) + } if muo.mutation.StatsCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, diff --git a/ent/matchplayer.go b/ent/matchplayer.go index b916e43..22ce97a 100644 --- a/ent/matchplayer.go +++ b/ent/matchplayer.go @@ -98,9 +98,11 @@ type MatchPlayerEdges struct { RoundStats []*RoundStats `json:"round_stats,omitempty"` // Spray holds the value of the spray edge. Spray []*Spray `json:"spray,omitempty"` + // Messages holds the value of the messages edge. + Messages []*Messages `json:"messages,omitempty"` // loadedTypes holds the information for reporting if a // type was loaded (or requested) in eager-loading or not. - loadedTypes [5]bool + loadedTypes [6]bool } // MatchesOrErr returns the Matches value or an error if the edge @@ -158,6 +160,15 @@ func (e MatchPlayerEdges) SprayOrErr() ([]*Spray, error) { return nil, &NotLoadedError{edge: "spray"} } +// MessagesOrErr returns the Messages value or an error if the edge +// was not loaded in eager-loading. +func (e MatchPlayerEdges) MessagesOrErr() ([]*Messages, error) { + if e.loadedTypes[5] { + return e.Messages, nil + } + return nil, &NotLoadedError{edge: "messages"} +} + // scanValues returns the types for scanning values from sql.Rows. func (*MatchPlayer) scanValues(columns []string) ([]interface{}, error) { values := make([]interface{}, len(columns)) @@ -412,6 +423,11 @@ func (mp *MatchPlayer) QuerySpray() *SprayQuery { return (&MatchPlayerClient{config: mp.config}).QuerySpray(mp) } +// QueryMessages queries the "messages" edge of the MatchPlayer entity. +func (mp *MatchPlayer) QueryMessages() *MessagesQuery { + return (&MatchPlayerClient{config: mp.config}).QueryMessages(mp) +} + // Update returns a builder for updating this MatchPlayer. // Note that you need to call MatchPlayer.Unwrap() before calling this method if this MatchPlayer // was returned from a transaction, and the transaction was committed or rolled back. diff --git a/ent/matchplayer/matchplayer.go b/ent/matchplayer/matchplayer.go index 4732e85..ca64162 100644 --- a/ent/matchplayer/matchplayer.go +++ b/ent/matchplayer/matchplayer.go @@ -85,6 +85,8 @@ const ( EdgeRoundStats = "round_stats" // EdgeSpray holds the string denoting the spray edge name in mutations. EdgeSpray = "spray" + // EdgeMessages holds the string denoting the messages edge name in mutations. + EdgeMessages = "messages" // Table holds the table name of the matchplayer in the database. Table = "match_players" // MatchesTable is the table that holds the matches relation/edge. @@ -122,6 +124,13 @@ const ( SprayInverseTable = "sprays" // SprayColumn is the table column denoting the spray relation/edge. SprayColumn = "match_player_spray" + // MessagesTable is the table that holds the messages relation/edge. + MessagesTable = "messages" + // MessagesInverseTable is the table name for the Messages entity. + // It exists in this package in order to avoid circular dependency with the "messages" package. + MessagesInverseTable = "messages" + // MessagesColumn is the table column denoting the messages relation/edge. + MessagesColumn = "match_player_messages" ) // Columns holds all SQL columns for matchplayer fields. diff --git a/ent/matchplayer/where.go b/ent/matchplayer/where.go index 0cbd3ff..5f58e9e 100644 --- a/ent/matchplayer/where.go +++ b/ent/matchplayer/where.go @@ -3182,6 +3182,34 @@ func HasSprayWith(preds ...predicate.Spray) predicate.MatchPlayer { }) } +// HasMessages applies the HasEdge predicate on the "messages" edge. +func HasMessages() predicate.MatchPlayer { + return predicate.MatchPlayer(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(MessagesTable, FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, MessagesTable, MessagesColumn), + ) + sqlgraph.HasNeighbors(s, step) + }) +} + +// HasMessagesWith applies the HasEdge predicate on the "messages" edge with a given conditions (other predicates). +func HasMessagesWith(preds ...predicate.Messages) predicate.MatchPlayer { + return predicate.MatchPlayer(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(MessagesInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, MessagesTable, MessagesColumn), + ) + sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { + for _, p := range preds { + p(s) + } + }) + }) +} + // And groups predicates with the AND operator between them. func And(predicates ...predicate.MatchPlayer) predicate.MatchPlayer { return predicate.MatchPlayer(func(s *sql.Selector) { diff --git a/ent/matchplayer_create.go b/ent/matchplayer_create.go index 47e8138..435d8f2 100644 --- a/ent/matchplayer_create.go +++ b/ent/matchplayer_create.go @@ -6,6 +6,7 @@ import ( "context" "csgowtfd/ent/match" "csgowtfd/ent/matchplayer" + "csgowtfd/ent/messages" "csgowtfd/ent/player" "csgowtfd/ent/roundstats" "csgowtfd/ent/spray" @@ -499,6 +500,21 @@ func (mpc *MatchPlayerCreate) AddSpray(s ...*Spray) *MatchPlayerCreate { return mpc.AddSprayIDs(ids...) } +// AddMessageIDs adds the "messages" edge to the Messages entity by IDs. +func (mpc *MatchPlayerCreate) AddMessageIDs(ids ...int) *MatchPlayerCreate { + mpc.mutation.AddMessageIDs(ids...) + return mpc +} + +// AddMessages adds the "messages" edges to the Messages entity. +func (mpc *MatchPlayerCreate) AddMessages(m ...*Messages) *MatchPlayerCreate { + ids := make([]int, len(m)) + for i := range m { + ids[i] = m[i].ID + } + return mpc.AddMessageIDs(ids...) +} + // Mutation returns the MatchPlayerMutation object of the builder. func (mpc *MatchPlayerCreate) Mutation() *MatchPlayerMutation { return mpc.mutation @@ -570,29 +586,29 @@ func (mpc *MatchPlayerCreate) ExecX(ctx context.Context) { // check runs all checks and user-defined validators on the builder. func (mpc *MatchPlayerCreate) check() error { if _, ok := mpc.mutation.TeamID(); !ok { - return &ValidationError{Name: "team_id", err: errors.New(`ent: missing required field "team_id"`)} + return &ValidationError{Name: "team_id", err: errors.New(`ent: missing required field "MatchPlayer.team_id"`)} } if _, ok := mpc.mutation.Kills(); !ok { - return &ValidationError{Name: "kills", err: errors.New(`ent: missing required field "kills"`)} + return &ValidationError{Name: "kills", err: errors.New(`ent: missing required field "MatchPlayer.kills"`)} } if _, ok := mpc.mutation.Deaths(); !ok { - return &ValidationError{Name: "deaths", err: errors.New(`ent: missing required field "deaths"`)} + return &ValidationError{Name: "deaths", err: errors.New(`ent: missing required field "MatchPlayer.deaths"`)} } if _, ok := mpc.mutation.Assists(); !ok { - return &ValidationError{Name: "assists", err: errors.New(`ent: missing required field "assists"`)} + return &ValidationError{Name: "assists", err: errors.New(`ent: missing required field "MatchPlayer.assists"`)} } if _, ok := mpc.mutation.Headshot(); !ok { - return &ValidationError{Name: "headshot", err: errors.New(`ent: missing required field "headshot"`)} + return &ValidationError{Name: "headshot", err: errors.New(`ent: missing required field "MatchPlayer.headshot"`)} } if _, ok := mpc.mutation.Mvp(); !ok { - return &ValidationError{Name: "mvp", err: errors.New(`ent: missing required field "mvp"`)} + return &ValidationError{Name: "mvp", err: errors.New(`ent: missing required field "MatchPlayer.mvp"`)} } if _, ok := mpc.mutation.Score(); !ok { - return &ValidationError{Name: "score", err: errors.New(`ent: missing required field "score"`)} + return &ValidationError{Name: "score", err: errors.New(`ent: missing required field "MatchPlayer.score"`)} } if v, ok := mpc.mutation.Color(); ok { if err := matchplayer.ColorValidator(v); err != nil { - return &ValidationError{Name: "color", err: fmt.Errorf(`ent: validator failed for field "color": %w`, err)} + return &ValidationError{Name: "color", err: fmt.Errorf(`ent: validator failed for field "MatchPlayer.color": %w`, err)} } } return nil @@ -959,6 +975,25 @@ func (mpc *MatchPlayerCreate) createSpec() (*MatchPlayer, *sqlgraph.CreateSpec) } _spec.Edges = append(_spec.Edges, edge) } + if nodes := mpc.mutation.MessagesIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: matchplayer.MessagesTable, + Columns: []string{matchplayer.MessagesColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: &sqlgraph.FieldSpec{ + Type: field.TypeInt, + Column: messages.FieldID, + }, + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges = append(_spec.Edges, edge) + } return _node, _spec } diff --git a/ent/matchplayer_query.go b/ent/matchplayer_query.go index 8aed82e..db9bc5a 100644 --- a/ent/matchplayer_query.go +++ b/ent/matchplayer_query.go @@ -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...)...) diff --git a/ent/matchplayer_update.go b/ent/matchplayer_update.go index 7745b59..d3ae436 100644 --- a/ent/matchplayer_update.go +++ b/ent/matchplayer_update.go @@ -6,11 +6,13 @@ import ( "context" "csgowtfd/ent/match" "csgowtfd/ent/matchplayer" + "csgowtfd/ent/messages" "csgowtfd/ent/player" "csgowtfd/ent/predicate" "csgowtfd/ent/roundstats" "csgowtfd/ent/spray" "csgowtfd/ent/weapon" + "errors" "fmt" "entgo.io/ent/dialect/sql" @@ -104,7 +106,7 @@ func (mpu *MatchPlayerUpdate) SetMvp(u uint) *MatchPlayerUpdate { } // AddMvp adds u to the "mvp" field. -func (mpu *MatchPlayerUpdate) AddMvp(u uint) *MatchPlayerUpdate { +func (mpu *MatchPlayerUpdate) AddMvp(u int) *MatchPlayerUpdate { mpu.mutation.AddMvp(u) return mpu } @@ -192,7 +194,7 @@ func (mpu *MatchPlayerUpdate) SetNillableMk2(u *uint) *MatchPlayerUpdate { } // AddMk2 adds u to the "mk_2" field. -func (mpu *MatchPlayerUpdate) AddMk2(u uint) *MatchPlayerUpdate { +func (mpu *MatchPlayerUpdate) AddMk2(u int) *MatchPlayerUpdate { mpu.mutation.AddMk2(u) return mpu } @@ -219,7 +221,7 @@ func (mpu *MatchPlayerUpdate) SetNillableMk3(u *uint) *MatchPlayerUpdate { } // AddMk3 adds u to the "mk_3" field. -func (mpu *MatchPlayerUpdate) AddMk3(u uint) *MatchPlayerUpdate { +func (mpu *MatchPlayerUpdate) AddMk3(u int) *MatchPlayerUpdate { mpu.mutation.AddMk3(u) return mpu } @@ -246,7 +248,7 @@ func (mpu *MatchPlayerUpdate) SetNillableMk4(u *uint) *MatchPlayerUpdate { } // AddMk4 adds u to the "mk_4" field. -func (mpu *MatchPlayerUpdate) AddMk4(u uint) *MatchPlayerUpdate { +func (mpu *MatchPlayerUpdate) AddMk4(u int) *MatchPlayerUpdate { mpu.mutation.AddMk4(u) return mpu } @@ -273,7 +275,7 @@ func (mpu *MatchPlayerUpdate) SetNillableMk5(u *uint) *MatchPlayerUpdate { } // AddMk5 adds u to the "mk_5" field. -func (mpu *MatchPlayerUpdate) AddMk5(u uint) *MatchPlayerUpdate { +func (mpu *MatchPlayerUpdate) AddMk5(u int) *MatchPlayerUpdate { mpu.mutation.AddMk5(u) return mpu } @@ -300,7 +302,7 @@ func (mpu *MatchPlayerUpdate) SetNillableDmgEnemy(u *uint) *MatchPlayerUpdate { } // AddDmgEnemy adds u to the "dmg_enemy" field. -func (mpu *MatchPlayerUpdate) AddDmgEnemy(u uint) *MatchPlayerUpdate { +func (mpu *MatchPlayerUpdate) AddDmgEnemy(u int) *MatchPlayerUpdate { mpu.mutation.AddDmgEnemy(u) return mpu } @@ -327,7 +329,7 @@ func (mpu *MatchPlayerUpdate) SetNillableDmgTeam(u *uint) *MatchPlayerUpdate { } // AddDmgTeam adds u to the "dmg_team" field. -func (mpu *MatchPlayerUpdate) AddDmgTeam(u uint) *MatchPlayerUpdate { +func (mpu *MatchPlayerUpdate) AddDmgTeam(u int) *MatchPlayerUpdate { mpu.mutation.AddDmgTeam(u) return mpu } @@ -354,7 +356,7 @@ func (mpu *MatchPlayerUpdate) SetNillableUdHe(u *uint) *MatchPlayerUpdate { } // AddUdHe adds u to the "ud_he" field. -func (mpu *MatchPlayerUpdate) AddUdHe(u uint) *MatchPlayerUpdate { +func (mpu *MatchPlayerUpdate) AddUdHe(u int) *MatchPlayerUpdate { mpu.mutation.AddUdHe(u) return mpu } @@ -381,7 +383,7 @@ func (mpu *MatchPlayerUpdate) SetNillableUdFlames(u *uint) *MatchPlayerUpdate { } // AddUdFlames adds u to the "ud_flames" field. -func (mpu *MatchPlayerUpdate) AddUdFlames(u uint) *MatchPlayerUpdate { +func (mpu *MatchPlayerUpdate) AddUdFlames(u int) *MatchPlayerUpdate { mpu.mutation.AddUdFlames(u) return mpu } @@ -408,7 +410,7 @@ func (mpu *MatchPlayerUpdate) SetNillableUdFlash(u *uint) *MatchPlayerUpdate { } // AddUdFlash adds u to the "ud_flash" field. -func (mpu *MatchPlayerUpdate) AddUdFlash(u uint) *MatchPlayerUpdate { +func (mpu *MatchPlayerUpdate) AddUdFlash(u int) *MatchPlayerUpdate { mpu.mutation.AddUdFlash(u) return mpu } @@ -435,7 +437,7 @@ func (mpu *MatchPlayerUpdate) SetNillableUdDecoy(u *uint) *MatchPlayerUpdate { } // AddUdDecoy adds u to the "ud_decoy" field. -func (mpu *MatchPlayerUpdate) AddUdDecoy(u uint) *MatchPlayerUpdate { +func (mpu *MatchPlayerUpdate) AddUdDecoy(u int) *MatchPlayerUpdate { mpu.mutation.AddUdDecoy(u) return mpu } @@ -462,7 +464,7 @@ func (mpu *MatchPlayerUpdate) SetNillableUdSmoke(u *uint) *MatchPlayerUpdate { } // AddUdSmoke adds u to the "ud_smoke" field. -func (mpu *MatchPlayerUpdate) AddUdSmoke(u uint) *MatchPlayerUpdate { +func (mpu *MatchPlayerUpdate) AddUdSmoke(u int) *MatchPlayerUpdate { mpu.mutation.AddUdSmoke(u) return mpu } @@ -637,7 +639,7 @@ func (mpu *MatchPlayerUpdate) SetNillableFlashTotalSelf(u *uint) *MatchPlayerUpd } // AddFlashTotalSelf adds u to the "flash_total_self" field. -func (mpu *MatchPlayerUpdate) AddFlashTotalSelf(u uint) *MatchPlayerUpdate { +func (mpu *MatchPlayerUpdate) AddFlashTotalSelf(u int) *MatchPlayerUpdate { mpu.mutation.AddFlashTotalSelf(u) return mpu } @@ -664,7 +666,7 @@ func (mpu *MatchPlayerUpdate) SetNillableFlashTotalTeam(u *uint) *MatchPlayerUpd } // AddFlashTotalTeam adds u to the "flash_total_team" field. -func (mpu *MatchPlayerUpdate) AddFlashTotalTeam(u uint) *MatchPlayerUpdate { +func (mpu *MatchPlayerUpdate) AddFlashTotalTeam(u int) *MatchPlayerUpdate { mpu.mutation.AddFlashTotalTeam(u) return mpu } @@ -691,7 +693,7 @@ func (mpu *MatchPlayerUpdate) SetNillableFlashTotalEnemy(u *uint) *MatchPlayerUp } // AddFlashTotalEnemy adds u to the "flash_total_enemy" field. -func (mpu *MatchPlayerUpdate) AddFlashTotalEnemy(u uint) *MatchPlayerUpdate { +func (mpu *MatchPlayerUpdate) AddFlashTotalEnemy(u int) *MatchPlayerUpdate { mpu.mutation.AddFlashTotalEnemy(u) return mpu } @@ -852,6 +854,21 @@ func (mpu *MatchPlayerUpdate) AddSpray(s ...*Spray) *MatchPlayerUpdate { return mpu.AddSprayIDs(ids...) } +// AddMessageIDs adds the "messages" edge to the Messages entity by IDs. +func (mpu *MatchPlayerUpdate) AddMessageIDs(ids ...int) *MatchPlayerUpdate { + mpu.mutation.AddMessageIDs(ids...) + return mpu +} + +// AddMessages adds the "messages" edges to the Messages entity. +func (mpu *MatchPlayerUpdate) AddMessages(m ...*Messages) *MatchPlayerUpdate { + ids := make([]int, len(m)) + for i := range m { + ids[i] = m[i].ID + } + return mpu.AddMessageIDs(ids...) +} + // Mutation returns the MatchPlayerMutation object of the builder. func (mpu *MatchPlayerUpdate) Mutation() *MatchPlayerMutation { return mpu.mutation @@ -932,6 +949,27 @@ func (mpu *MatchPlayerUpdate) RemoveSpray(s ...*Spray) *MatchPlayerUpdate { return mpu.RemoveSprayIDs(ids...) } +// ClearMessages clears all "messages" edges to the Messages entity. +func (mpu *MatchPlayerUpdate) ClearMessages() *MatchPlayerUpdate { + mpu.mutation.ClearMessages() + return mpu +} + +// RemoveMessageIDs removes the "messages" edge to Messages entities by IDs. +func (mpu *MatchPlayerUpdate) RemoveMessageIDs(ids ...int) *MatchPlayerUpdate { + mpu.mutation.RemoveMessageIDs(ids...) + return mpu +} + +// RemoveMessages removes "messages" edges to Messages entities. +func (mpu *MatchPlayerUpdate) RemoveMessages(m ...*Messages) *MatchPlayerUpdate { + ids := make([]int, len(m)) + for i := range m { + ids[i] = m[i].ID + } + return mpu.RemoveMessageIDs(ids...) +} + // Save executes the query and returns the number of nodes affected by the update operation. func (mpu *MatchPlayerUpdate) Save(ctx context.Context) (int, error) { var ( @@ -996,7 +1034,7 @@ func (mpu *MatchPlayerUpdate) ExecX(ctx context.Context) { func (mpu *MatchPlayerUpdate) check() error { if v, ok := mpu.mutation.Color(); ok { if err := matchplayer.ColorValidator(v); err != nil { - return &ValidationError{Name: "color", err: fmt.Errorf("ent: validator failed for field \"color\": %w", err)} + return &ValidationError{Name: "color", err: fmt.Errorf(`ent: validator failed for field "MatchPlayer.color": %w`, err)} } } return nil @@ -1796,6 +1834,60 @@ func (mpu *MatchPlayerUpdate) sqlSave(ctx context.Context) (n int, err error) { } _spec.Edges.Add = append(_spec.Edges.Add, edge) } + if mpu.mutation.MessagesCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: matchplayer.MessagesTable, + Columns: []string{matchplayer.MessagesColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: &sqlgraph.FieldSpec{ + Type: field.TypeInt, + Column: messages.FieldID, + }, + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := mpu.mutation.RemovedMessagesIDs(); len(nodes) > 0 && !mpu.mutation.MessagesCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: matchplayer.MessagesTable, + Columns: []string{matchplayer.MessagesColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: &sqlgraph.FieldSpec{ + Type: field.TypeInt, + Column: messages.FieldID, + }, + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := mpu.mutation.MessagesIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: matchplayer.MessagesTable, + Columns: []string{matchplayer.MessagesColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: &sqlgraph.FieldSpec{ + Type: field.TypeInt, + Column: messages.FieldID, + }, + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } if n, err = sqlgraph.UpdateNodes(ctx, mpu.driver, _spec); err != nil { if _, ok := err.(*sqlgraph.NotFoundError); ok { err = &NotFoundError{matchplayer.Label} @@ -1888,7 +1980,7 @@ func (mpuo *MatchPlayerUpdateOne) SetMvp(u uint) *MatchPlayerUpdateOne { } // AddMvp adds u to the "mvp" field. -func (mpuo *MatchPlayerUpdateOne) AddMvp(u uint) *MatchPlayerUpdateOne { +func (mpuo *MatchPlayerUpdateOne) AddMvp(u int) *MatchPlayerUpdateOne { mpuo.mutation.AddMvp(u) return mpuo } @@ -1976,7 +2068,7 @@ func (mpuo *MatchPlayerUpdateOne) SetNillableMk2(u *uint) *MatchPlayerUpdateOne } // AddMk2 adds u to the "mk_2" field. -func (mpuo *MatchPlayerUpdateOne) AddMk2(u uint) *MatchPlayerUpdateOne { +func (mpuo *MatchPlayerUpdateOne) AddMk2(u int) *MatchPlayerUpdateOne { mpuo.mutation.AddMk2(u) return mpuo } @@ -2003,7 +2095,7 @@ func (mpuo *MatchPlayerUpdateOne) SetNillableMk3(u *uint) *MatchPlayerUpdateOne } // AddMk3 adds u to the "mk_3" field. -func (mpuo *MatchPlayerUpdateOne) AddMk3(u uint) *MatchPlayerUpdateOne { +func (mpuo *MatchPlayerUpdateOne) AddMk3(u int) *MatchPlayerUpdateOne { mpuo.mutation.AddMk3(u) return mpuo } @@ -2030,7 +2122,7 @@ func (mpuo *MatchPlayerUpdateOne) SetNillableMk4(u *uint) *MatchPlayerUpdateOne } // AddMk4 adds u to the "mk_4" field. -func (mpuo *MatchPlayerUpdateOne) AddMk4(u uint) *MatchPlayerUpdateOne { +func (mpuo *MatchPlayerUpdateOne) AddMk4(u int) *MatchPlayerUpdateOne { mpuo.mutation.AddMk4(u) return mpuo } @@ -2057,7 +2149,7 @@ func (mpuo *MatchPlayerUpdateOne) SetNillableMk5(u *uint) *MatchPlayerUpdateOne } // AddMk5 adds u to the "mk_5" field. -func (mpuo *MatchPlayerUpdateOne) AddMk5(u uint) *MatchPlayerUpdateOne { +func (mpuo *MatchPlayerUpdateOne) AddMk5(u int) *MatchPlayerUpdateOne { mpuo.mutation.AddMk5(u) return mpuo } @@ -2084,7 +2176,7 @@ func (mpuo *MatchPlayerUpdateOne) SetNillableDmgEnemy(u *uint) *MatchPlayerUpdat } // AddDmgEnemy adds u to the "dmg_enemy" field. -func (mpuo *MatchPlayerUpdateOne) AddDmgEnemy(u uint) *MatchPlayerUpdateOne { +func (mpuo *MatchPlayerUpdateOne) AddDmgEnemy(u int) *MatchPlayerUpdateOne { mpuo.mutation.AddDmgEnemy(u) return mpuo } @@ -2111,7 +2203,7 @@ func (mpuo *MatchPlayerUpdateOne) SetNillableDmgTeam(u *uint) *MatchPlayerUpdate } // AddDmgTeam adds u to the "dmg_team" field. -func (mpuo *MatchPlayerUpdateOne) AddDmgTeam(u uint) *MatchPlayerUpdateOne { +func (mpuo *MatchPlayerUpdateOne) AddDmgTeam(u int) *MatchPlayerUpdateOne { mpuo.mutation.AddDmgTeam(u) return mpuo } @@ -2138,7 +2230,7 @@ func (mpuo *MatchPlayerUpdateOne) SetNillableUdHe(u *uint) *MatchPlayerUpdateOne } // AddUdHe adds u to the "ud_he" field. -func (mpuo *MatchPlayerUpdateOne) AddUdHe(u uint) *MatchPlayerUpdateOne { +func (mpuo *MatchPlayerUpdateOne) AddUdHe(u int) *MatchPlayerUpdateOne { mpuo.mutation.AddUdHe(u) return mpuo } @@ -2165,7 +2257,7 @@ func (mpuo *MatchPlayerUpdateOne) SetNillableUdFlames(u *uint) *MatchPlayerUpdat } // AddUdFlames adds u to the "ud_flames" field. -func (mpuo *MatchPlayerUpdateOne) AddUdFlames(u uint) *MatchPlayerUpdateOne { +func (mpuo *MatchPlayerUpdateOne) AddUdFlames(u int) *MatchPlayerUpdateOne { mpuo.mutation.AddUdFlames(u) return mpuo } @@ -2192,7 +2284,7 @@ func (mpuo *MatchPlayerUpdateOne) SetNillableUdFlash(u *uint) *MatchPlayerUpdate } // AddUdFlash adds u to the "ud_flash" field. -func (mpuo *MatchPlayerUpdateOne) AddUdFlash(u uint) *MatchPlayerUpdateOne { +func (mpuo *MatchPlayerUpdateOne) AddUdFlash(u int) *MatchPlayerUpdateOne { mpuo.mutation.AddUdFlash(u) return mpuo } @@ -2219,7 +2311,7 @@ func (mpuo *MatchPlayerUpdateOne) SetNillableUdDecoy(u *uint) *MatchPlayerUpdate } // AddUdDecoy adds u to the "ud_decoy" field. -func (mpuo *MatchPlayerUpdateOne) AddUdDecoy(u uint) *MatchPlayerUpdateOne { +func (mpuo *MatchPlayerUpdateOne) AddUdDecoy(u int) *MatchPlayerUpdateOne { mpuo.mutation.AddUdDecoy(u) return mpuo } @@ -2246,7 +2338,7 @@ func (mpuo *MatchPlayerUpdateOne) SetNillableUdSmoke(u *uint) *MatchPlayerUpdate } // AddUdSmoke adds u to the "ud_smoke" field. -func (mpuo *MatchPlayerUpdateOne) AddUdSmoke(u uint) *MatchPlayerUpdateOne { +func (mpuo *MatchPlayerUpdateOne) AddUdSmoke(u int) *MatchPlayerUpdateOne { mpuo.mutation.AddUdSmoke(u) return mpuo } @@ -2421,7 +2513,7 @@ func (mpuo *MatchPlayerUpdateOne) SetNillableFlashTotalSelf(u *uint) *MatchPlaye } // AddFlashTotalSelf adds u to the "flash_total_self" field. -func (mpuo *MatchPlayerUpdateOne) AddFlashTotalSelf(u uint) *MatchPlayerUpdateOne { +func (mpuo *MatchPlayerUpdateOne) AddFlashTotalSelf(u int) *MatchPlayerUpdateOne { mpuo.mutation.AddFlashTotalSelf(u) return mpuo } @@ -2448,7 +2540,7 @@ func (mpuo *MatchPlayerUpdateOne) SetNillableFlashTotalTeam(u *uint) *MatchPlaye } // AddFlashTotalTeam adds u to the "flash_total_team" field. -func (mpuo *MatchPlayerUpdateOne) AddFlashTotalTeam(u uint) *MatchPlayerUpdateOne { +func (mpuo *MatchPlayerUpdateOne) AddFlashTotalTeam(u int) *MatchPlayerUpdateOne { mpuo.mutation.AddFlashTotalTeam(u) return mpuo } @@ -2475,7 +2567,7 @@ func (mpuo *MatchPlayerUpdateOne) SetNillableFlashTotalEnemy(u *uint) *MatchPlay } // AddFlashTotalEnemy adds u to the "flash_total_enemy" field. -func (mpuo *MatchPlayerUpdateOne) AddFlashTotalEnemy(u uint) *MatchPlayerUpdateOne { +func (mpuo *MatchPlayerUpdateOne) AddFlashTotalEnemy(u int) *MatchPlayerUpdateOne { mpuo.mutation.AddFlashTotalEnemy(u) return mpuo } @@ -2636,6 +2728,21 @@ func (mpuo *MatchPlayerUpdateOne) AddSpray(s ...*Spray) *MatchPlayerUpdateOne { return mpuo.AddSprayIDs(ids...) } +// AddMessageIDs adds the "messages" edge to the Messages entity by IDs. +func (mpuo *MatchPlayerUpdateOne) AddMessageIDs(ids ...int) *MatchPlayerUpdateOne { + mpuo.mutation.AddMessageIDs(ids...) + return mpuo +} + +// AddMessages adds the "messages" edges to the Messages entity. +func (mpuo *MatchPlayerUpdateOne) AddMessages(m ...*Messages) *MatchPlayerUpdateOne { + ids := make([]int, len(m)) + for i := range m { + ids[i] = m[i].ID + } + return mpuo.AddMessageIDs(ids...) +} + // Mutation returns the MatchPlayerMutation object of the builder. func (mpuo *MatchPlayerUpdateOne) Mutation() *MatchPlayerMutation { return mpuo.mutation @@ -2716,6 +2823,27 @@ func (mpuo *MatchPlayerUpdateOne) RemoveSpray(s ...*Spray) *MatchPlayerUpdateOne return mpuo.RemoveSprayIDs(ids...) } +// ClearMessages clears all "messages" edges to the Messages entity. +func (mpuo *MatchPlayerUpdateOne) ClearMessages() *MatchPlayerUpdateOne { + mpuo.mutation.ClearMessages() + return mpuo +} + +// RemoveMessageIDs removes the "messages" edge to Messages entities by IDs. +func (mpuo *MatchPlayerUpdateOne) RemoveMessageIDs(ids ...int) *MatchPlayerUpdateOne { + mpuo.mutation.RemoveMessageIDs(ids...) + return mpuo +} + +// RemoveMessages removes "messages" edges to Messages entities. +func (mpuo *MatchPlayerUpdateOne) RemoveMessages(m ...*Messages) *MatchPlayerUpdateOne { + ids := make([]int, len(m)) + for i := range m { + ids[i] = m[i].ID + } + return mpuo.RemoveMessageIDs(ids...) +} + // Select allows selecting one or more fields (columns) of the returned entity. // The default is selecting all fields defined in the entity schema. func (mpuo *MatchPlayerUpdateOne) Select(field string, fields ...string) *MatchPlayerUpdateOne { @@ -2787,7 +2915,7 @@ func (mpuo *MatchPlayerUpdateOne) ExecX(ctx context.Context) { func (mpuo *MatchPlayerUpdateOne) check() error { if v, ok := mpuo.mutation.Color(); ok { if err := matchplayer.ColorValidator(v); err != nil { - return &ValidationError{Name: "color", err: fmt.Errorf("ent: validator failed for field \"color\": %w", err)} + return &ValidationError{Name: "color", err: fmt.Errorf(`ent: validator failed for field "MatchPlayer.color": %w`, err)} } } return nil @@ -2806,7 +2934,7 @@ func (mpuo *MatchPlayerUpdateOne) sqlSave(ctx context.Context) (_node *MatchPlay } id, ok := mpuo.mutation.ID() if !ok { - return nil, &ValidationError{Name: "ID", err: fmt.Errorf("missing MatchPlayer.ID for update")} + return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "MatchPlayer.id" for update`)} } _spec.Node.ID.Value = id if fields := mpuo.fields; len(fields) > 0 { @@ -3604,6 +3732,60 @@ func (mpuo *MatchPlayerUpdateOne) sqlSave(ctx context.Context) (_node *MatchPlay } _spec.Edges.Add = append(_spec.Edges.Add, edge) } + if mpuo.mutation.MessagesCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: matchplayer.MessagesTable, + Columns: []string{matchplayer.MessagesColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: &sqlgraph.FieldSpec{ + Type: field.TypeInt, + Column: messages.FieldID, + }, + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := mpuo.mutation.RemovedMessagesIDs(); len(nodes) > 0 && !mpuo.mutation.MessagesCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: matchplayer.MessagesTable, + Columns: []string{matchplayer.MessagesColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: &sqlgraph.FieldSpec{ + Type: field.TypeInt, + Column: messages.FieldID, + }, + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := mpuo.mutation.MessagesIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: matchplayer.MessagesTable, + Columns: []string{matchplayer.MessagesColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: &sqlgraph.FieldSpec{ + Type: field.TypeInt, + Column: messages.FieldID, + }, + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } _node = &MatchPlayer{config: mpuo.config} _spec.Assign = _node.assignValues _spec.ScanValues = _node.scanValues diff --git a/ent/messages.go b/ent/messages.go new file mode 100644 index 0000000..5eaf228 --- /dev/null +++ b/ent/messages.go @@ -0,0 +1,153 @@ +// Code generated by entc, DO NOT EDIT. + +package ent + +import ( + "csgowtfd/ent/matchplayer" + "csgowtfd/ent/messages" + "fmt" + "strings" + + "entgo.io/ent/dialect/sql" +) + +// Messages is the model entity for the Messages schema. +type Messages struct { + config `json:"-"` + // ID of the ent. + ID int `json:"id,omitempty"` + // Message holds the value of the "message" field. + Message string `json:"message,omitempty"` + // AllChat holds the value of the "all_chat" field. + AllChat bool `json:"all_chat,omitempty"` + // Edges holds the relations/edges for other nodes in the graph. + // The values are being populated by the MessagesQuery when eager-loading is set. + Edges MessagesEdges `json:"edges"` + match_player_messages *int +} + +// MessagesEdges holds the relations/edges for other nodes in the graph. +type MessagesEdges struct { + // MatchPlayer holds the value of the match_player edge. + MatchPlayer *MatchPlayer `json:"match_player,omitempty"` + // loadedTypes holds the information for reporting if a + // type was loaded (or requested) in eager-loading or not. + loadedTypes [1]bool +} + +// MatchPlayerOrErr returns the MatchPlayer value or an error if the edge +// was not loaded in eager-loading, or loaded but was not found. +func (e MessagesEdges) MatchPlayerOrErr() (*MatchPlayer, error) { + if e.loadedTypes[0] { + if e.MatchPlayer == nil { + // The edge match_player was loaded in eager-loading, + // but was not found. + return nil, &NotFoundError{label: matchplayer.Label} + } + return e.MatchPlayer, nil + } + return nil, &NotLoadedError{edge: "match_player"} +} + +// scanValues returns the types for scanning values from sql.Rows. +func (*Messages) scanValues(columns []string) ([]interface{}, error) { + values := make([]interface{}, len(columns)) + for i := range columns { + switch columns[i] { + case messages.FieldAllChat: + values[i] = new(sql.NullBool) + case messages.FieldID: + values[i] = new(sql.NullInt64) + case messages.FieldMessage: + values[i] = new(sql.NullString) + case messages.ForeignKeys[0]: // match_player_messages + values[i] = new(sql.NullInt64) + default: + return nil, fmt.Errorf("unexpected column %q for type Messages", columns[i]) + } + } + return values, nil +} + +// assignValues assigns the values that were returned from sql.Rows (after scanning) +// to the Messages fields. +func (m *Messages) assignValues(columns []string, values []interface{}) error { + if m, n := len(values), len(columns); m < n { + return fmt.Errorf("mismatch number of scan values: %d != %d", m, n) + } + for i := range columns { + switch columns[i] { + case messages.FieldID: + value, ok := values[i].(*sql.NullInt64) + if !ok { + return fmt.Errorf("unexpected type %T for field id", value) + } + m.ID = int(value.Int64) + case messages.FieldMessage: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field message", values[i]) + } else if value.Valid { + m.Message = value.String + } + case messages.FieldAllChat: + if value, ok := values[i].(*sql.NullBool); !ok { + return fmt.Errorf("unexpected type %T for field all_chat", values[i]) + } else if value.Valid { + m.AllChat = value.Bool + } + case messages.ForeignKeys[0]: + if value, ok := values[i].(*sql.NullInt64); !ok { + return fmt.Errorf("unexpected type %T for edge-field match_player_messages", value) + } else if value.Valid { + m.match_player_messages = new(int) + *m.match_player_messages = int(value.Int64) + } + } + } + return nil +} + +// QueryMatchPlayer queries the "match_player" edge of the Messages entity. +func (m *Messages) QueryMatchPlayer() *MatchPlayerQuery { + return (&MessagesClient{config: m.config}).QueryMatchPlayer(m) +} + +// Update returns a builder for updating this Messages. +// Note that you need to call Messages.Unwrap() before calling this method if this Messages +// was returned from a transaction, and the transaction was committed or rolled back. +func (m *Messages) Update() *MessagesUpdateOne { + return (&MessagesClient{config: m.config}).UpdateOne(m) +} + +// Unwrap unwraps the Messages entity that was returned from a transaction after it was closed, +// so that all future queries will be executed through the driver which created the transaction. +func (m *Messages) Unwrap() *Messages { + tx, ok := m.config.driver.(*txDriver) + if !ok { + panic("ent: Messages is not a transactional entity") + } + m.config.driver = tx.drv + return m +} + +// String implements the fmt.Stringer. +func (m *Messages) String() string { + var builder strings.Builder + builder.WriteString("Messages(") + builder.WriteString(fmt.Sprintf("id=%v", m.ID)) + builder.WriteString(", message=") + builder.WriteString(m.Message) + builder.WriteString(", all_chat=") + builder.WriteString(fmt.Sprintf("%v", m.AllChat)) + builder.WriteByte(')') + return builder.String() +} + +// MessagesSlice is a parsable slice of Messages. +type MessagesSlice []*Messages + +func (m MessagesSlice) config(cfg config) { + for _i := range m { + m[_i].config = cfg + } +} diff --git a/ent/messages/messages.go b/ent/messages/messages.go new file mode 100644 index 0000000..6a7df02 --- /dev/null +++ b/ent/messages/messages.go @@ -0,0 +1,53 @@ +// Code generated by entc, DO NOT EDIT. + +package messages + +const ( + // Label holds the string label denoting the messages type in the database. + Label = "messages" + // FieldID holds the string denoting the id field in the database. + FieldID = "id" + // FieldMessage holds the string denoting the message field in the database. + FieldMessage = "message" + // FieldAllChat holds the string denoting the all_chat field in the database. + FieldAllChat = "all_chat" + // EdgeMatchPlayer holds the string denoting the match_player edge name in mutations. + EdgeMatchPlayer = "match_player" + // Table holds the table name of the messages in the database. + Table = "messages" + // MatchPlayerTable is the table that holds the match_player relation/edge. + MatchPlayerTable = "messages" + // MatchPlayerInverseTable is the table name for the MatchPlayer entity. + // It exists in this package in order to avoid circular dependency with the "matchplayer" package. + MatchPlayerInverseTable = "match_players" + // MatchPlayerColumn is the table column denoting the match_player relation/edge. + MatchPlayerColumn = "match_player_messages" +) + +// Columns holds all SQL columns for messages fields. +var Columns = []string{ + FieldID, + FieldMessage, + FieldAllChat, +} + +// ForeignKeys holds the SQL foreign-keys that are owned by the "messages" +// table and are not defined as standalone fields in the schema. +var ForeignKeys = []string{ + "match_player_messages", +} + +// ValidColumn reports if the column name is valid (part of the table columns). +func ValidColumn(column string) bool { + for i := range Columns { + if column == Columns[i] { + return true + } + } + for i := range ForeignKeys { + if column == ForeignKeys[i] { + return true + } + } + return false +} diff --git a/ent/messages/where.go b/ent/messages/where.go new file mode 100644 index 0000000..2e4ff91 --- /dev/null +++ b/ent/messages/where.go @@ -0,0 +1,292 @@ +// Code generated by entc, DO NOT EDIT. + +package messages + +import ( + "csgowtfd/ent/predicate" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" +) + +// ID filters vertices based on their ID field. +func ID(id int) predicate.Messages { + return predicate.Messages(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldID), id)) + }) +} + +// IDEQ applies the EQ predicate on the ID field. +func IDEQ(id int) predicate.Messages { + return predicate.Messages(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldID), id)) + }) +} + +// IDNEQ applies the NEQ predicate on the ID field. +func IDNEQ(id int) predicate.Messages { + return predicate.Messages(func(s *sql.Selector) { + s.Where(sql.NEQ(s.C(FieldID), id)) + }) +} + +// IDIn applies the In predicate on the ID field. +func IDIn(ids ...int) predicate.Messages { + return predicate.Messages(func(s *sql.Selector) { + // if not arguments were provided, append the FALSE constants, + // since we can't apply "IN ()". This will make this predicate falsy. + if len(ids) == 0 { + s.Where(sql.False()) + return + } + v := make([]interface{}, len(ids)) + for i := range v { + v[i] = ids[i] + } + s.Where(sql.In(s.C(FieldID), v...)) + }) +} + +// IDNotIn applies the NotIn predicate on the ID field. +func IDNotIn(ids ...int) predicate.Messages { + return predicate.Messages(func(s *sql.Selector) { + // if not arguments were provided, append the FALSE constants, + // since we can't apply "IN ()". This will make this predicate falsy. + if len(ids) == 0 { + s.Where(sql.False()) + return + } + v := make([]interface{}, len(ids)) + for i := range v { + v[i] = ids[i] + } + s.Where(sql.NotIn(s.C(FieldID), v...)) + }) +} + +// IDGT applies the GT predicate on the ID field. +func IDGT(id int) predicate.Messages { + return predicate.Messages(func(s *sql.Selector) { + s.Where(sql.GT(s.C(FieldID), id)) + }) +} + +// IDGTE applies the GTE predicate on the ID field. +func IDGTE(id int) predicate.Messages { + return predicate.Messages(func(s *sql.Selector) { + s.Where(sql.GTE(s.C(FieldID), id)) + }) +} + +// IDLT applies the LT predicate on the ID field. +func IDLT(id int) predicate.Messages { + return predicate.Messages(func(s *sql.Selector) { + s.Where(sql.LT(s.C(FieldID), id)) + }) +} + +// IDLTE applies the LTE predicate on the ID field. +func IDLTE(id int) predicate.Messages { + return predicate.Messages(func(s *sql.Selector) { + s.Where(sql.LTE(s.C(FieldID), id)) + }) +} + +// Message applies equality check predicate on the "message" field. It's identical to MessageEQ. +func Message(v string) predicate.Messages { + return predicate.Messages(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldMessage), v)) + }) +} + +// AllChat applies equality check predicate on the "all_chat" field. It's identical to AllChatEQ. +func AllChat(v bool) predicate.Messages { + return predicate.Messages(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldAllChat), v)) + }) +} + +// MessageEQ applies the EQ predicate on the "message" field. +func MessageEQ(v string) predicate.Messages { + return predicate.Messages(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldMessage), v)) + }) +} + +// MessageNEQ applies the NEQ predicate on the "message" field. +func MessageNEQ(v string) predicate.Messages { + return predicate.Messages(func(s *sql.Selector) { + s.Where(sql.NEQ(s.C(FieldMessage), v)) + }) +} + +// MessageIn applies the In predicate on the "message" field. +func MessageIn(vs ...string) predicate.Messages { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.Messages(func(s *sql.Selector) { + // if not arguments were provided, append the FALSE constants, + // since we can't apply "IN ()". This will make this predicate falsy. + if len(v) == 0 { + s.Where(sql.False()) + return + } + s.Where(sql.In(s.C(FieldMessage), v...)) + }) +} + +// MessageNotIn applies the NotIn predicate on the "message" field. +func MessageNotIn(vs ...string) predicate.Messages { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.Messages(func(s *sql.Selector) { + // if not arguments were provided, append the FALSE constants, + // since we can't apply "IN ()". This will make this predicate falsy. + if len(v) == 0 { + s.Where(sql.False()) + return + } + s.Where(sql.NotIn(s.C(FieldMessage), v...)) + }) +} + +// MessageGT applies the GT predicate on the "message" field. +func MessageGT(v string) predicate.Messages { + return predicate.Messages(func(s *sql.Selector) { + s.Where(sql.GT(s.C(FieldMessage), v)) + }) +} + +// MessageGTE applies the GTE predicate on the "message" field. +func MessageGTE(v string) predicate.Messages { + return predicate.Messages(func(s *sql.Selector) { + s.Where(sql.GTE(s.C(FieldMessage), v)) + }) +} + +// MessageLT applies the LT predicate on the "message" field. +func MessageLT(v string) predicate.Messages { + return predicate.Messages(func(s *sql.Selector) { + s.Where(sql.LT(s.C(FieldMessage), v)) + }) +} + +// MessageLTE applies the LTE predicate on the "message" field. +func MessageLTE(v string) predicate.Messages { + return predicate.Messages(func(s *sql.Selector) { + s.Where(sql.LTE(s.C(FieldMessage), v)) + }) +} + +// MessageContains applies the Contains predicate on the "message" field. +func MessageContains(v string) predicate.Messages { + return predicate.Messages(func(s *sql.Selector) { + s.Where(sql.Contains(s.C(FieldMessage), v)) + }) +} + +// MessageHasPrefix applies the HasPrefix predicate on the "message" field. +func MessageHasPrefix(v string) predicate.Messages { + return predicate.Messages(func(s *sql.Selector) { + s.Where(sql.HasPrefix(s.C(FieldMessage), v)) + }) +} + +// MessageHasSuffix applies the HasSuffix predicate on the "message" field. +func MessageHasSuffix(v string) predicate.Messages { + return predicate.Messages(func(s *sql.Selector) { + s.Where(sql.HasSuffix(s.C(FieldMessage), v)) + }) +} + +// MessageEqualFold applies the EqualFold predicate on the "message" field. +func MessageEqualFold(v string) predicate.Messages { + return predicate.Messages(func(s *sql.Selector) { + s.Where(sql.EqualFold(s.C(FieldMessage), v)) + }) +} + +// MessageContainsFold applies the ContainsFold predicate on the "message" field. +func MessageContainsFold(v string) predicate.Messages { + return predicate.Messages(func(s *sql.Selector) { + s.Where(sql.ContainsFold(s.C(FieldMessage), v)) + }) +} + +// AllChatEQ applies the EQ predicate on the "all_chat" field. +func AllChatEQ(v bool) predicate.Messages { + return predicate.Messages(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldAllChat), v)) + }) +} + +// AllChatNEQ applies the NEQ predicate on the "all_chat" field. +func AllChatNEQ(v bool) predicate.Messages { + return predicate.Messages(func(s *sql.Selector) { + s.Where(sql.NEQ(s.C(FieldAllChat), v)) + }) +} + +// HasMatchPlayer applies the HasEdge predicate on the "match_player" edge. +func HasMatchPlayer() predicate.Messages { + return predicate.Messages(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(MatchPlayerTable, FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, MatchPlayerTable, MatchPlayerColumn), + ) + sqlgraph.HasNeighbors(s, step) + }) +} + +// HasMatchPlayerWith applies the HasEdge predicate on the "match_player" edge with a given conditions (other predicates). +func HasMatchPlayerWith(preds ...predicate.MatchPlayer) predicate.Messages { + return predicate.Messages(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(MatchPlayerInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, MatchPlayerTable, MatchPlayerColumn), + ) + sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { + for _, p := range preds { + p(s) + } + }) + }) +} + +// And groups predicates with the AND operator between them. +func And(predicates ...predicate.Messages) predicate.Messages { + return predicate.Messages(func(s *sql.Selector) { + s1 := s.Clone().SetP(nil) + for _, p := range predicates { + p(s1) + } + s.Where(s1.P()) + }) +} + +// Or groups predicates with the OR operator between them. +func Or(predicates ...predicate.Messages) predicate.Messages { + return predicate.Messages(func(s *sql.Selector) { + s1 := s.Clone().SetP(nil) + for i, p := range predicates { + if i > 0 { + s1.Or() + } + p(s1) + } + s.Where(s1.P()) + }) +} + +// Not applies the not operator on the given predicate. +func Not(p predicate.Messages) predicate.Messages { + return predicate.Messages(func(s *sql.Selector) { + p(s.Not()) + }) +} diff --git a/ent/messages_create.go b/ent/messages_create.go new file mode 100644 index 0000000..8e91116 --- /dev/null +++ b/ent/messages_create.go @@ -0,0 +1,277 @@ +// Code generated by entc, DO NOT EDIT. + +package ent + +import ( + "context" + "csgowtfd/ent/matchplayer" + "csgowtfd/ent/messages" + "errors" + "fmt" + + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" +) + +// MessagesCreate is the builder for creating a Messages entity. +type MessagesCreate struct { + config + mutation *MessagesMutation + hooks []Hook +} + +// SetMessage sets the "message" field. +func (mc *MessagesCreate) SetMessage(s string) *MessagesCreate { + mc.mutation.SetMessage(s) + return mc +} + +// SetAllChat sets the "all_chat" field. +func (mc *MessagesCreate) SetAllChat(b bool) *MessagesCreate { + mc.mutation.SetAllChat(b) + return mc +} + +// SetMatchPlayerID sets the "match_player" edge to the MatchPlayer entity by ID. +func (mc *MessagesCreate) SetMatchPlayerID(id int) *MessagesCreate { + mc.mutation.SetMatchPlayerID(id) + return mc +} + +// SetNillableMatchPlayerID sets the "match_player" edge to the MatchPlayer entity by ID if the given value is not nil. +func (mc *MessagesCreate) SetNillableMatchPlayerID(id *int) *MessagesCreate { + if id != nil { + mc = mc.SetMatchPlayerID(*id) + } + return mc +} + +// SetMatchPlayer sets the "match_player" edge to the MatchPlayer entity. +func (mc *MessagesCreate) SetMatchPlayer(m *MatchPlayer) *MessagesCreate { + return mc.SetMatchPlayerID(m.ID) +} + +// Mutation returns the MessagesMutation object of the builder. +func (mc *MessagesCreate) Mutation() *MessagesMutation { + return mc.mutation +} + +// Save creates the Messages in the database. +func (mc *MessagesCreate) Save(ctx context.Context) (*Messages, error) { + var ( + err error + node *Messages + ) + if len(mc.hooks) == 0 { + if err = mc.check(); err != nil { + return nil, err + } + node, err = mc.sqlSave(ctx) + } else { + var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { + mutation, ok := m.(*MessagesMutation) + if !ok { + return nil, fmt.Errorf("unexpected mutation type %T", m) + } + if err = mc.check(); err != nil { + return nil, err + } + mc.mutation = mutation + if node, err = mc.sqlSave(ctx); err != nil { + return nil, err + } + mutation.id = &node.ID + mutation.done = true + return node, err + }) + for i := len(mc.hooks) - 1; i >= 0; i-- { + if mc.hooks[i] == nil { + return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") + } + mut = mc.hooks[i](mut) + } + if _, err := mut.Mutate(ctx, mc.mutation); err != nil { + return nil, err + } + } + return node, err +} + +// SaveX calls Save and panics if Save returns an error. +func (mc *MessagesCreate) SaveX(ctx context.Context) *Messages { + v, err := mc.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (mc *MessagesCreate) Exec(ctx context.Context) error { + _, err := mc.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (mc *MessagesCreate) ExecX(ctx context.Context) { + if err := mc.Exec(ctx); err != nil { + panic(err) + } +} + +// check runs all checks and user-defined validators on the builder. +func (mc *MessagesCreate) check() error { + if _, ok := mc.mutation.Message(); !ok { + return &ValidationError{Name: "message", err: errors.New(`ent: missing required field "Messages.message"`)} + } + if _, ok := mc.mutation.AllChat(); !ok { + return &ValidationError{Name: "all_chat", err: errors.New(`ent: missing required field "Messages.all_chat"`)} + } + return nil +} + +func (mc *MessagesCreate) sqlSave(ctx context.Context) (*Messages, error) { + _node, _spec := mc.createSpec() + if err := sqlgraph.CreateNode(ctx, mc.driver, _spec); err != nil { + if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{err.Error(), err} + } + return nil, err + } + id := _spec.ID.Value.(int64) + _node.ID = int(id) + return _node, nil +} + +func (mc *MessagesCreate) createSpec() (*Messages, *sqlgraph.CreateSpec) { + var ( + _node = &Messages{config: mc.config} + _spec = &sqlgraph.CreateSpec{ + Table: messages.Table, + ID: &sqlgraph.FieldSpec{ + Type: field.TypeInt, + Column: messages.FieldID, + }, + } + ) + if value, ok := mc.mutation.Message(); ok { + _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ + Type: field.TypeString, + Value: value, + Column: messages.FieldMessage, + }) + _node.Message = value + } + if value, ok := mc.mutation.AllChat(); ok { + _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ + Type: field.TypeBool, + Value: value, + Column: messages.FieldAllChat, + }) + _node.AllChat = value + } + if nodes := mc.mutation.MatchPlayerIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: messages.MatchPlayerTable, + Columns: []string{messages.MatchPlayerColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: &sqlgraph.FieldSpec{ + Type: field.TypeInt, + Column: matchplayer.FieldID, + }, + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _node.match_player_messages = &nodes[0] + _spec.Edges = append(_spec.Edges, edge) + } + return _node, _spec +} + +// MessagesCreateBulk is the builder for creating many Messages entities in bulk. +type MessagesCreateBulk struct { + config + builders []*MessagesCreate +} + +// Save creates the Messages entities in the database. +func (mcb *MessagesCreateBulk) Save(ctx context.Context) ([]*Messages, error) { + specs := make([]*sqlgraph.CreateSpec, len(mcb.builders)) + nodes := make([]*Messages, len(mcb.builders)) + mutators := make([]Mutator, len(mcb.builders)) + for i := range mcb.builders { + func(i int, root context.Context) { + builder := mcb.builders[i] + var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { + mutation, ok := m.(*MessagesMutation) + if !ok { + return nil, fmt.Errorf("unexpected mutation type %T", m) + } + if err := builder.check(); err != nil { + return nil, err + } + builder.mutation = mutation + nodes[i], specs[i] = builder.createSpec() + var err error + if i < len(mutators)-1 { + _, err = mutators[i+1].Mutate(root, mcb.builders[i+1].mutation) + } else { + spec := &sqlgraph.BatchCreateSpec{Nodes: specs} + // Invoke the actual operation on the latest mutation in the chain. + if err = sqlgraph.BatchCreate(ctx, mcb.driver, spec); err != nil { + if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{err.Error(), err} + } + } + } + if err != nil { + return nil, err + } + mutation.id = &nodes[i].ID + mutation.done = true + if specs[i].ID.Value != nil { + id := specs[i].ID.Value.(int64) + nodes[i].ID = int(id) + } + return nodes[i], nil + }) + for i := len(builder.hooks) - 1; i >= 0; i-- { + mut = builder.hooks[i](mut) + } + mutators[i] = mut + }(i, ctx) + } + if len(mutators) > 0 { + if _, err := mutators[0].Mutate(ctx, mcb.builders[0].mutation); err != nil { + return nil, err + } + } + return nodes, nil +} + +// SaveX is like Save, but panics if an error occurs. +func (mcb *MessagesCreateBulk) SaveX(ctx context.Context) []*Messages { + v, err := mcb.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (mcb *MessagesCreateBulk) Exec(ctx context.Context) error { + _, err := mcb.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (mcb *MessagesCreateBulk) ExecX(ctx context.Context) { + if err := mcb.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/ent/messages_delete.go b/ent/messages_delete.go new file mode 100644 index 0000000..25254b8 --- /dev/null +++ b/ent/messages_delete.go @@ -0,0 +1,111 @@ +// Code generated by entc, DO NOT EDIT. + +package ent + +import ( + "context" + "csgowtfd/ent/messages" + "csgowtfd/ent/predicate" + "fmt" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" +) + +// MessagesDelete is the builder for deleting a Messages entity. +type MessagesDelete struct { + config + hooks []Hook + mutation *MessagesMutation +} + +// Where appends a list predicates to the MessagesDelete builder. +func (md *MessagesDelete) Where(ps ...predicate.Messages) *MessagesDelete { + md.mutation.Where(ps...) + return md +} + +// Exec executes the deletion query and returns how many vertices were deleted. +func (md *MessagesDelete) Exec(ctx context.Context) (int, error) { + var ( + err error + affected int + ) + if len(md.hooks) == 0 { + affected, err = md.sqlExec(ctx) + } else { + var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { + mutation, ok := m.(*MessagesMutation) + if !ok { + return nil, fmt.Errorf("unexpected mutation type %T", m) + } + md.mutation = mutation + affected, err = md.sqlExec(ctx) + mutation.done = true + return affected, err + }) + for i := len(md.hooks) - 1; i >= 0; i-- { + if md.hooks[i] == nil { + return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") + } + mut = md.hooks[i](mut) + } + if _, err := mut.Mutate(ctx, md.mutation); err != nil { + return 0, err + } + } + return affected, err +} + +// ExecX is like Exec, but panics if an error occurs. +func (md *MessagesDelete) ExecX(ctx context.Context) int { + n, err := md.Exec(ctx) + if err != nil { + panic(err) + } + return n +} + +func (md *MessagesDelete) sqlExec(ctx context.Context) (int, error) { + _spec := &sqlgraph.DeleteSpec{ + Node: &sqlgraph.NodeSpec{ + Table: messages.Table, + ID: &sqlgraph.FieldSpec{ + Type: field.TypeInt, + Column: messages.FieldID, + }, + }, + } + if ps := md.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + return sqlgraph.DeleteNodes(ctx, md.driver, _spec) +} + +// MessagesDeleteOne is the builder for deleting a single Messages entity. +type MessagesDeleteOne struct { + md *MessagesDelete +} + +// Exec executes the deletion query. +func (mdo *MessagesDeleteOne) Exec(ctx context.Context) error { + n, err := mdo.md.Exec(ctx) + switch { + case err != nil: + return err + case n == 0: + return &NotFoundError{messages.Label} + default: + return nil + } +} + +// ExecX is like Exec, but panics if an error occurs. +func (mdo *MessagesDeleteOne) ExecX(ctx context.Context) { + mdo.md.ExecX(ctx) +} diff --git a/ent/messages_query.go b/ent/messages_query.go new file mode 100644 index 0000000..c003a68 --- /dev/null +++ b/ent/messages_query.go @@ -0,0 +1,1021 @@ +// Code generated by entc, DO NOT EDIT. + +package ent + +import ( + "context" + "csgowtfd/ent/matchplayer" + "csgowtfd/ent/messages" + "csgowtfd/ent/predicate" + "errors" + "fmt" + "math" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" +) + +// MessagesQuery is the builder for querying Messages entities. +type MessagesQuery struct { + config + limit *int + offset *int + unique *bool + order []OrderFunc + fields []string + predicates []predicate.Messages + // eager-loading edges. + withMatchPlayer *MatchPlayerQuery + withFKs bool + modifiers []func(s *sql.Selector) + // intermediate query (i.e. traversal path). + sql *sql.Selector + path func(context.Context) (*sql.Selector, error) +} + +// Where adds a new predicate for the MessagesQuery builder. +func (mq *MessagesQuery) Where(ps ...predicate.Messages) *MessagesQuery { + mq.predicates = append(mq.predicates, ps...) + return mq +} + +// Limit adds a limit step to the query. +func (mq *MessagesQuery) Limit(limit int) *MessagesQuery { + mq.limit = &limit + return mq +} + +// Offset adds an offset step to the query. +func (mq *MessagesQuery) Offset(offset int) *MessagesQuery { + mq.offset = &offset + return mq +} + +// 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 (mq *MessagesQuery) Unique(unique bool) *MessagesQuery { + mq.unique = &unique + return mq +} + +// Order adds an order step to the query. +func (mq *MessagesQuery) Order(o ...OrderFunc) *MessagesQuery { + mq.order = append(mq.order, o...) + return mq +} + +// QueryMatchPlayer chains the current query on the "match_player" edge. +func (mq *MessagesQuery) QueryMatchPlayer() *MatchPlayerQuery { + query := &MatchPlayerQuery{config: mq.config} + query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { + if err := mq.prepareQuery(ctx); err != nil { + return nil, err + } + selector := mq.sqlQuery(ctx) + if err := selector.Err(); err != nil { + return nil, err + } + step := sqlgraph.NewStep( + sqlgraph.From(messages.Table, messages.FieldID, selector), + sqlgraph.To(matchplayer.Table, matchplayer.FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, messages.MatchPlayerTable, messages.MatchPlayerColumn), + ) + fromU = sqlgraph.SetNeighbors(mq.driver.Dialect(), step) + return fromU, nil + } + return query +} + +// First returns the first Messages entity from the query. +// Returns a *NotFoundError when no Messages was found. +func (mq *MessagesQuery) First(ctx context.Context) (*Messages, error) { + nodes, err := mq.Limit(1).All(ctx) + if err != nil { + return nil, err + } + if len(nodes) == 0 { + return nil, &NotFoundError{messages.Label} + } + return nodes[0], nil +} + +// FirstX is like First, but panics if an error occurs. +func (mq *MessagesQuery) FirstX(ctx context.Context) *Messages { + node, err := mq.First(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return node +} + +// FirstID returns the first Messages ID from the query. +// Returns a *NotFoundError when no Messages ID was found. +func (mq *MessagesQuery) FirstID(ctx context.Context) (id int, err error) { + var ids []int + if ids, err = mq.Limit(1).IDs(ctx); err != nil { + return + } + if len(ids) == 0 { + err = &NotFoundError{messages.Label} + return + } + return ids[0], nil +} + +// FirstIDX is like FirstID, but panics if an error occurs. +func (mq *MessagesQuery) FirstIDX(ctx context.Context) int { + id, err := mq.FirstID(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return id +} + +// Only returns a single Messages entity found by the query, ensuring it only returns one. +// Returns a *NotSingularError when exactly one Messages entity is not found. +// Returns a *NotFoundError when no Messages entities are found. +func (mq *MessagesQuery) Only(ctx context.Context) (*Messages, error) { + nodes, err := mq.Limit(2).All(ctx) + if err != nil { + return nil, err + } + switch len(nodes) { + case 1: + return nodes[0], nil + case 0: + return nil, &NotFoundError{messages.Label} + default: + return nil, &NotSingularError{messages.Label} + } +} + +// OnlyX is like Only, but panics if an error occurs. +func (mq *MessagesQuery) OnlyX(ctx context.Context) *Messages { + node, err := mq.Only(ctx) + if err != nil { + panic(err) + } + return node +} + +// OnlyID is like Only, but returns the only Messages ID in the query. +// Returns a *NotSingularError when exactly one Messages ID is not found. +// Returns a *NotFoundError when no entities are found. +func (mq *MessagesQuery) OnlyID(ctx context.Context) (id int, err error) { + var ids []int + if ids, err = mq.Limit(2).IDs(ctx); err != nil { + return + } + switch len(ids) { + case 1: + id = ids[0] + case 0: + err = &NotFoundError{messages.Label} + default: + err = &NotSingularError{messages.Label} + } + return +} + +// OnlyIDX is like OnlyID, but panics if an error occurs. +func (mq *MessagesQuery) OnlyIDX(ctx context.Context) int { + id, err := mq.OnlyID(ctx) + if err != nil { + panic(err) + } + return id +} + +// All executes the query and returns a list of MessagesSlice. +func (mq *MessagesQuery) All(ctx context.Context) ([]*Messages, error) { + if err := mq.prepareQuery(ctx); err != nil { + return nil, err + } + return mq.sqlAll(ctx) +} + +// AllX is like All, but panics if an error occurs. +func (mq *MessagesQuery) AllX(ctx context.Context) []*Messages { + nodes, err := mq.All(ctx) + if err != nil { + panic(err) + } + return nodes +} + +// IDs executes the query and returns a list of Messages IDs. +func (mq *MessagesQuery) IDs(ctx context.Context) ([]int, error) { + var ids []int + if err := mq.Select(messages.FieldID).Scan(ctx, &ids); err != nil { + return nil, err + } + return ids, nil +} + +// IDsX is like IDs, but panics if an error occurs. +func (mq *MessagesQuery) IDsX(ctx context.Context) []int { + ids, err := mq.IDs(ctx) + if err != nil { + panic(err) + } + return ids +} + +// Count returns the count of the given query. +func (mq *MessagesQuery) Count(ctx context.Context) (int, error) { + if err := mq.prepareQuery(ctx); err != nil { + return 0, err + } + return mq.sqlCount(ctx) +} + +// CountX is like Count, but panics if an error occurs. +func (mq *MessagesQuery) CountX(ctx context.Context) int { + count, err := mq.Count(ctx) + if err != nil { + panic(err) + } + return count +} + +// Exist returns true if the query has elements in the graph. +func (mq *MessagesQuery) Exist(ctx context.Context) (bool, error) { + if err := mq.prepareQuery(ctx); err != nil { + return false, err + } + return mq.sqlExist(ctx) +} + +// ExistX is like Exist, but panics if an error occurs. +func (mq *MessagesQuery) ExistX(ctx context.Context) bool { + exist, err := mq.Exist(ctx) + if err != nil { + panic(err) + } + return exist +} + +// Clone returns a duplicate of the MessagesQuery builder, including all associated steps. It can be +// used to prepare common query builders and use them differently after the clone is made. +func (mq *MessagesQuery) Clone() *MessagesQuery { + if mq == nil { + return nil + } + return &MessagesQuery{ + config: mq.config, + limit: mq.limit, + offset: mq.offset, + order: append([]OrderFunc{}, mq.order...), + predicates: append([]predicate.Messages{}, mq.predicates...), + withMatchPlayer: mq.withMatchPlayer.Clone(), + // clone intermediate query. + sql: mq.sql.Clone(), + path: mq.path, + } +} + +// WithMatchPlayer tells the query-builder to eager-load the nodes that are connected to +// the "match_player" edge. The optional arguments are used to configure the query builder of the edge. +func (mq *MessagesQuery) WithMatchPlayer(opts ...func(*MatchPlayerQuery)) *MessagesQuery { + query := &MatchPlayerQuery{config: mq.config} + for _, opt := range opts { + opt(query) + } + mq.withMatchPlayer = query + return mq +} + +// 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. +// +// Example: +// +// var v []struct { +// Message string `json:"message,omitempty"` +// Count int `json:"count,omitempty"` +// } +// +// client.Messages.Query(). +// GroupBy(messages.FieldMessage). +// Aggregate(ent.Count()). +// Scan(ctx, &v) +// +func (mq *MessagesQuery) GroupBy(field string, fields ...string) *MessagesGroupBy { + group := &MessagesGroupBy{config: mq.config} + group.fields = append([]string{field}, fields...) + group.path = func(ctx context.Context) (prev *sql.Selector, err error) { + if err := mq.prepareQuery(ctx); err != nil { + return nil, err + } + return mq.sqlQuery(ctx), nil + } + return group +} + +// Select allows the selection one or more fields/columns for the given query, +// instead of selecting all fields in the entity. +// +// Example: +// +// var v []struct { +// Message string `json:"message,omitempty"` +// } +// +// client.Messages.Query(). +// Select(messages.FieldMessage). +// Scan(ctx, &v) +// +func (mq *MessagesQuery) Select(fields ...string) *MessagesSelect { + mq.fields = append(mq.fields, fields...) + return &MessagesSelect{MessagesQuery: mq} +} + +func (mq *MessagesQuery) prepareQuery(ctx context.Context) error { + for _, f := range mq.fields { + if !messages.ValidColumn(f) { + return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} + } + } + if mq.path != nil { + prev, err := mq.path(ctx) + if err != nil { + return err + } + mq.sql = prev + } + return nil +} + +func (mq *MessagesQuery) sqlAll(ctx context.Context) ([]*Messages, error) { + var ( + nodes = []*Messages{} + withFKs = mq.withFKs + _spec = mq.querySpec() + loadedTypes = [1]bool{ + mq.withMatchPlayer != nil, + } + ) + if mq.withMatchPlayer != nil { + withFKs = true + } + if withFKs { + _spec.Node.Columns = append(_spec.Node.Columns, messages.ForeignKeys...) + } + _spec.ScanValues = func(columns []string) ([]interface{}, error) { + node := &Messages{config: mq.config} + nodes = append(nodes, node) + return node.scanValues(columns) + } + _spec.Assign = func(columns []string, values []interface{}) error { + if len(nodes) == 0 { + return fmt.Errorf("ent: Assign called without calling ScanValues") + } + node := nodes[len(nodes)-1] + 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 + } + if len(nodes) == 0 { + return nodes, nil + } + + if query := mq.withMatchPlayer; query != nil { + ids := make([]int, 0, len(nodes)) + nodeids := make(map[int][]*Messages) + for i := range nodes { + if nodes[i].match_player_messages == nil { + continue + } + fk := *nodes[i].match_player_messages + if _, ok := nodeids[fk]; !ok { + ids = append(ids, fk) + } + nodeids[fk] = append(nodeids[fk], nodes[i]) + } + query.Where(matchplayer.IDIn(ids...)) + neighbors, err := query.All(ctx) + if err != nil { + return nil, err + } + for _, n := range neighbors { + nodes, ok := nodeids[n.ID] + if !ok { + return nil, fmt.Errorf(`unexpected foreign-key "match_player_messages" returned %v`, n.ID) + } + for i := range nodes { + nodes[i].Edges.MatchPlayer = n + } + } + } + + return nodes, nil +} + +func (mq *MessagesQuery) sqlCount(ctx context.Context) (int, error) { + _spec := mq.querySpec() + if len(mq.modifiers) > 0 { + _spec.Modifiers = mq.modifiers + } + _spec.Node.Columns = mq.fields + if len(mq.fields) > 0 { + _spec.Unique = mq.unique != nil && *mq.unique + } + return sqlgraph.CountNodes(ctx, mq.driver, _spec) +} + +func (mq *MessagesQuery) sqlExist(ctx context.Context) (bool, error) { + n, err := mq.sqlCount(ctx) + if err != nil { + return false, fmt.Errorf("ent: check existence: %w", err) + } + return n > 0, nil +} + +func (mq *MessagesQuery) querySpec() *sqlgraph.QuerySpec { + _spec := &sqlgraph.QuerySpec{ + Node: &sqlgraph.NodeSpec{ + Table: messages.Table, + Columns: messages.Columns, + ID: &sqlgraph.FieldSpec{ + Type: field.TypeInt, + Column: messages.FieldID, + }, + }, + From: mq.sql, + Unique: true, + } + if unique := mq.unique; unique != nil { + _spec.Unique = *unique + } + if fields := mq.fields; len(fields) > 0 { + _spec.Node.Columns = make([]string, 0, len(fields)) + _spec.Node.Columns = append(_spec.Node.Columns, messages.FieldID) + for i := range fields { + if fields[i] != messages.FieldID { + _spec.Node.Columns = append(_spec.Node.Columns, fields[i]) + } + } + } + if ps := mq.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if limit := mq.limit; limit != nil { + _spec.Limit = *limit + } + if offset := mq.offset; offset != nil { + _spec.Offset = *offset + } + if ps := mq.order; len(ps) > 0 { + _spec.Order = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + return _spec +} + +func (mq *MessagesQuery) sqlQuery(ctx context.Context) *sql.Selector { + builder := sql.Dialect(mq.driver.Dialect()) + t1 := builder.Table(messages.Table) + columns := mq.fields + if len(columns) == 0 { + columns = messages.Columns + } + selector := builder.Select(t1.Columns(columns...)...).From(t1) + if mq.sql != nil { + selector = mq.sql + selector.Select(selector.Columns(columns...)...) + } + if mq.unique != nil && *mq.unique { + selector.Distinct() + } + for _, m := range mq.modifiers { + m(selector) + } + for _, p := range mq.predicates { + p(selector) + } + for _, p := range mq.order { + p(selector) + } + if offset := mq.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 := mq.limit; limit != nil { + selector.Limit(*limit) + } + return selector +} + +// Modify adds a query modifier for attaching custom logic to queries. +func (mq *MessagesQuery) Modify(modifiers ...func(s *sql.Selector)) *MessagesSelect { + mq.modifiers = append(mq.modifiers, modifiers...) + return mq.Select() +} + +// MessagesGroupBy is the group-by builder for Messages entities. +type MessagesGroupBy struct { + config + fields []string + fns []AggregateFunc + // intermediate query (i.e. traversal path). + sql *sql.Selector + path func(context.Context) (*sql.Selector, error) +} + +// Aggregate adds the given aggregation functions to the group-by query. +func (mgb *MessagesGroupBy) Aggregate(fns ...AggregateFunc) *MessagesGroupBy { + mgb.fns = append(mgb.fns, fns...) + return mgb +} + +// Scan applies the group-by query and scans the result into the given value. +func (mgb *MessagesGroupBy) Scan(ctx context.Context, v interface{}) error { + query, err := mgb.path(ctx) + if err != nil { + return err + } + mgb.sql = query + return mgb.sqlScan(ctx, v) +} + +// ScanX is like Scan, but panics if an error occurs. +func (mgb *MessagesGroupBy) ScanX(ctx context.Context, v interface{}) { + if err := mgb.Scan(ctx, v); err != nil { + panic(err) + } +} + +// Strings returns list of strings from group-by. +// It is only allowed when executing a group-by query with one field. +func (mgb *MessagesGroupBy) Strings(ctx context.Context) ([]string, error) { + if len(mgb.fields) > 1 { + return nil, errors.New("ent: MessagesGroupBy.Strings is not achievable when grouping more than 1 field") + } + var v []string + if err := mgb.Scan(ctx, &v); err != nil { + return nil, err + } + return v, nil +} + +// StringsX is like Strings, but panics if an error occurs. +func (mgb *MessagesGroupBy) StringsX(ctx context.Context) []string { + v, err := mgb.Strings(ctx) + if err != nil { + panic(err) + } + return v +} + +// String returns a single string from a group-by query. +// It is only allowed when executing a group-by query with one field. +func (mgb *MessagesGroupBy) String(ctx context.Context) (_ string, err error) { + var v []string + if v, err = mgb.Strings(ctx); err != nil { + return + } + switch len(v) { + case 1: + return v[0], nil + case 0: + err = &NotFoundError{messages.Label} + default: + err = fmt.Errorf("ent: MessagesGroupBy.Strings returned %d results when one was expected", len(v)) + } + return +} + +// StringX is like String, but panics if an error occurs. +func (mgb *MessagesGroupBy) StringX(ctx context.Context) string { + v, err := mgb.String(ctx) + if err != nil { + panic(err) + } + return v +} + +// Ints returns list of ints from group-by. +// It is only allowed when executing a group-by query with one field. +func (mgb *MessagesGroupBy) Ints(ctx context.Context) ([]int, error) { + if len(mgb.fields) > 1 { + return nil, errors.New("ent: MessagesGroupBy.Ints is not achievable when grouping more than 1 field") + } + var v []int + if err := mgb.Scan(ctx, &v); err != nil { + return nil, err + } + return v, nil +} + +// IntsX is like Ints, but panics if an error occurs. +func (mgb *MessagesGroupBy) IntsX(ctx context.Context) []int { + v, err := mgb.Ints(ctx) + if err != nil { + panic(err) + } + return v +} + +// Int returns a single int from a group-by query. +// It is only allowed when executing a group-by query with one field. +func (mgb *MessagesGroupBy) Int(ctx context.Context) (_ int, err error) { + var v []int + if v, err = mgb.Ints(ctx); err != nil { + return + } + switch len(v) { + case 1: + return v[0], nil + case 0: + err = &NotFoundError{messages.Label} + default: + err = fmt.Errorf("ent: MessagesGroupBy.Ints returned %d results when one was expected", len(v)) + } + return +} + +// IntX is like Int, but panics if an error occurs. +func (mgb *MessagesGroupBy) IntX(ctx context.Context) int { + v, err := mgb.Int(ctx) + if err != nil { + panic(err) + } + return v +} + +// Float64s returns list of float64s from group-by. +// It is only allowed when executing a group-by query with one field. +func (mgb *MessagesGroupBy) Float64s(ctx context.Context) ([]float64, error) { + if len(mgb.fields) > 1 { + return nil, errors.New("ent: MessagesGroupBy.Float64s is not achievable when grouping more than 1 field") + } + var v []float64 + if err := mgb.Scan(ctx, &v); err != nil { + return nil, err + } + return v, nil +} + +// Float64sX is like Float64s, but panics if an error occurs. +func (mgb *MessagesGroupBy) Float64sX(ctx context.Context) []float64 { + v, err := mgb.Float64s(ctx) + if err != nil { + panic(err) + } + return v +} + +// Float64 returns a single float64 from a group-by query. +// It is only allowed when executing a group-by query with one field. +func (mgb *MessagesGroupBy) Float64(ctx context.Context) (_ float64, err error) { + var v []float64 + if v, err = mgb.Float64s(ctx); err != nil { + return + } + switch len(v) { + case 1: + return v[0], nil + case 0: + err = &NotFoundError{messages.Label} + default: + err = fmt.Errorf("ent: MessagesGroupBy.Float64s returned %d results when one was expected", len(v)) + } + return +} + +// Float64X is like Float64, but panics if an error occurs. +func (mgb *MessagesGroupBy) Float64X(ctx context.Context) float64 { + v, err := mgb.Float64(ctx) + if err != nil { + panic(err) + } + return v +} + +// Bools returns list of bools from group-by. +// It is only allowed when executing a group-by query with one field. +func (mgb *MessagesGroupBy) Bools(ctx context.Context) ([]bool, error) { + if len(mgb.fields) > 1 { + return nil, errors.New("ent: MessagesGroupBy.Bools is not achievable when grouping more than 1 field") + } + var v []bool + if err := mgb.Scan(ctx, &v); err != nil { + return nil, err + } + return v, nil +} + +// BoolsX is like Bools, but panics if an error occurs. +func (mgb *MessagesGroupBy) BoolsX(ctx context.Context) []bool { + v, err := mgb.Bools(ctx) + if err != nil { + panic(err) + } + return v +} + +// Bool returns a single bool from a group-by query. +// It is only allowed when executing a group-by query with one field. +func (mgb *MessagesGroupBy) Bool(ctx context.Context) (_ bool, err error) { + var v []bool + if v, err = mgb.Bools(ctx); err != nil { + return + } + switch len(v) { + case 1: + return v[0], nil + case 0: + err = &NotFoundError{messages.Label} + default: + err = fmt.Errorf("ent: MessagesGroupBy.Bools returned %d results when one was expected", len(v)) + } + return +} + +// BoolX is like Bool, but panics if an error occurs. +func (mgb *MessagesGroupBy) BoolX(ctx context.Context) bool { + v, err := mgb.Bool(ctx) + if err != nil { + panic(err) + } + return v +} + +func (mgb *MessagesGroupBy) sqlScan(ctx context.Context, v interface{}) error { + for _, f := range mgb.fields { + if !messages.ValidColumn(f) { + return &ValidationError{Name: f, err: fmt.Errorf("invalid field %q for group-by", f)} + } + } + selector := mgb.sqlQuery() + if err := selector.Err(); err != nil { + return err + } + rows := &sql.Rows{} + query, args := selector.Query() + if err := mgb.driver.Query(ctx, query, args, rows); err != nil { + return err + } + defer rows.Close() + return sql.ScanSlice(rows, v) +} + +func (mgb *MessagesGroupBy) sqlQuery() *sql.Selector { + selector := mgb.sql.Select() + aggregation := make([]string, 0, len(mgb.fns)) + for _, fn := range mgb.fns { + aggregation = append(aggregation, fn(selector)) + } + // If no columns were selected in a custom aggregation function, the default + // selection is the fields used for "group-by", and the aggregation functions. + if len(selector.SelectedColumns()) == 0 { + columns := make([]string, 0, len(mgb.fields)+len(mgb.fns)) + for _, f := range mgb.fields { + columns = append(columns, selector.C(f)) + } + columns = append(columns, aggregation...) + selector.Select(columns...) + } + return selector.GroupBy(selector.Columns(mgb.fields...)...) +} + +// MessagesSelect is the builder for selecting fields of Messages entities. +type MessagesSelect struct { + *MessagesQuery + // intermediate query (i.e. traversal path). + sql *sql.Selector +} + +// Scan applies the selector query and scans the result into the given value. +func (ms *MessagesSelect) Scan(ctx context.Context, v interface{}) error { + if err := ms.prepareQuery(ctx); err != nil { + return err + } + ms.sql = ms.MessagesQuery.sqlQuery(ctx) + return ms.sqlScan(ctx, v) +} + +// ScanX is like Scan, but panics if an error occurs. +func (ms *MessagesSelect) ScanX(ctx context.Context, v interface{}) { + if err := ms.Scan(ctx, v); err != nil { + panic(err) + } +} + +// Strings returns list of strings from a selector. It is only allowed when selecting one field. +func (ms *MessagesSelect) Strings(ctx context.Context) ([]string, error) { + if len(ms.fields) > 1 { + return nil, errors.New("ent: MessagesSelect.Strings is not achievable when selecting more than 1 field") + } + var v []string + if err := ms.Scan(ctx, &v); err != nil { + return nil, err + } + return v, nil +} + +// StringsX is like Strings, but panics if an error occurs. +func (ms *MessagesSelect) StringsX(ctx context.Context) []string { + v, err := ms.Strings(ctx) + if err != nil { + panic(err) + } + return v +} + +// String returns a single string from a selector. It is only allowed when selecting one field. +func (ms *MessagesSelect) String(ctx context.Context) (_ string, err error) { + var v []string + if v, err = ms.Strings(ctx); err != nil { + return + } + switch len(v) { + case 1: + return v[0], nil + case 0: + err = &NotFoundError{messages.Label} + default: + err = fmt.Errorf("ent: MessagesSelect.Strings returned %d results when one was expected", len(v)) + } + return +} + +// StringX is like String, but panics if an error occurs. +func (ms *MessagesSelect) StringX(ctx context.Context) string { + v, err := ms.String(ctx) + if err != nil { + panic(err) + } + return v +} + +// Ints returns list of ints from a selector. It is only allowed when selecting one field. +func (ms *MessagesSelect) Ints(ctx context.Context) ([]int, error) { + if len(ms.fields) > 1 { + return nil, errors.New("ent: MessagesSelect.Ints is not achievable when selecting more than 1 field") + } + var v []int + if err := ms.Scan(ctx, &v); err != nil { + return nil, err + } + return v, nil +} + +// IntsX is like Ints, but panics if an error occurs. +func (ms *MessagesSelect) IntsX(ctx context.Context) []int { + v, err := ms.Ints(ctx) + if err != nil { + panic(err) + } + return v +} + +// Int returns a single int from a selector. It is only allowed when selecting one field. +func (ms *MessagesSelect) Int(ctx context.Context) (_ int, err error) { + var v []int + if v, err = ms.Ints(ctx); err != nil { + return + } + switch len(v) { + case 1: + return v[0], nil + case 0: + err = &NotFoundError{messages.Label} + default: + err = fmt.Errorf("ent: MessagesSelect.Ints returned %d results when one was expected", len(v)) + } + return +} + +// IntX is like Int, but panics if an error occurs. +func (ms *MessagesSelect) IntX(ctx context.Context) int { + v, err := ms.Int(ctx) + if err != nil { + panic(err) + } + return v +} + +// Float64s returns list of float64s from a selector. It is only allowed when selecting one field. +func (ms *MessagesSelect) Float64s(ctx context.Context) ([]float64, error) { + if len(ms.fields) > 1 { + return nil, errors.New("ent: MessagesSelect.Float64s is not achievable when selecting more than 1 field") + } + var v []float64 + if err := ms.Scan(ctx, &v); err != nil { + return nil, err + } + return v, nil +} + +// Float64sX is like Float64s, but panics if an error occurs. +func (ms *MessagesSelect) Float64sX(ctx context.Context) []float64 { + v, err := ms.Float64s(ctx) + if err != nil { + panic(err) + } + return v +} + +// Float64 returns a single float64 from a selector. It is only allowed when selecting one field. +func (ms *MessagesSelect) Float64(ctx context.Context) (_ float64, err error) { + var v []float64 + if v, err = ms.Float64s(ctx); err != nil { + return + } + switch len(v) { + case 1: + return v[0], nil + case 0: + err = &NotFoundError{messages.Label} + default: + err = fmt.Errorf("ent: MessagesSelect.Float64s returned %d results when one was expected", len(v)) + } + return +} + +// Float64X is like Float64, but panics if an error occurs. +func (ms *MessagesSelect) Float64X(ctx context.Context) float64 { + v, err := ms.Float64(ctx) + if err != nil { + panic(err) + } + return v +} + +// Bools returns list of bools from a selector. It is only allowed when selecting one field. +func (ms *MessagesSelect) Bools(ctx context.Context) ([]bool, error) { + if len(ms.fields) > 1 { + return nil, errors.New("ent: MessagesSelect.Bools is not achievable when selecting more than 1 field") + } + var v []bool + if err := ms.Scan(ctx, &v); err != nil { + return nil, err + } + return v, nil +} + +// BoolsX is like Bools, but panics if an error occurs. +func (ms *MessagesSelect) BoolsX(ctx context.Context) []bool { + v, err := ms.Bools(ctx) + if err != nil { + panic(err) + } + return v +} + +// Bool returns a single bool from a selector. It is only allowed when selecting one field. +func (ms *MessagesSelect) Bool(ctx context.Context) (_ bool, err error) { + var v []bool + if v, err = ms.Bools(ctx); err != nil { + return + } + switch len(v) { + case 1: + return v[0], nil + case 0: + err = &NotFoundError{messages.Label} + default: + err = fmt.Errorf("ent: MessagesSelect.Bools returned %d results when one was expected", len(v)) + } + return +} + +// BoolX is like Bool, but panics if an error occurs. +func (ms *MessagesSelect) BoolX(ctx context.Context) bool { + v, err := ms.Bool(ctx) + if err != nil { + panic(err) + } + return v +} + +func (ms *MessagesSelect) sqlScan(ctx context.Context, v interface{}) error { + rows := &sql.Rows{} + query, args := ms.sql.Query() + if err := ms.driver.Query(ctx, query, args, rows); err != nil { + return err + } + defer rows.Close() + return sql.ScanSlice(rows, v) +} + +// Modify adds a query modifier for attaching custom logic to queries. +func (ms *MessagesSelect) Modify(modifiers ...func(s *sql.Selector)) *MessagesSelect { + ms.modifiers = append(ms.modifiers, modifiers...) + return ms +} diff --git a/ent/messages_update.go b/ent/messages_update.go new file mode 100644 index 0000000..9a48e7a --- /dev/null +++ b/ent/messages_update.go @@ -0,0 +1,412 @@ +// Code generated by entc, DO NOT EDIT. + +package ent + +import ( + "context" + "csgowtfd/ent/matchplayer" + "csgowtfd/ent/messages" + "csgowtfd/ent/predicate" + "errors" + "fmt" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" +) + +// MessagesUpdate is the builder for updating Messages entities. +type MessagesUpdate struct { + config + hooks []Hook + mutation *MessagesMutation +} + +// Where appends a list predicates to the MessagesUpdate builder. +func (mu *MessagesUpdate) Where(ps ...predicate.Messages) *MessagesUpdate { + mu.mutation.Where(ps...) + return mu +} + +// SetMessage sets the "message" field. +func (mu *MessagesUpdate) SetMessage(s string) *MessagesUpdate { + mu.mutation.SetMessage(s) + return mu +} + +// SetAllChat sets the "all_chat" field. +func (mu *MessagesUpdate) SetAllChat(b bool) *MessagesUpdate { + mu.mutation.SetAllChat(b) + return mu +} + +// SetMatchPlayerID sets the "match_player" edge to the MatchPlayer entity by ID. +func (mu *MessagesUpdate) SetMatchPlayerID(id int) *MessagesUpdate { + mu.mutation.SetMatchPlayerID(id) + return mu +} + +// SetNillableMatchPlayerID sets the "match_player" edge to the MatchPlayer entity by ID if the given value is not nil. +func (mu *MessagesUpdate) SetNillableMatchPlayerID(id *int) *MessagesUpdate { + if id != nil { + mu = mu.SetMatchPlayerID(*id) + } + return mu +} + +// SetMatchPlayer sets the "match_player" edge to the MatchPlayer entity. +func (mu *MessagesUpdate) SetMatchPlayer(m *MatchPlayer) *MessagesUpdate { + return mu.SetMatchPlayerID(m.ID) +} + +// Mutation returns the MessagesMutation object of the builder. +func (mu *MessagesUpdate) Mutation() *MessagesMutation { + return mu.mutation +} + +// ClearMatchPlayer clears the "match_player" edge to the MatchPlayer entity. +func (mu *MessagesUpdate) ClearMatchPlayer() *MessagesUpdate { + mu.mutation.ClearMatchPlayer() + return mu +} + +// Save executes the query and returns the number of nodes affected by the update operation. +func (mu *MessagesUpdate) Save(ctx context.Context) (int, error) { + var ( + err error + affected int + ) + if len(mu.hooks) == 0 { + affected, err = mu.sqlSave(ctx) + } else { + var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { + mutation, ok := m.(*MessagesMutation) + if !ok { + return nil, fmt.Errorf("unexpected mutation type %T", m) + } + mu.mutation = mutation + affected, err = mu.sqlSave(ctx) + mutation.done = true + return affected, err + }) + for i := len(mu.hooks) - 1; i >= 0; i-- { + if mu.hooks[i] == nil { + return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") + } + mut = mu.hooks[i](mut) + } + if _, err := mut.Mutate(ctx, mu.mutation); err != nil { + return 0, err + } + } + return affected, err +} + +// SaveX is like Save, but panics if an error occurs. +func (mu *MessagesUpdate) SaveX(ctx context.Context) int { + affected, err := mu.Save(ctx) + if err != nil { + panic(err) + } + return affected +} + +// Exec executes the query. +func (mu *MessagesUpdate) Exec(ctx context.Context) error { + _, err := mu.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (mu *MessagesUpdate) ExecX(ctx context.Context) { + if err := mu.Exec(ctx); err != nil { + panic(err) + } +} + +func (mu *MessagesUpdate) sqlSave(ctx context.Context) (n int, err error) { + _spec := &sqlgraph.UpdateSpec{ + Node: &sqlgraph.NodeSpec{ + Table: messages.Table, + Columns: messages.Columns, + ID: &sqlgraph.FieldSpec{ + Type: field.TypeInt, + Column: messages.FieldID, + }, + }, + } + if ps := mu.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if value, ok := mu.mutation.Message(); ok { + _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ + Type: field.TypeString, + Value: value, + Column: messages.FieldMessage, + }) + } + if value, ok := mu.mutation.AllChat(); ok { + _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ + Type: field.TypeBool, + Value: value, + Column: messages.FieldAllChat, + }) + } + if mu.mutation.MatchPlayerCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: messages.MatchPlayerTable, + Columns: []string{messages.MatchPlayerColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: &sqlgraph.FieldSpec{ + Type: field.TypeInt, + Column: matchplayer.FieldID, + }, + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := mu.mutation.MatchPlayerIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: messages.MatchPlayerTable, + Columns: []string{messages.MatchPlayerColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: &sqlgraph.FieldSpec{ + Type: field.TypeInt, + Column: matchplayer.FieldID, + }, + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + if n, err = sqlgraph.UpdateNodes(ctx, mu.driver, _spec); err != nil { + if _, ok := err.(*sqlgraph.NotFoundError); ok { + err = &NotFoundError{messages.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{err.Error(), err} + } + return 0, err + } + return n, nil +} + +// MessagesUpdateOne is the builder for updating a single Messages entity. +type MessagesUpdateOne struct { + config + fields []string + hooks []Hook + mutation *MessagesMutation +} + +// SetMessage sets the "message" field. +func (muo *MessagesUpdateOne) SetMessage(s string) *MessagesUpdateOne { + muo.mutation.SetMessage(s) + return muo +} + +// SetAllChat sets the "all_chat" field. +func (muo *MessagesUpdateOne) SetAllChat(b bool) *MessagesUpdateOne { + muo.mutation.SetAllChat(b) + return muo +} + +// SetMatchPlayerID sets the "match_player" edge to the MatchPlayer entity by ID. +func (muo *MessagesUpdateOne) SetMatchPlayerID(id int) *MessagesUpdateOne { + muo.mutation.SetMatchPlayerID(id) + return muo +} + +// SetNillableMatchPlayerID sets the "match_player" edge to the MatchPlayer entity by ID if the given value is not nil. +func (muo *MessagesUpdateOne) SetNillableMatchPlayerID(id *int) *MessagesUpdateOne { + if id != nil { + muo = muo.SetMatchPlayerID(*id) + } + return muo +} + +// SetMatchPlayer sets the "match_player" edge to the MatchPlayer entity. +func (muo *MessagesUpdateOne) SetMatchPlayer(m *MatchPlayer) *MessagesUpdateOne { + return muo.SetMatchPlayerID(m.ID) +} + +// Mutation returns the MessagesMutation object of the builder. +func (muo *MessagesUpdateOne) Mutation() *MessagesMutation { + return muo.mutation +} + +// ClearMatchPlayer clears the "match_player" edge to the MatchPlayer entity. +func (muo *MessagesUpdateOne) ClearMatchPlayer() *MessagesUpdateOne { + muo.mutation.ClearMatchPlayer() + return muo +} + +// Select allows selecting one or more fields (columns) of the returned entity. +// The default is selecting all fields defined in the entity schema. +func (muo *MessagesUpdateOne) Select(field string, fields ...string) *MessagesUpdateOne { + muo.fields = append([]string{field}, fields...) + return muo +} + +// Save executes the query and returns the updated Messages entity. +func (muo *MessagesUpdateOne) Save(ctx context.Context) (*Messages, error) { + var ( + err error + node *Messages + ) + if len(muo.hooks) == 0 { + node, err = muo.sqlSave(ctx) + } else { + var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { + mutation, ok := m.(*MessagesMutation) + if !ok { + return nil, fmt.Errorf("unexpected mutation type %T", m) + } + muo.mutation = mutation + node, err = muo.sqlSave(ctx) + mutation.done = true + return node, err + }) + for i := len(muo.hooks) - 1; i >= 0; i-- { + if muo.hooks[i] == nil { + return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") + } + mut = muo.hooks[i](mut) + } + if _, err := mut.Mutate(ctx, muo.mutation); err != nil { + return nil, err + } + } + return node, err +} + +// SaveX is like Save, but panics if an error occurs. +func (muo *MessagesUpdateOne) SaveX(ctx context.Context) *Messages { + node, err := muo.Save(ctx) + if err != nil { + panic(err) + } + return node +} + +// Exec executes the query on the entity. +func (muo *MessagesUpdateOne) Exec(ctx context.Context) error { + _, err := muo.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (muo *MessagesUpdateOne) ExecX(ctx context.Context) { + if err := muo.Exec(ctx); err != nil { + panic(err) + } +} + +func (muo *MessagesUpdateOne) sqlSave(ctx context.Context) (_node *Messages, err error) { + _spec := &sqlgraph.UpdateSpec{ + Node: &sqlgraph.NodeSpec{ + Table: messages.Table, + Columns: messages.Columns, + ID: &sqlgraph.FieldSpec{ + Type: field.TypeInt, + Column: messages.FieldID, + }, + }, + } + id, ok := muo.mutation.ID() + if !ok { + return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Messages.id" for update`)} + } + _spec.Node.ID.Value = id + if fields := muo.fields; len(fields) > 0 { + _spec.Node.Columns = make([]string, 0, len(fields)) + _spec.Node.Columns = append(_spec.Node.Columns, messages.FieldID) + for _, f := range fields { + if !messages.ValidColumn(f) { + return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} + } + if f != messages.FieldID { + _spec.Node.Columns = append(_spec.Node.Columns, f) + } + } + } + if ps := muo.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if value, ok := muo.mutation.Message(); ok { + _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ + Type: field.TypeString, + Value: value, + Column: messages.FieldMessage, + }) + } + if value, ok := muo.mutation.AllChat(); ok { + _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ + Type: field.TypeBool, + Value: value, + Column: messages.FieldAllChat, + }) + } + if muo.mutation.MatchPlayerCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: messages.MatchPlayerTable, + Columns: []string{messages.MatchPlayerColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: &sqlgraph.FieldSpec{ + Type: field.TypeInt, + Column: matchplayer.FieldID, + }, + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := muo.mutation.MatchPlayerIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: messages.MatchPlayerTable, + Columns: []string{messages.MatchPlayerColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: &sqlgraph.FieldSpec{ + Type: field.TypeInt, + Column: matchplayer.FieldID, + }, + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + _node = &Messages{config: muo.config} + _spec.Assign = _node.assignValues + _spec.ScanValues = _node.scanValues + if err = sqlgraph.UpdateNode(ctx, muo.driver, _spec); err != nil { + if _, ok := err.(*sqlgraph.NotFoundError); ok { + err = &NotFoundError{messages.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{err.Error(), err} + } + return nil, err + } + return _node, nil +} diff --git a/ent/migrate/migrate.go b/ent/migrate/migrate.go index e4a9a22..9bdaf52 100644 --- a/ent/migrate/migrate.go +++ b/ent/migrate/migrate.go @@ -37,8 +37,7 @@ var ( // Schema is the API for creating, migrating and dropping a schema. type Schema struct { - drv dialect.Driver - universalID bool + drv dialect.Driver } // NewSchema creates a new schema client. diff --git a/ent/migrate/schema.go b/ent/migrate/schema.go index 6d9287e..65a951f 100644 --- a/ent/migrate/schema.go +++ b/ent/migrate/schema.go @@ -23,6 +23,7 @@ var ( {Name: "demo_parsed", Type: field.TypeBool, Default: false}, {Name: "vac_present", Type: field.TypeBool, Default: false}, {Name: "gameban_present", Type: field.TypeBool, Default: false}, + {Name: "decryption_key", Type: field.TypeBytes, Nullable: true}, } // MatchesTable holds the schema information for the "matches" table. MatchesTable = &schema.Table{ @@ -86,6 +87,27 @@ var ( }, }, } + // MessagesColumns holds the columns for the "messages" table. + MessagesColumns = []*schema.Column{ + {Name: "id", Type: field.TypeInt, Increment: true}, + {Name: "message", Type: field.TypeString, Size: 2147483647}, + {Name: "all_chat", Type: field.TypeBool}, + {Name: "match_player_messages", Type: field.TypeInt, Nullable: true}, + } + // MessagesTable holds the schema information for the "messages" table. + MessagesTable = &schema.Table{ + Name: "messages", + Columns: MessagesColumns, + PrimaryKey: []*schema.Column{MessagesColumns[0]}, + ForeignKeys: []*schema.ForeignKey{ + { + Symbol: "messages_match_players_messages", + Columns: []*schema.Column{MessagesColumns[3]}, + RefColumns: []*schema.Column{MatchPlayersColumns[0]}, + OnDelete: schema.SetNull, + }, + }, + } // PlayersColumns holds the columns for the "players" table. PlayersColumns = []*schema.Column{ {Name: "id", Type: field.TypeUint64, Increment: true}, @@ -208,6 +230,7 @@ var ( Tables = []*schema.Table{ MatchesTable, MatchPlayersTable, + MessagesTable, PlayersTable, RoundStatsTable, SpraysTable, @@ -219,6 +242,7 @@ var ( func init() { MatchPlayersTable.ForeignKeys[0].RefTable = MatchesTable MatchPlayersTable.ForeignKeys[1].RefTable = PlayersTable + MessagesTable.ForeignKeys[0].RefTable = MatchPlayersTable RoundStatsTable.ForeignKeys[0].RefTable = MatchPlayersTable SpraysTable.ForeignKeys[0].RefTable = MatchPlayersTable WeaponsTable.ForeignKeys[0].RefTable = MatchPlayersTable diff --git a/ent/mutation.go b/ent/mutation.go index c8b4e16..5c48fe0 100644 --- a/ent/mutation.go +++ b/ent/mutation.go @@ -6,11 +6,13 @@ import ( "context" "csgowtfd/ent/match" "csgowtfd/ent/matchplayer" + "csgowtfd/ent/messages" "csgowtfd/ent/player" "csgowtfd/ent/predicate" "csgowtfd/ent/roundstats" "csgowtfd/ent/spray" "csgowtfd/ent/weapon" + "errors" "fmt" "sync" "time" @@ -29,6 +31,7 @@ const ( // Node types. TypeMatch = "Match" TypeMatchPlayer = "MatchPlayer" + TypeMessages = "Messages" TypePlayer = "Player" TypeRoundStats = "RoundStats" TypeSpray = "Spray" @@ -58,6 +61,7 @@ type MatchMutation struct { demo_parsed *bool vac_present *bool gameban_present *bool + decryption_key *[]byte clearedFields map[string]struct{} stats map[int]struct{} removedstats map[int]struct{} @@ -100,7 +104,7 @@ func withMatchID(id uint64) matchOption { m.oldValue = func(ctx context.Context) (*Match, error) { once.Do(func() { if m.done { - err = fmt.Errorf("querying old values post mutation is not allowed") + err = errors.New("querying old values post mutation is not allowed") } else { value, err = m.Client().Match.Get(ctx, id) } @@ -133,7 +137,7 @@ func (m MatchMutation) Client() *Client { // it returns an error otherwise. func (m MatchMutation) Tx() (*Tx, error) { if _, ok := m.driver.(*txDriver); !ok { - return nil, fmt.Errorf("ent: mutation is not running in a transaction") + return nil, errors.New("ent: mutation is not running in a transaction") } tx := &Tx{config: m.config} tx.init() @@ -155,6 +159,25 @@ func (m *MatchMutation) ID() (id uint64, exists bool) { return *m.id, true } +// IDs queries the database and returns the entity ids that match the mutation's predicate. +// That means, if the mutation is applied within a transaction with an isolation level such +// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated +// or updated by the mutation. +func (m *MatchMutation) IDs(ctx context.Context) ([]uint64, error) { + switch { + case m.op.Is(OpUpdateOne | OpDeleteOne): + id, exists := m.ID() + if exists { + return []uint64{id}, nil + } + fallthrough + case m.op.Is(OpUpdate | OpDelete): + return m.Client().Match.Query().Where(m.predicates...).IDs(ctx) + default: + return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) + } +} + // SetShareCode sets the "share_code" field. func (m *MatchMutation) SetShareCode(s string) { m.share_code = &s @@ -174,10 +197,10 @@ func (m *MatchMutation) ShareCode() (r string, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *MatchMutation) OldShareCode(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldShareCode is only allowed on UpdateOne operations") + return v, errors.New("OldShareCode is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldShareCode requires an ID field in the mutation") + return v, errors.New("OldShareCode requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -210,10 +233,10 @@ func (m *MatchMutation) Map() (r string, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *MatchMutation) OldMap(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldMap is only allowed on UpdateOne operations") + return v, errors.New("OldMap is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldMap requires an ID field in the mutation") + return v, errors.New("OldMap requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -259,10 +282,10 @@ func (m *MatchMutation) Date() (r time.Time, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *MatchMutation) OldDate(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldDate is only allowed on UpdateOne operations") + return v, errors.New("OldDate is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldDate requires an ID field in the mutation") + return v, errors.New("OldDate requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -296,10 +319,10 @@ func (m *MatchMutation) ScoreTeamA() (r int, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *MatchMutation) OldScoreTeamA(ctx context.Context) (v int, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldScoreTeamA is only allowed on UpdateOne operations") + return v, errors.New("OldScoreTeamA is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldScoreTeamA requires an ID field in the mutation") + return v, errors.New("OldScoreTeamA requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -352,10 +375,10 @@ func (m *MatchMutation) ScoreTeamB() (r int, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *MatchMutation) OldScoreTeamB(ctx context.Context) (v int, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldScoreTeamB is only allowed on UpdateOne operations") + return v, errors.New("OldScoreTeamB is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldScoreTeamB requires an ID field in the mutation") + return v, errors.New("OldScoreTeamB requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -407,10 +430,10 @@ func (m *MatchMutation) ReplayURL() (r string, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *MatchMutation) OldReplayURL(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldReplayURL is only allowed on UpdateOne operations") + return v, errors.New("OldReplayURL is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldReplayURL requires an ID field in the mutation") + return v, errors.New("OldReplayURL requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -457,10 +480,10 @@ func (m *MatchMutation) Duration() (r int, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *MatchMutation) OldDuration(ctx context.Context) (v int, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldDuration is only allowed on UpdateOne operations") + return v, errors.New("OldDuration is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldDuration requires an ID field in the mutation") + return v, errors.New("OldDuration requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -513,10 +536,10 @@ func (m *MatchMutation) MatchResult() (r int, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *MatchMutation) OldMatchResult(ctx context.Context) (v int, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldMatchResult is only allowed on UpdateOne operations") + return v, errors.New("OldMatchResult is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldMatchResult requires an ID field in the mutation") + return v, errors.New("OldMatchResult requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -569,10 +592,10 @@ func (m *MatchMutation) MaxRounds() (r int, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *MatchMutation) OldMaxRounds(ctx context.Context) (v int, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldMaxRounds is only allowed on UpdateOne operations") + return v, errors.New("OldMaxRounds is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldMaxRounds requires an ID field in the mutation") + return v, errors.New("OldMaxRounds requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -624,10 +647,10 @@ func (m *MatchMutation) DemoParsed() (r bool, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *MatchMutation) OldDemoParsed(ctx context.Context) (v bool, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldDemoParsed is only allowed on UpdateOne operations") + return v, errors.New("OldDemoParsed is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldDemoParsed requires an ID field in the mutation") + return v, errors.New("OldDemoParsed requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -660,10 +683,10 @@ func (m *MatchMutation) VacPresent() (r bool, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *MatchMutation) OldVacPresent(ctx context.Context) (v bool, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldVacPresent is only allowed on UpdateOne operations") + return v, errors.New("OldVacPresent is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldVacPresent requires an ID field in the mutation") + return v, errors.New("OldVacPresent requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -696,10 +719,10 @@ func (m *MatchMutation) GamebanPresent() (r bool, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *MatchMutation) OldGamebanPresent(ctx context.Context) (v bool, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldGamebanPresent is only allowed on UpdateOne operations") + return v, errors.New("OldGamebanPresent is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldGamebanPresent requires an ID field in the mutation") + return v, errors.New("OldGamebanPresent requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -713,6 +736,55 @@ func (m *MatchMutation) ResetGamebanPresent() { m.gameban_present = nil } +// SetDecryptionKey sets the "decryption_key" field. +func (m *MatchMutation) SetDecryptionKey(b []byte) { + m.decryption_key = &b +} + +// DecryptionKey returns the value of the "decryption_key" field in the mutation. +func (m *MatchMutation) DecryptionKey() (r []byte, exists bool) { + v := m.decryption_key + if v == nil { + return + } + return *v, true +} + +// OldDecryptionKey returns the old "decryption_key" field's value of the Match entity. +// If the Match object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *MatchMutation) OldDecryptionKey(ctx context.Context) (v []byte, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldDecryptionKey is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldDecryptionKey requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldDecryptionKey: %w", err) + } + return oldValue.DecryptionKey, nil +} + +// ClearDecryptionKey clears the value of the "decryption_key" field. +func (m *MatchMutation) ClearDecryptionKey() { + m.decryption_key = nil + m.clearedFields[match.FieldDecryptionKey] = struct{}{} +} + +// DecryptionKeyCleared returns if the "decryption_key" field was cleared in this mutation. +func (m *MatchMutation) DecryptionKeyCleared() bool { + _, ok := m.clearedFields[match.FieldDecryptionKey] + return ok +} + +// ResetDecryptionKey resets all changes to the "decryption_key" field. +func (m *MatchMutation) ResetDecryptionKey() { + m.decryption_key = nil + delete(m.clearedFields, match.FieldDecryptionKey) +} + // AddStatIDs adds the "stats" edge to the MatchPlayer entity by ids. func (m *MatchMutation) AddStatIDs(ids ...int) { if m.stats == nil { @@ -840,7 +912,7 @@ func (m *MatchMutation) Type() string { // order to get all numeric fields that were incremented/decremented, call // AddedFields(). func (m *MatchMutation) Fields() []string { - fields := make([]string, 0, 12) + fields := make([]string, 0, 13) if m.share_code != nil { fields = append(fields, match.FieldShareCode) } @@ -877,6 +949,9 @@ func (m *MatchMutation) Fields() []string { if m.gameban_present != nil { fields = append(fields, match.FieldGamebanPresent) } + if m.decryption_key != nil { + fields = append(fields, match.FieldDecryptionKey) + } return fields } @@ -909,6 +984,8 @@ func (m *MatchMutation) Field(name string) (ent.Value, bool) { return m.VacPresent() case match.FieldGamebanPresent: return m.GamebanPresent() + case match.FieldDecryptionKey: + return m.DecryptionKey() } return nil, false } @@ -942,6 +1019,8 @@ func (m *MatchMutation) OldField(ctx context.Context, name string) (ent.Value, e return m.OldVacPresent(ctx) case match.FieldGamebanPresent: return m.OldGamebanPresent(ctx) + case match.FieldDecryptionKey: + return m.OldDecryptionKey(ctx) } return nil, fmt.Errorf("unknown Match field %s", name) } @@ -1035,6 +1114,13 @@ func (m *MatchMutation) SetField(name string, value ent.Value) error { } m.SetGamebanPresent(v) return nil + case match.FieldDecryptionKey: + v, ok := value.([]byte) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetDecryptionKey(v) + return nil } return fmt.Errorf("unknown Match field %s", name) } @@ -1134,6 +1220,9 @@ func (m *MatchMutation) ClearedFields() []string { if m.FieldCleared(match.FieldReplayURL) { fields = append(fields, match.FieldReplayURL) } + if m.FieldCleared(match.FieldDecryptionKey) { + fields = append(fields, match.FieldDecryptionKey) + } return fields } @@ -1154,6 +1243,9 @@ func (m *MatchMutation) ClearField(name string) error { case match.FieldReplayURL: m.ClearReplayURL() return nil + case match.FieldDecryptionKey: + m.ClearDecryptionKey() + return nil } return fmt.Errorf("unknown Match nullable field %s", name) } @@ -1198,6 +1290,9 @@ func (m *MatchMutation) ResetField(name string) error { case match.FieldGamebanPresent: m.ResetGamebanPresent() return nil + case match.FieldDecryptionKey: + m.ResetDecryptionKey() + return nil } return fmt.Errorf("unknown Match field %s", name) } @@ -1329,7 +1424,7 @@ type MatchPlayerMutation struct { headshot *int addheadshot *int mvp *uint - addmvp *uint + addmvp *int score *int addscore *int rank_new *int @@ -1337,27 +1432,27 @@ type MatchPlayerMutation struct { rank_old *int addrank_old *int mk_2 *uint - addmk_2 *uint + addmk_2 *int mk_3 *uint - addmk_3 *uint + addmk_3 *int mk_4 *uint - addmk_4 *uint + addmk_4 *int mk_5 *uint - addmk_5 *uint + addmk_5 *int dmg_enemy *uint - adddmg_enemy *uint + adddmg_enemy *int dmg_team *uint - adddmg_team *uint + adddmg_team *int ud_he *uint - addud_he *uint + addud_he *int ud_flames *uint - addud_flames *uint + addud_flames *int ud_flash *uint - addud_flash *uint + addud_flash *int ud_decoy *uint - addud_decoy *uint + addud_decoy *int ud_smoke *uint - addud_smoke *uint + addud_smoke *int crosshair *string color *matchplayer.Color kast *int @@ -1369,11 +1464,11 @@ type MatchPlayerMutation struct { flash_duration_enemy *float32 addflash_duration_enemy *float32 flash_total_self *uint - addflash_total_self *uint + addflash_total_self *int flash_total_team *uint - addflash_total_team *uint + addflash_total_team *int flash_total_enemy *uint - addflash_total_enemy *uint + addflash_total_enemy *int flash_assists *int addflash_assists *int clearedFields map[string]struct{} @@ -1390,6 +1485,9 @@ type MatchPlayerMutation struct { spray map[int]struct{} removedspray map[int]struct{} clearedspray bool + messages map[int]struct{} + removedmessages map[int]struct{} + clearedmessages bool done bool oldValue func(context.Context) (*MatchPlayer, error) predicates []predicate.MatchPlayer @@ -1425,7 +1523,7 @@ func withMatchPlayerID(id int) matchplayerOption { m.oldValue = func(ctx context.Context) (*MatchPlayer, error) { once.Do(func() { if m.done { - err = fmt.Errorf("querying old values post mutation is not allowed") + err = errors.New("querying old values post mutation is not allowed") } else { value, err = m.Client().MatchPlayer.Get(ctx, id) } @@ -1458,7 +1556,7 @@ func (m MatchPlayerMutation) Client() *Client { // it returns an error otherwise. func (m MatchPlayerMutation) Tx() (*Tx, error) { if _, ok := m.driver.(*txDriver); !ok { - return nil, fmt.Errorf("ent: mutation is not running in a transaction") + return nil, errors.New("ent: mutation is not running in a transaction") } tx := &Tx{config: m.config} tx.init() @@ -1474,6 +1572,25 @@ func (m *MatchPlayerMutation) ID() (id int, exists bool) { return *m.id, true } +// IDs queries the database and returns the entity ids that match the mutation's predicate. +// That means, if the mutation is applied within a transaction with an isolation level such +// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated +// or updated by the mutation. +func (m *MatchPlayerMutation) IDs(ctx context.Context) ([]int, error) { + switch { + case m.op.Is(OpUpdateOne | OpDeleteOne): + id, exists := m.ID() + if exists { + return []int{id}, nil + } + fallthrough + case m.op.Is(OpUpdate | OpDelete): + return m.Client().MatchPlayer.Query().Where(m.predicates...).IDs(ctx) + default: + return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) + } +} + // SetTeamID sets the "team_id" field. func (m *MatchPlayerMutation) SetTeamID(i int) { m.team_id = &i @@ -1494,10 +1611,10 @@ func (m *MatchPlayerMutation) TeamID() (r int, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *MatchPlayerMutation) OldTeamID(ctx context.Context) (v int, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldTeamID is only allowed on UpdateOne operations") + return v, errors.New("OldTeamID is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldTeamID requires an ID field in the mutation") + return v, errors.New("OldTeamID requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -1550,10 +1667,10 @@ func (m *MatchPlayerMutation) Kills() (r int, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *MatchPlayerMutation) OldKills(ctx context.Context) (v int, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldKills is only allowed on UpdateOne operations") + return v, errors.New("OldKills is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldKills requires an ID field in the mutation") + return v, errors.New("OldKills requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -1606,10 +1723,10 @@ func (m *MatchPlayerMutation) Deaths() (r int, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *MatchPlayerMutation) OldDeaths(ctx context.Context) (v int, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldDeaths is only allowed on UpdateOne operations") + return v, errors.New("OldDeaths is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldDeaths requires an ID field in the mutation") + return v, errors.New("OldDeaths requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -1662,10 +1779,10 @@ func (m *MatchPlayerMutation) Assists() (r int, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *MatchPlayerMutation) OldAssists(ctx context.Context) (v int, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldAssists is only allowed on UpdateOne operations") + return v, errors.New("OldAssists is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldAssists requires an ID field in the mutation") + return v, errors.New("OldAssists requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -1718,10 +1835,10 @@ func (m *MatchPlayerMutation) Headshot() (r int, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *MatchPlayerMutation) OldHeadshot(ctx context.Context) (v int, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldHeadshot is only allowed on UpdateOne operations") + return v, errors.New("OldHeadshot is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldHeadshot requires an ID field in the mutation") + return v, errors.New("OldHeadshot requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -1774,10 +1891,10 @@ func (m *MatchPlayerMutation) Mvp() (r uint, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *MatchPlayerMutation) OldMvp(ctx context.Context) (v uint, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldMvp is only allowed on UpdateOne operations") + return v, errors.New("OldMvp is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldMvp requires an ID field in the mutation") + return v, errors.New("OldMvp requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -1787,7 +1904,7 @@ func (m *MatchPlayerMutation) OldMvp(ctx context.Context) (v uint, err error) { } // AddMvp adds u to the "mvp" field. -func (m *MatchPlayerMutation) AddMvp(u uint) { +func (m *MatchPlayerMutation) AddMvp(u int) { if m.addmvp != nil { *m.addmvp += u } else { @@ -1796,7 +1913,7 @@ func (m *MatchPlayerMutation) AddMvp(u uint) { } // AddedMvp returns the value that was added to the "mvp" field in this mutation. -func (m *MatchPlayerMutation) AddedMvp() (r uint, exists bool) { +func (m *MatchPlayerMutation) AddedMvp() (r int, exists bool) { v := m.addmvp if v == nil { return @@ -1830,10 +1947,10 @@ func (m *MatchPlayerMutation) Score() (r int, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *MatchPlayerMutation) OldScore(ctx context.Context) (v int, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldScore is only allowed on UpdateOne operations") + return v, errors.New("OldScore is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldScore requires an ID field in the mutation") + return v, errors.New("OldScore requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -1886,10 +2003,10 @@ func (m *MatchPlayerMutation) RankNew() (r int, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *MatchPlayerMutation) OldRankNew(ctx context.Context) (v int, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldRankNew is only allowed on UpdateOne operations") + return v, errors.New("OldRankNew is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldRankNew requires an ID field in the mutation") + return v, errors.New("OldRankNew requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -1956,10 +2073,10 @@ func (m *MatchPlayerMutation) RankOld() (r int, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *MatchPlayerMutation) OldRankOld(ctx context.Context) (v int, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldRankOld is only allowed on UpdateOne operations") + return v, errors.New("OldRankOld is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldRankOld requires an ID field in the mutation") + return v, errors.New("OldRankOld requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -2026,10 +2143,10 @@ func (m *MatchPlayerMutation) Mk2() (r uint, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *MatchPlayerMutation) OldMk2(ctx context.Context) (v uint, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldMk2 is only allowed on UpdateOne operations") + return v, errors.New("OldMk2 is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldMk2 requires an ID field in the mutation") + return v, errors.New("OldMk2 requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -2039,7 +2156,7 @@ func (m *MatchPlayerMutation) OldMk2(ctx context.Context) (v uint, err error) { } // AddMk2 adds u to the "mk_2" field. -func (m *MatchPlayerMutation) AddMk2(u uint) { +func (m *MatchPlayerMutation) AddMk2(u int) { if m.addmk_2 != nil { *m.addmk_2 += u } else { @@ -2048,7 +2165,7 @@ func (m *MatchPlayerMutation) AddMk2(u uint) { } // AddedMk2 returns the value that was added to the "mk_2" field in this mutation. -func (m *MatchPlayerMutation) AddedMk2() (r uint, exists bool) { +func (m *MatchPlayerMutation) AddedMk2() (r int, exists bool) { v := m.addmk_2 if v == nil { return @@ -2096,10 +2213,10 @@ func (m *MatchPlayerMutation) Mk3() (r uint, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *MatchPlayerMutation) OldMk3(ctx context.Context) (v uint, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldMk3 is only allowed on UpdateOne operations") + return v, errors.New("OldMk3 is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldMk3 requires an ID field in the mutation") + return v, errors.New("OldMk3 requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -2109,7 +2226,7 @@ func (m *MatchPlayerMutation) OldMk3(ctx context.Context) (v uint, err error) { } // AddMk3 adds u to the "mk_3" field. -func (m *MatchPlayerMutation) AddMk3(u uint) { +func (m *MatchPlayerMutation) AddMk3(u int) { if m.addmk_3 != nil { *m.addmk_3 += u } else { @@ -2118,7 +2235,7 @@ func (m *MatchPlayerMutation) AddMk3(u uint) { } // AddedMk3 returns the value that was added to the "mk_3" field in this mutation. -func (m *MatchPlayerMutation) AddedMk3() (r uint, exists bool) { +func (m *MatchPlayerMutation) AddedMk3() (r int, exists bool) { v := m.addmk_3 if v == nil { return @@ -2166,10 +2283,10 @@ func (m *MatchPlayerMutation) Mk4() (r uint, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *MatchPlayerMutation) OldMk4(ctx context.Context) (v uint, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldMk4 is only allowed on UpdateOne operations") + return v, errors.New("OldMk4 is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldMk4 requires an ID field in the mutation") + return v, errors.New("OldMk4 requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -2179,7 +2296,7 @@ func (m *MatchPlayerMutation) OldMk4(ctx context.Context) (v uint, err error) { } // AddMk4 adds u to the "mk_4" field. -func (m *MatchPlayerMutation) AddMk4(u uint) { +func (m *MatchPlayerMutation) AddMk4(u int) { if m.addmk_4 != nil { *m.addmk_4 += u } else { @@ -2188,7 +2305,7 @@ func (m *MatchPlayerMutation) AddMk4(u uint) { } // AddedMk4 returns the value that was added to the "mk_4" field in this mutation. -func (m *MatchPlayerMutation) AddedMk4() (r uint, exists bool) { +func (m *MatchPlayerMutation) AddedMk4() (r int, exists bool) { v := m.addmk_4 if v == nil { return @@ -2236,10 +2353,10 @@ func (m *MatchPlayerMutation) Mk5() (r uint, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *MatchPlayerMutation) OldMk5(ctx context.Context) (v uint, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldMk5 is only allowed on UpdateOne operations") + return v, errors.New("OldMk5 is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldMk5 requires an ID field in the mutation") + return v, errors.New("OldMk5 requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -2249,7 +2366,7 @@ func (m *MatchPlayerMutation) OldMk5(ctx context.Context) (v uint, err error) { } // AddMk5 adds u to the "mk_5" field. -func (m *MatchPlayerMutation) AddMk5(u uint) { +func (m *MatchPlayerMutation) AddMk5(u int) { if m.addmk_5 != nil { *m.addmk_5 += u } else { @@ -2258,7 +2375,7 @@ func (m *MatchPlayerMutation) AddMk5(u uint) { } // AddedMk5 returns the value that was added to the "mk_5" field in this mutation. -func (m *MatchPlayerMutation) AddedMk5() (r uint, exists bool) { +func (m *MatchPlayerMutation) AddedMk5() (r int, exists bool) { v := m.addmk_5 if v == nil { return @@ -2306,10 +2423,10 @@ func (m *MatchPlayerMutation) DmgEnemy() (r uint, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *MatchPlayerMutation) OldDmgEnemy(ctx context.Context) (v uint, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldDmgEnemy is only allowed on UpdateOne operations") + return v, errors.New("OldDmgEnemy is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldDmgEnemy requires an ID field in the mutation") + return v, errors.New("OldDmgEnemy requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -2319,7 +2436,7 @@ func (m *MatchPlayerMutation) OldDmgEnemy(ctx context.Context) (v uint, err erro } // AddDmgEnemy adds u to the "dmg_enemy" field. -func (m *MatchPlayerMutation) AddDmgEnemy(u uint) { +func (m *MatchPlayerMutation) AddDmgEnemy(u int) { if m.adddmg_enemy != nil { *m.adddmg_enemy += u } else { @@ -2328,7 +2445,7 @@ func (m *MatchPlayerMutation) AddDmgEnemy(u uint) { } // AddedDmgEnemy returns the value that was added to the "dmg_enemy" field in this mutation. -func (m *MatchPlayerMutation) AddedDmgEnemy() (r uint, exists bool) { +func (m *MatchPlayerMutation) AddedDmgEnemy() (r int, exists bool) { v := m.adddmg_enemy if v == nil { return @@ -2376,10 +2493,10 @@ func (m *MatchPlayerMutation) DmgTeam() (r uint, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *MatchPlayerMutation) OldDmgTeam(ctx context.Context) (v uint, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldDmgTeam is only allowed on UpdateOne operations") + return v, errors.New("OldDmgTeam is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldDmgTeam requires an ID field in the mutation") + return v, errors.New("OldDmgTeam requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -2389,7 +2506,7 @@ func (m *MatchPlayerMutation) OldDmgTeam(ctx context.Context) (v uint, err error } // AddDmgTeam adds u to the "dmg_team" field. -func (m *MatchPlayerMutation) AddDmgTeam(u uint) { +func (m *MatchPlayerMutation) AddDmgTeam(u int) { if m.adddmg_team != nil { *m.adddmg_team += u } else { @@ -2398,7 +2515,7 @@ func (m *MatchPlayerMutation) AddDmgTeam(u uint) { } // AddedDmgTeam returns the value that was added to the "dmg_team" field in this mutation. -func (m *MatchPlayerMutation) AddedDmgTeam() (r uint, exists bool) { +func (m *MatchPlayerMutation) AddedDmgTeam() (r int, exists bool) { v := m.adddmg_team if v == nil { return @@ -2446,10 +2563,10 @@ func (m *MatchPlayerMutation) UdHe() (r uint, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *MatchPlayerMutation) OldUdHe(ctx context.Context) (v uint, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldUdHe is only allowed on UpdateOne operations") + return v, errors.New("OldUdHe is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldUdHe requires an ID field in the mutation") + return v, errors.New("OldUdHe requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -2459,7 +2576,7 @@ func (m *MatchPlayerMutation) OldUdHe(ctx context.Context) (v uint, err error) { } // AddUdHe adds u to the "ud_he" field. -func (m *MatchPlayerMutation) AddUdHe(u uint) { +func (m *MatchPlayerMutation) AddUdHe(u int) { if m.addud_he != nil { *m.addud_he += u } else { @@ -2468,7 +2585,7 @@ func (m *MatchPlayerMutation) AddUdHe(u uint) { } // AddedUdHe returns the value that was added to the "ud_he" field in this mutation. -func (m *MatchPlayerMutation) AddedUdHe() (r uint, exists bool) { +func (m *MatchPlayerMutation) AddedUdHe() (r int, exists bool) { v := m.addud_he if v == nil { return @@ -2516,10 +2633,10 @@ func (m *MatchPlayerMutation) UdFlames() (r uint, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *MatchPlayerMutation) OldUdFlames(ctx context.Context) (v uint, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldUdFlames is only allowed on UpdateOne operations") + return v, errors.New("OldUdFlames is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldUdFlames requires an ID field in the mutation") + return v, errors.New("OldUdFlames requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -2529,7 +2646,7 @@ func (m *MatchPlayerMutation) OldUdFlames(ctx context.Context) (v uint, err erro } // AddUdFlames adds u to the "ud_flames" field. -func (m *MatchPlayerMutation) AddUdFlames(u uint) { +func (m *MatchPlayerMutation) AddUdFlames(u int) { if m.addud_flames != nil { *m.addud_flames += u } else { @@ -2538,7 +2655,7 @@ func (m *MatchPlayerMutation) AddUdFlames(u uint) { } // AddedUdFlames returns the value that was added to the "ud_flames" field in this mutation. -func (m *MatchPlayerMutation) AddedUdFlames() (r uint, exists bool) { +func (m *MatchPlayerMutation) AddedUdFlames() (r int, exists bool) { v := m.addud_flames if v == nil { return @@ -2586,10 +2703,10 @@ func (m *MatchPlayerMutation) UdFlash() (r uint, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *MatchPlayerMutation) OldUdFlash(ctx context.Context) (v uint, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldUdFlash is only allowed on UpdateOne operations") + return v, errors.New("OldUdFlash is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldUdFlash requires an ID field in the mutation") + return v, errors.New("OldUdFlash requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -2599,7 +2716,7 @@ func (m *MatchPlayerMutation) OldUdFlash(ctx context.Context) (v uint, err error } // AddUdFlash adds u to the "ud_flash" field. -func (m *MatchPlayerMutation) AddUdFlash(u uint) { +func (m *MatchPlayerMutation) AddUdFlash(u int) { if m.addud_flash != nil { *m.addud_flash += u } else { @@ -2608,7 +2725,7 @@ func (m *MatchPlayerMutation) AddUdFlash(u uint) { } // AddedUdFlash returns the value that was added to the "ud_flash" field in this mutation. -func (m *MatchPlayerMutation) AddedUdFlash() (r uint, exists bool) { +func (m *MatchPlayerMutation) AddedUdFlash() (r int, exists bool) { v := m.addud_flash if v == nil { return @@ -2656,10 +2773,10 @@ func (m *MatchPlayerMutation) UdDecoy() (r uint, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *MatchPlayerMutation) OldUdDecoy(ctx context.Context) (v uint, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldUdDecoy is only allowed on UpdateOne operations") + return v, errors.New("OldUdDecoy is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldUdDecoy requires an ID field in the mutation") + return v, errors.New("OldUdDecoy requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -2669,7 +2786,7 @@ func (m *MatchPlayerMutation) OldUdDecoy(ctx context.Context) (v uint, err error } // AddUdDecoy adds u to the "ud_decoy" field. -func (m *MatchPlayerMutation) AddUdDecoy(u uint) { +func (m *MatchPlayerMutation) AddUdDecoy(u int) { if m.addud_decoy != nil { *m.addud_decoy += u } else { @@ -2678,7 +2795,7 @@ func (m *MatchPlayerMutation) AddUdDecoy(u uint) { } // AddedUdDecoy returns the value that was added to the "ud_decoy" field in this mutation. -func (m *MatchPlayerMutation) AddedUdDecoy() (r uint, exists bool) { +func (m *MatchPlayerMutation) AddedUdDecoy() (r int, exists bool) { v := m.addud_decoy if v == nil { return @@ -2726,10 +2843,10 @@ func (m *MatchPlayerMutation) UdSmoke() (r uint, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *MatchPlayerMutation) OldUdSmoke(ctx context.Context) (v uint, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldUdSmoke is only allowed on UpdateOne operations") + return v, errors.New("OldUdSmoke is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldUdSmoke requires an ID field in the mutation") + return v, errors.New("OldUdSmoke requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -2739,7 +2856,7 @@ func (m *MatchPlayerMutation) OldUdSmoke(ctx context.Context) (v uint, err error } // AddUdSmoke adds u to the "ud_smoke" field. -func (m *MatchPlayerMutation) AddUdSmoke(u uint) { +func (m *MatchPlayerMutation) AddUdSmoke(u int) { if m.addud_smoke != nil { *m.addud_smoke += u } else { @@ -2748,7 +2865,7 @@ func (m *MatchPlayerMutation) AddUdSmoke(u uint) { } // AddedUdSmoke returns the value that was added to the "ud_smoke" field in this mutation. -func (m *MatchPlayerMutation) AddedUdSmoke() (r uint, exists bool) { +func (m *MatchPlayerMutation) AddedUdSmoke() (r int, exists bool) { v := m.addud_smoke if v == nil { return @@ -2795,10 +2912,10 @@ func (m *MatchPlayerMutation) Crosshair() (r string, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *MatchPlayerMutation) OldCrosshair(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldCrosshair is only allowed on UpdateOne operations") + return v, errors.New("OldCrosshair is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldCrosshair requires an ID field in the mutation") + return v, errors.New("OldCrosshair requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -2844,10 +2961,10 @@ func (m *MatchPlayerMutation) Color() (r matchplayer.Color, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *MatchPlayerMutation) OldColor(ctx context.Context) (v matchplayer.Color, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldColor is only allowed on UpdateOne operations") + return v, errors.New("OldColor is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldColor requires an ID field in the mutation") + return v, errors.New("OldColor requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -2894,10 +3011,10 @@ func (m *MatchPlayerMutation) Kast() (r int, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *MatchPlayerMutation) OldKast(ctx context.Context) (v int, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldKast is only allowed on UpdateOne operations") + return v, errors.New("OldKast is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldKast requires an ID field in the mutation") + return v, errors.New("OldKast requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -2964,10 +3081,10 @@ func (m *MatchPlayerMutation) FlashDurationSelf() (r float32, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *MatchPlayerMutation) OldFlashDurationSelf(ctx context.Context) (v float32, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldFlashDurationSelf is only allowed on UpdateOne operations") + return v, errors.New("OldFlashDurationSelf is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldFlashDurationSelf requires an ID field in the mutation") + return v, errors.New("OldFlashDurationSelf requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -3034,10 +3151,10 @@ func (m *MatchPlayerMutation) FlashDurationTeam() (r float32, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *MatchPlayerMutation) OldFlashDurationTeam(ctx context.Context) (v float32, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldFlashDurationTeam is only allowed on UpdateOne operations") + return v, errors.New("OldFlashDurationTeam is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldFlashDurationTeam requires an ID field in the mutation") + return v, errors.New("OldFlashDurationTeam requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -3104,10 +3221,10 @@ func (m *MatchPlayerMutation) FlashDurationEnemy() (r float32, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *MatchPlayerMutation) OldFlashDurationEnemy(ctx context.Context) (v float32, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldFlashDurationEnemy is only allowed on UpdateOne operations") + return v, errors.New("OldFlashDurationEnemy is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldFlashDurationEnemy requires an ID field in the mutation") + return v, errors.New("OldFlashDurationEnemy requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -3174,10 +3291,10 @@ func (m *MatchPlayerMutation) FlashTotalSelf() (r uint, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *MatchPlayerMutation) OldFlashTotalSelf(ctx context.Context) (v uint, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldFlashTotalSelf is only allowed on UpdateOne operations") + return v, errors.New("OldFlashTotalSelf is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldFlashTotalSelf requires an ID field in the mutation") + return v, errors.New("OldFlashTotalSelf requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -3187,7 +3304,7 @@ func (m *MatchPlayerMutation) OldFlashTotalSelf(ctx context.Context) (v uint, er } // AddFlashTotalSelf adds u to the "flash_total_self" field. -func (m *MatchPlayerMutation) AddFlashTotalSelf(u uint) { +func (m *MatchPlayerMutation) AddFlashTotalSelf(u int) { if m.addflash_total_self != nil { *m.addflash_total_self += u } else { @@ -3196,7 +3313,7 @@ func (m *MatchPlayerMutation) AddFlashTotalSelf(u uint) { } // AddedFlashTotalSelf returns the value that was added to the "flash_total_self" field in this mutation. -func (m *MatchPlayerMutation) AddedFlashTotalSelf() (r uint, exists bool) { +func (m *MatchPlayerMutation) AddedFlashTotalSelf() (r int, exists bool) { v := m.addflash_total_self if v == nil { return @@ -3244,10 +3361,10 @@ func (m *MatchPlayerMutation) FlashTotalTeam() (r uint, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *MatchPlayerMutation) OldFlashTotalTeam(ctx context.Context) (v uint, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldFlashTotalTeam is only allowed on UpdateOne operations") + return v, errors.New("OldFlashTotalTeam is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldFlashTotalTeam requires an ID field in the mutation") + return v, errors.New("OldFlashTotalTeam requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -3257,7 +3374,7 @@ func (m *MatchPlayerMutation) OldFlashTotalTeam(ctx context.Context) (v uint, er } // AddFlashTotalTeam adds u to the "flash_total_team" field. -func (m *MatchPlayerMutation) AddFlashTotalTeam(u uint) { +func (m *MatchPlayerMutation) AddFlashTotalTeam(u int) { if m.addflash_total_team != nil { *m.addflash_total_team += u } else { @@ -3266,7 +3383,7 @@ func (m *MatchPlayerMutation) AddFlashTotalTeam(u uint) { } // AddedFlashTotalTeam returns the value that was added to the "flash_total_team" field in this mutation. -func (m *MatchPlayerMutation) AddedFlashTotalTeam() (r uint, exists bool) { +func (m *MatchPlayerMutation) AddedFlashTotalTeam() (r int, exists bool) { v := m.addflash_total_team if v == nil { return @@ -3314,10 +3431,10 @@ func (m *MatchPlayerMutation) FlashTotalEnemy() (r uint, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *MatchPlayerMutation) OldFlashTotalEnemy(ctx context.Context) (v uint, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldFlashTotalEnemy is only allowed on UpdateOne operations") + return v, errors.New("OldFlashTotalEnemy is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldFlashTotalEnemy requires an ID field in the mutation") + return v, errors.New("OldFlashTotalEnemy requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -3327,7 +3444,7 @@ func (m *MatchPlayerMutation) OldFlashTotalEnemy(ctx context.Context) (v uint, e } // AddFlashTotalEnemy adds u to the "flash_total_enemy" field. -func (m *MatchPlayerMutation) AddFlashTotalEnemy(u uint) { +func (m *MatchPlayerMutation) AddFlashTotalEnemy(u int) { if m.addflash_total_enemy != nil { *m.addflash_total_enemy += u } else { @@ -3336,7 +3453,7 @@ func (m *MatchPlayerMutation) AddFlashTotalEnemy(u uint) { } // AddedFlashTotalEnemy returns the value that was added to the "flash_total_enemy" field in this mutation. -func (m *MatchPlayerMutation) AddedFlashTotalEnemy() (r uint, exists bool) { +func (m *MatchPlayerMutation) AddedFlashTotalEnemy() (r int, exists bool) { v := m.addflash_total_enemy if v == nil { return @@ -3383,10 +3500,10 @@ func (m *MatchPlayerMutation) MatchStats() (r uint64, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *MatchPlayerMutation) OldMatchStats(ctx context.Context) (v uint64, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldMatchStats is only allowed on UpdateOne operations") + return v, errors.New("OldMatchStats is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldMatchStats requires an ID field in the mutation") + return v, errors.New("OldMatchStats requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -3432,10 +3549,10 @@ func (m *MatchPlayerMutation) PlayerStats() (r uint64, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *MatchPlayerMutation) OldPlayerStats(ctx context.Context) (v uint64, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldPlayerStats is only allowed on UpdateOne operations") + return v, errors.New("OldPlayerStats is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldPlayerStats requires an ID field in the mutation") + return v, errors.New("OldPlayerStats requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -3482,10 +3599,10 @@ func (m *MatchPlayerMutation) FlashAssists() (r int, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *MatchPlayerMutation) OldFlashAssists(ctx context.Context) (v int, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldFlashAssists is only allowed on UpdateOne operations") + return v, errors.New("OldFlashAssists is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldFlashAssists requires an ID field in the mutation") + return v, errors.New("OldFlashAssists requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -3772,6 +3889,60 @@ func (m *MatchPlayerMutation) ResetSpray() { m.removedspray = nil } +// AddMessageIDs adds the "messages" edge to the Messages entity by ids. +func (m *MatchPlayerMutation) AddMessageIDs(ids ...int) { + if m.messages == nil { + m.messages = make(map[int]struct{}) + } + for i := range ids { + m.messages[ids[i]] = struct{}{} + } +} + +// ClearMessages clears the "messages" edge to the Messages entity. +func (m *MatchPlayerMutation) ClearMessages() { + m.clearedmessages = true +} + +// MessagesCleared reports if the "messages" edge to the Messages entity was cleared. +func (m *MatchPlayerMutation) MessagesCleared() bool { + return m.clearedmessages +} + +// RemoveMessageIDs removes the "messages" edge to the Messages entity by IDs. +func (m *MatchPlayerMutation) RemoveMessageIDs(ids ...int) { + if m.removedmessages == nil { + m.removedmessages = make(map[int]struct{}) + } + for i := range ids { + delete(m.messages, ids[i]) + m.removedmessages[ids[i]] = struct{}{} + } +} + +// RemovedMessages returns the removed IDs of the "messages" edge to the Messages entity. +func (m *MatchPlayerMutation) RemovedMessagesIDs() (ids []int) { + for id := range m.removedmessages { + ids = append(ids, id) + } + return +} + +// MessagesIDs returns the "messages" edge IDs in the mutation. +func (m *MatchPlayerMutation) MessagesIDs() (ids []int) { + for id := range m.messages { + ids = append(ids, id) + } + return +} + +// ResetMessages resets all changes to the "messages" edge. +func (m *MatchPlayerMutation) ResetMessages() { + m.messages = nil + m.clearedmessages = false + m.removedmessages = nil +} + // Where appends a list predicates to the MatchPlayerMutation builder. func (m *MatchPlayerMutation) Where(ps ...predicate.MatchPlayer) { m.predicates = append(m.predicates, ps...) @@ -4467,7 +4638,7 @@ func (m *MatchPlayerMutation) AddField(name string, value ent.Value) error { m.AddHeadshot(v) return nil case matchplayer.FieldMvp: - v, ok := value.(uint) + v, ok := value.(int) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } @@ -4495,77 +4666,77 @@ func (m *MatchPlayerMutation) AddField(name string, value ent.Value) error { m.AddRankOld(v) return nil case matchplayer.FieldMk2: - v, ok := value.(uint) + v, ok := value.(int) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.AddMk2(v) return nil case matchplayer.FieldMk3: - v, ok := value.(uint) + v, ok := value.(int) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.AddMk3(v) return nil case matchplayer.FieldMk4: - v, ok := value.(uint) + v, ok := value.(int) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.AddMk4(v) return nil case matchplayer.FieldMk5: - v, ok := value.(uint) + v, ok := value.(int) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.AddMk5(v) return nil case matchplayer.FieldDmgEnemy: - v, ok := value.(uint) + v, ok := value.(int) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.AddDmgEnemy(v) return nil case matchplayer.FieldDmgTeam: - v, ok := value.(uint) + v, ok := value.(int) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.AddDmgTeam(v) return nil case matchplayer.FieldUdHe: - v, ok := value.(uint) + v, ok := value.(int) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.AddUdHe(v) return nil case matchplayer.FieldUdFlames: - v, ok := value.(uint) + v, ok := value.(int) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.AddUdFlames(v) return nil case matchplayer.FieldUdFlash: - v, ok := value.(uint) + v, ok := value.(int) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.AddUdFlash(v) return nil case matchplayer.FieldUdDecoy: - v, ok := value.(uint) + v, ok := value.(int) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.AddUdDecoy(v) return nil case matchplayer.FieldUdSmoke: - v, ok := value.(uint) + v, ok := value.(int) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } @@ -4600,21 +4771,21 @@ func (m *MatchPlayerMutation) AddField(name string, value ent.Value) error { m.AddFlashDurationEnemy(v) return nil case matchplayer.FieldFlashTotalSelf: - v, ok := value.(uint) + v, ok := value.(int) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.AddFlashTotalSelf(v) return nil case matchplayer.FieldFlashTotalTeam: - v, ok := value.(uint) + v, ok := value.(int) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.AddFlashTotalTeam(v) return nil case matchplayer.FieldFlashTotalEnemy: - v, ok := value.(uint) + v, ok := value.(int) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } @@ -4909,7 +5080,7 @@ func (m *MatchPlayerMutation) ResetField(name string) error { // AddedEdges returns all edge names that were set/added in this mutation. func (m *MatchPlayerMutation) AddedEdges() []string { - edges := make([]string, 0, 5) + edges := make([]string, 0, 6) if m.matches != nil { edges = append(edges, matchplayer.EdgeMatches) } @@ -4925,6 +5096,9 @@ func (m *MatchPlayerMutation) AddedEdges() []string { if m.spray != nil { edges = append(edges, matchplayer.EdgeSpray) } + if m.messages != nil { + edges = append(edges, matchplayer.EdgeMessages) + } return edges } @@ -4958,13 +5132,19 @@ func (m *MatchPlayerMutation) AddedIDs(name string) []ent.Value { ids = append(ids, id) } return ids + case matchplayer.EdgeMessages: + ids := make([]ent.Value, 0, len(m.messages)) + for id := range m.messages { + ids = append(ids, id) + } + return ids } return nil } // RemovedEdges returns all edge names that were removed in this mutation. func (m *MatchPlayerMutation) RemovedEdges() []string { - edges := make([]string, 0, 5) + edges := make([]string, 0, 6) if m.removedweapon_stats != nil { edges = append(edges, matchplayer.EdgeWeaponStats) } @@ -4974,6 +5154,9 @@ func (m *MatchPlayerMutation) RemovedEdges() []string { if m.removedspray != nil { edges = append(edges, matchplayer.EdgeSpray) } + if m.removedmessages != nil { + edges = append(edges, matchplayer.EdgeMessages) + } return edges } @@ -4999,13 +5182,19 @@ func (m *MatchPlayerMutation) RemovedIDs(name string) []ent.Value { ids = append(ids, id) } return ids + case matchplayer.EdgeMessages: + ids := make([]ent.Value, 0, len(m.removedmessages)) + for id := range m.removedmessages { + ids = append(ids, id) + } + return ids } return nil } // ClearedEdges returns all edge names that were cleared in this mutation. func (m *MatchPlayerMutation) ClearedEdges() []string { - edges := make([]string, 0, 5) + edges := make([]string, 0, 6) if m.clearedmatches { edges = append(edges, matchplayer.EdgeMatches) } @@ -5021,6 +5210,9 @@ func (m *MatchPlayerMutation) ClearedEdges() []string { if m.clearedspray { edges = append(edges, matchplayer.EdgeSpray) } + if m.clearedmessages { + edges = append(edges, matchplayer.EdgeMessages) + } return edges } @@ -5038,6 +5230,8 @@ func (m *MatchPlayerMutation) EdgeCleared(name string) bool { return m.clearedround_stats case matchplayer.EdgeSpray: return m.clearedspray + case matchplayer.EdgeMessages: + return m.clearedmessages } return false } @@ -5075,10 +5269,447 @@ func (m *MatchPlayerMutation) ResetEdge(name string) error { case matchplayer.EdgeSpray: m.ResetSpray() return nil + case matchplayer.EdgeMessages: + m.ResetMessages() + return nil } return fmt.Errorf("unknown MatchPlayer edge %s", name) } +// MessagesMutation represents an operation that mutates the Messages nodes in the graph. +type MessagesMutation struct { + config + op Op + typ string + id *int + message *string + all_chat *bool + clearedFields map[string]struct{} + match_player *int + clearedmatch_player bool + done bool + oldValue func(context.Context) (*Messages, error) + predicates []predicate.Messages +} + +var _ ent.Mutation = (*MessagesMutation)(nil) + +// messagesOption allows management of the mutation configuration using functional options. +type messagesOption func(*MessagesMutation) + +// newMessagesMutation creates new mutation for the Messages entity. +func newMessagesMutation(c config, op Op, opts ...messagesOption) *MessagesMutation { + m := &MessagesMutation{ + config: c, + op: op, + typ: TypeMessages, + clearedFields: make(map[string]struct{}), + } + for _, opt := range opts { + opt(m) + } + return m +} + +// withMessagesID sets the ID field of the mutation. +func withMessagesID(id int) messagesOption { + return func(m *MessagesMutation) { + var ( + err error + once sync.Once + value *Messages + ) + m.oldValue = func(ctx context.Context) (*Messages, error) { + once.Do(func() { + if m.done { + err = errors.New("querying old values post mutation is not allowed") + } else { + value, err = m.Client().Messages.Get(ctx, id) + } + }) + return value, err + } + m.id = &id + } +} + +// withMessages sets the old Messages of the mutation. +func withMessages(node *Messages) messagesOption { + return func(m *MessagesMutation) { + m.oldValue = func(context.Context) (*Messages, error) { + return node, nil + } + m.id = &node.ID + } +} + +// Client returns a new `ent.Client` from the mutation. If the mutation was +// executed in a transaction (ent.Tx), a transactional client is returned. +func (m MessagesMutation) Client() *Client { + client := &Client{config: m.config} + client.init() + return client +} + +// Tx returns an `ent.Tx` for mutations that were executed in transactions; +// it returns an error otherwise. +func (m MessagesMutation) Tx() (*Tx, error) { + if _, ok := m.driver.(*txDriver); !ok { + return nil, errors.New("ent: mutation is not running in a transaction") + } + tx := &Tx{config: m.config} + tx.init() + return tx, nil +} + +// ID returns the ID value in the mutation. Note that the ID is only available +// if it was provided to the builder or after it was returned from the database. +func (m *MessagesMutation) ID() (id int, exists bool) { + if m.id == nil { + return + } + return *m.id, true +} + +// IDs queries the database and returns the entity ids that match the mutation's predicate. +// That means, if the mutation is applied within a transaction with an isolation level such +// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated +// or updated by the mutation. +func (m *MessagesMutation) IDs(ctx context.Context) ([]int, error) { + switch { + case m.op.Is(OpUpdateOne | OpDeleteOne): + id, exists := m.ID() + if exists { + return []int{id}, nil + } + fallthrough + case m.op.Is(OpUpdate | OpDelete): + return m.Client().Messages.Query().Where(m.predicates...).IDs(ctx) + default: + return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) + } +} + +// SetMessage sets the "message" field. +func (m *MessagesMutation) SetMessage(s string) { + m.message = &s +} + +// Message returns the value of the "message" field in the mutation. +func (m *MessagesMutation) Message() (r string, exists bool) { + v := m.message + if v == nil { + return + } + return *v, true +} + +// OldMessage returns the old "message" field's value of the Messages entity. +// If the Messages object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *MessagesMutation) OldMessage(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldMessage is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldMessage requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldMessage: %w", err) + } + return oldValue.Message, nil +} + +// ResetMessage resets all changes to the "message" field. +func (m *MessagesMutation) ResetMessage() { + m.message = nil +} + +// SetAllChat sets the "all_chat" field. +func (m *MessagesMutation) SetAllChat(b bool) { + m.all_chat = &b +} + +// AllChat returns the value of the "all_chat" field in the mutation. +func (m *MessagesMutation) AllChat() (r bool, exists bool) { + v := m.all_chat + if v == nil { + return + } + return *v, true +} + +// OldAllChat returns the old "all_chat" field's value of the Messages entity. +// If the Messages object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *MessagesMutation) OldAllChat(ctx context.Context) (v bool, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldAllChat is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldAllChat requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldAllChat: %w", err) + } + return oldValue.AllChat, nil +} + +// ResetAllChat resets all changes to the "all_chat" field. +func (m *MessagesMutation) ResetAllChat() { + m.all_chat = nil +} + +// SetMatchPlayerID sets the "match_player" edge to the MatchPlayer entity by id. +func (m *MessagesMutation) SetMatchPlayerID(id int) { + m.match_player = &id +} + +// ClearMatchPlayer clears the "match_player" edge to the MatchPlayer entity. +func (m *MessagesMutation) ClearMatchPlayer() { + m.clearedmatch_player = true +} + +// MatchPlayerCleared reports if the "match_player" edge to the MatchPlayer entity was cleared. +func (m *MessagesMutation) MatchPlayerCleared() bool { + return m.clearedmatch_player +} + +// MatchPlayerID returns the "match_player" edge ID in the mutation. +func (m *MessagesMutation) MatchPlayerID() (id int, exists bool) { + if m.match_player != nil { + return *m.match_player, true + } + return +} + +// MatchPlayerIDs returns the "match_player" edge IDs in the mutation. +// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use +// MatchPlayerID instead. It exists only for internal usage by the builders. +func (m *MessagesMutation) MatchPlayerIDs() (ids []int) { + if id := m.match_player; id != nil { + ids = append(ids, *id) + } + return +} + +// ResetMatchPlayer resets all changes to the "match_player" edge. +func (m *MessagesMutation) ResetMatchPlayer() { + m.match_player = nil + m.clearedmatch_player = false +} + +// Where appends a list predicates to the MessagesMutation builder. +func (m *MessagesMutation) Where(ps ...predicate.Messages) { + m.predicates = append(m.predicates, ps...) +} + +// Op returns the operation name. +func (m *MessagesMutation) Op() Op { + return m.op +} + +// Type returns the node type of this mutation (Messages). +func (m *MessagesMutation) Type() string { + return m.typ +} + +// Fields returns all fields that were changed during this mutation. Note that in +// order to get all numeric fields that were incremented/decremented, call +// AddedFields(). +func (m *MessagesMutation) Fields() []string { + fields := make([]string, 0, 2) + if m.message != nil { + fields = append(fields, messages.FieldMessage) + } + if m.all_chat != nil { + fields = append(fields, messages.FieldAllChat) + } + return fields +} + +// Field returns the value of a field with the given name. The second boolean +// return value indicates that this field was not set, or was not defined in the +// schema. +func (m *MessagesMutation) Field(name string) (ent.Value, bool) { + switch name { + case messages.FieldMessage: + return m.Message() + case messages.FieldAllChat: + return m.AllChat() + } + return nil, false +} + +// OldField returns the old value of the field from the database. An error is +// returned if the mutation operation is not UpdateOne, or the query to the +// database failed. +func (m *MessagesMutation) OldField(ctx context.Context, name string) (ent.Value, error) { + switch name { + case messages.FieldMessage: + return m.OldMessage(ctx) + case messages.FieldAllChat: + return m.OldAllChat(ctx) + } + return nil, fmt.Errorf("unknown Messages field %s", name) +} + +// SetField sets the value of a field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. +func (m *MessagesMutation) SetField(name string, value ent.Value) error { + switch name { + case messages.FieldMessage: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetMessage(v) + return nil + case messages.FieldAllChat: + v, ok := value.(bool) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetAllChat(v) + return nil + } + return fmt.Errorf("unknown Messages field %s", name) +} + +// AddedFields returns all numeric fields that were incremented/decremented during +// this mutation. +func (m *MessagesMutation) AddedFields() []string { + return nil +} + +// AddedField returns the numeric value that was incremented/decremented on a field +// with the given name. The second boolean return value indicates that this field +// was not set, or was not defined in the schema. +func (m *MessagesMutation) AddedField(name string) (ent.Value, bool) { + return nil, false +} + +// AddField adds the value to the field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. +func (m *MessagesMutation) AddField(name string, value ent.Value) error { + switch name { + } + return fmt.Errorf("unknown Messages numeric field %s", name) +} + +// ClearedFields returns all nullable fields that were cleared during this +// mutation. +func (m *MessagesMutation) ClearedFields() []string { + return nil +} + +// FieldCleared returns a boolean indicating if a field with the given name was +// cleared in this mutation. +func (m *MessagesMutation) FieldCleared(name string) bool { + _, ok := m.clearedFields[name] + return ok +} + +// ClearField clears the value of the field with the given name. It returns an +// error if the field is not defined in the schema. +func (m *MessagesMutation) ClearField(name string) error { + return fmt.Errorf("unknown Messages nullable field %s", name) +} + +// ResetField resets all changes in the mutation for the field with the given name. +// It returns an error if the field is not defined in the schema. +func (m *MessagesMutation) ResetField(name string) error { + switch name { + case messages.FieldMessage: + m.ResetMessage() + return nil + case messages.FieldAllChat: + m.ResetAllChat() + return nil + } + return fmt.Errorf("unknown Messages field %s", name) +} + +// AddedEdges returns all edge names that were set/added in this mutation. +func (m *MessagesMutation) AddedEdges() []string { + edges := make([]string, 0, 1) + if m.match_player != nil { + edges = append(edges, messages.EdgeMatchPlayer) + } + return edges +} + +// AddedIDs returns all IDs (to other nodes) that were added for the given edge +// name in this mutation. +func (m *MessagesMutation) AddedIDs(name string) []ent.Value { + switch name { + case messages.EdgeMatchPlayer: + if id := m.match_player; id != nil { + return []ent.Value{*id} + } + } + return nil +} + +// RemovedEdges returns all edge names that were removed in this mutation. +func (m *MessagesMutation) RemovedEdges() []string { + edges := make([]string, 0, 1) + return edges +} + +// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with +// the given name in this mutation. +func (m *MessagesMutation) RemovedIDs(name string) []ent.Value { + switch name { + } + return nil +} + +// ClearedEdges returns all edge names that were cleared in this mutation. +func (m *MessagesMutation) ClearedEdges() []string { + edges := make([]string, 0, 1) + if m.clearedmatch_player { + edges = append(edges, messages.EdgeMatchPlayer) + } + return edges +} + +// EdgeCleared returns a boolean which indicates if the edge with the given name +// was cleared in this mutation. +func (m *MessagesMutation) EdgeCleared(name string) bool { + switch name { + case messages.EdgeMatchPlayer: + return m.clearedmatch_player + } + return false +} + +// ClearEdge clears the value of the edge with the given name. It returns an error +// if that edge is not defined in the schema. +func (m *MessagesMutation) ClearEdge(name string) error { + switch name { + case messages.EdgeMatchPlayer: + m.ClearMatchPlayer() + return nil + } + return fmt.Errorf("unknown Messages unique edge %s", name) +} + +// ResetEdge resets all changes to the edge with the given name in this mutation. +// It returns an error if the edge is not defined in the schema. +func (m *MessagesMutation) ResetEdge(name string) error { + switch name { + case messages.EdgeMatchPlayer: + m.ResetMatchPlayer() + return nil + } + return fmt.Errorf("unknown Messages edge %s", name) +} + // PlayerMutation represents an operation that mutates the Player nodes in the graph. type PlayerMutation struct { config @@ -5148,7 +5779,7 @@ func withPlayerID(id uint64) playerOption { m.oldValue = func(ctx context.Context) (*Player, error) { once.Do(func() { if m.done { - err = fmt.Errorf("querying old values post mutation is not allowed") + err = errors.New("querying old values post mutation is not allowed") } else { value, err = m.Client().Player.Get(ctx, id) } @@ -5181,7 +5812,7 @@ func (m PlayerMutation) Client() *Client { // it returns an error otherwise. func (m PlayerMutation) Tx() (*Tx, error) { if _, ok := m.driver.(*txDriver); !ok { - return nil, fmt.Errorf("ent: mutation is not running in a transaction") + return nil, errors.New("ent: mutation is not running in a transaction") } tx := &Tx{config: m.config} tx.init() @@ -5203,6 +5834,25 @@ func (m *PlayerMutation) ID() (id uint64, exists bool) { return *m.id, true } +// IDs queries the database and returns the entity ids that match the mutation's predicate. +// That means, if the mutation is applied within a transaction with an isolation level such +// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated +// or updated by the mutation. +func (m *PlayerMutation) IDs(ctx context.Context) ([]uint64, error) { + switch { + case m.op.Is(OpUpdateOne | OpDeleteOne): + id, exists := m.ID() + if exists { + return []uint64{id}, nil + } + fallthrough + case m.op.Is(OpUpdate | OpDelete): + return m.Client().Player.Query().Where(m.predicates...).IDs(ctx) + default: + return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) + } +} + // SetName sets the "name" field. func (m *PlayerMutation) SetName(s string) { m.name = &s @@ -5222,10 +5872,10 @@ func (m *PlayerMutation) Name() (r string, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *PlayerMutation) OldName(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldName is only allowed on UpdateOne operations") + return v, errors.New("OldName is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldName requires an ID field in the mutation") + return v, errors.New("OldName requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -5271,10 +5921,10 @@ func (m *PlayerMutation) Avatar() (r string, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *PlayerMutation) OldAvatar(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldAvatar is only allowed on UpdateOne operations") + return v, errors.New("OldAvatar is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldAvatar requires an ID field in the mutation") + return v, errors.New("OldAvatar requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -5320,10 +5970,10 @@ func (m *PlayerMutation) VanityURL() (r string, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *PlayerMutation) OldVanityURL(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldVanityURL is only allowed on UpdateOne operations") + return v, errors.New("OldVanityURL is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldVanityURL requires an ID field in the mutation") + return v, errors.New("OldVanityURL requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -5369,10 +6019,10 @@ func (m *PlayerMutation) VanityURLReal() (r string, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *PlayerMutation) OldVanityURLReal(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldVanityURLReal is only allowed on UpdateOne operations") + return v, errors.New("OldVanityURLReal is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldVanityURLReal requires an ID field in the mutation") + return v, errors.New("OldVanityURLReal requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -5418,10 +6068,10 @@ func (m *PlayerMutation) VacDate() (r time.Time, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *PlayerMutation) OldVacDate(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldVacDate is only allowed on UpdateOne operations") + return v, errors.New("OldVacDate is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldVacDate requires an ID field in the mutation") + return v, errors.New("OldVacDate requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -5468,10 +6118,10 @@ func (m *PlayerMutation) VacCount() (r int, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *PlayerMutation) OldVacCount(ctx context.Context) (v int, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldVacCount is only allowed on UpdateOne operations") + return v, errors.New("OldVacCount is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldVacCount requires an ID field in the mutation") + return v, errors.New("OldVacCount requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -5537,10 +6187,10 @@ func (m *PlayerMutation) GameBanDate() (r time.Time, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *PlayerMutation) OldGameBanDate(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldGameBanDate is only allowed on UpdateOne operations") + return v, errors.New("OldGameBanDate is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldGameBanDate requires an ID field in the mutation") + return v, errors.New("OldGameBanDate requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -5587,10 +6237,10 @@ func (m *PlayerMutation) GameBanCount() (r int, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *PlayerMutation) OldGameBanCount(ctx context.Context) (v int, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldGameBanCount is only allowed on UpdateOne operations") + return v, errors.New("OldGameBanCount is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldGameBanCount requires an ID field in the mutation") + return v, errors.New("OldGameBanCount requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -5656,10 +6306,10 @@ func (m *PlayerMutation) SteamUpdated() (r time.Time, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *PlayerMutation) OldSteamUpdated(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldSteamUpdated is only allowed on UpdateOne operations") + return v, errors.New("OldSteamUpdated is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldSteamUpdated requires an ID field in the mutation") + return v, errors.New("OldSteamUpdated requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -5692,10 +6342,10 @@ func (m *PlayerMutation) SharecodeUpdated() (r time.Time, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *PlayerMutation) OldSharecodeUpdated(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldSharecodeUpdated is only allowed on UpdateOne operations") + return v, errors.New("OldSharecodeUpdated is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldSharecodeUpdated requires an ID field in the mutation") + return v, errors.New("OldSharecodeUpdated requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -5741,10 +6391,10 @@ func (m *PlayerMutation) AuthCode() (r string, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *PlayerMutation) OldAuthCode(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldAuthCode is only allowed on UpdateOne operations") + return v, errors.New("OldAuthCode is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldAuthCode requires an ID field in the mutation") + return v, errors.New("OldAuthCode requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -5790,10 +6440,10 @@ func (m *PlayerMutation) ProfileCreated() (r time.Time, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *PlayerMutation) OldProfileCreated(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldProfileCreated is only allowed on UpdateOne operations") + return v, errors.New("OldProfileCreated is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldProfileCreated requires an ID field in the mutation") + return v, errors.New("OldProfileCreated requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -5839,10 +6489,10 @@ func (m *PlayerMutation) OldestSharecodeSeen() (r string, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *PlayerMutation) OldOldestSharecodeSeen(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldOldestSharecodeSeen is only allowed on UpdateOne operations") + return v, errors.New("OldOldestSharecodeSeen is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldOldestSharecodeSeen requires an ID field in the mutation") + return v, errors.New("OldOldestSharecodeSeen requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -5889,10 +6539,10 @@ func (m *PlayerMutation) Wins() (r int, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *PlayerMutation) OldWins(ctx context.Context) (v int, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldWins is only allowed on UpdateOne operations") + return v, errors.New("OldWins is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldWins requires an ID field in the mutation") + return v, errors.New("OldWins requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -5959,10 +6609,10 @@ func (m *PlayerMutation) Looses() (r int, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *PlayerMutation) OldLooses(ctx context.Context) (v int, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldLooses is only allowed on UpdateOne operations") + return v, errors.New("OldLooses is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldLooses requires an ID field in the mutation") + return v, errors.New("OldLooses requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -6029,10 +6679,10 @@ func (m *PlayerMutation) Ties() (r int, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *PlayerMutation) OldTies(ctx context.Context) (v int, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldTies is only allowed on UpdateOne operations") + return v, errors.New("OldTies is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldTies requires an ID field in the mutation") + return v, errors.New("OldTies requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -6831,13 +7481,13 @@ type RoundStatsMutation struct { typ string id *int round *uint - addround *uint + addround *int bank *uint - addbank *uint + addbank *int equipment *uint - addequipment *uint + addequipment *int spent *uint - addspent *uint + addspent *int clearedFields map[string]struct{} match_player *int clearedmatch_player bool @@ -6876,7 +7526,7 @@ func withRoundStatsID(id int) roundstatsOption { m.oldValue = func(ctx context.Context) (*RoundStats, error) { once.Do(func() { if m.done { - err = fmt.Errorf("querying old values post mutation is not allowed") + err = errors.New("querying old values post mutation is not allowed") } else { value, err = m.Client().RoundStats.Get(ctx, id) } @@ -6909,7 +7559,7 @@ func (m RoundStatsMutation) Client() *Client { // it returns an error otherwise. func (m RoundStatsMutation) Tx() (*Tx, error) { if _, ok := m.driver.(*txDriver); !ok { - return nil, fmt.Errorf("ent: mutation is not running in a transaction") + return nil, errors.New("ent: mutation is not running in a transaction") } tx := &Tx{config: m.config} tx.init() @@ -6925,6 +7575,25 @@ func (m *RoundStatsMutation) ID() (id int, exists bool) { return *m.id, true } +// IDs queries the database and returns the entity ids that match the mutation's predicate. +// That means, if the mutation is applied within a transaction with an isolation level such +// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated +// or updated by the mutation. +func (m *RoundStatsMutation) IDs(ctx context.Context) ([]int, error) { + switch { + case m.op.Is(OpUpdateOne | OpDeleteOne): + id, exists := m.ID() + if exists { + return []int{id}, nil + } + fallthrough + case m.op.Is(OpUpdate | OpDelete): + return m.Client().RoundStats.Query().Where(m.predicates...).IDs(ctx) + default: + return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) + } +} + // SetRound sets the "round" field. func (m *RoundStatsMutation) SetRound(u uint) { m.round = &u @@ -6945,10 +7614,10 @@ func (m *RoundStatsMutation) Round() (r uint, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *RoundStatsMutation) OldRound(ctx context.Context) (v uint, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldRound is only allowed on UpdateOne operations") + return v, errors.New("OldRound is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldRound requires an ID field in the mutation") + return v, errors.New("OldRound requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -6958,7 +7627,7 @@ func (m *RoundStatsMutation) OldRound(ctx context.Context) (v uint, err error) { } // AddRound adds u to the "round" field. -func (m *RoundStatsMutation) AddRound(u uint) { +func (m *RoundStatsMutation) AddRound(u int) { if m.addround != nil { *m.addround += u } else { @@ -6967,7 +7636,7 @@ func (m *RoundStatsMutation) AddRound(u uint) { } // AddedRound returns the value that was added to the "round" field in this mutation. -func (m *RoundStatsMutation) AddedRound() (r uint, exists bool) { +func (m *RoundStatsMutation) AddedRound() (r int, exists bool) { v := m.addround if v == nil { return @@ -7001,10 +7670,10 @@ func (m *RoundStatsMutation) Bank() (r uint, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *RoundStatsMutation) OldBank(ctx context.Context) (v uint, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldBank is only allowed on UpdateOne operations") + return v, errors.New("OldBank is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldBank requires an ID field in the mutation") + return v, errors.New("OldBank requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -7014,7 +7683,7 @@ func (m *RoundStatsMutation) OldBank(ctx context.Context) (v uint, err error) { } // AddBank adds u to the "bank" field. -func (m *RoundStatsMutation) AddBank(u uint) { +func (m *RoundStatsMutation) AddBank(u int) { if m.addbank != nil { *m.addbank += u } else { @@ -7023,7 +7692,7 @@ func (m *RoundStatsMutation) AddBank(u uint) { } // AddedBank returns the value that was added to the "bank" field in this mutation. -func (m *RoundStatsMutation) AddedBank() (r uint, exists bool) { +func (m *RoundStatsMutation) AddedBank() (r int, exists bool) { v := m.addbank if v == nil { return @@ -7057,10 +7726,10 @@ func (m *RoundStatsMutation) Equipment() (r uint, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *RoundStatsMutation) OldEquipment(ctx context.Context) (v uint, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldEquipment is only allowed on UpdateOne operations") + return v, errors.New("OldEquipment is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldEquipment requires an ID field in the mutation") + return v, errors.New("OldEquipment requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -7070,7 +7739,7 @@ func (m *RoundStatsMutation) OldEquipment(ctx context.Context) (v uint, err erro } // AddEquipment adds u to the "equipment" field. -func (m *RoundStatsMutation) AddEquipment(u uint) { +func (m *RoundStatsMutation) AddEquipment(u int) { if m.addequipment != nil { *m.addequipment += u } else { @@ -7079,7 +7748,7 @@ func (m *RoundStatsMutation) AddEquipment(u uint) { } // AddedEquipment returns the value that was added to the "equipment" field in this mutation. -func (m *RoundStatsMutation) AddedEquipment() (r uint, exists bool) { +func (m *RoundStatsMutation) AddedEquipment() (r int, exists bool) { v := m.addequipment if v == nil { return @@ -7113,10 +7782,10 @@ func (m *RoundStatsMutation) Spent() (r uint, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *RoundStatsMutation) OldSpent(ctx context.Context) (v uint, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldSpent is only allowed on UpdateOne operations") + return v, errors.New("OldSpent is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldSpent requires an ID field in the mutation") + return v, errors.New("OldSpent requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -7126,7 +7795,7 @@ func (m *RoundStatsMutation) OldSpent(ctx context.Context) (v uint, err error) { } // AddSpent adds u to the "spent" field. -func (m *RoundStatsMutation) AddSpent(u uint) { +func (m *RoundStatsMutation) AddSpent(u int) { if m.addspent != nil { *m.addspent += u } else { @@ -7135,7 +7804,7 @@ func (m *RoundStatsMutation) AddSpent(u uint) { } // AddedSpent returns the value that was added to the "spent" field in this mutation. -func (m *RoundStatsMutation) AddedSpent() (r uint, exists bool) { +func (m *RoundStatsMutation) AddedSpent() (r int, exists bool) { v := m.addspent if v == nil { return @@ -7336,28 +8005,28 @@ func (m *RoundStatsMutation) AddedField(name string) (ent.Value, bool) { func (m *RoundStatsMutation) AddField(name string, value ent.Value) error { switch name { case roundstats.FieldRound: - v, ok := value.(uint) + v, ok := value.(int) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.AddRound(v) return nil case roundstats.FieldBank: - v, ok := value.(uint) + v, ok := value.(int) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.AddBank(v) return nil case roundstats.FieldEquipment: - v, ok := value.(uint) + v, ok := value.(int) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.AddEquipment(v) return nil case roundstats.FieldSpent: - v, ok := value.(uint) + v, ok := value.(int) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } @@ -7529,7 +8198,7 @@ func withSprayID(id int) sprayOption { m.oldValue = func(ctx context.Context) (*Spray, error) { once.Do(func() { if m.done { - err = fmt.Errorf("querying old values post mutation is not allowed") + err = errors.New("querying old values post mutation is not allowed") } else { value, err = m.Client().Spray.Get(ctx, id) } @@ -7562,7 +8231,7 @@ func (m SprayMutation) Client() *Client { // it returns an error otherwise. func (m SprayMutation) Tx() (*Tx, error) { if _, ok := m.driver.(*txDriver); !ok { - return nil, fmt.Errorf("ent: mutation is not running in a transaction") + return nil, errors.New("ent: mutation is not running in a transaction") } tx := &Tx{config: m.config} tx.init() @@ -7578,6 +8247,25 @@ func (m *SprayMutation) ID() (id int, exists bool) { return *m.id, true } +// IDs queries the database and returns the entity ids that match the mutation's predicate. +// That means, if the mutation is applied within a transaction with an isolation level such +// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated +// or updated by the mutation. +func (m *SprayMutation) IDs(ctx context.Context) ([]int, error) { + switch { + case m.op.Is(OpUpdateOne | OpDeleteOne): + id, exists := m.ID() + if exists { + return []int{id}, nil + } + fallthrough + case m.op.Is(OpUpdate | OpDelete): + return m.Client().Spray.Query().Where(m.predicates...).IDs(ctx) + default: + return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) + } +} + // SetWeapon sets the "weapon" field. func (m *SprayMutation) SetWeapon(i int) { m.weapon = &i @@ -7598,10 +8286,10 @@ func (m *SprayMutation) Weapon() (r int, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *SprayMutation) OldWeapon(ctx context.Context) (v int, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldWeapon is only allowed on UpdateOne operations") + return v, errors.New("OldWeapon is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldWeapon requires an ID field in the mutation") + return v, errors.New("OldWeapon requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -7653,10 +8341,10 @@ func (m *SprayMutation) Spray() (r []byte, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *SprayMutation) OldSpray(ctx context.Context) (v []byte, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldSpray is only allowed on UpdateOne operations") + return v, errors.New("OldSpray is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldSpray requires an ID field in the mutation") + return v, errors.New("OldSpray requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -7940,9 +8628,9 @@ type WeaponMutation struct { typ string id *int victim *uint64 - addvictim *uint64 + addvictim *int64 dmg *uint - adddmg *uint + adddmg *int eq_type *int addeq_type *int hit_group *int @@ -7985,7 +8673,7 @@ func withWeaponID(id int) weaponOption { m.oldValue = func(ctx context.Context) (*Weapon, error) { once.Do(func() { if m.done { - err = fmt.Errorf("querying old values post mutation is not allowed") + err = errors.New("querying old values post mutation is not allowed") } else { value, err = m.Client().Weapon.Get(ctx, id) } @@ -8018,7 +8706,7 @@ func (m WeaponMutation) Client() *Client { // it returns an error otherwise. func (m WeaponMutation) Tx() (*Tx, error) { if _, ok := m.driver.(*txDriver); !ok { - return nil, fmt.Errorf("ent: mutation is not running in a transaction") + return nil, errors.New("ent: mutation is not running in a transaction") } tx := &Tx{config: m.config} tx.init() @@ -8034,6 +8722,25 @@ func (m *WeaponMutation) ID() (id int, exists bool) { return *m.id, true } +// IDs queries the database and returns the entity ids that match the mutation's predicate. +// That means, if the mutation is applied within a transaction with an isolation level such +// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated +// or updated by the mutation. +func (m *WeaponMutation) IDs(ctx context.Context) ([]int, error) { + switch { + case m.op.Is(OpUpdateOne | OpDeleteOne): + id, exists := m.ID() + if exists { + return []int{id}, nil + } + fallthrough + case m.op.Is(OpUpdate | OpDelete): + return m.Client().Weapon.Query().Where(m.predicates...).IDs(ctx) + default: + return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) + } +} + // SetVictim sets the "victim" field. func (m *WeaponMutation) SetVictim(u uint64) { m.victim = &u @@ -8054,10 +8761,10 @@ func (m *WeaponMutation) Victim() (r uint64, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *WeaponMutation) OldVictim(ctx context.Context) (v uint64, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldVictim is only allowed on UpdateOne operations") + return v, errors.New("OldVictim is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldVictim requires an ID field in the mutation") + return v, errors.New("OldVictim requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -8067,7 +8774,7 @@ func (m *WeaponMutation) OldVictim(ctx context.Context) (v uint64, err error) { } // AddVictim adds u to the "victim" field. -func (m *WeaponMutation) AddVictim(u uint64) { +func (m *WeaponMutation) AddVictim(u int64) { if m.addvictim != nil { *m.addvictim += u } else { @@ -8076,7 +8783,7 @@ func (m *WeaponMutation) AddVictim(u uint64) { } // AddedVictim returns the value that was added to the "victim" field in this mutation. -func (m *WeaponMutation) AddedVictim() (r uint64, exists bool) { +func (m *WeaponMutation) AddedVictim() (r int64, exists bool) { v := m.addvictim if v == nil { return @@ -8110,10 +8817,10 @@ func (m *WeaponMutation) Dmg() (r uint, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *WeaponMutation) OldDmg(ctx context.Context) (v uint, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldDmg is only allowed on UpdateOne operations") + return v, errors.New("OldDmg is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldDmg requires an ID field in the mutation") + return v, errors.New("OldDmg requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -8123,7 +8830,7 @@ func (m *WeaponMutation) OldDmg(ctx context.Context) (v uint, err error) { } // AddDmg adds u to the "dmg" field. -func (m *WeaponMutation) AddDmg(u uint) { +func (m *WeaponMutation) AddDmg(u int) { if m.adddmg != nil { *m.adddmg += u } else { @@ -8132,7 +8839,7 @@ func (m *WeaponMutation) AddDmg(u uint) { } // AddedDmg returns the value that was added to the "dmg" field in this mutation. -func (m *WeaponMutation) AddedDmg() (r uint, exists bool) { +func (m *WeaponMutation) AddedDmg() (r int, exists bool) { v := m.adddmg if v == nil { return @@ -8166,10 +8873,10 @@ func (m *WeaponMutation) EqType() (r int, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *WeaponMutation) OldEqType(ctx context.Context) (v int, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldEqType is only allowed on UpdateOne operations") + return v, errors.New("OldEqType is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldEqType requires an ID field in the mutation") + return v, errors.New("OldEqType requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -8222,10 +8929,10 @@ func (m *WeaponMutation) HitGroup() (r int, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *WeaponMutation) OldHitGroup(ctx context.Context) (v int, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldHitGroup is only allowed on UpdateOne operations") + return v, errors.New("OldHitGroup is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldHitGroup requires an ID field in the mutation") + return v, errors.New("OldHitGroup requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -8445,14 +9152,14 @@ func (m *WeaponMutation) AddedField(name string) (ent.Value, bool) { func (m *WeaponMutation) AddField(name string, value ent.Value) error { switch name { case weapon.FieldVictim: - v, ok := value.(uint64) + v, ok := value.(int64) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.AddVictim(v) return nil case weapon.FieldDmg: - v, ok := value.(uint) + v, ok := value.(int) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } diff --git a/ent/player_create.go b/ent/player_create.go index e7c5396..9190e79 100644 --- a/ent/player_create.go +++ b/ent/player_create.go @@ -362,7 +362,7 @@ func (pc *PlayerCreate) defaults() { // check runs all checks and user-defined validators on the builder. func (pc *PlayerCreate) check() error { if _, ok := pc.mutation.SteamUpdated(); !ok { - return &ValidationError{Name: "steam_updated", err: errors.New(`ent: missing required field "steam_updated"`)} + return &ValidationError{Name: "steam_updated", err: errors.New(`ent: missing required field "Player.steam_updated"`)} } return nil } diff --git a/ent/player_query.go b/ent/player_query.go index 494845c..1176663 100644 --- a/ent/player_query.go +++ b/ent/player_query.go @@ -513,6 +513,10 @@ 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 + } return sqlgraph.CountNodes(ctx, pq.driver, _spec) } @@ -584,6 +588,9 @@ func (pq *PlayerQuery) sqlQuery(ctx context.Context) *sql.Selector { selector = pq.sql selector.Select(selector.Columns(columns...)...) } + if pq.unique != nil && *pq.unique { + selector.Distinct() + } for _, m := range pq.modifiers { m(selector) } @@ -871,9 +878,7 @@ func (pgb *PlayerGroupBy) sqlQuery() *sql.Selector { for _, f := range pgb.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(pgb.fields...)...) diff --git a/ent/player_update.go b/ent/player_update.go index fe42a5e..bc90d50 100644 --- a/ent/player_update.go +++ b/ent/player_update.go @@ -8,6 +8,7 @@ import ( "csgowtfd/ent/matchplayer" "csgowtfd/ent/player" "csgowtfd/ent/predicate" + "errors" "fmt" "time" @@ -1391,7 +1392,7 @@ func (puo *PlayerUpdateOne) sqlSave(ctx context.Context) (_node *Player, err err } id, ok := puo.mutation.ID() if !ok { - return nil, &ValidationError{Name: "ID", err: fmt.Errorf("missing Player.ID for update")} + return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Player.id" for update`)} } _spec.Node.ID.Value = id if fields := puo.fields; len(fields) > 0 { diff --git a/ent/predicate/predicate.go b/ent/predicate/predicate.go index 020f865..614f3f4 100644 --- a/ent/predicate/predicate.go +++ b/ent/predicate/predicate.go @@ -12,6 +12,9 @@ type Match func(*sql.Selector) // MatchPlayer is the predicate function for matchplayer builders. type MatchPlayer func(*sql.Selector) +// Messages is the predicate function for messages builders. +type Messages func(*sql.Selector) + // Player is the predicate function for player builders. type Player func(*sql.Selector) diff --git a/ent/roundstats_create.go b/ent/roundstats_create.go index 34f3d20..788e1e2 100644 --- a/ent/roundstats_create.go +++ b/ent/roundstats_create.go @@ -134,16 +134,16 @@ func (rsc *RoundStatsCreate) ExecX(ctx context.Context) { // check runs all checks and user-defined validators on the builder. func (rsc *RoundStatsCreate) check() error { if _, ok := rsc.mutation.Round(); !ok { - return &ValidationError{Name: "round", err: errors.New(`ent: missing required field "round"`)} + return &ValidationError{Name: "round", err: errors.New(`ent: missing required field "RoundStats.round"`)} } if _, ok := rsc.mutation.Bank(); !ok { - return &ValidationError{Name: "bank", err: errors.New(`ent: missing required field "bank"`)} + return &ValidationError{Name: "bank", err: errors.New(`ent: missing required field "RoundStats.bank"`)} } if _, ok := rsc.mutation.Equipment(); !ok { - return &ValidationError{Name: "equipment", err: errors.New(`ent: missing required field "equipment"`)} + return &ValidationError{Name: "equipment", err: errors.New(`ent: missing required field "RoundStats.equipment"`)} } if _, ok := rsc.mutation.Spent(); !ok { - return &ValidationError{Name: "spent", err: errors.New(`ent: missing required field "spent"`)} + return &ValidationError{Name: "spent", err: errors.New(`ent: missing required field "RoundStats.spent"`)} } return nil } diff --git a/ent/roundstats_query.go b/ent/roundstats_query.go index 5fc9fda..a7cb7cd 100644 --- a/ent/roundstats_query.go +++ b/ent/roundstats_query.go @@ -422,6 +422,10 @@ func (rsq *RoundStatsQuery) sqlCount(ctx context.Context) (int, error) { if len(rsq.modifiers) > 0 { _spec.Modifiers = rsq.modifiers } + _spec.Node.Columns = rsq.fields + if len(rsq.fields) > 0 { + _spec.Unique = rsq.unique != nil && *rsq.unique + } return sqlgraph.CountNodes(ctx, rsq.driver, _spec) } @@ -493,6 +497,9 @@ func (rsq *RoundStatsQuery) sqlQuery(ctx context.Context) *sql.Selector { selector = rsq.sql selector.Select(selector.Columns(columns...)...) } + if rsq.unique != nil && *rsq.unique { + selector.Distinct() + } for _, m := range rsq.modifiers { m(selector) } @@ -780,9 +787,7 @@ func (rsgb *RoundStatsGroupBy) sqlQuery() *sql.Selector { for _, f := range rsgb.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(rsgb.fields...)...) diff --git a/ent/roundstats_update.go b/ent/roundstats_update.go index b88dd0c..89d3363 100644 --- a/ent/roundstats_update.go +++ b/ent/roundstats_update.go @@ -7,6 +7,7 @@ import ( "csgowtfd/ent/matchplayer" "csgowtfd/ent/predicate" "csgowtfd/ent/roundstats" + "errors" "fmt" "entgo.io/ent/dialect/sql" @@ -35,7 +36,7 @@ func (rsu *RoundStatsUpdate) SetRound(u uint) *RoundStatsUpdate { } // AddRound adds u to the "round" field. -func (rsu *RoundStatsUpdate) AddRound(u uint) *RoundStatsUpdate { +func (rsu *RoundStatsUpdate) AddRound(u int) *RoundStatsUpdate { rsu.mutation.AddRound(u) return rsu } @@ -48,7 +49,7 @@ func (rsu *RoundStatsUpdate) SetBank(u uint) *RoundStatsUpdate { } // AddBank adds u to the "bank" field. -func (rsu *RoundStatsUpdate) AddBank(u uint) *RoundStatsUpdate { +func (rsu *RoundStatsUpdate) AddBank(u int) *RoundStatsUpdate { rsu.mutation.AddBank(u) return rsu } @@ -61,7 +62,7 @@ func (rsu *RoundStatsUpdate) SetEquipment(u uint) *RoundStatsUpdate { } // AddEquipment adds u to the "equipment" field. -func (rsu *RoundStatsUpdate) AddEquipment(u uint) *RoundStatsUpdate { +func (rsu *RoundStatsUpdate) AddEquipment(u int) *RoundStatsUpdate { rsu.mutation.AddEquipment(u) return rsu } @@ -74,7 +75,7 @@ func (rsu *RoundStatsUpdate) SetSpent(u uint) *RoundStatsUpdate { } // AddSpent adds u to the "spent" field. -func (rsu *RoundStatsUpdate) AddSpent(u uint) *RoundStatsUpdate { +func (rsu *RoundStatsUpdate) AddSpent(u int) *RoundStatsUpdate { rsu.mutation.AddSpent(u) return rsu } @@ -299,7 +300,7 @@ func (rsuo *RoundStatsUpdateOne) SetRound(u uint) *RoundStatsUpdateOne { } // AddRound adds u to the "round" field. -func (rsuo *RoundStatsUpdateOne) AddRound(u uint) *RoundStatsUpdateOne { +func (rsuo *RoundStatsUpdateOne) AddRound(u int) *RoundStatsUpdateOne { rsuo.mutation.AddRound(u) return rsuo } @@ -312,7 +313,7 @@ func (rsuo *RoundStatsUpdateOne) SetBank(u uint) *RoundStatsUpdateOne { } // AddBank adds u to the "bank" field. -func (rsuo *RoundStatsUpdateOne) AddBank(u uint) *RoundStatsUpdateOne { +func (rsuo *RoundStatsUpdateOne) AddBank(u int) *RoundStatsUpdateOne { rsuo.mutation.AddBank(u) return rsuo } @@ -325,7 +326,7 @@ func (rsuo *RoundStatsUpdateOne) SetEquipment(u uint) *RoundStatsUpdateOne { } // AddEquipment adds u to the "equipment" field. -func (rsuo *RoundStatsUpdateOne) AddEquipment(u uint) *RoundStatsUpdateOne { +func (rsuo *RoundStatsUpdateOne) AddEquipment(u int) *RoundStatsUpdateOne { rsuo.mutation.AddEquipment(u) return rsuo } @@ -338,7 +339,7 @@ func (rsuo *RoundStatsUpdateOne) SetSpent(u uint) *RoundStatsUpdateOne { } // AddSpent adds u to the "spent" field. -func (rsuo *RoundStatsUpdateOne) AddSpent(u uint) *RoundStatsUpdateOne { +func (rsuo *RoundStatsUpdateOne) AddSpent(u int) *RoundStatsUpdateOne { rsuo.mutation.AddSpent(u) return rsuo } @@ -447,7 +448,7 @@ func (rsuo *RoundStatsUpdateOne) sqlSave(ctx context.Context) (_node *RoundStats } id, ok := rsuo.mutation.ID() if !ok { - return nil, &ValidationError{Name: "ID", err: fmt.Errorf("missing RoundStats.ID for update")} + return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "RoundStats.id" for update`)} } _spec.Node.ID.Value = id if fields := rsuo.fields; len(fields) > 0 { diff --git a/ent/runtime/runtime.go b/ent/runtime/runtime.go index 965c8bb..4417d09 100644 --- a/ent/runtime/runtime.go +++ b/ent/runtime/runtime.go @@ -5,6 +5,6 @@ package runtime // The schema-stitching logic is generated in csgowtfd/ent/runtime.go const ( - Version = "v0.9.1" // Version of ent codegen. - Sum = "h1:IG8andyeD79GG24U8Q+1Y45hQXj6gY5evSBcva5gtBk=" // Sum of ent codegen. + Version = "v0.10.0" // Version of ent codegen. + Sum = "h1:9cBomE1fh+WX34DPYQL7tDNAIvhKa3tXvwxuLyhYCMo=" // Sum of ent codegen. ) diff --git a/ent/schema/match.go b/ent/schema/match.go index 883b50c..bb66e62 100644 --- a/ent/schema/match.go +++ b/ent/schema/match.go @@ -27,6 +27,7 @@ func (Match) Fields() []ent.Field { field.Bool("demo_parsed").Default(false), field.Bool("vac_present").Default(false), field.Bool("gameban_present").Default(false), + field.Bytes("decryption_key").Optional(), } } diff --git a/ent/schema/matchplayer.go b/ent/schema/matchplayer.go index ff432dd..b943ccf 100644 --- a/ent/schema/matchplayer.go +++ b/ent/schema/matchplayer.go @@ -57,5 +57,6 @@ func (MatchPlayer) Edges() []ent.Edge { edge.To("weapon_stats", Weapon.Type), edge.To("round_stats", RoundStats.Type), edge.To("spray", Spray.Type), + edge.To("messages", Messages.Type), } } diff --git a/ent/schema/messages.go b/ent/schema/messages.go new file mode 100644 index 0000000..5c0d2cb --- /dev/null +++ b/ent/schema/messages.go @@ -0,0 +1,27 @@ +package schema + +import ( + "entgo.io/ent" + "entgo.io/ent/schema/edge" + "entgo.io/ent/schema/field" +) + +// Messages holds the schema definition for the Messages entity. +type Messages struct { + ent.Schema +} + +// Fields of the Messages. +func (Messages) Fields() []ent.Field { + return []ent.Field{ + field.Text("message"), + field.Bool("all_chat"), + } +} + +// Edges of the Messages. +func (Messages) Edges() []ent.Edge { + return []ent.Edge{ + edge.From("match_player", MatchPlayer.Type).Ref("messages").Unique(), + } +} diff --git a/ent/spray_create.go b/ent/spray_create.go index 025bfee..0d471cb 100644 --- a/ent/spray_create.go +++ b/ent/spray_create.go @@ -122,10 +122,10 @@ func (sc *SprayCreate) ExecX(ctx context.Context) { // check runs all checks and user-defined validators on the builder. func (sc *SprayCreate) check() error { if _, ok := sc.mutation.Weapon(); !ok { - return &ValidationError{Name: "weapon", err: errors.New(`ent: missing required field "weapon"`)} + return &ValidationError{Name: "weapon", err: errors.New(`ent: missing required field "Spray.weapon"`)} } if _, ok := sc.mutation.Spray(); !ok { - return &ValidationError{Name: "spray", err: errors.New(`ent: missing required field "spray"`)} + return &ValidationError{Name: "spray", err: errors.New(`ent: missing required field "Spray.spray"`)} } return nil } diff --git a/ent/spray_query.go b/ent/spray_query.go index d703af5..dc57b7a 100644 --- a/ent/spray_query.go +++ b/ent/spray_query.go @@ -422,6 +422,10 @@ 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 + } return sqlgraph.CountNodes(ctx, sq.driver, _spec) } @@ -493,6 +497,9 @@ func (sq *SprayQuery) sqlQuery(ctx context.Context) *sql.Selector { selector = sq.sql selector.Select(selector.Columns(columns...)...) } + if sq.unique != nil && *sq.unique { + selector.Distinct() + } for _, m := range sq.modifiers { m(selector) } @@ -780,9 +787,7 @@ func (sgb *SprayGroupBy) sqlQuery() *sql.Selector { for _, f := range sgb.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(sgb.fields...)...) diff --git a/ent/spray_update.go b/ent/spray_update.go index 1da037b..d2e03cb 100644 --- a/ent/spray_update.go +++ b/ent/spray_update.go @@ -7,6 +7,7 @@ import ( "csgowtfd/ent/matchplayer" "csgowtfd/ent/predicate" "csgowtfd/ent/spray" + "errors" "fmt" "entgo.io/ent/dialect/sql" @@ -346,7 +347,7 @@ func (suo *SprayUpdateOne) sqlSave(ctx context.Context) (_node *Spray, err error } id, ok := suo.mutation.ID() if !ok { - return nil, &ValidationError{Name: "ID", err: fmt.Errorf("missing Spray.ID for update")} + return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Spray.id" for update`)} } _spec.Node.ID.Value = id if fields := suo.fields; len(fields) > 0 { diff --git a/ent/tx.go b/ent/tx.go index 6630e78..455b1a9 100644 --- a/ent/tx.go +++ b/ent/tx.go @@ -16,6 +16,8 @@ type Tx struct { Match *MatchClient // MatchPlayer is the client for interacting with the MatchPlayer builders. MatchPlayer *MatchPlayerClient + // Messages is the client for interacting with the Messages builders. + Messages *MessagesClient // Player is the client for interacting with the Player builders. Player *PlayerClient // RoundStats is the client for interacting with the RoundStats builders. @@ -40,7 +42,7 @@ type Tx struct { } type ( - // Committer is the interface that wraps the Committer method. + // Committer is the interface that wraps the Commit method. Committer interface { Commit(context.Context, *Tx) error } @@ -54,7 +56,7 @@ type ( // and returns a Committer. For example: // // hook := func(next ent.Committer) ent.Committer { - // return ent.CommitFunc(func(context.Context, tx *ent.Tx) error { + // return ent.CommitFunc(func(ctx context.Context, tx *ent.Tx) error { // // Do some stuff before. // if err := next.Commit(ctx, tx); err != nil { // return err @@ -95,7 +97,7 @@ func (tx *Tx) OnCommit(f CommitHook) { } type ( - // Rollbacker is the interface that wraps the Rollbacker method. + // Rollbacker is the interface that wraps the Rollback method. Rollbacker interface { Rollback(context.Context, *Tx) error } @@ -109,7 +111,7 @@ type ( // and returns a Rollbacker. For example: // // hook := func(next ent.Rollbacker) ent.Rollbacker { - // return ent.RollbackFunc(func(context.Context, tx *ent.Tx) error { + // return ent.RollbackFunc(func(ctx context.Context, tx *ent.Tx) error { // // Do some stuff before. // if err := next.Rollback(ctx, tx); err != nil { // return err @@ -161,6 +163,7 @@ func (tx *Tx) Client() *Client { func (tx *Tx) init() { tx.Match = NewMatchClient(tx.config) tx.MatchPlayer = NewMatchPlayerClient(tx.config) + tx.Messages = NewMessagesClient(tx.config) tx.Player = NewPlayerClient(tx.config) tx.RoundStats = NewRoundStatsClient(tx.config) tx.Spray = NewSprayClient(tx.config) diff --git a/ent/weapon_create.go b/ent/weapon_create.go index 24e339c..2867bcb 100644 --- a/ent/weapon_create.go +++ b/ent/weapon_create.go @@ -134,16 +134,16 @@ func (wc *WeaponCreate) ExecX(ctx context.Context) { // check runs all checks and user-defined validators on the builder. func (wc *WeaponCreate) check() error { if _, ok := wc.mutation.Victim(); !ok { - return &ValidationError{Name: "victim", err: errors.New(`ent: missing required field "victim"`)} + return &ValidationError{Name: "victim", err: errors.New(`ent: missing required field "Weapon.victim"`)} } if _, ok := wc.mutation.Dmg(); !ok { - return &ValidationError{Name: "dmg", err: errors.New(`ent: missing required field "dmg"`)} + return &ValidationError{Name: "dmg", err: errors.New(`ent: missing required field "Weapon.dmg"`)} } if _, ok := wc.mutation.EqType(); !ok { - return &ValidationError{Name: "eq_type", err: errors.New(`ent: missing required field "eq_type"`)} + return &ValidationError{Name: "eq_type", err: errors.New(`ent: missing required field "Weapon.eq_type"`)} } if _, ok := wc.mutation.HitGroup(); !ok { - return &ValidationError{Name: "hit_group", err: errors.New(`ent: missing required field "hit_group"`)} + return &ValidationError{Name: "hit_group", err: errors.New(`ent: missing required field "Weapon.hit_group"`)} } return nil } diff --git a/ent/weapon_query.go b/ent/weapon_query.go index 8783d19..7718d93 100644 --- a/ent/weapon_query.go +++ b/ent/weapon_query.go @@ -422,6 +422,10 @@ 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 + } return sqlgraph.CountNodes(ctx, wq.driver, _spec) } @@ -493,6 +497,9 @@ func (wq *WeaponQuery) sqlQuery(ctx context.Context) *sql.Selector { selector = wq.sql selector.Select(selector.Columns(columns...)...) } + if wq.unique != nil && *wq.unique { + selector.Distinct() + } for _, m := range wq.modifiers { m(selector) } @@ -780,9 +787,7 @@ func (wgb *WeaponGroupBy) sqlQuery() *sql.Selector { for _, f := range wgb.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(wgb.fields...)...) diff --git a/ent/weapon_update.go b/ent/weapon_update.go index 1d9cd25..1617ba3 100644 --- a/ent/weapon_update.go +++ b/ent/weapon_update.go @@ -7,6 +7,7 @@ import ( "csgowtfd/ent/matchplayer" "csgowtfd/ent/predicate" "csgowtfd/ent/weapon" + "errors" "fmt" "entgo.io/ent/dialect/sql" @@ -35,7 +36,7 @@ func (wu *WeaponUpdate) SetVictim(u uint64) *WeaponUpdate { } // AddVictim adds u to the "victim" field. -func (wu *WeaponUpdate) AddVictim(u uint64) *WeaponUpdate { +func (wu *WeaponUpdate) AddVictim(u int64) *WeaponUpdate { wu.mutation.AddVictim(u) return wu } @@ -48,7 +49,7 @@ func (wu *WeaponUpdate) SetDmg(u uint) *WeaponUpdate { } // AddDmg adds u to the "dmg" field. -func (wu *WeaponUpdate) AddDmg(u uint) *WeaponUpdate { +func (wu *WeaponUpdate) AddDmg(u int) *WeaponUpdate { wu.mutation.AddDmg(u) return wu } @@ -299,7 +300,7 @@ func (wuo *WeaponUpdateOne) SetVictim(u uint64) *WeaponUpdateOne { } // AddVictim adds u to the "victim" field. -func (wuo *WeaponUpdateOne) AddVictim(u uint64) *WeaponUpdateOne { +func (wuo *WeaponUpdateOne) AddVictim(u int64) *WeaponUpdateOne { wuo.mutation.AddVictim(u) return wuo } @@ -312,7 +313,7 @@ func (wuo *WeaponUpdateOne) SetDmg(u uint) *WeaponUpdateOne { } // AddDmg adds u to the "dmg" field. -func (wuo *WeaponUpdateOne) AddDmg(u uint) *WeaponUpdateOne { +func (wuo *WeaponUpdateOne) AddDmg(u int) *WeaponUpdateOne { wuo.mutation.AddDmg(u) return wuo } @@ -447,7 +448,7 @@ func (wuo *WeaponUpdateOne) sqlSave(ctx context.Context) (_node *Weapon, err err } id, ok := wuo.mutation.ID() if !ok { - return nil, &ValidationError{Name: "ID", err: fmt.Errorf("missing Weapon.ID for update")} + return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Weapon.id" for update`)} } _spec.Node.ID.Value = id if fields := wuo.fields; len(fields) > 0 { diff --git a/go.mod b/go.mod index 190b105..9999c42 100644 --- a/go.mod +++ b/go.mod @@ -29,6 +29,7 @@ require ( github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf // indirect github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect github.com/felixge/httpsnoop v1.0.2 // indirect + github.com/fsnotify/fsnotify v1.5.1 // indirect github.com/go-openapi/inflect v0.19.0 // indirect github.com/gogo/protobuf v1.3.2 // indirect github.com/google/go-cmp v0.5.7 // indirect @@ -42,6 +43,7 @@ require ( github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b // indirect github.com/jackc/pgtype v1.9.1 // indirect github.com/klauspost/compress v1.14.2 // indirect + github.com/kr/pretty v0.2.0 // indirect github.com/markus-wa/go-unassert v0.1.2 // indirect github.com/markus-wa/gobitread v0.2.3 // indirect github.com/markus-wa/godispatch v1.4.1 // indirect diff --git a/go.sum b/go.sum index d0c91e6..a239c5f 100644 --- a/go.sum +++ b/go.sum @@ -88,8 +88,9 @@ github.com/felixge/httpsnoop v1.0.2/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSw github.com/franela/goblin v0.0.0-20200105215937-c9ffbefa60db/go.mod h1:7dvUGVsVBjqR7JHJk0brhHOZYGmfBYOrK0ZhYMEtBr4= github.com/franela/goreq v0.0.0-20171204163338-bcd34c9993f8/go.mod h1:ZhphrRTfi2rbfLwlschooIH4+wKKDR4Pdxhh+TRoA20= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= -github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4= github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= +github.com/fsnotify/fsnotify v1.5.1 h1:mZcQUHVQUQWoPXXtuf9yuEXKudkV2sx1E06UadKWpgI= +github.com/fsnotify/fsnotify v1.5.1/go.mod h1:T3375wBYaZdLLcVNkcVbzGHY7f1l/uK5T5Ai1i3InKU= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/go-gl/gl v0.0.0-20180407155706-68e253793080/go.mod h1:482civXOzJJCPzJ4ZOX/pwvXBWSnzD4OKMdH4ClKGbk= github.com/go-gl/glfw v0.0.0-20180426074136-46a8d530c326/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= @@ -261,8 +262,9 @@ github.com/klauspost/compress v1.14.2/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47e github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= -github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pretty v0.2.0 h1:s5hAObm+yFO5uHYt5dYjxi2rXrsnmRpJx4OYvIWUaQs= +github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/pty v1.1.8/go.mod h1:O1sed60cT9XZ5uDucP5qwvh+TE3NnUj51EiZO/lmSfw= github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= @@ -581,6 +583,7 @@ golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220128215802-99c3d69c2c27 h1:XDXtA5hveEEV8JB2l7nhMTp3t3cHp9ZpwcdjqyEWLlo= golang.org/x/sys v0.0.0-20220128215802-99c3d69c2c27/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=