1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645 |
- // 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/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
- }
- // SetDeletedAt sets the "deleted_at" field.
- func (mrc *MessageRecordsCreate) SetDeletedAt(t time.Time) *MessageRecordsCreate {
- mrc.mutation.SetDeletedAt(t)
- return mrc
- }
- // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
- func (mrc *MessageRecordsCreate) SetNillableDeletedAt(t *time.Time) *MessageRecordsCreate {
- if t != nil {
- mrc.SetDeletedAt(*t)
- }
- return mrc
- }
- // SetBotWxid sets the "bot_wxid" field.
- func (mrc *MessageRecordsCreate) SetBotWxid(s string) *MessageRecordsCreate {
- mrc.mutation.SetBotWxid(s)
- return mrc
- }
- // SetContactID sets the "contact_id" field.
- func (mrc *MessageRecordsCreate) SetContactID(u uint64) *MessageRecordsCreate {
- mrc.mutation.SetContactID(u)
- return mrc
- }
- // SetNillableContactID sets the "contact_id" field if the given value is not nil.
- func (mrc *MessageRecordsCreate) SetNillableContactID(u *uint64) *MessageRecordsCreate {
- if u != nil {
- mrc.SetContactID(*u)
- }
- return mrc
- }
- // SetContactType sets the "contact_type" field.
- func (mrc *MessageRecordsCreate) SetContactType(i int) *MessageRecordsCreate {
- mrc.mutation.SetContactType(i)
- return mrc
- }
- // SetNillableContactType sets the "contact_type" field if the given value is not nil.
- func (mrc *MessageRecordsCreate) SetNillableContactType(i *int) *MessageRecordsCreate {
- if i != nil {
- mrc.SetContactType(*i)
- }
- return mrc
- }
- // SetContactWxid sets the "contact_wxid" field.
- func (mrc *MessageRecordsCreate) SetContactWxid(s string) *MessageRecordsCreate {
- mrc.mutation.SetContactWxid(s)
- return mrc
- }
- // SetNillableContactWxid sets the "contact_wxid" field if the given value is not nil.
- func (mrc *MessageRecordsCreate) SetNillableContactWxid(s *string) *MessageRecordsCreate {
- if s != nil {
- mrc.SetContactWxid(*s)
- }
- return mrc
- }
- // SetContentType sets the "content_type" field.
- func (mrc *MessageRecordsCreate) SetContentType(i int) *MessageRecordsCreate {
- mrc.mutation.SetContentType(i)
- return mrc
- }
- // SetNillableContentType sets the "content_type" field if the given value is not nil.
- func (mrc *MessageRecordsCreate) SetNillableContentType(i *int) *MessageRecordsCreate {
- if i != nil {
- mrc.SetContentType(*i)
- }
- return mrc
- }
- // SetContent sets the "content" field.
- func (mrc *MessageRecordsCreate) SetContent(s string) *MessageRecordsCreate {
- mrc.mutation.SetContent(s)
- return mrc
- }
- // SetNillableContent sets the "content" field if the given value is not nil.
- func (mrc *MessageRecordsCreate) SetNillableContent(s *string) *MessageRecordsCreate {
- if s != nil {
- mrc.SetContent(*s)
- }
- return mrc
- }
- // SetErrorDetail sets the "error_detail" field.
- func (mrc *MessageRecordsCreate) SetErrorDetail(s string) *MessageRecordsCreate {
- mrc.mutation.SetErrorDetail(s)
- return mrc
- }
- // SetNillableErrorDetail sets the "error_detail" field if the given value is not nil.
- func (mrc *MessageRecordsCreate) SetNillableErrorDetail(s *string) *MessageRecordsCreate {
- if s != nil {
- mrc.SetErrorDetail(*s)
- }
- return mrc
- }
- // SetSendTime sets the "send_time" field.
- func (mrc *MessageRecordsCreate) SetSendTime(t time.Time) *MessageRecordsCreate {
- mrc.mutation.SetSendTime(t)
- return mrc
- }
- // SetNillableSendTime sets the "send_time" field if the given value is not nil.
- func (mrc *MessageRecordsCreate) SetNillableSendTime(t *time.Time) *MessageRecordsCreate {
- if t != nil {
- mrc.SetSendTime(*t)
- }
- return mrc
- }
- // SetSourceType sets the "source_type" field.
- func (mrc *MessageRecordsCreate) SetSourceType(i int) *MessageRecordsCreate {
- mrc.mutation.SetSourceType(i)
- return mrc
- }
- // SetNillableSourceType sets the "source_type" field if the given value is not nil.
- func (mrc *MessageRecordsCreate) SetNillableSourceType(i *int) *MessageRecordsCreate {
- if i != nil {
- mrc.SetSourceType(*i)
- }
- return mrc
- }
- // SetSourceID sets the "source_id" field.
- func (mrc *MessageRecordsCreate) SetSourceID(u uint64) *MessageRecordsCreate {
- mrc.mutation.SetSourceID(u)
- return mrc
- }
- // SetNillableSourceID sets the "source_id" field if the given value is not nil.
- func (mrc *MessageRecordsCreate) SetNillableSourceID(u *uint64) *MessageRecordsCreate {
- if u != nil {
- mrc.SetSourceID(*u)
- }
- return mrc
- }
- // SetSubSourceID sets the "sub_source_id" field.
- func (mrc *MessageRecordsCreate) SetSubSourceID(u uint64) *MessageRecordsCreate {
- mrc.mutation.SetSubSourceID(u)
- return mrc
- }
- // SetNillableSubSourceID sets the "sub_source_id" field if the given value is not nil.
- func (mrc *MessageRecordsCreate) SetNillableSubSourceID(u *uint64) *MessageRecordsCreate {
- if u != nil {
- mrc.SetSubSourceID(*u)
- }
- return mrc
- }
- // SetID sets the "id" field.
- func (mrc *MessageRecordsCreate) SetID(u uint64) *MessageRecordsCreate {
- mrc.mutation.SetID(u)
- return mrc
- }
- // 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) {
- if err := mrc.defaults(); err != nil {
- return nil, err
- }
- 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() error {
- if _, ok := mrc.mutation.CreatedAt(); !ok {
- if messagerecords.DefaultCreatedAt == nil {
- return fmt.Errorf("ent: uninitialized messagerecords.DefaultCreatedAt (forgotten import ent/runtime?)")
- }
- v := messagerecords.DefaultCreatedAt()
- mrc.mutation.SetCreatedAt(v)
- }
- if _, ok := mrc.mutation.UpdatedAt(); !ok {
- if messagerecords.DefaultUpdatedAt == nil {
- return fmt.Errorf("ent: uninitialized messagerecords.DefaultUpdatedAt (forgotten import ent/runtime?)")
- }
- 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)
- }
- return nil
- }
- // 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.DeletedAt(); ok {
- _spec.SetField(messagerecords.FieldDeletedAt, field.TypeTime, value)
- _node.DeletedAt = 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.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 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
- }
- // SetDeletedAt sets the "deleted_at" field.
- func (u *MessageRecordsUpsert) SetDeletedAt(v time.Time) *MessageRecordsUpsert {
- u.Set(messagerecords.FieldDeletedAt, v)
- return u
- }
- // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
- func (u *MessageRecordsUpsert) UpdateDeletedAt() *MessageRecordsUpsert {
- u.SetExcluded(messagerecords.FieldDeletedAt)
- return u
- }
- // ClearDeletedAt clears the value of the "deleted_at" field.
- func (u *MessageRecordsUpsert) ClearDeletedAt() *MessageRecordsUpsert {
- u.SetNull(messagerecords.FieldDeletedAt)
- 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
- }
- // 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
- }
- // 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()
- })
- }
- // SetDeletedAt sets the "deleted_at" field.
- func (u *MessageRecordsUpsertOne) SetDeletedAt(v time.Time) *MessageRecordsUpsertOne {
- return u.Update(func(s *MessageRecordsUpsert) {
- s.SetDeletedAt(v)
- })
- }
- // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
- func (u *MessageRecordsUpsertOne) UpdateDeletedAt() *MessageRecordsUpsertOne {
- return u.Update(func(s *MessageRecordsUpsert) {
- s.UpdateDeletedAt()
- })
- }
- // ClearDeletedAt clears the value of the "deleted_at" field.
- func (u *MessageRecordsUpsertOne) ClearDeletedAt() *MessageRecordsUpsertOne {
- return u.Update(func(s *MessageRecordsUpsert) {
- s.ClearDeletedAt()
- })
- }
- // 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()
- })
- }
- // 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()
- })
- }
- // 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()
- })
- }
- // SetDeletedAt sets the "deleted_at" field.
- func (u *MessageRecordsUpsertBulk) SetDeletedAt(v time.Time) *MessageRecordsUpsertBulk {
- return u.Update(func(s *MessageRecordsUpsert) {
- s.SetDeletedAt(v)
- })
- }
- // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
- func (u *MessageRecordsUpsertBulk) UpdateDeletedAt() *MessageRecordsUpsertBulk {
- return u.Update(func(s *MessageRecordsUpsert) {
- s.UpdateDeletedAt()
- })
- }
- // ClearDeletedAt clears the value of the "deleted_at" field.
- func (u *MessageRecordsUpsertBulk) ClearDeletedAt() *MessageRecordsUpsertBulk {
- return u.Update(func(s *MessageRecordsUpsert) {
- s.ClearDeletedAt()
- })
- }
- // 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()
- })
- }
- // 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()
- })
- }
- // 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)
- }
- }
|