12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739 |
- // Code generated by ent, DO NOT EDIT.
- package ent
- import (
- "context"
- "errors"
- "fmt"
- "time"
- "wechat-api/ent/contact"
- "wechat-api/ent/custom_types"
- "wechat-api/ent/messagerecords"
- "wechat-api/ent/sopnode"
- "wechat-api/ent/sopstage"
- "entgo.io/ent/dialect/sql"
- "entgo.io/ent/dialect/sql/sqlgraph"
- "entgo.io/ent/schema/field"
- )
- // MessageRecordsCreate is the builder for creating a MessageRecords entity.
- type MessageRecordsCreate struct {
- config
- mutation *MessageRecordsMutation
- hooks []Hook
- conflict []sql.ConflictOption
- }
- // 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
- }
- // SetMeta sets the "meta" field.
- func (mrc *MessageRecordsCreate) SetMeta(ct custom_types.Meta) *MessageRecordsCreate {
- mrc.mutation.SetMeta(ct)
- return mrc
- }
- // SetNillableMeta sets the "meta" field if the given value is not nil.
- func (mrc *MessageRecordsCreate) SetNillableMeta(ct *custom_types.Meta) *MessageRecordsCreate {
- if ct != nil {
- mrc.SetMeta(*ct)
- }
- 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
- }
- // SetOrganizationID sets the "organization_id" field.
- func (mrc *MessageRecordsCreate) SetOrganizationID(u uint64) *MessageRecordsCreate {
- mrc.mutation.SetOrganizationID(u)
- return mrc
- }
- // SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
- func (mrc *MessageRecordsCreate) SetNillableOrganizationID(u *uint64) *MessageRecordsCreate {
- if u != nil {
- mrc.SetOrganizationID(*u)
- }
- return mrc
- }
- // SetID sets the "id" field.
- func (mrc *MessageRecordsCreate) SetID(u uint64) *MessageRecordsCreate {
- mrc.mutation.SetID(u)
- return mrc
- }
- // SetSopStageID sets the "sop_stage" edge to the SopStage entity by ID.
- func (mrc *MessageRecordsCreate) SetSopStageID(id uint64) *MessageRecordsCreate {
- mrc.mutation.SetSopStageID(id)
- return mrc
- }
- // SetNillableSopStageID sets the "sop_stage" edge to the SopStage entity by ID if the given value is not nil.
- func (mrc *MessageRecordsCreate) SetNillableSopStageID(id *uint64) *MessageRecordsCreate {
- if id != nil {
- mrc = mrc.SetSopStageID(*id)
- }
- return mrc
- }
- // SetSopStage sets the "sop_stage" edge to the SopStage entity.
- func (mrc *MessageRecordsCreate) SetSopStage(s *SopStage) *MessageRecordsCreate {
- return mrc.SetSopStageID(s.ID)
- }
- // SetSopNodeID sets the "sop_node" edge to the SopNode entity by ID.
- func (mrc *MessageRecordsCreate) SetSopNodeID(id uint64) *MessageRecordsCreate {
- mrc.mutation.SetSopNodeID(id)
- return mrc
- }
- // SetNillableSopNodeID sets the "sop_node" edge to the SopNode entity by ID if the given value is not nil.
- func (mrc *MessageRecordsCreate) SetNillableSopNodeID(id *uint64) *MessageRecordsCreate {
- if id != nil {
- mrc = mrc.SetSopNodeID(*id)
- }
- return mrc
- }
- // SetSopNode sets the "sop_node" edge to the SopNode entity.
- func (mrc *MessageRecordsCreate) SetSopNode(s *SopNode) *MessageRecordsCreate {
- return mrc.SetSopNodeID(s.ID)
- }
- // SetMessageContactID sets the "message_contact" edge to the Contact entity by ID.
- func (mrc *MessageRecordsCreate) SetMessageContactID(id uint64) *MessageRecordsCreate {
- mrc.mutation.SetMessageContactID(id)
- return mrc
- }
- // SetNillableMessageContactID sets the "message_contact" edge to the Contact entity by ID if the given value is not nil.
- func (mrc *MessageRecordsCreate) SetNillableMessageContactID(id *uint64) *MessageRecordsCreate {
- if id != nil {
- mrc = mrc.SetMessageContactID(*id)
- }
- return mrc
- }
- // SetMessageContact sets the "message_contact" edge to the Contact entity.
- func (mrc *MessageRecordsCreate) SetMessageContact(c *Contact) *MessageRecordsCreate {
- return mrc.SetMessageContactID(c.ID)
- }
- // 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)
- }
- if _, ok := mrc.mutation.OrganizationID(); !ok {
- v := messagerecords.DefaultOrganizationID
- mrc.mutation.SetOrganizationID(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))
- )
- _spec.OnConflict = mrc.conflict
- 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.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.Meta(); ok {
- _spec.SetField(messagerecords.FieldMeta, field.TypeJSON, value)
- _node.Meta = 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.OrganizationID(); ok {
- _spec.SetField(messagerecords.FieldOrganizationID, field.TypeUint64, value)
- _node.OrganizationID = value
- }
- if nodes := mrc.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)
- }
- _node.SourceID = nodes[0]
- _spec.Edges = append(_spec.Edges, edge)
- }
- if nodes := mrc.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)
- }
- _node.SubSourceID = nodes[0]
- _spec.Edges = append(_spec.Edges, edge)
- }
- if nodes := mrc.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)
- }
- _node.ContactID = 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.MessageRecords.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.MessageRecordsUpsert) {
- // SetCreatedAt(v+v).
- // }).
- // Exec(ctx)
- func (mrc *MessageRecordsCreate) OnConflict(opts ...sql.ConflictOption) *MessageRecordsUpsertOne {
- mrc.conflict = opts
- return &MessageRecordsUpsertOne{
- create: mrc,
- }
- }
- // OnConflictColumns calls `OnConflict` and configures the columns
- // as conflict target. Using this option is equivalent to using:
- //
- // client.MessageRecords.Create().
- // OnConflict(sql.ConflictColumns(columns...)).
- // Exec(ctx)
- func (mrc *MessageRecordsCreate) OnConflictColumns(columns ...string) *MessageRecordsUpsertOne {
- mrc.conflict = append(mrc.conflict, sql.ConflictColumns(columns...))
- return &MessageRecordsUpsertOne{
- create: mrc,
- }
- }
- type (
- // MessageRecordsUpsertOne is the builder for "upsert"-ing
- // one MessageRecords node.
- MessageRecordsUpsertOne struct {
- create *MessageRecordsCreate
- }
- // MessageRecordsUpsert is the "OnConflict" setter.
- MessageRecordsUpsert struct {
- *sql.UpdateSet
- }
- )
- // SetUpdatedAt sets the "updated_at" field.
- func (u *MessageRecordsUpsert) SetUpdatedAt(v time.Time) *MessageRecordsUpsert {
- u.Set(messagerecords.FieldUpdatedAt, v)
- return u
- }
- // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
- func (u *MessageRecordsUpsert) UpdateUpdatedAt() *MessageRecordsUpsert {
- u.SetExcluded(messagerecords.FieldUpdatedAt)
- return u
- }
- // SetStatus sets the "status" field.
- func (u *MessageRecordsUpsert) SetStatus(v uint8) *MessageRecordsUpsert {
- u.Set(messagerecords.FieldStatus, v)
- return u
- }
- // UpdateStatus sets the "status" field to the value that was provided on create.
- func (u *MessageRecordsUpsert) UpdateStatus() *MessageRecordsUpsert {
- u.SetExcluded(messagerecords.FieldStatus)
- return u
- }
- // AddStatus adds v to the "status" field.
- func (u *MessageRecordsUpsert) AddStatus(v uint8) *MessageRecordsUpsert {
- u.Add(messagerecords.FieldStatus, v)
- return u
- }
- // ClearStatus clears the value of the "status" field.
- func (u *MessageRecordsUpsert) ClearStatus() *MessageRecordsUpsert {
- u.SetNull(messagerecords.FieldStatus)
- return u
- }
- // SetBotWxid sets the "bot_wxid" field.
- func (u *MessageRecordsUpsert) SetBotWxid(v string) *MessageRecordsUpsert {
- u.Set(messagerecords.FieldBotWxid, v)
- return u
- }
- // UpdateBotWxid sets the "bot_wxid" field to the value that was provided on create.
- func (u *MessageRecordsUpsert) UpdateBotWxid() *MessageRecordsUpsert {
- u.SetExcluded(messagerecords.FieldBotWxid)
- return u
- }
- // SetContactID sets the "contact_id" field.
- func (u *MessageRecordsUpsert) SetContactID(v uint64) *MessageRecordsUpsert {
- u.Set(messagerecords.FieldContactID, v)
- return u
- }
- // UpdateContactID sets the "contact_id" field to the value that was provided on create.
- func (u *MessageRecordsUpsert) UpdateContactID() *MessageRecordsUpsert {
- u.SetExcluded(messagerecords.FieldContactID)
- return u
- }
- // ClearContactID clears the value of the "contact_id" field.
- func (u *MessageRecordsUpsert) ClearContactID() *MessageRecordsUpsert {
- u.SetNull(messagerecords.FieldContactID)
- return u
- }
- // SetContactType sets the "contact_type" field.
- func (u *MessageRecordsUpsert) SetContactType(v int) *MessageRecordsUpsert {
- u.Set(messagerecords.FieldContactType, v)
- return u
- }
- // UpdateContactType sets the "contact_type" field to the value that was provided on create.
- func (u *MessageRecordsUpsert) UpdateContactType() *MessageRecordsUpsert {
- u.SetExcluded(messagerecords.FieldContactType)
- return u
- }
- // AddContactType adds v to the "contact_type" field.
- func (u *MessageRecordsUpsert) AddContactType(v int) *MessageRecordsUpsert {
- u.Add(messagerecords.FieldContactType, v)
- return u
- }
- // SetContactWxid sets the "contact_wxid" field.
- func (u *MessageRecordsUpsert) SetContactWxid(v string) *MessageRecordsUpsert {
- u.Set(messagerecords.FieldContactWxid, v)
- return u
- }
- // UpdateContactWxid sets the "contact_wxid" field to the value that was provided on create.
- func (u *MessageRecordsUpsert) UpdateContactWxid() *MessageRecordsUpsert {
- u.SetExcluded(messagerecords.FieldContactWxid)
- return u
- }
- // SetContentType sets the "content_type" field.
- func (u *MessageRecordsUpsert) SetContentType(v int) *MessageRecordsUpsert {
- u.Set(messagerecords.FieldContentType, v)
- return u
- }
- // UpdateContentType sets the "content_type" field to the value that was provided on create.
- func (u *MessageRecordsUpsert) UpdateContentType() *MessageRecordsUpsert {
- u.SetExcluded(messagerecords.FieldContentType)
- return u
- }
- // AddContentType adds v to the "content_type" field.
- func (u *MessageRecordsUpsert) AddContentType(v int) *MessageRecordsUpsert {
- u.Add(messagerecords.FieldContentType, v)
- return u
- }
- // SetContent sets the "content" field.
- func (u *MessageRecordsUpsert) SetContent(v string) *MessageRecordsUpsert {
- u.Set(messagerecords.FieldContent, v)
- return u
- }
- // UpdateContent sets the "content" field to the value that was provided on create.
- func (u *MessageRecordsUpsert) UpdateContent() *MessageRecordsUpsert {
- u.SetExcluded(messagerecords.FieldContent)
- return u
- }
- // SetMeta sets the "meta" field.
- func (u *MessageRecordsUpsert) SetMeta(v custom_types.Meta) *MessageRecordsUpsert {
- u.Set(messagerecords.FieldMeta, v)
- return u
- }
- // UpdateMeta sets the "meta" field to the value that was provided on create.
- func (u *MessageRecordsUpsert) UpdateMeta() *MessageRecordsUpsert {
- u.SetExcluded(messagerecords.FieldMeta)
- return u
- }
- // ClearMeta clears the value of the "meta" field.
- func (u *MessageRecordsUpsert) ClearMeta() *MessageRecordsUpsert {
- u.SetNull(messagerecords.FieldMeta)
- return u
- }
- // SetErrorDetail sets the "error_detail" field.
- func (u *MessageRecordsUpsert) SetErrorDetail(v string) *MessageRecordsUpsert {
- u.Set(messagerecords.FieldErrorDetail, v)
- return u
- }
- // UpdateErrorDetail sets the "error_detail" field to the value that was provided on create.
- func (u *MessageRecordsUpsert) UpdateErrorDetail() *MessageRecordsUpsert {
- u.SetExcluded(messagerecords.FieldErrorDetail)
- return u
- }
- // SetSendTime sets the "send_time" field.
- func (u *MessageRecordsUpsert) SetSendTime(v time.Time) *MessageRecordsUpsert {
- u.Set(messagerecords.FieldSendTime, v)
- return u
- }
- // UpdateSendTime sets the "send_time" field to the value that was provided on create.
- func (u *MessageRecordsUpsert) UpdateSendTime() *MessageRecordsUpsert {
- u.SetExcluded(messagerecords.FieldSendTime)
- return u
- }
- // ClearSendTime clears the value of the "send_time" field.
- func (u *MessageRecordsUpsert) ClearSendTime() *MessageRecordsUpsert {
- u.SetNull(messagerecords.FieldSendTime)
- return u
- }
- // SetSourceType sets the "source_type" field.
- func (u *MessageRecordsUpsert) SetSourceType(v int) *MessageRecordsUpsert {
- u.Set(messagerecords.FieldSourceType, v)
- return u
- }
- // UpdateSourceType sets the "source_type" field to the value that was provided on create.
- func (u *MessageRecordsUpsert) UpdateSourceType() *MessageRecordsUpsert {
- u.SetExcluded(messagerecords.FieldSourceType)
- return u
- }
- // AddSourceType adds v to the "source_type" field.
- func (u *MessageRecordsUpsert) AddSourceType(v int) *MessageRecordsUpsert {
- u.Add(messagerecords.FieldSourceType, v)
- return u
- }
- // SetSourceID sets the "source_id" field.
- func (u *MessageRecordsUpsert) SetSourceID(v uint64) *MessageRecordsUpsert {
- u.Set(messagerecords.FieldSourceID, v)
- return u
- }
- // UpdateSourceID sets the "source_id" field to the value that was provided on create.
- func (u *MessageRecordsUpsert) UpdateSourceID() *MessageRecordsUpsert {
- u.SetExcluded(messagerecords.FieldSourceID)
- return u
- }
- // ClearSourceID clears the value of the "source_id" field.
- func (u *MessageRecordsUpsert) ClearSourceID() *MessageRecordsUpsert {
- u.SetNull(messagerecords.FieldSourceID)
- return u
- }
- // SetSubSourceID sets the "sub_source_id" field.
- func (u *MessageRecordsUpsert) SetSubSourceID(v uint64) *MessageRecordsUpsert {
- u.Set(messagerecords.FieldSubSourceID, v)
- return u
- }
- // UpdateSubSourceID sets the "sub_source_id" field to the value that was provided on create.
- func (u *MessageRecordsUpsert) UpdateSubSourceID() *MessageRecordsUpsert {
- u.SetExcluded(messagerecords.FieldSubSourceID)
- return u
- }
- // ClearSubSourceID clears the value of the "sub_source_id" field.
- func (u *MessageRecordsUpsert) ClearSubSourceID() *MessageRecordsUpsert {
- u.SetNull(messagerecords.FieldSubSourceID)
- return u
- }
- // SetOrganizationID sets the "organization_id" field.
- func (u *MessageRecordsUpsert) SetOrganizationID(v uint64) *MessageRecordsUpsert {
- u.Set(messagerecords.FieldOrganizationID, v)
- return u
- }
- // UpdateOrganizationID sets the "organization_id" field to the value that was provided on create.
- func (u *MessageRecordsUpsert) UpdateOrganizationID() *MessageRecordsUpsert {
- u.SetExcluded(messagerecords.FieldOrganizationID)
- return u
- }
- // AddOrganizationID adds v to the "organization_id" field.
- func (u *MessageRecordsUpsert) AddOrganizationID(v uint64) *MessageRecordsUpsert {
- u.Add(messagerecords.FieldOrganizationID, v)
- return u
- }
- // ClearOrganizationID clears the value of the "organization_id" field.
- func (u *MessageRecordsUpsert) ClearOrganizationID() *MessageRecordsUpsert {
- u.SetNull(messagerecords.FieldOrganizationID)
- return u
- }
- // UpdateNewValues updates the mutable fields using the new values that were set on create except the ID field.
- // Using this option is equivalent to using:
- //
- // client.MessageRecords.Create().
- // OnConflict(
- // sql.ResolveWithNewValues(),
- // sql.ResolveWith(func(u *sql.UpdateSet) {
- // u.SetIgnore(messagerecords.FieldID)
- // }),
- // ).
- // Exec(ctx)
- func (u *MessageRecordsUpsertOne) UpdateNewValues() *MessageRecordsUpsertOne {
- 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.ID(); exists {
- s.SetIgnore(messagerecords.FieldID)
- }
- if _, exists := u.create.mutation.CreatedAt(); exists {
- s.SetIgnore(messagerecords.FieldCreatedAt)
- }
- }))
- return u
- }
- // Ignore sets each column to itself in case of conflict.
- // Using this option is equivalent to using:
- //
- // client.MessageRecords.Create().
- // OnConflict(sql.ResolveWithIgnore()).
- // Exec(ctx)
- func (u *MessageRecordsUpsertOne) Ignore() *MessageRecordsUpsertOne {
- 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 *MessageRecordsUpsertOne) DoNothing() *MessageRecordsUpsertOne {
- u.create.conflict = append(u.create.conflict, sql.DoNothing())
- return u
- }
- // Update allows overriding fields `UPDATE` values. See the MessageRecordsCreate.OnConflict
- // documentation for more info.
- func (u *MessageRecordsUpsertOne) Update(set func(*MessageRecordsUpsert)) *MessageRecordsUpsertOne {
- u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
- set(&MessageRecordsUpsert{UpdateSet: update})
- }))
- return u
- }
- // SetUpdatedAt sets the "updated_at" field.
- func (u *MessageRecordsUpsertOne) SetUpdatedAt(v time.Time) *MessageRecordsUpsertOne {
- return u.Update(func(s *MessageRecordsUpsert) {
- s.SetUpdatedAt(v)
- })
- }
- // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
- func (u *MessageRecordsUpsertOne) UpdateUpdatedAt() *MessageRecordsUpsertOne {
- return u.Update(func(s *MessageRecordsUpsert) {
- s.UpdateUpdatedAt()
- })
- }
- // SetStatus sets the "status" field.
- func (u *MessageRecordsUpsertOne) SetStatus(v uint8) *MessageRecordsUpsertOne {
- return u.Update(func(s *MessageRecordsUpsert) {
- s.SetStatus(v)
- })
- }
- // AddStatus adds v to the "status" field.
- func (u *MessageRecordsUpsertOne) AddStatus(v uint8) *MessageRecordsUpsertOne {
- return u.Update(func(s *MessageRecordsUpsert) {
- s.AddStatus(v)
- })
- }
- // UpdateStatus sets the "status" field to the value that was provided on create.
- func (u *MessageRecordsUpsertOne) UpdateStatus() *MessageRecordsUpsertOne {
- return u.Update(func(s *MessageRecordsUpsert) {
- s.UpdateStatus()
- })
- }
- // ClearStatus clears the value of the "status" field.
- func (u *MessageRecordsUpsertOne) ClearStatus() *MessageRecordsUpsertOne {
- return u.Update(func(s *MessageRecordsUpsert) {
- s.ClearStatus()
- })
- }
- // SetBotWxid sets the "bot_wxid" field.
- func (u *MessageRecordsUpsertOne) SetBotWxid(v string) *MessageRecordsUpsertOne {
- return u.Update(func(s *MessageRecordsUpsert) {
- s.SetBotWxid(v)
- })
- }
- // UpdateBotWxid sets the "bot_wxid" field to the value that was provided on create.
- func (u *MessageRecordsUpsertOne) UpdateBotWxid() *MessageRecordsUpsertOne {
- return u.Update(func(s *MessageRecordsUpsert) {
- s.UpdateBotWxid()
- })
- }
- // SetContactID sets the "contact_id" field.
- func (u *MessageRecordsUpsertOne) SetContactID(v uint64) *MessageRecordsUpsertOne {
- return u.Update(func(s *MessageRecordsUpsert) {
- s.SetContactID(v)
- })
- }
- // UpdateContactID sets the "contact_id" field to the value that was provided on create.
- func (u *MessageRecordsUpsertOne) UpdateContactID() *MessageRecordsUpsertOne {
- return u.Update(func(s *MessageRecordsUpsert) {
- s.UpdateContactID()
- })
- }
- // ClearContactID clears the value of the "contact_id" field.
- func (u *MessageRecordsUpsertOne) ClearContactID() *MessageRecordsUpsertOne {
- return u.Update(func(s *MessageRecordsUpsert) {
- s.ClearContactID()
- })
- }
- // SetContactType sets the "contact_type" field.
- func (u *MessageRecordsUpsertOne) SetContactType(v int) *MessageRecordsUpsertOne {
- return u.Update(func(s *MessageRecordsUpsert) {
- s.SetContactType(v)
- })
- }
- // AddContactType adds v to the "contact_type" field.
- func (u *MessageRecordsUpsertOne) AddContactType(v int) *MessageRecordsUpsertOne {
- return u.Update(func(s *MessageRecordsUpsert) {
- s.AddContactType(v)
- })
- }
- // UpdateContactType sets the "contact_type" field to the value that was provided on create.
- func (u *MessageRecordsUpsertOne) UpdateContactType() *MessageRecordsUpsertOne {
- return u.Update(func(s *MessageRecordsUpsert) {
- s.UpdateContactType()
- })
- }
- // SetContactWxid sets the "contact_wxid" field.
- func (u *MessageRecordsUpsertOne) SetContactWxid(v string) *MessageRecordsUpsertOne {
- return u.Update(func(s *MessageRecordsUpsert) {
- s.SetContactWxid(v)
- })
- }
- // UpdateContactWxid sets the "contact_wxid" field to the value that was provided on create.
- func (u *MessageRecordsUpsertOne) UpdateContactWxid() *MessageRecordsUpsertOne {
- return u.Update(func(s *MessageRecordsUpsert) {
- s.UpdateContactWxid()
- })
- }
- // SetContentType sets the "content_type" field.
- func (u *MessageRecordsUpsertOne) SetContentType(v int) *MessageRecordsUpsertOne {
- return u.Update(func(s *MessageRecordsUpsert) {
- s.SetContentType(v)
- })
- }
- // AddContentType adds v to the "content_type" field.
- func (u *MessageRecordsUpsertOne) AddContentType(v int) *MessageRecordsUpsertOne {
- return u.Update(func(s *MessageRecordsUpsert) {
- s.AddContentType(v)
- })
- }
- // UpdateContentType sets the "content_type" field to the value that was provided on create.
- func (u *MessageRecordsUpsertOne) UpdateContentType() *MessageRecordsUpsertOne {
- return u.Update(func(s *MessageRecordsUpsert) {
- s.UpdateContentType()
- })
- }
- // SetContent sets the "content" field.
- func (u *MessageRecordsUpsertOne) SetContent(v string) *MessageRecordsUpsertOne {
- return u.Update(func(s *MessageRecordsUpsert) {
- s.SetContent(v)
- })
- }
- // UpdateContent sets the "content" field to the value that was provided on create.
- func (u *MessageRecordsUpsertOne) UpdateContent() *MessageRecordsUpsertOne {
- return u.Update(func(s *MessageRecordsUpsert) {
- s.UpdateContent()
- })
- }
- // SetMeta sets the "meta" field.
- func (u *MessageRecordsUpsertOne) SetMeta(v custom_types.Meta) *MessageRecordsUpsertOne {
- return u.Update(func(s *MessageRecordsUpsert) {
- s.SetMeta(v)
- })
- }
- // UpdateMeta sets the "meta" field to the value that was provided on create.
- func (u *MessageRecordsUpsertOne) UpdateMeta() *MessageRecordsUpsertOne {
- return u.Update(func(s *MessageRecordsUpsert) {
- s.UpdateMeta()
- })
- }
- // ClearMeta clears the value of the "meta" field.
- func (u *MessageRecordsUpsertOne) ClearMeta() *MessageRecordsUpsertOne {
- return u.Update(func(s *MessageRecordsUpsert) {
- s.ClearMeta()
- })
- }
- // SetErrorDetail sets the "error_detail" field.
- func (u *MessageRecordsUpsertOne) SetErrorDetail(v string) *MessageRecordsUpsertOne {
- return u.Update(func(s *MessageRecordsUpsert) {
- s.SetErrorDetail(v)
- })
- }
- // UpdateErrorDetail sets the "error_detail" field to the value that was provided on create.
- func (u *MessageRecordsUpsertOne) UpdateErrorDetail() *MessageRecordsUpsertOne {
- return u.Update(func(s *MessageRecordsUpsert) {
- s.UpdateErrorDetail()
- })
- }
- // SetSendTime sets the "send_time" field.
- func (u *MessageRecordsUpsertOne) SetSendTime(v time.Time) *MessageRecordsUpsertOne {
- return u.Update(func(s *MessageRecordsUpsert) {
- s.SetSendTime(v)
- })
- }
- // UpdateSendTime sets the "send_time" field to the value that was provided on create.
- func (u *MessageRecordsUpsertOne) UpdateSendTime() *MessageRecordsUpsertOne {
- return u.Update(func(s *MessageRecordsUpsert) {
- s.UpdateSendTime()
- })
- }
- // ClearSendTime clears the value of the "send_time" field.
- func (u *MessageRecordsUpsertOne) ClearSendTime() *MessageRecordsUpsertOne {
- return u.Update(func(s *MessageRecordsUpsert) {
- s.ClearSendTime()
- })
- }
- // SetSourceType sets the "source_type" field.
- func (u *MessageRecordsUpsertOne) SetSourceType(v int) *MessageRecordsUpsertOne {
- return u.Update(func(s *MessageRecordsUpsert) {
- s.SetSourceType(v)
- })
- }
- // AddSourceType adds v to the "source_type" field.
- func (u *MessageRecordsUpsertOne) AddSourceType(v int) *MessageRecordsUpsertOne {
- return u.Update(func(s *MessageRecordsUpsert) {
- s.AddSourceType(v)
- })
- }
- // UpdateSourceType sets the "source_type" field to the value that was provided on create.
- func (u *MessageRecordsUpsertOne) UpdateSourceType() *MessageRecordsUpsertOne {
- return u.Update(func(s *MessageRecordsUpsert) {
- s.UpdateSourceType()
- })
- }
- // SetSourceID sets the "source_id" field.
- func (u *MessageRecordsUpsertOne) SetSourceID(v uint64) *MessageRecordsUpsertOne {
- return u.Update(func(s *MessageRecordsUpsert) {
- s.SetSourceID(v)
- })
- }
- // UpdateSourceID sets the "source_id" field to the value that was provided on create.
- func (u *MessageRecordsUpsertOne) UpdateSourceID() *MessageRecordsUpsertOne {
- return u.Update(func(s *MessageRecordsUpsert) {
- s.UpdateSourceID()
- })
- }
- // ClearSourceID clears the value of the "source_id" field.
- func (u *MessageRecordsUpsertOne) ClearSourceID() *MessageRecordsUpsertOne {
- return u.Update(func(s *MessageRecordsUpsert) {
- s.ClearSourceID()
- })
- }
- // SetSubSourceID sets the "sub_source_id" field.
- func (u *MessageRecordsUpsertOne) SetSubSourceID(v uint64) *MessageRecordsUpsertOne {
- return u.Update(func(s *MessageRecordsUpsert) {
- s.SetSubSourceID(v)
- })
- }
- // UpdateSubSourceID sets the "sub_source_id" field to the value that was provided on create.
- func (u *MessageRecordsUpsertOne) UpdateSubSourceID() *MessageRecordsUpsertOne {
- return u.Update(func(s *MessageRecordsUpsert) {
- s.UpdateSubSourceID()
- })
- }
- // ClearSubSourceID clears the value of the "sub_source_id" field.
- func (u *MessageRecordsUpsertOne) ClearSubSourceID() *MessageRecordsUpsertOne {
- return u.Update(func(s *MessageRecordsUpsert) {
- s.ClearSubSourceID()
- })
- }
- // SetOrganizationID sets the "organization_id" field.
- func (u *MessageRecordsUpsertOne) SetOrganizationID(v uint64) *MessageRecordsUpsertOne {
- return u.Update(func(s *MessageRecordsUpsert) {
- s.SetOrganizationID(v)
- })
- }
- // AddOrganizationID adds v to the "organization_id" field.
- func (u *MessageRecordsUpsertOne) AddOrganizationID(v uint64) *MessageRecordsUpsertOne {
- return u.Update(func(s *MessageRecordsUpsert) {
- s.AddOrganizationID(v)
- })
- }
- // UpdateOrganizationID sets the "organization_id" field to the value that was provided on create.
- func (u *MessageRecordsUpsertOne) UpdateOrganizationID() *MessageRecordsUpsertOne {
- return u.Update(func(s *MessageRecordsUpsert) {
- s.UpdateOrganizationID()
- })
- }
- // ClearOrganizationID clears the value of the "organization_id" field.
- func (u *MessageRecordsUpsertOne) ClearOrganizationID() *MessageRecordsUpsertOne {
- return u.Update(func(s *MessageRecordsUpsert) {
- s.ClearOrganizationID()
- })
- }
- // Exec executes the query.
- func (u *MessageRecordsUpsertOne) Exec(ctx context.Context) error {
- if len(u.create.conflict) == 0 {
- return errors.New("ent: missing options for MessageRecordsCreate.OnConflict")
- }
- return u.create.Exec(ctx)
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (u *MessageRecordsUpsertOne) 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 *MessageRecordsUpsertOne) ID(ctx context.Context) (id uint64, 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 *MessageRecordsUpsertOne) IDX(ctx context.Context) uint64 {
- id, err := u.ID(ctx)
- if err != nil {
- panic(err)
- }
- return id
- }
- // MessageRecordsCreateBulk is the builder for creating many MessageRecords entities in bulk.
- type MessageRecordsCreateBulk struct {
- config
- err error
- builders []*MessageRecordsCreate
- conflict []sql.ConflictOption
- }
- // 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}
- spec.OnConflict = mrcb.conflict
- // 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)
- }
- }
- // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
- // of the `INSERT` statement. For example:
- //
- // client.MessageRecords.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.MessageRecordsUpsert) {
- // SetCreatedAt(v+v).
- // }).
- // Exec(ctx)
- func (mrcb *MessageRecordsCreateBulk) OnConflict(opts ...sql.ConflictOption) *MessageRecordsUpsertBulk {
- mrcb.conflict = opts
- return &MessageRecordsUpsertBulk{
- create: mrcb,
- }
- }
- // OnConflictColumns calls `OnConflict` and configures the columns
- // as conflict target. Using this option is equivalent to using:
- //
- // client.MessageRecords.Create().
- // OnConflict(sql.ConflictColumns(columns...)).
- // Exec(ctx)
- func (mrcb *MessageRecordsCreateBulk) OnConflictColumns(columns ...string) *MessageRecordsUpsertBulk {
- mrcb.conflict = append(mrcb.conflict, sql.ConflictColumns(columns...))
- return &MessageRecordsUpsertBulk{
- create: mrcb,
- }
- }
- // MessageRecordsUpsertBulk is the builder for "upsert"-ing
- // a bulk of MessageRecords nodes.
- type MessageRecordsUpsertBulk struct {
- create *MessageRecordsCreateBulk
- }
- // UpdateNewValues updates the mutable fields using the new values that
- // were set on create. Using this option is equivalent to using:
- //
- // client.MessageRecords.Create().
- // OnConflict(
- // sql.ResolveWithNewValues(),
- // sql.ResolveWith(func(u *sql.UpdateSet) {
- // u.SetIgnore(messagerecords.FieldID)
- // }),
- // ).
- // Exec(ctx)
- func (u *MessageRecordsUpsertBulk) UpdateNewValues() *MessageRecordsUpsertBulk {
- 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.ID(); exists {
- s.SetIgnore(messagerecords.FieldID)
- }
- if _, exists := b.mutation.CreatedAt(); exists {
- s.SetIgnore(messagerecords.FieldCreatedAt)
- }
- }
- }))
- return u
- }
- // Ignore sets each column to itself in case of conflict.
- // Using this option is equivalent to using:
- //
- // client.MessageRecords.Create().
- // OnConflict(sql.ResolveWithIgnore()).
- // Exec(ctx)
- func (u *MessageRecordsUpsertBulk) Ignore() *MessageRecordsUpsertBulk {
- 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 *MessageRecordsUpsertBulk) DoNothing() *MessageRecordsUpsertBulk {
- u.create.conflict = append(u.create.conflict, sql.DoNothing())
- return u
- }
- // Update allows overriding fields `UPDATE` values. See the MessageRecordsCreateBulk.OnConflict
- // documentation for more info.
- func (u *MessageRecordsUpsertBulk) Update(set func(*MessageRecordsUpsert)) *MessageRecordsUpsertBulk {
- u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
- set(&MessageRecordsUpsert{UpdateSet: update})
- }))
- return u
- }
- // SetUpdatedAt sets the "updated_at" field.
- func (u *MessageRecordsUpsertBulk) SetUpdatedAt(v time.Time) *MessageRecordsUpsertBulk {
- return u.Update(func(s *MessageRecordsUpsert) {
- s.SetUpdatedAt(v)
- })
- }
- // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
- func (u *MessageRecordsUpsertBulk) UpdateUpdatedAt() *MessageRecordsUpsertBulk {
- return u.Update(func(s *MessageRecordsUpsert) {
- s.UpdateUpdatedAt()
- })
- }
- // SetStatus sets the "status" field.
- func (u *MessageRecordsUpsertBulk) SetStatus(v uint8) *MessageRecordsUpsertBulk {
- return u.Update(func(s *MessageRecordsUpsert) {
- s.SetStatus(v)
- })
- }
- // AddStatus adds v to the "status" field.
- func (u *MessageRecordsUpsertBulk) AddStatus(v uint8) *MessageRecordsUpsertBulk {
- return u.Update(func(s *MessageRecordsUpsert) {
- s.AddStatus(v)
- })
- }
- // UpdateStatus sets the "status" field to the value that was provided on create.
- func (u *MessageRecordsUpsertBulk) UpdateStatus() *MessageRecordsUpsertBulk {
- return u.Update(func(s *MessageRecordsUpsert) {
- s.UpdateStatus()
- })
- }
- // ClearStatus clears the value of the "status" field.
- func (u *MessageRecordsUpsertBulk) ClearStatus() *MessageRecordsUpsertBulk {
- return u.Update(func(s *MessageRecordsUpsert) {
- s.ClearStatus()
- })
- }
- // SetBotWxid sets the "bot_wxid" field.
- func (u *MessageRecordsUpsertBulk) SetBotWxid(v string) *MessageRecordsUpsertBulk {
- return u.Update(func(s *MessageRecordsUpsert) {
- s.SetBotWxid(v)
- })
- }
- // UpdateBotWxid sets the "bot_wxid" field to the value that was provided on create.
- func (u *MessageRecordsUpsertBulk) UpdateBotWxid() *MessageRecordsUpsertBulk {
- return u.Update(func(s *MessageRecordsUpsert) {
- s.UpdateBotWxid()
- })
- }
- // SetContactID sets the "contact_id" field.
- func (u *MessageRecordsUpsertBulk) SetContactID(v uint64) *MessageRecordsUpsertBulk {
- return u.Update(func(s *MessageRecordsUpsert) {
- s.SetContactID(v)
- })
- }
- // UpdateContactID sets the "contact_id" field to the value that was provided on create.
- func (u *MessageRecordsUpsertBulk) UpdateContactID() *MessageRecordsUpsertBulk {
- return u.Update(func(s *MessageRecordsUpsert) {
- s.UpdateContactID()
- })
- }
- // ClearContactID clears the value of the "contact_id" field.
- func (u *MessageRecordsUpsertBulk) ClearContactID() *MessageRecordsUpsertBulk {
- return u.Update(func(s *MessageRecordsUpsert) {
- s.ClearContactID()
- })
- }
- // SetContactType sets the "contact_type" field.
- func (u *MessageRecordsUpsertBulk) SetContactType(v int) *MessageRecordsUpsertBulk {
- return u.Update(func(s *MessageRecordsUpsert) {
- s.SetContactType(v)
- })
- }
- // AddContactType adds v to the "contact_type" field.
- func (u *MessageRecordsUpsertBulk) AddContactType(v int) *MessageRecordsUpsertBulk {
- return u.Update(func(s *MessageRecordsUpsert) {
- s.AddContactType(v)
- })
- }
- // UpdateContactType sets the "contact_type" field to the value that was provided on create.
- func (u *MessageRecordsUpsertBulk) UpdateContactType() *MessageRecordsUpsertBulk {
- return u.Update(func(s *MessageRecordsUpsert) {
- s.UpdateContactType()
- })
- }
- // SetContactWxid sets the "contact_wxid" field.
- func (u *MessageRecordsUpsertBulk) SetContactWxid(v string) *MessageRecordsUpsertBulk {
- return u.Update(func(s *MessageRecordsUpsert) {
- s.SetContactWxid(v)
- })
- }
- // UpdateContactWxid sets the "contact_wxid" field to the value that was provided on create.
- func (u *MessageRecordsUpsertBulk) UpdateContactWxid() *MessageRecordsUpsertBulk {
- return u.Update(func(s *MessageRecordsUpsert) {
- s.UpdateContactWxid()
- })
- }
- // SetContentType sets the "content_type" field.
- func (u *MessageRecordsUpsertBulk) SetContentType(v int) *MessageRecordsUpsertBulk {
- return u.Update(func(s *MessageRecordsUpsert) {
- s.SetContentType(v)
- })
- }
- // AddContentType adds v to the "content_type" field.
- func (u *MessageRecordsUpsertBulk) AddContentType(v int) *MessageRecordsUpsertBulk {
- return u.Update(func(s *MessageRecordsUpsert) {
- s.AddContentType(v)
- })
- }
- // UpdateContentType sets the "content_type" field to the value that was provided on create.
- func (u *MessageRecordsUpsertBulk) UpdateContentType() *MessageRecordsUpsertBulk {
- return u.Update(func(s *MessageRecordsUpsert) {
- s.UpdateContentType()
- })
- }
- // SetContent sets the "content" field.
- func (u *MessageRecordsUpsertBulk) SetContent(v string) *MessageRecordsUpsertBulk {
- return u.Update(func(s *MessageRecordsUpsert) {
- s.SetContent(v)
- })
- }
- // UpdateContent sets the "content" field to the value that was provided on create.
- func (u *MessageRecordsUpsertBulk) UpdateContent() *MessageRecordsUpsertBulk {
- return u.Update(func(s *MessageRecordsUpsert) {
- s.UpdateContent()
- })
- }
- // SetMeta sets the "meta" field.
- func (u *MessageRecordsUpsertBulk) SetMeta(v custom_types.Meta) *MessageRecordsUpsertBulk {
- return u.Update(func(s *MessageRecordsUpsert) {
- s.SetMeta(v)
- })
- }
- // UpdateMeta sets the "meta" field to the value that was provided on create.
- func (u *MessageRecordsUpsertBulk) UpdateMeta() *MessageRecordsUpsertBulk {
- return u.Update(func(s *MessageRecordsUpsert) {
- s.UpdateMeta()
- })
- }
- // ClearMeta clears the value of the "meta" field.
- func (u *MessageRecordsUpsertBulk) ClearMeta() *MessageRecordsUpsertBulk {
- return u.Update(func(s *MessageRecordsUpsert) {
- s.ClearMeta()
- })
- }
- // SetErrorDetail sets the "error_detail" field.
- func (u *MessageRecordsUpsertBulk) SetErrorDetail(v string) *MessageRecordsUpsertBulk {
- return u.Update(func(s *MessageRecordsUpsert) {
- s.SetErrorDetail(v)
- })
- }
- // UpdateErrorDetail sets the "error_detail" field to the value that was provided on create.
- func (u *MessageRecordsUpsertBulk) UpdateErrorDetail() *MessageRecordsUpsertBulk {
- return u.Update(func(s *MessageRecordsUpsert) {
- s.UpdateErrorDetail()
- })
- }
- // SetSendTime sets the "send_time" field.
- func (u *MessageRecordsUpsertBulk) SetSendTime(v time.Time) *MessageRecordsUpsertBulk {
- return u.Update(func(s *MessageRecordsUpsert) {
- s.SetSendTime(v)
- })
- }
- // UpdateSendTime sets the "send_time" field to the value that was provided on create.
- func (u *MessageRecordsUpsertBulk) UpdateSendTime() *MessageRecordsUpsertBulk {
- return u.Update(func(s *MessageRecordsUpsert) {
- s.UpdateSendTime()
- })
- }
- // ClearSendTime clears the value of the "send_time" field.
- func (u *MessageRecordsUpsertBulk) ClearSendTime() *MessageRecordsUpsertBulk {
- return u.Update(func(s *MessageRecordsUpsert) {
- s.ClearSendTime()
- })
- }
- // SetSourceType sets the "source_type" field.
- func (u *MessageRecordsUpsertBulk) SetSourceType(v int) *MessageRecordsUpsertBulk {
- return u.Update(func(s *MessageRecordsUpsert) {
- s.SetSourceType(v)
- })
- }
- // AddSourceType adds v to the "source_type" field.
- func (u *MessageRecordsUpsertBulk) AddSourceType(v int) *MessageRecordsUpsertBulk {
- return u.Update(func(s *MessageRecordsUpsert) {
- s.AddSourceType(v)
- })
- }
- // UpdateSourceType sets the "source_type" field to the value that was provided on create.
- func (u *MessageRecordsUpsertBulk) UpdateSourceType() *MessageRecordsUpsertBulk {
- return u.Update(func(s *MessageRecordsUpsert) {
- s.UpdateSourceType()
- })
- }
- // SetSourceID sets the "source_id" field.
- func (u *MessageRecordsUpsertBulk) SetSourceID(v uint64) *MessageRecordsUpsertBulk {
- return u.Update(func(s *MessageRecordsUpsert) {
- s.SetSourceID(v)
- })
- }
- // UpdateSourceID sets the "source_id" field to the value that was provided on create.
- func (u *MessageRecordsUpsertBulk) UpdateSourceID() *MessageRecordsUpsertBulk {
- return u.Update(func(s *MessageRecordsUpsert) {
- s.UpdateSourceID()
- })
- }
- // ClearSourceID clears the value of the "source_id" field.
- func (u *MessageRecordsUpsertBulk) ClearSourceID() *MessageRecordsUpsertBulk {
- return u.Update(func(s *MessageRecordsUpsert) {
- s.ClearSourceID()
- })
- }
- // SetSubSourceID sets the "sub_source_id" field.
- func (u *MessageRecordsUpsertBulk) SetSubSourceID(v uint64) *MessageRecordsUpsertBulk {
- return u.Update(func(s *MessageRecordsUpsert) {
- s.SetSubSourceID(v)
- })
- }
- // UpdateSubSourceID sets the "sub_source_id" field to the value that was provided on create.
- func (u *MessageRecordsUpsertBulk) UpdateSubSourceID() *MessageRecordsUpsertBulk {
- return u.Update(func(s *MessageRecordsUpsert) {
- s.UpdateSubSourceID()
- })
- }
- // ClearSubSourceID clears the value of the "sub_source_id" field.
- func (u *MessageRecordsUpsertBulk) ClearSubSourceID() *MessageRecordsUpsertBulk {
- return u.Update(func(s *MessageRecordsUpsert) {
- s.ClearSubSourceID()
- })
- }
- // SetOrganizationID sets the "organization_id" field.
- func (u *MessageRecordsUpsertBulk) SetOrganizationID(v uint64) *MessageRecordsUpsertBulk {
- return u.Update(func(s *MessageRecordsUpsert) {
- s.SetOrganizationID(v)
- })
- }
- // AddOrganizationID adds v to the "organization_id" field.
- func (u *MessageRecordsUpsertBulk) AddOrganizationID(v uint64) *MessageRecordsUpsertBulk {
- return u.Update(func(s *MessageRecordsUpsert) {
- s.AddOrganizationID(v)
- })
- }
- // UpdateOrganizationID sets the "organization_id" field to the value that was provided on create.
- func (u *MessageRecordsUpsertBulk) UpdateOrganizationID() *MessageRecordsUpsertBulk {
- return u.Update(func(s *MessageRecordsUpsert) {
- s.UpdateOrganizationID()
- })
- }
- // ClearOrganizationID clears the value of the "organization_id" field.
- func (u *MessageRecordsUpsertBulk) ClearOrganizationID() *MessageRecordsUpsertBulk {
- return u.Update(func(s *MessageRecordsUpsert) {
- s.ClearOrganizationID()
- })
- }
- // Exec executes the query.
- func (u *MessageRecordsUpsertBulk) 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 MessageRecordsCreateBulk instead", i)
- }
- }
- if len(u.create.conflict) == 0 {
- return errors.New("ent: missing options for MessageRecordsCreateBulk.OnConflict")
- }
- return u.create.Exec(ctx)
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (u *MessageRecordsUpsertBulk) ExecX(ctx context.Context) {
- if err := u.create.Exec(ctx); err != nil {
- panic(err)
- }
- }
|