815 lines
24 KiB
Go
815 lines
24 KiB
Go
// ENT数据库文件,请勿编辑。
|
|
|
|
package ent
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"likedream-goframe/internal/ent/cpimage"
|
|
"likedream-goframe/internal/ent/sysuser"
|
|
"likedream-goframe/internal/framework/ent2"
|
|
|
|
"entgo.io/ent/dialect/sql"
|
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
|
"entgo.io/ent/schema/field"
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
// CpImageCreate is the builder for creating a CpImage entity.
|
|
type CpImageCreate struct {
|
|
config
|
|
mutation *CpImageMutation
|
|
hooks []Hook
|
|
conflict []sql.ConflictOption
|
|
}
|
|
|
|
// SetCreateTime sets the "create_time" field.
|
|
func (_c *CpImageCreate) SetCreateTime(v *ent2.CustomTime) *CpImageCreate {
|
|
_c.mutation.SetCreateTime(v)
|
|
return _c
|
|
}
|
|
|
|
// SetUpdateTime sets the "update_time" field.
|
|
func (_c *CpImageCreate) SetUpdateTime(v *ent2.CustomTime) *CpImageCreate {
|
|
_c.mutation.SetUpdateTime(v)
|
|
return _c
|
|
}
|
|
|
|
// SetImageID sets the "image_id" field.
|
|
func (_c *CpImageCreate) SetImageID(v uuid.UUID) *CpImageCreate {
|
|
_c.mutation.SetImageID(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableImageID sets the "image_id" field if the given value is not nil.
|
|
func (_c *CpImageCreate) SetNillableImageID(v *uuid.UUID) *CpImageCreate {
|
|
if v != nil {
|
|
_c.SetImageID(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetKey sets the "key" field.
|
|
func (_c *CpImageCreate) SetKey(v string) *CpImageCreate {
|
|
_c.mutation.SetKey(v)
|
|
return _c
|
|
}
|
|
|
|
// SetUserID sets the "user_id" field.
|
|
func (_c *CpImageCreate) SetUserID(v int64) *CpImageCreate {
|
|
_c.mutation.SetUserID(v)
|
|
return _c
|
|
}
|
|
|
|
// SetContentType sets the "content_type" field.
|
|
func (_c *CpImageCreate) SetContentType(v string) *CpImageCreate {
|
|
_c.mutation.SetContentType(v)
|
|
return _c
|
|
}
|
|
|
|
// SetContentLength sets the "content_length" field.
|
|
func (_c *CpImageCreate) SetContentLength(v int64) *CpImageCreate {
|
|
_c.mutation.SetContentLength(v)
|
|
return _c
|
|
}
|
|
|
|
// SetUser sets the "user" edge to the SysUser entity.
|
|
func (_c *CpImageCreate) SetUser(v *SysUser) *CpImageCreate {
|
|
return _c.SetUserID(v.ID)
|
|
}
|
|
|
|
// Mutation returns the CpImageMutation object of the builder.
|
|
func (_c *CpImageCreate) Mutation() *CpImageMutation {
|
|
return _c.mutation
|
|
}
|
|
|
|
// Save creates the CpImage in the database.
|
|
func (_c *CpImageCreate) Save(ctx context.Context) (*CpImage, error) {
|
|
if err := _c.defaults(); err != nil {
|
|
return nil, err
|
|
}
|
|
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
|
|
}
|
|
|
|
// SaveX calls Save and panics if Save returns an error.
|
|
func (_c *CpImageCreate) SaveX(ctx context.Context) *CpImage {
|
|
v, err := _c.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_c *CpImageCreate) Exec(ctx context.Context) error {
|
|
_, err := _c.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_c *CpImageCreate) 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 *CpImageCreate) defaults() error {
|
|
if _, ok := _c.mutation.CreateTime(); !ok {
|
|
if cpimage.DefaultCreateTime == nil {
|
|
return fmt.Errorf("ent: uninitialized cpimage.DefaultCreateTime (forgotten import ent/runtime?)")
|
|
}
|
|
v := cpimage.DefaultCreateTime()
|
|
_c.mutation.SetCreateTime(v)
|
|
}
|
|
if _, ok := _c.mutation.UpdateTime(); !ok {
|
|
if cpimage.DefaultUpdateTime == nil {
|
|
return fmt.Errorf("ent: uninitialized cpimage.DefaultUpdateTime (forgotten import ent/runtime?)")
|
|
}
|
|
v := cpimage.DefaultUpdateTime()
|
|
_c.mutation.SetUpdateTime(v)
|
|
}
|
|
if _, ok := _c.mutation.ImageID(); !ok {
|
|
if cpimage.DefaultImageID == nil {
|
|
return fmt.Errorf("ent: uninitialized cpimage.DefaultImageID (forgotten import ent/runtime?)")
|
|
}
|
|
v := cpimage.DefaultImageID()
|
|
_c.mutation.SetImageID(v)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (_c *CpImageCreate) check() error {
|
|
if _, ok := _c.mutation.CreateTime(); !ok {
|
|
return &ValidationError{Name: "create_time", err: errors.New(`ent: missing required field "CpImage.create_time"`)}
|
|
}
|
|
if _, ok := _c.mutation.UpdateTime(); !ok {
|
|
return &ValidationError{Name: "update_time", err: errors.New(`ent: missing required field "CpImage.update_time"`)}
|
|
}
|
|
if _, ok := _c.mutation.ImageID(); !ok {
|
|
return &ValidationError{Name: "image_id", err: errors.New(`ent: missing required field "CpImage.image_id"`)}
|
|
}
|
|
if _, ok := _c.mutation.Key(); !ok {
|
|
return &ValidationError{Name: "key", err: errors.New(`ent: missing required field "CpImage.key"`)}
|
|
}
|
|
if v, ok := _c.mutation.Key(); ok {
|
|
if err := cpimage.KeyValidator(v); err != nil {
|
|
return &ValidationError{Name: "key", err: fmt.Errorf(`ent: validator failed for field "CpImage.key": %w`, err)}
|
|
}
|
|
}
|
|
if _, ok := _c.mutation.UserID(); !ok {
|
|
return &ValidationError{Name: "user_id", err: errors.New(`ent: missing required field "CpImage.user_id"`)}
|
|
}
|
|
if v, ok := _c.mutation.UserID(); ok {
|
|
if err := cpimage.UserIDValidator(v); err != nil {
|
|
return &ValidationError{Name: "user_id", err: fmt.Errorf(`ent: validator failed for field "CpImage.user_id": %w`, err)}
|
|
}
|
|
}
|
|
if _, ok := _c.mutation.ContentType(); !ok {
|
|
return &ValidationError{Name: "content_type", err: errors.New(`ent: missing required field "CpImage.content_type"`)}
|
|
}
|
|
if v, ok := _c.mutation.ContentType(); ok {
|
|
if err := cpimage.ContentTypeValidator(v); err != nil {
|
|
return &ValidationError{Name: "content_type", err: fmt.Errorf(`ent: validator failed for field "CpImage.content_type": %w`, err)}
|
|
}
|
|
}
|
|
if _, ok := _c.mutation.ContentLength(); !ok {
|
|
return &ValidationError{Name: "content_length", err: errors.New(`ent: missing required field "CpImage.content_length"`)}
|
|
}
|
|
if v, ok := _c.mutation.ContentLength(); ok {
|
|
if err := cpimage.ContentLengthValidator(v); err != nil {
|
|
return &ValidationError{Name: "content_length", err: fmt.Errorf(`ent: validator failed for field "CpImage.content_length": %w`, err)}
|
|
}
|
|
}
|
|
if len(_c.mutation.UserIDs()) == 0 {
|
|
return &ValidationError{Name: "user", err: errors.New(`ent: missing required edge "CpImage.user"`)}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (_c *CpImageCreate) sqlSave(ctx context.Context) (*CpImage, 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 = int64(id)
|
|
_c.mutation.id = &_node.ID
|
|
_c.mutation.done = true
|
|
return _node, nil
|
|
}
|
|
|
|
func (_c *CpImageCreate) createSpec() (*CpImage, *sqlgraph.CreateSpec) {
|
|
var (
|
|
_node = &CpImage{config: _c.config}
|
|
_spec = sqlgraph.NewCreateSpec(cpimage.Table, sqlgraph.NewFieldSpec(cpimage.FieldID, field.TypeInt64))
|
|
)
|
|
_spec.Schema = _c.schemaConfig.CpImage
|
|
_spec.OnConflict = _c.conflict
|
|
if value, ok := _c.mutation.CreateTime(); ok {
|
|
_spec.SetField(cpimage.FieldCreateTime, field.TypeString, value)
|
|
_node.CreateTime = value
|
|
}
|
|
if value, ok := _c.mutation.UpdateTime(); ok {
|
|
_spec.SetField(cpimage.FieldUpdateTime, field.TypeString, value)
|
|
_node.UpdateTime = value
|
|
}
|
|
if value, ok := _c.mutation.ImageID(); ok {
|
|
_spec.SetField(cpimage.FieldImageID, field.TypeUUID, value)
|
|
_node.ImageID = value
|
|
}
|
|
if value, ok := _c.mutation.Key(); ok {
|
|
_spec.SetField(cpimage.FieldKey, field.TypeString, value)
|
|
_node.Key = value
|
|
}
|
|
if value, ok := _c.mutation.ContentType(); ok {
|
|
_spec.SetField(cpimage.FieldContentType, field.TypeString, value)
|
|
_node.ContentType = value
|
|
}
|
|
if value, ok := _c.mutation.ContentLength(); ok {
|
|
_spec.SetField(cpimage.FieldContentLength, field.TypeInt64, value)
|
|
_node.ContentLength = value
|
|
}
|
|
if nodes := _c.mutation.UserIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: cpimage.UserTable,
|
|
Columns: []string{cpimage.UserColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(sysuser.FieldID, field.TypeInt64),
|
|
},
|
|
}
|
|
edge.Schema = _c.schemaConfig.CpImage
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_node.UserID = nodes[0]
|
|
_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.CpImage.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.CpImageUpsert) {
|
|
// SetCreateTime(v+v).
|
|
// }).
|
|
// Exec(ctx)
|
|
func (_c *CpImageCreate) OnConflict(opts ...sql.ConflictOption) *CpImageUpsertOne {
|
|
_c.conflict = opts
|
|
return &CpImageUpsertOne{
|
|
create: _c,
|
|
}
|
|
}
|
|
|
|
// OnConflictColumns calls `OnConflict` and configures the columns
|
|
// as conflict target. Using this option is equivalent to using:
|
|
//
|
|
// client.CpImage.Create().
|
|
// OnConflict(sql.ConflictColumns(columns...)).
|
|
// Exec(ctx)
|
|
func (_c *CpImageCreate) OnConflictColumns(columns ...string) *CpImageUpsertOne {
|
|
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
|
|
return &CpImageUpsertOne{
|
|
create: _c,
|
|
}
|
|
}
|
|
|
|
type (
|
|
// CpImageUpsertOne is the builder for "upsert"-ing
|
|
// one CpImage node.
|
|
CpImageUpsertOne struct {
|
|
create *CpImageCreate
|
|
}
|
|
|
|
// CpImageUpsert is the "OnConflict" setter.
|
|
CpImageUpsert struct {
|
|
*sql.UpdateSet
|
|
}
|
|
)
|
|
|
|
// SetUpdateTime sets the "update_time" field.
|
|
func (u *CpImageUpsert) SetUpdateTime(v *ent2.CustomTime) *CpImageUpsert {
|
|
u.Set(cpimage.FieldUpdateTime, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateUpdateTime sets the "update_time" field to the value that was provided on create.
|
|
func (u *CpImageUpsert) UpdateUpdateTime() *CpImageUpsert {
|
|
u.SetExcluded(cpimage.FieldUpdateTime)
|
|
return u
|
|
}
|
|
|
|
// SetKey sets the "key" field.
|
|
func (u *CpImageUpsert) SetKey(v string) *CpImageUpsert {
|
|
u.Set(cpimage.FieldKey, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateKey sets the "key" field to the value that was provided on create.
|
|
func (u *CpImageUpsert) UpdateKey() *CpImageUpsert {
|
|
u.SetExcluded(cpimage.FieldKey)
|
|
return u
|
|
}
|
|
|
|
// SetUserID sets the "user_id" field.
|
|
func (u *CpImageUpsert) SetUserID(v int64) *CpImageUpsert {
|
|
u.Set(cpimage.FieldUserID, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateUserID sets the "user_id" field to the value that was provided on create.
|
|
func (u *CpImageUpsert) UpdateUserID() *CpImageUpsert {
|
|
u.SetExcluded(cpimage.FieldUserID)
|
|
return u
|
|
}
|
|
|
|
// SetContentType sets the "content_type" field.
|
|
func (u *CpImageUpsert) SetContentType(v string) *CpImageUpsert {
|
|
u.Set(cpimage.FieldContentType, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateContentType sets the "content_type" field to the value that was provided on create.
|
|
func (u *CpImageUpsert) UpdateContentType() *CpImageUpsert {
|
|
u.SetExcluded(cpimage.FieldContentType)
|
|
return u
|
|
}
|
|
|
|
// SetContentLength sets the "content_length" field.
|
|
func (u *CpImageUpsert) SetContentLength(v int64) *CpImageUpsert {
|
|
u.Set(cpimage.FieldContentLength, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateContentLength sets the "content_length" field to the value that was provided on create.
|
|
func (u *CpImageUpsert) UpdateContentLength() *CpImageUpsert {
|
|
u.SetExcluded(cpimage.FieldContentLength)
|
|
return u
|
|
}
|
|
|
|
// AddContentLength adds v to the "content_length" field.
|
|
func (u *CpImageUpsert) AddContentLength(v int64) *CpImageUpsert {
|
|
u.Add(cpimage.FieldContentLength, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateNewValues updates the mutable fields using the new values that were set on create.
|
|
// Using this option is equivalent to using:
|
|
//
|
|
// client.CpImage.Create().
|
|
// OnConflict(
|
|
// sql.ResolveWithNewValues(),
|
|
// ).
|
|
// Exec(ctx)
|
|
func (u *CpImageUpsertOne) UpdateNewValues() *CpImageUpsertOne {
|
|
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.CreateTime(); exists {
|
|
s.SetIgnore(cpimage.FieldCreateTime)
|
|
}
|
|
if _, exists := u.create.mutation.ImageID(); exists {
|
|
s.SetIgnore(cpimage.FieldImageID)
|
|
}
|
|
}))
|
|
return u
|
|
}
|
|
|
|
// Ignore sets each column to itself in case of conflict.
|
|
// Using this option is equivalent to using:
|
|
//
|
|
// client.CpImage.Create().
|
|
// OnConflict(sql.ResolveWithIgnore()).
|
|
// Exec(ctx)
|
|
func (u *CpImageUpsertOne) Ignore() *CpImageUpsertOne {
|
|
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 *CpImageUpsertOne) DoNothing() *CpImageUpsertOne {
|
|
u.create.conflict = append(u.create.conflict, sql.DoNothing())
|
|
return u
|
|
}
|
|
|
|
// Update allows overriding fields `UPDATE` values. See the CpImageCreate.OnConflict
|
|
// documentation for more info.
|
|
func (u *CpImageUpsertOne) Update(set func(*CpImageUpsert)) *CpImageUpsertOne {
|
|
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
|
|
set(&CpImageUpsert{UpdateSet: update})
|
|
}))
|
|
return u
|
|
}
|
|
|
|
// SetUpdateTime sets the "update_time" field.
|
|
func (u *CpImageUpsertOne) SetUpdateTime(v *ent2.CustomTime) *CpImageUpsertOne {
|
|
return u.Update(func(s *CpImageUpsert) {
|
|
s.SetUpdateTime(v)
|
|
})
|
|
}
|
|
|
|
// UpdateUpdateTime sets the "update_time" field to the value that was provided on create.
|
|
func (u *CpImageUpsertOne) UpdateUpdateTime() *CpImageUpsertOne {
|
|
return u.Update(func(s *CpImageUpsert) {
|
|
s.UpdateUpdateTime()
|
|
})
|
|
}
|
|
|
|
// SetKey sets the "key" field.
|
|
func (u *CpImageUpsertOne) SetKey(v string) *CpImageUpsertOne {
|
|
return u.Update(func(s *CpImageUpsert) {
|
|
s.SetKey(v)
|
|
})
|
|
}
|
|
|
|
// UpdateKey sets the "key" field to the value that was provided on create.
|
|
func (u *CpImageUpsertOne) UpdateKey() *CpImageUpsertOne {
|
|
return u.Update(func(s *CpImageUpsert) {
|
|
s.UpdateKey()
|
|
})
|
|
}
|
|
|
|
// SetUserID sets the "user_id" field.
|
|
func (u *CpImageUpsertOne) SetUserID(v int64) *CpImageUpsertOne {
|
|
return u.Update(func(s *CpImageUpsert) {
|
|
s.SetUserID(v)
|
|
})
|
|
}
|
|
|
|
// UpdateUserID sets the "user_id" field to the value that was provided on create.
|
|
func (u *CpImageUpsertOne) UpdateUserID() *CpImageUpsertOne {
|
|
return u.Update(func(s *CpImageUpsert) {
|
|
s.UpdateUserID()
|
|
})
|
|
}
|
|
|
|
// SetContentType sets the "content_type" field.
|
|
func (u *CpImageUpsertOne) SetContentType(v string) *CpImageUpsertOne {
|
|
return u.Update(func(s *CpImageUpsert) {
|
|
s.SetContentType(v)
|
|
})
|
|
}
|
|
|
|
// UpdateContentType sets the "content_type" field to the value that was provided on create.
|
|
func (u *CpImageUpsertOne) UpdateContentType() *CpImageUpsertOne {
|
|
return u.Update(func(s *CpImageUpsert) {
|
|
s.UpdateContentType()
|
|
})
|
|
}
|
|
|
|
// SetContentLength sets the "content_length" field.
|
|
func (u *CpImageUpsertOne) SetContentLength(v int64) *CpImageUpsertOne {
|
|
return u.Update(func(s *CpImageUpsert) {
|
|
s.SetContentLength(v)
|
|
})
|
|
}
|
|
|
|
// AddContentLength adds v to the "content_length" field.
|
|
func (u *CpImageUpsertOne) AddContentLength(v int64) *CpImageUpsertOne {
|
|
return u.Update(func(s *CpImageUpsert) {
|
|
s.AddContentLength(v)
|
|
})
|
|
}
|
|
|
|
// UpdateContentLength sets the "content_length" field to the value that was provided on create.
|
|
func (u *CpImageUpsertOne) UpdateContentLength() *CpImageUpsertOne {
|
|
return u.Update(func(s *CpImageUpsert) {
|
|
s.UpdateContentLength()
|
|
})
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (u *CpImageUpsertOne) Exec(ctx context.Context) error {
|
|
if len(u.create.conflict) == 0 {
|
|
return errors.New("ent: missing options for CpImageCreate.OnConflict")
|
|
}
|
|
return u.create.Exec(ctx)
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (u *CpImageUpsertOne) 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 *CpImageUpsertOne) ID(ctx context.Context) (id int64, 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 *CpImageUpsertOne) IDX(ctx context.Context) int64 {
|
|
id, err := u.ID(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return id
|
|
}
|
|
|
|
// CpImageCreateBulk is the builder for creating many CpImage entities in bulk.
|
|
type CpImageCreateBulk struct {
|
|
config
|
|
err error
|
|
builders []*CpImageCreate
|
|
conflict []sql.ConflictOption
|
|
}
|
|
|
|
// Save creates the CpImage entities in the database.
|
|
func (_c *CpImageCreateBulk) Save(ctx context.Context) ([]*CpImage, error) {
|
|
if _c.err != nil {
|
|
return nil, _c.err
|
|
}
|
|
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
|
|
nodes := make([]*CpImage, 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.(*CpImageMutation)
|
|
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 = int64(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 *CpImageCreateBulk) SaveX(ctx context.Context) []*CpImage {
|
|
v, err := _c.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_c *CpImageCreateBulk) Exec(ctx context.Context) error {
|
|
_, err := _c.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_c *CpImageCreateBulk) 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.CpImage.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.CpImageUpsert) {
|
|
// SetCreateTime(v+v).
|
|
// }).
|
|
// Exec(ctx)
|
|
func (_c *CpImageCreateBulk) OnConflict(opts ...sql.ConflictOption) *CpImageUpsertBulk {
|
|
_c.conflict = opts
|
|
return &CpImageUpsertBulk{
|
|
create: _c,
|
|
}
|
|
}
|
|
|
|
// OnConflictColumns calls `OnConflict` and configures the columns
|
|
// as conflict target. Using this option is equivalent to using:
|
|
//
|
|
// client.CpImage.Create().
|
|
// OnConflict(sql.ConflictColumns(columns...)).
|
|
// Exec(ctx)
|
|
func (_c *CpImageCreateBulk) OnConflictColumns(columns ...string) *CpImageUpsertBulk {
|
|
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
|
|
return &CpImageUpsertBulk{
|
|
create: _c,
|
|
}
|
|
}
|
|
|
|
// CpImageUpsertBulk is the builder for "upsert"-ing
|
|
// a bulk of CpImage nodes.
|
|
type CpImageUpsertBulk struct {
|
|
create *CpImageCreateBulk
|
|
}
|
|
|
|
// UpdateNewValues updates the mutable fields using the new values that
|
|
// were set on create. Using this option is equivalent to using:
|
|
//
|
|
// client.CpImage.Create().
|
|
// OnConflict(
|
|
// sql.ResolveWithNewValues(),
|
|
// ).
|
|
// Exec(ctx)
|
|
func (u *CpImageUpsertBulk) UpdateNewValues() *CpImageUpsertBulk {
|
|
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.CreateTime(); exists {
|
|
s.SetIgnore(cpimage.FieldCreateTime)
|
|
}
|
|
if _, exists := b.mutation.ImageID(); exists {
|
|
s.SetIgnore(cpimage.FieldImageID)
|
|
}
|
|
}
|
|
}))
|
|
return u
|
|
}
|
|
|
|
// Ignore sets each column to itself in case of conflict.
|
|
// Using this option is equivalent to using:
|
|
//
|
|
// client.CpImage.Create().
|
|
// OnConflict(sql.ResolveWithIgnore()).
|
|
// Exec(ctx)
|
|
func (u *CpImageUpsertBulk) Ignore() *CpImageUpsertBulk {
|
|
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 *CpImageUpsertBulk) DoNothing() *CpImageUpsertBulk {
|
|
u.create.conflict = append(u.create.conflict, sql.DoNothing())
|
|
return u
|
|
}
|
|
|
|
// Update allows overriding fields `UPDATE` values. See the CpImageCreateBulk.OnConflict
|
|
// documentation for more info.
|
|
func (u *CpImageUpsertBulk) Update(set func(*CpImageUpsert)) *CpImageUpsertBulk {
|
|
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
|
|
set(&CpImageUpsert{UpdateSet: update})
|
|
}))
|
|
return u
|
|
}
|
|
|
|
// SetUpdateTime sets the "update_time" field.
|
|
func (u *CpImageUpsertBulk) SetUpdateTime(v *ent2.CustomTime) *CpImageUpsertBulk {
|
|
return u.Update(func(s *CpImageUpsert) {
|
|
s.SetUpdateTime(v)
|
|
})
|
|
}
|
|
|
|
// UpdateUpdateTime sets the "update_time" field to the value that was provided on create.
|
|
func (u *CpImageUpsertBulk) UpdateUpdateTime() *CpImageUpsertBulk {
|
|
return u.Update(func(s *CpImageUpsert) {
|
|
s.UpdateUpdateTime()
|
|
})
|
|
}
|
|
|
|
// SetKey sets the "key" field.
|
|
func (u *CpImageUpsertBulk) SetKey(v string) *CpImageUpsertBulk {
|
|
return u.Update(func(s *CpImageUpsert) {
|
|
s.SetKey(v)
|
|
})
|
|
}
|
|
|
|
// UpdateKey sets the "key" field to the value that was provided on create.
|
|
func (u *CpImageUpsertBulk) UpdateKey() *CpImageUpsertBulk {
|
|
return u.Update(func(s *CpImageUpsert) {
|
|
s.UpdateKey()
|
|
})
|
|
}
|
|
|
|
// SetUserID sets the "user_id" field.
|
|
func (u *CpImageUpsertBulk) SetUserID(v int64) *CpImageUpsertBulk {
|
|
return u.Update(func(s *CpImageUpsert) {
|
|
s.SetUserID(v)
|
|
})
|
|
}
|
|
|
|
// UpdateUserID sets the "user_id" field to the value that was provided on create.
|
|
func (u *CpImageUpsertBulk) UpdateUserID() *CpImageUpsertBulk {
|
|
return u.Update(func(s *CpImageUpsert) {
|
|
s.UpdateUserID()
|
|
})
|
|
}
|
|
|
|
// SetContentType sets the "content_type" field.
|
|
func (u *CpImageUpsertBulk) SetContentType(v string) *CpImageUpsertBulk {
|
|
return u.Update(func(s *CpImageUpsert) {
|
|
s.SetContentType(v)
|
|
})
|
|
}
|
|
|
|
// UpdateContentType sets the "content_type" field to the value that was provided on create.
|
|
func (u *CpImageUpsertBulk) UpdateContentType() *CpImageUpsertBulk {
|
|
return u.Update(func(s *CpImageUpsert) {
|
|
s.UpdateContentType()
|
|
})
|
|
}
|
|
|
|
// SetContentLength sets the "content_length" field.
|
|
func (u *CpImageUpsertBulk) SetContentLength(v int64) *CpImageUpsertBulk {
|
|
return u.Update(func(s *CpImageUpsert) {
|
|
s.SetContentLength(v)
|
|
})
|
|
}
|
|
|
|
// AddContentLength adds v to the "content_length" field.
|
|
func (u *CpImageUpsertBulk) AddContentLength(v int64) *CpImageUpsertBulk {
|
|
return u.Update(func(s *CpImageUpsert) {
|
|
s.AddContentLength(v)
|
|
})
|
|
}
|
|
|
|
// UpdateContentLength sets the "content_length" field to the value that was provided on create.
|
|
func (u *CpImageUpsertBulk) UpdateContentLength() *CpImageUpsertBulk {
|
|
return u.Update(func(s *CpImageUpsert) {
|
|
s.UpdateContentLength()
|
|
})
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (u *CpImageUpsertBulk) 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 CpImageCreateBulk instead", i)
|
|
}
|
|
}
|
|
if len(u.create.conflict) == 0 {
|
|
return errors.New("ent: missing options for CpImageCreateBulk.OnConflict")
|
|
}
|
|
return u.create.Exec(ctx)
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (u *CpImageUpsertBulk) ExecX(ctx context.Context) {
|
|
if err := u.create.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|