// Code generated by ent, DO NOT EDIT. package ent import ( "context" "errors" "fmt" "time" "wechat-api/ent/predicate" "wechat-api/ent/usagetotal" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" ) // UsageTotalUpdate is the builder for updating UsageTotal entities. type UsageTotalUpdate struct { config hooks []Hook mutation *UsageTotalMutation } // Where appends a list predicates to the UsageTotalUpdate builder. func (utu *UsageTotalUpdate) Where(ps ...predicate.UsageTotal) *UsageTotalUpdate { utu.mutation.Where(ps...) return utu } // SetUpdatedAt sets the "updated_at" field. func (utu *UsageTotalUpdate) SetUpdatedAt(t time.Time) *UsageTotalUpdate { utu.mutation.SetUpdatedAt(t) return utu } // SetStatus sets the "status" field. func (utu *UsageTotalUpdate) SetStatus(u uint8) *UsageTotalUpdate { utu.mutation.ResetStatus() utu.mutation.SetStatus(u) return utu } // SetNillableStatus sets the "status" field if the given value is not nil. func (utu *UsageTotalUpdate) SetNillableStatus(u *uint8) *UsageTotalUpdate { if u != nil { utu.SetStatus(*u) } return utu } // AddStatus adds u to the "status" field. func (utu *UsageTotalUpdate) AddStatus(u int8) *UsageTotalUpdate { utu.mutation.AddStatus(u) return utu } // ClearStatus clears the value of the "status" field. func (utu *UsageTotalUpdate) ClearStatus() *UsageTotalUpdate { utu.mutation.ClearStatus() return utu } // SetType sets the "type" field. func (utu *UsageTotalUpdate) SetType(i int) *UsageTotalUpdate { utu.mutation.ResetType() utu.mutation.SetType(i) return utu } // SetNillableType sets the "type" field if the given value is not nil. func (utu *UsageTotalUpdate) SetNillableType(i *int) *UsageTotalUpdate { if i != nil { utu.SetType(*i) } return utu } // AddType adds i to the "type" field. func (utu *UsageTotalUpdate) AddType(i int) *UsageTotalUpdate { utu.mutation.AddType(i) return utu } // ClearType clears the value of the "type" field. func (utu *UsageTotalUpdate) ClearType() *UsageTotalUpdate { utu.mutation.ClearType() return utu } // SetBotID sets the "bot_id" field. func (utu *UsageTotalUpdate) SetBotID(s string) *UsageTotalUpdate { utu.mutation.SetBotID(s) return utu } // SetNillableBotID sets the "bot_id" field if the given value is not nil. func (utu *UsageTotalUpdate) SetNillableBotID(s *string) *UsageTotalUpdate { if s != nil { utu.SetBotID(*s) } return utu } // SetTotalTokens sets the "total_tokens" field. func (utu *UsageTotalUpdate) SetTotalTokens(u uint64) *UsageTotalUpdate { utu.mutation.ResetTotalTokens() utu.mutation.SetTotalTokens(u) return utu } // SetNillableTotalTokens sets the "total_tokens" field if the given value is not nil. func (utu *UsageTotalUpdate) SetNillableTotalTokens(u *uint64) *UsageTotalUpdate { if u != nil { utu.SetTotalTokens(*u) } return utu } // AddTotalTokens adds u to the "total_tokens" field. func (utu *UsageTotalUpdate) AddTotalTokens(u int64) *UsageTotalUpdate { utu.mutation.AddTotalTokens(u) return utu } // ClearTotalTokens clears the value of the "total_tokens" field. func (utu *UsageTotalUpdate) ClearTotalTokens() *UsageTotalUpdate { utu.mutation.ClearTotalTokens() return utu } // SetStartIndex sets the "start_index" field. func (utu *UsageTotalUpdate) SetStartIndex(u uint64) *UsageTotalUpdate { utu.mutation.ResetStartIndex() utu.mutation.SetStartIndex(u) return utu } // SetNillableStartIndex sets the "start_index" field if the given value is not nil. func (utu *UsageTotalUpdate) SetNillableStartIndex(u *uint64) *UsageTotalUpdate { if u != nil { utu.SetStartIndex(*u) } return utu } // AddStartIndex adds u to the "start_index" field. func (utu *UsageTotalUpdate) AddStartIndex(u int64) *UsageTotalUpdate { utu.mutation.AddStartIndex(u) return utu } // ClearStartIndex clears the value of the "start_index" field. func (utu *UsageTotalUpdate) ClearStartIndex() *UsageTotalUpdate { utu.mutation.ClearStartIndex() return utu } // SetEndIndex sets the "end_index" field. func (utu *UsageTotalUpdate) SetEndIndex(u uint64) *UsageTotalUpdate { utu.mutation.ResetEndIndex() utu.mutation.SetEndIndex(u) return utu } // SetNillableEndIndex sets the "end_index" field if the given value is not nil. func (utu *UsageTotalUpdate) SetNillableEndIndex(u *uint64) *UsageTotalUpdate { if u != nil { utu.SetEndIndex(*u) } return utu } // AddEndIndex adds u to the "end_index" field. func (utu *UsageTotalUpdate) AddEndIndex(u int64) *UsageTotalUpdate { utu.mutation.AddEndIndex(u) return utu } // ClearEndIndex clears the value of the "end_index" field. func (utu *UsageTotalUpdate) ClearEndIndex() *UsageTotalUpdate { utu.mutation.ClearEndIndex() return utu } // SetOrganizationID sets the "organization_id" field. func (utu *UsageTotalUpdate) SetOrganizationID(u uint64) *UsageTotalUpdate { utu.mutation.ResetOrganizationID() utu.mutation.SetOrganizationID(u) return utu } // SetNillableOrganizationID sets the "organization_id" field if the given value is not nil. func (utu *UsageTotalUpdate) SetNillableOrganizationID(u *uint64) *UsageTotalUpdate { if u != nil { utu.SetOrganizationID(*u) } return utu } // AddOrganizationID adds u to the "organization_id" field. func (utu *UsageTotalUpdate) AddOrganizationID(u int64) *UsageTotalUpdate { utu.mutation.AddOrganizationID(u) return utu } // ClearOrganizationID clears the value of the "organization_id" field. func (utu *UsageTotalUpdate) ClearOrganizationID() *UsageTotalUpdate { utu.mutation.ClearOrganizationID() return utu } // Mutation returns the UsageTotalMutation object of the builder. func (utu *UsageTotalUpdate) Mutation() *UsageTotalMutation { return utu.mutation } // Save executes the query and returns the number of nodes affected by the update operation. func (utu *UsageTotalUpdate) Save(ctx context.Context) (int, error) { utu.defaults() return withHooks(ctx, utu.sqlSave, utu.mutation, utu.hooks) } // SaveX is like Save, but panics if an error occurs. func (utu *UsageTotalUpdate) SaveX(ctx context.Context) int { affected, err := utu.Save(ctx) if err != nil { panic(err) } return affected } // Exec executes the query. func (utu *UsageTotalUpdate) Exec(ctx context.Context) error { _, err := utu.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (utu *UsageTotalUpdate) ExecX(ctx context.Context) { if err := utu.Exec(ctx); err != nil { panic(err) } } // defaults sets the default values of the builder before save. func (utu *UsageTotalUpdate) defaults() { if _, ok := utu.mutation.UpdatedAt(); !ok { v := usagetotal.UpdateDefaultUpdatedAt() utu.mutation.SetUpdatedAt(v) } } func (utu *UsageTotalUpdate) sqlSave(ctx context.Context) (n int, err error) { _spec := sqlgraph.NewUpdateSpec(usagetotal.Table, usagetotal.Columns, sqlgraph.NewFieldSpec(usagetotal.FieldID, field.TypeUint64)) if ps := utu.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { ps[i](selector) } } } if value, ok := utu.mutation.UpdatedAt(); ok { _spec.SetField(usagetotal.FieldUpdatedAt, field.TypeTime, value) } if value, ok := utu.mutation.Status(); ok { _spec.SetField(usagetotal.FieldStatus, field.TypeUint8, value) } if value, ok := utu.mutation.AddedStatus(); ok { _spec.AddField(usagetotal.FieldStatus, field.TypeUint8, value) } if utu.mutation.StatusCleared() { _spec.ClearField(usagetotal.FieldStatus, field.TypeUint8) } if value, ok := utu.mutation.GetType(); ok { _spec.SetField(usagetotal.FieldType, field.TypeInt, value) } if value, ok := utu.mutation.AddedType(); ok { _spec.AddField(usagetotal.FieldType, field.TypeInt, value) } if utu.mutation.TypeCleared() { _spec.ClearField(usagetotal.FieldType, field.TypeInt) } if value, ok := utu.mutation.BotID(); ok { _spec.SetField(usagetotal.FieldBotID, field.TypeString, value) } if value, ok := utu.mutation.TotalTokens(); ok { _spec.SetField(usagetotal.FieldTotalTokens, field.TypeUint64, value) } if value, ok := utu.mutation.AddedTotalTokens(); ok { _spec.AddField(usagetotal.FieldTotalTokens, field.TypeUint64, value) } if utu.mutation.TotalTokensCleared() { _spec.ClearField(usagetotal.FieldTotalTokens, field.TypeUint64) } if value, ok := utu.mutation.StartIndex(); ok { _spec.SetField(usagetotal.FieldStartIndex, field.TypeUint64, value) } if value, ok := utu.mutation.AddedStartIndex(); ok { _spec.AddField(usagetotal.FieldStartIndex, field.TypeUint64, value) } if utu.mutation.StartIndexCleared() { _spec.ClearField(usagetotal.FieldStartIndex, field.TypeUint64) } if value, ok := utu.mutation.EndIndex(); ok { _spec.SetField(usagetotal.FieldEndIndex, field.TypeUint64, value) } if value, ok := utu.mutation.AddedEndIndex(); ok { _spec.AddField(usagetotal.FieldEndIndex, field.TypeUint64, value) } if utu.mutation.EndIndexCleared() { _spec.ClearField(usagetotal.FieldEndIndex, field.TypeUint64) } if value, ok := utu.mutation.OrganizationID(); ok { _spec.SetField(usagetotal.FieldOrganizationID, field.TypeUint64, value) } if value, ok := utu.mutation.AddedOrganizationID(); ok { _spec.AddField(usagetotal.FieldOrganizationID, field.TypeUint64, value) } if utu.mutation.OrganizationIDCleared() { _spec.ClearField(usagetotal.FieldOrganizationID, field.TypeUint64) } if n, err = sqlgraph.UpdateNodes(ctx, utu.driver, _spec); err != nil { if _, ok := err.(*sqlgraph.NotFoundError); ok { err = &NotFoundError{usagetotal.Label} } else if sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } return 0, err } utu.mutation.done = true return n, nil } // UsageTotalUpdateOne is the builder for updating a single UsageTotal entity. type UsageTotalUpdateOne struct { config fields []string hooks []Hook mutation *UsageTotalMutation } // SetUpdatedAt sets the "updated_at" field. func (utuo *UsageTotalUpdateOne) SetUpdatedAt(t time.Time) *UsageTotalUpdateOne { utuo.mutation.SetUpdatedAt(t) return utuo } // SetStatus sets the "status" field. func (utuo *UsageTotalUpdateOne) SetStatus(u uint8) *UsageTotalUpdateOne { utuo.mutation.ResetStatus() utuo.mutation.SetStatus(u) return utuo } // SetNillableStatus sets the "status" field if the given value is not nil. func (utuo *UsageTotalUpdateOne) SetNillableStatus(u *uint8) *UsageTotalUpdateOne { if u != nil { utuo.SetStatus(*u) } return utuo } // AddStatus adds u to the "status" field. func (utuo *UsageTotalUpdateOne) AddStatus(u int8) *UsageTotalUpdateOne { utuo.mutation.AddStatus(u) return utuo } // ClearStatus clears the value of the "status" field. func (utuo *UsageTotalUpdateOne) ClearStatus() *UsageTotalUpdateOne { utuo.mutation.ClearStatus() return utuo } // SetType sets the "type" field. func (utuo *UsageTotalUpdateOne) SetType(i int) *UsageTotalUpdateOne { utuo.mutation.ResetType() utuo.mutation.SetType(i) return utuo } // SetNillableType sets the "type" field if the given value is not nil. func (utuo *UsageTotalUpdateOne) SetNillableType(i *int) *UsageTotalUpdateOne { if i != nil { utuo.SetType(*i) } return utuo } // AddType adds i to the "type" field. func (utuo *UsageTotalUpdateOne) AddType(i int) *UsageTotalUpdateOne { utuo.mutation.AddType(i) return utuo } // ClearType clears the value of the "type" field. func (utuo *UsageTotalUpdateOne) ClearType() *UsageTotalUpdateOne { utuo.mutation.ClearType() return utuo } // SetBotID sets the "bot_id" field. func (utuo *UsageTotalUpdateOne) SetBotID(s string) *UsageTotalUpdateOne { utuo.mutation.SetBotID(s) return utuo } // SetNillableBotID sets the "bot_id" field if the given value is not nil. func (utuo *UsageTotalUpdateOne) SetNillableBotID(s *string) *UsageTotalUpdateOne { if s != nil { utuo.SetBotID(*s) } return utuo } // SetTotalTokens sets the "total_tokens" field. func (utuo *UsageTotalUpdateOne) SetTotalTokens(u uint64) *UsageTotalUpdateOne { utuo.mutation.ResetTotalTokens() utuo.mutation.SetTotalTokens(u) return utuo } // SetNillableTotalTokens sets the "total_tokens" field if the given value is not nil. func (utuo *UsageTotalUpdateOne) SetNillableTotalTokens(u *uint64) *UsageTotalUpdateOne { if u != nil { utuo.SetTotalTokens(*u) } return utuo } // AddTotalTokens adds u to the "total_tokens" field. func (utuo *UsageTotalUpdateOne) AddTotalTokens(u int64) *UsageTotalUpdateOne { utuo.mutation.AddTotalTokens(u) return utuo } // ClearTotalTokens clears the value of the "total_tokens" field. func (utuo *UsageTotalUpdateOne) ClearTotalTokens() *UsageTotalUpdateOne { utuo.mutation.ClearTotalTokens() return utuo } // SetStartIndex sets the "start_index" field. func (utuo *UsageTotalUpdateOne) SetStartIndex(u uint64) *UsageTotalUpdateOne { utuo.mutation.ResetStartIndex() utuo.mutation.SetStartIndex(u) return utuo } // SetNillableStartIndex sets the "start_index" field if the given value is not nil. func (utuo *UsageTotalUpdateOne) SetNillableStartIndex(u *uint64) *UsageTotalUpdateOne { if u != nil { utuo.SetStartIndex(*u) } return utuo } // AddStartIndex adds u to the "start_index" field. func (utuo *UsageTotalUpdateOne) AddStartIndex(u int64) *UsageTotalUpdateOne { utuo.mutation.AddStartIndex(u) return utuo } // ClearStartIndex clears the value of the "start_index" field. func (utuo *UsageTotalUpdateOne) ClearStartIndex() *UsageTotalUpdateOne { utuo.mutation.ClearStartIndex() return utuo } // SetEndIndex sets the "end_index" field. func (utuo *UsageTotalUpdateOne) SetEndIndex(u uint64) *UsageTotalUpdateOne { utuo.mutation.ResetEndIndex() utuo.mutation.SetEndIndex(u) return utuo } // SetNillableEndIndex sets the "end_index" field if the given value is not nil. func (utuo *UsageTotalUpdateOne) SetNillableEndIndex(u *uint64) *UsageTotalUpdateOne { if u != nil { utuo.SetEndIndex(*u) } return utuo } // AddEndIndex adds u to the "end_index" field. func (utuo *UsageTotalUpdateOne) AddEndIndex(u int64) *UsageTotalUpdateOne { utuo.mutation.AddEndIndex(u) return utuo } // ClearEndIndex clears the value of the "end_index" field. func (utuo *UsageTotalUpdateOne) ClearEndIndex() *UsageTotalUpdateOne { utuo.mutation.ClearEndIndex() return utuo } // SetOrganizationID sets the "organization_id" field. func (utuo *UsageTotalUpdateOne) SetOrganizationID(u uint64) *UsageTotalUpdateOne { utuo.mutation.ResetOrganizationID() utuo.mutation.SetOrganizationID(u) return utuo } // SetNillableOrganizationID sets the "organization_id" field if the given value is not nil. func (utuo *UsageTotalUpdateOne) SetNillableOrganizationID(u *uint64) *UsageTotalUpdateOne { if u != nil { utuo.SetOrganizationID(*u) } return utuo } // AddOrganizationID adds u to the "organization_id" field. func (utuo *UsageTotalUpdateOne) AddOrganizationID(u int64) *UsageTotalUpdateOne { utuo.mutation.AddOrganizationID(u) return utuo } // ClearOrganizationID clears the value of the "organization_id" field. func (utuo *UsageTotalUpdateOne) ClearOrganizationID() *UsageTotalUpdateOne { utuo.mutation.ClearOrganizationID() return utuo } // Mutation returns the UsageTotalMutation object of the builder. func (utuo *UsageTotalUpdateOne) Mutation() *UsageTotalMutation { return utuo.mutation } // Where appends a list predicates to the UsageTotalUpdate builder. func (utuo *UsageTotalUpdateOne) Where(ps ...predicate.UsageTotal) *UsageTotalUpdateOne { utuo.mutation.Where(ps...) return utuo } // Select allows selecting one or more fields (columns) of the returned entity. // The default is selecting all fields defined in the entity schema. func (utuo *UsageTotalUpdateOne) Select(field string, fields ...string) *UsageTotalUpdateOne { utuo.fields = append([]string{field}, fields...) return utuo } // Save executes the query and returns the updated UsageTotal entity. func (utuo *UsageTotalUpdateOne) Save(ctx context.Context) (*UsageTotal, error) { utuo.defaults() return withHooks(ctx, utuo.sqlSave, utuo.mutation, utuo.hooks) } // SaveX is like Save, but panics if an error occurs. func (utuo *UsageTotalUpdateOne) SaveX(ctx context.Context) *UsageTotal { node, err := utuo.Save(ctx) if err != nil { panic(err) } return node } // Exec executes the query on the entity. func (utuo *UsageTotalUpdateOne) Exec(ctx context.Context) error { _, err := utuo.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (utuo *UsageTotalUpdateOne) ExecX(ctx context.Context) { if err := utuo.Exec(ctx); err != nil { panic(err) } } // defaults sets the default values of the builder before save. func (utuo *UsageTotalUpdateOne) defaults() { if _, ok := utuo.mutation.UpdatedAt(); !ok { v := usagetotal.UpdateDefaultUpdatedAt() utuo.mutation.SetUpdatedAt(v) } } func (utuo *UsageTotalUpdateOne) sqlSave(ctx context.Context) (_node *UsageTotal, err error) { _spec := sqlgraph.NewUpdateSpec(usagetotal.Table, usagetotal.Columns, sqlgraph.NewFieldSpec(usagetotal.FieldID, field.TypeUint64)) id, ok := utuo.mutation.ID() if !ok { return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "UsageTotal.id" for update`)} } _spec.Node.ID.Value = id if fields := utuo.fields; len(fields) > 0 { _spec.Node.Columns = make([]string, 0, len(fields)) _spec.Node.Columns = append(_spec.Node.Columns, usagetotal.FieldID) for _, f := range fields { if !usagetotal.ValidColumn(f) { return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} } if f != usagetotal.FieldID { _spec.Node.Columns = append(_spec.Node.Columns, f) } } } if ps := utuo.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { ps[i](selector) } } } if value, ok := utuo.mutation.UpdatedAt(); ok { _spec.SetField(usagetotal.FieldUpdatedAt, field.TypeTime, value) } if value, ok := utuo.mutation.Status(); ok { _spec.SetField(usagetotal.FieldStatus, field.TypeUint8, value) } if value, ok := utuo.mutation.AddedStatus(); ok { _spec.AddField(usagetotal.FieldStatus, field.TypeUint8, value) } if utuo.mutation.StatusCleared() { _spec.ClearField(usagetotal.FieldStatus, field.TypeUint8) } if value, ok := utuo.mutation.GetType(); ok { _spec.SetField(usagetotal.FieldType, field.TypeInt, value) } if value, ok := utuo.mutation.AddedType(); ok { _spec.AddField(usagetotal.FieldType, field.TypeInt, value) } if utuo.mutation.TypeCleared() { _spec.ClearField(usagetotal.FieldType, field.TypeInt) } if value, ok := utuo.mutation.BotID(); ok { _spec.SetField(usagetotal.FieldBotID, field.TypeString, value) } if value, ok := utuo.mutation.TotalTokens(); ok { _spec.SetField(usagetotal.FieldTotalTokens, field.TypeUint64, value) } if value, ok := utuo.mutation.AddedTotalTokens(); ok { _spec.AddField(usagetotal.FieldTotalTokens, field.TypeUint64, value) } if utuo.mutation.TotalTokensCleared() { _spec.ClearField(usagetotal.FieldTotalTokens, field.TypeUint64) } if value, ok := utuo.mutation.StartIndex(); ok { _spec.SetField(usagetotal.FieldStartIndex, field.TypeUint64, value) } if value, ok := utuo.mutation.AddedStartIndex(); ok { _spec.AddField(usagetotal.FieldStartIndex, field.TypeUint64, value) } if utuo.mutation.StartIndexCleared() { _spec.ClearField(usagetotal.FieldStartIndex, field.TypeUint64) } if value, ok := utuo.mutation.EndIndex(); ok { _spec.SetField(usagetotal.FieldEndIndex, field.TypeUint64, value) } if value, ok := utuo.mutation.AddedEndIndex(); ok { _spec.AddField(usagetotal.FieldEndIndex, field.TypeUint64, value) } if utuo.mutation.EndIndexCleared() { _spec.ClearField(usagetotal.FieldEndIndex, field.TypeUint64) } if value, ok := utuo.mutation.OrganizationID(); ok { _spec.SetField(usagetotal.FieldOrganizationID, field.TypeUint64, value) } if value, ok := utuo.mutation.AddedOrganizationID(); ok { _spec.AddField(usagetotal.FieldOrganizationID, field.TypeUint64, value) } if utuo.mutation.OrganizationIDCleared() { _spec.ClearField(usagetotal.FieldOrganizationID, field.TypeUint64) } _node = &UsageTotal{config: utuo.config} _spec.Assign = _node.assignValues _spec.ScanValues = _node.scanValues if err = sqlgraph.UpdateNode(ctx, utuo.driver, _spec); err != nil { if _, ok := err.(*sqlgraph.NotFoundError); ok { err = &NotFoundError{usagetotal.Label} } else if sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } return nil, err } utuo.mutation.done = true return _node, nil }