mirror of
https://github.com/cloudreve/cloudreve.git
synced 2025-12-15 10:04:01 +08:00
828 lines
23 KiB
Go
828 lines
23 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/fsevent"
|
|
"github.com/cloudreve/Cloudreve/v4/ent/user"
|
|
"github.com/gofrs/uuid"
|
|
)
|
|
|
|
// FsEventCreate is the builder for creating a FsEvent entity.
|
|
type FsEventCreate struct {
|
|
config
|
|
mutation *FsEventMutation
|
|
hooks []Hook
|
|
conflict []sql.ConflictOption
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (fec *FsEventCreate) SetCreatedAt(t time.Time) *FsEventCreate {
|
|
fec.mutation.SetCreatedAt(t)
|
|
return fec
|
|
}
|
|
|
|
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
|
func (fec *FsEventCreate) SetNillableCreatedAt(t *time.Time) *FsEventCreate {
|
|
if t != nil {
|
|
fec.SetCreatedAt(*t)
|
|
}
|
|
return fec
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (fec *FsEventCreate) SetUpdatedAt(t time.Time) *FsEventCreate {
|
|
fec.mutation.SetUpdatedAt(t)
|
|
return fec
|
|
}
|
|
|
|
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
|
|
func (fec *FsEventCreate) SetNillableUpdatedAt(t *time.Time) *FsEventCreate {
|
|
if t != nil {
|
|
fec.SetUpdatedAt(*t)
|
|
}
|
|
return fec
|
|
}
|
|
|
|
// SetDeletedAt sets the "deleted_at" field.
|
|
func (fec *FsEventCreate) SetDeletedAt(t time.Time) *FsEventCreate {
|
|
fec.mutation.SetDeletedAt(t)
|
|
return fec
|
|
}
|
|
|
|
// SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
|
|
func (fec *FsEventCreate) SetNillableDeletedAt(t *time.Time) *FsEventCreate {
|
|
if t != nil {
|
|
fec.SetDeletedAt(*t)
|
|
}
|
|
return fec
|
|
}
|
|
|
|
// SetEvent sets the "event" field.
|
|
func (fec *FsEventCreate) SetEvent(s string) *FsEventCreate {
|
|
fec.mutation.SetEvent(s)
|
|
return fec
|
|
}
|
|
|
|
// SetSubscriber sets the "subscriber" field.
|
|
func (fec *FsEventCreate) SetSubscriber(u uuid.UUID) *FsEventCreate {
|
|
fec.mutation.SetSubscriber(u)
|
|
return fec
|
|
}
|
|
|
|
// SetUserFsevent sets the "user_fsevent" field.
|
|
func (fec *FsEventCreate) SetUserFsevent(i int) *FsEventCreate {
|
|
fec.mutation.SetUserFsevent(i)
|
|
return fec
|
|
}
|
|
|
|
// SetNillableUserFsevent sets the "user_fsevent" field if the given value is not nil.
|
|
func (fec *FsEventCreate) SetNillableUserFsevent(i *int) *FsEventCreate {
|
|
if i != nil {
|
|
fec.SetUserFsevent(*i)
|
|
}
|
|
return fec
|
|
}
|
|
|
|
// SetUserID sets the "user" edge to the User entity by ID.
|
|
func (fec *FsEventCreate) SetUserID(id int) *FsEventCreate {
|
|
fec.mutation.SetUserID(id)
|
|
return fec
|
|
}
|
|
|
|
// SetNillableUserID sets the "user" edge to the User entity by ID if the given value is not nil.
|
|
func (fec *FsEventCreate) SetNillableUserID(id *int) *FsEventCreate {
|
|
if id != nil {
|
|
fec = fec.SetUserID(*id)
|
|
}
|
|
return fec
|
|
}
|
|
|
|
// SetUser sets the "user" edge to the User entity.
|
|
func (fec *FsEventCreate) SetUser(u *User) *FsEventCreate {
|
|
return fec.SetUserID(u.ID)
|
|
}
|
|
|
|
// Mutation returns the FsEventMutation object of the builder.
|
|
func (fec *FsEventCreate) Mutation() *FsEventMutation {
|
|
return fec.mutation
|
|
}
|
|
|
|
// Save creates the FsEvent in the database.
|
|
func (fec *FsEventCreate) Save(ctx context.Context) (*FsEvent, error) {
|
|
if err := fec.defaults(); err != nil {
|
|
return nil, err
|
|
}
|
|
return withHooks(ctx, fec.sqlSave, fec.mutation, fec.hooks)
|
|
}
|
|
|
|
// SaveX calls Save and panics if Save returns an error.
|
|
func (fec *FsEventCreate) SaveX(ctx context.Context) *FsEvent {
|
|
v, err := fec.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (fec *FsEventCreate) Exec(ctx context.Context) error {
|
|
_, err := fec.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (fec *FsEventCreate) ExecX(ctx context.Context) {
|
|
if err := fec.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// defaults sets the default values of the builder before save.
|
|
func (fec *FsEventCreate) defaults() error {
|
|
if _, ok := fec.mutation.CreatedAt(); !ok {
|
|
if fsevent.DefaultCreatedAt == nil {
|
|
return fmt.Errorf("ent: uninitialized fsevent.DefaultCreatedAt (forgotten import ent/runtime?)")
|
|
}
|
|
v := fsevent.DefaultCreatedAt()
|
|
fec.mutation.SetCreatedAt(v)
|
|
}
|
|
if _, ok := fec.mutation.UpdatedAt(); !ok {
|
|
if fsevent.DefaultUpdatedAt == nil {
|
|
return fmt.Errorf("ent: uninitialized fsevent.DefaultUpdatedAt (forgotten import ent/runtime?)")
|
|
}
|
|
v := fsevent.DefaultUpdatedAt()
|
|
fec.mutation.SetUpdatedAt(v)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (fec *FsEventCreate) check() error {
|
|
if _, ok := fec.mutation.CreatedAt(); !ok {
|
|
return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "FsEvent.created_at"`)}
|
|
}
|
|
if _, ok := fec.mutation.UpdatedAt(); !ok {
|
|
return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "FsEvent.updated_at"`)}
|
|
}
|
|
if _, ok := fec.mutation.Event(); !ok {
|
|
return &ValidationError{Name: "event", err: errors.New(`ent: missing required field "FsEvent.event"`)}
|
|
}
|
|
if _, ok := fec.mutation.Subscriber(); !ok {
|
|
return &ValidationError{Name: "subscriber", err: errors.New(`ent: missing required field "FsEvent.subscriber"`)}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (fec *FsEventCreate) sqlSave(ctx context.Context) (*FsEvent, error) {
|
|
if err := fec.check(); err != nil {
|
|
return nil, err
|
|
}
|
|
_node, _spec := fec.createSpec()
|
|
if err := sqlgraph.CreateNode(ctx, fec.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)
|
|
fec.mutation.id = &_node.ID
|
|
fec.mutation.done = true
|
|
return _node, nil
|
|
}
|
|
|
|
func (fec *FsEventCreate) createSpec() (*FsEvent, *sqlgraph.CreateSpec) {
|
|
var (
|
|
_node = &FsEvent{config: fec.config}
|
|
_spec = sqlgraph.NewCreateSpec(fsevent.Table, sqlgraph.NewFieldSpec(fsevent.FieldID, field.TypeInt))
|
|
)
|
|
|
|
if id, ok := fec.mutation.ID(); ok {
|
|
_node.ID = id
|
|
id64 := int64(id)
|
|
_spec.ID.Value = id64
|
|
}
|
|
|
|
_spec.OnConflict = fec.conflict
|
|
if value, ok := fec.mutation.CreatedAt(); ok {
|
|
_spec.SetField(fsevent.FieldCreatedAt, field.TypeTime, value)
|
|
_node.CreatedAt = value
|
|
}
|
|
if value, ok := fec.mutation.UpdatedAt(); ok {
|
|
_spec.SetField(fsevent.FieldUpdatedAt, field.TypeTime, value)
|
|
_node.UpdatedAt = value
|
|
}
|
|
if value, ok := fec.mutation.DeletedAt(); ok {
|
|
_spec.SetField(fsevent.FieldDeletedAt, field.TypeTime, value)
|
|
_node.DeletedAt = &value
|
|
}
|
|
if value, ok := fec.mutation.Event(); ok {
|
|
_spec.SetField(fsevent.FieldEvent, field.TypeString, value)
|
|
_node.Event = value
|
|
}
|
|
if value, ok := fec.mutation.Subscriber(); ok {
|
|
_spec.SetField(fsevent.FieldSubscriber, field.TypeUUID, value)
|
|
_node.Subscriber = value
|
|
}
|
|
if nodes := fec.mutation.UserIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: fsevent.UserTable,
|
|
Columns: []string{fsevent.UserColumn},
|
|
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.UserFsevent = 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.FsEvent.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.FsEventUpsert) {
|
|
// SetCreatedAt(v+v).
|
|
// }).
|
|
// Exec(ctx)
|
|
func (fec *FsEventCreate) OnConflict(opts ...sql.ConflictOption) *FsEventUpsertOne {
|
|
fec.conflict = opts
|
|
return &FsEventUpsertOne{
|
|
create: fec,
|
|
}
|
|
}
|
|
|
|
// OnConflictColumns calls `OnConflict` and configures the columns
|
|
// as conflict target. Using this option is equivalent to using:
|
|
//
|
|
// client.FsEvent.Create().
|
|
// OnConflict(sql.ConflictColumns(columns...)).
|
|
// Exec(ctx)
|
|
func (fec *FsEventCreate) OnConflictColumns(columns ...string) *FsEventUpsertOne {
|
|
fec.conflict = append(fec.conflict, sql.ConflictColumns(columns...))
|
|
return &FsEventUpsertOne{
|
|
create: fec,
|
|
}
|
|
}
|
|
|
|
type (
|
|
// FsEventUpsertOne is the builder for "upsert"-ing
|
|
// one FsEvent node.
|
|
FsEventUpsertOne struct {
|
|
create *FsEventCreate
|
|
}
|
|
|
|
// FsEventUpsert is the "OnConflict" setter.
|
|
FsEventUpsert struct {
|
|
*sql.UpdateSet
|
|
}
|
|
)
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (u *FsEventUpsert) SetUpdatedAt(v time.Time) *FsEventUpsert {
|
|
u.Set(fsevent.FieldUpdatedAt, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
|
|
func (u *FsEventUpsert) UpdateUpdatedAt() *FsEventUpsert {
|
|
u.SetExcluded(fsevent.FieldUpdatedAt)
|
|
return u
|
|
}
|
|
|
|
// SetDeletedAt sets the "deleted_at" field.
|
|
func (u *FsEventUpsert) SetDeletedAt(v time.Time) *FsEventUpsert {
|
|
u.Set(fsevent.FieldDeletedAt, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
|
|
func (u *FsEventUpsert) UpdateDeletedAt() *FsEventUpsert {
|
|
u.SetExcluded(fsevent.FieldDeletedAt)
|
|
return u
|
|
}
|
|
|
|
// ClearDeletedAt clears the value of the "deleted_at" field.
|
|
func (u *FsEventUpsert) ClearDeletedAt() *FsEventUpsert {
|
|
u.SetNull(fsevent.FieldDeletedAt)
|
|
return u
|
|
}
|
|
|
|
// SetEvent sets the "event" field.
|
|
func (u *FsEventUpsert) SetEvent(v string) *FsEventUpsert {
|
|
u.Set(fsevent.FieldEvent, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateEvent sets the "event" field to the value that was provided on create.
|
|
func (u *FsEventUpsert) UpdateEvent() *FsEventUpsert {
|
|
u.SetExcluded(fsevent.FieldEvent)
|
|
return u
|
|
}
|
|
|
|
// SetSubscriber sets the "subscriber" field.
|
|
func (u *FsEventUpsert) SetSubscriber(v uuid.UUID) *FsEventUpsert {
|
|
u.Set(fsevent.FieldSubscriber, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateSubscriber sets the "subscriber" field to the value that was provided on create.
|
|
func (u *FsEventUpsert) UpdateSubscriber() *FsEventUpsert {
|
|
u.SetExcluded(fsevent.FieldSubscriber)
|
|
return u
|
|
}
|
|
|
|
// SetUserFsevent sets the "user_fsevent" field.
|
|
func (u *FsEventUpsert) SetUserFsevent(v int) *FsEventUpsert {
|
|
u.Set(fsevent.FieldUserFsevent, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateUserFsevent sets the "user_fsevent" field to the value that was provided on create.
|
|
func (u *FsEventUpsert) UpdateUserFsevent() *FsEventUpsert {
|
|
u.SetExcluded(fsevent.FieldUserFsevent)
|
|
return u
|
|
}
|
|
|
|
// ClearUserFsevent clears the value of the "user_fsevent" field.
|
|
func (u *FsEventUpsert) ClearUserFsevent() *FsEventUpsert {
|
|
u.SetNull(fsevent.FieldUserFsevent)
|
|
return u
|
|
}
|
|
|
|
// UpdateNewValues updates the mutable fields using the new values that were set on create.
|
|
// Using this option is equivalent to using:
|
|
//
|
|
// client.FsEvent.Create().
|
|
// OnConflict(
|
|
// sql.ResolveWithNewValues(),
|
|
// ).
|
|
// Exec(ctx)
|
|
func (u *FsEventUpsertOne) UpdateNewValues() *FsEventUpsertOne {
|
|
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(fsevent.FieldCreatedAt)
|
|
}
|
|
}))
|
|
return u
|
|
}
|
|
|
|
// Ignore sets each column to itself in case of conflict.
|
|
// Using this option is equivalent to using:
|
|
//
|
|
// client.FsEvent.Create().
|
|
// OnConflict(sql.ResolveWithIgnore()).
|
|
// Exec(ctx)
|
|
func (u *FsEventUpsertOne) Ignore() *FsEventUpsertOne {
|
|
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 *FsEventUpsertOne) DoNothing() *FsEventUpsertOne {
|
|
u.create.conflict = append(u.create.conflict, sql.DoNothing())
|
|
return u
|
|
}
|
|
|
|
// Update allows overriding fields `UPDATE` values. See the FsEventCreate.OnConflict
|
|
// documentation for more info.
|
|
func (u *FsEventUpsertOne) Update(set func(*FsEventUpsert)) *FsEventUpsertOne {
|
|
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
|
|
set(&FsEventUpsert{UpdateSet: update})
|
|
}))
|
|
return u
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (u *FsEventUpsertOne) SetUpdatedAt(v time.Time) *FsEventUpsertOne {
|
|
return u.Update(func(s *FsEventUpsert) {
|
|
s.SetUpdatedAt(v)
|
|
})
|
|
}
|
|
|
|
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
|
|
func (u *FsEventUpsertOne) UpdateUpdatedAt() *FsEventUpsertOne {
|
|
return u.Update(func(s *FsEventUpsert) {
|
|
s.UpdateUpdatedAt()
|
|
})
|
|
}
|
|
|
|
// SetDeletedAt sets the "deleted_at" field.
|
|
func (u *FsEventUpsertOne) SetDeletedAt(v time.Time) *FsEventUpsertOne {
|
|
return u.Update(func(s *FsEventUpsert) {
|
|
s.SetDeletedAt(v)
|
|
})
|
|
}
|
|
|
|
// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
|
|
func (u *FsEventUpsertOne) UpdateDeletedAt() *FsEventUpsertOne {
|
|
return u.Update(func(s *FsEventUpsert) {
|
|
s.UpdateDeletedAt()
|
|
})
|
|
}
|
|
|
|
// ClearDeletedAt clears the value of the "deleted_at" field.
|
|
func (u *FsEventUpsertOne) ClearDeletedAt() *FsEventUpsertOne {
|
|
return u.Update(func(s *FsEventUpsert) {
|
|
s.ClearDeletedAt()
|
|
})
|
|
}
|
|
|
|
// SetEvent sets the "event" field.
|
|
func (u *FsEventUpsertOne) SetEvent(v string) *FsEventUpsertOne {
|
|
return u.Update(func(s *FsEventUpsert) {
|
|
s.SetEvent(v)
|
|
})
|
|
}
|
|
|
|
// UpdateEvent sets the "event" field to the value that was provided on create.
|
|
func (u *FsEventUpsertOne) UpdateEvent() *FsEventUpsertOne {
|
|
return u.Update(func(s *FsEventUpsert) {
|
|
s.UpdateEvent()
|
|
})
|
|
}
|
|
|
|
// SetSubscriber sets the "subscriber" field.
|
|
func (u *FsEventUpsertOne) SetSubscriber(v uuid.UUID) *FsEventUpsertOne {
|
|
return u.Update(func(s *FsEventUpsert) {
|
|
s.SetSubscriber(v)
|
|
})
|
|
}
|
|
|
|
// UpdateSubscriber sets the "subscriber" field to the value that was provided on create.
|
|
func (u *FsEventUpsertOne) UpdateSubscriber() *FsEventUpsertOne {
|
|
return u.Update(func(s *FsEventUpsert) {
|
|
s.UpdateSubscriber()
|
|
})
|
|
}
|
|
|
|
// SetUserFsevent sets the "user_fsevent" field.
|
|
func (u *FsEventUpsertOne) SetUserFsevent(v int) *FsEventUpsertOne {
|
|
return u.Update(func(s *FsEventUpsert) {
|
|
s.SetUserFsevent(v)
|
|
})
|
|
}
|
|
|
|
// UpdateUserFsevent sets the "user_fsevent" field to the value that was provided on create.
|
|
func (u *FsEventUpsertOne) UpdateUserFsevent() *FsEventUpsertOne {
|
|
return u.Update(func(s *FsEventUpsert) {
|
|
s.UpdateUserFsevent()
|
|
})
|
|
}
|
|
|
|
// ClearUserFsevent clears the value of the "user_fsevent" field.
|
|
func (u *FsEventUpsertOne) ClearUserFsevent() *FsEventUpsertOne {
|
|
return u.Update(func(s *FsEventUpsert) {
|
|
s.ClearUserFsevent()
|
|
})
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (u *FsEventUpsertOne) Exec(ctx context.Context) error {
|
|
if len(u.create.conflict) == 0 {
|
|
return errors.New("ent: missing options for FsEventCreate.OnConflict")
|
|
}
|
|
return u.create.Exec(ctx)
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (u *FsEventUpsertOne) 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 *FsEventUpsertOne) 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 *FsEventUpsertOne) IDX(ctx context.Context) int {
|
|
id, err := u.ID(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return id
|
|
}
|
|
|
|
func (m *FsEventCreate) SetRawID(t int) *FsEventCreate {
|
|
m.mutation.SetRawID(t)
|
|
return m
|
|
}
|
|
|
|
// FsEventCreateBulk is the builder for creating many FsEvent entities in bulk.
|
|
type FsEventCreateBulk struct {
|
|
config
|
|
err error
|
|
builders []*FsEventCreate
|
|
conflict []sql.ConflictOption
|
|
}
|
|
|
|
// Save creates the FsEvent entities in the database.
|
|
func (fecb *FsEventCreateBulk) Save(ctx context.Context) ([]*FsEvent, error) {
|
|
if fecb.err != nil {
|
|
return nil, fecb.err
|
|
}
|
|
specs := make([]*sqlgraph.CreateSpec, len(fecb.builders))
|
|
nodes := make([]*FsEvent, len(fecb.builders))
|
|
mutators := make([]Mutator, len(fecb.builders))
|
|
for i := range fecb.builders {
|
|
func(i int, root context.Context) {
|
|
builder := fecb.builders[i]
|
|
builder.defaults()
|
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
|
mutation, ok := m.(*FsEventMutation)
|
|
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, fecb.builders[i+1].mutation)
|
|
} else {
|
|
spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
|
|
spec.OnConflict = fecb.conflict
|
|
// Invoke the actual operation on the latest mutation in the chain.
|
|
if err = sqlgraph.BatchCreate(ctx, fecb.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, fecb.builders[0].mutation); err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
return nodes, nil
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (fecb *FsEventCreateBulk) SaveX(ctx context.Context) []*FsEvent {
|
|
v, err := fecb.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (fecb *FsEventCreateBulk) Exec(ctx context.Context) error {
|
|
_, err := fecb.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (fecb *FsEventCreateBulk) ExecX(ctx context.Context) {
|
|
if err := fecb.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
|
|
// of the `INSERT` statement. For example:
|
|
//
|
|
// client.FsEvent.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.FsEventUpsert) {
|
|
// SetCreatedAt(v+v).
|
|
// }).
|
|
// Exec(ctx)
|
|
func (fecb *FsEventCreateBulk) OnConflict(opts ...sql.ConflictOption) *FsEventUpsertBulk {
|
|
fecb.conflict = opts
|
|
return &FsEventUpsertBulk{
|
|
create: fecb,
|
|
}
|
|
}
|
|
|
|
// OnConflictColumns calls `OnConflict` and configures the columns
|
|
// as conflict target. Using this option is equivalent to using:
|
|
//
|
|
// client.FsEvent.Create().
|
|
// OnConflict(sql.ConflictColumns(columns...)).
|
|
// Exec(ctx)
|
|
func (fecb *FsEventCreateBulk) OnConflictColumns(columns ...string) *FsEventUpsertBulk {
|
|
fecb.conflict = append(fecb.conflict, sql.ConflictColumns(columns...))
|
|
return &FsEventUpsertBulk{
|
|
create: fecb,
|
|
}
|
|
}
|
|
|
|
// FsEventUpsertBulk is the builder for "upsert"-ing
|
|
// a bulk of FsEvent nodes.
|
|
type FsEventUpsertBulk struct {
|
|
create *FsEventCreateBulk
|
|
}
|
|
|
|
// UpdateNewValues updates the mutable fields using the new values that
|
|
// were set on create. Using this option is equivalent to using:
|
|
//
|
|
// client.FsEvent.Create().
|
|
// OnConflict(
|
|
// sql.ResolveWithNewValues(),
|
|
// ).
|
|
// Exec(ctx)
|
|
func (u *FsEventUpsertBulk) UpdateNewValues() *FsEventUpsertBulk {
|
|
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(fsevent.FieldCreatedAt)
|
|
}
|
|
}
|
|
}))
|
|
return u
|
|
}
|
|
|
|
// Ignore sets each column to itself in case of conflict.
|
|
// Using this option is equivalent to using:
|
|
//
|
|
// client.FsEvent.Create().
|
|
// OnConflict(sql.ResolveWithIgnore()).
|
|
// Exec(ctx)
|
|
func (u *FsEventUpsertBulk) Ignore() *FsEventUpsertBulk {
|
|
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 *FsEventUpsertBulk) DoNothing() *FsEventUpsertBulk {
|
|
u.create.conflict = append(u.create.conflict, sql.DoNothing())
|
|
return u
|
|
}
|
|
|
|
// Update allows overriding fields `UPDATE` values. See the FsEventCreateBulk.OnConflict
|
|
// documentation for more info.
|
|
func (u *FsEventUpsertBulk) Update(set func(*FsEventUpsert)) *FsEventUpsertBulk {
|
|
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
|
|
set(&FsEventUpsert{UpdateSet: update})
|
|
}))
|
|
return u
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (u *FsEventUpsertBulk) SetUpdatedAt(v time.Time) *FsEventUpsertBulk {
|
|
return u.Update(func(s *FsEventUpsert) {
|
|
s.SetUpdatedAt(v)
|
|
})
|
|
}
|
|
|
|
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
|
|
func (u *FsEventUpsertBulk) UpdateUpdatedAt() *FsEventUpsertBulk {
|
|
return u.Update(func(s *FsEventUpsert) {
|
|
s.UpdateUpdatedAt()
|
|
})
|
|
}
|
|
|
|
// SetDeletedAt sets the "deleted_at" field.
|
|
func (u *FsEventUpsertBulk) SetDeletedAt(v time.Time) *FsEventUpsertBulk {
|
|
return u.Update(func(s *FsEventUpsert) {
|
|
s.SetDeletedAt(v)
|
|
})
|
|
}
|
|
|
|
// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
|
|
func (u *FsEventUpsertBulk) UpdateDeletedAt() *FsEventUpsertBulk {
|
|
return u.Update(func(s *FsEventUpsert) {
|
|
s.UpdateDeletedAt()
|
|
})
|
|
}
|
|
|
|
// ClearDeletedAt clears the value of the "deleted_at" field.
|
|
func (u *FsEventUpsertBulk) ClearDeletedAt() *FsEventUpsertBulk {
|
|
return u.Update(func(s *FsEventUpsert) {
|
|
s.ClearDeletedAt()
|
|
})
|
|
}
|
|
|
|
// SetEvent sets the "event" field.
|
|
func (u *FsEventUpsertBulk) SetEvent(v string) *FsEventUpsertBulk {
|
|
return u.Update(func(s *FsEventUpsert) {
|
|
s.SetEvent(v)
|
|
})
|
|
}
|
|
|
|
// UpdateEvent sets the "event" field to the value that was provided on create.
|
|
func (u *FsEventUpsertBulk) UpdateEvent() *FsEventUpsertBulk {
|
|
return u.Update(func(s *FsEventUpsert) {
|
|
s.UpdateEvent()
|
|
})
|
|
}
|
|
|
|
// SetSubscriber sets the "subscriber" field.
|
|
func (u *FsEventUpsertBulk) SetSubscriber(v uuid.UUID) *FsEventUpsertBulk {
|
|
return u.Update(func(s *FsEventUpsert) {
|
|
s.SetSubscriber(v)
|
|
})
|
|
}
|
|
|
|
// UpdateSubscriber sets the "subscriber" field to the value that was provided on create.
|
|
func (u *FsEventUpsertBulk) UpdateSubscriber() *FsEventUpsertBulk {
|
|
return u.Update(func(s *FsEventUpsert) {
|
|
s.UpdateSubscriber()
|
|
})
|
|
}
|
|
|
|
// SetUserFsevent sets the "user_fsevent" field.
|
|
func (u *FsEventUpsertBulk) SetUserFsevent(v int) *FsEventUpsertBulk {
|
|
return u.Update(func(s *FsEventUpsert) {
|
|
s.SetUserFsevent(v)
|
|
})
|
|
}
|
|
|
|
// UpdateUserFsevent sets the "user_fsevent" field to the value that was provided on create.
|
|
func (u *FsEventUpsertBulk) UpdateUserFsevent() *FsEventUpsertBulk {
|
|
return u.Update(func(s *FsEventUpsert) {
|
|
s.UpdateUserFsevent()
|
|
})
|
|
}
|
|
|
|
// ClearUserFsevent clears the value of the "user_fsevent" field.
|
|
func (u *FsEventUpsertBulk) ClearUserFsevent() *FsEventUpsertBulk {
|
|
return u.Update(func(s *FsEventUpsert) {
|
|
s.ClearUserFsevent()
|
|
})
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (u *FsEventUpsertBulk) 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 FsEventCreateBulk instead", i)
|
|
}
|
|
}
|
|
if len(u.create.conflict) == 0 {
|
|
return errors.New("ent: missing options for FsEventCreateBulk.OnConflict")
|
|
}
|
|
return u.create.Exec(ctx)
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (u *FsEventUpsertBulk) ExecX(ctx context.Context) {
|
|
if err := u.create.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|