// 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/schema/field" "leafdev.top/leaf/rag/ent/document" "leafdev.top/leaf/rag/ent/predicate" ) // DocumentUpdate is the builder for updating Document entities. type DocumentUpdate struct { config hooks []Hook mutation *DocumentMutation } // Where appends a list predicates to the DocumentUpdate builder. func (du *DocumentUpdate) Where(ps ...predicate.Document) *DocumentUpdate { du.mutation.Where(ps...) return du } // SetName sets the "name" field. func (du *DocumentUpdate) SetName(s string) *DocumentUpdate { du.mutation.SetName(s) return du } // SetNillableName sets the "name" field if the given value is not nil. func (du *DocumentUpdate) SetNillableName(s *string) *DocumentUpdate { if s != nil { du.SetName(*s) } return du } // SetUserID sets the "user_id" field. func (du *DocumentUpdate) SetUserID(s string) *DocumentUpdate { du.mutation.SetUserID(s) return du } // SetNillableUserID sets the "user_id" field if the given value is not nil. func (du *DocumentUpdate) SetNillableUserID(s *string) *DocumentUpdate { if s != nil { du.SetUserID(*s) } return du } // SetLibraryID sets the "library_id" field. func (du *DocumentUpdate) SetLibraryID(i int64) *DocumentUpdate { du.mutation.ResetLibraryID() du.mutation.SetLibraryID(i) return du } // SetNillableLibraryID sets the "library_id" field if the given value is not nil. func (du *DocumentUpdate) SetNillableLibraryID(i *int64) *DocumentUpdate { if i != nil { du.SetLibraryID(*i) } return du } // AddLibraryID adds i to the "library_id" field. func (du *DocumentUpdate) AddLibraryID(i int64) *DocumentUpdate { du.mutation.AddLibraryID(i) return du } // SetCreatedAt sets the "created_at" field. func (du *DocumentUpdate) SetCreatedAt(t time.Time) *DocumentUpdate { du.mutation.SetCreatedAt(t) return du } // SetNillableCreatedAt sets the "created_at" field if the given value is not nil. func (du *DocumentUpdate) SetNillableCreatedAt(t *time.Time) *DocumentUpdate { if t != nil { du.SetCreatedAt(*t) } return du } // SetUpdatedAt sets the "updated_at" field. func (du *DocumentUpdate) SetUpdatedAt(t time.Time) *DocumentUpdate { du.mutation.SetUpdatedAt(t) return du } // SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. func (du *DocumentUpdate) SetNillableUpdatedAt(t *time.Time) *DocumentUpdate { if t != nil { du.SetUpdatedAt(*t) } return du } // Mutation returns the DocumentMutation object of the builder. func (du *DocumentUpdate) Mutation() *DocumentMutation { return du.mutation } // Save executes the query and returns the number of nodes affected by the update operation. func (du *DocumentUpdate) Save(ctx context.Context) (int, error) { return withHooks(ctx, du.sqlSave, du.mutation, du.hooks) } // SaveX is like Save, but panics if an error occurs. func (du *DocumentUpdate) SaveX(ctx context.Context) int { affected, err := du.Save(ctx) if err != nil { panic(err) } return affected } // Exec executes the query. func (du *DocumentUpdate) Exec(ctx context.Context) error { _, err := du.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (du *DocumentUpdate) ExecX(ctx context.Context) { if err := du.Exec(ctx); err != nil { panic(err) } } func (du *DocumentUpdate) sqlSave(ctx context.Context) (n int, err error) { _spec := sqlgraph.NewUpdateSpec(document.Table, document.Columns, sqlgraph.NewFieldSpec(document.FieldID, field.TypeInt)) if ps := du.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { ps[i](selector) } } } if value, ok := du.mutation.Name(); ok { _spec.SetField(document.FieldName, field.TypeString, value) } if value, ok := du.mutation.UserID(); ok { _spec.SetField(document.FieldUserID, field.TypeString, value) } if value, ok := du.mutation.LibraryID(); ok { _spec.SetField(document.FieldLibraryID, field.TypeInt64, value) } if value, ok := du.mutation.AddedLibraryID(); ok { _spec.AddField(document.FieldLibraryID, field.TypeInt64, value) } if value, ok := du.mutation.CreatedAt(); ok { _spec.SetField(document.FieldCreatedAt, field.TypeTime, value) } if value, ok := du.mutation.UpdatedAt(); ok { _spec.SetField(document.FieldUpdatedAt, field.TypeTime, value) } if n, err = sqlgraph.UpdateNodes(ctx, du.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 } du.mutation.done = true return n, nil } // DocumentUpdateOne is the builder for updating a single Document entity. type DocumentUpdateOne struct { config fields []string hooks []Hook mutation *DocumentMutation } // SetName sets the "name" field. func (duo *DocumentUpdateOne) SetName(s string) *DocumentUpdateOne { duo.mutation.SetName(s) return duo } // SetNillableName sets the "name" field if the given value is not nil. func (duo *DocumentUpdateOne) SetNillableName(s *string) *DocumentUpdateOne { if s != nil { duo.SetName(*s) } return duo } // SetUserID sets the "user_id" field. func (duo *DocumentUpdateOne) SetUserID(s string) *DocumentUpdateOne { duo.mutation.SetUserID(s) return duo } // SetNillableUserID sets the "user_id" field if the given value is not nil. func (duo *DocumentUpdateOne) SetNillableUserID(s *string) *DocumentUpdateOne { if s != nil { duo.SetUserID(*s) } return duo } // SetLibraryID sets the "library_id" field. func (duo *DocumentUpdateOne) SetLibraryID(i int64) *DocumentUpdateOne { duo.mutation.ResetLibraryID() duo.mutation.SetLibraryID(i) return duo } // SetNillableLibraryID sets the "library_id" field if the given value is not nil. func (duo *DocumentUpdateOne) SetNillableLibraryID(i *int64) *DocumentUpdateOne { if i != nil { duo.SetLibraryID(*i) } return duo } // AddLibraryID adds i to the "library_id" field. func (duo *DocumentUpdateOne) AddLibraryID(i int64) *DocumentUpdateOne { duo.mutation.AddLibraryID(i) return duo } // SetCreatedAt sets the "created_at" field. func (duo *DocumentUpdateOne) SetCreatedAt(t time.Time) *DocumentUpdateOne { duo.mutation.SetCreatedAt(t) return duo } // SetNillableCreatedAt sets the "created_at" field if the given value is not nil. func (duo *DocumentUpdateOne) SetNillableCreatedAt(t *time.Time) *DocumentUpdateOne { if t != nil { duo.SetCreatedAt(*t) } return duo } // SetUpdatedAt sets the "updated_at" field. func (duo *DocumentUpdateOne) SetUpdatedAt(t time.Time) *DocumentUpdateOne { duo.mutation.SetUpdatedAt(t) return duo } // SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. func (duo *DocumentUpdateOne) SetNillableUpdatedAt(t *time.Time) *DocumentUpdateOne { if t != nil { duo.SetUpdatedAt(*t) } return duo } // Mutation returns the DocumentMutation object of the builder. func (duo *DocumentUpdateOne) Mutation() *DocumentMutation { return duo.mutation } // Where appends a list predicates to the DocumentUpdate builder. func (duo *DocumentUpdateOne) Where(ps ...predicate.Document) *DocumentUpdateOne { duo.mutation.Where(ps...) return duo } // Select allows selecting one or more fields (columns) of the returned entity. // The default is selecting all fields defined in the entity schema. func (duo *DocumentUpdateOne) Select(field string, fields ...string) *DocumentUpdateOne { duo.fields = append([]string{field}, fields...) return duo } // Save executes the query and returns the updated Document entity. func (duo *DocumentUpdateOne) Save(ctx context.Context) (*Document, error) { return withHooks(ctx, duo.sqlSave, duo.mutation, duo.hooks) } // SaveX is like Save, but panics if an error occurs. func (duo *DocumentUpdateOne) SaveX(ctx context.Context) *Document { node, err := duo.Save(ctx) if err != nil { panic(err) } return node } // Exec executes the query on the entity. func (duo *DocumentUpdateOne) Exec(ctx context.Context) error { _, err := duo.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (duo *DocumentUpdateOne) ExecX(ctx context.Context) { if err := duo.Exec(ctx); err != nil { panic(err) } } func (duo *DocumentUpdateOne) sqlSave(ctx context.Context) (_node *Document, err error) { _spec := sqlgraph.NewUpdateSpec(document.Table, document.Columns, sqlgraph.NewFieldSpec(document.FieldID, field.TypeInt)) id, ok := duo.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 := duo.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 := duo.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { ps[i](selector) } } } if value, ok := duo.mutation.Name(); ok { _spec.SetField(document.FieldName, field.TypeString, value) } if value, ok := duo.mutation.UserID(); ok { _spec.SetField(document.FieldUserID, field.TypeString, value) } if value, ok := duo.mutation.LibraryID(); ok { _spec.SetField(document.FieldLibraryID, field.TypeInt64, value) } if value, ok := duo.mutation.AddedLibraryID(); ok { _spec.AddField(document.FieldLibraryID, field.TypeInt64, value) } if value, ok := duo.mutation.CreatedAt(); ok { _spec.SetField(document.FieldCreatedAt, field.TypeTime, value) } if value, ok := duo.mutation.UpdatedAt(); ok { _spec.SetField(document.FieldUpdatedAt, field.TypeTime, value) } _node = &Document{config: duo.config} _spec.Assign = _node.assignValues _spec.ScanValues = _node.scanValues if err = sqlgraph.UpdateNode(ctx, duo.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 } duo.mutation.done = true return _node, nil }