Files
upstream-ent/entc/integration/ent/file_create.go
upstream-mirror 4b3ad0b611
Some checks failed
Atlas CI Public / lint (push) Failing after 13s
Atlas CI Public / sync (push) Has been skipped
snapshot of https://github.com/ent/ent.git (master, 2026-09-15; blobs > 131072B omitted)
2026-09-15 22:12:36 +05:00

1175 lines
30 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/user"
"entgo.io/ent/schema/field"
)
// FileCreate is the builder for creating a File entity.
type FileCreate struct {
config
mutation *FileMutation
hooks []Hook
conflict []sql.ConflictOption
}
// SetSetID sets the "set_id" field.
func (_c *FileCreate) SetSetID(v int) *FileCreate {
_c.mutation.SetSetID(v)
return _c
}
// SetNillableSetID sets the "set_id" field if the given value is not nil.
func (_c *FileCreate) SetNillableSetID(v *int) *FileCreate {
if v != nil {
_c.SetSetID(*v)
}
return _c
}
// SetSize sets the "size" field.
func (_c *FileCreate) SetSize(v int) *FileCreate {
_c.mutation.SetSize(v)
return _c
}
// SetNillableSize sets the "size" field if the given value is not nil.
func (_c *FileCreate) SetNillableSize(v *int) *FileCreate {
if v != nil {
_c.SetSize(*v)
}
return _c
}
// SetName sets the "name" field.
func (_c *FileCreate) SetName(v string) *FileCreate {
_c.mutation.SetName(v)
return _c
}
// SetUser sets the "user" field.
func (_c *FileCreate) SetUser(v string) *FileCreate {
_c.mutation.SetUser(v)
return _c
}
// SetNillableUser sets the "user" field if the given value is not nil.
func (_c *FileCreate) SetNillableUser(v *string) *FileCreate {
if v != nil {
_c.SetUser(*v)
}
return _c
}
// SetGroup sets the "group" field.
func (_c *FileCreate) SetGroup(v string) *FileCreate {
_c.mutation.SetGroup(v)
return _c
}
// SetNillableGroup sets the "group" field if the given value is not nil.
func (_c *FileCreate) SetNillableGroup(v *string) *FileCreate {
if v != nil {
_c.SetGroup(*v)
}
return _c
}
// SetOp sets the "op" field.
func (_c *FileCreate) SetOp(v bool) *FileCreate {
_c.mutation.SetOpField(v)
return _c
}
// SetNillableOp sets the "op" field if the given value is not nil.
func (_c *FileCreate) SetNillableOp(v *bool) *FileCreate {
if v != nil {
_c.SetOp(*v)
}
return _c
}
// SetFieldID sets the "field_id" field.
func (_c *FileCreate) SetFieldID(v int) *FileCreate {
_c.mutation.SetFieldID(v)
return _c
}
// SetNillableFieldID sets the "field_id" field if the given value is not nil.
func (_c *FileCreate) SetNillableFieldID(v *int) *FileCreate {
if v != nil {
_c.SetFieldID(*v)
}
return _c
}
// SetCreateTime sets the "create_time" field.
func (_c *FileCreate) SetCreateTime(v time.Time) *FileCreate {
_c.mutation.SetCreateTime(v)
return _c
}
// SetNillableCreateTime sets the "create_time" field if the given value is not nil.
func (_c *FileCreate) SetNillableCreateTime(v *time.Time) *FileCreate {
if v != nil {
_c.SetCreateTime(*v)
}
return _c
}
// SetOwnerID sets the "owner" edge to the User entity by ID.
func (_c *FileCreate) SetOwnerID(id int) *FileCreate {
_c.mutation.SetOwnerID(id)
return _c
}
// SetNillableOwnerID sets the "owner" edge to the User entity by ID if the given value is not nil.
func (_c *FileCreate) SetNillableOwnerID(id *int) *FileCreate {
if id != nil {
_c = _c.SetOwnerID(*id)
}
return _c
}
// SetOwner sets the "owner" edge to the User entity.
func (_c *FileCreate) SetOwner(v *User) *FileCreate {
return _c.SetOwnerID(v.ID)
}
// SetTypeID sets the "type" edge to the FileType entity by ID.
func (_c *FileCreate) SetTypeID(id int) *FileCreate {
_c.mutation.SetTypeID(id)
return _c
}
// SetNillableTypeID sets the "type" edge to the FileType entity by ID if the given value is not nil.
func (_c *FileCreate) SetNillableTypeID(id *int) *FileCreate {
if id != nil {
_c = _c.SetTypeID(*id)
}
return _c
}
// SetType sets the "type" edge to the FileType entity.
func (_c *FileCreate) SetType(v *FileType) *FileCreate {
return _c.SetTypeID(v.ID)
}
// AddFieldIDs adds the "field" edge to the FieldType entity by IDs.
func (_c *FileCreate) AddFieldIDs(ids ...int) *FileCreate {
_c.mutation.AddFieldIDs(ids...)
return _c
}
// AddField adds the "field" edges to the FieldType entity.
func (_c *FileCreate) AddField(v ...*FieldType) *FileCreate {
ids := make([]int, len(v))
for i := range v {
ids[i] = v[i].ID
}
return _c.AddFieldIDs(ids...)
}
// Mutation returns the FileMutation object of the builder.
func (_c *FileCreate) Mutation() *FileMutation {
return _c.mutation
}
// Save creates the File in the database.
func (_c *FileCreate) Save(ctx context.Context) (*File, error) {
_c.defaults()
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
}
// SaveX calls Save and panics if Save returns an error.
func (_c *FileCreate) SaveX(ctx context.Context) *File {
v, err := _c.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (_c *FileCreate) Exec(ctx context.Context) error {
_, err := _c.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_c *FileCreate) ExecX(ctx context.Context) {
if err := _c.Exec(ctx); err != nil {
panic(err)
}
}
// defaults sets the default values of the builder before save.
func (_c *FileCreate) defaults() {
if _, ok := _c.mutation.Size(); !ok {
v := file.DefaultSize
_c.mutation.SetSize(v)
}
}
// check runs all checks and user-defined validators on the builder.
func (_c *FileCreate) check() error {
if v, ok := _c.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 _, ok := _c.mutation.Size(); !ok {
return &ValidationError{Name: "size", err: errors.New(`ent: missing required field "File.size"`)}
}
if v, ok := _c.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)}
}
}
if _, ok := _c.mutation.Name(); !ok {
return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "File.name"`)}
}
return nil
}
func (_c *FileCreate) sqlSave(ctx context.Context) (*File, error) {
if err := _c.check(); err != nil {
return nil, err
}
_node, _spec := _c.createSpec()
if err := sqlgraph.CreateNode(ctx, _c.driver, _spec); err != nil {
if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return nil, err
}
id := _spec.ID.Value.(int64)
_node.ID = int(id)
_c.mutation.id = &_node.ID
_c.mutation.done = true
return _node, nil
}
func (_c *FileCreate) createSpec() (*File, *sqlgraph.CreateSpec) {
var (
_node = &File{config: _c.config}
_spec = sqlgraph.NewCreateSpec(file.Table, sqlgraph.NewFieldSpec(file.FieldID, field.TypeInt))
)
_spec.OnConflict = _c.conflict
if value, ok := _c.mutation.SetID(); ok {
_spec.SetField(file.FieldSetID, field.TypeInt, value)
_node.SetID = value
}
if value, ok := _c.mutation.Size(); ok {
_spec.SetField(file.FieldSize, field.TypeInt, value)
_node.Size = value
}
if value, ok := _c.mutation.Name(); ok {
_spec.SetField(file.FieldName, field.TypeString, value)
_node.Name = value
}
if value, ok := _c.mutation.User(); ok {
_spec.SetField(file.FieldUser, field.TypeString, value)
_node.User = &value
}
if value, ok := _c.mutation.Group(); ok {
_spec.SetField(file.FieldGroup, field.TypeString, value)
_node.Group = value
}
if value, ok := _c.mutation.GetOp(); ok {
_spec.SetField(file.FieldOp, field.TypeBool, value)
_node.Op = value
}
if value, ok := _c.mutation.FieldID(); ok {
_spec.SetField(file.FieldFieldID, field.TypeInt, value)
_node.FieldID = value
}
if value, ok := _c.mutation.CreateTime(); ok {
_spec.SetField(file.FieldCreateTime, field.TypeTime, value)
_node.CreateTime = value
}
if nodes := _c.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)
}
_node.user_files = &nodes[0]
_spec.Edges = append(_spec.Edges, edge)
}
if nodes := _c.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)
}
_node.file_type_files = &nodes[0]
_spec.Edges = append(_spec.Edges, edge)
}
if nodes := _c.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 = append(_spec.Edges, edge)
}
return _node, _spec
}
// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
// of the `INSERT` statement. For example:
//
// client.File.Create().
// SetSetID(v).
// OnConflict(
// // Update the row with the new values
// // the was proposed for insertion.
// sql.ResolveWithNewValues(),
// ).
// // Override some of the fields with custom
// // update values.
// Update(func(u *ent.FileUpsert) {
// SetSetID(v+v).
// }).
// Exec(ctx)
func (_c *FileCreate) OnConflict(opts ...sql.ConflictOption) *FileUpsertOne {
_c.conflict = opts
return &FileUpsertOne{
create: _c,
}
}
// OnConflictColumns calls `OnConflict` and configures the columns
// as conflict target. Using this option is equivalent to using:
//
// client.File.Create().
// OnConflict(sql.ConflictColumns(columns...)).
// Exec(ctx)
func (_c *FileCreate) OnConflictColumns(columns ...string) *FileUpsertOne {
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
return &FileUpsertOne{
create: _c,
}
}
type (
// FileUpsertOne is the builder for "upsert"-ing
// one File node.
FileUpsertOne struct {
create *FileCreate
}
// FileUpsert is the "OnConflict" setter.
FileUpsert struct {
*sql.UpdateSet
}
)
// SetSetID sets the "set_id" field.
func (u *FileUpsert) SetSetID(v int) *FileUpsert {
u.Set(file.FieldSetID, v)
return u
}
// UpdateSetID sets the "set_id" field to the value that was provided on create.
func (u *FileUpsert) UpdateSetID() *FileUpsert {
u.SetExcluded(file.FieldSetID)
return u
}
// AddSetID adds v to the "set_id" field.
func (u *FileUpsert) AddSetID(v int) *FileUpsert {
u.Add(file.FieldSetID, v)
return u
}
// ClearSetID clears the value of the "set_id" field.
func (u *FileUpsert) ClearSetID() *FileUpsert {
u.SetNull(file.FieldSetID)
return u
}
// SetSize sets the "size" field.
func (u *FileUpsert) SetSize(v int) *FileUpsert {
u.Set(file.FieldSize, v)
return u
}
// UpdateSize sets the "size" field to the value that was provided on create.
func (u *FileUpsert) UpdateSize() *FileUpsert {
u.SetExcluded(file.FieldSize)
return u
}
// AddSize adds v to the "size" field.
func (u *FileUpsert) AddSize(v int) *FileUpsert {
u.Add(file.FieldSize, v)
return u
}
// SetName sets the "name" field.
func (u *FileUpsert) SetName(v string) *FileUpsert {
u.Set(file.FieldName, v)
return u
}
// UpdateName sets the "name" field to the value that was provided on create.
func (u *FileUpsert) UpdateName() *FileUpsert {
u.SetExcluded(file.FieldName)
return u
}
// SetUser sets the "user" field.
func (u *FileUpsert) SetUser(v string) *FileUpsert {
u.Set(file.FieldUser, v)
return u
}
// UpdateUser sets the "user" field to the value that was provided on create.
func (u *FileUpsert) UpdateUser() *FileUpsert {
u.SetExcluded(file.FieldUser)
return u
}
// ClearUser clears the value of the "user" field.
func (u *FileUpsert) ClearUser() *FileUpsert {
u.SetNull(file.FieldUser)
return u
}
// SetGroup sets the "group" field.
func (u *FileUpsert) SetGroup(v string) *FileUpsert {
u.Set(file.FieldGroup, v)
return u
}
// UpdateGroup sets the "group" field to the value that was provided on create.
func (u *FileUpsert) UpdateGroup() *FileUpsert {
u.SetExcluded(file.FieldGroup)
return u
}
// ClearGroup clears the value of the "group" field.
func (u *FileUpsert) ClearGroup() *FileUpsert {
u.SetNull(file.FieldGroup)
return u
}
// SetOp sets the "op" field.
func (u *FileUpsert) SetOp(v bool) *FileUpsert {
u.Set(file.FieldOp, v)
return u
}
// UpdateOp sets the "op" field to the value that was provided on create.
func (u *FileUpsert) UpdateOp() *FileUpsert {
u.SetExcluded(file.FieldOp)
return u
}
// ClearOp clears the value of the "op" field.
func (u *FileUpsert) ClearOp() *FileUpsert {
u.SetNull(file.FieldOp)
return u
}
// SetFieldID sets the "field_id" field.
func (u *FileUpsert) SetFieldID(v int) *FileUpsert {
u.Set(file.FieldFieldID, v)
return u
}
// UpdateFieldID sets the "field_id" field to the value that was provided on create.
func (u *FileUpsert) UpdateFieldID() *FileUpsert {
u.SetExcluded(file.FieldFieldID)
return u
}
// AddFieldID adds v to the "field_id" field.
func (u *FileUpsert) AddFieldID(v int) *FileUpsert {
u.Add(file.FieldFieldID, v)
return u
}
// ClearFieldID clears the value of the "field_id" field.
func (u *FileUpsert) ClearFieldID() *FileUpsert {
u.SetNull(file.FieldFieldID)
return u
}
// SetCreateTime sets the "create_time" field.
func (u *FileUpsert) SetCreateTime(v time.Time) *FileUpsert {
u.Set(file.FieldCreateTime, v)
return u
}
// UpdateCreateTime sets the "create_time" field to the value that was provided on create.
func (u *FileUpsert) UpdateCreateTime() *FileUpsert {
u.SetExcluded(file.FieldCreateTime)
return u
}
// ClearCreateTime clears the value of the "create_time" field.
func (u *FileUpsert) ClearCreateTime() *FileUpsert {
u.SetNull(file.FieldCreateTime)
return u
}
// UpdateNewValues updates the mutable fields using the new values that were set on create.
// Using this option is equivalent to using:
//
// client.File.Create().
// OnConflict(
// sql.ResolveWithNewValues(),
// ).
// Exec(ctx)
func (u *FileUpsertOne) UpdateNewValues() *FileUpsertOne {
u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
return u
}
// Ignore sets each column to itself in case of conflict.
// Using this option is equivalent to using:
//
// client.File.Create().
// OnConflict(sql.ResolveWithIgnore()).
// Exec(ctx)
func (u *FileUpsertOne) Ignore() *FileUpsertOne {
u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
return u
}
// DoNothing configures the conflict_action to `DO NOTHING`.
// Supported only by SQLite and PostgreSQL.
func (u *FileUpsertOne) DoNothing() *FileUpsertOne {
u.create.conflict = append(u.create.conflict, sql.DoNothing())
return u
}
// Update allows overriding fields `UPDATE` values. See the FileCreate.OnConflict
// documentation for more info.
func (u *FileUpsertOne) Update(set func(*FileUpsert)) *FileUpsertOne {
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
set(&FileUpsert{UpdateSet: update})
}))
return u
}
// SetSetID sets the "set_id" field.
func (u *FileUpsertOne) SetSetID(v int) *FileUpsertOne {
return u.Update(func(s *FileUpsert) {
s.SetSetID(v)
})
}
// AddSetID adds v to the "set_id" field.
func (u *FileUpsertOne) AddSetID(v int) *FileUpsertOne {
return u.Update(func(s *FileUpsert) {
s.AddSetID(v)
})
}
// UpdateSetID sets the "set_id" field to the value that was provided on create.
func (u *FileUpsertOne) UpdateSetID() *FileUpsertOne {
return u.Update(func(s *FileUpsert) {
s.UpdateSetID()
})
}
// ClearSetID clears the value of the "set_id" field.
func (u *FileUpsertOne) ClearSetID() *FileUpsertOne {
return u.Update(func(s *FileUpsert) {
s.ClearSetID()
})
}
// SetSize sets the "size" field.
func (u *FileUpsertOne) SetSize(v int) *FileUpsertOne {
return u.Update(func(s *FileUpsert) {
s.SetSize(v)
})
}
// AddSize adds v to the "size" field.
func (u *FileUpsertOne) AddSize(v int) *FileUpsertOne {
return u.Update(func(s *FileUpsert) {
s.AddSize(v)
})
}
// UpdateSize sets the "size" field to the value that was provided on create.
func (u *FileUpsertOne) UpdateSize() *FileUpsertOne {
return u.Update(func(s *FileUpsert) {
s.UpdateSize()
})
}
// SetName sets the "name" field.
func (u *FileUpsertOne) SetName(v string) *FileUpsertOne {
return u.Update(func(s *FileUpsert) {
s.SetName(v)
})
}
// UpdateName sets the "name" field to the value that was provided on create.
func (u *FileUpsertOne) UpdateName() *FileUpsertOne {
return u.Update(func(s *FileUpsert) {
s.UpdateName()
})
}
// SetUser sets the "user" field.
func (u *FileUpsertOne) SetUser(v string) *FileUpsertOne {
return u.Update(func(s *FileUpsert) {
s.SetUser(v)
})
}
// UpdateUser sets the "user" field to the value that was provided on create.
func (u *FileUpsertOne) UpdateUser() *FileUpsertOne {
return u.Update(func(s *FileUpsert) {
s.UpdateUser()
})
}
// ClearUser clears the value of the "user" field.
func (u *FileUpsertOne) ClearUser() *FileUpsertOne {
return u.Update(func(s *FileUpsert) {
s.ClearUser()
})
}
// SetGroup sets the "group" field.
func (u *FileUpsertOne) SetGroup(v string) *FileUpsertOne {
return u.Update(func(s *FileUpsert) {
s.SetGroup(v)
})
}
// UpdateGroup sets the "group" field to the value that was provided on create.
func (u *FileUpsertOne) UpdateGroup() *FileUpsertOne {
return u.Update(func(s *FileUpsert) {
s.UpdateGroup()
})
}
// ClearGroup clears the value of the "group" field.
func (u *FileUpsertOne) ClearGroup() *FileUpsertOne {
return u.Update(func(s *FileUpsert) {
s.ClearGroup()
})
}
// SetOp sets the "op" field.
func (u *FileUpsertOne) SetOp(v bool) *FileUpsertOne {
return u.Update(func(s *FileUpsert) {
s.SetOp(v)
})
}
// UpdateOp sets the "op" field to the value that was provided on create.
func (u *FileUpsertOne) UpdateOp() *FileUpsertOne {
return u.Update(func(s *FileUpsert) {
s.UpdateOp()
})
}
// ClearOp clears the value of the "op" field.
func (u *FileUpsertOne) ClearOp() *FileUpsertOne {
return u.Update(func(s *FileUpsert) {
s.ClearOp()
})
}
// SetFieldID sets the "field_id" field.
func (u *FileUpsertOne) SetFieldID(v int) *FileUpsertOne {
return u.Update(func(s *FileUpsert) {
s.SetFieldID(v)
})
}
// AddFieldID adds v to the "field_id" field.
func (u *FileUpsertOne) AddFieldID(v int) *FileUpsertOne {
return u.Update(func(s *FileUpsert) {
s.AddFieldID(v)
})
}
// UpdateFieldID sets the "field_id" field to the value that was provided on create.
func (u *FileUpsertOne) UpdateFieldID() *FileUpsertOne {
return u.Update(func(s *FileUpsert) {
s.UpdateFieldID()
})
}
// ClearFieldID clears the value of the "field_id" field.
func (u *FileUpsertOne) ClearFieldID() *FileUpsertOne {
return u.Update(func(s *FileUpsert) {
s.ClearFieldID()
})
}
// SetCreateTime sets the "create_time" field.
func (u *FileUpsertOne) SetCreateTime(v time.Time) *FileUpsertOne {
return u.Update(func(s *FileUpsert) {
s.SetCreateTime(v)
})
}
// UpdateCreateTime sets the "create_time" field to the value that was provided on create.
func (u *FileUpsertOne) UpdateCreateTime() *FileUpsertOne {
return u.Update(func(s *FileUpsert) {
s.UpdateCreateTime()
})
}
// ClearCreateTime clears the value of the "create_time" field.
func (u *FileUpsertOne) ClearCreateTime() *FileUpsertOne {
return u.Update(func(s *FileUpsert) {
s.ClearCreateTime()
})
}
// Exec executes the query.
func (u *FileUpsertOne) Exec(ctx context.Context) error {
if len(u.create.conflict) == 0 {
return errors.New("ent: missing options for FileCreate.OnConflict")
}
return u.create.Exec(ctx)
}
// ExecX is like Exec, but panics if an error occurs.
func (u *FileUpsertOne) ExecX(ctx context.Context) {
if err := u.create.Exec(ctx); err != nil {
panic(err)
}
}
// Exec executes the UPSERT query and returns the inserted/updated ID.
func (u *FileUpsertOne) ID(ctx context.Context) (id int, err error) {
node, err := u.create.Save(ctx)
if err != nil {
return id, err
}
return node.ID, nil
}
// IDX is like ID, but panics if an error occurs.
func (u *FileUpsertOne) IDX(ctx context.Context) int {
id, err := u.ID(ctx)
if err != nil {
panic(err)
}
return id
}
// FileCreateBulk is the builder for creating many File entities in bulk.
type FileCreateBulk struct {
config
err error
builders []*FileCreate
conflict []sql.ConflictOption
}
// Save creates the File entities in the database.
func (_c *FileCreateBulk) Save(ctx context.Context) ([]*File, error) {
if _c.err != nil {
return nil, _c.err
}
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
nodes := make([]*File, len(_c.builders))
mutators := make([]Mutator, len(_c.builders))
for i := range _c.builders {
func(i int, root context.Context) {
builder := _c.builders[i]
builder.defaults()
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 := builder.check(); err != nil {
return nil, err
}
builder.mutation = mutation
var err error
nodes[i], specs[i] = builder.createSpec()
if i < len(mutators)-1 {
_, err = mutators[i+1].Mutate(root, _c.builders[i+1].mutation)
} else {
spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
spec.OnConflict = _c.conflict
// Invoke the actual operation on the latest mutation in the chain.
if err = sqlgraph.BatchCreate(ctx, _c.driver, spec); err != nil {
if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
}
}
if err != nil {
return nil, err
}
mutation.id = &nodes[i].ID
if specs[i].ID.Value != nil {
id := specs[i].ID.Value.(int64)
nodes[i].ID = int(id)
}
mutation.done = true
return nodes[i], nil
})
for i := len(builder.hooks) - 1; i >= 0; i-- {
mut = builder.hooks[i](mut)
}
mutators[i] = mut
}(i, ctx)
}
if len(mutators) > 0 {
if _, err := mutators[0].Mutate(ctx, _c.builders[0].mutation); err != nil {
return nil, err
}
}
return nodes, nil
}
// SaveX is like Save, but panics if an error occurs.
func (_c *FileCreateBulk) SaveX(ctx context.Context) []*File {
v, err := _c.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (_c *FileCreateBulk) Exec(ctx context.Context) error {
_, err := _c.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_c *FileCreateBulk) ExecX(ctx context.Context) {
if err := _c.Exec(ctx); err != nil {
panic(err)
}
}
// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
// of the `INSERT` statement. For example:
//
// client.File.CreateBulk(builders...).
// OnConflict(
// // Update the row with the new values
// // the was proposed for insertion.
// sql.ResolveWithNewValues(),
// ).
// // Override some of the fields with custom
// // update values.
// Update(func(u *ent.FileUpsert) {
// SetSetID(v+v).
// }).
// Exec(ctx)
func (_c *FileCreateBulk) OnConflict(opts ...sql.ConflictOption) *FileUpsertBulk {
_c.conflict = opts
return &FileUpsertBulk{
create: _c,
}
}
// OnConflictColumns calls `OnConflict` and configures the columns
// as conflict target. Using this option is equivalent to using:
//
// client.File.Create().
// OnConflict(sql.ConflictColumns(columns...)).
// Exec(ctx)
func (_c *FileCreateBulk) OnConflictColumns(columns ...string) *FileUpsertBulk {
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
return &FileUpsertBulk{
create: _c,
}
}
// FileUpsertBulk is the builder for "upsert"-ing
// a bulk of File nodes.
type FileUpsertBulk struct {
create *FileCreateBulk
}
// UpdateNewValues updates the mutable fields using the new values that
// were set on create. Using this option is equivalent to using:
//
// client.File.Create().
// OnConflict(
// sql.ResolveWithNewValues(),
// ).
// Exec(ctx)
func (u *FileUpsertBulk) UpdateNewValues() *FileUpsertBulk {
u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
return u
}
// Ignore sets each column to itself in case of conflict.
// Using this option is equivalent to using:
//
// client.File.Create().
// OnConflict(sql.ResolveWithIgnore()).
// Exec(ctx)
func (u *FileUpsertBulk) Ignore() *FileUpsertBulk {
u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
return u
}
// DoNothing configures the conflict_action to `DO NOTHING`.
// Supported only by SQLite and PostgreSQL.
func (u *FileUpsertBulk) DoNothing() *FileUpsertBulk {
u.create.conflict = append(u.create.conflict, sql.DoNothing())
return u
}
// Update allows overriding fields `UPDATE` values. See the FileCreateBulk.OnConflict
// documentation for more info.
func (u *FileUpsertBulk) Update(set func(*FileUpsert)) *FileUpsertBulk {
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
set(&FileUpsert{UpdateSet: update})
}))
return u
}
// SetSetID sets the "set_id" field.
func (u *FileUpsertBulk) SetSetID(v int) *FileUpsertBulk {
return u.Update(func(s *FileUpsert) {
s.SetSetID(v)
})
}
// AddSetID adds v to the "set_id" field.
func (u *FileUpsertBulk) AddSetID(v int) *FileUpsertBulk {
return u.Update(func(s *FileUpsert) {
s.AddSetID(v)
})
}
// UpdateSetID sets the "set_id" field to the value that was provided on create.
func (u *FileUpsertBulk) UpdateSetID() *FileUpsertBulk {
return u.Update(func(s *FileUpsert) {
s.UpdateSetID()
})
}
// ClearSetID clears the value of the "set_id" field.
func (u *FileUpsertBulk) ClearSetID() *FileUpsertBulk {
return u.Update(func(s *FileUpsert) {
s.ClearSetID()
})
}
// SetSize sets the "size" field.
func (u *FileUpsertBulk) SetSize(v int) *FileUpsertBulk {
return u.Update(func(s *FileUpsert) {
s.SetSize(v)
})
}
// AddSize adds v to the "size" field.
func (u *FileUpsertBulk) AddSize(v int) *FileUpsertBulk {
return u.Update(func(s *FileUpsert) {
s.AddSize(v)
})
}
// UpdateSize sets the "size" field to the value that was provided on create.
func (u *FileUpsertBulk) UpdateSize() *FileUpsertBulk {
return u.Update(func(s *FileUpsert) {
s.UpdateSize()
})
}
// SetName sets the "name" field.
func (u *FileUpsertBulk) SetName(v string) *FileUpsertBulk {
return u.Update(func(s *FileUpsert) {
s.SetName(v)
})
}
// UpdateName sets the "name" field to the value that was provided on create.
func (u *FileUpsertBulk) UpdateName() *FileUpsertBulk {
return u.Update(func(s *FileUpsert) {
s.UpdateName()
})
}
// SetUser sets the "user" field.
func (u *FileUpsertBulk) SetUser(v string) *FileUpsertBulk {
return u.Update(func(s *FileUpsert) {
s.SetUser(v)
})
}
// UpdateUser sets the "user" field to the value that was provided on create.
func (u *FileUpsertBulk) UpdateUser() *FileUpsertBulk {
return u.Update(func(s *FileUpsert) {
s.UpdateUser()
})
}
// ClearUser clears the value of the "user" field.
func (u *FileUpsertBulk) ClearUser() *FileUpsertBulk {
return u.Update(func(s *FileUpsert) {
s.ClearUser()
})
}
// SetGroup sets the "group" field.
func (u *FileUpsertBulk) SetGroup(v string) *FileUpsertBulk {
return u.Update(func(s *FileUpsert) {
s.SetGroup(v)
})
}
// UpdateGroup sets the "group" field to the value that was provided on create.
func (u *FileUpsertBulk) UpdateGroup() *FileUpsertBulk {
return u.Update(func(s *FileUpsert) {
s.UpdateGroup()
})
}
// ClearGroup clears the value of the "group" field.
func (u *FileUpsertBulk) ClearGroup() *FileUpsertBulk {
return u.Update(func(s *FileUpsert) {
s.ClearGroup()
})
}
// SetOp sets the "op" field.
func (u *FileUpsertBulk) SetOp(v bool) *FileUpsertBulk {
return u.Update(func(s *FileUpsert) {
s.SetOp(v)
})
}
// UpdateOp sets the "op" field to the value that was provided on create.
func (u *FileUpsertBulk) UpdateOp() *FileUpsertBulk {
return u.Update(func(s *FileUpsert) {
s.UpdateOp()
})
}
// ClearOp clears the value of the "op" field.
func (u *FileUpsertBulk) ClearOp() *FileUpsertBulk {
return u.Update(func(s *FileUpsert) {
s.ClearOp()
})
}
// SetFieldID sets the "field_id" field.
func (u *FileUpsertBulk) SetFieldID(v int) *FileUpsertBulk {
return u.Update(func(s *FileUpsert) {
s.SetFieldID(v)
})
}
// AddFieldID adds v to the "field_id" field.
func (u *FileUpsertBulk) AddFieldID(v int) *FileUpsertBulk {
return u.Update(func(s *FileUpsert) {
s.AddFieldID(v)
})
}
// UpdateFieldID sets the "field_id" field to the value that was provided on create.
func (u *FileUpsertBulk) UpdateFieldID() *FileUpsertBulk {
return u.Update(func(s *FileUpsert) {
s.UpdateFieldID()
})
}
// ClearFieldID clears the value of the "field_id" field.
func (u *FileUpsertBulk) ClearFieldID() *FileUpsertBulk {
return u.Update(func(s *FileUpsert) {
s.ClearFieldID()
})
}
// SetCreateTime sets the "create_time" field.
func (u *FileUpsertBulk) SetCreateTime(v time.Time) *FileUpsertBulk {
return u.Update(func(s *FileUpsert) {
s.SetCreateTime(v)
})
}
// UpdateCreateTime sets the "create_time" field to the value that was provided on create.
func (u *FileUpsertBulk) UpdateCreateTime() *FileUpsertBulk {
return u.Update(func(s *FileUpsert) {
s.UpdateCreateTime()
})
}
// ClearCreateTime clears the value of the "create_time" field.
func (u *FileUpsertBulk) ClearCreateTime() *FileUpsertBulk {
return u.Update(func(s *FileUpsert) {
s.ClearCreateTime()
})
}
// Exec executes the query.
func (u *FileUpsertBulk) Exec(ctx context.Context) error {
if u.create.err != nil {
return u.create.err
}
for i, b := range u.create.builders {
if len(b.conflict) != 0 {
return fmt.Errorf("ent: OnConflict was set for builder %d. Set it on the FileCreateBulk instead", i)
}
}
if len(u.create.conflict) == 0 {
return errors.New("ent: missing options for FileCreateBulk.OnConflict")
}
return u.create.Exec(ctx)
}
// ExecX is like Exec, but panics if an error occurs.
func (u *FileUpsertBulk) ExecX(ctx context.Context) {
if err := u.create.Exec(ctx); err != nil {
panic(err)
}
}