Cloudreve/ent/file_create.go

1432 lines
39 KiB
Go

// Code generated by ent, DO NOT EDIT.
package ent
import (
"context"
"errors"
"fmt"
"time"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"github.com/cloudreve/Cloudreve/v4/ent/directlink"
"github.com/cloudreve/Cloudreve/v4/ent/entity"
"github.com/cloudreve/Cloudreve/v4/ent/file"
"github.com/cloudreve/Cloudreve/v4/ent/metadata"
"github.com/cloudreve/Cloudreve/v4/ent/share"
"github.com/cloudreve/Cloudreve/v4/ent/storagepolicy"
"github.com/cloudreve/Cloudreve/v4/ent/user"
"github.com/cloudreve/Cloudreve/v4/inventory/types"
)
// FileCreate is the builder for creating a File entity.
type FileCreate struct {
config
mutation *FileMutation
hooks []Hook
conflict []sql.ConflictOption
}
// SetCreatedAt sets the "created_at" field.
func (fc *FileCreate) SetCreatedAt(t time.Time) *FileCreate {
fc.mutation.SetCreatedAt(t)
return fc
}
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
func (fc *FileCreate) SetNillableCreatedAt(t *time.Time) *FileCreate {
if t != nil {
fc.SetCreatedAt(*t)
}
return fc
}
// SetUpdatedAt sets the "updated_at" field.
func (fc *FileCreate) SetUpdatedAt(t time.Time) *FileCreate {
fc.mutation.SetUpdatedAt(t)
return fc
}
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
func (fc *FileCreate) SetNillableUpdatedAt(t *time.Time) *FileCreate {
if t != nil {
fc.SetUpdatedAt(*t)
}
return fc
}
// SetType sets the "type" field.
func (fc *FileCreate) SetType(i int) *FileCreate {
fc.mutation.SetType(i)
return fc
}
// SetName sets the "name" field.
func (fc *FileCreate) SetName(s string) *FileCreate {
fc.mutation.SetName(s)
return fc
}
// SetOwnerID sets the "owner_id" field.
func (fc *FileCreate) SetOwnerID(i int) *FileCreate {
fc.mutation.SetOwnerID(i)
return fc
}
// SetSize sets the "size" field.
func (fc *FileCreate) SetSize(i int64) *FileCreate {
fc.mutation.SetSize(i)
return fc
}
// SetNillableSize sets the "size" field if the given value is not nil.
func (fc *FileCreate) SetNillableSize(i *int64) *FileCreate {
if i != nil {
fc.SetSize(*i)
}
return fc
}
// SetPrimaryEntity sets the "primary_entity" field.
func (fc *FileCreate) SetPrimaryEntity(i int) *FileCreate {
fc.mutation.SetPrimaryEntity(i)
return fc
}
// SetNillablePrimaryEntity sets the "primary_entity" field if the given value is not nil.
func (fc *FileCreate) SetNillablePrimaryEntity(i *int) *FileCreate {
if i != nil {
fc.SetPrimaryEntity(*i)
}
return fc
}
// SetFileChildren sets the "file_children" field.
func (fc *FileCreate) SetFileChildren(i int) *FileCreate {
fc.mutation.SetFileChildren(i)
return fc
}
// SetNillableFileChildren sets the "file_children" field if the given value is not nil.
func (fc *FileCreate) SetNillableFileChildren(i *int) *FileCreate {
if i != nil {
fc.SetFileChildren(*i)
}
return fc
}
// SetIsSymbolic sets the "is_symbolic" field.
func (fc *FileCreate) SetIsSymbolic(b bool) *FileCreate {
fc.mutation.SetIsSymbolic(b)
return fc
}
// SetNillableIsSymbolic sets the "is_symbolic" field if the given value is not nil.
func (fc *FileCreate) SetNillableIsSymbolic(b *bool) *FileCreate {
if b != nil {
fc.SetIsSymbolic(*b)
}
return fc
}
// SetProps sets the "props" field.
func (fc *FileCreate) SetProps(tp *types.FileProps) *FileCreate {
fc.mutation.SetProps(tp)
return fc
}
// SetStoragePolicyFiles sets the "storage_policy_files" field.
func (fc *FileCreate) SetStoragePolicyFiles(i int) *FileCreate {
fc.mutation.SetStoragePolicyFiles(i)
return fc
}
// SetNillableStoragePolicyFiles sets the "storage_policy_files" field if the given value is not nil.
func (fc *FileCreate) SetNillableStoragePolicyFiles(i *int) *FileCreate {
if i != nil {
fc.SetStoragePolicyFiles(*i)
}
return fc
}
// SetOwner sets the "owner" edge to the User entity.
func (fc *FileCreate) SetOwner(u *User) *FileCreate {
return fc.SetOwnerID(u.ID)
}
// SetStoragePoliciesID sets the "storage_policies" edge to the StoragePolicy entity by ID.
func (fc *FileCreate) SetStoragePoliciesID(id int) *FileCreate {
fc.mutation.SetStoragePoliciesID(id)
return fc
}
// SetNillableStoragePoliciesID sets the "storage_policies" edge to the StoragePolicy entity by ID if the given value is not nil.
func (fc *FileCreate) SetNillableStoragePoliciesID(id *int) *FileCreate {
if id != nil {
fc = fc.SetStoragePoliciesID(*id)
}
return fc
}
// SetStoragePolicies sets the "storage_policies" edge to the StoragePolicy entity.
func (fc *FileCreate) SetStoragePolicies(s *StoragePolicy) *FileCreate {
return fc.SetStoragePoliciesID(s.ID)
}
// SetParentID sets the "parent" edge to the File entity by ID.
func (fc *FileCreate) SetParentID(id int) *FileCreate {
fc.mutation.SetParentID(id)
return fc
}
// SetNillableParentID sets the "parent" edge to the File entity by ID if the given value is not nil.
func (fc *FileCreate) SetNillableParentID(id *int) *FileCreate {
if id != nil {
fc = fc.SetParentID(*id)
}
return fc
}
// SetParent sets the "parent" edge to the File entity.
func (fc *FileCreate) SetParent(f *File) *FileCreate {
return fc.SetParentID(f.ID)
}
// AddChildIDs adds the "children" edge to the File entity by IDs.
func (fc *FileCreate) AddChildIDs(ids ...int) *FileCreate {
fc.mutation.AddChildIDs(ids...)
return fc
}
// AddChildren adds the "children" edges to the File entity.
func (fc *FileCreate) AddChildren(f ...*File) *FileCreate {
ids := make([]int, len(f))
for i := range f {
ids[i] = f[i].ID
}
return fc.AddChildIDs(ids...)
}
// AddMetadatumIDs adds the "metadata" edge to the Metadata entity by IDs.
func (fc *FileCreate) AddMetadatumIDs(ids ...int) *FileCreate {
fc.mutation.AddMetadatumIDs(ids...)
return fc
}
// AddMetadata adds the "metadata" edges to the Metadata entity.
func (fc *FileCreate) AddMetadata(m ...*Metadata) *FileCreate {
ids := make([]int, len(m))
for i := range m {
ids[i] = m[i].ID
}
return fc.AddMetadatumIDs(ids...)
}
// AddEntityIDs adds the "entities" edge to the Entity entity by IDs.
func (fc *FileCreate) AddEntityIDs(ids ...int) *FileCreate {
fc.mutation.AddEntityIDs(ids...)
return fc
}
// AddEntities adds the "entities" edges to the Entity entity.
func (fc *FileCreate) AddEntities(e ...*Entity) *FileCreate {
ids := make([]int, len(e))
for i := range e {
ids[i] = e[i].ID
}
return fc.AddEntityIDs(ids...)
}
// AddShareIDs adds the "shares" edge to the Share entity by IDs.
func (fc *FileCreate) AddShareIDs(ids ...int) *FileCreate {
fc.mutation.AddShareIDs(ids...)
return fc
}
// AddShares adds the "shares" edges to the Share entity.
func (fc *FileCreate) AddShares(s ...*Share) *FileCreate {
ids := make([]int, len(s))
for i := range s {
ids[i] = s[i].ID
}
return fc.AddShareIDs(ids...)
}
// AddDirectLinkIDs adds the "direct_links" edge to the DirectLink entity by IDs.
func (fc *FileCreate) AddDirectLinkIDs(ids ...int) *FileCreate {
fc.mutation.AddDirectLinkIDs(ids...)
return fc
}
// AddDirectLinks adds the "direct_links" edges to the DirectLink entity.
func (fc *FileCreate) AddDirectLinks(d ...*DirectLink) *FileCreate {
ids := make([]int, len(d))
for i := range d {
ids[i] = d[i].ID
}
return fc.AddDirectLinkIDs(ids...)
}
// Mutation returns the FileMutation object of the builder.
func (fc *FileCreate) Mutation() *FileMutation {
return fc.mutation
}
// Save creates the File in the database.
func (fc *FileCreate) Save(ctx context.Context) (*File, error) {
if err := fc.defaults(); err != nil {
return nil, err
}
return withHooks(ctx, fc.sqlSave, fc.mutation, fc.hooks)
}
// SaveX calls Save and panics if Save returns an error.
func (fc *FileCreate) SaveX(ctx context.Context) *File {
v, err := fc.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (fc *FileCreate) Exec(ctx context.Context) error {
_, err := fc.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (fc *FileCreate) ExecX(ctx context.Context) {
if err := fc.Exec(ctx); err != nil {
panic(err)
}
}
// defaults sets the default values of the builder before save.
func (fc *FileCreate) defaults() error {
if _, ok := fc.mutation.CreatedAt(); !ok {
if file.DefaultCreatedAt == nil {
return fmt.Errorf("ent: uninitialized file.DefaultCreatedAt (forgotten import ent/runtime?)")
}
v := file.DefaultCreatedAt()
fc.mutation.SetCreatedAt(v)
}
if _, ok := fc.mutation.UpdatedAt(); !ok {
if file.DefaultUpdatedAt == nil {
return fmt.Errorf("ent: uninitialized file.DefaultUpdatedAt (forgotten import ent/runtime?)")
}
v := file.DefaultUpdatedAt()
fc.mutation.SetUpdatedAt(v)
}
if _, ok := fc.mutation.Size(); !ok {
v := file.DefaultSize
fc.mutation.SetSize(v)
}
if _, ok := fc.mutation.IsSymbolic(); !ok {
v := file.DefaultIsSymbolic
fc.mutation.SetIsSymbolic(v)
}
return nil
}
// check runs all checks and user-defined validators on the builder.
func (fc *FileCreate) check() error {
if _, ok := fc.mutation.CreatedAt(); !ok {
return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "File.created_at"`)}
}
if _, ok := fc.mutation.UpdatedAt(); !ok {
return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "File.updated_at"`)}
}
if _, ok := fc.mutation.GetType(); !ok {
return &ValidationError{Name: "type", err: errors.New(`ent: missing required field "File.type"`)}
}
if _, ok := fc.mutation.Name(); !ok {
return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "File.name"`)}
}
if _, ok := fc.mutation.OwnerID(); !ok {
return &ValidationError{Name: "owner_id", err: errors.New(`ent: missing required field "File.owner_id"`)}
}
if _, ok := fc.mutation.Size(); !ok {
return &ValidationError{Name: "size", err: errors.New(`ent: missing required field "File.size"`)}
}
if _, ok := fc.mutation.IsSymbolic(); !ok {
return &ValidationError{Name: "is_symbolic", err: errors.New(`ent: missing required field "File.is_symbolic"`)}
}
if _, ok := fc.mutation.OwnerID(); !ok {
return &ValidationError{Name: "owner", err: errors.New(`ent: missing required edge "File.owner"`)}
}
return nil
}
func (fc *FileCreate) sqlSave(ctx context.Context) (*File, error) {
if err := fc.check(); err != nil {
return nil, err
}
_node, _spec := fc.createSpec()
if err := sqlgraph.CreateNode(ctx, fc.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)
fc.mutation.id = &_node.ID
fc.mutation.done = true
return _node, nil
}
func (fc *FileCreate) createSpec() (*File, *sqlgraph.CreateSpec) {
var (
_node = &File{config: fc.config}
_spec = sqlgraph.NewCreateSpec(file.Table, sqlgraph.NewFieldSpec(file.FieldID, field.TypeInt))
)
if id, ok := fc.mutation.ID(); ok {
_node.ID = id
id64 := int64(id)
_spec.ID.Value = id64
}
_spec.OnConflict = fc.conflict
if value, ok := fc.mutation.CreatedAt(); ok {
_spec.SetField(file.FieldCreatedAt, field.TypeTime, value)
_node.CreatedAt = value
}
if value, ok := fc.mutation.UpdatedAt(); ok {
_spec.SetField(file.FieldUpdatedAt, field.TypeTime, value)
_node.UpdatedAt = value
}
if value, ok := fc.mutation.GetType(); ok {
_spec.SetField(file.FieldType, field.TypeInt, value)
_node.Type = value
}
if value, ok := fc.mutation.Name(); ok {
_spec.SetField(file.FieldName, field.TypeString, value)
_node.Name = value
}
if value, ok := fc.mutation.Size(); ok {
_spec.SetField(file.FieldSize, field.TypeInt64, value)
_node.Size = value
}
if value, ok := fc.mutation.PrimaryEntity(); ok {
_spec.SetField(file.FieldPrimaryEntity, field.TypeInt, value)
_node.PrimaryEntity = value
}
if value, ok := fc.mutation.IsSymbolic(); ok {
_spec.SetField(file.FieldIsSymbolic, field.TypeBool, value)
_node.IsSymbolic = value
}
if value, ok := fc.mutation.Props(); ok {
_spec.SetField(file.FieldProps, field.TypeJSON, value)
_node.Props = value
}
if nodes := fc.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.OwnerID = nodes[0]
_spec.Edges = append(_spec.Edges, edge)
}
if nodes := fc.mutation.StoragePoliciesIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: file.StoragePoliciesTable,
Columns: []string{file.StoragePoliciesColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(storagepolicy.FieldID, field.TypeInt),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_node.StoragePolicyFiles = nodes[0]
_spec.Edges = append(_spec.Edges, edge)
}
if nodes := fc.mutation.ParentIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: file.ParentTable,
Columns: []string{file.ParentColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(file.FieldID, field.TypeInt),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_node.FileChildren = nodes[0]
_spec.Edges = append(_spec.Edges, edge)
}
if nodes := fc.mutation.ChildrenIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: file.ChildrenTable,
Columns: []string{file.ChildrenColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(file.FieldID, field.TypeInt),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges = append(_spec.Edges, edge)
}
if nodes := fc.mutation.MetadataIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: file.MetadataTable,
Columns: []string{file.MetadataColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(metadata.FieldID, field.TypeInt),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges = append(_spec.Edges, edge)
}
if nodes := fc.mutation.EntitiesIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2M,
Inverse: false,
Table: file.EntitiesTable,
Columns: file.EntitiesPrimaryKey,
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(entity.FieldID, field.TypeInt),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges = append(_spec.Edges, edge)
}
if nodes := fc.mutation.SharesIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: file.SharesTable,
Columns: []string{file.SharesColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(share.FieldID, field.TypeInt),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges = append(_spec.Edges, edge)
}
if nodes := fc.mutation.DirectLinksIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: file.DirectLinksTable,
Columns: []string{file.DirectLinksColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(directlink.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().
// SetCreatedAt(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) {
// SetCreatedAt(v+v).
// }).
// Exec(ctx)
func (fc *FileCreate) OnConflict(opts ...sql.ConflictOption) *FileUpsertOne {
fc.conflict = opts
return &FileUpsertOne{
create: fc,
}
}
// 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 (fc *FileCreate) OnConflictColumns(columns ...string) *FileUpsertOne {
fc.conflict = append(fc.conflict, sql.ConflictColumns(columns...))
return &FileUpsertOne{
create: fc,
}
}
type (
// FileUpsertOne is the builder for "upsert"-ing
// one File node.
FileUpsertOne struct {
create *FileCreate
}
// FileUpsert is the "OnConflict" setter.
FileUpsert struct {
*sql.UpdateSet
}
)
// SetUpdatedAt sets the "updated_at" field.
func (u *FileUpsert) SetUpdatedAt(v time.Time) *FileUpsert {
u.Set(file.FieldUpdatedAt, v)
return u
}
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
func (u *FileUpsert) UpdateUpdatedAt() *FileUpsert {
u.SetExcluded(file.FieldUpdatedAt)
return u
}
// SetType sets the "type" field.
func (u *FileUpsert) SetType(v int) *FileUpsert {
u.Set(file.FieldType, v)
return u
}
// UpdateType sets the "type" field to the value that was provided on create.
func (u *FileUpsert) UpdateType() *FileUpsert {
u.SetExcluded(file.FieldType)
return u
}
// AddType adds v to the "type" field.
func (u *FileUpsert) AddType(v int) *FileUpsert {
u.Add(file.FieldType, 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
}
// SetOwnerID sets the "owner_id" field.
func (u *FileUpsert) SetOwnerID(v int) *FileUpsert {
u.Set(file.FieldOwnerID, v)
return u
}
// UpdateOwnerID sets the "owner_id" field to the value that was provided on create.
func (u *FileUpsert) UpdateOwnerID() *FileUpsert {
u.SetExcluded(file.FieldOwnerID)
return u
}
// SetSize sets the "size" field.
func (u *FileUpsert) SetSize(v int64) *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 int64) *FileUpsert {
u.Add(file.FieldSize, v)
return u
}
// SetPrimaryEntity sets the "primary_entity" field.
func (u *FileUpsert) SetPrimaryEntity(v int) *FileUpsert {
u.Set(file.FieldPrimaryEntity, v)
return u
}
// UpdatePrimaryEntity sets the "primary_entity" field to the value that was provided on create.
func (u *FileUpsert) UpdatePrimaryEntity() *FileUpsert {
u.SetExcluded(file.FieldPrimaryEntity)
return u
}
// AddPrimaryEntity adds v to the "primary_entity" field.
func (u *FileUpsert) AddPrimaryEntity(v int) *FileUpsert {
u.Add(file.FieldPrimaryEntity, v)
return u
}
// ClearPrimaryEntity clears the value of the "primary_entity" field.
func (u *FileUpsert) ClearPrimaryEntity() *FileUpsert {
u.SetNull(file.FieldPrimaryEntity)
return u
}
// SetFileChildren sets the "file_children" field.
func (u *FileUpsert) SetFileChildren(v int) *FileUpsert {
u.Set(file.FieldFileChildren, v)
return u
}
// UpdateFileChildren sets the "file_children" field to the value that was provided on create.
func (u *FileUpsert) UpdateFileChildren() *FileUpsert {
u.SetExcluded(file.FieldFileChildren)
return u
}
// ClearFileChildren clears the value of the "file_children" field.
func (u *FileUpsert) ClearFileChildren() *FileUpsert {
u.SetNull(file.FieldFileChildren)
return u
}
// SetIsSymbolic sets the "is_symbolic" field.
func (u *FileUpsert) SetIsSymbolic(v bool) *FileUpsert {
u.Set(file.FieldIsSymbolic, v)
return u
}
// UpdateIsSymbolic sets the "is_symbolic" field to the value that was provided on create.
func (u *FileUpsert) UpdateIsSymbolic() *FileUpsert {
u.SetExcluded(file.FieldIsSymbolic)
return u
}
// SetProps sets the "props" field.
func (u *FileUpsert) SetProps(v *types.FileProps) *FileUpsert {
u.Set(file.FieldProps, v)
return u
}
// UpdateProps sets the "props" field to the value that was provided on create.
func (u *FileUpsert) UpdateProps() *FileUpsert {
u.SetExcluded(file.FieldProps)
return u
}
// ClearProps clears the value of the "props" field.
func (u *FileUpsert) ClearProps() *FileUpsert {
u.SetNull(file.FieldProps)
return u
}
// SetStoragePolicyFiles sets the "storage_policy_files" field.
func (u *FileUpsert) SetStoragePolicyFiles(v int) *FileUpsert {
u.Set(file.FieldStoragePolicyFiles, v)
return u
}
// UpdateStoragePolicyFiles sets the "storage_policy_files" field to the value that was provided on create.
func (u *FileUpsert) UpdateStoragePolicyFiles() *FileUpsert {
u.SetExcluded(file.FieldStoragePolicyFiles)
return u
}
// ClearStoragePolicyFiles clears the value of the "storage_policy_files" field.
func (u *FileUpsert) ClearStoragePolicyFiles() *FileUpsert {
u.SetNull(file.FieldStoragePolicyFiles)
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())
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
if _, exists := u.create.mutation.CreatedAt(); exists {
s.SetIgnore(file.FieldCreatedAt)
}
}))
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
}
// SetUpdatedAt sets the "updated_at" field.
func (u *FileUpsertOne) SetUpdatedAt(v time.Time) *FileUpsertOne {
return u.Update(func(s *FileUpsert) {
s.SetUpdatedAt(v)
})
}
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
func (u *FileUpsertOne) UpdateUpdatedAt() *FileUpsertOne {
return u.Update(func(s *FileUpsert) {
s.UpdateUpdatedAt()
})
}
// SetType sets the "type" field.
func (u *FileUpsertOne) SetType(v int) *FileUpsertOne {
return u.Update(func(s *FileUpsert) {
s.SetType(v)
})
}
// AddType adds v to the "type" field.
func (u *FileUpsertOne) AddType(v int) *FileUpsertOne {
return u.Update(func(s *FileUpsert) {
s.AddType(v)
})
}
// UpdateType sets the "type" field to the value that was provided on create.
func (u *FileUpsertOne) UpdateType() *FileUpsertOne {
return u.Update(func(s *FileUpsert) {
s.UpdateType()
})
}
// 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()
})
}
// SetOwnerID sets the "owner_id" field.
func (u *FileUpsertOne) SetOwnerID(v int) *FileUpsertOne {
return u.Update(func(s *FileUpsert) {
s.SetOwnerID(v)
})
}
// UpdateOwnerID sets the "owner_id" field to the value that was provided on create.
func (u *FileUpsertOne) UpdateOwnerID() *FileUpsertOne {
return u.Update(func(s *FileUpsert) {
s.UpdateOwnerID()
})
}
// SetSize sets the "size" field.
func (u *FileUpsertOne) SetSize(v int64) *FileUpsertOne {
return u.Update(func(s *FileUpsert) {
s.SetSize(v)
})
}
// AddSize adds v to the "size" field.
func (u *FileUpsertOne) AddSize(v int64) *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()
})
}
// SetPrimaryEntity sets the "primary_entity" field.
func (u *FileUpsertOne) SetPrimaryEntity(v int) *FileUpsertOne {
return u.Update(func(s *FileUpsert) {
s.SetPrimaryEntity(v)
})
}
// AddPrimaryEntity adds v to the "primary_entity" field.
func (u *FileUpsertOne) AddPrimaryEntity(v int) *FileUpsertOne {
return u.Update(func(s *FileUpsert) {
s.AddPrimaryEntity(v)
})
}
// UpdatePrimaryEntity sets the "primary_entity" field to the value that was provided on create.
func (u *FileUpsertOne) UpdatePrimaryEntity() *FileUpsertOne {
return u.Update(func(s *FileUpsert) {
s.UpdatePrimaryEntity()
})
}
// ClearPrimaryEntity clears the value of the "primary_entity" field.
func (u *FileUpsertOne) ClearPrimaryEntity() *FileUpsertOne {
return u.Update(func(s *FileUpsert) {
s.ClearPrimaryEntity()
})
}
// SetFileChildren sets the "file_children" field.
func (u *FileUpsertOne) SetFileChildren(v int) *FileUpsertOne {
return u.Update(func(s *FileUpsert) {
s.SetFileChildren(v)
})
}
// UpdateFileChildren sets the "file_children" field to the value that was provided on create.
func (u *FileUpsertOne) UpdateFileChildren() *FileUpsertOne {
return u.Update(func(s *FileUpsert) {
s.UpdateFileChildren()
})
}
// ClearFileChildren clears the value of the "file_children" field.
func (u *FileUpsertOne) ClearFileChildren() *FileUpsertOne {
return u.Update(func(s *FileUpsert) {
s.ClearFileChildren()
})
}
// SetIsSymbolic sets the "is_symbolic" field.
func (u *FileUpsertOne) SetIsSymbolic(v bool) *FileUpsertOne {
return u.Update(func(s *FileUpsert) {
s.SetIsSymbolic(v)
})
}
// UpdateIsSymbolic sets the "is_symbolic" field to the value that was provided on create.
func (u *FileUpsertOne) UpdateIsSymbolic() *FileUpsertOne {
return u.Update(func(s *FileUpsert) {
s.UpdateIsSymbolic()
})
}
// SetProps sets the "props" field.
func (u *FileUpsertOne) SetProps(v *types.FileProps) *FileUpsertOne {
return u.Update(func(s *FileUpsert) {
s.SetProps(v)
})
}
// UpdateProps sets the "props" field to the value that was provided on create.
func (u *FileUpsertOne) UpdateProps() *FileUpsertOne {
return u.Update(func(s *FileUpsert) {
s.UpdateProps()
})
}
// ClearProps clears the value of the "props" field.
func (u *FileUpsertOne) ClearProps() *FileUpsertOne {
return u.Update(func(s *FileUpsert) {
s.ClearProps()
})
}
// SetStoragePolicyFiles sets the "storage_policy_files" field.
func (u *FileUpsertOne) SetStoragePolicyFiles(v int) *FileUpsertOne {
return u.Update(func(s *FileUpsert) {
s.SetStoragePolicyFiles(v)
})
}
// UpdateStoragePolicyFiles sets the "storage_policy_files" field to the value that was provided on create.
func (u *FileUpsertOne) UpdateStoragePolicyFiles() *FileUpsertOne {
return u.Update(func(s *FileUpsert) {
s.UpdateStoragePolicyFiles()
})
}
// ClearStoragePolicyFiles clears the value of the "storage_policy_files" field.
func (u *FileUpsertOne) ClearStoragePolicyFiles() *FileUpsertOne {
return u.Update(func(s *FileUpsert) {
s.ClearStoragePolicyFiles()
})
}
// 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
}
func (m *FileCreate) SetRawID(t int) *FileCreate {
m.mutation.SetRawID(t)
return m
}
// 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 (fcb *FileCreateBulk) Save(ctx context.Context) ([]*File, error) {
if fcb.err != nil {
return nil, fcb.err
}
specs := make([]*sqlgraph.CreateSpec, len(fcb.builders))
nodes := make([]*File, len(fcb.builders))
mutators := make([]Mutator, len(fcb.builders))
for i := range fcb.builders {
func(i int, root context.Context) {
builder := fcb.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, fcb.builders[i+1].mutation)
} else {
spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
spec.OnConflict = fcb.conflict
// Invoke the actual operation on the latest mutation in the chain.
if err = sqlgraph.BatchCreate(ctx, fcb.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, fcb.builders[0].mutation); err != nil {
return nil, err
}
}
return nodes, nil
}
// SaveX is like Save, but panics if an error occurs.
func (fcb *FileCreateBulk) SaveX(ctx context.Context) []*File {
v, err := fcb.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (fcb *FileCreateBulk) Exec(ctx context.Context) error {
_, err := fcb.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (fcb *FileCreateBulk) ExecX(ctx context.Context) {
if err := fcb.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) {
// SetCreatedAt(v+v).
// }).
// Exec(ctx)
func (fcb *FileCreateBulk) OnConflict(opts ...sql.ConflictOption) *FileUpsertBulk {
fcb.conflict = opts
return &FileUpsertBulk{
create: fcb,
}
}
// 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 (fcb *FileCreateBulk) OnConflictColumns(columns ...string) *FileUpsertBulk {
fcb.conflict = append(fcb.conflict, sql.ConflictColumns(columns...))
return &FileUpsertBulk{
create: fcb,
}
}
// 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())
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
for _, b := range u.create.builders {
if _, exists := b.mutation.CreatedAt(); exists {
s.SetIgnore(file.FieldCreatedAt)
}
}
}))
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
}
// SetUpdatedAt sets the "updated_at" field.
func (u *FileUpsertBulk) SetUpdatedAt(v time.Time) *FileUpsertBulk {
return u.Update(func(s *FileUpsert) {
s.SetUpdatedAt(v)
})
}
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
func (u *FileUpsertBulk) UpdateUpdatedAt() *FileUpsertBulk {
return u.Update(func(s *FileUpsert) {
s.UpdateUpdatedAt()
})
}
// SetType sets the "type" field.
func (u *FileUpsertBulk) SetType(v int) *FileUpsertBulk {
return u.Update(func(s *FileUpsert) {
s.SetType(v)
})
}
// AddType adds v to the "type" field.
func (u *FileUpsertBulk) AddType(v int) *FileUpsertBulk {
return u.Update(func(s *FileUpsert) {
s.AddType(v)
})
}
// UpdateType sets the "type" field to the value that was provided on create.
func (u *FileUpsertBulk) UpdateType() *FileUpsertBulk {
return u.Update(func(s *FileUpsert) {
s.UpdateType()
})
}
// 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()
})
}
// SetOwnerID sets the "owner_id" field.
func (u *FileUpsertBulk) SetOwnerID(v int) *FileUpsertBulk {
return u.Update(func(s *FileUpsert) {
s.SetOwnerID(v)
})
}
// UpdateOwnerID sets the "owner_id" field to the value that was provided on create.
func (u *FileUpsertBulk) UpdateOwnerID() *FileUpsertBulk {
return u.Update(func(s *FileUpsert) {
s.UpdateOwnerID()
})
}
// SetSize sets the "size" field.
func (u *FileUpsertBulk) SetSize(v int64) *FileUpsertBulk {
return u.Update(func(s *FileUpsert) {
s.SetSize(v)
})
}
// AddSize adds v to the "size" field.
func (u *FileUpsertBulk) AddSize(v int64) *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()
})
}
// SetPrimaryEntity sets the "primary_entity" field.
func (u *FileUpsertBulk) SetPrimaryEntity(v int) *FileUpsertBulk {
return u.Update(func(s *FileUpsert) {
s.SetPrimaryEntity(v)
})
}
// AddPrimaryEntity adds v to the "primary_entity" field.
func (u *FileUpsertBulk) AddPrimaryEntity(v int) *FileUpsertBulk {
return u.Update(func(s *FileUpsert) {
s.AddPrimaryEntity(v)
})
}
// UpdatePrimaryEntity sets the "primary_entity" field to the value that was provided on create.
func (u *FileUpsertBulk) UpdatePrimaryEntity() *FileUpsertBulk {
return u.Update(func(s *FileUpsert) {
s.UpdatePrimaryEntity()
})
}
// ClearPrimaryEntity clears the value of the "primary_entity" field.
func (u *FileUpsertBulk) ClearPrimaryEntity() *FileUpsertBulk {
return u.Update(func(s *FileUpsert) {
s.ClearPrimaryEntity()
})
}
// SetFileChildren sets the "file_children" field.
func (u *FileUpsertBulk) SetFileChildren(v int) *FileUpsertBulk {
return u.Update(func(s *FileUpsert) {
s.SetFileChildren(v)
})
}
// UpdateFileChildren sets the "file_children" field to the value that was provided on create.
func (u *FileUpsertBulk) UpdateFileChildren() *FileUpsertBulk {
return u.Update(func(s *FileUpsert) {
s.UpdateFileChildren()
})
}
// ClearFileChildren clears the value of the "file_children" field.
func (u *FileUpsertBulk) ClearFileChildren() *FileUpsertBulk {
return u.Update(func(s *FileUpsert) {
s.ClearFileChildren()
})
}
// SetIsSymbolic sets the "is_symbolic" field.
func (u *FileUpsertBulk) SetIsSymbolic(v bool) *FileUpsertBulk {
return u.Update(func(s *FileUpsert) {
s.SetIsSymbolic(v)
})
}
// UpdateIsSymbolic sets the "is_symbolic" field to the value that was provided on create.
func (u *FileUpsertBulk) UpdateIsSymbolic() *FileUpsertBulk {
return u.Update(func(s *FileUpsert) {
s.UpdateIsSymbolic()
})
}
// SetProps sets the "props" field.
func (u *FileUpsertBulk) SetProps(v *types.FileProps) *FileUpsertBulk {
return u.Update(func(s *FileUpsert) {
s.SetProps(v)
})
}
// UpdateProps sets the "props" field to the value that was provided on create.
func (u *FileUpsertBulk) UpdateProps() *FileUpsertBulk {
return u.Update(func(s *FileUpsert) {
s.UpdateProps()
})
}
// ClearProps clears the value of the "props" field.
func (u *FileUpsertBulk) ClearProps() *FileUpsertBulk {
return u.Update(func(s *FileUpsert) {
s.ClearProps()
})
}
// SetStoragePolicyFiles sets the "storage_policy_files" field.
func (u *FileUpsertBulk) SetStoragePolicyFiles(v int) *FileUpsertBulk {
return u.Update(func(s *FileUpsert) {
s.SetStoragePolicyFiles(v)
})
}
// UpdateStoragePolicyFiles sets the "storage_policy_files" field to the value that was provided on create.
func (u *FileUpsertBulk) UpdateStoragePolicyFiles() *FileUpsertBulk {
return u.Update(func(s *FileUpsert) {
s.UpdateStoragePolicyFiles()
})
}
// ClearStoragePolicyFiles clears the value of the "storage_policy_files" field.
func (u *FileUpsertBulk) ClearStoragePolicyFiles() *FileUpsertBulk {
return u.Update(func(s *FileUpsert) {
s.ClearStoragePolicyFiles()
})
}
// 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)
}
}