// Code generated by ent, DO NOT EDIT. package ent import ( "context" "errors" "fmt" "mingyang-admin-pay/rpc/ent/paynotifylog" "mingyang-admin-pay/rpc/ent/paynotifytask" "time" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" ) // PayNotifyLogCreate is the builder for creating a PayNotifyLog entity. type PayNotifyLogCreate struct { config mutation *PayNotifyLogMutation hooks []Hook } // SetCreatedAt sets the "created_at" field. func (_c *PayNotifyLogCreate) SetCreatedAt(v time.Time) *PayNotifyLogCreate { _c.mutation.SetCreatedAt(v) return _c } // SetNillableCreatedAt sets the "created_at" field if the given value is not nil. func (_c *PayNotifyLogCreate) SetNillableCreatedAt(v *time.Time) *PayNotifyLogCreate { if v != nil { _c.SetCreatedAt(*v) } return _c } // SetUpdatedAt sets the "updated_at" field. func (_c *PayNotifyLogCreate) SetUpdatedAt(v time.Time) *PayNotifyLogCreate { _c.mutation.SetUpdatedAt(v) return _c } // SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. func (_c *PayNotifyLogCreate) SetNillableUpdatedAt(v *time.Time) *PayNotifyLogCreate { if v != nil { _c.SetUpdatedAt(*v) } return _c } // SetStatus sets the "status" field. func (_c *PayNotifyLogCreate) SetStatus(v uint8) *PayNotifyLogCreate { _c.mutation.SetStatus(v) return _c } // SetNillableStatus sets the "status" field if the given value is not nil. func (_c *PayNotifyLogCreate) SetNillableStatus(v *uint8) *PayNotifyLogCreate { if v != nil { _c.SetStatus(*v) } return _c } // SetTenantID sets the "tenant_id" field. func (_c *PayNotifyLogCreate) SetTenantID(v uint64) *PayNotifyLogCreate { _c.mutation.SetTenantID(v) return _c } // SetNillableTenantID sets the "tenant_id" field if the given value is not nil. func (_c *PayNotifyLogCreate) SetNillableTenantID(v *uint64) *PayNotifyLogCreate { if v != nil { _c.SetTenantID(*v) } return _c } // SetDeletedAt sets the "deleted_at" field. func (_c *PayNotifyLogCreate) SetDeletedAt(v time.Time) *PayNotifyLogCreate { _c.mutation.SetDeletedAt(v) return _c } // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil. func (_c *PayNotifyLogCreate) SetNillableDeletedAt(v *time.Time) *PayNotifyLogCreate { if v != nil { _c.SetDeletedAt(*v) } return _c } // SetTaskID sets the "task_id" field. func (_c *PayNotifyLogCreate) SetTaskID(v uint64) *PayNotifyLogCreate { _c.mutation.SetTaskID(v) return _c } // SetNotifyCount sets the "notify_count" field. func (_c *PayNotifyLogCreate) SetNotifyCount(v uint32) *PayNotifyLogCreate { _c.mutation.SetNotifyCount(v) return _c } // SetNillableNotifyCount sets the "notify_count" field if the given value is not nil. func (_c *PayNotifyLogCreate) SetNillableNotifyCount(v *uint32) *PayNotifyLogCreate { if v != nil { _c.SetNotifyCount(*v) } return _c } // SetResponse sets the "response" field. func (_c *PayNotifyLogCreate) SetResponse(v string) *PayNotifyLogCreate { _c.mutation.SetResponse(v) return _c } // SetNillableResponse sets the "response" field if the given value is not nil. func (_c *PayNotifyLogCreate) SetNillableResponse(v *string) *PayNotifyLogCreate { if v != nil { _c.SetResponse(*v) } return _c } // SetNotifyStatus sets the "notify_status" field. func (_c *PayNotifyLogCreate) SetNotifyStatus(v string) *PayNotifyLogCreate { _c.mutation.SetNotifyStatus(v) return _c } // SetNillableNotifyStatus sets the "notify_status" field if the given value is not nil. func (_c *PayNotifyLogCreate) SetNillableNotifyStatus(v *string) *PayNotifyLogCreate { if v != nil { _c.SetNotifyStatus(*v) } return _c } // SetID sets the "id" field. func (_c *PayNotifyLogCreate) SetID(v uint64) *PayNotifyLogCreate { _c.mutation.SetID(v) return _c } // SetTask sets the "task" edge to the PayNotifyTask entity. func (_c *PayNotifyLogCreate) SetTask(v *PayNotifyTask) *PayNotifyLogCreate { return _c.SetTaskID(v.ID) } // Mutation returns the PayNotifyLogMutation object of the builder. func (_c *PayNotifyLogCreate) Mutation() *PayNotifyLogMutation { return _c.mutation } // Save creates the PayNotifyLog in the database. func (_c *PayNotifyLogCreate) Save(ctx context.Context) (*PayNotifyLog, error) { _c.defaults() return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks) } // SaveX calls Save and panics if Save returns an error. func (_c *PayNotifyLogCreate) SaveX(ctx context.Context) *PayNotifyLog { v, err := _c.Save(ctx) if err != nil { panic(err) } return v } // Exec executes the query. func (_c *PayNotifyLogCreate) Exec(ctx context.Context) error { _, err := _c.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (_c *PayNotifyLogCreate) 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 *PayNotifyLogCreate) defaults() { if _, ok := _c.mutation.CreatedAt(); !ok { v := paynotifylog.DefaultCreatedAt() _c.mutation.SetCreatedAt(v) } if _, ok := _c.mutation.UpdatedAt(); !ok { v := paynotifylog.DefaultUpdatedAt() _c.mutation.SetUpdatedAt(v) } if _, ok := _c.mutation.Status(); !ok { v := paynotifylog.DefaultStatus _c.mutation.SetStatus(v) } if _, ok := _c.mutation.TenantID(); !ok { v := paynotifylog.DefaultTenantID _c.mutation.SetTenantID(v) } if _, ok := _c.mutation.NotifyCount(); !ok { v := paynotifylog.DefaultNotifyCount _c.mutation.SetNotifyCount(v) } } // check runs all checks and user-defined validators on the builder. func (_c *PayNotifyLogCreate) check() error { if _, ok := _c.mutation.CreatedAt(); !ok { return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "PayNotifyLog.created_at"`)} } if _, ok := _c.mutation.UpdatedAt(); !ok { return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "PayNotifyLog.updated_at"`)} } if _, ok := _c.mutation.TenantID(); !ok { return &ValidationError{Name: "tenant_id", err: errors.New(`ent: missing required field "PayNotifyLog.tenant_id"`)} } if _, ok := _c.mutation.TaskID(); !ok { return &ValidationError{Name: "task_id", err: errors.New(`ent: missing required field "PayNotifyLog.task_id"`)} } if _, ok := _c.mutation.NotifyCount(); !ok { return &ValidationError{Name: "notify_count", err: errors.New(`ent: missing required field "PayNotifyLog.notify_count"`)} } if len(_c.mutation.TaskIDs()) == 0 { return &ValidationError{Name: "task", err: errors.New(`ent: missing required edge "PayNotifyLog.task"`)} } return nil } func (_c *PayNotifyLogCreate) sqlSave(ctx context.Context) (*PayNotifyLog, 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 } if _spec.ID.Value != _node.ID { id := _spec.ID.Value.(int64) _node.ID = uint64(id) } _c.mutation.id = &_node.ID _c.mutation.done = true return _node, nil } func (_c *PayNotifyLogCreate) createSpec() (*PayNotifyLog, *sqlgraph.CreateSpec) { var ( _node = &PayNotifyLog{config: _c.config} _spec = sqlgraph.NewCreateSpec(paynotifylog.Table, sqlgraph.NewFieldSpec(paynotifylog.FieldID, field.TypeUint64)) ) if id, ok := _c.mutation.ID(); ok { _node.ID = id _spec.ID.Value = id } if value, ok := _c.mutation.CreatedAt(); ok { _spec.SetField(paynotifylog.FieldCreatedAt, field.TypeTime, value) _node.CreatedAt = value } if value, ok := _c.mutation.UpdatedAt(); ok { _spec.SetField(paynotifylog.FieldUpdatedAt, field.TypeTime, value) _node.UpdatedAt = value } if value, ok := _c.mutation.Status(); ok { _spec.SetField(paynotifylog.FieldStatus, field.TypeUint8, value) _node.Status = value } if value, ok := _c.mutation.TenantID(); ok { _spec.SetField(paynotifylog.FieldTenantID, field.TypeUint64, value) _node.TenantID = value } if value, ok := _c.mutation.DeletedAt(); ok { _spec.SetField(paynotifylog.FieldDeletedAt, field.TypeTime, value) _node.DeletedAt = value } if value, ok := _c.mutation.NotifyCount(); ok { _spec.SetField(paynotifylog.FieldNotifyCount, field.TypeUint32, value) _node.NotifyCount = value } if value, ok := _c.mutation.Response(); ok { _spec.SetField(paynotifylog.FieldResponse, field.TypeString, value) _node.Response = value } if value, ok := _c.mutation.NotifyStatus(); ok { _spec.SetField(paynotifylog.FieldNotifyStatus, field.TypeString, value) _node.NotifyStatus = value } if nodes := _c.mutation.TaskIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, Inverse: false, Table: paynotifylog.TaskTable, Columns: []string{paynotifylog.TaskColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(paynotifytask.FieldID, field.TypeUint64), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } _node.TaskID = nodes[0] _spec.Edges = append(_spec.Edges, edge) } return _node, _spec } // PayNotifyLogCreateBulk is the builder for creating many PayNotifyLog entities in bulk. type PayNotifyLogCreateBulk struct { config err error builders []*PayNotifyLogCreate } // Save creates the PayNotifyLog entities in the database. func (_c *PayNotifyLogCreateBulk) Save(ctx context.Context) ([]*PayNotifyLog, error) { if _c.err != nil { return nil, _c.err } specs := make([]*sqlgraph.CreateSpec, len(_c.builders)) nodes := make([]*PayNotifyLog, 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.(*PayNotifyLogMutation) 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} // 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 && nodes[i].ID == 0 { id := specs[i].ID.Value.(int64) nodes[i].ID = uint64(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 *PayNotifyLogCreateBulk) SaveX(ctx context.Context) []*PayNotifyLog { v, err := _c.Save(ctx) if err != nil { panic(err) } return v } // Exec executes the query. func (_c *PayNotifyLogCreateBulk) Exec(ctx context.Context) error { _, err := _c.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (_c *PayNotifyLogCreateBulk) ExecX(ctx context.Context) { if err := _c.Exec(ctx); err != nil { panic(err) } }