// Code generated by ent, DO NOT EDIT. package ent import ( "context" "errors" "fmt" "time" "wechat-api/ent/predicate" "wechat-api/ent/xunji" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" ) // XunjiUpdate is the builder for updating Xunji entities. type XunjiUpdate struct { config hooks []Hook mutation *XunjiMutation } // Where appends a list predicates to the XunjiUpdate builder. func (xu *XunjiUpdate) Where(ps ...predicate.Xunji) *XunjiUpdate { xu.mutation.Where(ps...) return xu } // SetUpdatedAt sets the "updated_at" field. func (xu *XunjiUpdate) SetUpdatedAt(t time.Time) *XunjiUpdate { xu.mutation.SetUpdatedAt(t) return xu } // SetStatus sets the "status" field. func (xu *XunjiUpdate) SetStatus(u uint8) *XunjiUpdate { xu.mutation.ResetStatus() xu.mutation.SetStatus(u) return xu } // SetNillableStatus sets the "status" field if the given value is not nil. func (xu *XunjiUpdate) SetNillableStatus(u *uint8) *XunjiUpdate { if u != nil { xu.SetStatus(*u) } return xu } // AddStatus adds u to the "status" field. func (xu *XunjiUpdate) AddStatus(u int8) *XunjiUpdate { xu.mutation.AddStatus(u) return xu } // ClearStatus clears the value of the "status" field. func (xu *XunjiUpdate) ClearStatus() *XunjiUpdate { xu.mutation.ClearStatus() return xu } // SetDeletedAt sets the "deleted_at" field. func (xu *XunjiUpdate) SetDeletedAt(t time.Time) *XunjiUpdate { xu.mutation.SetDeletedAt(t) return xu } // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil. func (xu *XunjiUpdate) SetNillableDeletedAt(t *time.Time) *XunjiUpdate { if t != nil { xu.SetDeletedAt(*t) } return xu } // ClearDeletedAt clears the value of the "deleted_at" field. func (xu *XunjiUpdate) ClearDeletedAt() *XunjiUpdate { xu.mutation.ClearDeletedAt() return xu } // SetAppKey sets the "app_key" field. func (xu *XunjiUpdate) SetAppKey(s string) *XunjiUpdate { xu.mutation.SetAppKey(s) return xu } // SetNillableAppKey sets the "app_key" field if the given value is not nil. func (xu *XunjiUpdate) SetNillableAppKey(s *string) *XunjiUpdate { if s != nil { xu.SetAppKey(*s) } return xu } // ClearAppKey clears the value of the "app_key" field. func (xu *XunjiUpdate) ClearAppKey() *XunjiUpdate { xu.mutation.ClearAppKey() return xu } // SetAppSecret sets the "app_secret" field. func (xu *XunjiUpdate) SetAppSecret(s string) *XunjiUpdate { xu.mutation.SetAppSecret(s) return xu } // SetNillableAppSecret sets the "app_secret" field if the given value is not nil. func (xu *XunjiUpdate) SetNillableAppSecret(s *string) *XunjiUpdate { if s != nil { xu.SetAppSecret(*s) } return xu } // ClearAppSecret clears the value of the "app_secret" field. func (xu *XunjiUpdate) ClearAppSecret() *XunjiUpdate { xu.mutation.ClearAppSecret() return xu } // SetToken sets the "token" field. func (xu *XunjiUpdate) SetToken(s string) *XunjiUpdate { xu.mutation.SetToken(s) return xu } // SetNillableToken sets the "token" field if the given value is not nil. func (xu *XunjiUpdate) SetNillableToken(s *string) *XunjiUpdate { if s != nil { xu.SetToken(*s) } return xu } // ClearToken clears the value of the "token" field. func (xu *XunjiUpdate) ClearToken() *XunjiUpdate { xu.mutation.ClearToken() return xu } // SetEncodingKey sets the "encoding_key" field. func (xu *XunjiUpdate) SetEncodingKey(s string) *XunjiUpdate { xu.mutation.SetEncodingKey(s) return xu } // SetNillableEncodingKey sets the "encoding_key" field if the given value is not nil. func (xu *XunjiUpdate) SetNillableEncodingKey(s *string) *XunjiUpdate { if s != nil { xu.SetEncodingKey(*s) } return xu } // ClearEncodingKey clears the value of the "encoding_key" field. func (xu *XunjiUpdate) ClearEncodingKey() *XunjiUpdate { xu.mutation.ClearEncodingKey() return xu } // SetOrganizationID sets the "organization_id" field. func (xu *XunjiUpdate) SetOrganizationID(u uint64) *XunjiUpdate { xu.mutation.ResetOrganizationID() xu.mutation.SetOrganizationID(u) return xu } // SetNillableOrganizationID sets the "organization_id" field if the given value is not nil. func (xu *XunjiUpdate) SetNillableOrganizationID(u *uint64) *XunjiUpdate { if u != nil { xu.SetOrganizationID(*u) } return xu } // AddOrganizationID adds u to the "organization_id" field. func (xu *XunjiUpdate) AddOrganizationID(u int64) *XunjiUpdate { xu.mutation.AddOrganizationID(u) return xu } // Mutation returns the XunjiMutation object of the builder. func (xu *XunjiUpdate) Mutation() *XunjiMutation { return xu.mutation } // Save executes the query and returns the number of nodes affected by the update operation. func (xu *XunjiUpdate) Save(ctx context.Context) (int, error) { if err := xu.defaults(); err != nil { return 0, err } return withHooks(ctx, xu.sqlSave, xu.mutation, xu.hooks) } // SaveX is like Save, but panics if an error occurs. func (xu *XunjiUpdate) SaveX(ctx context.Context) int { affected, err := xu.Save(ctx) if err != nil { panic(err) } return affected } // Exec executes the query. func (xu *XunjiUpdate) Exec(ctx context.Context) error { _, err := xu.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (xu *XunjiUpdate) ExecX(ctx context.Context) { if err := xu.Exec(ctx); err != nil { panic(err) } } // defaults sets the default values of the builder before save. func (xu *XunjiUpdate) defaults() error { if _, ok := xu.mutation.UpdatedAt(); !ok { if xunji.UpdateDefaultUpdatedAt == nil { return fmt.Errorf("ent: uninitialized xunji.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)") } v := xunji.UpdateDefaultUpdatedAt() xu.mutation.SetUpdatedAt(v) } return nil } // check runs all checks and user-defined validators on the builder. func (xu *XunjiUpdate) check() error { if v, ok := xu.mutation.OrganizationID(); ok { if err := xunji.OrganizationIDValidator(v); err != nil { return &ValidationError{Name: "organization_id", err: fmt.Errorf(`ent: validator failed for field "Xunji.organization_id": %w`, err)} } } return nil } func (xu *XunjiUpdate) sqlSave(ctx context.Context) (n int, err error) { if err := xu.check(); err != nil { return n, err } _spec := sqlgraph.NewUpdateSpec(xunji.Table, xunji.Columns, sqlgraph.NewFieldSpec(xunji.FieldID, field.TypeUint64)) if ps := xu.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { ps[i](selector) } } } if value, ok := xu.mutation.UpdatedAt(); ok { _spec.SetField(xunji.FieldUpdatedAt, field.TypeTime, value) } if value, ok := xu.mutation.Status(); ok { _spec.SetField(xunji.FieldStatus, field.TypeUint8, value) } if value, ok := xu.mutation.AddedStatus(); ok { _spec.AddField(xunji.FieldStatus, field.TypeUint8, value) } if xu.mutation.StatusCleared() { _spec.ClearField(xunji.FieldStatus, field.TypeUint8) } if value, ok := xu.mutation.DeletedAt(); ok { _spec.SetField(xunji.FieldDeletedAt, field.TypeTime, value) } if xu.mutation.DeletedAtCleared() { _spec.ClearField(xunji.FieldDeletedAt, field.TypeTime) } if value, ok := xu.mutation.AppKey(); ok { _spec.SetField(xunji.FieldAppKey, field.TypeString, value) } if xu.mutation.AppKeyCleared() { _spec.ClearField(xunji.FieldAppKey, field.TypeString) } if value, ok := xu.mutation.AppSecret(); ok { _spec.SetField(xunji.FieldAppSecret, field.TypeString, value) } if xu.mutation.AppSecretCleared() { _spec.ClearField(xunji.FieldAppSecret, field.TypeString) } if value, ok := xu.mutation.Token(); ok { _spec.SetField(xunji.FieldToken, field.TypeString, value) } if xu.mutation.TokenCleared() { _spec.ClearField(xunji.FieldToken, field.TypeString) } if value, ok := xu.mutation.EncodingKey(); ok { _spec.SetField(xunji.FieldEncodingKey, field.TypeString, value) } if xu.mutation.EncodingKeyCleared() { _spec.ClearField(xunji.FieldEncodingKey, field.TypeString) } if value, ok := xu.mutation.OrganizationID(); ok { _spec.SetField(xunji.FieldOrganizationID, field.TypeUint64, value) } if value, ok := xu.mutation.AddedOrganizationID(); ok { _spec.AddField(xunji.FieldOrganizationID, field.TypeUint64, value) } if n, err = sqlgraph.UpdateNodes(ctx, xu.driver, _spec); err != nil { if _, ok := err.(*sqlgraph.NotFoundError); ok { err = &NotFoundError{xunji.Label} } else if sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } return 0, err } xu.mutation.done = true return n, nil } // XunjiUpdateOne is the builder for updating a single Xunji entity. type XunjiUpdateOne struct { config fields []string hooks []Hook mutation *XunjiMutation } // SetUpdatedAt sets the "updated_at" field. func (xuo *XunjiUpdateOne) SetUpdatedAt(t time.Time) *XunjiUpdateOne { xuo.mutation.SetUpdatedAt(t) return xuo } // SetStatus sets the "status" field. func (xuo *XunjiUpdateOne) SetStatus(u uint8) *XunjiUpdateOne { xuo.mutation.ResetStatus() xuo.mutation.SetStatus(u) return xuo } // SetNillableStatus sets the "status" field if the given value is not nil. func (xuo *XunjiUpdateOne) SetNillableStatus(u *uint8) *XunjiUpdateOne { if u != nil { xuo.SetStatus(*u) } return xuo } // AddStatus adds u to the "status" field. func (xuo *XunjiUpdateOne) AddStatus(u int8) *XunjiUpdateOne { xuo.mutation.AddStatus(u) return xuo } // ClearStatus clears the value of the "status" field. func (xuo *XunjiUpdateOne) ClearStatus() *XunjiUpdateOne { xuo.mutation.ClearStatus() return xuo } // SetDeletedAt sets the "deleted_at" field. func (xuo *XunjiUpdateOne) SetDeletedAt(t time.Time) *XunjiUpdateOne { xuo.mutation.SetDeletedAt(t) return xuo } // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil. func (xuo *XunjiUpdateOne) SetNillableDeletedAt(t *time.Time) *XunjiUpdateOne { if t != nil { xuo.SetDeletedAt(*t) } return xuo } // ClearDeletedAt clears the value of the "deleted_at" field. func (xuo *XunjiUpdateOne) ClearDeletedAt() *XunjiUpdateOne { xuo.mutation.ClearDeletedAt() return xuo } // SetAppKey sets the "app_key" field. func (xuo *XunjiUpdateOne) SetAppKey(s string) *XunjiUpdateOne { xuo.mutation.SetAppKey(s) return xuo } // SetNillableAppKey sets the "app_key" field if the given value is not nil. func (xuo *XunjiUpdateOne) SetNillableAppKey(s *string) *XunjiUpdateOne { if s != nil { xuo.SetAppKey(*s) } return xuo } // ClearAppKey clears the value of the "app_key" field. func (xuo *XunjiUpdateOne) ClearAppKey() *XunjiUpdateOne { xuo.mutation.ClearAppKey() return xuo } // SetAppSecret sets the "app_secret" field. func (xuo *XunjiUpdateOne) SetAppSecret(s string) *XunjiUpdateOne { xuo.mutation.SetAppSecret(s) return xuo } // SetNillableAppSecret sets the "app_secret" field if the given value is not nil. func (xuo *XunjiUpdateOne) SetNillableAppSecret(s *string) *XunjiUpdateOne { if s != nil { xuo.SetAppSecret(*s) } return xuo } // ClearAppSecret clears the value of the "app_secret" field. func (xuo *XunjiUpdateOne) ClearAppSecret() *XunjiUpdateOne { xuo.mutation.ClearAppSecret() return xuo } // SetToken sets the "token" field. func (xuo *XunjiUpdateOne) SetToken(s string) *XunjiUpdateOne { xuo.mutation.SetToken(s) return xuo } // SetNillableToken sets the "token" field if the given value is not nil. func (xuo *XunjiUpdateOne) SetNillableToken(s *string) *XunjiUpdateOne { if s != nil { xuo.SetToken(*s) } return xuo } // ClearToken clears the value of the "token" field. func (xuo *XunjiUpdateOne) ClearToken() *XunjiUpdateOne { xuo.mutation.ClearToken() return xuo } // SetEncodingKey sets the "encoding_key" field. func (xuo *XunjiUpdateOne) SetEncodingKey(s string) *XunjiUpdateOne { xuo.mutation.SetEncodingKey(s) return xuo } // SetNillableEncodingKey sets the "encoding_key" field if the given value is not nil. func (xuo *XunjiUpdateOne) SetNillableEncodingKey(s *string) *XunjiUpdateOne { if s != nil { xuo.SetEncodingKey(*s) } return xuo } // ClearEncodingKey clears the value of the "encoding_key" field. func (xuo *XunjiUpdateOne) ClearEncodingKey() *XunjiUpdateOne { xuo.mutation.ClearEncodingKey() return xuo } // SetOrganizationID sets the "organization_id" field. func (xuo *XunjiUpdateOne) SetOrganizationID(u uint64) *XunjiUpdateOne { xuo.mutation.ResetOrganizationID() xuo.mutation.SetOrganizationID(u) return xuo } // SetNillableOrganizationID sets the "organization_id" field if the given value is not nil. func (xuo *XunjiUpdateOne) SetNillableOrganizationID(u *uint64) *XunjiUpdateOne { if u != nil { xuo.SetOrganizationID(*u) } return xuo } // AddOrganizationID adds u to the "organization_id" field. func (xuo *XunjiUpdateOne) AddOrganizationID(u int64) *XunjiUpdateOne { xuo.mutation.AddOrganizationID(u) return xuo } // Mutation returns the XunjiMutation object of the builder. func (xuo *XunjiUpdateOne) Mutation() *XunjiMutation { return xuo.mutation } // Where appends a list predicates to the XunjiUpdate builder. func (xuo *XunjiUpdateOne) Where(ps ...predicate.Xunji) *XunjiUpdateOne { xuo.mutation.Where(ps...) return xuo } // Select allows selecting one or more fields (columns) of the returned entity. // The default is selecting all fields defined in the entity schema. func (xuo *XunjiUpdateOne) Select(field string, fields ...string) *XunjiUpdateOne { xuo.fields = append([]string{field}, fields...) return xuo } // Save executes the query and returns the updated Xunji entity. func (xuo *XunjiUpdateOne) Save(ctx context.Context) (*Xunji, error) { if err := xuo.defaults(); err != nil { return nil, err } return withHooks(ctx, xuo.sqlSave, xuo.mutation, xuo.hooks) } // SaveX is like Save, but panics if an error occurs. func (xuo *XunjiUpdateOne) SaveX(ctx context.Context) *Xunji { node, err := xuo.Save(ctx) if err != nil { panic(err) } return node } // Exec executes the query on the entity. func (xuo *XunjiUpdateOne) Exec(ctx context.Context) error { _, err := xuo.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (xuo *XunjiUpdateOne) ExecX(ctx context.Context) { if err := xuo.Exec(ctx); err != nil { panic(err) } } // defaults sets the default values of the builder before save. func (xuo *XunjiUpdateOne) defaults() error { if _, ok := xuo.mutation.UpdatedAt(); !ok { if xunji.UpdateDefaultUpdatedAt == nil { return fmt.Errorf("ent: uninitialized xunji.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)") } v := xunji.UpdateDefaultUpdatedAt() xuo.mutation.SetUpdatedAt(v) } return nil } // check runs all checks and user-defined validators on the builder. func (xuo *XunjiUpdateOne) check() error { if v, ok := xuo.mutation.OrganizationID(); ok { if err := xunji.OrganizationIDValidator(v); err != nil { return &ValidationError{Name: "organization_id", err: fmt.Errorf(`ent: validator failed for field "Xunji.organization_id": %w`, err)} } } return nil } func (xuo *XunjiUpdateOne) sqlSave(ctx context.Context) (_node *Xunji, err error) { if err := xuo.check(); err != nil { return _node, err } _spec := sqlgraph.NewUpdateSpec(xunji.Table, xunji.Columns, sqlgraph.NewFieldSpec(xunji.FieldID, field.TypeUint64)) id, ok := xuo.mutation.ID() if !ok { return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Xunji.id" for update`)} } _spec.Node.ID.Value = id if fields := xuo.fields; len(fields) > 0 { _spec.Node.Columns = make([]string, 0, len(fields)) _spec.Node.Columns = append(_spec.Node.Columns, xunji.FieldID) for _, f := range fields { if !xunji.ValidColumn(f) { return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} } if f != xunji.FieldID { _spec.Node.Columns = append(_spec.Node.Columns, f) } } } if ps := xuo.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { ps[i](selector) } } } if value, ok := xuo.mutation.UpdatedAt(); ok { _spec.SetField(xunji.FieldUpdatedAt, field.TypeTime, value) } if value, ok := xuo.mutation.Status(); ok { _spec.SetField(xunji.FieldStatus, field.TypeUint8, value) } if value, ok := xuo.mutation.AddedStatus(); ok { _spec.AddField(xunji.FieldStatus, field.TypeUint8, value) } if xuo.mutation.StatusCleared() { _spec.ClearField(xunji.FieldStatus, field.TypeUint8) } if value, ok := xuo.mutation.DeletedAt(); ok { _spec.SetField(xunji.FieldDeletedAt, field.TypeTime, value) } if xuo.mutation.DeletedAtCleared() { _spec.ClearField(xunji.FieldDeletedAt, field.TypeTime) } if value, ok := xuo.mutation.AppKey(); ok { _spec.SetField(xunji.FieldAppKey, field.TypeString, value) } if xuo.mutation.AppKeyCleared() { _spec.ClearField(xunji.FieldAppKey, field.TypeString) } if value, ok := xuo.mutation.AppSecret(); ok { _spec.SetField(xunji.FieldAppSecret, field.TypeString, value) } if xuo.mutation.AppSecretCleared() { _spec.ClearField(xunji.FieldAppSecret, field.TypeString) } if value, ok := xuo.mutation.Token(); ok { _spec.SetField(xunji.FieldToken, field.TypeString, value) } if xuo.mutation.TokenCleared() { _spec.ClearField(xunji.FieldToken, field.TypeString) } if value, ok := xuo.mutation.EncodingKey(); ok { _spec.SetField(xunji.FieldEncodingKey, field.TypeString, value) } if xuo.mutation.EncodingKeyCleared() { _spec.ClearField(xunji.FieldEncodingKey, field.TypeString) } if value, ok := xuo.mutation.OrganizationID(); ok { _spec.SetField(xunji.FieldOrganizationID, field.TypeUint64, value) } if value, ok := xuo.mutation.AddedOrganizationID(); ok { _spec.AddField(xunji.FieldOrganizationID, field.TypeUint64, value) } _node = &Xunji{config: xuo.config} _spec.Assign = _node.assignValues _spec.ScanValues = _node.scanValues if err = sqlgraph.UpdateNode(ctx, xuo.driver, _spec); err != nil { if _, ok := err.(*sqlgraph.NotFoundError); ok { err = &NotFoundError{xunji.Label} } else if sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } return nil, err } xuo.mutation.done = true return _node, nil }