1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129 |
- // Code generated by ent, DO NOT EDIT.
- package ent
- import (
- "context"
- "errors"
- "fmt"
- "time"
- "wechat-api/ent/msg"
- "entgo.io/ent/dialect/sql"
- "entgo.io/ent/dialect/sql/sqlgraph"
- "entgo.io/ent/schema/field"
- )
- // MsgCreate is the builder for creating a Msg entity.
- type MsgCreate struct {
- config
- mutation *MsgMutation
- hooks []Hook
- conflict []sql.ConflictOption
- }
- // SetCreatedAt sets the "created_at" field.
- func (mc *MsgCreate) SetCreatedAt(t time.Time) *MsgCreate {
- mc.mutation.SetCreatedAt(t)
- return mc
- }
- // SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
- func (mc *MsgCreate) SetNillableCreatedAt(t *time.Time) *MsgCreate {
- if t != nil {
- mc.SetCreatedAt(*t)
- }
- return mc
- }
- // SetUpdatedAt sets the "updated_at" field.
- func (mc *MsgCreate) SetUpdatedAt(t time.Time) *MsgCreate {
- mc.mutation.SetUpdatedAt(t)
- return mc
- }
- // SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
- func (mc *MsgCreate) SetNillableUpdatedAt(t *time.Time) *MsgCreate {
- if t != nil {
- mc.SetUpdatedAt(*t)
- }
- return mc
- }
- // SetDeletedAt sets the "deleted_at" field.
- func (mc *MsgCreate) SetDeletedAt(t time.Time) *MsgCreate {
- mc.mutation.SetDeletedAt(t)
- return mc
- }
- // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
- func (mc *MsgCreate) SetNillableDeletedAt(t *time.Time) *MsgCreate {
- if t != nil {
- mc.SetDeletedAt(*t)
- }
- return mc
- }
- // SetStatus sets the "status" field.
- func (mc *MsgCreate) SetStatus(u uint8) *MsgCreate {
- mc.mutation.SetStatus(u)
- return mc
- }
- // SetNillableStatus sets the "status" field if the given value is not nil.
- func (mc *MsgCreate) SetNillableStatus(u *uint8) *MsgCreate {
- if u != nil {
- mc.SetStatus(*u)
- }
- return mc
- }
- // SetFromwxid sets the "fromwxid" field.
- func (mc *MsgCreate) SetFromwxid(s string) *MsgCreate {
- mc.mutation.SetFromwxid(s)
- return mc
- }
- // SetNillableFromwxid sets the "fromwxid" field if the given value is not nil.
- func (mc *MsgCreate) SetNillableFromwxid(s *string) *MsgCreate {
- if s != nil {
- mc.SetFromwxid(*s)
- }
- return mc
- }
- // SetToid sets the "toid" field.
- func (mc *MsgCreate) SetToid(s string) *MsgCreate {
- mc.mutation.SetToid(s)
- return mc
- }
- // SetNillableToid sets the "toid" field if the given value is not nil.
- func (mc *MsgCreate) SetNillableToid(s *string) *MsgCreate {
- if s != nil {
- mc.SetToid(*s)
- }
- return mc
- }
- // SetMsgtype sets the "msgtype" field.
- func (mc *MsgCreate) SetMsgtype(i int32) *MsgCreate {
- mc.mutation.SetMsgtype(i)
- return mc
- }
- // SetNillableMsgtype sets the "msgtype" field if the given value is not nil.
- func (mc *MsgCreate) SetNillableMsgtype(i *int32) *MsgCreate {
- if i != nil {
- mc.SetMsgtype(*i)
- }
- return mc
- }
- // SetMsg sets the "msg" field.
- func (mc *MsgCreate) SetMsg(s string) *MsgCreate {
- mc.mutation.SetMsg(s)
- return mc
- }
- // SetNillableMsg sets the "msg" field if the given value is not nil.
- func (mc *MsgCreate) SetNillableMsg(s *string) *MsgCreate {
- if s != nil {
- mc.SetMsg(*s)
- }
- return mc
- }
- // SetBatchNo sets the "batch_no" field.
- func (mc *MsgCreate) SetBatchNo(s string) *MsgCreate {
- mc.mutation.SetBatchNo(s)
- return mc
- }
- // SetNillableBatchNo sets the "batch_no" field if the given value is not nil.
- func (mc *MsgCreate) SetNillableBatchNo(s *string) *MsgCreate {
- if s != nil {
- mc.SetBatchNo(*s)
- }
- return mc
- }
- // SetID sets the "id" field.
- func (mc *MsgCreate) SetID(u uint64) *MsgCreate {
- mc.mutation.SetID(u)
- return mc
- }
- // Mutation returns the MsgMutation object of the builder.
- func (mc *MsgCreate) Mutation() *MsgMutation {
- return mc.mutation
- }
- // Save creates the Msg in the database.
- func (mc *MsgCreate) Save(ctx context.Context) (*Msg, error) {
- if err := mc.defaults(); err != nil {
- return nil, err
- }
- return withHooks(ctx, mc.sqlSave, mc.mutation, mc.hooks)
- }
- // SaveX calls Save and panics if Save returns an error.
- func (mc *MsgCreate) SaveX(ctx context.Context) *Msg {
- v, err := mc.Save(ctx)
- if err != nil {
- panic(err)
- }
- return v
- }
- // Exec executes the query.
- func (mc *MsgCreate) Exec(ctx context.Context) error {
- _, err := mc.Save(ctx)
- return err
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (mc *MsgCreate) ExecX(ctx context.Context) {
- if err := mc.Exec(ctx); err != nil {
- panic(err)
- }
- }
- // defaults sets the default values of the builder before save.
- func (mc *MsgCreate) defaults() error {
- if _, ok := mc.mutation.CreatedAt(); !ok {
- if msg.DefaultCreatedAt == nil {
- return fmt.Errorf("ent: uninitialized msg.DefaultCreatedAt (forgotten import ent/runtime?)")
- }
- v := msg.DefaultCreatedAt()
- mc.mutation.SetCreatedAt(v)
- }
- if _, ok := mc.mutation.UpdatedAt(); !ok {
- if msg.DefaultUpdatedAt == nil {
- return fmt.Errorf("ent: uninitialized msg.DefaultUpdatedAt (forgotten import ent/runtime?)")
- }
- v := msg.DefaultUpdatedAt()
- mc.mutation.SetUpdatedAt(v)
- }
- return nil
- }
- // check runs all checks and user-defined validators on the builder.
- func (mc *MsgCreate) check() error {
- if _, ok := mc.mutation.CreatedAt(); !ok {
- return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "Msg.created_at"`)}
- }
- if _, ok := mc.mutation.UpdatedAt(); !ok {
- return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "Msg.updated_at"`)}
- }
- return nil
- }
- func (mc *MsgCreate) sqlSave(ctx context.Context) (*Msg, error) {
- if err := mc.check(); err != nil {
- return nil, err
- }
- _node, _spec := mc.createSpec()
- if err := sqlgraph.CreateNode(ctx, mc.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)
- }
- mc.mutation.id = &_node.ID
- mc.mutation.done = true
- return _node, nil
- }
- func (mc *MsgCreate) createSpec() (*Msg, *sqlgraph.CreateSpec) {
- var (
- _node = &Msg{config: mc.config}
- _spec = sqlgraph.NewCreateSpec(msg.Table, sqlgraph.NewFieldSpec(msg.FieldID, field.TypeUint64))
- )
- _spec.OnConflict = mc.conflict
- if id, ok := mc.mutation.ID(); ok {
- _node.ID = id
- _spec.ID.Value = id
- }
- if value, ok := mc.mutation.CreatedAt(); ok {
- _spec.SetField(msg.FieldCreatedAt, field.TypeTime, value)
- _node.CreatedAt = value
- }
- if value, ok := mc.mutation.UpdatedAt(); ok {
- _spec.SetField(msg.FieldUpdatedAt, field.TypeTime, value)
- _node.UpdatedAt = value
- }
- if value, ok := mc.mutation.DeletedAt(); ok {
- _spec.SetField(msg.FieldDeletedAt, field.TypeTime, value)
- _node.DeletedAt = value
- }
- if value, ok := mc.mutation.Status(); ok {
- _spec.SetField(msg.FieldStatus, field.TypeUint8, value)
- _node.Status = value
- }
- if value, ok := mc.mutation.Fromwxid(); ok {
- _spec.SetField(msg.FieldFromwxid, field.TypeString, value)
- _node.Fromwxid = value
- }
- if value, ok := mc.mutation.Toid(); ok {
- _spec.SetField(msg.FieldToid, field.TypeString, value)
- _node.Toid = value
- }
- if value, ok := mc.mutation.Msgtype(); ok {
- _spec.SetField(msg.FieldMsgtype, field.TypeInt32, value)
- _node.Msgtype = value
- }
- if value, ok := mc.mutation.Msg(); ok {
- _spec.SetField(msg.FieldMsg, field.TypeString, value)
- _node.Msg = value
- }
- if value, ok := mc.mutation.BatchNo(); ok {
- _spec.SetField(msg.FieldBatchNo, field.TypeString, value)
- _node.BatchNo = value
- }
- return _node, _spec
- }
- // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
- // of the `INSERT` statement. For example:
- //
- // client.Msg.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.MsgUpsert) {
- // SetCreatedAt(v+v).
- // }).
- // Exec(ctx)
- func (mc *MsgCreate) OnConflict(opts ...sql.ConflictOption) *MsgUpsertOne {
- mc.conflict = opts
- return &MsgUpsertOne{
- create: mc,
- }
- }
- // OnConflictColumns calls `OnConflict` and configures the columns
- // as conflict target. Using this option is equivalent to using:
- //
- // client.Msg.Create().
- // OnConflict(sql.ConflictColumns(columns...)).
- // Exec(ctx)
- func (mc *MsgCreate) OnConflictColumns(columns ...string) *MsgUpsertOne {
- mc.conflict = append(mc.conflict, sql.ConflictColumns(columns...))
- return &MsgUpsertOne{
- create: mc,
- }
- }
- type (
- // MsgUpsertOne is the builder for "upsert"-ing
- // one Msg node.
- MsgUpsertOne struct {
- create *MsgCreate
- }
- // MsgUpsert is the "OnConflict" setter.
- MsgUpsert struct {
- *sql.UpdateSet
- }
- )
- // SetUpdatedAt sets the "updated_at" field.
- func (u *MsgUpsert) SetUpdatedAt(v time.Time) *MsgUpsert {
- u.Set(msg.FieldUpdatedAt, v)
- return u
- }
- // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
- func (u *MsgUpsert) UpdateUpdatedAt() *MsgUpsert {
- u.SetExcluded(msg.FieldUpdatedAt)
- return u
- }
- // SetDeletedAt sets the "deleted_at" field.
- func (u *MsgUpsert) SetDeletedAt(v time.Time) *MsgUpsert {
- u.Set(msg.FieldDeletedAt, v)
- return u
- }
- // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
- func (u *MsgUpsert) UpdateDeletedAt() *MsgUpsert {
- u.SetExcluded(msg.FieldDeletedAt)
- return u
- }
- // ClearDeletedAt clears the value of the "deleted_at" field.
- func (u *MsgUpsert) ClearDeletedAt() *MsgUpsert {
- u.SetNull(msg.FieldDeletedAt)
- return u
- }
- // SetStatus sets the "status" field.
- func (u *MsgUpsert) SetStatus(v uint8) *MsgUpsert {
- u.Set(msg.FieldStatus, v)
- return u
- }
- // UpdateStatus sets the "status" field to the value that was provided on create.
- func (u *MsgUpsert) UpdateStatus() *MsgUpsert {
- u.SetExcluded(msg.FieldStatus)
- return u
- }
- // AddStatus adds v to the "status" field.
- func (u *MsgUpsert) AddStatus(v uint8) *MsgUpsert {
- u.Add(msg.FieldStatus, v)
- return u
- }
- // ClearStatus clears the value of the "status" field.
- func (u *MsgUpsert) ClearStatus() *MsgUpsert {
- u.SetNull(msg.FieldStatus)
- return u
- }
- // SetFromwxid sets the "fromwxid" field.
- func (u *MsgUpsert) SetFromwxid(v string) *MsgUpsert {
- u.Set(msg.FieldFromwxid, v)
- return u
- }
- // UpdateFromwxid sets the "fromwxid" field to the value that was provided on create.
- func (u *MsgUpsert) UpdateFromwxid() *MsgUpsert {
- u.SetExcluded(msg.FieldFromwxid)
- return u
- }
- // ClearFromwxid clears the value of the "fromwxid" field.
- func (u *MsgUpsert) ClearFromwxid() *MsgUpsert {
- u.SetNull(msg.FieldFromwxid)
- return u
- }
- // SetToid sets the "toid" field.
- func (u *MsgUpsert) SetToid(v string) *MsgUpsert {
- u.Set(msg.FieldToid, v)
- return u
- }
- // UpdateToid sets the "toid" field to the value that was provided on create.
- func (u *MsgUpsert) UpdateToid() *MsgUpsert {
- u.SetExcluded(msg.FieldToid)
- return u
- }
- // ClearToid clears the value of the "toid" field.
- func (u *MsgUpsert) ClearToid() *MsgUpsert {
- u.SetNull(msg.FieldToid)
- return u
- }
- // SetMsgtype sets the "msgtype" field.
- func (u *MsgUpsert) SetMsgtype(v int32) *MsgUpsert {
- u.Set(msg.FieldMsgtype, v)
- return u
- }
- // UpdateMsgtype sets the "msgtype" field to the value that was provided on create.
- func (u *MsgUpsert) UpdateMsgtype() *MsgUpsert {
- u.SetExcluded(msg.FieldMsgtype)
- return u
- }
- // AddMsgtype adds v to the "msgtype" field.
- func (u *MsgUpsert) AddMsgtype(v int32) *MsgUpsert {
- u.Add(msg.FieldMsgtype, v)
- return u
- }
- // ClearMsgtype clears the value of the "msgtype" field.
- func (u *MsgUpsert) ClearMsgtype() *MsgUpsert {
- u.SetNull(msg.FieldMsgtype)
- return u
- }
- // SetMsg sets the "msg" field.
- func (u *MsgUpsert) SetMsg(v string) *MsgUpsert {
- u.Set(msg.FieldMsg, v)
- return u
- }
- // UpdateMsg sets the "msg" field to the value that was provided on create.
- func (u *MsgUpsert) UpdateMsg() *MsgUpsert {
- u.SetExcluded(msg.FieldMsg)
- return u
- }
- // ClearMsg clears the value of the "msg" field.
- func (u *MsgUpsert) ClearMsg() *MsgUpsert {
- u.SetNull(msg.FieldMsg)
- return u
- }
- // SetBatchNo sets the "batch_no" field.
- func (u *MsgUpsert) SetBatchNo(v string) *MsgUpsert {
- u.Set(msg.FieldBatchNo, v)
- return u
- }
- // UpdateBatchNo sets the "batch_no" field to the value that was provided on create.
- func (u *MsgUpsert) UpdateBatchNo() *MsgUpsert {
- u.SetExcluded(msg.FieldBatchNo)
- return u
- }
- // ClearBatchNo clears the value of the "batch_no" field.
- func (u *MsgUpsert) ClearBatchNo() *MsgUpsert {
- u.SetNull(msg.FieldBatchNo)
- 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.Msg.Create().
- // OnConflict(
- // sql.ResolveWithNewValues(),
- // sql.ResolveWith(func(u *sql.UpdateSet) {
- // u.SetIgnore(msg.FieldID)
- // }),
- // ).
- // Exec(ctx)
- func (u *MsgUpsertOne) UpdateNewValues() *MsgUpsertOne {
- 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(msg.FieldID)
- }
- if _, exists := u.create.mutation.CreatedAt(); exists {
- s.SetIgnore(msg.FieldCreatedAt)
- }
- }))
- return u
- }
- // Ignore sets each column to itself in case of conflict.
- // Using this option is equivalent to using:
- //
- // client.Msg.Create().
- // OnConflict(sql.ResolveWithIgnore()).
- // Exec(ctx)
- func (u *MsgUpsertOne) Ignore() *MsgUpsertOne {
- 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 *MsgUpsertOne) DoNothing() *MsgUpsertOne {
- u.create.conflict = append(u.create.conflict, sql.DoNothing())
- return u
- }
- // Update allows overriding fields `UPDATE` values. See the MsgCreate.OnConflict
- // documentation for more info.
- func (u *MsgUpsertOne) Update(set func(*MsgUpsert)) *MsgUpsertOne {
- u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
- set(&MsgUpsert{UpdateSet: update})
- }))
- return u
- }
- // SetUpdatedAt sets the "updated_at" field.
- func (u *MsgUpsertOne) SetUpdatedAt(v time.Time) *MsgUpsertOne {
- return u.Update(func(s *MsgUpsert) {
- s.SetUpdatedAt(v)
- })
- }
- // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
- func (u *MsgUpsertOne) UpdateUpdatedAt() *MsgUpsertOne {
- return u.Update(func(s *MsgUpsert) {
- s.UpdateUpdatedAt()
- })
- }
- // SetDeletedAt sets the "deleted_at" field.
- func (u *MsgUpsertOne) SetDeletedAt(v time.Time) *MsgUpsertOne {
- return u.Update(func(s *MsgUpsert) {
- s.SetDeletedAt(v)
- })
- }
- // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
- func (u *MsgUpsertOne) UpdateDeletedAt() *MsgUpsertOne {
- return u.Update(func(s *MsgUpsert) {
- s.UpdateDeletedAt()
- })
- }
- // ClearDeletedAt clears the value of the "deleted_at" field.
- func (u *MsgUpsertOne) ClearDeletedAt() *MsgUpsertOne {
- return u.Update(func(s *MsgUpsert) {
- s.ClearDeletedAt()
- })
- }
- // SetStatus sets the "status" field.
- func (u *MsgUpsertOne) SetStatus(v uint8) *MsgUpsertOne {
- return u.Update(func(s *MsgUpsert) {
- s.SetStatus(v)
- })
- }
- // AddStatus adds v to the "status" field.
- func (u *MsgUpsertOne) AddStatus(v uint8) *MsgUpsertOne {
- return u.Update(func(s *MsgUpsert) {
- s.AddStatus(v)
- })
- }
- // UpdateStatus sets the "status" field to the value that was provided on create.
- func (u *MsgUpsertOne) UpdateStatus() *MsgUpsertOne {
- return u.Update(func(s *MsgUpsert) {
- s.UpdateStatus()
- })
- }
- // ClearStatus clears the value of the "status" field.
- func (u *MsgUpsertOne) ClearStatus() *MsgUpsertOne {
- return u.Update(func(s *MsgUpsert) {
- s.ClearStatus()
- })
- }
- // SetFromwxid sets the "fromwxid" field.
- func (u *MsgUpsertOne) SetFromwxid(v string) *MsgUpsertOne {
- return u.Update(func(s *MsgUpsert) {
- s.SetFromwxid(v)
- })
- }
- // UpdateFromwxid sets the "fromwxid" field to the value that was provided on create.
- func (u *MsgUpsertOne) UpdateFromwxid() *MsgUpsertOne {
- return u.Update(func(s *MsgUpsert) {
- s.UpdateFromwxid()
- })
- }
- // ClearFromwxid clears the value of the "fromwxid" field.
- func (u *MsgUpsertOne) ClearFromwxid() *MsgUpsertOne {
- return u.Update(func(s *MsgUpsert) {
- s.ClearFromwxid()
- })
- }
- // SetToid sets the "toid" field.
- func (u *MsgUpsertOne) SetToid(v string) *MsgUpsertOne {
- return u.Update(func(s *MsgUpsert) {
- s.SetToid(v)
- })
- }
- // UpdateToid sets the "toid" field to the value that was provided on create.
- func (u *MsgUpsertOne) UpdateToid() *MsgUpsertOne {
- return u.Update(func(s *MsgUpsert) {
- s.UpdateToid()
- })
- }
- // ClearToid clears the value of the "toid" field.
- func (u *MsgUpsertOne) ClearToid() *MsgUpsertOne {
- return u.Update(func(s *MsgUpsert) {
- s.ClearToid()
- })
- }
- // SetMsgtype sets the "msgtype" field.
- func (u *MsgUpsertOne) SetMsgtype(v int32) *MsgUpsertOne {
- return u.Update(func(s *MsgUpsert) {
- s.SetMsgtype(v)
- })
- }
- // AddMsgtype adds v to the "msgtype" field.
- func (u *MsgUpsertOne) AddMsgtype(v int32) *MsgUpsertOne {
- return u.Update(func(s *MsgUpsert) {
- s.AddMsgtype(v)
- })
- }
- // UpdateMsgtype sets the "msgtype" field to the value that was provided on create.
- func (u *MsgUpsertOne) UpdateMsgtype() *MsgUpsertOne {
- return u.Update(func(s *MsgUpsert) {
- s.UpdateMsgtype()
- })
- }
- // ClearMsgtype clears the value of the "msgtype" field.
- func (u *MsgUpsertOne) ClearMsgtype() *MsgUpsertOne {
- return u.Update(func(s *MsgUpsert) {
- s.ClearMsgtype()
- })
- }
- // SetMsg sets the "msg" field.
- func (u *MsgUpsertOne) SetMsg(v string) *MsgUpsertOne {
- return u.Update(func(s *MsgUpsert) {
- s.SetMsg(v)
- })
- }
- // UpdateMsg sets the "msg" field to the value that was provided on create.
- func (u *MsgUpsertOne) UpdateMsg() *MsgUpsertOne {
- return u.Update(func(s *MsgUpsert) {
- s.UpdateMsg()
- })
- }
- // ClearMsg clears the value of the "msg" field.
- func (u *MsgUpsertOne) ClearMsg() *MsgUpsertOne {
- return u.Update(func(s *MsgUpsert) {
- s.ClearMsg()
- })
- }
- // SetBatchNo sets the "batch_no" field.
- func (u *MsgUpsertOne) SetBatchNo(v string) *MsgUpsertOne {
- return u.Update(func(s *MsgUpsert) {
- s.SetBatchNo(v)
- })
- }
- // UpdateBatchNo sets the "batch_no" field to the value that was provided on create.
- func (u *MsgUpsertOne) UpdateBatchNo() *MsgUpsertOne {
- return u.Update(func(s *MsgUpsert) {
- s.UpdateBatchNo()
- })
- }
- // ClearBatchNo clears the value of the "batch_no" field.
- func (u *MsgUpsertOne) ClearBatchNo() *MsgUpsertOne {
- return u.Update(func(s *MsgUpsert) {
- s.ClearBatchNo()
- })
- }
- // Exec executes the query.
- func (u *MsgUpsertOne) Exec(ctx context.Context) error {
- if len(u.create.conflict) == 0 {
- return errors.New("ent: missing options for MsgCreate.OnConflict")
- }
- return u.create.Exec(ctx)
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (u *MsgUpsertOne) 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 *MsgUpsertOne) 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 *MsgUpsertOne) IDX(ctx context.Context) uint64 {
- id, err := u.ID(ctx)
- if err != nil {
- panic(err)
- }
- return id
- }
- // MsgCreateBulk is the builder for creating many Msg entities in bulk.
- type MsgCreateBulk struct {
- config
- err error
- builders []*MsgCreate
- conflict []sql.ConflictOption
- }
- // Save creates the Msg entities in the database.
- func (mcb *MsgCreateBulk) Save(ctx context.Context) ([]*Msg, error) {
- if mcb.err != nil {
- return nil, mcb.err
- }
- specs := make([]*sqlgraph.CreateSpec, len(mcb.builders))
- nodes := make([]*Msg, len(mcb.builders))
- mutators := make([]Mutator, len(mcb.builders))
- for i := range mcb.builders {
- func(i int, root context.Context) {
- builder := mcb.builders[i]
- builder.defaults()
- var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
- mutation, ok := m.(*MsgMutation)
- 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, mcb.builders[i+1].mutation)
- } else {
- spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
- spec.OnConflict = mcb.conflict
- // Invoke the actual operation on the latest mutation in the chain.
- if err = sqlgraph.BatchCreate(ctx, mcb.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, mcb.builders[0].mutation); err != nil {
- return nil, err
- }
- }
- return nodes, nil
- }
- // SaveX is like Save, but panics if an error occurs.
- func (mcb *MsgCreateBulk) SaveX(ctx context.Context) []*Msg {
- v, err := mcb.Save(ctx)
- if err != nil {
- panic(err)
- }
- return v
- }
- // Exec executes the query.
- func (mcb *MsgCreateBulk) Exec(ctx context.Context) error {
- _, err := mcb.Save(ctx)
- return err
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (mcb *MsgCreateBulk) ExecX(ctx context.Context) {
- if err := mcb.Exec(ctx); err != nil {
- panic(err)
- }
- }
- // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
- // of the `INSERT` statement. For example:
- //
- // client.Msg.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.MsgUpsert) {
- // SetCreatedAt(v+v).
- // }).
- // Exec(ctx)
- func (mcb *MsgCreateBulk) OnConflict(opts ...sql.ConflictOption) *MsgUpsertBulk {
- mcb.conflict = opts
- return &MsgUpsertBulk{
- create: mcb,
- }
- }
- // OnConflictColumns calls `OnConflict` and configures the columns
- // as conflict target. Using this option is equivalent to using:
- //
- // client.Msg.Create().
- // OnConflict(sql.ConflictColumns(columns...)).
- // Exec(ctx)
- func (mcb *MsgCreateBulk) OnConflictColumns(columns ...string) *MsgUpsertBulk {
- mcb.conflict = append(mcb.conflict, sql.ConflictColumns(columns...))
- return &MsgUpsertBulk{
- create: mcb,
- }
- }
- // MsgUpsertBulk is the builder for "upsert"-ing
- // a bulk of Msg nodes.
- type MsgUpsertBulk struct {
- create *MsgCreateBulk
- }
- // UpdateNewValues updates the mutable fields using the new values that
- // were set on create. Using this option is equivalent to using:
- //
- // client.Msg.Create().
- // OnConflict(
- // sql.ResolveWithNewValues(),
- // sql.ResolveWith(func(u *sql.UpdateSet) {
- // u.SetIgnore(msg.FieldID)
- // }),
- // ).
- // Exec(ctx)
- func (u *MsgUpsertBulk) UpdateNewValues() *MsgUpsertBulk {
- 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(msg.FieldID)
- }
- if _, exists := b.mutation.CreatedAt(); exists {
- s.SetIgnore(msg.FieldCreatedAt)
- }
- }
- }))
- return u
- }
- // Ignore sets each column to itself in case of conflict.
- // Using this option is equivalent to using:
- //
- // client.Msg.Create().
- // OnConflict(sql.ResolveWithIgnore()).
- // Exec(ctx)
- func (u *MsgUpsertBulk) Ignore() *MsgUpsertBulk {
- 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 *MsgUpsertBulk) DoNothing() *MsgUpsertBulk {
- u.create.conflict = append(u.create.conflict, sql.DoNothing())
- return u
- }
- // Update allows overriding fields `UPDATE` values. See the MsgCreateBulk.OnConflict
- // documentation for more info.
- func (u *MsgUpsertBulk) Update(set func(*MsgUpsert)) *MsgUpsertBulk {
- u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
- set(&MsgUpsert{UpdateSet: update})
- }))
- return u
- }
- // SetUpdatedAt sets the "updated_at" field.
- func (u *MsgUpsertBulk) SetUpdatedAt(v time.Time) *MsgUpsertBulk {
- return u.Update(func(s *MsgUpsert) {
- s.SetUpdatedAt(v)
- })
- }
- // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
- func (u *MsgUpsertBulk) UpdateUpdatedAt() *MsgUpsertBulk {
- return u.Update(func(s *MsgUpsert) {
- s.UpdateUpdatedAt()
- })
- }
- // SetDeletedAt sets the "deleted_at" field.
- func (u *MsgUpsertBulk) SetDeletedAt(v time.Time) *MsgUpsertBulk {
- return u.Update(func(s *MsgUpsert) {
- s.SetDeletedAt(v)
- })
- }
- // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
- func (u *MsgUpsertBulk) UpdateDeletedAt() *MsgUpsertBulk {
- return u.Update(func(s *MsgUpsert) {
- s.UpdateDeletedAt()
- })
- }
- // ClearDeletedAt clears the value of the "deleted_at" field.
- func (u *MsgUpsertBulk) ClearDeletedAt() *MsgUpsertBulk {
- return u.Update(func(s *MsgUpsert) {
- s.ClearDeletedAt()
- })
- }
- // SetStatus sets the "status" field.
- func (u *MsgUpsertBulk) SetStatus(v uint8) *MsgUpsertBulk {
- return u.Update(func(s *MsgUpsert) {
- s.SetStatus(v)
- })
- }
- // AddStatus adds v to the "status" field.
- func (u *MsgUpsertBulk) AddStatus(v uint8) *MsgUpsertBulk {
- return u.Update(func(s *MsgUpsert) {
- s.AddStatus(v)
- })
- }
- // UpdateStatus sets the "status" field to the value that was provided on create.
- func (u *MsgUpsertBulk) UpdateStatus() *MsgUpsertBulk {
- return u.Update(func(s *MsgUpsert) {
- s.UpdateStatus()
- })
- }
- // ClearStatus clears the value of the "status" field.
- func (u *MsgUpsertBulk) ClearStatus() *MsgUpsertBulk {
- return u.Update(func(s *MsgUpsert) {
- s.ClearStatus()
- })
- }
- // SetFromwxid sets the "fromwxid" field.
- func (u *MsgUpsertBulk) SetFromwxid(v string) *MsgUpsertBulk {
- return u.Update(func(s *MsgUpsert) {
- s.SetFromwxid(v)
- })
- }
- // UpdateFromwxid sets the "fromwxid" field to the value that was provided on create.
- func (u *MsgUpsertBulk) UpdateFromwxid() *MsgUpsertBulk {
- return u.Update(func(s *MsgUpsert) {
- s.UpdateFromwxid()
- })
- }
- // ClearFromwxid clears the value of the "fromwxid" field.
- func (u *MsgUpsertBulk) ClearFromwxid() *MsgUpsertBulk {
- return u.Update(func(s *MsgUpsert) {
- s.ClearFromwxid()
- })
- }
- // SetToid sets the "toid" field.
- func (u *MsgUpsertBulk) SetToid(v string) *MsgUpsertBulk {
- return u.Update(func(s *MsgUpsert) {
- s.SetToid(v)
- })
- }
- // UpdateToid sets the "toid" field to the value that was provided on create.
- func (u *MsgUpsertBulk) UpdateToid() *MsgUpsertBulk {
- return u.Update(func(s *MsgUpsert) {
- s.UpdateToid()
- })
- }
- // ClearToid clears the value of the "toid" field.
- func (u *MsgUpsertBulk) ClearToid() *MsgUpsertBulk {
- return u.Update(func(s *MsgUpsert) {
- s.ClearToid()
- })
- }
- // SetMsgtype sets the "msgtype" field.
- func (u *MsgUpsertBulk) SetMsgtype(v int32) *MsgUpsertBulk {
- return u.Update(func(s *MsgUpsert) {
- s.SetMsgtype(v)
- })
- }
- // AddMsgtype adds v to the "msgtype" field.
- func (u *MsgUpsertBulk) AddMsgtype(v int32) *MsgUpsertBulk {
- return u.Update(func(s *MsgUpsert) {
- s.AddMsgtype(v)
- })
- }
- // UpdateMsgtype sets the "msgtype" field to the value that was provided on create.
- func (u *MsgUpsertBulk) UpdateMsgtype() *MsgUpsertBulk {
- return u.Update(func(s *MsgUpsert) {
- s.UpdateMsgtype()
- })
- }
- // ClearMsgtype clears the value of the "msgtype" field.
- func (u *MsgUpsertBulk) ClearMsgtype() *MsgUpsertBulk {
- return u.Update(func(s *MsgUpsert) {
- s.ClearMsgtype()
- })
- }
- // SetMsg sets the "msg" field.
- func (u *MsgUpsertBulk) SetMsg(v string) *MsgUpsertBulk {
- return u.Update(func(s *MsgUpsert) {
- s.SetMsg(v)
- })
- }
- // UpdateMsg sets the "msg" field to the value that was provided on create.
- func (u *MsgUpsertBulk) UpdateMsg() *MsgUpsertBulk {
- return u.Update(func(s *MsgUpsert) {
- s.UpdateMsg()
- })
- }
- // ClearMsg clears the value of the "msg" field.
- func (u *MsgUpsertBulk) ClearMsg() *MsgUpsertBulk {
- return u.Update(func(s *MsgUpsert) {
- s.ClearMsg()
- })
- }
- // SetBatchNo sets the "batch_no" field.
- func (u *MsgUpsertBulk) SetBatchNo(v string) *MsgUpsertBulk {
- return u.Update(func(s *MsgUpsert) {
- s.SetBatchNo(v)
- })
- }
- // UpdateBatchNo sets the "batch_no" field to the value that was provided on create.
- func (u *MsgUpsertBulk) UpdateBatchNo() *MsgUpsertBulk {
- return u.Update(func(s *MsgUpsert) {
- s.UpdateBatchNo()
- })
- }
- // ClearBatchNo clears the value of the "batch_no" field.
- func (u *MsgUpsertBulk) ClearBatchNo() *MsgUpsertBulk {
- return u.Update(func(s *MsgUpsert) {
- s.ClearBatchNo()
- })
- }
- // Exec executes the query.
- func (u *MsgUpsertBulk) 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 MsgCreateBulk instead", i)
- }
- }
- if len(u.create.conflict) == 0 {
- return errors.New("ent: missing options for MsgCreateBulk.OnConflict")
- }
- return u.create.Exec(ctx)
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (u *MsgUpsertBulk) ExecX(ctx context.Context) {
- if err := u.create.Exec(ctx); err != nil {
- panic(err)
- }
- }
|