12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145 |
- // Code generated by ent, DO NOT EDIT.
- package ent
- import (
- "context"
- "errors"
- "fmt"
- "time"
- "wechat-api/ent/contact"
- "wechat-api/ent/messagerecords"
- "wechat-api/ent/predicate"
- "wechat-api/ent/sopnode"
- "wechat-api/ent/sopstage"
- "entgo.io/ent/dialect/sql"
- "entgo.io/ent/dialect/sql/sqlgraph"
- "entgo.io/ent/schema/field"
- )
- // MessageRecordsUpdate is the builder for updating MessageRecords entities.
- type MessageRecordsUpdate struct {
- config
- hooks []Hook
- mutation *MessageRecordsMutation
- }
- // Where appends a list predicates to the MessageRecordsUpdate builder.
- func (mru *MessageRecordsUpdate) Where(ps ...predicate.MessageRecords) *MessageRecordsUpdate {
- mru.mutation.Where(ps...)
- return mru
- }
- // SetUpdatedAt sets the "updated_at" field.
- func (mru *MessageRecordsUpdate) SetUpdatedAt(t time.Time) *MessageRecordsUpdate {
- mru.mutation.SetUpdatedAt(t)
- return mru
- }
- // SetStatus sets the "status" field.
- func (mru *MessageRecordsUpdate) SetStatus(u uint8) *MessageRecordsUpdate {
- mru.mutation.ResetStatus()
- mru.mutation.SetStatus(u)
- return mru
- }
- // SetNillableStatus sets the "status" field if the given value is not nil.
- func (mru *MessageRecordsUpdate) SetNillableStatus(u *uint8) *MessageRecordsUpdate {
- if u != nil {
- mru.SetStatus(*u)
- }
- return mru
- }
- // AddStatus adds u to the "status" field.
- func (mru *MessageRecordsUpdate) AddStatus(u int8) *MessageRecordsUpdate {
- mru.mutation.AddStatus(u)
- return mru
- }
- // ClearStatus clears the value of the "status" field.
- func (mru *MessageRecordsUpdate) ClearStatus() *MessageRecordsUpdate {
- mru.mutation.ClearStatus()
- return mru
- }
- // SetDeletedAt sets the "deleted_at" field.
- func (mru *MessageRecordsUpdate) SetDeletedAt(t time.Time) *MessageRecordsUpdate {
- mru.mutation.SetDeletedAt(t)
- return mru
- }
- // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
- func (mru *MessageRecordsUpdate) SetNillableDeletedAt(t *time.Time) *MessageRecordsUpdate {
- if t != nil {
- mru.SetDeletedAt(*t)
- }
- return mru
- }
- // ClearDeletedAt clears the value of the "deleted_at" field.
- func (mru *MessageRecordsUpdate) ClearDeletedAt() *MessageRecordsUpdate {
- mru.mutation.ClearDeletedAt()
- return mru
- }
- // SetBotWxid sets the "bot_wxid" field.
- func (mru *MessageRecordsUpdate) SetBotWxid(s string) *MessageRecordsUpdate {
- mru.mutation.SetBotWxid(s)
- return mru
- }
- // SetNillableBotWxid sets the "bot_wxid" field if the given value is not nil.
- func (mru *MessageRecordsUpdate) SetNillableBotWxid(s *string) *MessageRecordsUpdate {
- if s != nil {
- mru.SetBotWxid(*s)
- }
- return mru
- }
- // SetContactID sets the "contact_id" field.
- func (mru *MessageRecordsUpdate) SetContactID(u uint64) *MessageRecordsUpdate {
- mru.mutation.SetContactID(u)
- return mru
- }
- // SetNillableContactID sets the "contact_id" field if the given value is not nil.
- func (mru *MessageRecordsUpdate) SetNillableContactID(u *uint64) *MessageRecordsUpdate {
- if u != nil {
- mru.SetContactID(*u)
- }
- return mru
- }
- // ClearContactID clears the value of the "contact_id" field.
- func (mru *MessageRecordsUpdate) ClearContactID() *MessageRecordsUpdate {
- mru.mutation.ClearContactID()
- return mru
- }
- // SetContactType sets the "contact_type" field.
- func (mru *MessageRecordsUpdate) SetContactType(i int) *MessageRecordsUpdate {
- mru.mutation.ResetContactType()
- mru.mutation.SetContactType(i)
- return mru
- }
- // SetNillableContactType sets the "contact_type" field if the given value is not nil.
- func (mru *MessageRecordsUpdate) SetNillableContactType(i *int) *MessageRecordsUpdate {
- if i != nil {
- mru.SetContactType(*i)
- }
- return mru
- }
- // AddContactType adds i to the "contact_type" field.
- func (mru *MessageRecordsUpdate) AddContactType(i int) *MessageRecordsUpdate {
- mru.mutation.AddContactType(i)
- return mru
- }
- // SetContactWxid sets the "contact_wxid" field.
- func (mru *MessageRecordsUpdate) SetContactWxid(s string) *MessageRecordsUpdate {
- mru.mutation.SetContactWxid(s)
- return mru
- }
- // SetNillableContactWxid sets the "contact_wxid" field if the given value is not nil.
- func (mru *MessageRecordsUpdate) SetNillableContactWxid(s *string) *MessageRecordsUpdate {
- if s != nil {
- mru.SetContactWxid(*s)
- }
- return mru
- }
- // SetContentType sets the "content_type" field.
- func (mru *MessageRecordsUpdate) SetContentType(i int) *MessageRecordsUpdate {
- mru.mutation.ResetContentType()
- mru.mutation.SetContentType(i)
- return mru
- }
- // SetNillableContentType sets the "content_type" field if the given value is not nil.
- func (mru *MessageRecordsUpdate) SetNillableContentType(i *int) *MessageRecordsUpdate {
- if i != nil {
- mru.SetContentType(*i)
- }
- return mru
- }
- // AddContentType adds i to the "content_type" field.
- func (mru *MessageRecordsUpdate) AddContentType(i int) *MessageRecordsUpdate {
- mru.mutation.AddContentType(i)
- return mru
- }
- // SetContent sets the "content" field.
- func (mru *MessageRecordsUpdate) SetContent(s string) *MessageRecordsUpdate {
- mru.mutation.SetContent(s)
- return mru
- }
- // SetNillableContent sets the "content" field if the given value is not nil.
- func (mru *MessageRecordsUpdate) SetNillableContent(s *string) *MessageRecordsUpdate {
- if s != nil {
- mru.SetContent(*s)
- }
- return mru
- }
- // SetErrorDetail sets the "error_detail" field.
- func (mru *MessageRecordsUpdate) SetErrorDetail(s string) *MessageRecordsUpdate {
- mru.mutation.SetErrorDetail(s)
- return mru
- }
- // SetNillableErrorDetail sets the "error_detail" field if the given value is not nil.
- func (mru *MessageRecordsUpdate) SetNillableErrorDetail(s *string) *MessageRecordsUpdate {
- if s != nil {
- mru.SetErrorDetail(*s)
- }
- return mru
- }
- // SetSendTime sets the "send_time" field.
- func (mru *MessageRecordsUpdate) SetSendTime(t time.Time) *MessageRecordsUpdate {
- mru.mutation.SetSendTime(t)
- return mru
- }
- // SetNillableSendTime sets the "send_time" field if the given value is not nil.
- func (mru *MessageRecordsUpdate) SetNillableSendTime(t *time.Time) *MessageRecordsUpdate {
- if t != nil {
- mru.SetSendTime(*t)
- }
- return mru
- }
- // ClearSendTime clears the value of the "send_time" field.
- func (mru *MessageRecordsUpdate) ClearSendTime() *MessageRecordsUpdate {
- mru.mutation.ClearSendTime()
- return mru
- }
- // SetSourceType sets the "source_type" field.
- func (mru *MessageRecordsUpdate) SetSourceType(i int) *MessageRecordsUpdate {
- mru.mutation.ResetSourceType()
- mru.mutation.SetSourceType(i)
- return mru
- }
- // SetNillableSourceType sets the "source_type" field if the given value is not nil.
- func (mru *MessageRecordsUpdate) SetNillableSourceType(i *int) *MessageRecordsUpdate {
- if i != nil {
- mru.SetSourceType(*i)
- }
- return mru
- }
- // AddSourceType adds i to the "source_type" field.
- func (mru *MessageRecordsUpdate) AddSourceType(i int) *MessageRecordsUpdate {
- mru.mutation.AddSourceType(i)
- return mru
- }
- // SetSourceID sets the "source_id" field.
- func (mru *MessageRecordsUpdate) SetSourceID(u uint64) *MessageRecordsUpdate {
- mru.mutation.SetSourceID(u)
- return mru
- }
- // SetNillableSourceID sets the "source_id" field if the given value is not nil.
- func (mru *MessageRecordsUpdate) SetNillableSourceID(u *uint64) *MessageRecordsUpdate {
- if u != nil {
- mru.SetSourceID(*u)
- }
- return mru
- }
- // ClearSourceID clears the value of the "source_id" field.
- func (mru *MessageRecordsUpdate) ClearSourceID() *MessageRecordsUpdate {
- mru.mutation.ClearSourceID()
- return mru
- }
- // SetSubSourceID sets the "sub_source_id" field.
- func (mru *MessageRecordsUpdate) SetSubSourceID(u uint64) *MessageRecordsUpdate {
- mru.mutation.SetSubSourceID(u)
- return mru
- }
- // SetNillableSubSourceID sets the "sub_source_id" field if the given value is not nil.
- func (mru *MessageRecordsUpdate) SetNillableSubSourceID(u *uint64) *MessageRecordsUpdate {
- if u != nil {
- mru.SetSubSourceID(*u)
- }
- return mru
- }
- // ClearSubSourceID clears the value of the "sub_source_id" field.
- func (mru *MessageRecordsUpdate) ClearSubSourceID() *MessageRecordsUpdate {
- mru.mutation.ClearSubSourceID()
- return mru
- }
- // SetSopStageID sets the "sop_stage" edge to the SopStage entity by ID.
- func (mru *MessageRecordsUpdate) SetSopStageID(id uint64) *MessageRecordsUpdate {
- mru.mutation.SetSopStageID(id)
- return mru
- }
- // SetNillableSopStageID sets the "sop_stage" edge to the SopStage entity by ID if the given value is not nil.
- func (mru *MessageRecordsUpdate) SetNillableSopStageID(id *uint64) *MessageRecordsUpdate {
- if id != nil {
- mru = mru.SetSopStageID(*id)
- }
- return mru
- }
- // SetSopStage sets the "sop_stage" edge to the SopStage entity.
- func (mru *MessageRecordsUpdate) SetSopStage(s *SopStage) *MessageRecordsUpdate {
- return mru.SetSopStageID(s.ID)
- }
- // SetSopNodeID sets the "sop_node" edge to the SopNode entity by ID.
- func (mru *MessageRecordsUpdate) SetSopNodeID(id uint64) *MessageRecordsUpdate {
- mru.mutation.SetSopNodeID(id)
- return mru
- }
- // SetNillableSopNodeID sets the "sop_node" edge to the SopNode entity by ID if the given value is not nil.
- func (mru *MessageRecordsUpdate) SetNillableSopNodeID(id *uint64) *MessageRecordsUpdate {
- if id != nil {
- mru = mru.SetSopNodeID(*id)
- }
- return mru
- }
- // SetSopNode sets the "sop_node" edge to the SopNode entity.
- func (mru *MessageRecordsUpdate) SetSopNode(s *SopNode) *MessageRecordsUpdate {
- return mru.SetSopNodeID(s.ID)
- }
- // SetMessageContactID sets the "message_contact" edge to the Contact entity by ID.
- func (mru *MessageRecordsUpdate) SetMessageContactID(id uint64) *MessageRecordsUpdate {
- mru.mutation.SetMessageContactID(id)
- return mru
- }
- // SetNillableMessageContactID sets the "message_contact" edge to the Contact entity by ID if the given value is not nil.
- func (mru *MessageRecordsUpdate) SetNillableMessageContactID(id *uint64) *MessageRecordsUpdate {
- if id != nil {
- mru = mru.SetMessageContactID(*id)
- }
- return mru
- }
- // SetMessageContact sets the "message_contact" edge to the Contact entity.
- func (mru *MessageRecordsUpdate) SetMessageContact(c *Contact) *MessageRecordsUpdate {
- return mru.SetMessageContactID(c.ID)
- }
- // Mutation returns the MessageRecordsMutation object of the builder.
- func (mru *MessageRecordsUpdate) Mutation() *MessageRecordsMutation {
- return mru.mutation
- }
- // ClearSopStage clears the "sop_stage" edge to the SopStage entity.
- func (mru *MessageRecordsUpdate) ClearSopStage() *MessageRecordsUpdate {
- mru.mutation.ClearSopStage()
- return mru
- }
- // ClearSopNode clears the "sop_node" edge to the SopNode entity.
- func (mru *MessageRecordsUpdate) ClearSopNode() *MessageRecordsUpdate {
- mru.mutation.ClearSopNode()
- return mru
- }
- // ClearMessageContact clears the "message_contact" edge to the Contact entity.
- func (mru *MessageRecordsUpdate) ClearMessageContact() *MessageRecordsUpdate {
- mru.mutation.ClearMessageContact()
- return mru
- }
- // Save executes the query and returns the number of nodes affected by the update operation.
- func (mru *MessageRecordsUpdate) Save(ctx context.Context) (int, error) {
- if err := mru.defaults(); err != nil {
- return 0, err
- }
- return withHooks(ctx, mru.sqlSave, mru.mutation, mru.hooks)
- }
- // SaveX is like Save, but panics if an error occurs.
- func (mru *MessageRecordsUpdate) SaveX(ctx context.Context) int {
- affected, err := mru.Save(ctx)
- if err != nil {
- panic(err)
- }
- return affected
- }
- // Exec executes the query.
- func (mru *MessageRecordsUpdate) Exec(ctx context.Context) error {
- _, err := mru.Save(ctx)
- return err
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (mru *MessageRecordsUpdate) ExecX(ctx context.Context) {
- if err := mru.Exec(ctx); err != nil {
- panic(err)
- }
- }
- // defaults sets the default values of the builder before save.
- func (mru *MessageRecordsUpdate) defaults() error {
- if _, ok := mru.mutation.UpdatedAt(); !ok {
- if messagerecords.UpdateDefaultUpdatedAt == nil {
- return fmt.Errorf("ent: uninitialized messagerecords.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
- }
- v := messagerecords.UpdateDefaultUpdatedAt()
- mru.mutation.SetUpdatedAt(v)
- }
- return nil
- }
- func (mru *MessageRecordsUpdate) sqlSave(ctx context.Context) (n int, err error) {
- _spec := sqlgraph.NewUpdateSpec(messagerecords.Table, messagerecords.Columns, sqlgraph.NewFieldSpec(messagerecords.FieldID, field.TypeUint64))
- if ps := mru.mutation.predicates; len(ps) > 0 {
- _spec.Predicate = func(selector *sql.Selector) {
- for i := range ps {
- ps[i](selector)
- }
- }
- }
- if value, ok := mru.mutation.UpdatedAt(); ok {
- _spec.SetField(messagerecords.FieldUpdatedAt, field.TypeTime, value)
- }
- if value, ok := mru.mutation.Status(); ok {
- _spec.SetField(messagerecords.FieldStatus, field.TypeUint8, value)
- }
- if value, ok := mru.mutation.AddedStatus(); ok {
- _spec.AddField(messagerecords.FieldStatus, field.TypeUint8, value)
- }
- if mru.mutation.StatusCleared() {
- _spec.ClearField(messagerecords.FieldStatus, field.TypeUint8)
- }
- if value, ok := mru.mutation.DeletedAt(); ok {
- _spec.SetField(messagerecords.FieldDeletedAt, field.TypeTime, value)
- }
- if mru.mutation.DeletedAtCleared() {
- _spec.ClearField(messagerecords.FieldDeletedAt, field.TypeTime)
- }
- if value, ok := mru.mutation.BotWxid(); ok {
- _spec.SetField(messagerecords.FieldBotWxid, field.TypeString, value)
- }
- if value, ok := mru.mutation.ContactType(); ok {
- _spec.SetField(messagerecords.FieldContactType, field.TypeInt, value)
- }
- if value, ok := mru.mutation.AddedContactType(); ok {
- _spec.AddField(messagerecords.FieldContactType, field.TypeInt, value)
- }
- if value, ok := mru.mutation.ContactWxid(); ok {
- _spec.SetField(messagerecords.FieldContactWxid, field.TypeString, value)
- }
- if value, ok := mru.mutation.ContentType(); ok {
- _spec.SetField(messagerecords.FieldContentType, field.TypeInt, value)
- }
- if value, ok := mru.mutation.AddedContentType(); ok {
- _spec.AddField(messagerecords.FieldContentType, field.TypeInt, value)
- }
- if value, ok := mru.mutation.Content(); ok {
- _spec.SetField(messagerecords.FieldContent, field.TypeString, value)
- }
- if value, ok := mru.mutation.ErrorDetail(); ok {
- _spec.SetField(messagerecords.FieldErrorDetail, field.TypeString, value)
- }
- if value, ok := mru.mutation.SendTime(); ok {
- _spec.SetField(messagerecords.FieldSendTime, field.TypeTime, value)
- }
- if mru.mutation.SendTimeCleared() {
- _spec.ClearField(messagerecords.FieldSendTime, field.TypeTime)
- }
- if value, ok := mru.mutation.SourceType(); ok {
- _spec.SetField(messagerecords.FieldSourceType, field.TypeInt, value)
- }
- if value, ok := mru.mutation.AddedSourceType(); ok {
- _spec.AddField(messagerecords.FieldSourceType, field.TypeInt, value)
- }
- if mru.mutation.SopStageCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.M2O,
- Inverse: true,
- Table: messagerecords.SopStageTable,
- Columns: []string{messagerecords.SopStageColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(sopstage.FieldID, field.TypeUint64),
- },
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := mru.mutation.SopStageIDs(); len(nodes) > 0 {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.M2O,
- Inverse: true,
- Table: messagerecords.SopStageTable,
- Columns: []string{messagerecords.SopStageColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(sopstage.FieldID, field.TypeUint64),
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges.Add = append(_spec.Edges.Add, edge)
- }
- if mru.mutation.SopNodeCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.M2O,
- Inverse: true,
- Table: messagerecords.SopNodeTable,
- Columns: []string{messagerecords.SopNodeColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(sopnode.FieldID, field.TypeUint64),
- },
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := mru.mutation.SopNodeIDs(); len(nodes) > 0 {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.M2O,
- Inverse: true,
- Table: messagerecords.SopNodeTable,
- Columns: []string{messagerecords.SopNodeColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(sopnode.FieldID, field.TypeUint64),
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges.Add = append(_spec.Edges.Add, edge)
- }
- if mru.mutation.MessageContactCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.M2O,
- Inverse: true,
- Table: messagerecords.MessageContactTable,
- Columns: []string{messagerecords.MessageContactColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(contact.FieldID, field.TypeUint64),
- },
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := mru.mutation.MessageContactIDs(); len(nodes) > 0 {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.M2O,
- Inverse: true,
- Table: messagerecords.MessageContactTable,
- Columns: []string{messagerecords.MessageContactColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(contact.FieldID, field.TypeUint64),
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges.Add = append(_spec.Edges.Add, edge)
- }
- if n, err = sqlgraph.UpdateNodes(ctx, mru.driver, _spec); err != nil {
- if _, ok := err.(*sqlgraph.NotFoundError); ok {
- err = &NotFoundError{messagerecords.Label}
- } else if sqlgraph.IsConstraintError(err) {
- err = &ConstraintError{msg: err.Error(), wrap: err}
- }
- return 0, err
- }
- mru.mutation.done = true
- return n, nil
- }
- // MessageRecordsUpdateOne is the builder for updating a single MessageRecords entity.
- type MessageRecordsUpdateOne struct {
- config
- fields []string
- hooks []Hook
- mutation *MessageRecordsMutation
- }
- // SetUpdatedAt sets the "updated_at" field.
- func (mruo *MessageRecordsUpdateOne) SetUpdatedAt(t time.Time) *MessageRecordsUpdateOne {
- mruo.mutation.SetUpdatedAt(t)
- return mruo
- }
- // SetStatus sets the "status" field.
- func (mruo *MessageRecordsUpdateOne) SetStatus(u uint8) *MessageRecordsUpdateOne {
- mruo.mutation.ResetStatus()
- mruo.mutation.SetStatus(u)
- return mruo
- }
- // SetNillableStatus sets the "status" field if the given value is not nil.
- func (mruo *MessageRecordsUpdateOne) SetNillableStatus(u *uint8) *MessageRecordsUpdateOne {
- if u != nil {
- mruo.SetStatus(*u)
- }
- return mruo
- }
- // AddStatus adds u to the "status" field.
- func (mruo *MessageRecordsUpdateOne) AddStatus(u int8) *MessageRecordsUpdateOne {
- mruo.mutation.AddStatus(u)
- return mruo
- }
- // ClearStatus clears the value of the "status" field.
- func (mruo *MessageRecordsUpdateOne) ClearStatus() *MessageRecordsUpdateOne {
- mruo.mutation.ClearStatus()
- return mruo
- }
- // SetDeletedAt sets the "deleted_at" field.
- func (mruo *MessageRecordsUpdateOne) SetDeletedAt(t time.Time) *MessageRecordsUpdateOne {
- mruo.mutation.SetDeletedAt(t)
- return mruo
- }
- // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
- func (mruo *MessageRecordsUpdateOne) SetNillableDeletedAt(t *time.Time) *MessageRecordsUpdateOne {
- if t != nil {
- mruo.SetDeletedAt(*t)
- }
- return mruo
- }
- // ClearDeletedAt clears the value of the "deleted_at" field.
- func (mruo *MessageRecordsUpdateOne) ClearDeletedAt() *MessageRecordsUpdateOne {
- mruo.mutation.ClearDeletedAt()
- return mruo
- }
- // SetBotWxid sets the "bot_wxid" field.
- func (mruo *MessageRecordsUpdateOne) SetBotWxid(s string) *MessageRecordsUpdateOne {
- mruo.mutation.SetBotWxid(s)
- return mruo
- }
- // SetNillableBotWxid sets the "bot_wxid" field if the given value is not nil.
- func (mruo *MessageRecordsUpdateOne) SetNillableBotWxid(s *string) *MessageRecordsUpdateOne {
- if s != nil {
- mruo.SetBotWxid(*s)
- }
- return mruo
- }
- // SetContactID sets the "contact_id" field.
- func (mruo *MessageRecordsUpdateOne) SetContactID(u uint64) *MessageRecordsUpdateOne {
- mruo.mutation.SetContactID(u)
- return mruo
- }
- // SetNillableContactID sets the "contact_id" field if the given value is not nil.
- func (mruo *MessageRecordsUpdateOne) SetNillableContactID(u *uint64) *MessageRecordsUpdateOne {
- if u != nil {
- mruo.SetContactID(*u)
- }
- return mruo
- }
- // ClearContactID clears the value of the "contact_id" field.
- func (mruo *MessageRecordsUpdateOne) ClearContactID() *MessageRecordsUpdateOne {
- mruo.mutation.ClearContactID()
- return mruo
- }
- // SetContactType sets the "contact_type" field.
- func (mruo *MessageRecordsUpdateOne) SetContactType(i int) *MessageRecordsUpdateOne {
- mruo.mutation.ResetContactType()
- mruo.mutation.SetContactType(i)
- return mruo
- }
- // SetNillableContactType sets the "contact_type" field if the given value is not nil.
- func (mruo *MessageRecordsUpdateOne) SetNillableContactType(i *int) *MessageRecordsUpdateOne {
- if i != nil {
- mruo.SetContactType(*i)
- }
- return mruo
- }
- // AddContactType adds i to the "contact_type" field.
- func (mruo *MessageRecordsUpdateOne) AddContactType(i int) *MessageRecordsUpdateOne {
- mruo.mutation.AddContactType(i)
- return mruo
- }
- // SetContactWxid sets the "contact_wxid" field.
- func (mruo *MessageRecordsUpdateOne) SetContactWxid(s string) *MessageRecordsUpdateOne {
- mruo.mutation.SetContactWxid(s)
- return mruo
- }
- // SetNillableContactWxid sets the "contact_wxid" field if the given value is not nil.
- func (mruo *MessageRecordsUpdateOne) SetNillableContactWxid(s *string) *MessageRecordsUpdateOne {
- if s != nil {
- mruo.SetContactWxid(*s)
- }
- return mruo
- }
- // SetContentType sets the "content_type" field.
- func (mruo *MessageRecordsUpdateOne) SetContentType(i int) *MessageRecordsUpdateOne {
- mruo.mutation.ResetContentType()
- mruo.mutation.SetContentType(i)
- return mruo
- }
- // SetNillableContentType sets the "content_type" field if the given value is not nil.
- func (mruo *MessageRecordsUpdateOne) SetNillableContentType(i *int) *MessageRecordsUpdateOne {
- if i != nil {
- mruo.SetContentType(*i)
- }
- return mruo
- }
- // AddContentType adds i to the "content_type" field.
- func (mruo *MessageRecordsUpdateOne) AddContentType(i int) *MessageRecordsUpdateOne {
- mruo.mutation.AddContentType(i)
- return mruo
- }
- // SetContent sets the "content" field.
- func (mruo *MessageRecordsUpdateOne) SetContent(s string) *MessageRecordsUpdateOne {
- mruo.mutation.SetContent(s)
- return mruo
- }
- // SetNillableContent sets the "content" field if the given value is not nil.
- func (mruo *MessageRecordsUpdateOne) SetNillableContent(s *string) *MessageRecordsUpdateOne {
- if s != nil {
- mruo.SetContent(*s)
- }
- return mruo
- }
- // SetErrorDetail sets the "error_detail" field.
- func (mruo *MessageRecordsUpdateOne) SetErrorDetail(s string) *MessageRecordsUpdateOne {
- mruo.mutation.SetErrorDetail(s)
- return mruo
- }
- // SetNillableErrorDetail sets the "error_detail" field if the given value is not nil.
- func (mruo *MessageRecordsUpdateOne) SetNillableErrorDetail(s *string) *MessageRecordsUpdateOne {
- if s != nil {
- mruo.SetErrorDetail(*s)
- }
- return mruo
- }
- // SetSendTime sets the "send_time" field.
- func (mruo *MessageRecordsUpdateOne) SetSendTime(t time.Time) *MessageRecordsUpdateOne {
- mruo.mutation.SetSendTime(t)
- return mruo
- }
- // SetNillableSendTime sets the "send_time" field if the given value is not nil.
- func (mruo *MessageRecordsUpdateOne) SetNillableSendTime(t *time.Time) *MessageRecordsUpdateOne {
- if t != nil {
- mruo.SetSendTime(*t)
- }
- return mruo
- }
- // ClearSendTime clears the value of the "send_time" field.
- func (mruo *MessageRecordsUpdateOne) ClearSendTime() *MessageRecordsUpdateOne {
- mruo.mutation.ClearSendTime()
- return mruo
- }
- // SetSourceType sets the "source_type" field.
- func (mruo *MessageRecordsUpdateOne) SetSourceType(i int) *MessageRecordsUpdateOne {
- mruo.mutation.ResetSourceType()
- mruo.mutation.SetSourceType(i)
- return mruo
- }
- // SetNillableSourceType sets the "source_type" field if the given value is not nil.
- func (mruo *MessageRecordsUpdateOne) SetNillableSourceType(i *int) *MessageRecordsUpdateOne {
- if i != nil {
- mruo.SetSourceType(*i)
- }
- return mruo
- }
- // AddSourceType adds i to the "source_type" field.
- func (mruo *MessageRecordsUpdateOne) AddSourceType(i int) *MessageRecordsUpdateOne {
- mruo.mutation.AddSourceType(i)
- return mruo
- }
- // SetSourceID sets the "source_id" field.
- func (mruo *MessageRecordsUpdateOne) SetSourceID(u uint64) *MessageRecordsUpdateOne {
- mruo.mutation.SetSourceID(u)
- return mruo
- }
- // SetNillableSourceID sets the "source_id" field if the given value is not nil.
- func (mruo *MessageRecordsUpdateOne) SetNillableSourceID(u *uint64) *MessageRecordsUpdateOne {
- if u != nil {
- mruo.SetSourceID(*u)
- }
- return mruo
- }
- // ClearSourceID clears the value of the "source_id" field.
- func (mruo *MessageRecordsUpdateOne) ClearSourceID() *MessageRecordsUpdateOne {
- mruo.mutation.ClearSourceID()
- return mruo
- }
- // SetSubSourceID sets the "sub_source_id" field.
- func (mruo *MessageRecordsUpdateOne) SetSubSourceID(u uint64) *MessageRecordsUpdateOne {
- mruo.mutation.SetSubSourceID(u)
- return mruo
- }
- // SetNillableSubSourceID sets the "sub_source_id" field if the given value is not nil.
- func (mruo *MessageRecordsUpdateOne) SetNillableSubSourceID(u *uint64) *MessageRecordsUpdateOne {
- if u != nil {
- mruo.SetSubSourceID(*u)
- }
- return mruo
- }
- // ClearSubSourceID clears the value of the "sub_source_id" field.
- func (mruo *MessageRecordsUpdateOne) ClearSubSourceID() *MessageRecordsUpdateOne {
- mruo.mutation.ClearSubSourceID()
- return mruo
- }
- // SetSopStageID sets the "sop_stage" edge to the SopStage entity by ID.
- func (mruo *MessageRecordsUpdateOne) SetSopStageID(id uint64) *MessageRecordsUpdateOne {
- mruo.mutation.SetSopStageID(id)
- return mruo
- }
- // SetNillableSopStageID sets the "sop_stage" edge to the SopStage entity by ID if the given value is not nil.
- func (mruo *MessageRecordsUpdateOne) SetNillableSopStageID(id *uint64) *MessageRecordsUpdateOne {
- if id != nil {
- mruo = mruo.SetSopStageID(*id)
- }
- return mruo
- }
- // SetSopStage sets the "sop_stage" edge to the SopStage entity.
- func (mruo *MessageRecordsUpdateOne) SetSopStage(s *SopStage) *MessageRecordsUpdateOne {
- return mruo.SetSopStageID(s.ID)
- }
- // SetSopNodeID sets the "sop_node" edge to the SopNode entity by ID.
- func (mruo *MessageRecordsUpdateOne) SetSopNodeID(id uint64) *MessageRecordsUpdateOne {
- mruo.mutation.SetSopNodeID(id)
- return mruo
- }
- // SetNillableSopNodeID sets the "sop_node" edge to the SopNode entity by ID if the given value is not nil.
- func (mruo *MessageRecordsUpdateOne) SetNillableSopNodeID(id *uint64) *MessageRecordsUpdateOne {
- if id != nil {
- mruo = mruo.SetSopNodeID(*id)
- }
- return mruo
- }
- // SetSopNode sets the "sop_node" edge to the SopNode entity.
- func (mruo *MessageRecordsUpdateOne) SetSopNode(s *SopNode) *MessageRecordsUpdateOne {
- return mruo.SetSopNodeID(s.ID)
- }
- // SetMessageContactID sets the "message_contact" edge to the Contact entity by ID.
- func (mruo *MessageRecordsUpdateOne) SetMessageContactID(id uint64) *MessageRecordsUpdateOne {
- mruo.mutation.SetMessageContactID(id)
- return mruo
- }
- // SetNillableMessageContactID sets the "message_contact" edge to the Contact entity by ID if the given value is not nil.
- func (mruo *MessageRecordsUpdateOne) SetNillableMessageContactID(id *uint64) *MessageRecordsUpdateOne {
- if id != nil {
- mruo = mruo.SetMessageContactID(*id)
- }
- return mruo
- }
- // SetMessageContact sets the "message_contact" edge to the Contact entity.
- func (mruo *MessageRecordsUpdateOne) SetMessageContact(c *Contact) *MessageRecordsUpdateOne {
- return mruo.SetMessageContactID(c.ID)
- }
- // Mutation returns the MessageRecordsMutation object of the builder.
- func (mruo *MessageRecordsUpdateOne) Mutation() *MessageRecordsMutation {
- return mruo.mutation
- }
- // ClearSopStage clears the "sop_stage" edge to the SopStage entity.
- func (mruo *MessageRecordsUpdateOne) ClearSopStage() *MessageRecordsUpdateOne {
- mruo.mutation.ClearSopStage()
- return mruo
- }
- // ClearSopNode clears the "sop_node" edge to the SopNode entity.
- func (mruo *MessageRecordsUpdateOne) ClearSopNode() *MessageRecordsUpdateOne {
- mruo.mutation.ClearSopNode()
- return mruo
- }
- // ClearMessageContact clears the "message_contact" edge to the Contact entity.
- func (mruo *MessageRecordsUpdateOne) ClearMessageContact() *MessageRecordsUpdateOne {
- mruo.mutation.ClearMessageContact()
- return mruo
- }
- // Where appends a list predicates to the MessageRecordsUpdate builder.
- func (mruo *MessageRecordsUpdateOne) Where(ps ...predicate.MessageRecords) *MessageRecordsUpdateOne {
- mruo.mutation.Where(ps...)
- return mruo
- }
- // Select allows selecting one or more fields (columns) of the returned entity.
- // The default is selecting all fields defined in the entity schema.
- func (mruo *MessageRecordsUpdateOne) Select(field string, fields ...string) *MessageRecordsUpdateOne {
- mruo.fields = append([]string{field}, fields...)
- return mruo
- }
- // Save executes the query and returns the updated MessageRecords entity.
- func (mruo *MessageRecordsUpdateOne) Save(ctx context.Context) (*MessageRecords, error) {
- if err := mruo.defaults(); err != nil {
- return nil, err
- }
- return withHooks(ctx, mruo.sqlSave, mruo.mutation, mruo.hooks)
- }
- // SaveX is like Save, but panics if an error occurs.
- func (mruo *MessageRecordsUpdateOne) SaveX(ctx context.Context) *MessageRecords {
- node, err := mruo.Save(ctx)
- if err != nil {
- panic(err)
- }
- return node
- }
- // Exec executes the query on the entity.
- func (mruo *MessageRecordsUpdateOne) Exec(ctx context.Context) error {
- _, err := mruo.Save(ctx)
- return err
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (mruo *MessageRecordsUpdateOne) ExecX(ctx context.Context) {
- if err := mruo.Exec(ctx); err != nil {
- panic(err)
- }
- }
- // defaults sets the default values of the builder before save.
- func (mruo *MessageRecordsUpdateOne) defaults() error {
- if _, ok := mruo.mutation.UpdatedAt(); !ok {
- if messagerecords.UpdateDefaultUpdatedAt == nil {
- return fmt.Errorf("ent: uninitialized messagerecords.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
- }
- v := messagerecords.UpdateDefaultUpdatedAt()
- mruo.mutation.SetUpdatedAt(v)
- }
- return nil
- }
- func (mruo *MessageRecordsUpdateOne) sqlSave(ctx context.Context) (_node *MessageRecords, err error) {
- _spec := sqlgraph.NewUpdateSpec(messagerecords.Table, messagerecords.Columns, sqlgraph.NewFieldSpec(messagerecords.FieldID, field.TypeUint64))
- id, ok := mruo.mutation.ID()
- if !ok {
- return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "MessageRecords.id" for update`)}
- }
- _spec.Node.ID.Value = id
- if fields := mruo.fields; len(fields) > 0 {
- _spec.Node.Columns = make([]string, 0, len(fields))
- _spec.Node.Columns = append(_spec.Node.Columns, messagerecords.FieldID)
- for _, f := range fields {
- if !messagerecords.ValidColumn(f) {
- return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
- }
- if f != messagerecords.FieldID {
- _spec.Node.Columns = append(_spec.Node.Columns, f)
- }
- }
- }
- if ps := mruo.mutation.predicates; len(ps) > 0 {
- _spec.Predicate = func(selector *sql.Selector) {
- for i := range ps {
- ps[i](selector)
- }
- }
- }
- if value, ok := mruo.mutation.UpdatedAt(); ok {
- _spec.SetField(messagerecords.FieldUpdatedAt, field.TypeTime, value)
- }
- if value, ok := mruo.mutation.Status(); ok {
- _spec.SetField(messagerecords.FieldStatus, field.TypeUint8, value)
- }
- if value, ok := mruo.mutation.AddedStatus(); ok {
- _spec.AddField(messagerecords.FieldStatus, field.TypeUint8, value)
- }
- if mruo.mutation.StatusCleared() {
- _spec.ClearField(messagerecords.FieldStatus, field.TypeUint8)
- }
- if value, ok := mruo.mutation.DeletedAt(); ok {
- _spec.SetField(messagerecords.FieldDeletedAt, field.TypeTime, value)
- }
- if mruo.mutation.DeletedAtCleared() {
- _spec.ClearField(messagerecords.FieldDeletedAt, field.TypeTime)
- }
- if value, ok := mruo.mutation.BotWxid(); ok {
- _spec.SetField(messagerecords.FieldBotWxid, field.TypeString, value)
- }
- if value, ok := mruo.mutation.ContactType(); ok {
- _spec.SetField(messagerecords.FieldContactType, field.TypeInt, value)
- }
- if value, ok := mruo.mutation.AddedContactType(); ok {
- _spec.AddField(messagerecords.FieldContactType, field.TypeInt, value)
- }
- if value, ok := mruo.mutation.ContactWxid(); ok {
- _spec.SetField(messagerecords.FieldContactWxid, field.TypeString, value)
- }
- if value, ok := mruo.mutation.ContentType(); ok {
- _spec.SetField(messagerecords.FieldContentType, field.TypeInt, value)
- }
- if value, ok := mruo.mutation.AddedContentType(); ok {
- _spec.AddField(messagerecords.FieldContentType, field.TypeInt, value)
- }
- if value, ok := mruo.mutation.Content(); ok {
- _spec.SetField(messagerecords.FieldContent, field.TypeString, value)
- }
- if value, ok := mruo.mutation.ErrorDetail(); ok {
- _spec.SetField(messagerecords.FieldErrorDetail, field.TypeString, value)
- }
- if value, ok := mruo.mutation.SendTime(); ok {
- _spec.SetField(messagerecords.FieldSendTime, field.TypeTime, value)
- }
- if mruo.mutation.SendTimeCleared() {
- _spec.ClearField(messagerecords.FieldSendTime, field.TypeTime)
- }
- if value, ok := mruo.mutation.SourceType(); ok {
- _spec.SetField(messagerecords.FieldSourceType, field.TypeInt, value)
- }
- if value, ok := mruo.mutation.AddedSourceType(); ok {
- _spec.AddField(messagerecords.FieldSourceType, field.TypeInt, value)
- }
- if mruo.mutation.SopStageCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.M2O,
- Inverse: true,
- Table: messagerecords.SopStageTable,
- Columns: []string{messagerecords.SopStageColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(sopstage.FieldID, field.TypeUint64),
- },
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := mruo.mutation.SopStageIDs(); len(nodes) > 0 {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.M2O,
- Inverse: true,
- Table: messagerecords.SopStageTable,
- Columns: []string{messagerecords.SopStageColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(sopstage.FieldID, field.TypeUint64),
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges.Add = append(_spec.Edges.Add, edge)
- }
- if mruo.mutation.SopNodeCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.M2O,
- Inverse: true,
- Table: messagerecords.SopNodeTable,
- Columns: []string{messagerecords.SopNodeColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(sopnode.FieldID, field.TypeUint64),
- },
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := mruo.mutation.SopNodeIDs(); len(nodes) > 0 {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.M2O,
- Inverse: true,
- Table: messagerecords.SopNodeTable,
- Columns: []string{messagerecords.SopNodeColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(sopnode.FieldID, field.TypeUint64),
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges.Add = append(_spec.Edges.Add, edge)
- }
- if mruo.mutation.MessageContactCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.M2O,
- Inverse: true,
- Table: messagerecords.MessageContactTable,
- Columns: []string{messagerecords.MessageContactColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(contact.FieldID, field.TypeUint64),
- },
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := mruo.mutation.MessageContactIDs(); len(nodes) > 0 {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.M2O,
- Inverse: true,
- Table: messagerecords.MessageContactTable,
- Columns: []string{messagerecords.MessageContactColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(contact.FieldID, field.TypeUint64),
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges.Add = append(_spec.Edges.Add, edge)
- }
- _node = &MessageRecords{config: mruo.config}
- _spec.Assign = _node.assignValues
- _spec.ScanValues = _node.scanValues
- if err = sqlgraph.UpdateNode(ctx, mruo.driver, _spec); err != nil {
- if _, ok := err.(*sqlgraph.NotFoundError); ok {
- err = &NotFoundError{messagerecords.Label}
- } else if sqlgraph.IsConstraintError(err) {
- err = &ConstraintError{msg: err.Error(), wrap: err}
- }
- return nil, err
- }
- mruo.mutation.done = true
- return _node, nil
- }
|