mirror of
https://github.com/hanzoui/registry-backend.git
synced 2026-10-30 20:30:45 +00:00
888 lines
27 KiB
Go
888 lines
27 KiB
Go
// Code generated by ent, DO NOT EDIT.
|
|
|
|
package ent
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"registry-backend/ent/storagefile"
|
|
"time"
|
|
|
|
"entgo.io/ent/dialect"
|
|
"entgo.io/ent/dialect/sql"
|
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
|
"entgo.io/ent/schema/field"
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
// StorageFileCreate is the builder for creating a StorageFile entity.
|
|
type StorageFileCreate struct {
|
|
config
|
|
mutation *StorageFileMutation
|
|
hooks []Hook
|
|
conflict []sql.ConflictOption
|
|
}
|
|
|
|
// SetCreateTime sets the "create_time" field.
|
|
func (sfc *StorageFileCreate) SetCreateTime(t time.Time) *StorageFileCreate {
|
|
sfc.mutation.SetCreateTime(t)
|
|
return sfc
|
|
}
|
|
|
|
// SetNillableCreateTime sets the "create_time" field if the given value is not nil.
|
|
func (sfc *StorageFileCreate) SetNillableCreateTime(t *time.Time) *StorageFileCreate {
|
|
if t != nil {
|
|
sfc.SetCreateTime(*t)
|
|
}
|
|
return sfc
|
|
}
|
|
|
|
// SetUpdateTime sets the "update_time" field.
|
|
func (sfc *StorageFileCreate) SetUpdateTime(t time.Time) *StorageFileCreate {
|
|
sfc.mutation.SetUpdateTime(t)
|
|
return sfc
|
|
}
|
|
|
|
// SetNillableUpdateTime sets the "update_time" field if the given value is not nil.
|
|
func (sfc *StorageFileCreate) SetNillableUpdateTime(t *time.Time) *StorageFileCreate {
|
|
if t != nil {
|
|
sfc.SetUpdateTime(*t)
|
|
}
|
|
return sfc
|
|
}
|
|
|
|
// SetBucketName sets the "bucket_name" field.
|
|
func (sfc *StorageFileCreate) SetBucketName(s string) *StorageFileCreate {
|
|
sfc.mutation.SetBucketName(s)
|
|
return sfc
|
|
}
|
|
|
|
// SetObjectName sets the "object_name" field.
|
|
func (sfc *StorageFileCreate) SetObjectName(s string) *StorageFileCreate {
|
|
sfc.mutation.SetObjectName(s)
|
|
return sfc
|
|
}
|
|
|
|
// SetNillableObjectName sets the "object_name" field if the given value is not nil.
|
|
func (sfc *StorageFileCreate) SetNillableObjectName(s *string) *StorageFileCreate {
|
|
if s != nil {
|
|
sfc.SetObjectName(*s)
|
|
}
|
|
return sfc
|
|
}
|
|
|
|
// SetFilePath sets the "file_path" field.
|
|
func (sfc *StorageFileCreate) SetFilePath(s string) *StorageFileCreate {
|
|
sfc.mutation.SetFilePath(s)
|
|
return sfc
|
|
}
|
|
|
|
// SetFileType sets the "file_type" field.
|
|
func (sfc *StorageFileCreate) SetFileType(s string) *StorageFileCreate {
|
|
sfc.mutation.SetFileType(s)
|
|
return sfc
|
|
}
|
|
|
|
// SetFileURL sets the "file_url" field.
|
|
func (sfc *StorageFileCreate) SetFileURL(s string) *StorageFileCreate {
|
|
sfc.mutation.SetFileURL(s)
|
|
return sfc
|
|
}
|
|
|
|
// SetNillableFileURL sets the "file_url" field if the given value is not nil.
|
|
func (sfc *StorageFileCreate) SetNillableFileURL(s *string) *StorageFileCreate {
|
|
if s != nil {
|
|
sfc.SetFileURL(*s)
|
|
}
|
|
return sfc
|
|
}
|
|
|
|
// SetID sets the "id" field.
|
|
func (sfc *StorageFileCreate) SetID(u uuid.UUID) *StorageFileCreate {
|
|
sfc.mutation.SetID(u)
|
|
return sfc
|
|
}
|
|
|
|
// SetNillableID sets the "id" field if the given value is not nil.
|
|
func (sfc *StorageFileCreate) SetNillableID(u *uuid.UUID) *StorageFileCreate {
|
|
if u != nil {
|
|
sfc.SetID(*u)
|
|
}
|
|
return sfc
|
|
}
|
|
|
|
// Mutation returns the StorageFileMutation object of the builder.
|
|
func (sfc *StorageFileCreate) Mutation() *StorageFileMutation {
|
|
return sfc.mutation
|
|
}
|
|
|
|
// Save creates the StorageFile in the database.
|
|
func (sfc *StorageFileCreate) Save(ctx context.Context) (*StorageFile, error) {
|
|
sfc.defaults()
|
|
return withHooks(ctx, sfc.sqlSave, sfc.mutation, sfc.hooks)
|
|
}
|
|
|
|
// SaveX calls Save and panics if Save returns an error.
|
|
func (sfc *StorageFileCreate) SaveX(ctx context.Context) *StorageFile {
|
|
v, err := sfc.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (sfc *StorageFileCreate) Exec(ctx context.Context) error {
|
|
_, err := sfc.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (sfc *StorageFileCreate) ExecX(ctx context.Context) {
|
|
if err := sfc.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// defaults sets the default values of the builder before save.
|
|
func (sfc *StorageFileCreate) defaults() {
|
|
if _, ok := sfc.mutation.CreateTime(); !ok {
|
|
v := storagefile.DefaultCreateTime()
|
|
sfc.mutation.SetCreateTime(v)
|
|
}
|
|
if _, ok := sfc.mutation.UpdateTime(); !ok {
|
|
v := storagefile.DefaultUpdateTime()
|
|
sfc.mutation.SetUpdateTime(v)
|
|
}
|
|
if _, ok := sfc.mutation.ID(); !ok {
|
|
v := storagefile.DefaultID()
|
|
sfc.mutation.SetID(v)
|
|
}
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (sfc *StorageFileCreate) check() error {
|
|
if _, ok := sfc.mutation.CreateTime(); !ok {
|
|
return &ValidationError{Name: "create_time", err: errors.New(`ent: missing required field "StorageFile.create_time"`)}
|
|
}
|
|
if _, ok := sfc.mutation.UpdateTime(); !ok {
|
|
return &ValidationError{Name: "update_time", err: errors.New(`ent: missing required field "StorageFile.update_time"`)}
|
|
}
|
|
if _, ok := sfc.mutation.BucketName(); !ok {
|
|
return &ValidationError{Name: "bucket_name", err: errors.New(`ent: missing required field "StorageFile.bucket_name"`)}
|
|
}
|
|
if v, ok := sfc.mutation.BucketName(); ok {
|
|
if err := storagefile.BucketNameValidator(v); err != nil {
|
|
return &ValidationError{Name: "bucket_name", err: fmt.Errorf(`ent: validator failed for field "StorageFile.bucket_name": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := sfc.mutation.ObjectName(); ok {
|
|
if err := storagefile.ObjectNameValidator(v); err != nil {
|
|
return &ValidationError{Name: "object_name", err: fmt.Errorf(`ent: validator failed for field "StorageFile.object_name": %w`, err)}
|
|
}
|
|
}
|
|
if _, ok := sfc.mutation.FilePath(); !ok {
|
|
return &ValidationError{Name: "file_path", err: errors.New(`ent: missing required field "StorageFile.file_path"`)}
|
|
}
|
|
if v, ok := sfc.mutation.FilePath(); ok {
|
|
if err := storagefile.FilePathValidator(v); err != nil {
|
|
return &ValidationError{Name: "file_path", err: fmt.Errorf(`ent: validator failed for field "StorageFile.file_path": %w`, err)}
|
|
}
|
|
}
|
|
if _, ok := sfc.mutation.FileType(); !ok {
|
|
return &ValidationError{Name: "file_type", err: errors.New(`ent: missing required field "StorageFile.file_type"`)}
|
|
}
|
|
if v, ok := sfc.mutation.FileType(); ok {
|
|
if err := storagefile.FileTypeValidator(v); err != nil {
|
|
return &ValidationError{Name: "file_type", err: fmt.Errorf(`ent: validator failed for field "StorageFile.file_type": %w`, err)}
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (sfc *StorageFileCreate) sqlSave(ctx context.Context) (*StorageFile, error) {
|
|
if err := sfc.check(); err != nil {
|
|
return nil, err
|
|
}
|
|
_node, _spec := sfc.createSpec()
|
|
if err := sqlgraph.CreateNode(ctx, sfc.driver, _spec); err != nil {
|
|
if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return nil, err
|
|
}
|
|
if _spec.ID.Value != nil {
|
|
if id, ok := _spec.ID.Value.(*uuid.UUID); ok {
|
|
_node.ID = *id
|
|
} else if err := _node.ID.Scan(_spec.ID.Value); err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
sfc.mutation.id = &_node.ID
|
|
sfc.mutation.done = true
|
|
return _node, nil
|
|
}
|
|
|
|
func (sfc *StorageFileCreate) createSpec() (*StorageFile, *sqlgraph.CreateSpec) {
|
|
var (
|
|
_node = &StorageFile{config: sfc.config}
|
|
_spec = sqlgraph.NewCreateSpec(storagefile.Table, sqlgraph.NewFieldSpec(storagefile.FieldID, field.TypeUUID))
|
|
)
|
|
_spec.OnConflict = sfc.conflict
|
|
if id, ok := sfc.mutation.ID(); ok {
|
|
_node.ID = id
|
|
_spec.ID.Value = &id
|
|
}
|
|
if value, ok := sfc.mutation.CreateTime(); ok {
|
|
_spec.SetField(storagefile.FieldCreateTime, field.TypeTime, value)
|
|
_node.CreateTime = value
|
|
}
|
|
if value, ok := sfc.mutation.UpdateTime(); ok {
|
|
_spec.SetField(storagefile.FieldUpdateTime, field.TypeTime, value)
|
|
_node.UpdateTime = value
|
|
}
|
|
if value, ok := sfc.mutation.BucketName(); ok {
|
|
_spec.SetField(storagefile.FieldBucketName, field.TypeString, value)
|
|
_node.BucketName = value
|
|
}
|
|
if value, ok := sfc.mutation.ObjectName(); ok {
|
|
_spec.SetField(storagefile.FieldObjectName, field.TypeString, value)
|
|
_node.ObjectName = value
|
|
}
|
|
if value, ok := sfc.mutation.FilePath(); ok {
|
|
_spec.SetField(storagefile.FieldFilePath, field.TypeString, value)
|
|
_node.FilePath = value
|
|
}
|
|
if value, ok := sfc.mutation.FileType(); ok {
|
|
_spec.SetField(storagefile.FieldFileType, field.TypeString, value)
|
|
_node.FileType = value
|
|
}
|
|
if value, ok := sfc.mutation.FileURL(); ok {
|
|
_spec.SetField(storagefile.FieldFileURL, field.TypeString, value)
|
|
_node.FileURL = value
|
|
}
|
|
return _node, _spec
|
|
}
|
|
|
|
// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
|
|
// of the `INSERT` statement. For example:
|
|
//
|
|
// client.StorageFile.Create().
|
|
// SetCreateTime(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.StorageFileUpsert) {
|
|
// SetCreateTime(v+v).
|
|
// }).
|
|
// Exec(ctx)
|
|
func (sfc *StorageFileCreate) OnConflict(opts ...sql.ConflictOption) *StorageFileUpsertOne {
|
|
sfc.conflict = opts
|
|
return &StorageFileUpsertOne{
|
|
create: sfc,
|
|
}
|
|
}
|
|
|
|
// OnConflictColumns calls `OnConflict` and configures the columns
|
|
// as conflict target. Using this option is equivalent to using:
|
|
//
|
|
// client.StorageFile.Create().
|
|
// OnConflict(sql.ConflictColumns(columns...)).
|
|
// Exec(ctx)
|
|
func (sfc *StorageFileCreate) OnConflictColumns(columns ...string) *StorageFileUpsertOne {
|
|
sfc.conflict = append(sfc.conflict, sql.ConflictColumns(columns...))
|
|
return &StorageFileUpsertOne{
|
|
create: sfc,
|
|
}
|
|
}
|
|
|
|
type (
|
|
// StorageFileUpsertOne is the builder for "upsert"-ing
|
|
// one StorageFile node.
|
|
StorageFileUpsertOne struct {
|
|
create *StorageFileCreate
|
|
}
|
|
|
|
// StorageFileUpsert is the "OnConflict" setter.
|
|
StorageFileUpsert struct {
|
|
*sql.UpdateSet
|
|
}
|
|
)
|
|
|
|
// SetUpdateTime sets the "update_time" field.
|
|
func (u *StorageFileUpsert) SetUpdateTime(v time.Time) *StorageFileUpsert {
|
|
u.Set(storagefile.FieldUpdateTime, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateUpdateTime sets the "update_time" field to the value that was provided on create.
|
|
func (u *StorageFileUpsert) UpdateUpdateTime() *StorageFileUpsert {
|
|
u.SetExcluded(storagefile.FieldUpdateTime)
|
|
return u
|
|
}
|
|
|
|
// SetBucketName sets the "bucket_name" field.
|
|
func (u *StorageFileUpsert) SetBucketName(v string) *StorageFileUpsert {
|
|
u.Set(storagefile.FieldBucketName, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateBucketName sets the "bucket_name" field to the value that was provided on create.
|
|
func (u *StorageFileUpsert) UpdateBucketName() *StorageFileUpsert {
|
|
u.SetExcluded(storagefile.FieldBucketName)
|
|
return u
|
|
}
|
|
|
|
// SetObjectName sets the "object_name" field.
|
|
func (u *StorageFileUpsert) SetObjectName(v string) *StorageFileUpsert {
|
|
u.Set(storagefile.FieldObjectName, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateObjectName sets the "object_name" field to the value that was provided on create.
|
|
func (u *StorageFileUpsert) UpdateObjectName() *StorageFileUpsert {
|
|
u.SetExcluded(storagefile.FieldObjectName)
|
|
return u
|
|
}
|
|
|
|
// ClearObjectName clears the value of the "object_name" field.
|
|
func (u *StorageFileUpsert) ClearObjectName() *StorageFileUpsert {
|
|
u.SetNull(storagefile.FieldObjectName)
|
|
return u
|
|
}
|
|
|
|
// SetFilePath sets the "file_path" field.
|
|
func (u *StorageFileUpsert) SetFilePath(v string) *StorageFileUpsert {
|
|
u.Set(storagefile.FieldFilePath, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateFilePath sets the "file_path" field to the value that was provided on create.
|
|
func (u *StorageFileUpsert) UpdateFilePath() *StorageFileUpsert {
|
|
u.SetExcluded(storagefile.FieldFilePath)
|
|
return u
|
|
}
|
|
|
|
// SetFileType sets the "file_type" field.
|
|
func (u *StorageFileUpsert) SetFileType(v string) *StorageFileUpsert {
|
|
u.Set(storagefile.FieldFileType, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateFileType sets the "file_type" field to the value that was provided on create.
|
|
func (u *StorageFileUpsert) UpdateFileType() *StorageFileUpsert {
|
|
u.SetExcluded(storagefile.FieldFileType)
|
|
return u
|
|
}
|
|
|
|
// SetFileURL sets the "file_url" field.
|
|
func (u *StorageFileUpsert) SetFileURL(v string) *StorageFileUpsert {
|
|
u.Set(storagefile.FieldFileURL, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateFileURL sets the "file_url" field to the value that was provided on create.
|
|
func (u *StorageFileUpsert) UpdateFileURL() *StorageFileUpsert {
|
|
u.SetExcluded(storagefile.FieldFileURL)
|
|
return u
|
|
}
|
|
|
|
// ClearFileURL clears the value of the "file_url" field.
|
|
func (u *StorageFileUpsert) ClearFileURL() *StorageFileUpsert {
|
|
u.SetNull(storagefile.FieldFileURL)
|
|
return u
|
|
}
|
|
|
|
// UpdateNewValues updates the mutable fields using the new values that were set on create except the ID field.
|
|
// Using this option is equivalent to using:
|
|
//
|
|
// client.StorageFile.Create().
|
|
// OnConflict(
|
|
// sql.ResolveWithNewValues(),
|
|
// sql.ResolveWith(func(u *sql.UpdateSet) {
|
|
// u.SetIgnore(storagefile.FieldID)
|
|
// }),
|
|
// ).
|
|
// Exec(ctx)
|
|
func (u *StorageFileUpsertOne) UpdateNewValues() *StorageFileUpsertOne {
|
|
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.ID(); exists {
|
|
s.SetIgnore(storagefile.FieldID)
|
|
}
|
|
if _, exists := u.create.mutation.CreateTime(); exists {
|
|
s.SetIgnore(storagefile.FieldCreateTime)
|
|
}
|
|
}))
|
|
return u
|
|
}
|
|
|
|
// Ignore sets each column to itself in case of conflict.
|
|
// Using this option is equivalent to using:
|
|
//
|
|
// client.StorageFile.Create().
|
|
// OnConflict(sql.ResolveWithIgnore()).
|
|
// Exec(ctx)
|
|
func (u *StorageFileUpsertOne) Ignore() *StorageFileUpsertOne {
|
|
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 *StorageFileUpsertOne) DoNothing() *StorageFileUpsertOne {
|
|
u.create.conflict = append(u.create.conflict, sql.DoNothing())
|
|
return u
|
|
}
|
|
|
|
// Update allows overriding fields `UPDATE` values. See the StorageFileCreate.OnConflict
|
|
// documentation for more info.
|
|
func (u *StorageFileUpsertOne) Update(set func(*StorageFileUpsert)) *StorageFileUpsertOne {
|
|
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
|
|
set(&StorageFileUpsert{UpdateSet: update})
|
|
}))
|
|
return u
|
|
}
|
|
|
|
// SetUpdateTime sets the "update_time" field.
|
|
func (u *StorageFileUpsertOne) SetUpdateTime(v time.Time) *StorageFileUpsertOne {
|
|
return u.Update(func(s *StorageFileUpsert) {
|
|
s.SetUpdateTime(v)
|
|
})
|
|
}
|
|
|
|
// UpdateUpdateTime sets the "update_time" field to the value that was provided on create.
|
|
func (u *StorageFileUpsertOne) UpdateUpdateTime() *StorageFileUpsertOne {
|
|
return u.Update(func(s *StorageFileUpsert) {
|
|
s.UpdateUpdateTime()
|
|
})
|
|
}
|
|
|
|
// SetBucketName sets the "bucket_name" field.
|
|
func (u *StorageFileUpsertOne) SetBucketName(v string) *StorageFileUpsertOne {
|
|
return u.Update(func(s *StorageFileUpsert) {
|
|
s.SetBucketName(v)
|
|
})
|
|
}
|
|
|
|
// UpdateBucketName sets the "bucket_name" field to the value that was provided on create.
|
|
func (u *StorageFileUpsertOne) UpdateBucketName() *StorageFileUpsertOne {
|
|
return u.Update(func(s *StorageFileUpsert) {
|
|
s.UpdateBucketName()
|
|
})
|
|
}
|
|
|
|
// SetObjectName sets the "object_name" field.
|
|
func (u *StorageFileUpsertOne) SetObjectName(v string) *StorageFileUpsertOne {
|
|
return u.Update(func(s *StorageFileUpsert) {
|
|
s.SetObjectName(v)
|
|
})
|
|
}
|
|
|
|
// UpdateObjectName sets the "object_name" field to the value that was provided on create.
|
|
func (u *StorageFileUpsertOne) UpdateObjectName() *StorageFileUpsertOne {
|
|
return u.Update(func(s *StorageFileUpsert) {
|
|
s.UpdateObjectName()
|
|
})
|
|
}
|
|
|
|
// ClearObjectName clears the value of the "object_name" field.
|
|
func (u *StorageFileUpsertOne) ClearObjectName() *StorageFileUpsertOne {
|
|
return u.Update(func(s *StorageFileUpsert) {
|
|
s.ClearObjectName()
|
|
})
|
|
}
|
|
|
|
// SetFilePath sets the "file_path" field.
|
|
func (u *StorageFileUpsertOne) SetFilePath(v string) *StorageFileUpsertOne {
|
|
return u.Update(func(s *StorageFileUpsert) {
|
|
s.SetFilePath(v)
|
|
})
|
|
}
|
|
|
|
// UpdateFilePath sets the "file_path" field to the value that was provided on create.
|
|
func (u *StorageFileUpsertOne) UpdateFilePath() *StorageFileUpsertOne {
|
|
return u.Update(func(s *StorageFileUpsert) {
|
|
s.UpdateFilePath()
|
|
})
|
|
}
|
|
|
|
// SetFileType sets the "file_type" field.
|
|
func (u *StorageFileUpsertOne) SetFileType(v string) *StorageFileUpsertOne {
|
|
return u.Update(func(s *StorageFileUpsert) {
|
|
s.SetFileType(v)
|
|
})
|
|
}
|
|
|
|
// UpdateFileType sets the "file_type" field to the value that was provided on create.
|
|
func (u *StorageFileUpsertOne) UpdateFileType() *StorageFileUpsertOne {
|
|
return u.Update(func(s *StorageFileUpsert) {
|
|
s.UpdateFileType()
|
|
})
|
|
}
|
|
|
|
// SetFileURL sets the "file_url" field.
|
|
func (u *StorageFileUpsertOne) SetFileURL(v string) *StorageFileUpsertOne {
|
|
return u.Update(func(s *StorageFileUpsert) {
|
|
s.SetFileURL(v)
|
|
})
|
|
}
|
|
|
|
// UpdateFileURL sets the "file_url" field to the value that was provided on create.
|
|
func (u *StorageFileUpsertOne) UpdateFileURL() *StorageFileUpsertOne {
|
|
return u.Update(func(s *StorageFileUpsert) {
|
|
s.UpdateFileURL()
|
|
})
|
|
}
|
|
|
|
// ClearFileURL clears the value of the "file_url" field.
|
|
func (u *StorageFileUpsertOne) ClearFileURL() *StorageFileUpsertOne {
|
|
return u.Update(func(s *StorageFileUpsert) {
|
|
s.ClearFileURL()
|
|
})
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (u *StorageFileUpsertOne) Exec(ctx context.Context) error {
|
|
if len(u.create.conflict) == 0 {
|
|
return errors.New("ent: missing options for StorageFileCreate.OnConflict")
|
|
}
|
|
return u.create.Exec(ctx)
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (u *StorageFileUpsertOne) 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 *StorageFileUpsertOne) ID(ctx context.Context) (id uuid.UUID, err error) {
|
|
if u.create.driver.Dialect() == dialect.MySQL {
|
|
// In case of "ON CONFLICT", there is no way to get back non-numeric ID
|
|
// fields from the database since MySQL does not support the RETURNING clause.
|
|
return id, errors.New("ent: StorageFileUpsertOne.ID is not supported by MySQL driver. Use StorageFileUpsertOne.Exec instead")
|
|
}
|
|
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 *StorageFileUpsertOne) IDX(ctx context.Context) uuid.UUID {
|
|
id, err := u.ID(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return id
|
|
}
|
|
|
|
// StorageFileCreateBulk is the builder for creating many StorageFile entities in bulk.
|
|
type StorageFileCreateBulk struct {
|
|
config
|
|
err error
|
|
builders []*StorageFileCreate
|
|
conflict []sql.ConflictOption
|
|
}
|
|
|
|
// Save creates the StorageFile entities in the database.
|
|
func (sfcb *StorageFileCreateBulk) Save(ctx context.Context) ([]*StorageFile, error) {
|
|
if sfcb.err != nil {
|
|
return nil, sfcb.err
|
|
}
|
|
specs := make([]*sqlgraph.CreateSpec, len(sfcb.builders))
|
|
nodes := make([]*StorageFile, len(sfcb.builders))
|
|
mutators := make([]Mutator, len(sfcb.builders))
|
|
for i := range sfcb.builders {
|
|
func(i int, root context.Context) {
|
|
builder := sfcb.builders[i]
|
|
builder.defaults()
|
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
|
mutation, ok := m.(*StorageFileMutation)
|
|
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, sfcb.builders[i+1].mutation)
|
|
} else {
|
|
spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
|
|
spec.OnConflict = sfcb.conflict
|
|
// Invoke the actual operation on the latest mutation in the chain.
|
|
if err = sqlgraph.BatchCreate(ctx, sfcb.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
|
|
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, sfcb.builders[0].mutation); err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
return nodes, nil
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (sfcb *StorageFileCreateBulk) SaveX(ctx context.Context) []*StorageFile {
|
|
v, err := sfcb.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (sfcb *StorageFileCreateBulk) Exec(ctx context.Context) error {
|
|
_, err := sfcb.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (sfcb *StorageFileCreateBulk) ExecX(ctx context.Context) {
|
|
if err := sfcb.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
|
|
// of the `INSERT` statement. For example:
|
|
//
|
|
// client.StorageFile.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.StorageFileUpsert) {
|
|
// SetCreateTime(v+v).
|
|
// }).
|
|
// Exec(ctx)
|
|
func (sfcb *StorageFileCreateBulk) OnConflict(opts ...sql.ConflictOption) *StorageFileUpsertBulk {
|
|
sfcb.conflict = opts
|
|
return &StorageFileUpsertBulk{
|
|
create: sfcb,
|
|
}
|
|
}
|
|
|
|
// OnConflictColumns calls `OnConflict` and configures the columns
|
|
// as conflict target. Using this option is equivalent to using:
|
|
//
|
|
// client.StorageFile.Create().
|
|
// OnConflict(sql.ConflictColumns(columns...)).
|
|
// Exec(ctx)
|
|
func (sfcb *StorageFileCreateBulk) OnConflictColumns(columns ...string) *StorageFileUpsertBulk {
|
|
sfcb.conflict = append(sfcb.conflict, sql.ConflictColumns(columns...))
|
|
return &StorageFileUpsertBulk{
|
|
create: sfcb,
|
|
}
|
|
}
|
|
|
|
// StorageFileUpsertBulk is the builder for "upsert"-ing
|
|
// a bulk of StorageFile nodes.
|
|
type StorageFileUpsertBulk struct {
|
|
create *StorageFileCreateBulk
|
|
}
|
|
|
|
// UpdateNewValues updates the mutable fields using the new values that
|
|
// were set on create. Using this option is equivalent to using:
|
|
//
|
|
// client.StorageFile.Create().
|
|
// OnConflict(
|
|
// sql.ResolveWithNewValues(),
|
|
// sql.ResolveWith(func(u *sql.UpdateSet) {
|
|
// u.SetIgnore(storagefile.FieldID)
|
|
// }),
|
|
// ).
|
|
// Exec(ctx)
|
|
func (u *StorageFileUpsertBulk) UpdateNewValues() *StorageFileUpsertBulk {
|
|
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.ID(); exists {
|
|
s.SetIgnore(storagefile.FieldID)
|
|
}
|
|
if _, exists := b.mutation.CreateTime(); exists {
|
|
s.SetIgnore(storagefile.FieldCreateTime)
|
|
}
|
|
}
|
|
}))
|
|
return u
|
|
}
|
|
|
|
// Ignore sets each column to itself in case of conflict.
|
|
// Using this option is equivalent to using:
|
|
//
|
|
// client.StorageFile.Create().
|
|
// OnConflict(sql.ResolveWithIgnore()).
|
|
// Exec(ctx)
|
|
func (u *StorageFileUpsertBulk) Ignore() *StorageFileUpsertBulk {
|
|
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 *StorageFileUpsertBulk) DoNothing() *StorageFileUpsertBulk {
|
|
u.create.conflict = append(u.create.conflict, sql.DoNothing())
|
|
return u
|
|
}
|
|
|
|
// Update allows overriding fields `UPDATE` values. See the StorageFileCreateBulk.OnConflict
|
|
// documentation for more info.
|
|
func (u *StorageFileUpsertBulk) Update(set func(*StorageFileUpsert)) *StorageFileUpsertBulk {
|
|
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
|
|
set(&StorageFileUpsert{UpdateSet: update})
|
|
}))
|
|
return u
|
|
}
|
|
|
|
// SetUpdateTime sets the "update_time" field.
|
|
func (u *StorageFileUpsertBulk) SetUpdateTime(v time.Time) *StorageFileUpsertBulk {
|
|
return u.Update(func(s *StorageFileUpsert) {
|
|
s.SetUpdateTime(v)
|
|
})
|
|
}
|
|
|
|
// UpdateUpdateTime sets the "update_time" field to the value that was provided on create.
|
|
func (u *StorageFileUpsertBulk) UpdateUpdateTime() *StorageFileUpsertBulk {
|
|
return u.Update(func(s *StorageFileUpsert) {
|
|
s.UpdateUpdateTime()
|
|
})
|
|
}
|
|
|
|
// SetBucketName sets the "bucket_name" field.
|
|
func (u *StorageFileUpsertBulk) SetBucketName(v string) *StorageFileUpsertBulk {
|
|
return u.Update(func(s *StorageFileUpsert) {
|
|
s.SetBucketName(v)
|
|
})
|
|
}
|
|
|
|
// UpdateBucketName sets the "bucket_name" field to the value that was provided on create.
|
|
func (u *StorageFileUpsertBulk) UpdateBucketName() *StorageFileUpsertBulk {
|
|
return u.Update(func(s *StorageFileUpsert) {
|
|
s.UpdateBucketName()
|
|
})
|
|
}
|
|
|
|
// SetObjectName sets the "object_name" field.
|
|
func (u *StorageFileUpsertBulk) SetObjectName(v string) *StorageFileUpsertBulk {
|
|
return u.Update(func(s *StorageFileUpsert) {
|
|
s.SetObjectName(v)
|
|
})
|
|
}
|
|
|
|
// UpdateObjectName sets the "object_name" field to the value that was provided on create.
|
|
func (u *StorageFileUpsertBulk) UpdateObjectName() *StorageFileUpsertBulk {
|
|
return u.Update(func(s *StorageFileUpsert) {
|
|
s.UpdateObjectName()
|
|
})
|
|
}
|
|
|
|
// ClearObjectName clears the value of the "object_name" field.
|
|
func (u *StorageFileUpsertBulk) ClearObjectName() *StorageFileUpsertBulk {
|
|
return u.Update(func(s *StorageFileUpsert) {
|
|
s.ClearObjectName()
|
|
})
|
|
}
|
|
|
|
// SetFilePath sets the "file_path" field.
|
|
func (u *StorageFileUpsertBulk) SetFilePath(v string) *StorageFileUpsertBulk {
|
|
return u.Update(func(s *StorageFileUpsert) {
|
|
s.SetFilePath(v)
|
|
})
|
|
}
|
|
|
|
// UpdateFilePath sets the "file_path" field to the value that was provided on create.
|
|
func (u *StorageFileUpsertBulk) UpdateFilePath() *StorageFileUpsertBulk {
|
|
return u.Update(func(s *StorageFileUpsert) {
|
|
s.UpdateFilePath()
|
|
})
|
|
}
|
|
|
|
// SetFileType sets the "file_type" field.
|
|
func (u *StorageFileUpsertBulk) SetFileType(v string) *StorageFileUpsertBulk {
|
|
return u.Update(func(s *StorageFileUpsert) {
|
|
s.SetFileType(v)
|
|
})
|
|
}
|
|
|
|
// UpdateFileType sets the "file_type" field to the value that was provided on create.
|
|
func (u *StorageFileUpsertBulk) UpdateFileType() *StorageFileUpsertBulk {
|
|
return u.Update(func(s *StorageFileUpsert) {
|
|
s.UpdateFileType()
|
|
})
|
|
}
|
|
|
|
// SetFileURL sets the "file_url" field.
|
|
func (u *StorageFileUpsertBulk) SetFileURL(v string) *StorageFileUpsertBulk {
|
|
return u.Update(func(s *StorageFileUpsert) {
|
|
s.SetFileURL(v)
|
|
})
|
|
}
|
|
|
|
// UpdateFileURL sets the "file_url" field to the value that was provided on create.
|
|
func (u *StorageFileUpsertBulk) UpdateFileURL() *StorageFileUpsertBulk {
|
|
return u.Update(func(s *StorageFileUpsert) {
|
|
s.UpdateFileURL()
|
|
})
|
|
}
|
|
|
|
// ClearFileURL clears the value of the "file_url" field.
|
|
func (u *StorageFileUpsertBulk) ClearFileURL() *StorageFileUpsertBulk {
|
|
return u.Update(func(s *StorageFileUpsert) {
|
|
s.ClearFileURL()
|
|
})
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (u *StorageFileUpsertBulk) 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 StorageFileCreateBulk instead", i)
|
|
}
|
|
}
|
|
if len(u.create.conflict) == 0 {
|
|
return errors.New("ent: missing options for StorageFileCreateBulk.OnConflict")
|
|
}
|
|
return u.create.Exec(ctx)
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (u *StorageFileUpsertBulk) ExecX(ctx context.Context) {
|
|
if err := u.create.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|