// 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/Wei-Shaw/sub2api/ent/paymentauditlog" ) // PaymentAuditLogCreate is the builder for creating a PaymentAuditLog entity. type PaymentAuditLogCreate struct { config mutation *PaymentAuditLogMutation hooks []Hook conflict []sql.ConflictOption } // SetOrderID sets the "order_id" field. func (_c *PaymentAuditLogCreate) SetOrderID(v string) *PaymentAuditLogCreate { _c.mutation.SetOrderID(v) return _c } // SetAction sets the "action" field. func (_c *PaymentAuditLogCreate) SetAction(v string) *PaymentAuditLogCreate { _c.mutation.SetAction(v) return _c } // SetDetail sets the "detail" field. func (_c *PaymentAuditLogCreate) SetDetail(v string) *PaymentAuditLogCreate { _c.mutation.SetDetail(v) return _c } // SetNillableDetail sets the "detail" field if the given value is not nil. func (_c *PaymentAuditLogCreate) SetNillableDetail(v *string) *PaymentAuditLogCreate { if v != nil { _c.SetDetail(*v) } return _c } // SetOperator sets the "operator" field. func (_c *PaymentAuditLogCreate) SetOperator(v string) *PaymentAuditLogCreate { _c.mutation.SetOperator(v) return _c } // SetNillableOperator sets the "operator" field if the given value is not nil. func (_c *PaymentAuditLogCreate) SetNillableOperator(v *string) *PaymentAuditLogCreate { if v != nil { _c.SetOperator(*v) } return _c } // SetCreatedAt sets the "created_at" field. func (_c *PaymentAuditLogCreate) SetCreatedAt(v time.Time) *PaymentAuditLogCreate { _c.mutation.SetCreatedAt(v) return _c } // SetNillableCreatedAt sets the "created_at" field if the given value is not nil. func (_c *PaymentAuditLogCreate) SetNillableCreatedAt(v *time.Time) *PaymentAuditLogCreate { if v != nil { _c.SetCreatedAt(*v) } return _c } // Mutation returns the PaymentAuditLogMutation object of the builder. func (_c *PaymentAuditLogCreate) Mutation() *PaymentAuditLogMutation { return _c.mutation } // Save creates the PaymentAuditLog in the database. func (_c *PaymentAuditLogCreate) Save(ctx context.Context) (*PaymentAuditLog, error) { _c.defaults() return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks) } // SaveX calls Save and panics if Save returns an error. func (_c *PaymentAuditLogCreate) SaveX(ctx context.Context) *PaymentAuditLog { v, err := _c.Save(ctx) if err != nil { panic(err) } return v } // Exec executes the query. func (_c *PaymentAuditLogCreate) Exec(ctx context.Context) error { _, err := _c.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (_c *PaymentAuditLogCreate) 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 *PaymentAuditLogCreate) defaults() { if _, ok := _c.mutation.Detail(); !ok { v := paymentauditlog.DefaultDetail _c.mutation.SetDetail(v) } if _, ok := _c.mutation.Operator(); !ok { v := paymentauditlog.DefaultOperator _c.mutation.SetOperator(v) } if _, ok := _c.mutation.CreatedAt(); !ok { v := paymentauditlog.DefaultCreatedAt() _c.mutation.SetCreatedAt(v) } } // check runs all checks and user-defined validators on the builder. func (_c *PaymentAuditLogCreate) check() error { if _, ok := _c.mutation.OrderID(); !ok { return &ValidationError{Name: "order_id", err: errors.New(`ent: missing required field "PaymentAuditLog.order_id"`)} } if v, ok := _c.mutation.OrderID(); ok { if err := paymentauditlog.OrderIDValidator(v); err != nil { return &ValidationError{Name: "order_id", err: fmt.Errorf(`ent: validator failed for field "PaymentAuditLog.order_id": %w`, err)} } } if _, ok := _c.mutation.Action(); !ok { return &ValidationError{Name: "action", err: errors.New(`ent: missing required field "PaymentAuditLog.action"`)} } if v, ok := _c.mutation.Action(); ok { if err := paymentauditlog.ActionValidator(v); err != nil { return &ValidationError{Name: "action", err: fmt.Errorf(`ent: validator failed for field "PaymentAuditLog.action": %w`, err)} } } if _, ok := _c.mutation.Detail(); !ok { return &ValidationError{Name: "detail", err: errors.New(`ent: missing required field "PaymentAuditLog.detail"`)} } if _, ok := _c.mutation.Operator(); !ok { return &ValidationError{Name: "operator", err: errors.New(`ent: missing required field "PaymentAuditLog.operator"`)} } if v, ok := _c.mutation.Operator(); ok { if err := paymentauditlog.OperatorValidator(v); err != nil { return &ValidationError{Name: "operator", err: fmt.Errorf(`ent: validator failed for field "PaymentAuditLog.operator": %w`, err)} } } if _, ok := _c.mutation.CreatedAt(); !ok { return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "PaymentAuditLog.created_at"`)} } return nil } func (_c *PaymentAuditLogCreate) sqlSave(ctx context.Context) (*PaymentAuditLog, 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 *PaymentAuditLogCreate) createSpec() (*PaymentAuditLog, *sqlgraph.CreateSpec) { var ( _node = &PaymentAuditLog{config: _c.config} _spec = sqlgraph.NewCreateSpec(paymentauditlog.Table, sqlgraph.NewFieldSpec(paymentauditlog.FieldID, field.TypeInt64)) ) _spec.OnConflict = _c.conflict if value, ok := _c.mutation.OrderID(); ok { _spec.SetField(paymentauditlog.FieldOrderID, field.TypeString, value) _node.OrderID = value } if value, ok := _c.mutation.Action(); ok { _spec.SetField(paymentauditlog.FieldAction, field.TypeString, value) _node.Action = value } if value, ok := _c.mutation.Detail(); ok { _spec.SetField(paymentauditlog.FieldDetail, field.TypeString, value) _node.Detail = value } if value, ok := _c.mutation.Operator(); ok { _spec.SetField(paymentauditlog.FieldOperator, field.TypeString, value) _node.Operator = value } if value, ok := _c.mutation.CreatedAt(); ok { _spec.SetField(paymentauditlog.FieldCreatedAt, field.TypeTime, value) _node.CreatedAt = value } return _node, _spec } // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause // of the `INSERT` statement. For example: // // client.PaymentAuditLog.Create(). // SetOrderID(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.PaymentAuditLogUpsert) { // SetOrderID(v+v). // }). // Exec(ctx) func (_c *PaymentAuditLogCreate) OnConflict(opts ...sql.ConflictOption) *PaymentAuditLogUpsertOne { _c.conflict = opts return &PaymentAuditLogUpsertOne{ create: _c, } } // OnConflictColumns calls `OnConflict` and configures the columns // as conflict target. Using this option is equivalent to using: // // client.PaymentAuditLog.Create(). // OnConflict(sql.ConflictColumns(columns...)). // Exec(ctx) func (_c *PaymentAuditLogCreate) OnConflictColumns(columns ...string) *PaymentAuditLogUpsertOne { _c.conflict = append(_c.conflict, sql.ConflictColumns(columns...)) return &PaymentAuditLogUpsertOne{ create: _c, } } type ( // PaymentAuditLogUpsertOne is the builder for "upsert"-ing // one PaymentAuditLog node. PaymentAuditLogUpsertOne struct { create *PaymentAuditLogCreate } // PaymentAuditLogUpsert is the "OnConflict" setter. PaymentAuditLogUpsert struct { *sql.UpdateSet } ) // SetOrderID sets the "order_id" field. func (u *PaymentAuditLogUpsert) SetOrderID(v string) *PaymentAuditLogUpsert { u.Set(paymentauditlog.FieldOrderID, v) return u } // UpdateOrderID sets the "order_id" field to the value that was provided on create. func (u *PaymentAuditLogUpsert) UpdateOrderID() *PaymentAuditLogUpsert { u.SetExcluded(paymentauditlog.FieldOrderID) return u } // SetAction sets the "action" field. func (u *PaymentAuditLogUpsert) SetAction(v string) *PaymentAuditLogUpsert { u.Set(paymentauditlog.FieldAction, v) return u } // UpdateAction sets the "action" field to the value that was provided on create. func (u *PaymentAuditLogUpsert) UpdateAction() *PaymentAuditLogUpsert { u.SetExcluded(paymentauditlog.FieldAction) return u } // SetDetail sets the "detail" field. func (u *PaymentAuditLogUpsert) SetDetail(v string) *PaymentAuditLogUpsert { u.Set(paymentauditlog.FieldDetail, v) return u } // UpdateDetail sets the "detail" field to the value that was provided on create. func (u *PaymentAuditLogUpsert) UpdateDetail() *PaymentAuditLogUpsert { u.SetExcluded(paymentauditlog.FieldDetail) return u } // SetOperator sets the "operator" field. func (u *PaymentAuditLogUpsert) SetOperator(v string) *PaymentAuditLogUpsert { u.Set(paymentauditlog.FieldOperator, v) return u } // UpdateOperator sets the "operator" field to the value that was provided on create. func (u *PaymentAuditLogUpsert) UpdateOperator() *PaymentAuditLogUpsert { u.SetExcluded(paymentauditlog.FieldOperator) return u } // UpdateNewValues updates the mutable fields using the new values that were set on create. // Using this option is equivalent to using: // // client.PaymentAuditLog.Create(). // OnConflict( // sql.ResolveWithNewValues(), // ). // Exec(ctx) func (u *PaymentAuditLogUpsertOne) UpdateNewValues() *PaymentAuditLogUpsertOne { 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(paymentauditlog.FieldCreatedAt) } })) return u } // Ignore sets each column to itself in case of conflict. // Using this option is equivalent to using: // // client.PaymentAuditLog.Create(). // OnConflict(sql.ResolveWithIgnore()). // Exec(ctx) func (u *PaymentAuditLogUpsertOne) Ignore() *PaymentAuditLogUpsertOne { 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 *PaymentAuditLogUpsertOne) DoNothing() *PaymentAuditLogUpsertOne { u.create.conflict = append(u.create.conflict, sql.DoNothing()) return u } // Update allows overriding fields `UPDATE` values. See the PaymentAuditLogCreate.OnConflict // documentation for more info. func (u *PaymentAuditLogUpsertOne) Update(set func(*PaymentAuditLogUpsert)) *PaymentAuditLogUpsertOne { u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) { set(&PaymentAuditLogUpsert{UpdateSet: update}) })) return u } // SetOrderID sets the "order_id" field. func (u *PaymentAuditLogUpsertOne) SetOrderID(v string) *PaymentAuditLogUpsertOne { return u.Update(func(s *PaymentAuditLogUpsert) { s.SetOrderID(v) }) } // UpdateOrderID sets the "order_id" field to the value that was provided on create. func (u *PaymentAuditLogUpsertOne) UpdateOrderID() *PaymentAuditLogUpsertOne { return u.Update(func(s *PaymentAuditLogUpsert) { s.UpdateOrderID() }) } // SetAction sets the "action" field. func (u *PaymentAuditLogUpsertOne) SetAction(v string) *PaymentAuditLogUpsertOne { return u.Update(func(s *PaymentAuditLogUpsert) { s.SetAction(v) }) } // UpdateAction sets the "action" field to the value that was provided on create. func (u *PaymentAuditLogUpsertOne) UpdateAction() *PaymentAuditLogUpsertOne { return u.Update(func(s *PaymentAuditLogUpsert) { s.UpdateAction() }) } // SetDetail sets the "detail" field. func (u *PaymentAuditLogUpsertOne) SetDetail(v string) *PaymentAuditLogUpsertOne { return u.Update(func(s *PaymentAuditLogUpsert) { s.SetDetail(v) }) } // UpdateDetail sets the "detail" field to the value that was provided on create. func (u *PaymentAuditLogUpsertOne) UpdateDetail() *PaymentAuditLogUpsertOne { return u.Update(func(s *PaymentAuditLogUpsert) { s.UpdateDetail() }) } // SetOperator sets the "operator" field. func (u *PaymentAuditLogUpsertOne) SetOperator(v string) *PaymentAuditLogUpsertOne { return u.Update(func(s *PaymentAuditLogUpsert) { s.SetOperator(v) }) } // UpdateOperator sets the "operator" field to the value that was provided on create. func (u *PaymentAuditLogUpsertOne) UpdateOperator() *PaymentAuditLogUpsertOne { return u.Update(func(s *PaymentAuditLogUpsert) { s.UpdateOperator() }) } // Exec executes the query. func (u *PaymentAuditLogUpsertOne) Exec(ctx context.Context) error { if len(u.create.conflict) == 0 { return errors.New("ent: missing options for PaymentAuditLogCreate.OnConflict") } return u.create.Exec(ctx) } // ExecX is like Exec, but panics if an error occurs. func (u *PaymentAuditLogUpsertOne) 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 *PaymentAuditLogUpsertOne) 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 *PaymentAuditLogUpsertOne) IDX(ctx context.Context) int64 { id, err := u.ID(ctx) if err != nil { panic(err) } return id } // PaymentAuditLogCreateBulk is the builder for creating many PaymentAuditLog entities in bulk. type PaymentAuditLogCreateBulk struct { config err error builders []*PaymentAuditLogCreate conflict []sql.ConflictOption } // Save creates the PaymentAuditLog entities in the database. func (_c *PaymentAuditLogCreateBulk) Save(ctx context.Context) ([]*PaymentAuditLog, error) { if _c.err != nil { return nil, _c.err } specs := make([]*sqlgraph.CreateSpec, len(_c.builders)) nodes := make([]*PaymentAuditLog, 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.(*PaymentAuditLogMutation) 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 *PaymentAuditLogCreateBulk) SaveX(ctx context.Context) []*PaymentAuditLog { v, err := _c.Save(ctx) if err != nil { panic(err) } return v } // Exec executes the query. func (_c *PaymentAuditLogCreateBulk) Exec(ctx context.Context) error { _, err := _c.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (_c *PaymentAuditLogCreateBulk) 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.PaymentAuditLog.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.PaymentAuditLogUpsert) { // SetOrderID(v+v). // }). // Exec(ctx) func (_c *PaymentAuditLogCreateBulk) OnConflict(opts ...sql.ConflictOption) *PaymentAuditLogUpsertBulk { _c.conflict = opts return &PaymentAuditLogUpsertBulk{ create: _c, } } // OnConflictColumns calls `OnConflict` and configures the columns // as conflict target. Using this option is equivalent to using: // // client.PaymentAuditLog.Create(). // OnConflict(sql.ConflictColumns(columns...)). // Exec(ctx) func (_c *PaymentAuditLogCreateBulk) OnConflictColumns(columns ...string) *PaymentAuditLogUpsertBulk { _c.conflict = append(_c.conflict, sql.ConflictColumns(columns...)) return &PaymentAuditLogUpsertBulk{ create: _c, } } // PaymentAuditLogUpsertBulk is the builder for "upsert"-ing // a bulk of PaymentAuditLog nodes. type PaymentAuditLogUpsertBulk struct { create *PaymentAuditLogCreateBulk } // UpdateNewValues updates the mutable fields using the new values that // were set on create. Using this option is equivalent to using: // // client.PaymentAuditLog.Create(). // OnConflict( // sql.ResolveWithNewValues(), // ). // Exec(ctx) func (u *PaymentAuditLogUpsertBulk) UpdateNewValues() *PaymentAuditLogUpsertBulk { 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(paymentauditlog.FieldCreatedAt) } } })) return u } // Ignore sets each column to itself in case of conflict. // Using this option is equivalent to using: // // client.PaymentAuditLog.Create(). // OnConflict(sql.ResolveWithIgnore()). // Exec(ctx) func (u *PaymentAuditLogUpsertBulk) Ignore() *PaymentAuditLogUpsertBulk { 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 *PaymentAuditLogUpsertBulk) DoNothing() *PaymentAuditLogUpsertBulk { u.create.conflict = append(u.create.conflict, sql.DoNothing()) return u } // Update allows overriding fields `UPDATE` values. See the PaymentAuditLogCreateBulk.OnConflict // documentation for more info. func (u *PaymentAuditLogUpsertBulk) Update(set func(*PaymentAuditLogUpsert)) *PaymentAuditLogUpsertBulk { u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) { set(&PaymentAuditLogUpsert{UpdateSet: update}) })) return u } // SetOrderID sets the "order_id" field. func (u *PaymentAuditLogUpsertBulk) SetOrderID(v string) *PaymentAuditLogUpsertBulk { return u.Update(func(s *PaymentAuditLogUpsert) { s.SetOrderID(v) }) } // UpdateOrderID sets the "order_id" field to the value that was provided on create. func (u *PaymentAuditLogUpsertBulk) UpdateOrderID() *PaymentAuditLogUpsertBulk { return u.Update(func(s *PaymentAuditLogUpsert) { s.UpdateOrderID() }) } // SetAction sets the "action" field. func (u *PaymentAuditLogUpsertBulk) SetAction(v string) *PaymentAuditLogUpsertBulk { return u.Update(func(s *PaymentAuditLogUpsert) { s.SetAction(v) }) } // UpdateAction sets the "action" field to the value that was provided on create. func (u *PaymentAuditLogUpsertBulk) UpdateAction() *PaymentAuditLogUpsertBulk { return u.Update(func(s *PaymentAuditLogUpsert) { s.UpdateAction() }) } // SetDetail sets the "detail" field. func (u *PaymentAuditLogUpsertBulk) SetDetail(v string) *PaymentAuditLogUpsertBulk { return u.Update(func(s *PaymentAuditLogUpsert) { s.SetDetail(v) }) } // UpdateDetail sets the "detail" field to the value that was provided on create. func (u *PaymentAuditLogUpsertBulk) UpdateDetail() *PaymentAuditLogUpsertBulk { return u.Update(func(s *PaymentAuditLogUpsert) { s.UpdateDetail() }) } // SetOperator sets the "operator" field. func (u *PaymentAuditLogUpsertBulk) SetOperator(v string) *PaymentAuditLogUpsertBulk { return u.Update(func(s *PaymentAuditLogUpsert) { s.SetOperator(v) }) } // UpdateOperator sets the "operator" field to the value that was provided on create. func (u *PaymentAuditLogUpsertBulk) UpdateOperator() *PaymentAuditLogUpsertBulk { return u.Update(func(s *PaymentAuditLogUpsert) { s.UpdateOperator() }) } // Exec executes the query. func (u *PaymentAuditLogUpsertBulk) 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 PaymentAuditLogCreateBulk instead", i) } } if len(u.create.conflict) == 0 { return errors.New("ent: missing options for PaymentAuditLogCreateBulk.OnConflict") } return u.create.Exec(ctx) } // ExecX is like Exec, but panics if an error occurs. func (u *PaymentAuditLogUpsertBulk) ExecX(ctx context.Context) { if err := u.create.Exec(ctx); err != nil { panic(err) } }