added chat messages

This commit is contained in:
2022-01-29 19:32:13 +01:00
parent 2e6c94de81
commit b036275665
48 changed files with 4167 additions and 353 deletions

View File

@@ -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)

View File

@@ -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))

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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)

View File

@@ -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()
}

View File

@@ -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 (

View File

@@ -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) {

View File

@@ -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,

View File

@@ -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...)...)

View File

@@ -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,

View File

@@ -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.

View File

@@ -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.

View File

@@ -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) {

View File

@@ -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
}

View File

@@ -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...)...)

View File

@@ -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

153
ent/messages.go Normal file
View File

@@ -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
}
}

53
ent/messages/messages.go Normal file
View File

@@ -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
}

292
ent/messages/where.go Normal file
View File

@@ -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())
})
}

277
ent/messages_create.go Normal file
View File

@@ -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)
}
}

111
ent/messages_delete.go Normal file
View File

@@ -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)
}

1021
ent/messages_query.go Normal file

File diff suppressed because it is too large Load Diff

412
ent/messages_update.go Normal file
View File

@@ -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
}

View File

@@ -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.

View File

@@ -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

File diff suppressed because it is too large Load Diff

View File

@@ -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
}

View File

@@ -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...)...)

View File

@@ -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 {

View File

@@ -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)

View File

@@ -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
}

View File

@@ -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...)...)

View File

@@ -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 {

View File

@@ -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.
)

View File

@@ -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(),
}
}

View File

@@ -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),
}
}

27
ent/schema/messages.go Normal file
View File

@@ -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(),
}
}

View File

@@ -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
}

View File

@@ -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...)...)

View File

@@ -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 {

View File

@@ -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)

View File

@@ -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
}

View File

@@ -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...)...)

View File

@@ -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 {

2
go.mod
View File

@@ -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

7
go.sum
View File

@@ -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=