Files
ent/entc/integration/ent/file_update.go
2020-12-23 17:35:39 +02:00

959 lines
24 KiB
Go

// Copyright 2019-present Facebook Inc. All rights reserved.
// This source code is licensed under the Apache 2.0 license found
// in the LICENSE file in the root directory of this source tree.
// Code generated by entc, DO NOT EDIT.
package ent
import (
"context"
"fmt"
"github.com/facebook/ent/dialect/sql"
"github.com/facebook/ent/dialect/sql/sqlgraph"
"github.com/facebook/ent/entc/integration/ent/fieldtype"
"github.com/facebook/ent/entc/integration/ent/file"
"github.com/facebook/ent/entc/integration/ent/filetype"
"github.com/facebook/ent/entc/integration/ent/predicate"
"github.com/facebook/ent/entc/integration/ent/user"
"github.com/facebook/ent/schema/field"
)
// FileUpdate is the builder for updating File entities.
type FileUpdate struct {
config
hooks []Hook
mutation *FileMutation
}
// Where adds a new predicate for the builder.
func (fu *FileUpdate) Where(ps ...predicate.File) *FileUpdate {
fu.mutation.predicates = append(fu.mutation.predicates, ps...)
return fu
}
// SetSize sets the size field.
func (fu *FileUpdate) SetSize(i int) *FileUpdate {
fu.mutation.ResetSize()
fu.mutation.SetSize(i)
return fu
}
// SetNillableSize sets the size field if the given value is not nil.
func (fu *FileUpdate) SetNillableSize(i *int) *FileUpdate {
if i != nil {
fu.SetSize(*i)
}
return fu
}
// AddSize adds i to size.
func (fu *FileUpdate) AddSize(i int) *FileUpdate {
fu.mutation.AddSize(i)
return fu
}
// SetName sets the name field.
func (fu *FileUpdate) SetName(s string) *FileUpdate {
fu.mutation.SetName(s)
return fu
}
// SetUser sets the user field.
func (fu *FileUpdate) SetUser(s string) *FileUpdate {
fu.mutation.SetUser(s)
return fu
}
// SetNillableUser sets the user field if the given value is not nil.
func (fu *FileUpdate) SetNillableUser(s *string) *FileUpdate {
if s != nil {
fu.SetUser(*s)
}
return fu
}
// ClearUser clears the value of user.
func (fu *FileUpdate) ClearUser() *FileUpdate {
fu.mutation.ClearUser()
return fu
}
// SetGroup sets the group field.
func (fu *FileUpdate) SetGroup(s string) *FileUpdate {
fu.mutation.SetGroup(s)
return fu
}
// SetNillableGroup sets the group field if the given value is not nil.
func (fu *FileUpdate) SetNillableGroup(s *string) *FileUpdate {
if s != nil {
fu.SetGroup(*s)
}
return fu
}
// ClearGroup clears the value of group.
func (fu *FileUpdate) ClearGroup() *FileUpdate {
fu.mutation.ClearGroup()
return fu
}
// SetOp sets the op field.
func (fu *FileUpdate) SetOp(b bool) *FileUpdate {
fu.mutation.SetOp(b)
return fu
}
// SetNillableOp sets the op field if the given value is not nil.
func (fu *FileUpdate) SetNillableOp(b *bool) *FileUpdate {
if b != nil {
fu.SetOp(*b)
}
return fu
}
// ClearOp clears the value of op.
func (fu *FileUpdate) ClearOp() *FileUpdate {
fu.mutation.ClearOp()
return fu
}
// SetOwnerID sets the owner edge to User by id.
func (fu *FileUpdate) SetOwnerID(id int) *FileUpdate {
fu.mutation.SetOwnerID(id)
return fu
}
// SetNillableOwnerID sets the owner edge to User by id if the given value is not nil.
func (fu *FileUpdate) SetNillableOwnerID(id *int) *FileUpdate {
if id != nil {
fu = fu.SetOwnerID(*id)
}
return fu
}
// SetOwner sets the owner edge to User.
func (fu *FileUpdate) SetOwner(u *User) *FileUpdate {
return fu.SetOwnerID(u.ID)
}
// SetTypeID sets the type edge to FileType by id.
func (fu *FileUpdate) SetTypeID(id int) *FileUpdate {
fu.mutation.SetTypeID(id)
return fu
}
// SetNillableTypeID sets the type edge to FileType by id if the given value is not nil.
func (fu *FileUpdate) SetNillableTypeID(id *int) *FileUpdate {
if id != nil {
fu = fu.SetTypeID(*id)
}
return fu
}
// SetType sets the type edge to FileType.
func (fu *FileUpdate) SetType(f *FileType) *FileUpdate {
return fu.SetTypeID(f.ID)
}
// AddFieldIDs adds the field edge to FieldType by ids.
func (fu *FileUpdate) AddFieldIDs(ids ...int) *FileUpdate {
fu.mutation.AddFieldIDs(ids...)
return fu
}
// AddField adds the field edges to FieldType.
func (fu *FileUpdate) AddField(f ...*FieldType) *FileUpdate {
ids := make([]int, len(f))
for i := range f {
ids[i] = f[i].ID
}
return fu.AddFieldIDs(ids...)
}
// Mutation returns the FileMutation object of the builder.
func (fu *FileUpdate) Mutation() *FileMutation {
return fu.mutation
}
// ClearOwner clears the "owner" edge to type User.
func (fu *FileUpdate) ClearOwner() *FileUpdate {
fu.mutation.ClearOwner()
return fu
}
// ClearType clears the "type" edge to type FileType.
func (fu *FileUpdate) ClearType() *FileUpdate {
fu.mutation.ClearType()
return fu
}
// ClearFieldEdge clears all "field" edges to type FieldType.
func (fu *FileUpdate) ClearFieldEdge() *FileUpdate {
fu.mutation.ClearFieldEdge()
return fu
}
// RemoveFieldIDs removes the field edge to FieldType by ids.
func (fu *FileUpdate) RemoveFieldIDs(ids ...int) *FileUpdate {
fu.mutation.RemoveFieldIDs(ids...)
return fu
}
// RemoveField removes field edges to FieldType.
func (fu *FileUpdate) RemoveField(f ...*FieldType) *FileUpdate {
ids := make([]int, len(f))
for i := range f {
ids[i] = f[i].ID
}
return fu.RemoveFieldIDs(ids...)
}
// Save executes the query and returns the number of nodes affected by the update operation.
func (fu *FileUpdate) Save(ctx context.Context) (int, error) {
var (
err error
affected int
)
if len(fu.hooks) == 0 {
if err = fu.check(); err != nil {
return 0, err
}
affected, err = fu.sqlSave(ctx)
} else {
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
mutation, ok := m.(*FileMutation)
if !ok {
return nil, fmt.Errorf("unexpected mutation type %T", m)
}
if err = fu.check(); err != nil {
return 0, err
}
fu.mutation = mutation
affected, err = fu.sqlSave(ctx)
mutation.done = true
return affected, err
})
for i := len(fu.hooks) - 1; i >= 0; i-- {
mut = fu.hooks[i](mut)
}
if _, err := mut.Mutate(ctx, fu.mutation); err != nil {
return 0, err
}
}
return affected, err
}
// SaveX is like Save, but panics if an error occurs.
func (fu *FileUpdate) SaveX(ctx context.Context) int {
affected, err := fu.Save(ctx)
if err != nil {
panic(err)
}
return affected
}
// Exec executes the query.
func (fu *FileUpdate) Exec(ctx context.Context) error {
_, err := fu.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (fu *FileUpdate) ExecX(ctx context.Context) {
if err := fu.Exec(ctx); err != nil {
panic(err)
}
}
// check runs all checks and user-defined validators on the builder.
func (fu *FileUpdate) check() error {
if v, ok := fu.mutation.Size(); ok {
if err := file.SizeValidator(v); err != nil {
return &ValidationError{Name: "size", err: fmt.Errorf("ent: validator failed for field \"size\": %w", err)}
}
}
return nil
}
func (fu *FileUpdate) sqlSave(ctx context.Context) (n int, err error) {
_spec := &sqlgraph.UpdateSpec{
Node: &sqlgraph.NodeSpec{
Table: file.Table,
Columns: file.Columns,
ID: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: file.FieldID,
},
},
}
if ps := fu.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := fu.mutation.Size(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeInt,
Value: value,
Column: file.FieldSize,
})
}
if value, ok := fu.mutation.AddedSize(); ok {
_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
Type: field.TypeInt,
Value: value,
Column: file.FieldSize,
})
}
if value, ok := fu.mutation.Name(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeString,
Value: value,
Column: file.FieldName,
})
}
if value, ok := fu.mutation.User(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeString,
Value: value,
Column: file.FieldUser,
})
}
if fu.mutation.UserCleared() {
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
Type: field.TypeString,
Column: file.FieldUser,
})
}
if value, ok := fu.mutation.Group(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeString,
Value: value,
Column: file.FieldGroup,
})
}
if fu.mutation.GroupCleared() {
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
Type: field.TypeString,
Column: file.FieldGroup,
})
}
if value, ok := fu.mutation.GetOp(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeBool,
Value: value,
Column: file.FieldOp,
})
}
if fu.mutation.OpCleared() {
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
Type: field.TypeBool,
Column: file.FieldOp,
})
}
if fu.mutation.OwnerCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: file.OwnerTable,
Columns: []string{file.OwnerColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: user.FieldID,
},
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := fu.mutation.OwnerIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: file.OwnerTable,
Columns: []string{file.OwnerColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: user.FieldID,
},
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if fu.mutation.TypeCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: file.TypeTable,
Columns: []string{file.TypeColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: filetype.FieldID,
},
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := fu.mutation.TypeIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: file.TypeTable,
Columns: []string{file.TypeColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: filetype.FieldID,
},
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if fu.mutation.FieldEdgeCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: file.FieldTable,
Columns: []string{file.FieldColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: fieldtype.FieldID,
},
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := fu.mutation.RemovedFieldIDs(); len(nodes) > 0 && !fu.mutation.FieldEdgeCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: file.FieldTable,
Columns: []string{file.FieldColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: fieldtype.FieldID,
},
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := fu.mutation.FieldIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: file.FieldTable,
Columns: []string{file.FieldColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: fieldtype.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, fu.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{file.Label}
} else if cerr, ok := isSQLConstraintError(err); ok {
err = cerr
}
return 0, err
}
return n, nil
}
// FileUpdateOne is the builder for updating a single File entity.
type FileUpdateOne struct {
config
hooks []Hook
mutation *FileMutation
}
// SetSize sets the size field.
func (fuo *FileUpdateOne) SetSize(i int) *FileUpdateOne {
fuo.mutation.ResetSize()
fuo.mutation.SetSize(i)
return fuo
}
// SetNillableSize sets the size field if the given value is not nil.
func (fuo *FileUpdateOne) SetNillableSize(i *int) *FileUpdateOne {
if i != nil {
fuo.SetSize(*i)
}
return fuo
}
// AddSize adds i to size.
func (fuo *FileUpdateOne) AddSize(i int) *FileUpdateOne {
fuo.mutation.AddSize(i)
return fuo
}
// SetName sets the name field.
func (fuo *FileUpdateOne) SetName(s string) *FileUpdateOne {
fuo.mutation.SetName(s)
return fuo
}
// SetUser sets the user field.
func (fuo *FileUpdateOne) SetUser(s string) *FileUpdateOne {
fuo.mutation.SetUser(s)
return fuo
}
// SetNillableUser sets the user field if the given value is not nil.
func (fuo *FileUpdateOne) SetNillableUser(s *string) *FileUpdateOne {
if s != nil {
fuo.SetUser(*s)
}
return fuo
}
// ClearUser clears the value of user.
func (fuo *FileUpdateOne) ClearUser() *FileUpdateOne {
fuo.mutation.ClearUser()
return fuo
}
// SetGroup sets the group field.
func (fuo *FileUpdateOne) SetGroup(s string) *FileUpdateOne {
fuo.mutation.SetGroup(s)
return fuo
}
// SetNillableGroup sets the group field if the given value is not nil.
func (fuo *FileUpdateOne) SetNillableGroup(s *string) *FileUpdateOne {
if s != nil {
fuo.SetGroup(*s)
}
return fuo
}
// ClearGroup clears the value of group.
func (fuo *FileUpdateOne) ClearGroup() *FileUpdateOne {
fuo.mutation.ClearGroup()
return fuo
}
// SetOp sets the op field.
func (fuo *FileUpdateOne) SetOp(b bool) *FileUpdateOne {
fuo.mutation.SetOp(b)
return fuo
}
// SetNillableOp sets the op field if the given value is not nil.
func (fuo *FileUpdateOne) SetNillableOp(b *bool) *FileUpdateOne {
if b != nil {
fuo.SetOp(*b)
}
return fuo
}
// ClearOp clears the value of op.
func (fuo *FileUpdateOne) ClearOp() *FileUpdateOne {
fuo.mutation.ClearOp()
return fuo
}
// SetOwnerID sets the owner edge to User by id.
func (fuo *FileUpdateOne) SetOwnerID(id int) *FileUpdateOne {
fuo.mutation.SetOwnerID(id)
return fuo
}
// SetNillableOwnerID sets the owner edge to User by id if the given value is not nil.
func (fuo *FileUpdateOne) SetNillableOwnerID(id *int) *FileUpdateOne {
if id != nil {
fuo = fuo.SetOwnerID(*id)
}
return fuo
}
// SetOwner sets the owner edge to User.
func (fuo *FileUpdateOne) SetOwner(u *User) *FileUpdateOne {
return fuo.SetOwnerID(u.ID)
}
// SetTypeID sets the type edge to FileType by id.
func (fuo *FileUpdateOne) SetTypeID(id int) *FileUpdateOne {
fuo.mutation.SetTypeID(id)
return fuo
}
// SetNillableTypeID sets the type edge to FileType by id if the given value is not nil.
func (fuo *FileUpdateOne) SetNillableTypeID(id *int) *FileUpdateOne {
if id != nil {
fuo = fuo.SetTypeID(*id)
}
return fuo
}
// SetType sets the type edge to FileType.
func (fuo *FileUpdateOne) SetType(f *FileType) *FileUpdateOne {
return fuo.SetTypeID(f.ID)
}
// AddFieldIDs adds the field edge to FieldType by ids.
func (fuo *FileUpdateOne) AddFieldIDs(ids ...int) *FileUpdateOne {
fuo.mutation.AddFieldIDs(ids...)
return fuo
}
// AddField adds the field edges to FieldType.
func (fuo *FileUpdateOne) AddField(f ...*FieldType) *FileUpdateOne {
ids := make([]int, len(f))
for i := range f {
ids[i] = f[i].ID
}
return fuo.AddFieldIDs(ids...)
}
// Mutation returns the FileMutation object of the builder.
func (fuo *FileUpdateOne) Mutation() *FileMutation {
return fuo.mutation
}
// ClearOwner clears the "owner" edge to type User.
func (fuo *FileUpdateOne) ClearOwner() *FileUpdateOne {
fuo.mutation.ClearOwner()
return fuo
}
// ClearType clears the "type" edge to type FileType.
func (fuo *FileUpdateOne) ClearType() *FileUpdateOne {
fuo.mutation.ClearType()
return fuo
}
// ClearFieldEdge clears all "field" edges to type FieldType.
func (fuo *FileUpdateOne) ClearFieldEdge() *FileUpdateOne {
fuo.mutation.ClearFieldEdge()
return fuo
}
// RemoveFieldIDs removes the field edge to FieldType by ids.
func (fuo *FileUpdateOne) RemoveFieldIDs(ids ...int) *FileUpdateOne {
fuo.mutation.RemoveFieldIDs(ids...)
return fuo
}
// RemoveField removes field edges to FieldType.
func (fuo *FileUpdateOne) RemoveField(f ...*FieldType) *FileUpdateOne {
ids := make([]int, len(f))
for i := range f {
ids[i] = f[i].ID
}
return fuo.RemoveFieldIDs(ids...)
}
// Save executes the query and returns the updated entity.
func (fuo *FileUpdateOne) Save(ctx context.Context) (*File, error) {
var (
err error
node *File
)
if len(fuo.hooks) == 0 {
if err = fuo.check(); err != nil {
return nil, err
}
node, err = fuo.sqlSave(ctx)
} else {
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
mutation, ok := m.(*FileMutation)
if !ok {
return nil, fmt.Errorf("unexpected mutation type %T", m)
}
if err = fuo.check(); err != nil {
return nil, err
}
fuo.mutation = mutation
node, err = fuo.sqlSave(ctx)
mutation.done = true
return node, err
})
for i := len(fuo.hooks) - 1; i >= 0; i-- {
mut = fuo.hooks[i](mut)
}
if _, err := mut.Mutate(ctx, fuo.mutation); err != nil {
return nil, err
}
}
return node, err
}
// SaveX is like Save, but panics if an error occurs.
func (fuo *FileUpdateOne) SaveX(ctx context.Context) *File {
node, err := fuo.Save(ctx)
if err != nil {
panic(err)
}
return node
}
// Exec executes the query on the entity.
func (fuo *FileUpdateOne) Exec(ctx context.Context) error {
_, err := fuo.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (fuo *FileUpdateOne) ExecX(ctx context.Context) {
if err := fuo.Exec(ctx); err != nil {
panic(err)
}
}
// check runs all checks and user-defined validators on the builder.
func (fuo *FileUpdateOne) check() error {
if v, ok := fuo.mutation.Size(); ok {
if err := file.SizeValidator(v); err != nil {
return &ValidationError{Name: "size", err: fmt.Errorf("ent: validator failed for field \"size\": %w", err)}
}
}
return nil
}
func (fuo *FileUpdateOne) sqlSave(ctx context.Context) (_node *File, err error) {
_spec := &sqlgraph.UpdateSpec{
Node: &sqlgraph.NodeSpec{
Table: file.Table,
Columns: file.Columns,
ID: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: file.FieldID,
},
},
}
id, ok := fuo.mutation.ID()
if !ok {
return nil, &ValidationError{Name: "ID", err: fmt.Errorf("missing File.ID for update")}
}
_spec.Node.ID.Value = id
if value, ok := fuo.mutation.Size(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeInt,
Value: value,
Column: file.FieldSize,
})
}
if value, ok := fuo.mutation.AddedSize(); ok {
_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
Type: field.TypeInt,
Value: value,
Column: file.FieldSize,
})
}
if value, ok := fuo.mutation.Name(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeString,
Value: value,
Column: file.FieldName,
})
}
if value, ok := fuo.mutation.User(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeString,
Value: value,
Column: file.FieldUser,
})
}
if fuo.mutation.UserCleared() {
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
Type: field.TypeString,
Column: file.FieldUser,
})
}
if value, ok := fuo.mutation.Group(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeString,
Value: value,
Column: file.FieldGroup,
})
}
if fuo.mutation.GroupCleared() {
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
Type: field.TypeString,
Column: file.FieldGroup,
})
}
if value, ok := fuo.mutation.GetOp(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeBool,
Value: value,
Column: file.FieldOp,
})
}
if fuo.mutation.OpCleared() {
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
Type: field.TypeBool,
Column: file.FieldOp,
})
}
if fuo.mutation.OwnerCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: file.OwnerTable,
Columns: []string{file.OwnerColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: user.FieldID,
},
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := fuo.mutation.OwnerIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: file.OwnerTable,
Columns: []string{file.OwnerColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: user.FieldID,
},
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if fuo.mutation.TypeCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: file.TypeTable,
Columns: []string{file.TypeColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: filetype.FieldID,
},
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := fuo.mutation.TypeIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: file.TypeTable,
Columns: []string{file.TypeColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: filetype.FieldID,
},
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if fuo.mutation.FieldEdgeCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: file.FieldTable,
Columns: []string{file.FieldColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: fieldtype.FieldID,
},
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := fuo.mutation.RemovedFieldIDs(); len(nodes) > 0 && !fuo.mutation.FieldEdgeCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: file.FieldTable,
Columns: []string{file.FieldColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: fieldtype.FieldID,
},
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := fuo.mutation.FieldIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: file.FieldTable,
Columns: []string{file.FieldColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: fieldtype.FieldID,
},
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
_node = &File{config: fuo.config}
_spec.Assign = _node.assignValues
_spec.ScanValues = _node.scanValues
if err = sqlgraph.UpdateNode(ctx, fuo.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{file.Label}
} else if cerr, ok := isSQLConstraintError(err); ok {
err = cerr
}
return nil, err
}
return _node, nil
}