Files
2026-01-28 13:25:18 +08:00

454 lines
12 KiB
Go

// Code generated by ent, DO NOT EDIT.
package ent
import (
"context"
"errors"
"fmt"
"home-vue-go/internal/ent/contact"
"home-vue-go/internal/ent/predicate"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
)
// ContactUpdate is the builder for updating Contact entities.
type ContactUpdate struct {
config
hooks []Hook
mutation *ContactMutation
}
// Where appends a list predicates to the ContactUpdate builder.
func (_u *ContactUpdate) Where(ps ...predicate.Contact) *ContactUpdate {
_u.mutation.Where(ps...)
return _u
}
// SetType sets the "type" field.
func (_u *ContactUpdate) SetType(v string) *ContactUpdate {
_u.mutation.SetType(v)
return _u
}
// SetNillableType sets the "type" field if the given value is not nil.
func (_u *ContactUpdate) SetNillableType(v *string) *ContactUpdate {
if v != nil {
_u.SetType(*v)
}
return _u
}
// SetIcon sets the "icon" field.
func (_u *ContactUpdate) SetIcon(v string) *ContactUpdate {
_u.mutation.SetIcon(v)
return _u
}
// SetNillableIcon sets the "icon" field if the given value is not nil.
func (_u *ContactUpdate) SetNillableIcon(v *string) *ContactUpdate {
if v != nil {
_u.SetIcon(*v)
}
return _u
}
// SetURL sets the "url" field.
func (_u *ContactUpdate) SetURL(v string) *ContactUpdate {
_u.mutation.SetURL(v)
return _u
}
// SetNillableURL sets the "url" field if the given value is not nil.
func (_u *ContactUpdate) SetNillableURL(v *string) *ContactUpdate {
if v != nil {
_u.SetURL(*v)
}
return _u
}
// ClearURL clears the value of the "url" field.
func (_u *ContactUpdate) ClearURL() *ContactUpdate {
_u.mutation.ClearURL()
return _u
}
// SetQrCode sets the "qr_code" field.
func (_u *ContactUpdate) SetQrCode(v string) *ContactUpdate {
_u.mutation.SetQrCode(v)
return _u
}
// SetNillableQrCode sets the "qr_code" field if the given value is not nil.
func (_u *ContactUpdate) SetNillableQrCode(v *string) *ContactUpdate {
if v != nil {
_u.SetQrCode(*v)
}
return _u
}
// ClearQrCode clears the value of the "qr_code" field.
func (_u *ContactUpdate) ClearQrCode() *ContactUpdate {
_u.mutation.ClearQrCode()
return _u
}
// SetHoverColor sets the "hover_color" field.
func (_u *ContactUpdate) SetHoverColor(v string) *ContactUpdate {
_u.mutation.SetHoverColor(v)
return _u
}
// SetNillableHoverColor sets the "hover_color" field if the given value is not nil.
func (_u *ContactUpdate) SetNillableHoverColor(v *string) *ContactUpdate {
if v != nil {
_u.SetHoverColor(*v)
}
return _u
}
// ClearHoverColor clears the value of the "hover_color" field.
func (_u *ContactUpdate) ClearHoverColor() *ContactUpdate {
_u.mutation.ClearHoverColor()
return _u
}
// SetSortOrder sets the "sort_order" field.
func (_u *ContactUpdate) SetSortOrder(v int) *ContactUpdate {
_u.mutation.ResetSortOrder()
_u.mutation.SetSortOrder(v)
return _u
}
// SetNillableSortOrder sets the "sort_order" field if the given value is not nil.
func (_u *ContactUpdate) SetNillableSortOrder(v *int) *ContactUpdate {
if v != nil {
_u.SetSortOrder(*v)
}
return _u
}
// AddSortOrder adds value to the "sort_order" field.
func (_u *ContactUpdate) AddSortOrder(v int) *ContactUpdate {
_u.mutation.AddSortOrder(v)
return _u
}
// Mutation returns the ContactMutation object of the builder.
func (_u *ContactUpdate) Mutation() *ContactMutation {
return _u.mutation
}
// Save executes the query and returns the number of nodes affected by the update operation.
func (_u *ContactUpdate) Save(ctx context.Context) (int, error) {
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (_u *ContactUpdate) SaveX(ctx context.Context) int {
affected, err := _u.Save(ctx)
if err != nil {
panic(err)
}
return affected
}
// Exec executes the query.
func (_u *ContactUpdate) Exec(ctx context.Context) error {
_, err := _u.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_u *ContactUpdate) ExecX(ctx context.Context) {
if err := _u.Exec(ctx); err != nil {
panic(err)
}
}
func (_u *ContactUpdate) sqlSave(ctx context.Context) (_node int, err error) {
_spec := sqlgraph.NewUpdateSpec(contact.Table, contact.Columns, sqlgraph.NewFieldSpec(contact.FieldID, field.TypeInt))
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.GetType(); ok {
_spec.SetField(contact.FieldType, field.TypeString, value)
}
if value, ok := _u.mutation.Icon(); ok {
_spec.SetField(contact.FieldIcon, field.TypeString, value)
}
if value, ok := _u.mutation.URL(); ok {
_spec.SetField(contact.FieldURL, field.TypeString, value)
}
if _u.mutation.URLCleared() {
_spec.ClearField(contact.FieldURL, field.TypeString)
}
if value, ok := _u.mutation.QrCode(); ok {
_spec.SetField(contact.FieldQrCode, field.TypeString, value)
}
if _u.mutation.QrCodeCleared() {
_spec.ClearField(contact.FieldQrCode, field.TypeString)
}
if value, ok := _u.mutation.HoverColor(); ok {
_spec.SetField(contact.FieldHoverColor, field.TypeString, value)
}
if _u.mutation.HoverColorCleared() {
_spec.ClearField(contact.FieldHoverColor, field.TypeString)
}
if value, ok := _u.mutation.SortOrder(); ok {
_spec.SetField(contact.FieldSortOrder, field.TypeInt, value)
}
if value, ok := _u.mutation.AddedSortOrder(); ok {
_spec.AddField(contact.FieldSortOrder, field.TypeInt, value)
}
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{contact.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return 0, err
}
_u.mutation.done = true
return _node, nil
}
// ContactUpdateOne is the builder for updating a single Contact entity.
type ContactUpdateOne struct {
config
fields []string
hooks []Hook
mutation *ContactMutation
}
// SetType sets the "type" field.
func (_u *ContactUpdateOne) SetType(v string) *ContactUpdateOne {
_u.mutation.SetType(v)
return _u
}
// SetNillableType sets the "type" field if the given value is not nil.
func (_u *ContactUpdateOne) SetNillableType(v *string) *ContactUpdateOne {
if v != nil {
_u.SetType(*v)
}
return _u
}
// SetIcon sets the "icon" field.
func (_u *ContactUpdateOne) SetIcon(v string) *ContactUpdateOne {
_u.mutation.SetIcon(v)
return _u
}
// SetNillableIcon sets the "icon" field if the given value is not nil.
func (_u *ContactUpdateOne) SetNillableIcon(v *string) *ContactUpdateOne {
if v != nil {
_u.SetIcon(*v)
}
return _u
}
// SetURL sets the "url" field.
func (_u *ContactUpdateOne) SetURL(v string) *ContactUpdateOne {
_u.mutation.SetURL(v)
return _u
}
// SetNillableURL sets the "url" field if the given value is not nil.
func (_u *ContactUpdateOne) SetNillableURL(v *string) *ContactUpdateOne {
if v != nil {
_u.SetURL(*v)
}
return _u
}
// ClearURL clears the value of the "url" field.
func (_u *ContactUpdateOne) ClearURL() *ContactUpdateOne {
_u.mutation.ClearURL()
return _u
}
// SetQrCode sets the "qr_code" field.
func (_u *ContactUpdateOne) SetQrCode(v string) *ContactUpdateOne {
_u.mutation.SetQrCode(v)
return _u
}
// SetNillableQrCode sets the "qr_code" field if the given value is not nil.
func (_u *ContactUpdateOne) SetNillableQrCode(v *string) *ContactUpdateOne {
if v != nil {
_u.SetQrCode(*v)
}
return _u
}
// ClearQrCode clears the value of the "qr_code" field.
func (_u *ContactUpdateOne) ClearQrCode() *ContactUpdateOne {
_u.mutation.ClearQrCode()
return _u
}
// SetHoverColor sets the "hover_color" field.
func (_u *ContactUpdateOne) SetHoverColor(v string) *ContactUpdateOne {
_u.mutation.SetHoverColor(v)
return _u
}
// SetNillableHoverColor sets the "hover_color" field if the given value is not nil.
func (_u *ContactUpdateOne) SetNillableHoverColor(v *string) *ContactUpdateOne {
if v != nil {
_u.SetHoverColor(*v)
}
return _u
}
// ClearHoverColor clears the value of the "hover_color" field.
func (_u *ContactUpdateOne) ClearHoverColor() *ContactUpdateOne {
_u.mutation.ClearHoverColor()
return _u
}
// SetSortOrder sets the "sort_order" field.
func (_u *ContactUpdateOne) SetSortOrder(v int) *ContactUpdateOne {
_u.mutation.ResetSortOrder()
_u.mutation.SetSortOrder(v)
return _u
}
// SetNillableSortOrder sets the "sort_order" field if the given value is not nil.
func (_u *ContactUpdateOne) SetNillableSortOrder(v *int) *ContactUpdateOne {
if v != nil {
_u.SetSortOrder(*v)
}
return _u
}
// AddSortOrder adds value to the "sort_order" field.
func (_u *ContactUpdateOne) AddSortOrder(v int) *ContactUpdateOne {
_u.mutation.AddSortOrder(v)
return _u
}
// Mutation returns the ContactMutation object of the builder.
func (_u *ContactUpdateOne) Mutation() *ContactMutation {
return _u.mutation
}
// Where appends a list predicates to the ContactUpdate builder.
func (_u *ContactUpdateOne) Where(ps ...predicate.Contact) *ContactUpdateOne {
_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 *ContactUpdateOne) Select(field string, fields ...string) *ContactUpdateOne {
_u.fields = append([]string{field}, fields...)
return _u
}
// Save executes the query and returns the updated Contact entity.
func (_u *ContactUpdateOne) Save(ctx context.Context) (*Contact, error) {
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (_u *ContactUpdateOne) SaveX(ctx context.Context) *Contact {
node, err := _u.Save(ctx)
if err != nil {
panic(err)
}
return node
}
// Exec executes the query on the entity.
func (_u *ContactUpdateOne) Exec(ctx context.Context) error {
_, err := _u.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_u *ContactUpdateOne) ExecX(ctx context.Context) {
if err := _u.Exec(ctx); err != nil {
panic(err)
}
}
func (_u *ContactUpdateOne) sqlSave(ctx context.Context) (_node *Contact, err error) {
_spec := sqlgraph.NewUpdateSpec(contact.Table, contact.Columns, sqlgraph.NewFieldSpec(contact.FieldID, field.TypeInt))
id, ok := _u.mutation.ID()
if !ok {
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Contact.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, contact.FieldID)
for _, f := range fields {
if !contact.ValidColumn(f) {
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
}
if f != contact.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.GetType(); ok {
_spec.SetField(contact.FieldType, field.TypeString, value)
}
if value, ok := _u.mutation.Icon(); ok {
_spec.SetField(contact.FieldIcon, field.TypeString, value)
}
if value, ok := _u.mutation.URL(); ok {
_spec.SetField(contact.FieldURL, field.TypeString, value)
}
if _u.mutation.URLCleared() {
_spec.ClearField(contact.FieldURL, field.TypeString)
}
if value, ok := _u.mutation.QrCode(); ok {
_spec.SetField(contact.FieldQrCode, field.TypeString, value)
}
if _u.mutation.QrCodeCleared() {
_spec.ClearField(contact.FieldQrCode, field.TypeString)
}
if value, ok := _u.mutation.HoverColor(); ok {
_spec.SetField(contact.FieldHoverColor, field.TypeString, value)
}
if _u.mutation.HoverColorCleared() {
_spec.ClearField(contact.FieldHoverColor, field.TypeString)
}
if value, ok := _u.mutation.SortOrder(); ok {
_spec.SetField(contact.FieldSortOrder, field.TypeInt, value)
}
if value, ok := _u.mutation.AddedSortOrder(); ok {
_spec.AddField(contact.FieldSortOrder, field.TypeInt, value)
}
_node = &Contact{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{contact.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return nil, err
}
_u.mutation.done = true
return _node, nil
}