// Code generated by ent, DO NOT EDIT. package ent import ( "context" "errors" "fmt" "polaris/ent/blocklist" "polaris/ent/predicate" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" ) // BlocklistUpdate is the builder for updating Blocklist entities. type BlocklistUpdate struct { config hooks []Hook mutation *BlocklistMutation } // Where appends a list predicates to the BlocklistUpdate builder. func (bu *BlocklistUpdate) Where(ps ...predicate.Blocklist) *BlocklistUpdate { bu.mutation.Where(ps...) return bu } // SetType sets the "type" field. func (bu *BlocklistUpdate) SetType(b blocklist.Type) *BlocklistUpdate { bu.mutation.SetType(b) return bu } // SetNillableType sets the "type" field if the given value is not nil. func (bu *BlocklistUpdate) SetNillableType(b *blocklist.Type) *BlocklistUpdate { if b != nil { bu.SetType(*b) } return bu } // SetValue sets the "value" field. func (bu *BlocklistUpdate) SetValue(s string) *BlocklistUpdate { bu.mutation.SetValue(s) return bu } // SetNillableValue sets the "value" field if the given value is not nil. func (bu *BlocklistUpdate) SetNillableValue(s *string) *BlocklistUpdate { if s != nil { bu.SetValue(*s) } return bu } // Mutation returns the BlocklistMutation object of the builder. func (bu *BlocklistUpdate) Mutation() *BlocklistMutation { return bu.mutation } // Save executes the query and returns the number of nodes affected by the update operation. func (bu *BlocklistUpdate) Save(ctx context.Context) (int, error) { return withHooks(ctx, bu.sqlSave, bu.mutation, bu.hooks) } // SaveX is like Save, but panics if an error occurs. func (bu *BlocklistUpdate) SaveX(ctx context.Context) int { affected, err := bu.Save(ctx) if err != nil { panic(err) } return affected } // Exec executes the query. func (bu *BlocklistUpdate) Exec(ctx context.Context) error { _, err := bu.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (bu *BlocklistUpdate) ExecX(ctx context.Context) { if err := bu.Exec(ctx); err != nil { panic(err) } } // check runs all checks and user-defined validators on the builder. func (bu *BlocklistUpdate) check() error { if v, ok := bu.mutation.GetType(); ok { if err := blocklist.TypeValidator(v); err != nil { return &ValidationError{Name: "type", err: fmt.Errorf(`ent: validator failed for field "Blocklist.type": %w`, err)} } } return nil } func (bu *BlocklistUpdate) sqlSave(ctx context.Context) (n int, err error) { if err := bu.check(); err != nil { return n, err } _spec := sqlgraph.NewUpdateSpec(blocklist.Table, blocklist.Columns, sqlgraph.NewFieldSpec(blocklist.FieldID, field.TypeInt)) if ps := bu.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { ps[i](selector) } } } if value, ok := bu.mutation.GetType(); ok { _spec.SetField(blocklist.FieldType, field.TypeEnum, value) } if value, ok := bu.mutation.Value(); ok { _spec.SetField(blocklist.FieldValue, field.TypeString, value) } if n, err = sqlgraph.UpdateNodes(ctx, bu.driver, _spec); err != nil { if _, ok := err.(*sqlgraph.NotFoundError); ok { err = &NotFoundError{blocklist.Label} } else if sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } return 0, err } bu.mutation.done = true return n, nil } // BlocklistUpdateOne is the builder for updating a single Blocklist entity. type BlocklistUpdateOne struct { config fields []string hooks []Hook mutation *BlocklistMutation } // SetType sets the "type" field. func (buo *BlocklistUpdateOne) SetType(b blocklist.Type) *BlocklistUpdateOne { buo.mutation.SetType(b) return buo } // SetNillableType sets the "type" field if the given value is not nil. func (buo *BlocklistUpdateOne) SetNillableType(b *blocklist.Type) *BlocklistUpdateOne { if b != nil { buo.SetType(*b) } return buo } // SetValue sets the "value" field. func (buo *BlocklistUpdateOne) SetValue(s string) *BlocklistUpdateOne { buo.mutation.SetValue(s) return buo } // SetNillableValue sets the "value" field if the given value is not nil. func (buo *BlocklistUpdateOne) SetNillableValue(s *string) *BlocklistUpdateOne { if s != nil { buo.SetValue(*s) } return buo } // Mutation returns the BlocklistMutation object of the builder. func (buo *BlocklistUpdateOne) Mutation() *BlocklistMutation { return buo.mutation } // Where appends a list predicates to the BlocklistUpdate builder. func (buo *BlocklistUpdateOne) Where(ps ...predicate.Blocklist) *BlocklistUpdateOne { buo.mutation.Where(ps...) return buo } // Select allows selecting one or more fields (columns) of the returned entity. // The default is selecting all fields defined in the entity schema. func (buo *BlocklistUpdateOne) Select(field string, fields ...string) *BlocklistUpdateOne { buo.fields = append([]string{field}, fields...) return buo } // Save executes the query and returns the updated Blocklist entity. func (buo *BlocklistUpdateOne) Save(ctx context.Context) (*Blocklist, error) { return withHooks(ctx, buo.sqlSave, buo.mutation, buo.hooks) } // SaveX is like Save, but panics if an error occurs. func (buo *BlocklistUpdateOne) SaveX(ctx context.Context) *Blocklist { node, err := buo.Save(ctx) if err != nil { panic(err) } return node } // Exec executes the query on the entity. func (buo *BlocklistUpdateOne) Exec(ctx context.Context) error { _, err := buo.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (buo *BlocklistUpdateOne) ExecX(ctx context.Context) { if err := buo.Exec(ctx); err != nil { panic(err) } } // check runs all checks and user-defined validators on the builder. func (buo *BlocklistUpdateOne) check() error { if v, ok := buo.mutation.GetType(); ok { if err := blocklist.TypeValidator(v); err != nil { return &ValidationError{Name: "type", err: fmt.Errorf(`ent: validator failed for field "Blocklist.type": %w`, err)} } } return nil } func (buo *BlocklistUpdateOne) sqlSave(ctx context.Context) (_node *Blocklist, err error) { if err := buo.check(); err != nil { return _node, err } _spec := sqlgraph.NewUpdateSpec(blocklist.Table, blocklist.Columns, sqlgraph.NewFieldSpec(blocklist.FieldID, field.TypeInt)) id, ok := buo.mutation.ID() if !ok { return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Blocklist.id" for update`)} } _spec.Node.ID.Value = id if fields := buo.fields; len(fields) > 0 { _spec.Node.Columns = make([]string, 0, len(fields)) _spec.Node.Columns = append(_spec.Node.Columns, blocklist.FieldID) for _, f := range fields { if !blocklist.ValidColumn(f) { return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} } if f != blocklist.FieldID { _spec.Node.Columns = append(_spec.Node.Columns, f) } } } if ps := buo.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { ps[i](selector) } } } if value, ok := buo.mutation.GetType(); ok { _spec.SetField(blocklist.FieldType, field.TypeEnum, value) } if value, ok := buo.mutation.Value(); ok { _spec.SetField(blocklist.FieldValue, field.TypeString, value) } _node = &Blocklist{config: buo.config} _spec.Assign = _node.assignValues _spec.ScanValues = _node.scanValues if err = sqlgraph.UpdateNode(ctx, buo.driver, _spec); err != nil { if _, ok := err.(*sqlgraph.NotFoundError); ok { err = &NotFoundError{blocklist.Label} } else if sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } return nil, err } buo.mutation.done = true return _node, nil }