2022-09-12 22:47:27 +00:00
|
|
|
// 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"
|
|
|
|
"github.com/google/uuid"
|
2022-10-30 04:05:38 +00:00
|
|
|
"github.com/hay-kot/homebox/backend/internal/data/ent/attachment"
|
|
|
|
"github.com/hay-kot/homebox/backend/internal/data/ent/document"
|
|
|
|
"github.com/hay-kot/homebox/backend/internal/data/ent/group"
|
|
|
|
"github.com/hay-kot/homebox/backend/internal/data/ent/predicate"
|
2022-09-12 22:47:27 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// 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
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
|
|
func (du *DocumentUpdate) SetUpdatedAt(t time.Time) *DocumentUpdate {
|
|
|
|
du.mutation.SetUpdatedAt(t)
|
|
|
|
return du
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetTitle sets the "title" field.
|
|
|
|
func (du *DocumentUpdate) SetTitle(s string) *DocumentUpdate {
|
|
|
|
du.mutation.SetTitle(s)
|
|
|
|
return du
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetPath sets the "path" field.
|
|
|
|
func (du *DocumentUpdate) SetPath(s string) *DocumentUpdate {
|
|
|
|
du.mutation.SetPath(s)
|
|
|
|
return du
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetGroupID sets the "group" edge to the Group entity by ID.
|
|
|
|
func (du *DocumentUpdate) SetGroupID(id uuid.UUID) *DocumentUpdate {
|
|
|
|
du.mutation.SetGroupID(id)
|
|
|
|
return du
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetGroup sets the "group" edge to the Group entity.
|
|
|
|
func (du *DocumentUpdate) SetGroup(g *Group) *DocumentUpdate {
|
|
|
|
return du.SetGroupID(g.ID)
|
|
|
|
}
|
|
|
|
|
|
|
|
// AddAttachmentIDs adds the "attachments" edge to the Attachment entity by IDs.
|
|
|
|
func (du *DocumentUpdate) AddAttachmentIDs(ids ...uuid.UUID) *DocumentUpdate {
|
|
|
|
du.mutation.AddAttachmentIDs(ids...)
|
|
|
|
return du
|
|
|
|
}
|
|
|
|
|
|
|
|
// AddAttachments adds the "attachments" edges to the Attachment entity.
|
|
|
|
func (du *DocumentUpdate) AddAttachments(a ...*Attachment) *DocumentUpdate {
|
|
|
|
ids := make([]uuid.UUID, len(a))
|
|
|
|
for i := range a {
|
|
|
|
ids[i] = a[i].ID
|
|
|
|
}
|
|
|
|
return du.AddAttachmentIDs(ids...)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Mutation returns the DocumentMutation object of the builder.
|
|
|
|
func (du *DocumentUpdate) Mutation() *DocumentMutation {
|
|
|
|
return du.mutation
|
|
|
|
}
|
|
|
|
|
|
|
|
// ClearGroup clears the "group" edge to the Group entity.
|
|
|
|
func (du *DocumentUpdate) ClearGroup() *DocumentUpdate {
|
|
|
|
du.mutation.ClearGroup()
|
|
|
|
return du
|
|
|
|
}
|
|
|
|
|
|
|
|
// ClearAttachments clears all "attachments" edges to the Attachment entity.
|
|
|
|
func (du *DocumentUpdate) ClearAttachments() *DocumentUpdate {
|
|
|
|
du.mutation.ClearAttachments()
|
|
|
|
return du
|
|
|
|
}
|
|
|
|
|
|
|
|
// RemoveAttachmentIDs removes the "attachments" edge to Attachment entities by IDs.
|
|
|
|
func (du *DocumentUpdate) RemoveAttachmentIDs(ids ...uuid.UUID) *DocumentUpdate {
|
|
|
|
du.mutation.RemoveAttachmentIDs(ids...)
|
|
|
|
return du
|
|
|
|
}
|
|
|
|
|
|
|
|
// RemoveAttachments removes "attachments" edges to Attachment entities.
|
|
|
|
func (du *DocumentUpdate) RemoveAttachments(a ...*Attachment) *DocumentUpdate {
|
|
|
|
ids := make([]uuid.UUID, len(a))
|
|
|
|
for i := range a {
|
|
|
|
ids[i] = a[i].ID
|
|
|
|
}
|
|
|
|
return du.RemoveAttachmentIDs(ids...)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Save executes the query and returns the number of nodes affected by the update operation.
|
|
|
|
func (du *DocumentUpdate) Save(ctx context.Context) (int, error) {
|
|
|
|
du.defaults()
|
2023-01-19 05:44:06 +00:00
|
|
|
return withHooks[int, DocumentMutation](ctx, du.sqlSave, du.mutation, du.hooks)
|
2022-09-12 22:47:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// defaults sets the default values of the builder before save.
|
|
|
|
func (du *DocumentUpdate) defaults() {
|
|
|
|
if _, ok := du.mutation.UpdatedAt(); !ok {
|
|
|
|
v := document.UpdateDefaultUpdatedAt()
|
|
|
|
du.mutation.SetUpdatedAt(v)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
|
|
func (du *DocumentUpdate) check() error {
|
|
|
|
if v, ok := du.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)}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if v, ok := du.mutation.Path(); ok {
|
|
|
|
if err := document.PathValidator(v); err != nil {
|
|
|
|
return &ValidationError{Name: "path", err: fmt.Errorf(`ent: validator failed for field "Document.path": %w`, err)}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if _, ok := du.mutation.GroupID(); du.mutation.GroupCleared() && !ok {
|
|
|
|
return errors.New(`ent: clearing a required unique edge "Document.group"`)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (du *DocumentUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
2023-01-19 05:44:06 +00:00
|
|
|
if err := du.check(); err != nil {
|
|
|
|
return n, err
|
|
|
|
}
|
2022-09-12 22:47:27 +00:00
|
|
|
_spec := &sqlgraph.UpdateSpec{
|
|
|
|
Node: &sqlgraph.NodeSpec{
|
|
|
|
Table: document.Table,
|
|
|
|
Columns: document.Columns,
|
|
|
|
ID: &sqlgraph.FieldSpec{
|
|
|
|
Type: field.TypeUUID,
|
|
|
|
Column: document.FieldID,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
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.UpdatedAt(); ok {
|
2022-12-02 01:45:28 +00:00
|
|
|
_spec.SetField(document.FieldUpdatedAt, field.TypeTime, value)
|
2022-09-12 22:47:27 +00:00
|
|
|
}
|
|
|
|
if value, ok := du.mutation.Title(); ok {
|
2022-12-02 01:45:28 +00:00
|
|
|
_spec.SetField(document.FieldTitle, field.TypeString, value)
|
2022-09-12 22:47:27 +00:00
|
|
|
}
|
|
|
|
if value, ok := du.mutation.Path(); ok {
|
2022-12-02 01:45:28 +00:00
|
|
|
_spec.SetField(document.FieldPath, field.TypeString, value)
|
2022-09-12 22:47:27 +00:00
|
|
|
}
|
|
|
|
if du.mutation.GroupCleared() {
|
|
|
|
edge := &sqlgraph.EdgeSpec{
|
|
|
|
Rel: sqlgraph.M2O,
|
|
|
|
Inverse: true,
|
|
|
|
Table: document.GroupTable,
|
|
|
|
Columns: []string{document.GroupColumn},
|
|
|
|
Bidi: false,
|
|
|
|
Target: &sqlgraph.EdgeTarget{
|
|
|
|
IDSpec: &sqlgraph.FieldSpec{
|
|
|
|
Type: field.TypeUUID,
|
|
|
|
Column: group.FieldID,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
|
|
}
|
|
|
|
if nodes := du.mutation.GroupIDs(); len(nodes) > 0 {
|
|
|
|
edge := &sqlgraph.EdgeSpec{
|
|
|
|
Rel: sqlgraph.M2O,
|
|
|
|
Inverse: true,
|
|
|
|
Table: document.GroupTable,
|
|
|
|
Columns: []string{document.GroupColumn},
|
|
|
|
Bidi: false,
|
|
|
|
Target: &sqlgraph.EdgeTarget{
|
|
|
|
IDSpec: &sqlgraph.FieldSpec{
|
|
|
|
Type: field.TypeUUID,
|
|
|
|
Column: group.FieldID,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, k := range nodes {
|
|
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
|
|
}
|
|
|
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
|
|
|
}
|
|
|
|
if du.mutation.AttachmentsCleared() {
|
|
|
|
edge := &sqlgraph.EdgeSpec{
|
|
|
|
Rel: sqlgraph.O2M,
|
|
|
|
Inverse: false,
|
|
|
|
Table: document.AttachmentsTable,
|
|
|
|
Columns: []string{document.AttachmentsColumn},
|
|
|
|
Bidi: false,
|
|
|
|
Target: &sqlgraph.EdgeTarget{
|
|
|
|
IDSpec: &sqlgraph.FieldSpec{
|
|
|
|
Type: field.TypeUUID,
|
|
|
|
Column: attachment.FieldID,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
|
|
}
|
|
|
|
if nodes := du.mutation.RemovedAttachmentsIDs(); len(nodes) > 0 && !du.mutation.AttachmentsCleared() {
|
|
|
|
edge := &sqlgraph.EdgeSpec{
|
|
|
|
Rel: sqlgraph.O2M,
|
|
|
|
Inverse: false,
|
|
|
|
Table: document.AttachmentsTable,
|
|
|
|
Columns: []string{document.AttachmentsColumn},
|
|
|
|
Bidi: false,
|
|
|
|
Target: &sqlgraph.EdgeTarget{
|
|
|
|
IDSpec: &sqlgraph.FieldSpec{
|
|
|
|
Type: field.TypeUUID,
|
|
|
|
Column: attachment.FieldID,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, k := range nodes {
|
|
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
|
|
}
|
|
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
|
|
}
|
|
|
|
if nodes := du.mutation.AttachmentsIDs(); len(nodes) > 0 {
|
|
|
|
edge := &sqlgraph.EdgeSpec{
|
|
|
|
Rel: sqlgraph.O2M,
|
|
|
|
Inverse: false,
|
|
|
|
Table: document.AttachmentsTable,
|
|
|
|
Columns: []string{document.AttachmentsColumn},
|
|
|
|
Bidi: false,
|
|
|
|
Target: &sqlgraph.EdgeTarget{
|
|
|
|
IDSpec: &sqlgraph.FieldSpec{
|
|
|
|
Type: field.TypeUUID,
|
|
|
|
Column: attachment.FieldID,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
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, 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
|
|
|
|
}
|
2023-01-19 05:44:06 +00:00
|
|
|
du.mutation.done = true
|
2022-09-12 22:47:27 +00:00
|
|
|
return n, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// DocumentUpdateOne is the builder for updating a single Document entity.
|
|
|
|
type DocumentUpdateOne struct {
|
|
|
|
config
|
|
|
|
fields []string
|
|
|
|
hooks []Hook
|
|
|
|
mutation *DocumentMutation
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
|
|
func (duo *DocumentUpdateOne) SetUpdatedAt(t time.Time) *DocumentUpdateOne {
|
|
|
|
duo.mutation.SetUpdatedAt(t)
|
|
|
|
return duo
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetTitle sets the "title" field.
|
|
|
|
func (duo *DocumentUpdateOne) SetTitle(s string) *DocumentUpdateOne {
|
|
|
|
duo.mutation.SetTitle(s)
|
|
|
|
return duo
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetPath sets the "path" field.
|
|
|
|
func (duo *DocumentUpdateOne) SetPath(s string) *DocumentUpdateOne {
|
|
|
|
duo.mutation.SetPath(s)
|
|
|
|
return duo
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetGroupID sets the "group" edge to the Group entity by ID.
|
|
|
|
func (duo *DocumentUpdateOne) SetGroupID(id uuid.UUID) *DocumentUpdateOne {
|
|
|
|
duo.mutation.SetGroupID(id)
|
|
|
|
return duo
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetGroup sets the "group" edge to the Group entity.
|
|
|
|
func (duo *DocumentUpdateOne) SetGroup(g *Group) *DocumentUpdateOne {
|
|
|
|
return duo.SetGroupID(g.ID)
|
|
|
|
}
|
|
|
|
|
|
|
|
// AddAttachmentIDs adds the "attachments" edge to the Attachment entity by IDs.
|
|
|
|
func (duo *DocumentUpdateOne) AddAttachmentIDs(ids ...uuid.UUID) *DocumentUpdateOne {
|
|
|
|
duo.mutation.AddAttachmentIDs(ids...)
|
|
|
|
return duo
|
|
|
|
}
|
|
|
|
|
|
|
|
// AddAttachments adds the "attachments" edges to the Attachment entity.
|
|
|
|
func (duo *DocumentUpdateOne) AddAttachments(a ...*Attachment) *DocumentUpdateOne {
|
|
|
|
ids := make([]uuid.UUID, len(a))
|
|
|
|
for i := range a {
|
|
|
|
ids[i] = a[i].ID
|
|
|
|
}
|
|
|
|
return duo.AddAttachmentIDs(ids...)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Mutation returns the DocumentMutation object of the builder.
|
|
|
|
func (duo *DocumentUpdateOne) Mutation() *DocumentMutation {
|
|
|
|
return duo.mutation
|
|
|
|
}
|
|
|
|
|
|
|
|
// ClearGroup clears the "group" edge to the Group entity.
|
|
|
|
func (duo *DocumentUpdateOne) ClearGroup() *DocumentUpdateOne {
|
|
|
|
duo.mutation.ClearGroup()
|
|
|
|
return duo
|
|
|
|
}
|
|
|
|
|
|
|
|
// ClearAttachments clears all "attachments" edges to the Attachment entity.
|
|
|
|
func (duo *DocumentUpdateOne) ClearAttachments() *DocumentUpdateOne {
|
|
|
|
duo.mutation.ClearAttachments()
|
|
|
|
return duo
|
|
|
|
}
|
|
|
|
|
|
|
|
// RemoveAttachmentIDs removes the "attachments" edge to Attachment entities by IDs.
|
|
|
|
func (duo *DocumentUpdateOne) RemoveAttachmentIDs(ids ...uuid.UUID) *DocumentUpdateOne {
|
|
|
|
duo.mutation.RemoveAttachmentIDs(ids...)
|
|
|
|
return duo
|
|
|
|
}
|
|
|
|
|
|
|
|
// RemoveAttachments removes "attachments" edges to Attachment entities.
|
|
|
|
func (duo *DocumentUpdateOne) RemoveAttachments(a ...*Attachment) *DocumentUpdateOne {
|
|
|
|
ids := make([]uuid.UUID, len(a))
|
|
|
|
for i := range a {
|
|
|
|
ids[i] = a[i].ID
|
|
|
|
}
|
|
|
|
return duo.RemoveAttachmentIDs(ids...)
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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) {
|
|
|
|
duo.defaults()
|
2023-01-19 05:44:06 +00:00
|
|
|
return withHooks[*Document, DocumentMutation](ctx, duo.sqlSave, duo.mutation, duo.hooks)
|
2022-09-12 22:47:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// defaults sets the default values of the builder before save.
|
|
|
|
func (duo *DocumentUpdateOne) defaults() {
|
|
|
|
if _, ok := duo.mutation.UpdatedAt(); !ok {
|
|
|
|
v := document.UpdateDefaultUpdatedAt()
|
|
|
|
duo.mutation.SetUpdatedAt(v)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
|
|
func (duo *DocumentUpdateOne) check() error {
|
|
|
|
if v, ok := duo.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)}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if v, ok := duo.mutation.Path(); ok {
|
|
|
|
if err := document.PathValidator(v); err != nil {
|
|
|
|
return &ValidationError{Name: "path", err: fmt.Errorf(`ent: validator failed for field "Document.path": %w`, err)}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if _, ok := duo.mutation.GroupID(); duo.mutation.GroupCleared() && !ok {
|
|
|
|
return errors.New(`ent: clearing a required unique edge "Document.group"`)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (duo *DocumentUpdateOne) sqlSave(ctx context.Context) (_node *Document, err error) {
|
2023-01-19 05:44:06 +00:00
|
|
|
if err := duo.check(); err != nil {
|
|
|
|
return _node, err
|
|
|
|
}
|
2022-09-12 22:47:27 +00:00
|
|
|
_spec := &sqlgraph.UpdateSpec{
|
|
|
|
Node: &sqlgraph.NodeSpec{
|
|
|
|
Table: document.Table,
|
|
|
|
Columns: document.Columns,
|
|
|
|
ID: &sqlgraph.FieldSpec{
|
|
|
|
Type: field.TypeUUID,
|
|
|
|
Column: document.FieldID,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
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.UpdatedAt(); ok {
|
2022-12-02 01:45:28 +00:00
|
|
|
_spec.SetField(document.FieldUpdatedAt, field.TypeTime, value)
|
2022-09-12 22:47:27 +00:00
|
|
|
}
|
|
|
|
if value, ok := duo.mutation.Title(); ok {
|
2022-12-02 01:45:28 +00:00
|
|
|
_spec.SetField(document.FieldTitle, field.TypeString, value)
|
2022-09-12 22:47:27 +00:00
|
|
|
}
|
|
|
|
if value, ok := duo.mutation.Path(); ok {
|
2022-12-02 01:45:28 +00:00
|
|
|
_spec.SetField(document.FieldPath, field.TypeString, value)
|
2022-09-12 22:47:27 +00:00
|
|
|
}
|
|
|
|
if duo.mutation.GroupCleared() {
|
|
|
|
edge := &sqlgraph.EdgeSpec{
|
|
|
|
Rel: sqlgraph.M2O,
|
|
|
|
Inverse: true,
|
|
|
|
Table: document.GroupTable,
|
|
|
|
Columns: []string{document.GroupColumn},
|
|
|
|
Bidi: false,
|
|
|
|
Target: &sqlgraph.EdgeTarget{
|
|
|
|
IDSpec: &sqlgraph.FieldSpec{
|
|
|
|
Type: field.TypeUUID,
|
|
|
|
Column: group.FieldID,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
|
|
}
|
|
|
|
if nodes := duo.mutation.GroupIDs(); len(nodes) > 0 {
|
|
|
|
edge := &sqlgraph.EdgeSpec{
|
|
|
|
Rel: sqlgraph.M2O,
|
|
|
|
Inverse: true,
|
|
|
|
Table: document.GroupTable,
|
|
|
|
Columns: []string{document.GroupColumn},
|
|
|
|
Bidi: false,
|
|
|
|
Target: &sqlgraph.EdgeTarget{
|
|
|
|
IDSpec: &sqlgraph.FieldSpec{
|
|
|
|
Type: field.TypeUUID,
|
|
|
|
Column: group.FieldID,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, k := range nodes {
|
|
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
|
|
}
|
|
|
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
|
|
|
}
|
|
|
|
if duo.mutation.AttachmentsCleared() {
|
|
|
|
edge := &sqlgraph.EdgeSpec{
|
|
|
|
Rel: sqlgraph.O2M,
|
|
|
|
Inverse: false,
|
|
|
|
Table: document.AttachmentsTable,
|
|
|
|
Columns: []string{document.AttachmentsColumn},
|
|
|
|
Bidi: false,
|
|
|
|
Target: &sqlgraph.EdgeTarget{
|
|
|
|
IDSpec: &sqlgraph.FieldSpec{
|
|
|
|
Type: field.TypeUUID,
|
|
|
|
Column: attachment.FieldID,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
|
|
}
|
|
|
|
if nodes := duo.mutation.RemovedAttachmentsIDs(); len(nodes) > 0 && !duo.mutation.AttachmentsCleared() {
|
|
|
|
edge := &sqlgraph.EdgeSpec{
|
|
|
|
Rel: sqlgraph.O2M,
|
|
|
|
Inverse: false,
|
|
|
|
Table: document.AttachmentsTable,
|
|
|
|
Columns: []string{document.AttachmentsColumn},
|
|
|
|
Bidi: false,
|
|
|
|
Target: &sqlgraph.EdgeTarget{
|
|
|
|
IDSpec: &sqlgraph.FieldSpec{
|
|
|
|
Type: field.TypeUUID,
|
|
|
|
Column: attachment.FieldID,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, k := range nodes {
|
|
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
|
|
}
|
|
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
|
|
}
|
|
|
|
if nodes := duo.mutation.AttachmentsIDs(); len(nodes) > 0 {
|
|
|
|
edge := &sqlgraph.EdgeSpec{
|
|
|
|
Rel: sqlgraph.O2M,
|
|
|
|
Inverse: false,
|
|
|
|
Table: document.AttachmentsTable,
|
|
|
|
Columns: []string{document.AttachmentsColumn},
|
|
|
|
Bidi: false,
|
|
|
|
Target: &sqlgraph.EdgeTarget{
|
|
|
|
IDSpec: &sqlgraph.FieldSpec{
|
|
|
|
Type: field.TypeUUID,
|
|
|
|
Column: attachment.FieldID,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, k := range nodes {
|
|
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
|
|
}
|
|
|
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
|
|
|
}
|
|
|
|
_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
|
|
|
|
}
|
2023-01-19 05:44:06 +00:00
|
|
|
duo.mutation.done = true
|
2022-09-12 22:47:27 +00:00
|
|
|
return _node, nil
|
|
|
|
}
|