rag/ent/documentblock_update.go

618 lines
18 KiB
Go
Raw Normal View History

// 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/documentblock"
"leafdev.top/leaf/rag/ent/predicate"
)
// DocumentBlockUpdate is the builder for updating DocumentBlock entities.
type DocumentBlockUpdate struct {
config
hooks []Hook
mutation *DocumentBlockMutation
}
// Where appends a list predicates to the DocumentBlockUpdate builder.
func (dbu *DocumentBlockUpdate) Where(ps ...predicate.DocumentBlock) *DocumentBlockUpdate {
dbu.mutation.Where(ps...)
return dbu
}
// SetName sets the "name" field.
func (dbu *DocumentBlockUpdate) SetName(s string) *DocumentBlockUpdate {
dbu.mutation.SetName(s)
return dbu
}
// SetNillableName sets the "name" field if the given value is not nil.
func (dbu *DocumentBlockUpdate) SetNillableName(s *string) *DocumentBlockUpdate {
if s != nil {
dbu.SetName(*s)
}
return dbu
}
// SetContent sets the "content" field.
func (dbu *DocumentBlockUpdate) SetContent(s string) *DocumentBlockUpdate {
dbu.mutation.SetContent(s)
return dbu
}
// SetNillableContent sets the "content" field if the given value is not nil.
func (dbu *DocumentBlockUpdate) SetNillableContent(s *string) *DocumentBlockUpdate {
if s != nil {
dbu.SetContent(*s)
}
return dbu
}
// SetOrder sets the "order" field.
func (dbu *DocumentBlockUpdate) SetOrder(i int) *DocumentBlockUpdate {
dbu.mutation.ResetOrder()
dbu.mutation.SetOrder(i)
return dbu
}
// SetNillableOrder sets the "order" field if the given value is not nil.
func (dbu *DocumentBlockUpdate) SetNillableOrder(i *int) *DocumentBlockUpdate {
if i != nil {
dbu.SetOrder(*i)
}
return dbu
}
// AddOrder adds i to the "order" field.
func (dbu *DocumentBlockUpdate) AddOrder(i int) *DocumentBlockUpdate {
dbu.mutation.AddOrder(i)
return dbu
}
// SetDocumentID sets the "document_id" field.
func (dbu *DocumentBlockUpdate) SetDocumentID(i int) *DocumentBlockUpdate {
dbu.mutation.ResetDocumentID()
dbu.mutation.SetDocumentID(i)
return dbu
}
// SetNillableDocumentID sets the "document_id" field if the given value is not nil.
func (dbu *DocumentBlockUpdate) SetNillableDocumentID(i *int) *DocumentBlockUpdate {
if i != nil {
dbu.SetDocumentID(*i)
}
return dbu
}
// AddDocumentID adds i to the "document_id" field.
func (dbu *DocumentBlockUpdate) AddDocumentID(i int) *DocumentBlockUpdate {
dbu.mutation.AddDocumentID(i)
return dbu
}
// SetUserID sets the "user_id" field.
func (dbu *DocumentBlockUpdate) SetUserID(s string) *DocumentBlockUpdate {
dbu.mutation.SetUserID(s)
return dbu
}
// SetNillableUserID sets the "user_id" field if the given value is not nil.
func (dbu *DocumentBlockUpdate) SetNillableUserID(s *string) *DocumentBlockUpdate {
if s != nil {
dbu.SetUserID(*s)
}
return dbu
}
// SetCreatedAt sets the "created_at" field.
func (dbu *DocumentBlockUpdate) SetCreatedAt(t time.Time) *DocumentBlockUpdate {
dbu.mutation.SetCreatedAt(t)
return dbu
}
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
func (dbu *DocumentBlockUpdate) SetNillableCreatedAt(t *time.Time) *DocumentBlockUpdate {
if t != nil {
dbu.SetCreatedAt(*t)
}
return dbu
}
// SetUpdatedAt sets the "updated_at" field.
func (dbu *DocumentBlockUpdate) SetUpdatedAt(t time.Time) *DocumentBlockUpdate {
dbu.mutation.SetUpdatedAt(t)
return dbu
}
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
func (dbu *DocumentBlockUpdate) SetNillableUpdatedAt(t *time.Time) *DocumentBlockUpdate {
if t != nil {
dbu.SetUpdatedAt(*t)
}
return dbu
}
// AddDocumentIDs adds the "document" edge to the Document entity by IDs.
func (dbu *DocumentBlockUpdate) AddDocumentIDs(ids ...int) *DocumentBlockUpdate {
dbu.mutation.AddDocumentIDs(ids...)
return dbu
}
// AddDocument adds the "document" edges to the Document entity.
func (dbu *DocumentBlockUpdate) AddDocument(d ...*Document) *DocumentBlockUpdate {
ids := make([]int, len(d))
for i := range d {
ids[i] = d[i].ID
}
return dbu.AddDocumentIDs(ids...)
}
// Mutation returns the DocumentBlockMutation object of the builder.
func (dbu *DocumentBlockUpdate) Mutation() *DocumentBlockMutation {
return dbu.mutation
}
// ClearDocument clears all "document" edges to the Document entity.
func (dbu *DocumentBlockUpdate) ClearDocument() *DocumentBlockUpdate {
dbu.mutation.ClearDocument()
return dbu
}
// RemoveDocumentIDs removes the "document" edge to Document entities by IDs.
func (dbu *DocumentBlockUpdate) RemoveDocumentIDs(ids ...int) *DocumentBlockUpdate {
dbu.mutation.RemoveDocumentIDs(ids...)
return dbu
}
// RemoveDocument removes "document" edges to Document entities.
func (dbu *DocumentBlockUpdate) RemoveDocument(d ...*Document) *DocumentBlockUpdate {
ids := make([]int, len(d))
for i := range d {
ids[i] = d[i].ID
}
return dbu.RemoveDocumentIDs(ids...)
}
// Save executes the query and returns the number of nodes affected by the update operation.
func (dbu *DocumentBlockUpdate) Save(ctx context.Context) (int, error) {
return withHooks(ctx, dbu.sqlSave, dbu.mutation, dbu.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (dbu *DocumentBlockUpdate) SaveX(ctx context.Context) int {
affected, err := dbu.Save(ctx)
if err != nil {
panic(err)
}
return affected
}
// Exec executes the query.
func (dbu *DocumentBlockUpdate) Exec(ctx context.Context) error {
_, err := dbu.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (dbu *DocumentBlockUpdate) ExecX(ctx context.Context) {
if err := dbu.Exec(ctx); err != nil {
panic(err)
}
}
func (dbu *DocumentBlockUpdate) sqlSave(ctx context.Context) (n int, err error) {
_spec := sqlgraph.NewUpdateSpec(documentblock.Table, documentblock.Columns, sqlgraph.NewFieldSpec(documentblock.FieldID, field.TypeInt))
if ps := dbu.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := dbu.mutation.Name(); ok {
_spec.SetField(documentblock.FieldName, field.TypeString, value)
}
if value, ok := dbu.mutation.Content(); ok {
_spec.SetField(documentblock.FieldContent, field.TypeString, value)
}
if value, ok := dbu.mutation.Order(); ok {
_spec.SetField(documentblock.FieldOrder, field.TypeInt, value)
}
if value, ok := dbu.mutation.AddedOrder(); ok {
_spec.AddField(documentblock.FieldOrder, field.TypeInt, value)
}
if value, ok := dbu.mutation.DocumentID(); ok {
_spec.SetField(documentblock.FieldDocumentID, field.TypeInt, value)
}
if value, ok := dbu.mutation.AddedDocumentID(); ok {
_spec.AddField(documentblock.FieldDocumentID, field.TypeInt, value)
}
if value, ok := dbu.mutation.UserID(); ok {
_spec.SetField(documentblock.FieldUserID, field.TypeString, value)
}
if value, ok := dbu.mutation.CreatedAt(); ok {
_spec.SetField(documentblock.FieldCreatedAt, field.TypeTime, value)
}
if value, ok := dbu.mutation.UpdatedAt(); ok {
_spec.SetField(documentblock.FieldUpdatedAt, field.TypeTime, value)
}
if dbu.mutation.DocumentCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: documentblock.DocumentTable,
Columns: []string{documentblock.DocumentColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(document.FieldID, field.TypeInt),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := dbu.mutation.RemovedDocumentIDs(); len(nodes) > 0 && !dbu.mutation.DocumentCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: documentblock.DocumentTable,
Columns: []string{documentblock.DocumentColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(document.FieldID, field.TypeInt),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := dbu.mutation.DocumentIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: documentblock.DocumentTable,
Columns: []string{documentblock.DocumentColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(document.FieldID, field.TypeInt),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if n, err = sqlgraph.UpdateNodes(ctx, dbu.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{documentblock.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return 0, err
}
dbu.mutation.done = true
return n, nil
}
// DocumentBlockUpdateOne is the builder for updating a single DocumentBlock entity.
type DocumentBlockUpdateOne struct {
config
fields []string
hooks []Hook
mutation *DocumentBlockMutation
}
// SetName sets the "name" field.
func (dbuo *DocumentBlockUpdateOne) SetName(s string) *DocumentBlockUpdateOne {
dbuo.mutation.SetName(s)
return dbuo
}
// SetNillableName sets the "name" field if the given value is not nil.
func (dbuo *DocumentBlockUpdateOne) SetNillableName(s *string) *DocumentBlockUpdateOne {
if s != nil {
dbuo.SetName(*s)
}
return dbuo
}
// SetContent sets the "content" field.
func (dbuo *DocumentBlockUpdateOne) SetContent(s string) *DocumentBlockUpdateOne {
dbuo.mutation.SetContent(s)
return dbuo
}
// SetNillableContent sets the "content" field if the given value is not nil.
func (dbuo *DocumentBlockUpdateOne) SetNillableContent(s *string) *DocumentBlockUpdateOne {
if s != nil {
dbuo.SetContent(*s)
}
return dbuo
}
// SetOrder sets the "order" field.
func (dbuo *DocumentBlockUpdateOne) SetOrder(i int) *DocumentBlockUpdateOne {
dbuo.mutation.ResetOrder()
dbuo.mutation.SetOrder(i)
return dbuo
}
// SetNillableOrder sets the "order" field if the given value is not nil.
func (dbuo *DocumentBlockUpdateOne) SetNillableOrder(i *int) *DocumentBlockUpdateOne {
if i != nil {
dbuo.SetOrder(*i)
}
return dbuo
}
// AddOrder adds i to the "order" field.
func (dbuo *DocumentBlockUpdateOne) AddOrder(i int) *DocumentBlockUpdateOne {
dbuo.mutation.AddOrder(i)
return dbuo
}
// SetDocumentID sets the "document_id" field.
func (dbuo *DocumentBlockUpdateOne) SetDocumentID(i int) *DocumentBlockUpdateOne {
dbuo.mutation.ResetDocumentID()
dbuo.mutation.SetDocumentID(i)
return dbuo
}
// SetNillableDocumentID sets the "document_id" field if the given value is not nil.
func (dbuo *DocumentBlockUpdateOne) SetNillableDocumentID(i *int) *DocumentBlockUpdateOne {
if i != nil {
dbuo.SetDocumentID(*i)
}
return dbuo
}
// AddDocumentID adds i to the "document_id" field.
func (dbuo *DocumentBlockUpdateOne) AddDocumentID(i int) *DocumentBlockUpdateOne {
dbuo.mutation.AddDocumentID(i)
return dbuo
}
// SetUserID sets the "user_id" field.
func (dbuo *DocumentBlockUpdateOne) SetUserID(s string) *DocumentBlockUpdateOne {
dbuo.mutation.SetUserID(s)
return dbuo
}
// SetNillableUserID sets the "user_id" field if the given value is not nil.
func (dbuo *DocumentBlockUpdateOne) SetNillableUserID(s *string) *DocumentBlockUpdateOne {
if s != nil {
dbuo.SetUserID(*s)
}
return dbuo
}
// SetCreatedAt sets the "created_at" field.
func (dbuo *DocumentBlockUpdateOne) SetCreatedAt(t time.Time) *DocumentBlockUpdateOne {
dbuo.mutation.SetCreatedAt(t)
return dbuo
}
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
func (dbuo *DocumentBlockUpdateOne) SetNillableCreatedAt(t *time.Time) *DocumentBlockUpdateOne {
if t != nil {
dbuo.SetCreatedAt(*t)
}
return dbuo
}
// SetUpdatedAt sets the "updated_at" field.
func (dbuo *DocumentBlockUpdateOne) SetUpdatedAt(t time.Time) *DocumentBlockUpdateOne {
dbuo.mutation.SetUpdatedAt(t)
return dbuo
}
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
func (dbuo *DocumentBlockUpdateOne) SetNillableUpdatedAt(t *time.Time) *DocumentBlockUpdateOne {
if t != nil {
dbuo.SetUpdatedAt(*t)
}
return dbuo
}
// AddDocumentIDs adds the "document" edge to the Document entity by IDs.
func (dbuo *DocumentBlockUpdateOne) AddDocumentIDs(ids ...int) *DocumentBlockUpdateOne {
dbuo.mutation.AddDocumentIDs(ids...)
return dbuo
}
// AddDocument adds the "document" edges to the Document entity.
func (dbuo *DocumentBlockUpdateOne) AddDocument(d ...*Document) *DocumentBlockUpdateOne {
ids := make([]int, len(d))
for i := range d {
ids[i] = d[i].ID
}
return dbuo.AddDocumentIDs(ids...)
}
// Mutation returns the DocumentBlockMutation object of the builder.
func (dbuo *DocumentBlockUpdateOne) Mutation() *DocumentBlockMutation {
return dbuo.mutation
}
// ClearDocument clears all "document" edges to the Document entity.
func (dbuo *DocumentBlockUpdateOne) ClearDocument() *DocumentBlockUpdateOne {
dbuo.mutation.ClearDocument()
return dbuo
}
// RemoveDocumentIDs removes the "document" edge to Document entities by IDs.
func (dbuo *DocumentBlockUpdateOne) RemoveDocumentIDs(ids ...int) *DocumentBlockUpdateOne {
dbuo.mutation.RemoveDocumentIDs(ids...)
return dbuo
}
// RemoveDocument removes "document" edges to Document entities.
func (dbuo *DocumentBlockUpdateOne) RemoveDocument(d ...*Document) *DocumentBlockUpdateOne {
ids := make([]int, len(d))
for i := range d {
ids[i] = d[i].ID
}
return dbuo.RemoveDocumentIDs(ids...)
}
// Where appends a list predicates to the DocumentBlockUpdate builder.
func (dbuo *DocumentBlockUpdateOne) Where(ps ...predicate.DocumentBlock) *DocumentBlockUpdateOne {
dbuo.mutation.Where(ps...)
return dbuo
}
// Select allows selecting one or more fields (columns) of the returned entity.
// The default is selecting all fields defined in the entity schema.
func (dbuo *DocumentBlockUpdateOne) Select(field string, fields ...string) *DocumentBlockUpdateOne {
dbuo.fields = append([]string{field}, fields...)
return dbuo
}
// Save executes the query and returns the updated DocumentBlock entity.
func (dbuo *DocumentBlockUpdateOne) Save(ctx context.Context) (*DocumentBlock, error) {
return withHooks(ctx, dbuo.sqlSave, dbuo.mutation, dbuo.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (dbuo *DocumentBlockUpdateOne) SaveX(ctx context.Context) *DocumentBlock {
node, err := dbuo.Save(ctx)
if err != nil {
panic(err)
}
return node
}
// Exec executes the query on the entity.
func (dbuo *DocumentBlockUpdateOne) Exec(ctx context.Context) error {
_, err := dbuo.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (dbuo *DocumentBlockUpdateOne) ExecX(ctx context.Context) {
if err := dbuo.Exec(ctx); err != nil {
panic(err)
}
}
func (dbuo *DocumentBlockUpdateOne) sqlSave(ctx context.Context) (_node *DocumentBlock, err error) {
_spec := sqlgraph.NewUpdateSpec(documentblock.Table, documentblock.Columns, sqlgraph.NewFieldSpec(documentblock.FieldID, field.TypeInt))
id, ok := dbuo.mutation.ID()
if !ok {
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "DocumentBlock.id" for update`)}
}
_spec.Node.ID.Value = id
if fields := dbuo.fields; len(fields) > 0 {
_spec.Node.Columns = make([]string, 0, len(fields))
_spec.Node.Columns = append(_spec.Node.Columns, documentblock.FieldID)
for _, f := range fields {
if !documentblock.ValidColumn(f) {
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
}
if f != documentblock.FieldID {
_spec.Node.Columns = append(_spec.Node.Columns, f)
}
}
}
if ps := dbuo.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := dbuo.mutation.Name(); ok {
_spec.SetField(documentblock.FieldName, field.TypeString, value)
}
if value, ok := dbuo.mutation.Content(); ok {
_spec.SetField(documentblock.FieldContent, field.TypeString, value)
}
if value, ok := dbuo.mutation.Order(); ok {
_spec.SetField(documentblock.FieldOrder, field.TypeInt, value)
}
if value, ok := dbuo.mutation.AddedOrder(); ok {
_spec.AddField(documentblock.FieldOrder, field.TypeInt, value)
}
if value, ok := dbuo.mutation.DocumentID(); ok {
_spec.SetField(documentblock.FieldDocumentID, field.TypeInt, value)
}
if value, ok := dbuo.mutation.AddedDocumentID(); ok {
_spec.AddField(documentblock.FieldDocumentID, field.TypeInt, value)
}
if value, ok := dbuo.mutation.UserID(); ok {
_spec.SetField(documentblock.FieldUserID, field.TypeString, value)
}
if value, ok := dbuo.mutation.CreatedAt(); ok {
_spec.SetField(documentblock.FieldCreatedAt, field.TypeTime, value)
}
if value, ok := dbuo.mutation.UpdatedAt(); ok {
_spec.SetField(documentblock.FieldUpdatedAt, field.TypeTime, value)
}
if dbuo.mutation.DocumentCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: documentblock.DocumentTable,
Columns: []string{documentblock.DocumentColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(document.FieldID, field.TypeInt),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := dbuo.mutation.RemovedDocumentIDs(); len(nodes) > 0 && !dbuo.mutation.DocumentCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: documentblock.DocumentTable,
Columns: []string{documentblock.DocumentColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(document.FieldID, field.TypeInt),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := dbuo.mutation.DocumentIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: documentblock.DocumentTable,
Columns: []string{documentblock.DocumentColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(document.FieldID, field.TypeInt),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
_node = &DocumentBlock{config: dbuo.config}
_spec.Assign = _node.assignValues
_spec.ScanValues = _node.scanValues
if err = sqlgraph.UpdateNode(ctx, dbuo.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{documentblock.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return nil, err
}
dbuo.mutation.done = true
return _node, nil
}