// Code generated by ent, DO NOT EDIT. package ent import ( "context" "errors" "fmt" "time" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" "github.com/suyuan32/simple-admin-job/ent/messagerecords" ) // MessageRecordsCreate is the builder for creating a MessageRecords entity. type MessageRecordsCreate struct { config mutation *MessageRecordsMutation hooks []Hook } // SetCreatedAt sets the "created_at" field. func (mrc *MessageRecordsCreate) SetCreatedAt(t time.Time) *MessageRecordsCreate { mrc.mutation.SetCreatedAt(t) return mrc } // SetNillableCreatedAt sets the "created_at" field if the given value is not nil. func (mrc *MessageRecordsCreate) SetNillableCreatedAt(t *time.Time) *MessageRecordsCreate { if t != nil { mrc.SetCreatedAt(*t) } return mrc } // SetUpdatedAt sets the "updated_at" field. func (mrc *MessageRecordsCreate) SetUpdatedAt(t time.Time) *MessageRecordsCreate { mrc.mutation.SetUpdatedAt(t) return mrc } // SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. func (mrc *MessageRecordsCreate) SetNillableUpdatedAt(t *time.Time) *MessageRecordsCreate { if t != nil { mrc.SetUpdatedAt(*t) } return mrc } // SetStatus sets the "status" field. func (mrc *MessageRecordsCreate) SetStatus(u uint8) *MessageRecordsCreate { mrc.mutation.SetStatus(u) return mrc } // SetNillableStatus sets the "status" field if the given value is not nil. func (mrc *MessageRecordsCreate) SetNillableStatus(u *uint8) *MessageRecordsCreate { if u != nil { mrc.SetStatus(*u) } return mrc } // SetBotWxid sets the "bot_wxid" field. func (mrc *MessageRecordsCreate) SetBotWxid(s string) *MessageRecordsCreate { mrc.mutation.SetBotWxid(s) return mrc } // SetContactID sets the "contact_id" field. func (mrc *MessageRecordsCreate) SetContactID(u uint64) *MessageRecordsCreate { mrc.mutation.SetContactID(u) return mrc } // SetNillableContactID sets the "contact_id" field if the given value is not nil. func (mrc *MessageRecordsCreate) SetNillableContactID(u *uint64) *MessageRecordsCreate { if u != nil { mrc.SetContactID(*u) } return mrc } // SetContactType sets the "contact_type" field. func (mrc *MessageRecordsCreate) SetContactType(i int) *MessageRecordsCreate { mrc.mutation.SetContactType(i) return mrc } // SetNillableContactType sets the "contact_type" field if the given value is not nil. func (mrc *MessageRecordsCreate) SetNillableContactType(i *int) *MessageRecordsCreate { if i != nil { mrc.SetContactType(*i) } return mrc } // SetContactWxid sets the "contact_wxid" field. func (mrc *MessageRecordsCreate) SetContactWxid(s string) *MessageRecordsCreate { mrc.mutation.SetContactWxid(s) return mrc } // SetNillableContactWxid sets the "contact_wxid" field if the given value is not nil. func (mrc *MessageRecordsCreate) SetNillableContactWxid(s *string) *MessageRecordsCreate { if s != nil { mrc.SetContactWxid(*s) } return mrc } // SetContentType sets the "content_type" field. func (mrc *MessageRecordsCreate) SetContentType(i int) *MessageRecordsCreate { mrc.mutation.SetContentType(i) return mrc } // SetNillableContentType sets the "content_type" field if the given value is not nil. func (mrc *MessageRecordsCreate) SetNillableContentType(i *int) *MessageRecordsCreate { if i != nil { mrc.SetContentType(*i) } return mrc } // SetContent sets the "content" field. func (mrc *MessageRecordsCreate) SetContent(s string) *MessageRecordsCreate { mrc.mutation.SetContent(s) return mrc } // SetNillableContent sets the "content" field if the given value is not nil. func (mrc *MessageRecordsCreate) SetNillableContent(s *string) *MessageRecordsCreate { if s != nil { mrc.SetContent(*s) } return mrc } // SetErrorDetail sets the "error_detail" field. func (mrc *MessageRecordsCreate) SetErrorDetail(s string) *MessageRecordsCreate { mrc.mutation.SetErrorDetail(s) return mrc } // SetNillableErrorDetail sets the "error_detail" field if the given value is not nil. func (mrc *MessageRecordsCreate) SetNillableErrorDetail(s *string) *MessageRecordsCreate { if s != nil { mrc.SetErrorDetail(*s) } return mrc } // SetSendTime sets the "send_time" field. func (mrc *MessageRecordsCreate) SetSendTime(t time.Time) *MessageRecordsCreate { mrc.mutation.SetSendTime(t) return mrc } // SetNillableSendTime sets the "send_time" field if the given value is not nil. func (mrc *MessageRecordsCreate) SetNillableSendTime(t *time.Time) *MessageRecordsCreate { if t != nil { mrc.SetSendTime(*t) } return mrc } // SetSourceType sets the "source_type" field. func (mrc *MessageRecordsCreate) SetSourceType(i int) *MessageRecordsCreate { mrc.mutation.SetSourceType(i) return mrc } // SetNillableSourceType sets the "source_type" field if the given value is not nil. func (mrc *MessageRecordsCreate) SetNillableSourceType(i *int) *MessageRecordsCreate { if i != nil { mrc.SetSourceType(*i) } return mrc } // SetSourceID sets the "source_id" field. func (mrc *MessageRecordsCreate) SetSourceID(u uint64) *MessageRecordsCreate { mrc.mutation.SetSourceID(u) return mrc } // SetNillableSourceID sets the "source_id" field if the given value is not nil. func (mrc *MessageRecordsCreate) SetNillableSourceID(u *uint64) *MessageRecordsCreate { if u != nil { mrc.SetSourceID(*u) } return mrc } // SetSubSourceID sets the "sub_source_id" field. func (mrc *MessageRecordsCreate) SetSubSourceID(u uint64) *MessageRecordsCreate { mrc.mutation.SetSubSourceID(u) return mrc } // SetNillableSubSourceID sets the "sub_source_id" field if the given value is not nil. func (mrc *MessageRecordsCreate) SetNillableSubSourceID(u *uint64) *MessageRecordsCreate { if u != nil { mrc.SetSubSourceID(*u) } return mrc } // SetID sets the "id" field. func (mrc *MessageRecordsCreate) SetID(u uint64) *MessageRecordsCreate { mrc.mutation.SetID(u) return mrc } // Mutation returns the MessageRecordsMutation object of the builder. func (mrc *MessageRecordsCreate) Mutation() *MessageRecordsMutation { return mrc.mutation } // Save creates the MessageRecords in the database. func (mrc *MessageRecordsCreate) Save(ctx context.Context) (*MessageRecords, error) { mrc.defaults() return withHooks(ctx, mrc.sqlSave, mrc.mutation, mrc.hooks) } // SaveX calls Save and panics if Save returns an error. func (mrc *MessageRecordsCreate) SaveX(ctx context.Context) *MessageRecords { v, err := mrc.Save(ctx) if err != nil { panic(err) } return v } // Exec executes the query. func (mrc *MessageRecordsCreate) Exec(ctx context.Context) error { _, err := mrc.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (mrc *MessageRecordsCreate) ExecX(ctx context.Context) { if err := mrc.Exec(ctx); err != nil { panic(err) } } // defaults sets the default values of the builder before save. func (mrc *MessageRecordsCreate) defaults() { if _, ok := mrc.mutation.CreatedAt(); !ok { v := messagerecords.DefaultCreatedAt() mrc.mutation.SetCreatedAt(v) } if _, ok := mrc.mutation.UpdatedAt(); !ok { v := messagerecords.DefaultUpdatedAt() mrc.mutation.SetUpdatedAt(v) } if _, ok := mrc.mutation.Status(); !ok { v := messagerecords.DefaultStatus mrc.mutation.SetStatus(v) } if _, ok := mrc.mutation.ContactType(); !ok { v := messagerecords.DefaultContactType mrc.mutation.SetContactType(v) } if _, ok := mrc.mutation.ContactWxid(); !ok { v := messagerecords.DefaultContactWxid mrc.mutation.SetContactWxid(v) } if _, ok := mrc.mutation.ContentType(); !ok { v := messagerecords.DefaultContentType mrc.mutation.SetContentType(v) } if _, ok := mrc.mutation.Content(); !ok { v := messagerecords.DefaultContent mrc.mutation.SetContent(v) } if _, ok := mrc.mutation.ErrorDetail(); !ok { v := messagerecords.DefaultErrorDetail mrc.mutation.SetErrorDetail(v) } if _, ok := mrc.mutation.SourceType(); !ok { v := messagerecords.DefaultSourceType mrc.mutation.SetSourceType(v) } if _, ok := mrc.mutation.SourceID(); !ok { v := messagerecords.DefaultSourceID mrc.mutation.SetSourceID(v) } if _, ok := mrc.mutation.SubSourceID(); !ok { v := messagerecords.DefaultSubSourceID mrc.mutation.SetSubSourceID(v) } } // check runs all checks and user-defined validators on the builder. func (mrc *MessageRecordsCreate) check() error { if _, ok := mrc.mutation.CreatedAt(); !ok { return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "MessageRecords.created_at"`)} } if _, ok := mrc.mutation.UpdatedAt(); !ok { return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "MessageRecords.updated_at"`)} } if _, ok := mrc.mutation.BotWxid(); !ok { return &ValidationError{Name: "bot_wxid", err: errors.New(`ent: missing required field "MessageRecords.bot_wxid"`)} } if _, ok := mrc.mutation.ContactType(); !ok { return &ValidationError{Name: "contact_type", err: errors.New(`ent: missing required field "MessageRecords.contact_type"`)} } if _, ok := mrc.mutation.ContactWxid(); !ok { return &ValidationError{Name: "contact_wxid", err: errors.New(`ent: missing required field "MessageRecords.contact_wxid"`)} } if _, ok := mrc.mutation.ContentType(); !ok { return &ValidationError{Name: "content_type", err: errors.New(`ent: missing required field "MessageRecords.content_type"`)} } if _, ok := mrc.mutation.Content(); !ok { return &ValidationError{Name: "content", err: errors.New(`ent: missing required field "MessageRecords.content"`)} } if _, ok := mrc.mutation.ErrorDetail(); !ok { return &ValidationError{Name: "error_detail", err: errors.New(`ent: missing required field "MessageRecords.error_detail"`)} } if _, ok := mrc.mutation.SourceType(); !ok { return &ValidationError{Name: "source_type", err: errors.New(`ent: missing required field "MessageRecords.source_type"`)} } return nil } func (mrc *MessageRecordsCreate) sqlSave(ctx context.Context) (*MessageRecords, error) { if err := mrc.check(); err != nil { return nil, err } _node, _spec := mrc.createSpec() if err := sqlgraph.CreateNode(ctx, mrc.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) } mrc.mutation.id = &_node.ID mrc.mutation.done = true return _node, nil } func (mrc *MessageRecordsCreate) createSpec() (*MessageRecords, *sqlgraph.CreateSpec) { var ( _node = &MessageRecords{config: mrc.config} _spec = sqlgraph.NewCreateSpec(messagerecords.Table, sqlgraph.NewFieldSpec(messagerecords.FieldID, field.TypeUint64)) ) if id, ok := mrc.mutation.ID(); ok { _node.ID = id _spec.ID.Value = id } if value, ok := mrc.mutation.CreatedAt(); ok { _spec.SetField(messagerecords.FieldCreatedAt, field.TypeTime, value) _node.CreatedAt = value } if value, ok := mrc.mutation.UpdatedAt(); ok { _spec.SetField(messagerecords.FieldUpdatedAt, field.TypeTime, value) _node.UpdatedAt = value } if value, ok := mrc.mutation.Status(); ok { _spec.SetField(messagerecords.FieldStatus, field.TypeUint8, value) _node.Status = value } if value, ok := mrc.mutation.BotWxid(); ok { _spec.SetField(messagerecords.FieldBotWxid, field.TypeString, value) _node.BotWxid = value } if value, ok := mrc.mutation.ContactID(); ok { _spec.SetField(messagerecords.FieldContactID, field.TypeUint64, value) _node.ContactID = value } if value, ok := mrc.mutation.ContactType(); ok { _spec.SetField(messagerecords.FieldContactType, field.TypeInt, value) _node.ContactType = value } if value, ok := mrc.mutation.ContactWxid(); ok { _spec.SetField(messagerecords.FieldContactWxid, field.TypeString, value) _node.ContactWxid = value } if value, ok := mrc.mutation.ContentType(); ok { _spec.SetField(messagerecords.FieldContentType, field.TypeInt, value) _node.ContentType = value } if value, ok := mrc.mutation.Content(); ok { _spec.SetField(messagerecords.FieldContent, field.TypeString, value) _node.Content = value } if value, ok := mrc.mutation.ErrorDetail(); ok { _spec.SetField(messagerecords.FieldErrorDetail, field.TypeString, value) _node.ErrorDetail = value } if value, ok := mrc.mutation.SendTime(); ok { _spec.SetField(messagerecords.FieldSendTime, field.TypeTime, value) _node.SendTime = value } if value, ok := mrc.mutation.SourceType(); ok { _spec.SetField(messagerecords.FieldSourceType, field.TypeInt, value) _node.SourceType = value } if value, ok := mrc.mutation.SourceID(); ok { _spec.SetField(messagerecords.FieldSourceID, field.TypeUint64, value) _node.SourceID = value } if value, ok := mrc.mutation.SubSourceID(); ok { _spec.SetField(messagerecords.FieldSubSourceID, field.TypeUint64, value) _node.SubSourceID = value } return _node, _spec } // MessageRecordsCreateBulk is the builder for creating many MessageRecords entities in bulk. type MessageRecordsCreateBulk struct { config err error builders []*MessageRecordsCreate } // Save creates the MessageRecords entities in the database. func (mrcb *MessageRecordsCreateBulk) Save(ctx context.Context) ([]*MessageRecords, error) { if mrcb.err != nil { return nil, mrcb.err } specs := make([]*sqlgraph.CreateSpec, len(mrcb.builders)) nodes := make([]*MessageRecords, len(mrcb.builders)) mutators := make([]Mutator, len(mrcb.builders)) for i := range mrcb.builders { func(i int, root context.Context) { builder := mrcb.builders[i] builder.defaults() var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { mutation, ok := m.(*MessageRecordsMutation) 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, mrcb.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, mrcb.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, mrcb.builders[0].mutation); err != nil { return nil, err } } return nodes, nil } // SaveX is like Save, but panics if an error occurs. func (mrcb *MessageRecordsCreateBulk) SaveX(ctx context.Context) []*MessageRecords { v, err := mrcb.Save(ctx) if err != nil { panic(err) } return v } // Exec executes the query. func (mrcb *MessageRecordsCreateBulk) Exec(ctx context.Context) error { _, err := mrcb.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (mrcb *MessageRecordsCreateBulk) ExecX(ctx context.Context) { if err := mrcb.Exec(ctx); err != nil { panic(err) } }