mirror of
https://github.com/ent/ent.git
synced 2026-05-24 09:31:56 +03:00
820 lines
20 KiB
Go
820 lines
20 KiB
Go
// Copyright (c) Facebook, Inc. and its affiliates. 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/facebookincubator/ent/dialect/sql"
|
|
"github.com/facebookincubator/ent/dialect/sql/sqlgraph"
|
|
"github.com/facebookincubator/ent/entc/integration/ent/fieldtype"
|
|
"github.com/facebookincubator/ent/entc/integration/ent/file"
|
|
"github.com/facebookincubator/ent/entc/integration/ent/filetype"
|
|
"github.com/facebookincubator/ent/entc/integration/ent/predicate"
|
|
"github.com/facebookincubator/ent/entc/integration/ent/user"
|
|
"github.com/facebookincubator/ent/schema/field"
|
|
)
|
|
|
|
// FileUpdate is the builder for updating File entities.
|
|
type FileUpdate struct {
|
|
config
|
|
hooks []Hook
|
|
mutation *FileMutation
|
|
predicates []predicate.File
|
|
}
|
|
|
|
// Where adds a new predicate for the builder.
|
|
func (fu *FileUpdate) Where(ps ...predicate.File) *FileUpdate {
|
|
fu.predicates = append(fu.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
|
|
}
|
|
|
|
// 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...)
|
|
}
|
|
|
|
// ClearOwner clears the owner edge to User.
|
|
func (fu *FileUpdate) ClearOwner() *FileUpdate {
|
|
fu.mutation.ClearOwner()
|
|
return fu
|
|
}
|
|
|
|
// ClearType clears the type edge to FileType.
|
|
func (fu *FileUpdate) ClearType() *FileUpdate {
|
|
fu.mutation.ClearType()
|
|
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 rows/vertices matched by this operation.
|
|
func (fu *FileUpdate) Save(ctx context.Context) (int, error) {
|
|
if v, ok := fu.mutation.Size(); ok {
|
|
if err := file.SizeValidator(v); err != nil {
|
|
return 0, fmt.Errorf("ent: validator failed for field \"size\": %v", err)
|
|
}
|
|
}
|
|
|
|
var (
|
|
err error
|
|
affected int
|
|
)
|
|
if len(fu.hooks) == 0 {
|
|
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)
|
|
}
|
|
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)
|
|
}
|
|
}
|
|
|
|
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.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 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 nodes := fu.mutation.RemovedFieldIDs(); 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.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
|
|
}
|
|
|
|
// 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...)
|
|
}
|
|
|
|
// ClearOwner clears the owner edge to User.
|
|
func (fuo *FileUpdateOne) ClearOwner() *FileUpdateOne {
|
|
fuo.mutation.ClearOwner()
|
|
return fuo
|
|
}
|
|
|
|
// ClearType clears the type edge to FileType.
|
|
func (fuo *FileUpdateOne) ClearType() *FileUpdateOne {
|
|
fuo.mutation.ClearType()
|
|
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) {
|
|
if v, ok := fuo.mutation.Size(); ok {
|
|
if err := file.SizeValidator(v); err != nil {
|
|
return nil, fmt.Errorf("ent: validator failed for field \"size\": %v", err)
|
|
}
|
|
}
|
|
|
|
var (
|
|
err error
|
|
node *File
|
|
)
|
|
if len(fuo.hooks) == 0 {
|
|
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)
|
|
}
|
|
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 {
|
|
f, err := fuo.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return f
|
|
}
|
|
|
|
// 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)
|
|
}
|
|
}
|
|
|
|
func (fuo *FileUpdateOne) sqlSave(ctx context.Context) (f *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, 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 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 nodes := fuo.mutation.RemovedFieldIDs(); 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.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)
|
|
}
|
|
f = &File{config: fuo.config}
|
|
_spec.Assign = f.assignValues
|
|
_spec.ScanValues = f.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 f, nil
|
|
}
|