// Code generated by ent, DO NOT EDIT. package ent import ( "context" "errors" "fmt" "voidraft/internal/models/ent/document" "voidraft/internal/models/ent/predicate" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" ) // DocumentUpdate is the builder for updating Document entities. type DocumentUpdate struct { config hooks []Hook mutation *DocumentMutation modifiers []func(*sql.UpdateBuilder) } // Where appends a list predicates to the DocumentUpdate builder. func (_u *DocumentUpdate) Where(ps ...predicate.Document) *DocumentUpdate { _u.mutation.Where(ps...) return _u } // SetUpdatedAt sets the "updated_at" field. func (_u *DocumentUpdate) SetUpdatedAt(v string) *DocumentUpdate { _u.mutation.SetUpdatedAt(v) return _u } // SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. func (_u *DocumentUpdate) SetNillableUpdatedAt(v *string) *DocumentUpdate { if v != nil { _u.SetUpdatedAt(*v) } return _u } // SetDeletedAt sets the "deleted_at" field. func (_u *DocumentUpdate) SetDeletedAt(v string) *DocumentUpdate { _u.mutation.SetDeletedAt(v) return _u } // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil. func (_u *DocumentUpdate) SetNillableDeletedAt(v *string) *DocumentUpdate { if v != nil { _u.SetDeletedAt(*v) } return _u } // ClearDeletedAt clears the value of the "deleted_at" field. func (_u *DocumentUpdate) ClearDeletedAt() *DocumentUpdate { _u.mutation.ClearDeletedAt() return _u } // SetTitle sets the "title" field. func (_u *DocumentUpdate) SetTitle(v string) *DocumentUpdate { _u.mutation.SetTitle(v) return _u } // SetNillableTitle sets the "title" field if the given value is not nil. func (_u *DocumentUpdate) SetNillableTitle(v *string) *DocumentUpdate { if v != nil { _u.SetTitle(*v) } return _u } // SetContent sets the "content" field. func (_u *DocumentUpdate) SetContent(v string) *DocumentUpdate { _u.mutation.SetContent(v) return _u } // SetNillableContent sets the "content" field if the given value is not nil. func (_u *DocumentUpdate) SetNillableContent(v *string) *DocumentUpdate { if v != nil { _u.SetContent(*v) } return _u } // ClearContent clears the value of the "content" field. func (_u *DocumentUpdate) ClearContent() *DocumentUpdate { _u.mutation.ClearContent() return _u } // SetLocked sets the "locked" field. func (_u *DocumentUpdate) SetLocked(v bool) *DocumentUpdate { _u.mutation.SetLocked(v) return _u } // SetNillableLocked sets the "locked" field if the given value is not nil. func (_u *DocumentUpdate) SetNillableLocked(v *bool) *DocumentUpdate { if v != nil { _u.SetLocked(*v) } return _u } // Mutation returns the DocumentMutation object of the builder. func (_u *DocumentUpdate) Mutation() *DocumentMutation { return _u.mutation } // Save executes the query and returns the number of nodes affected by the update operation. func (_u *DocumentUpdate) 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 *DocumentUpdate) SaveX(ctx context.Context) int { affected, err := _u.Save(ctx) if err != nil { panic(err) } return affected } // Exec executes the query. func (_u *DocumentUpdate) Exec(ctx context.Context) error { _, err := _u.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (_u *DocumentUpdate) ExecX(ctx context.Context) { if err := _u.Exec(ctx); err != nil { panic(err) } } // check runs all checks and user-defined validators on the builder. func (_u *DocumentUpdate) check() error { if v, ok := _u.mutation.Title(); ok { if err := document.TitleValidator(v); err != nil { return &ValidationError{Name: "title", err: fmt.Errorf(`ent: validator failed for field "Document.title": %w`, err)} } } return nil } // Modify adds a statement modifier for attaching custom logic to the UPDATE statement. func (_u *DocumentUpdate) Modify(modifiers ...func(u *sql.UpdateBuilder)) *DocumentUpdate { _u.modifiers = append(_u.modifiers, modifiers...) return _u } func (_u *DocumentUpdate) sqlSave(ctx context.Context) (_node int, err error) { if err := _u.check(); err != nil { return _node, err } _spec := sqlgraph.NewUpdateSpec(document.Table, document.Columns, sqlgraph.NewFieldSpec(document.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.UpdatedAt(); ok { _spec.SetField(document.FieldUpdatedAt, field.TypeString, value) } if value, ok := _u.mutation.DeletedAt(); ok { _spec.SetField(document.FieldDeletedAt, field.TypeString, value) } if _u.mutation.DeletedAtCleared() { _spec.ClearField(document.FieldDeletedAt, field.TypeString) } if value, ok := _u.mutation.Title(); ok { _spec.SetField(document.FieldTitle, field.TypeString, value) } if value, ok := _u.mutation.Content(); ok { _spec.SetField(document.FieldContent, field.TypeString, value) } if _u.mutation.ContentCleared() { _spec.ClearField(document.FieldContent, field.TypeString) } if value, ok := _u.mutation.Locked(); ok { _spec.SetField(document.FieldLocked, field.TypeBool, value) } _spec.AddModifiers(_u.modifiers...) if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil { if _, ok := err.(*sqlgraph.NotFoundError); ok { err = &NotFoundError{document.Label} } else if sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } return 0, err } _u.mutation.done = true return _node, nil } // DocumentUpdateOne is the builder for updating a single Document entity. type DocumentUpdateOne struct { config fields []string hooks []Hook mutation *DocumentMutation modifiers []func(*sql.UpdateBuilder) } // SetUpdatedAt sets the "updated_at" field. func (_u *DocumentUpdateOne) SetUpdatedAt(v string) *DocumentUpdateOne { _u.mutation.SetUpdatedAt(v) return _u } // SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. func (_u *DocumentUpdateOne) SetNillableUpdatedAt(v *string) *DocumentUpdateOne { if v != nil { _u.SetUpdatedAt(*v) } return _u } // SetDeletedAt sets the "deleted_at" field. func (_u *DocumentUpdateOne) SetDeletedAt(v string) *DocumentUpdateOne { _u.mutation.SetDeletedAt(v) return _u } // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil. func (_u *DocumentUpdateOne) SetNillableDeletedAt(v *string) *DocumentUpdateOne { if v != nil { _u.SetDeletedAt(*v) } return _u } // ClearDeletedAt clears the value of the "deleted_at" field. func (_u *DocumentUpdateOne) ClearDeletedAt() *DocumentUpdateOne { _u.mutation.ClearDeletedAt() return _u } // SetTitle sets the "title" field. func (_u *DocumentUpdateOne) SetTitle(v string) *DocumentUpdateOne { _u.mutation.SetTitle(v) return _u } // SetNillableTitle sets the "title" field if the given value is not nil. func (_u *DocumentUpdateOne) SetNillableTitle(v *string) *DocumentUpdateOne { if v != nil { _u.SetTitle(*v) } return _u } // SetContent sets the "content" field. func (_u *DocumentUpdateOne) SetContent(v string) *DocumentUpdateOne { _u.mutation.SetContent(v) return _u } // SetNillableContent sets the "content" field if the given value is not nil. func (_u *DocumentUpdateOne) SetNillableContent(v *string) *DocumentUpdateOne { if v != nil { _u.SetContent(*v) } return _u } // ClearContent clears the value of the "content" field. func (_u *DocumentUpdateOne) ClearContent() *DocumentUpdateOne { _u.mutation.ClearContent() return _u } // SetLocked sets the "locked" field. func (_u *DocumentUpdateOne) SetLocked(v bool) *DocumentUpdateOne { _u.mutation.SetLocked(v) return _u } // SetNillableLocked sets the "locked" field if the given value is not nil. func (_u *DocumentUpdateOne) SetNillableLocked(v *bool) *DocumentUpdateOne { if v != nil { _u.SetLocked(*v) } return _u } // Mutation returns the DocumentMutation object of the builder. func (_u *DocumentUpdateOne) Mutation() *DocumentMutation { return _u.mutation } // Where appends a list predicates to the DocumentUpdate builder. func (_u *DocumentUpdateOne) Where(ps ...predicate.Document) *DocumentUpdateOne { _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 *DocumentUpdateOne) Select(field string, fields ...string) *DocumentUpdateOne { _u.fields = append([]string{field}, fields...) return _u } // Save executes the query and returns the updated Document entity. func (_u *DocumentUpdateOne) Save(ctx context.Context) (*Document, error) { return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) } // SaveX is like Save, but panics if an error occurs. func (_u *DocumentUpdateOne) SaveX(ctx context.Context) *Document { node, err := _u.Save(ctx) if err != nil { panic(err) } return node } // Exec executes the query on the entity. func (_u *DocumentUpdateOne) Exec(ctx context.Context) error { _, err := _u.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (_u *DocumentUpdateOne) ExecX(ctx context.Context) { if err := _u.Exec(ctx); err != nil { panic(err) } } // check runs all checks and user-defined validators on the builder. func (_u *DocumentUpdateOne) check() error { if v, ok := _u.mutation.Title(); ok { if err := document.TitleValidator(v); err != nil { return &ValidationError{Name: "title", err: fmt.Errorf(`ent: validator failed for field "Document.title": %w`, err)} } } return nil } // Modify adds a statement modifier for attaching custom logic to the UPDATE statement. func (_u *DocumentUpdateOne) Modify(modifiers ...func(u *sql.UpdateBuilder)) *DocumentUpdateOne { _u.modifiers = append(_u.modifiers, modifiers...) return _u } func (_u *DocumentUpdateOne) sqlSave(ctx context.Context) (_node *Document, err error) { if err := _u.check(); err != nil { return _node, err } _spec := sqlgraph.NewUpdateSpec(document.Table, document.Columns, sqlgraph.NewFieldSpec(document.FieldID, field.TypeInt)) id, ok := _u.mutation.ID() if !ok { return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Document.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, document.FieldID) for _, f := range fields { if !document.ValidColumn(f) { return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} } if f != document.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(document.FieldUpdatedAt, field.TypeString, value) } if value, ok := _u.mutation.DeletedAt(); ok { _spec.SetField(document.FieldDeletedAt, field.TypeString, value) } if _u.mutation.DeletedAtCleared() { _spec.ClearField(document.FieldDeletedAt, field.TypeString) } if value, ok := _u.mutation.Title(); ok { _spec.SetField(document.FieldTitle, field.TypeString, value) } if value, ok := _u.mutation.Content(); ok { _spec.SetField(document.FieldContent, field.TypeString, value) } if _u.mutation.ContentCleared() { _spec.ClearField(document.FieldContent, field.TypeString) } if value, ok := _u.mutation.Locked(); ok { _spec.SetField(document.FieldLocked, field.TypeBool, value) } _spec.AddModifiers(_u.modifiers...) _node = &Document{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{document.Label} } else if sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } return nil, err } _u.mutation.done = true return _node, nil }