| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857 |
- // Code generated by ent, DO NOT EDIT.
- package ent
- import (
- "context"
- "errors"
- "fmt"
- "time"
- "entgo.io/ent/dialect/sql"
- "entgo.io/ent/dialect/sql/sqlgraph"
- "entgo.io/ent/dialect/sql/sqljson"
- "entgo.io/ent/schema/field"
- "github.com/Wei-Shaw/sub2api/ent/errorpassthroughrule"
- "github.com/Wei-Shaw/sub2api/ent/predicate"
- )
- // ErrorPassthroughRuleUpdate is the builder for updating ErrorPassthroughRule entities.
- type ErrorPassthroughRuleUpdate struct {
- config
- hooks []Hook
- mutation *ErrorPassthroughRuleMutation
- }
- // Where appends a list predicates to the ErrorPassthroughRuleUpdate builder.
- func (_u *ErrorPassthroughRuleUpdate) Where(ps ...predicate.ErrorPassthroughRule) *ErrorPassthroughRuleUpdate {
- _u.mutation.Where(ps...)
- return _u
- }
- // SetUpdatedAt sets the "updated_at" field.
- func (_u *ErrorPassthroughRuleUpdate) SetUpdatedAt(v time.Time) *ErrorPassthroughRuleUpdate {
- _u.mutation.SetUpdatedAt(v)
- return _u
- }
- // SetName sets the "name" field.
- func (_u *ErrorPassthroughRuleUpdate) SetName(v string) *ErrorPassthroughRuleUpdate {
- _u.mutation.SetName(v)
- return _u
- }
- // SetNillableName sets the "name" field if the given value is not nil.
- func (_u *ErrorPassthroughRuleUpdate) SetNillableName(v *string) *ErrorPassthroughRuleUpdate {
- if v != nil {
- _u.SetName(*v)
- }
- return _u
- }
- // SetEnabled sets the "enabled" field.
- func (_u *ErrorPassthroughRuleUpdate) SetEnabled(v bool) *ErrorPassthroughRuleUpdate {
- _u.mutation.SetEnabled(v)
- return _u
- }
- // SetNillableEnabled sets the "enabled" field if the given value is not nil.
- func (_u *ErrorPassthroughRuleUpdate) SetNillableEnabled(v *bool) *ErrorPassthroughRuleUpdate {
- if v != nil {
- _u.SetEnabled(*v)
- }
- return _u
- }
- // SetPriority sets the "priority" field.
- func (_u *ErrorPassthroughRuleUpdate) SetPriority(v int) *ErrorPassthroughRuleUpdate {
- _u.mutation.ResetPriority()
- _u.mutation.SetPriority(v)
- return _u
- }
- // SetNillablePriority sets the "priority" field if the given value is not nil.
- func (_u *ErrorPassthroughRuleUpdate) SetNillablePriority(v *int) *ErrorPassthroughRuleUpdate {
- if v != nil {
- _u.SetPriority(*v)
- }
- return _u
- }
- // AddPriority adds value to the "priority" field.
- func (_u *ErrorPassthroughRuleUpdate) AddPriority(v int) *ErrorPassthroughRuleUpdate {
- _u.mutation.AddPriority(v)
- return _u
- }
- // SetErrorCodes sets the "error_codes" field.
- func (_u *ErrorPassthroughRuleUpdate) SetErrorCodes(v []int) *ErrorPassthroughRuleUpdate {
- _u.mutation.SetErrorCodes(v)
- return _u
- }
- // AppendErrorCodes appends value to the "error_codes" field.
- func (_u *ErrorPassthroughRuleUpdate) AppendErrorCodes(v []int) *ErrorPassthroughRuleUpdate {
- _u.mutation.AppendErrorCodes(v)
- return _u
- }
- // ClearErrorCodes clears the value of the "error_codes" field.
- func (_u *ErrorPassthroughRuleUpdate) ClearErrorCodes() *ErrorPassthroughRuleUpdate {
- _u.mutation.ClearErrorCodes()
- return _u
- }
- // SetKeywords sets the "keywords" field.
- func (_u *ErrorPassthroughRuleUpdate) SetKeywords(v []string) *ErrorPassthroughRuleUpdate {
- _u.mutation.SetKeywords(v)
- return _u
- }
- // AppendKeywords appends value to the "keywords" field.
- func (_u *ErrorPassthroughRuleUpdate) AppendKeywords(v []string) *ErrorPassthroughRuleUpdate {
- _u.mutation.AppendKeywords(v)
- return _u
- }
- // ClearKeywords clears the value of the "keywords" field.
- func (_u *ErrorPassthroughRuleUpdate) ClearKeywords() *ErrorPassthroughRuleUpdate {
- _u.mutation.ClearKeywords()
- return _u
- }
- // SetMatchMode sets the "match_mode" field.
- func (_u *ErrorPassthroughRuleUpdate) SetMatchMode(v string) *ErrorPassthroughRuleUpdate {
- _u.mutation.SetMatchMode(v)
- return _u
- }
- // SetNillableMatchMode sets the "match_mode" field if the given value is not nil.
- func (_u *ErrorPassthroughRuleUpdate) SetNillableMatchMode(v *string) *ErrorPassthroughRuleUpdate {
- if v != nil {
- _u.SetMatchMode(*v)
- }
- return _u
- }
- // SetPlatforms sets the "platforms" field.
- func (_u *ErrorPassthroughRuleUpdate) SetPlatforms(v []string) *ErrorPassthroughRuleUpdate {
- _u.mutation.SetPlatforms(v)
- return _u
- }
- // AppendPlatforms appends value to the "platforms" field.
- func (_u *ErrorPassthroughRuleUpdate) AppendPlatforms(v []string) *ErrorPassthroughRuleUpdate {
- _u.mutation.AppendPlatforms(v)
- return _u
- }
- // ClearPlatforms clears the value of the "platforms" field.
- func (_u *ErrorPassthroughRuleUpdate) ClearPlatforms() *ErrorPassthroughRuleUpdate {
- _u.mutation.ClearPlatforms()
- return _u
- }
- // SetPassthroughCode sets the "passthrough_code" field.
- func (_u *ErrorPassthroughRuleUpdate) SetPassthroughCode(v bool) *ErrorPassthroughRuleUpdate {
- _u.mutation.SetPassthroughCode(v)
- return _u
- }
- // SetNillablePassthroughCode sets the "passthrough_code" field if the given value is not nil.
- func (_u *ErrorPassthroughRuleUpdate) SetNillablePassthroughCode(v *bool) *ErrorPassthroughRuleUpdate {
- if v != nil {
- _u.SetPassthroughCode(*v)
- }
- return _u
- }
- // SetResponseCode sets the "response_code" field.
- func (_u *ErrorPassthroughRuleUpdate) SetResponseCode(v int) *ErrorPassthroughRuleUpdate {
- _u.mutation.ResetResponseCode()
- _u.mutation.SetResponseCode(v)
- return _u
- }
- // SetNillableResponseCode sets the "response_code" field if the given value is not nil.
- func (_u *ErrorPassthroughRuleUpdate) SetNillableResponseCode(v *int) *ErrorPassthroughRuleUpdate {
- if v != nil {
- _u.SetResponseCode(*v)
- }
- return _u
- }
- // AddResponseCode adds value to the "response_code" field.
- func (_u *ErrorPassthroughRuleUpdate) AddResponseCode(v int) *ErrorPassthroughRuleUpdate {
- _u.mutation.AddResponseCode(v)
- return _u
- }
- // ClearResponseCode clears the value of the "response_code" field.
- func (_u *ErrorPassthroughRuleUpdate) ClearResponseCode() *ErrorPassthroughRuleUpdate {
- _u.mutation.ClearResponseCode()
- return _u
- }
- // SetPassthroughBody sets the "passthrough_body" field.
- func (_u *ErrorPassthroughRuleUpdate) SetPassthroughBody(v bool) *ErrorPassthroughRuleUpdate {
- _u.mutation.SetPassthroughBody(v)
- return _u
- }
- // SetNillablePassthroughBody sets the "passthrough_body" field if the given value is not nil.
- func (_u *ErrorPassthroughRuleUpdate) SetNillablePassthroughBody(v *bool) *ErrorPassthroughRuleUpdate {
- if v != nil {
- _u.SetPassthroughBody(*v)
- }
- return _u
- }
- // SetCustomMessage sets the "custom_message" field.
- func (_u *ErrorPassthroughRuleUpdate) SetCustomMessage(v string) *ErrorPassthroughRuleUpdate {
- _u.mutation.SetCustomMessage(v)
- return _u
- }
- // SetNillableCustomMessage sets the "custom_message" field if the given value is not nil.
- func (_u *ErrorPassthroughRuleUpdate) SetNillableCustomMessage(v *string) *ErrorPassthroughRuleUpdate {
- if v != nil {
- _u.SetCustomMessage(*v)
- }
- return _u
- }
- // ClearCustomMessage clears the value of the "custom_message" field.
- func (_u *ErrorPassthroughRuleUpdate) ClearCustomMessage() *ErrorPassthroughRuleUpdate {
- _u.mutation.ClearCustomMessage()
- return _u
- }
- // SetSkipMonitoring sets the "skip_monitoring" field.
- func (_u *ErrorPassthroughRuleUpdate) SetSkipMonitoring(v bool) *ErrorPassthroughRuleUpdate {
- _u.mutation.SetSkipMonitoring(v)
- return _u
- }
- // SetNillableSkipMonitoring sets the "skip_monitoring" field if the given value is not nil.
- func (_u *ErrorPassthroughRuleUpdate) SetNillableSkipMonitoring(v *bool) *ErrorPassthroughRuleUpdate {
- if v != nil {
- _u.SetSkipMonitoring(*v)
- }
- return _u
- }
- // SetDescription sets the "description" field.
- func (_u *ErrorPassthroughRuleUpdate) SetDescription(v string) *ErrorPassthroughRuleUpdate {
- _u.mutation.SetDescription(v)
- return _u
- }
- // SetNillableDescription sets the "description" field if the given value is not nil.
- func (_u *ErrorPassthroughRuleUpdate) SetNillableDescription(v *string) *ErrorPassthroughRuleUpdate {
- if v != nil {
- _u.SetDescription(*v)
- }
- return _u
- }
- // ClearDescription clears the value of the "description" field.
- func (_u *ErrorPassthroughRuleUpdate) ClearDescription() *ErrorPassthroughRuleUpdate {
- _u.mutation.ClearDescription()
- return _u
- }
- // Mutation returns the ErrorPassthroughRuleMutation object of the builder.
- func (_u *ErrorPassthroughRuleUpdate) Mutation() *ErrorPassthroughRuleMutation {
- return _u.mutation
- }
- // Save executes the query and returns the number of nodes affected by the update operation.
- func (_u *ErrorPassthroughRuleUpdate) Save(ctx context.Context) (int, error) {
- _u.defaults()
- return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
- }
- // SaveX is like Save, but panics if an error occurs.
- func (_u *ErrorPassthroughRuleUpdate) SaveX(ctx context.Context) int {
- affected, err := _u.Save(ctx)
- if err != nil {
- panic(err)
- }
- return affected
- }
- // Exec executes the query.
- func (_u *ErrorPassthroughRuleUpdate) Exec(ctx context.Context) error {
- _, err := _u.Save(ctx)
- return err
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (_u *ErrorPassthroughRuleUpdate) ExecX(ctx context.Context) {
- if err := _u.Exec(ctx); err != nil {
- panic(err)
- }
- }
- // defaults sets the default values of the builder before save.
- func (_u *ErrorPassthroughRuleUpdate) defaults() {
- if _, ok := _u.mutation.UpdatedAt(); !ok {
- v := errorpassthroughrule.UpdateDefaultUpdatedAt()
- _u.mutation.SetUpdatedAt(v)
- }
- }
- // check runs all checks and user-defined validators on the builder.
- func (_u *ErrorPassthroughRuleUpdate) check() error {
- if v, ok := _u.mutation.Name(); ok {
- if err := errorpassthroughrule.NameValidator(v); err != nil {
- return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "ErrorPassthroughRule.name": %w`, err)}
- }
- }
- if v, ok := _u.mutation.MatchMode(); ok {
- if err := errorpassthroughrule.MatchModeValidator(v); err != nil {
- return &ValidationError{Name: "match_mode", err: fmt.Errorf(`ent: validator failed for field "ErrorPassthroughRule.match_mode": %w`, err)}
- }
- }
- return nil
- }
- func (_u *ErrorPassthroughRuleUpdate) sqlSave(ctx context.Context) (_node int, err error) {
- if err := _u.check(); err != nil {
- return _node, err
- }
- _spec := sqlgraph.NewUpdateSpec(errorpassthroughrule.Table, errorpassthroughrule.Columns, sqlgraph.NewFieldSpec(errorpassthroughrule.FieldID, field.TypeInt64))
- if ps := _u.mutation.predicates; len(ps) > 0 {
- _spec.Predicate = func(selector *sql.Selector) {
- for i := range ps {
- ps[i](selector)
- }
- }
- }
- if value, ok := _u.mutation.UpdatedAt(); ok {
- _spec.SetField(errorpassthroughrule.FieldUpdatedAt, field.TypeTime, value)
- }
- if value, ok := _u.mutation.Name(); ok {
- _spec.SetField(errorpassthroughrule.FieldName, field.TypeString, value)
- }
- if value, ok := _u.mutation.Enabled(); ok {
- _spec.SetField(errorpassthroughrule.FieldEnabled, field.TypeBool, value)
- }
- if value, ok := _u.mutation.Priority(); ok {
- _spec.SetField(errorpassthroughrule.FieldPriority, field.TypeInt, value)
- }
- if value, ok := _u.mutation.AddedPriority(); ok {
- _spec.AddField(errorpassthroughrule.FieldPriority, field.TypeInt, value)
- }
- if value, ok := _u.mutation.ErrorCodes(); ok {
- _spec.SetField(errorpassthroughrule.FieldErrorCodes, field.TypeJSON, value)
- }
- if value, ok := _u.mutation.AppendedErrorCodes(); ok {
- _spec.AddModifier(func(u *sql.UpdateBuilder) {
- sqljson.Append(u, errorpassthroughrule.FieldErrorCodes, value)
- })
- }
- if _u.mutation.ErrorCodesCleared() {
- _spec.ClearField(errorpassthroughrule.FieldErrorCodes, field.TypeJSON)
- }
- if value, ok := _u.mutation.Keywords(); ok {
- _spec.SetField(errorpassthroughrule.FieldKeywords, field.TypeJSON, value)
- }
- if value, ok := _u.mutation.AppendedKeywords(); ok {
- _spec.AddModifier(func(u *sql.UpdateBuilder) {
- sqljson.Append(u, errorpassthroughrule.FieldKeywords, value)
- })
- }
- if _u.mutation.KeywordsCleared() {
- _spec.ClearField(errorpassthroughrule.FieldKeywords, field.TypeJSON)
- }
- if value, ok := _u.mutation.MatchMode(); ok {
- _spec.SetField(errorpassthroughrule.FieldMatchMode, field.TypeString, value)
- }
- if value, ok := _u.mutation.Platforms(); ok {
- _spec.SetField(errorpassthroughrule.FieldPlatforms, field.TypeJSON, value)
- }
- if value, ok := _u.mutation.AppendedPlatforms(); ok {
- _spec.AddModifier(func(u *sql.UpdateBuilder) {
- sqljson.Append(u, errorpassthroughrule.FieldPlatforms, value)
- })
- }
- if _u.mutation.PlatformsCleared() {
- _spec.ClearField(errorpassthroughrule.FieldPlatforms, field.TypeJSON)
- }
- if value, ok := _u.mutation.PassthroughCode(); ok {
- _spec.SetField(errorpassthroughrule.FieldPassthroughCode, field.TypeBool, value)
- }
- if value, ok := _u.mutation.ResponseCode(); ok {
- _spec.SetField(errorpassthroughrule.FieldResponseCode, field.TypeInt, value)
- }
- if value, ok := _u.mutation.AddedResponseCode(); ok {
- _spec.AddField(errorpassthroughrule.FieldResponseCode, field.TypeInt, value)
- }
- if _u.mutation.ResponseCodeCleared() {
- _spec.ClearField(errorpassthroughrule.FieldResponseCode, field.TypeInt)
- }
- if value, ok := _u.mutation.PassthroughBody(); ok {
- _spec.SetField(errorpassthroughrule.FieldPassthroughBody, field.TypeBool, value)
- }
- if value, ok := _u.mutation.CustomMessage(); ok {
- _spec.SetField(errorpassthroughrule.FieldCustomMessage, field.TypeString, value)
- }
- if _u.mutation.CustomMessageCleared() {
- _spec.ClearField(errorpassthroughrule.FieldCustomMessage, field.TypeString)
- }
- if value, ok := _u.mutation.SkipMonitoring(); ok {
- _spec.SetField(errorpassthroughrule.FieldSkipMonitoring, field.TypeBool, value)
- }
- if value, ok := _u.mutation.Description(); ok {
- _spec.SetField(errorpassthroughrule.FieldDescription, field.TypeString, value)
- }
- if _u.mutation.DescriptionCleared() {
- _spec.ClearField(errorpassthroughrule.FieldDescription, field.TypeString)
- }
- if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
- if _, ok := err.(*sqlgraph.NotFoundError); ok {
- err = &NotFoundError{errorpassthroughrule.Label}
- } else if sqlgraph.IsConstraintError(err) {
- err = &ConstraintError{msg: err.Error(), wrap: err}
- }
- return 0, err
- }
- _u.mutation.done = true
- return _node, nil
- }
- // ErrorPassthroughRuleUpdateOne is the builder for updating a single ErrorPassthroughRule entity.
- type ErrorPassthroughRuleUpdateOne struct {
- config
- fields []string
- hooks []Hook
- mutation *ErrorPassthroughRuleMutation
- }
- // SetUpdatedAt sets the "updated_at" field.
- func (_u *ErrorPassthroughRuleUpdateOne) SetUpdatedAt(v time.Time) *ErrorPassthroughRuleUpdateOne {
- _u.mutation.SetUpdatedAt(v)
- return _u
- }
- // SetName sets the "name" field.
- func (_u *ErrorPassthroughRuleUpdateOne) SetName(v string) *ErrorPassthroughRuleUpdateOne {
- _u.mutation.SetName(v)
- return _u
- }
- // SetNillableName sets the "name" field if the given value is not nil.
- func (_u *ErrorPassthroughRuleUpdateOne) SetNillableName(v *string) *ErrorPassthroughRuleUpdateOne {
- if v != nil {
- _u.SetName(*v)
- }
- return _u
- }
- // SetEnabled sets the "enabled" field.
- func (_u *ErrorPassthroughRuleUpdateOne) SetEnabled(v bool) *ErrorPassthroughRuleUpdateOne {
- _u.mutation.SetEnabled(v)
- return _u
- }
- // SetNillableEnabled sets the "enabled" field if the given value is not nil.
- func (_u *ErrorPassthroughRuleUpdateOne) SetNillableEnabled(v *bool) *ErrorPassthroughRuleUpdateOne {
- if v != nil {
- _u.SetEnabled(*v)
- }
- return _u
- }
- // SetPriority sets the "priority" field.
- func (_u *ErrorPassthroughRuleUpdateOne) SetPriority(v int) *ErrorPassthroughRuleUpdateOne {
- _u.mutation.ResetPriority()
- _u.mutation.SetPriority(v)
- return _u
- }
- // SetNillablePriority sets the "priority" field if the given value is not nil.
- func (_u *ErrorPassthroughRuleUpdateOne) SetNillablePriority(v *int) *ErrorPassthroughRuleUpdateOne {
- if v != nil {
- _u.SetPriority(*v)
- }
- return _u
- }
- // AddPriority adds value to the "priority" field.
- func (_u *ErrorPassthroughRuleUpdateOne) AddPriority(v int) *ErrorPassthroughRuleUpdateOne {
- _u.mutation.AddPriority(v)
- return _u
- }
- // SetErrorCodes sets the "error_codes" field.
- func (_u *ErrorPassthroughRuleUpdateOne) SetErrorCodes(v []int) *ErrorPassthroughRuleUpdateOne {
- _u.mutation.SetErrorCodes(v)
- return _u
- }
- // AppendErrorCodes appends value to the "error_codes" field.
- func (_u *ErrorPassthroughRuleUpdateOne) AppendErrorCodes(v []int) *ErrorPassthroughRuleUpdateOne {
- _u.mutation.AppendErrorCodes(v)
- return _u
- }
- // ClearErrorCodes clears the value of the "error_codes" field.
- func (_u *ErrorPassthroughRuleUpdateOne) ClearErrorCodes() *ErrorPassthroughRuleUpdateOne {
- _u.mutation.ClearErrorCodes()
- return _u
- }
- // SetKeywords sets the "keywords" field.
- func (_u *ErrorPassthroughRuleUpdateOne) SetKeywords(v []string) *ErrorPassthroughRuleUpdateOne {
- _u.mutation.SetKeywords(v)
- return _u
- }
- // AppendKeywords appends value to the "keywords" field.
- func (_u *ErrorPassthroughRuleUpdateOne) AppendKeywords(v []string) *ErrorPassthroughRuleUpdateOne {
- _u.mutation.AppendKeywords(v)
- return _u
- }
- // ClearKeywords clears the value of the "keywords" field.
- func (_u *ErrorPassthroughRuleUpdateOne) ClearKeywords() *ErrorPassthroughRuleUpdateOne {
- _u.mutation.ClearKeywords()
- return _u
- }
- // SetMatchMode sets the "match_mode" field.
- func (_u *ErrorPassthroughRuleUpdateOne) SetMatchMode(v string) *ErrorPassthroughRuleUpdateOne {
- _u.mutation.SetMatchMode(v)
- return _u
- }
- // SetNillableMatchMode sets the "match_mode" field if the given value is not nil.
- func (_u *ErrorPassthroughRuleUpdateOne) SetNillableMatchMode(v *string) *ErrorPassthroughRuleUpdateOne {
- if v != nil {
- _u.SetMatchMode(*v)
- }
- return _u
- }
- // SetPlatforms sets the "platforms" field.
- func (_u *ErrorPassthroughRuleUpdateOne) SetPlatforms(v []string) *ErrorPassthroughRuleUpdateOne {
- _u.mutation.SetPlatforms(v)
- return _u
- }
- // AppendPlatforms appends value to the "platforms" field.
- func (_u *ErrorPassthroughRuleUpdateOne) AppendPlatforms(v []string) *ErrorPassthroughRuleUpdateOne {
- _u.mutation.AppendPlatforms(v)
- return _u
- }
- // ClearPlatforms clears the value of the "platforms" field.
- func (_u *ErrorPassthroughRuleUpdateOne) ClearPlatforms() *ErrorPassthroughRuleUpdateOne {
- _u.mutation.ClearPlatforms()
- return _u
- }
- // SetPassthroughCode sets the "passthrough_code" field.
- func (_u *ErrorPassthroughRuleUpdateOne) SetPassthroughCode(v bool) *ErrorPassthroughRuleUpdateOne {
- _u.mutation.SetPassthroughCode(v)
- return _u
- }
- // SetNillablePassthroughCode sets the "passthrough_code" field if the given value is not nil.
- func (_u *ErrorPassthroughRuleUpdateOne) SetNillablePassthroughCode(v *bool) *ErrorPassthroughRuleUpdateOne {
- if v != nil {
- _u.SetPassthroughCode(*v)
- }
- return _u
- }
- // SetResponseCode sets the "response_code" field.
- func (_u *ErrorPassthroughRuleUpdateOne) SetResponseCode(v int) *ErrorPassthroughRuleUpdateOne {
- _u.mutation.ResetResponseCode()
- _u.mutation.SetResponseCode(v)
- return _u
- }
- // SetNillableResponseCode sets the "response_code" field if the given value is not nil.
- func (_u *ErrorPassthroughRuleUpdateOne) SetNillableResponseCode(v *int) *ErrorPassthroughRuleUpdateOne {
- if v != nil {
- _u.SetResponseCode(*v)
- }
- return _u
- }
- // AddResponseCode adds value to the "response_code" field.
- func (_u *ErrorPassthroughRuleUpdateOne) AddResponseCode(v int) *ErrorPassthroughRuleUpdateOne {
- _u.mutation.AddResponseCode(v)
- return _u
- }
- // ClearResponseCode clears the value of the "response_code" field.
- func (_u *ErrorPassthroughRuleUpdateOne) ClearResponseCode() *ErrorPassthroughRuleUpdateOne {
- _u.mutation.ClearResponseCode()
- return _u
- }
- // SetPassthroughBody sets the "passthrough_body" field.
- func (_u *ErrorPassthroughRuleUpdateOne) SetPassthroughBody(v bool) *ErrorPassthroughRuleUpdateOne {
- _u.mutation.SetPassthroughBody(v)
- return _u
- }
- // SetNillablePassthroughBody sets the "passthrough_body" field if the given value is not nil.
- func (_u *ErrorPassthroughRuleUpdateOne) SetNillablePassthroughBody(v *bool) *ErrorPassthroughRuleUpdateOne {
- if v != nil {
- _u.SetPassthroughBody(*v)
- }
- return _u
- }
- // SetCustomMessage sets the "custom_message" field.
- func (_u *ErrorPassthroughRuleUpdateOne) SetCustomMessage(v string) *ErrorPassthroughRuleUpdateOne {
- _u.mutation.SetCustomMessage(v)
- return _u
- }
- // SetNillableCustomMessage sets the "custom_message" field if the given value is not nil.
- func (_u *ErrorPassthroughRuleUpdateOne) SetNillableCustomMessage(v *string) *ErrorPassthroughRuleUpdateOne {
- if v != nil {
- _u.SetCustomMessage(*v)
- }
- return _u
- }
- // ClearCustomMessage clears the value of the "custom_message" field.
- func (_u *ErrorPassthroughRuleUpdateOne) ClearCustomMessage() *ErrorPassthroughRuleUpdateOne {
- _u.mutation.ClearCustomMessage()
- return _u
- }
- // SetSkipMonitoring sets the "skip_monitoring" field.
- func (_u *ErrorPassthroughRuleUpdateOne) SetSkipMonitoring(v bool) *ErrorPassthroughRuleUpdateOne {
- _u.mutation.SetSkipMonitoring(v)
- return _u
- }
- // SetNillableSkipMonitoring sets the "skip_monitoring" field if the given value is not nil.
- func (_u *ErrorPassthroughRuleUpdateOne) SetNillableSkipMonitoring(v *bool) *ErrorPassthroughRuleUpdateOne {
- if v != nil {
- _u.SetSkipMonitoring(*v)
- }
- return _u
- }
- // SetDescription sets the "description" field.
- func (_u *ErrorPassthroughRuleUpdateOne) SetDescription(v string) *ErrorPassthroughRuleUpdateOne {
- _u.mutation.SetDescription(v)
- return _u
- }
- // SetNillableDescription sets the "description" field if the given value is not nil.
- func (_u *ErrorPassthroughRuleUpdateOne) SetNillableDescription(v *string) *ErrorPassthroughRuleUpdateOne {
- if v != nil {
- _u.SetDescription(*v)
- }
- return _u
- }
- // ClearDescription clears the value of the "description" field.
- func (_u *ErrorPassthroughRuleUpdateOne) ClearDescription() *ErrorPassthroughRuleUpdateOne {
- _u.mutation.ClearDescription()
- return _u
- }
- // Mutation returns the ErrorPassthroughRuleMutation object of the builder.
- func (_u *ErrorPassthroughRuleUpdateOne) Mutation() *ErrorPassthroughRuleMutation {
- return _u.mutation
- }
- // Where appends a list predicates to the ErrorPassthroughRuleUpdate builder.
- func (_u *ErrorPassthroughRuleUpdateOne) Where(ps ...predicate.ErrorPassthroughRule) *ErrorPassthroughRuleUpdateOne {
- _u.mutation.Where(ps...)
- return _u
- }
- // Select allows selecting one or more fields (columns) of the returned entity.
- // The default is selecting all fields defined in the entity schema.
- func (_u *ErrorPassthroughRuleUpdateOne) Select(field string, fields ...string) *ErrorPassthroughRuleUpdateOne {
- _u.fields = append([]string{field}, fields...)
- return _u
- }
- // Save executes the query and returns the updated ErrorPassthroughRule entity.
- func (_u *ErrorPassthroughRuleUpdateOne) Save(ctx context.Context) (*ErrorPassthroughRule, error) {
- _u.defaults()
- return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
- }
- // SaveX is like Save, but panics if an error occurs.
- func (_u *ErrorPassthroughRuleUpdateOne) SaveX(ctx context.Context) *ErrorPassthroughRule {
- node, err := _u.Save(ctx)
- if err != nil {
- panic(err)
- }
- return node
- }
- // Exec executes the query on the entity.
- func (_u *ErrorPassthroughRuleUpdateOne) Exec(ctx context.Context) error {
- _, err := _u.Save(ctx)
- return err
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (_u *ErrorPassthroughRuleUpdateOne) ExecX(ctx context.Context) {
- if err := _u.Exec(ctx); err != nil {
- panic(err)
- }
- }
- // defaults sets the default values of the builder before save.
- func (_u *ErrorPassthroughRuleUpdateOne) defaults() {
- if _, ok := _u.mutation.UpdatedAt(); !ok {
- v := errorpassthroughrule.UpdateDefaultUpdatedAt()
- _u.mutation.SetUpdatedAt(v)
- }
- }
- // check runs all checks and user-defined validators on the builder.
- func (_u *ErrorPassthroughRuleUpdateOne) check() error {
- if v, ok := _u.mutation.Name(); ok {
- if err := errorpassthroughrule.NameValidator(v); err != nil {
- return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "ErrorPassthroughRule.name": %w`, err)}
- }
- }
- if v, ok := _u.mutation.MatchMode(); ok {
- if err := errorpassthroughrule.MatchModeValidator(v); err != nil {
- return &ValidationError{Name: "match_mode", err: fmt.Errorf(`ent: validator failed for field "ErrorPassthroughRule.match_mode": %w`, err)}
- }
- }
- return nil
- }
- func (_u *ErrorPassthroughRuleUpdateOne) sqlSave(ctx context.Context) (_node *ErrorPassthroughRule, err error) {
- if err := _u.check(); err != nil {
- return _node, err
- }
- _spec := sqlgraph.NewUpdateSpec(errorpassthroughrule.Table, errorpassthroughrule.Columns, sqlgraph.NewFieldSpec(errorpassthroughrule.FieldID, field.TypeInt64))
- id, ok := _u.mutation.ID()
- if !ok {
- return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "ErrorPassthroughRule.id" for update`)}
- }
- _spec.Node.ID.Value = id
- if fields := _u.fields; len(fields) > 0 {
- _spec.Node.Columns = make([]string, 0, len(fields))
- _spec.Node.Columns = append(_spec.Node.Columns, errorpassthroughrule.FieldID)
- for _, f := range fields {
- if !errorpassthroughrule.ValidColumn(f) {
- return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
- }
- if f != errorpassthroughrule.FieldID {
- _spec.Node.Columns = append(_spec.Node.Columns, f)
- }
- }
- }
- if ps := _u.mutation.predicates; len(ps) > 0 {
- _spec.Predicate = func(selector *sql.Selector) {
- for i := range ps {
- ps[i](selector)
- }
- }
- }
- if value, ok := _u.mutation.UpdatedAt(); ok {
- _spec.SetField(errorpassthroughrule.FieldUpdatedAt, field.TypeTime, value)
- }
- if value, ok := _u.mutation.Name(); ok {
- _spec.SetField(errorpassthroughrule.FieldName, field.TypeString, value)
- }
- if value, ok := _u.mutation.Enabled(); ok {
- _spec.SetField(errorpassthroughrule.FieldEnabled, field.TypeBool, value)
- }
- if value, ok := _u.mutation.Priority(); ok {
- _spec.SetField(errorpassthroughrule.FieldPriority, field.TypeInt, value)
- }
- if value, ok := _u.mutation.AddedPriority(); ok {
- _spec.AddField(errorpassthroughrule.FieldPriority, field.TypeInt, value)
- }
- if value, ok := _u.mutation.ErrorCodes(); ok {
- _spec.SetField(errorpassthroughrule.FieldErrorCodes, field.TypeJSON, value)
- }
- if value, ok := _u.mutation.AppendedErrorCodes(); ok {
- _spec.AddModifier(func(u *sql.UpdateBuilder) {
- sqljson.Append(u, errorpassthroughrule.FieldErrorCodes, value)
- })
- }
- if _u.mutation.ErrorCodesCleared() {
- _spec.ClearField(errorpassthroughrule.FieldErrorCodes, field.TypeJSON)
- }
- if value, ok := _u.mutation.Keywords(); ok {
- _spec.SetField(errorpassthroughrule.FieldKeywords, field.TypeJSON, value)
- }
- if value, ok := _u.mutation.AppendedKeywords(); ok {
- _spec.AddModifier(func(u *sql.UpdateBuilder) {
- sqljson.Append(u, errorpassthroughrule.FieldKeywords, value)
- })
- }
- if _u.mutation.KeywordsCleared() {
- _spec.ClearField(errorpassthroughrule.FieldKeywords, field.TypeJSON)
- }
- if value, ok := _u.mutation.MatchMode(); ok {
- _spec.SetField(errorpassthroughrule.FieldMatchMode, field.TypeString, value)
- }
- if value, ok := _u.mutation.Platforms(); ok {
- _spec.SetField(errorpassthroughrule.FieldPlatforms, field.TypeJSON, value)
- }
- if value, ok := _u.mutation.AppendedPlatforms(); ok {
- _spec.AddModifier(func(u *sql.UpdateBuilder) {
- sqljson.Append(u, errorpassthroughrule.FieldPlatforms, value)
- })
- }
- if _u.mutation.PlatformsCleared() {
- _spec.ClearField(errorpassthroughrule.FieldPlatforms, field.TypeJSON)
- }
- if value, ok := _u.mutation.PassthroughCode(); ok {
- _spec.SetField(errorpassthroughrule.FieldPassthroughCode, field.TypeBool, value)
- }
- if value, ok := _u.mutation.ResponseCode(); ok {
- _spec.SetField(errorpassthroughrule.FieldResponseCode, field.TypeInt, value)
- }
- if value, ok := _u.mutation.AddedResponseCode(); ok {
- _spec.AddField(errorpassthroughrule.FieldResponseCode, field.TypeInt, value)
- }
- if _u.mutation.ResponseCodeCleared() {
- _spec.ClearField(errorpassthroughrule.FieldResponseCode, field.TypeInt)
- }
- if value, ok := _u.mutation.PassthroughBody(); ok {
- _spec.SetField(errorpassthroughrule.FieldPassthroughBody, field.TypeBool, value)
- }
- if value, ok := _u.mutation.CustomMessage(); ok {
- _spec.SetField(errorpassthroughrule.FieldCustomMessage, field.TypeString, value)
- }
- if _u.mutation.CustomMessageCleared() {
- _spec.ClearField(errorpassthroughrule.FieldCustomMessage, field.TypeString)
- }
- if value, ok := _u.mutation.SkipMonitoring(); ok {
- _spec.SetField(errorpassthroughrule.FieldSkipMonitoring, field.TypeBool, value)
- }
- if value, ok := _u.mutation.Description(); ok {
- _spec.SetField(errorpassthroughrule.FieldDescription, field.TypeString, value)
- }
- if _u.mutation.DescriptionCleared() {
- _spec.ClearField(errorpassthroughrule.FieldDescription, field.TypeString)
- }
- _node = &ErrorPassthroughRule{config: _u.config}
- _spec.Assign = _node.assignValues
- _spec.ScanValues = _node.scanValues
- if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil {
- if _, ok := err.(*sqlgraph.NotFoundError); ok {
- err = &NotFoundError{errorpassthroughrule.Label}
- } else if sqlgraph.IsConstraintError(err) {
- err = &ConstraintError{msg: err.Error(), wrap: err}
- }
- return nil, err
- }
- _u.mutation.done = true
- return _node, nil
- }
|