1054 lines
28 KiB
Go
1054 lines
28 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 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/entc/integration/ent/fieldtype"
|
|
"entgo.io/ent/entc/integration/ent/file"
|
|
"entgo.io/ent/entc/integration/ent/filetype"
|
|
"entgo.io/ent/entc/integration/ent/predicate"
|
|
"entgo.io/ent/entc/integration/ent/user"
|
|
"entgo.io/ent/schema/field"
|
|
)
|
|
|
|
// FileUpdate is the builder for updating File entities.
|
|
type FileUpdate struct {
|
|
config
|
|
hooks []Hook
|
|
mutation *FileMutation
|
|
modifiers []func(*sql.UpdateBuilder)
|
|
}
|
|
|
|
// Where appends a list predicates to the FileUpdate builder.
|
|
func (_u *FileUpdate) Where(ps ...predicate.File) *FileUpdate {
|
|
_u.mutation.Where(ps...)
|
|
return _u
|
|
}
|
|
|
|
// SetSetID sets the "set_id" field.
|
|
func (_u *FileUpdate) SetSetID(v int) *FileUpdate {
|
|
_u.mutation.ResetSetID()
|
|
_u.mutation.SetSetID(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableSetID sets the "set_id" field if the given value is not nil.
|
|
func (_u *FileUpdate) SetNillableSetID(v *int) *FileUpdate {
|
|
if v != nil {
|
|
_u.SetSetID(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// AddSetID adds value to the "set_id" field.
|
|
func (_u *FileUpdate) AddSetID(v int) *FileUpdate {
|
|
_u.mutation.AddSetID(v)
|
|
return _u
|
|
}
|
|
|
|
// ClearSetID clears the value of the "set_id" field.
|
|
func (_u *FileUpdate) ClearSetID() *FileUpdate {
|
|
_u.mutation.ClearSetID()
|
|
return _u
|
|
}
|
|
|
|
// SetSize sets the "size" field.
|
|
func (_u *FileUpdate) SetSize(v int) *FileUpdate {
|
|
_u.mutation.ResetSize()
|
|
_u.mutation.SetSize(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableSize sets the "size" field if the given value is not nil.
|
|
func (_u *FileUpdate) SetNillableSize(v *int) *FileUpdate {
|
|
if v != nil {
|
|
_u.SetSize(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// AddSize adds value to the "size" field.
|
|
func (_u *FileUpdate) AddSize(v int) *FileUpdate {
|
|
_u.mutation.AddSize(v)
|
|
return _u
|
|
}
|
|
|
|
// SetName sets the "name" field.
|
|
func (_u *FileUpdate) SetName(v string) *FileUpdate {
|
|
_u.mutation.SetName(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableName sets the "name" field if the given value is not nil.
|
|
func (_u *FileUpdate) SetNillableName(v *string) *FileUpdate {
|
|
if v != nil {
|
|
_u.SetName(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetUser sets the "user" field.
|
|
func (_u *FileUpdate) SetUser(v string) *FileUpdate {
|
|
_u.mutation.SetUser(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableUser sets the "user" field if the given value is not nil.
|
|
func (_u *FileUpdate) SetNillableUser(v *string) *FileUpdate {
|
|
if v != nil {
|
|
_u.SetUser(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearUser clears the value of the "user" field.
|
|
func (_u *FileUpdate) ClearUser() *FileUpdate {
|
|
_u.mutation.ClearUser()
|
|
return _u
|
|
}
|
|
|
|
// SetGroup sets the "group" field.
|
|
func (_u *FileUpdate) SetGroup(v string) *FileUpdate {
|
|
_u.mutation.SetGroup(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableGroup sets the "group" field if the given value is not nil.
|
|
func (_u *FileUpdate) SetNillableGroup(v *string) *FileUpdate {
|
|
if v != nil {
|
|
_u.SetGroup(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearGroup clears the value of the "group" field.
|
|
func (_u *FileUpdate) ClearGroup() *FileUpdate {
|
|
_u.mutation.ClearGroup()
|
|
return _u
|
|
}
|
|
|
|
// SetOp sets the "op" field.
|
|
func (_u *FileUpdate) SetOp(v bool) *FileUpdate {
|
|
_u.mutation.SetOpField(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableOp sets the "op" field if the given value is not nil.
|
|
func (_u *FileUpdate) SetNillableOp(v *bool) *FileUpdate {
|
|
if v != nil {
|
|
_u.SetOp(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearOp clears the value of the "op" field.
|
|
func (_u *FileUpdate) ClearOp() *FileUpdate {
|
|
_u.mutation.ClearOp()
|
|
return _u
|
|
}
|
|
|
|
// SetFieldID sets the "field_id" field.
|
|
func (_u *FileUpdate) SetFieldID(v int) *FileUpdate {
|
|
_u.mutation.ResetFieldID()
|
|
_u.mutation.SetFieldID(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableFieldID sets the "field_id" field if the given value is not nil.
|
|
func (_u *FileUpdate) SetNillableFieldID(v *int) *FileUpdate {
|
|
if v != nil {
|
|
_u.SetFieldID(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// AddFieldID adds value to the "field_id" field.
|
|
func (_u *FileUpdate) AddFieldID(v int) *FileUpdate {
|
|
_u.mutation.AddFieldID(v)
|
|
return _u
|
|
}
|
|
|
|
// ClearFieldID clears the value of the "field_id" field.
|
|
func (_u *FileUpdate) ClearFieldID() *FileUpdate {
|
|
_u.mutation.ClearFieldID()
|
|
return _u
|
|
}
|
|
|
|
// SetCreateTime sets the "create_time" field.
|
|
func (_u *FileUpdate) SetCreateTime(v time.Time) *FileUpdate {
|
|
_u.mutation.SetCreateTime(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableCreateTime sets the "create_time" field if the given value is not nil.
|
|
func (_u *FileUpdate) SetNillableCreateTime(v *time.Time) *FileUpdate {
|
|
if v != nil {
|
|
_u.SetCreateTime(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearCreateTime clears the value of the "create_time" field.
|
|
func (_u *FileUpdate) ClearCreateTime() *FileUpdate {
|
|
_u.mutation.ClearCreateTime()
|
|
return _u
|
|
}
|
|
|
|
// SetOwnerID sets the "owner" edge to the User entity by ID.
|
|
func (_u *FileUpdate) SetOwnerID(id int) *FileUpdate {
|
|
_u.mutation.SetOwnerID(id)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableOwnerID sets the "owner" edge to the User entity by ID if the given value is not nil.
|
|
func (_u *FileUpdate) SetNillableOwnerID(id *int) *FileUpdate {
|
|
if id != nil {
|
|
_u = _u.SetOwnerID(*id)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetOwner sets the "owner" edge to the User entity.
|
|
func (_u *FileUpdate) SetOwner(v *User) *FileUpdate {
|
|
return _u.SetOwnerID(v.ID)
|
|
}
|
|
|
|
// SetTypeID sets the "type" edge to the FileType entity by ID.
|
|
func (_u *FileUpdate) SetTypeID(id int) *FileUpdate {
|
|
_u.mutation.SetTypeID(id)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableTypeID sets the "type" edge to the FileType entity by ID if the given value is not nil.
|
|
func (_u *FileUpdate) SetNillableTypeID(id *int) *FileUpdate {
|
|
if id != nil {
|
|
_u = _u.SetTypeID(*id)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetType sets the "type" edge to the FileType entity.
|
|
func (_u *FileUpdate) SetType(v *FileType) *FileUpdate {
|
|
return _u.SetTypeID(v.ID)
|
|
}
|
|
|
|
// AddFieldIDs adds the "field" edge to the FieldType entity by IDs.
|
|
func (_u *FileUpdate) AddFieldIDs(ids ...int) *FileUpdate {
|
|
_u.mutation.AddFieldIDs(ids...)
|
|
return _u
|
|
}
|
|
|
|
// AddField adds the "field" edges to the FieldType entity.
|
|
func (_u *FileUpdate) AddField(v ...*FieldType) *FileUpdate {
|
|
ids := make([]int, len(v))
|
|
for i := range v {
|
|
ids[i] = v[i].ID
|
|
}
|
|
return _u.AddFieldIDs(ids...)
|
|
}
|
|
|
|
// Mutation returns the FileMutation object of the builder.
|
|
func (_u *FileUpdate) Mutation() *FileMutation {
|
|
return _u.mutation
|
|
}
|
|
|
|
// ClearOwner clears the "owner" edge to the User entity.
|
|
func (_u *FileUpdate) ClearOwner() *FileUpdate {
|
|
_u.mutation.ClearOwner()
|
|
return _u
|
|
}
|
|
|
|
// ClearType clears the "type" edge to the FileType entity.
|
|
func (_u *FileUpdate) ClearType() *FileUpdate {
|
|
_u.mutation.ClearType()
|
|
return _u
|
|
}
|
|
|
|
// ClearFieldEdge clears all "field" edges to the FieldType entity.
|
|
func (_u *FileUpdate) ClearFieldEdge() *FileUpdate {
|
|
_u.mutation.ClearFieldEdge()
|
|
return _u
|
|
}
|
|
|
|
// RemoveFieldIDs removes the "field" edge to FieldType entities by IDs.
|
|
func (_u *FileUpdate) RemoveFieldIDs(ids ...int) *FileUpdate {
|
|
_u.mutation.RemoveFieldIDs(ids...)
|
|
return _u
|
|
}
|
|
|
|
// RemoveField removes "field" edges to FieldType entities.
|
|
func (_u *FileUpdate) RemoveField(v ...*FieldType) *FileUpdate {
|
|
ids := make([]int, len(v))
|
|
for i := range v {
|
|
ids[i] = v[i].ID
|
|
}
|
|
return _u.RemoveFieldIDs(ids...)
|
|
}
|
|
|
|
// Save executes the query and returns the number of nodes affected by the update operation.
|
|
func (_u *FileUpdate) Save(ctx context.Context) (int, error) {
|
|
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (_u *FileUpdate) SaveX(ctx context.Context) int {
|
|
affected, err := _u.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return affected
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_u *FileUpdate) Exec(ctx context.Context) error {
|
|
_, err := _u.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_u *FileUpdate) ExecX(ctx context.Context) {
|
|
if err := _u.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (_u *FileUpdate) check() error {
|
|
if v, ok := _u.mutation.SetID(); ok {
|
|
if err := file.SetIDValidator(v); err != nil {
|
|
return &ValidationError{Name: "set_id", err: fmt.Errorf(`ent: validator failed for field "File.set_id": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.Size(); ok {
|
|
if err := file.SizeValidator(v); err != nil {
|
|
return &ValidationError{Name: "size", err: fmt.Errorf(`ent: validator failed for field "File.size": %w`, err)}
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
|
|
func (_u *FileUpdate) Modify(modifiers ...func(u *sql.UpdateBuilder)) *FileUpdate {
|
|
_u.modifiers = append(_u.modifiers, modifiers...)
|
|
return _u
|
|
}
|
|
|
|
func (_u *FileUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
|
if err := _u.check(); err != nil {
|
|
return _node, err
|
|
}
|
|
_spec := sqlgraph.NewUpdateSpec(file.Table, file.Columns, sqlgraph.NewFieldSpec(file.FieldID, field.TypeInt))
|
|
if ps := _u.mutation.Predicates(); len(ps) > 0 {
|
|
_spec.Predicate = func(selector *sql.Selector) {
|
|
for i := range ps {
|
|
ps[i](selector)
|
|
}
|
|
}
|
|
}
|
|
if value, ok := _u.mutation.SetID(); ok {
|
|
_spec.SetField(file.FieldSetID, field.TypeInt, value)
|
|
}
|
|
if value, ok := _u.mutation.AddedSetID(); ok {
|
|
_spec.AddField(file.FieldSetID, field.TypeInt, value)
|
|
}
|
|
if _u.mutation.SetIDCleared() {
|
|
_spec.ClearField(file.FieldSetID, field.TypeInt)
|
|
}
|
|
if value, ok := _u.mutation.Size(); ok {
|
|
_spec.SetField(file.FieldSize, field.TypeInt, value)
|
|
}
|
|
if value, ok := _u.mutation.AddedSize(); ok {
|
|
_spec.AddField(file.FieldSize, field.TypeInt, value)
|
|
}
|
|
if value, ok := _u.mutation.Name(); ok {
|
|
_spec.SetField(file.FieldName, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.User(); ok {
|
|
_spec.SetField(file.FieldUser, field.TypeString, value)
|
|
}
|
|
if _u.mutation.UserCleared() {
|
|
_spec.ClearField(file.FieldUser, field.TypeString)
|
|
}
|
|
if value, ok := _u.mutation.Group(); ok {
|
|
_spec.SetField(file.FieldGroup, field.TypeString, value)
|
|
}
|
|
if _u.mutation.GroupCleared() {
|
|
_spec.ClearField(file.FieldGroup, field.TypeString)
|
|
}
|
|
if value, ok := _u.mutation.GetOp(); ok {
|
|
_spec.SetField(file.FieldOp, field.TypeBool, value)
|
|
}
|
|
if _u.mutation.OpCleared() {
|
|
_spec.ClearField(file.FieldOp, field.TypeBool)
|
|
}
|
|
if value, ok := _u.mutation.FieldID(); ok {
|
|
_spec.SetField(file.FieldFieldID, field.TypeInt, value)
|
|
}
|
|
if value, ok := _u.mutation.AddedFieldID(); ok {
|
|
_spec.AddField(file.FieldFieldID, field.TypeInt, value)
|
|
}
|
|
if _u.mutation.FieldIDCleared() {
|
|
_spec.ClearField(file.FieldFieldID, field.TypeInt)
|
|
}
|
|
if value, ok := _u.mutation.CreateTime(); ok {
|
|
_spec.SetField(file.FieldCreateTime, field.TypeTime, value)
|
|
}
|
|
if _u.mutation.CreateTimeCleared() {
|
|
_spec.ClearField(file.FieldCreateTime, field.TypeTime)
|
|
}
|
|
if _u.mutation.OwnerCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: file.OwnerTable,
|
|
Columns: []string{file.OwnerColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := _u.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.NewFieldSpec(user.FieldID, field.TypeInt),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
|
}
|
|
if _u.mutation.TypeCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: file.TypeTable,
|
|
Columns: []string{file.TypeColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(filetype.FieldID, field.TypeInt),
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := _u.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.NewFieldSpec(filetype.FieldID, field.TypeInt),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
|
}
|
|
if _u.mutation.FieldEdgeCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: file.FieldTable,
|
|
Columns: []string{file.FieldColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(fieldtype.FieldID, field.TypeInt),
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := _u.mutation.RemovedFieldIDs(); len(nodes) > 0 && !_u.mutation.FieldEdgeCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: file.FieldTable,
|
|
Columns: []string{file.FieldColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(fieldtype.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 := _u.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.NewFieldSpec(fieldtype.FieldID, field.TypeInt),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
|
}
|
|
_spec.AddModifiers(_u.modifiers...)
|
|
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
|
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
|
err = &NotFoundError{file.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return 0, err
|
|
}
|
|
_u.mutation.done = true
|
|
return _node, nil
|
|
}
|
|
|
|
// FileUpdateOne is the builder for updating a single File entity.
|
|
type FileUpdateOne struct {
|
|
config
|
|
fields []string
|
|
hooks []Hook
|
|
mutation *FileMutation
|
|
modifiers []func(*sql.UpdateBuilder)
|
|
}
|
|
|
|
// SetSetID sets the "set_id" field.
|
|
func (_u *FileUpdateOne) SetSetID(v int) *FileUpdateOne {
|
|
_u.mutation.ResetSetID()
|
|
_u.mutation.SetSetID(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableSetID sets the "set_id" field if the given value is not nil.
|
|
func (_u *FileUpdateOne) SetNillableSetID(v *int) *FileUpdateOne {
|
|
if v != nil {
|
|
_u.SetSetID(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// AddSetID adds value to the "set_id" field.
|
|
func (_u *FileUpdateOne) AddSetID(v int) *FileUpdateOne {
|
|
_u.mutation.AddSetID(v)
|
|
return _u
|
|
}
|
|
|
|
// ClearSetID clears the value of the "set_id" field.
|
|
func (_u *FileUpdateOne) ClearSetID() *FileUpdateOne {
|
|
_u.mutation.ClearSetID()
|
|
return _u
|
|
}
|
|
|
|
// SetSize sets the "size" field.
|
|
func (_u *FileUpdateOne) SetSize(v int) *FileUpdateOne {
|
|
_u.mutation.ResetSize()
|
|
_u.mutation.SetSize(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableSize sets the "size" field if the given value is not nil.
|
|
func (_u *FileUpdateOne) SetNillableSize(v *int) *FileUpdateOne {
|
|
if v != nil {
|
|
_u.SetSize(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// AddSize adds value to the "size" field.
|
|
func (_u *FileUpdateOne) AddSize(v int) *FileUpdateOne {
|
|
_u.mutation.AddSize(v)
|
|
return _u
|
|
}
|
|
|
|
// SetName sets the "name" field.
|
|
func (_u *FileUpdateOne) SetName(v string) *FileUpdateOne {
|
|
_u.mutation.SetName(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableName sets the "name" field if the given value is not nil.
|
|
func (_u *FileUpdateOne) SetNillableName(v *string) *FileUpdateOne {
|
|
if v != nil {
|
|
_u.SetName(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetUser sets the "user" field.
|
|
func (_u *FileUpdateOne) SetUser(v string) *FileUpdateOne {
|
|
_u.mutation.SetUser(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableUser sets the "user" field if the given value is not nil.
|
|
func (_u *FileUpdateOne) SetNillableUser(v *string) *FileUpdateOne {
|
|
if v != nil {
|
|
_u.SetUser(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearUser clears the value of the "user" field.
|
|
func (_u *FileUpdateOne) ClearUser() *FileUpdateOne {
|
|
_u.mutation.ClearUser()
|
|
return _u
|
|
}
|
|
|
|
// SetGroup sets the "group" field.
|
|
func (_u *FileUpdateOne) SetGroup(v string) *FileUpdateOne {
|
|
_u.mutation.SetGroup(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableGroup sets the "group" field if the given value is not nil.
|
|
func (_u *FileUpdateOne) SetNillableGroup(v *string) *FileUpdateOne {
|
|
if v != nil {
|
|
_u.SetGroup(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearGroup clears the value of the "group" field.
|
|
func (_u *FileUpdateOne) ClearGroup() *FileUpdateOne {
|
|
_u.mutation.ClearGroup()
|
|
return _u
|
|
}
|
|
|
|
// SetOp sets the "op" field.
|
|
func (_u *FileUpdateOne) SetOp(v bool) *FileUpdateOne {
|
|
_u.mutation.SetOpField(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableOp sets the "op" field if the given value is not nil.
|
|
func (_u *FileUpdateOne) SetNillableOp(v *bool) *FileUpdateOne {
|
|
if v != nil {
|
|
_u.SetOp(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearOp clears the value of the "op" field.
|
|
func (_u *FileUpdateOne) ClearOp() *FileUpdateOne {
|
|
_u.mutation.ClearOp()
|
|
return _u
|
|
}
|
|
|
|
// SetFieldID sets the "field_id" field.
|
|
func (_u *FileUpdateOne) SetFieldID(v int) *FileUpdateOne {
|
|
_u.mutation.ResetFieldID()
|
|
_u.mutation.SetFieldID(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableFieldID sets the "field_id" field if the given value is not nil.
|
|
func (_u *FileUpdateOne) SetNillableFieldID(v *int) *FileUpdateOne {
|
|
if v != nil {
|
|
_u.SetFieldID(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// AddFieldID adds value to the "field_id" field.
|
|
func (_u *FileUpdateOne) AddFieldID(v int) *FileUpdateOne {
|
|
_u.mutation.AddFieldID(v)
|
|
return _u
|
|
}
|
|
|
|
// ClearFieldID clears the value of the "field_id" field.
|
|
func (_u *FileUpdateOne) ClearFieldID() *FileUpdateOne {
|
|
_u.mutation.ClearFieldID()
|
|
return _u
|
|
}
|
|
|
|
// SetCreateTime sets the "create_time" field.
|
|
func (_u *FileUpdateOne) SetCreateTime(v time.Time) *FileUpdateOne {
|
|
_u.mutation.SetCreateTime(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableCreateTime sets the "create_time" field if the given value is not nil.
|
|
func (_u *FileUpdateOne) SetNillableCreateTime(v *time.Time) *FileUpdateOne {
|
|
if v != nil {
|
|
_u.SetCreateTime(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearCreateTime clears the value of the "create_time" field.
|
|
func (_u *FileUpdateOne) ClearCreateTime() *FileUpdateOne {
|
|
_u.mutation.ClearCreateTime()
|
|
return _u
|
|
}
|
|
|
|
// SetOwnerID sets the "owner" edge to the User entity by ID.
|
|
func (_u *FileUpdateOne) SetOwnerID(id int) *FileUpdateOne {
|
|
_u.mutation.SetOwnerID(id)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableOwnerID sets the "owner" edge to the User entity by ID if the given value is not nil.
|
|
func (_u *FileUpdateOne) SetNillableOwnerID(id *int) *FileUpdateOne {
|
|
if id != nil {
|
|
_u = _u.SetOwnerID(*id)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetOwner sets the "owner" edge to the User entity.
|
|
func (_u *FileUpdateOne) SetOwner(v *User) *FileUpdateOne {
|
|
return _u.SetOwnerID(v.ID)
|
|
}
|
|
|
|
// SetTypeID sets the "type" edge to the FileType entity by ID.
|
|
func (_u *FileUpdateOne) SetTypeID(id int) *FileUpdateOne {
|
|
_u.mutation.SetTypeID(id)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableTypeID sets the "type" edge to the FileType entity by ID if the given value is not nil.
|
|
func (_u *FileUpdateOne) SetNillableTypeID(id *int) *FileUpdateOne {
|
|
if id != nil {
|
|
_u = _u.SetTypeID(*id)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetType sets the "type" edge to the FileType entity.
|
|
func (_u *FileUpdateOne) SetType(v *FileType) *FileUpdateOne {
|
|
return _u.SetTypeID(v.ID)
|
|
}
|
|
|
|
// AddFieldIDs adds the "field" edge to the FieldType entity by IDs.
|
|
func (_u *FileUpdateOne) AddFieldIDs(ids ...int) *FileUpdateOne {
|
|
_u.mutation.AddFieldIDs(ids...)
|
|
return _u
|
|
}
|
|
|
|
// AddField adds the "field" edges to the FieldType entity.
|
|
func (_u *FileUpdateOne) AddField(v ...*FieldType) *FileUpdateOne {
|
|
ids := make([]int, len(v))
|
|
for i := range v {
|
|
ids[i] = v[i].ID
|
|
}
|
|
return _u.AddFieldIDs(ids...)
|
|
}
|
|
|
|
// Mutation returns the FileMutation object of the builder.
|
|
func (_u *FileUpdateOne) Mutation() *FileMutation {
|
|
return _u.mutation
|
|
}
|
|
|
|
// ClearOwner clears the "owner" edge to the User entity.
|
|
func (_u *FileUpdateOne) ClearOwner() *FileUpdateOne {
|
|
_u.mutation.ClearOwner()
|
|
return _u
|
|
}
|
|
|
|
// ClearType clears the "type" edge to the FileType entity.
|
|
func (_u *FileUpdateOne) ClearType() *FileUpdateOne {
|
|
_u.mutation.ClearType()
|
|
return _u
|
|
}
|
|
|
|
// ClearFieldEdge clears all "field" edges to the FieldType entity.
|
|
func (_u *FileUpdateOne) ClearFieldEdge() *FileUpdateOne {
|
|
_u.mutation.ClearFieldEdge()
|
|
return _u
|
|
}
|
|
|
|
// RemoveFieldIDs removes the "field" edge to FieldType entities by IDs.
|
|
func (_u *FileUpdateOne) RemoveFieldIDs(ids ...int) *FileUpdateOne {
|
|
_u.mutation.RemoveFieldIDs(ids...)
|
|
return _u
|
|
}
|
|
|
|
// RemoveField removes "field" edges to FieldType entities.
|
|
func (_u *FileUpdateOne) RemoveField(v ...*FieldType) *FileUpdateOne {
|
|
ids := make([]int, len(v))
|
|
for i := range v {
|
|
ids[i] = v[i].ID
|
|
}
|
|
return _u.RemoveFieldIDs(ids...)
|
|
}
|
|
|
|
// Where appends a list predicates to the FileUpdate builder.
|
|
func (_u *FileUpdateOne) Where(ps ...predicate.File) *FileUpdateOne {
|
|
_u.mutation.Where(ps...)
|
|
return _u
|
|
}
|
|
|
|
// Select allows selecting one or more fields (columns) of the returned entity.
|
|
// The default is selecting all fields defined in the entity schema.
|
|
func (_u *FileUpdateOne) Select(field string, fields ...string) *FileUpdateOne {
|
|
_u.fields = append([]string{field}, fields...)
|
|
return _u
|
|
}
|
|
|
|
// Save executes the query and returns the updated File entity.
|
|
func (_u *FileUpdateOne) Save(ctx context.Context) (*File, error) {
|
|
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (_u *FileUpdateOne) SaveX(ctx context.Context) *File {
|
|
node, err := _u.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return node
|
|
}
|
|
|
|
// Exec executes the query on the entity.
|
|
func (_u *FileUpdateOne) Exec(ctx context.Context) error {
|
|
_, err := _u.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_u *FileUpdateOne) ExecX(ctx context.Context) {
|
|
if err := _u.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (_u *FileUpdateOne) check() error {
|
|
if v, ok := _u.mutation.SetID(); ok {
|
|
if err := file.SetIDValidator(v); err != nil {
|
|
return &ValidationError{Name: "set_id", err: fmt.Errorf(`ent: validator failed for field "File.set_id": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.Size(); ok {
|
|
if err := file.SizeValidator(v); err != nil {
|
|
return &ValidationError{Name: "size", err: fmt.Errorf(`ent: validator failed for field "File.size": %w`, err)}
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
|
|
func (_u *FileUpdateOne) Modify(modifiers ...func(u *sql.UpdateBuilder)) *FileUpdateOne {
|
|
_u.modifiers = append(_u.modifiers, modifiers...)
|
|
return _u
|
|
}
|
|
|
|
func (_u *FileUpdateOne) sqlSave(ctx context.Context) (_node *File, err error) {
|
|
if err := _u.check(); err != nil {
|
|
return _node, err
|
|
}
|
|
_spec := sqlgraph.NewUpdateSpec(file.Table, file.Columns, sqlgraph.NewFieldSpec(file.FieldID, field.TypeInt))
|
|
id, ok := _u.mutation.ID()
|
|
if !ok {
|
|
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "File.id" for update`)}
|
|
}
|
|
_spec.Node.ID.Value = id
|
|
if fields := _u.fields; len(fields) > 0 {
|
|
_spec.Node.Columns = make([]string, 0, len(fields))
|
|
_spec.Node.Columns = append(_spec.Node.Columns, file.FieldID)
|
|
for _, f := range fields {
|
|
if !file.ValidColumn(f) {
|
|
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
|
}
|
|
if f != file.FieldID {
|
|
_spec.Node.Columns = append(_spec.Node.Columns, f)
|
|
}
|
|
}
|
|
}
|
|
if ps := _u.mutation.Predicates(); len(ps) > 0 {
|
|
_spec.Predicate = func(selector *sql.Selector) {
|
|
for i := range ps {
|
|
ps[i](selector)
|
|
}
|
|
}
|
|
}
|
|
if value, ok := _u.mutation.SetID(); ok {
|
|
_spec.SetField(file.FieldSetID, field.TypeInt, value)
|
|
}
|
|
if value, ok := _u.mutation.AddedSetID(); ok {
|
|
_spec.AddField(file.FieldSetID, field.TypeInt, value)
|
|
}
|
|
if _u.mutation.SetIDCleared() {
|
|
_spec.ClearField(file.FieldSetID, field.TypeInt)
|
|
}
|
|
if value, ok := _u.mutation.Size(); ok {
|
|
_spec.SetField(file.FieldSize, field.TypeInt, value)
|
|
}
|
|
if value, ok := _u.mutation.AddedSize(); ok {
|
|
_spec.AddField(file.FieldSize, field.TypeInt, value)
|
|
}
|
|
if value, ok := _u.mutation.Name(); ok {
|
|
_spec.SetField(file.FieldName, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.User(); ok {
|
|
_spec.SetField(file.FieldUser, field.TypeString, value)
|
|
}
|
|
if _u.mutation.UserCleared() {
|
|
_spec.ClearField(file.FieldUser, field.TypeString)
|
|
}
|
|
if value, ok := _u.mutation.Group(); ok {
|
|
_spec.SetField(file.FieldGroup, field.TypeString, value)
|
|
}
|
|
if _u.mutation.GroupCleared() {
|
|
_spec.ClearField(file.FieldGroup, field.TypeString)
|
|
}
|
|
if value, ok := _u.mutation.GetOp(); ok {
|
|
_spec.SetField(file.FieldOp, field.TypeBool, value)
|
|
}
|
|
if _u.mutation.OpCleared() {
|
|
_spec.ClearField(file.FieldOp, field.TypeBool)
|
|
}
|
|
if value, ok := _u.mutation.FieldID(); ok {
|
|
_spec.SetField(file.FieldFieldID, field.TypeInt, value)
|
|
}
|
|
if value, ok := _u.mutation.AddedFieldID(); ok {
|
|
_spec.AddField(file.FieldFieldID, field.TypeInt, value)
|
|
}
|
|
if _u.mutation.FieldIDCleared() {
|
|
_spec.ClearField(file.FieldFieldID, field.TypeInt)
|
|
}
|
|
if value, ok := _u.mutation.CreateTime(); ok {
|
|
_spec.SetField(file.FieldCreateTime, field.TypeTime, value)
|
|
}
|
|
if _u.mutation.CreateTimeCleared() {
|
|
_spec.ClearField(file.FieldCreateTime, field.TypeTime)
|
|
}
|
|
if _u.mutation.OwnerCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: file.OwnerTable,
|
|
Columns: []string{file.OwnerColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := _u.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.NewFieldSpec(user.FieldID, field.TypeInt),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
|
}
|
|
if _u.mutation.TypeCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: file.TypeTable,
|
|
Columns: []string{file.TypeColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(filetype.FieldID, field.TypeInt),
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := _u.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.NewFieldSpec(filetype.FieldID, field.TypeInt),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
|
}
|
|
if _u.mutation.FieldEdgeCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: file.FieldTable,
|
|
Columns: []string{file.FieldColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(fieldtype.FieldID, field.TypeInt),
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := _u.mutation.RemovedFieldIDs(); len(nodes) > 0 && !_u.mutation.FieldEdgeCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: file.FieldTable,
|
|
Columns: []string{file.FieldColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(fieldtype.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 := _u.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.NewFieldSpec(fieldtype.FieldID, field.TypeInt),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
|
}
|
|
_spec.AddModifiers(_u.modifiers...)
|
|
_node = &File{config: _u.config}
|
|
_spec.Assign = _node.assignValues
|
|
_spec.ScanValues = _node.scanValues
|
|
if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil {
|
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
|
err = &NotFoundError{file.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return nil, err
|
|
}
|
|
_u.mutation.done = true
|
|
return _node, nil
|
|
}
|