12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259 |
- // 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
- }
- // SetCc sets the "cc" field.
- func (mc *MsgCreate) SetCc(s string) *MsgCreate {
- mc.mutation.SetCc(s)
- return mc
- }
- // SetNillableCc sets the "cc" field if the given value is not nil.
- func (mc *MsgCreate) SetNillableCc(s *string) *MsgCreate {
- if s != nil {
- mc.SetCc(*s)
- }
- return mc
- }
- // SetPhone sets the "phone" field.
- func (mc *MsgCreate) SetPhone(s string) *MsgCreate {
- mc.mutation.SetPhone(s)
- return mc
- }
- // SetNillablePhone sets the "phone" field if the given value is not nil.
- func (mc *MsgCreate) SetNillablePhone(s *string) *MsgCreate {
- if s != nil {
- mc.SetPhone(*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)
- }
- if _, ok := mc.mutation.Cc(); !ok {
- v := msg.DefaultCc
- mc.mutation.SetCc(v)
- }
- if _, ok := mc.mutation.Phone(); !ok {
- v := msg.DefaultPhone
- mc.mutation.SetPhone(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"`)}
- }
- if _, ok := mc.mutation.Cc(); !ok {
- return &ValidationError{Name: "cc", err: errors.New(`ent: missing required field "Msg.cc"`)}
- }
- if _, ok := mc.mutation.Phone(); !ok {
- return &ValidationError{Name: "phone", err: errors.New(`ent: missing required field "Msg.phone"`)}
- }
- 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
- }
- if value, ok := mc.mutation.Cc(); ok {
- _spec.SetField(msg.FieldCc, field.TypeString, value)
- _node.Cc = value
- }
- if value, ok := mc.mutation.Phone(); ok {
- _spec.SetField(msg.FieldPhone, field.TypeString, value)
- _node.Phone = 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
- }
- // SetCc sets the "cc" field.
- func (u *MsgUpsert) SetCc(v string) *MsgUpsert {
- u.Set(msg.FieldCc, v)
- return u
- }
- // UpdateCc sets the "cc" field to the value that was provided on create.
- func (u *MsgUpsert) UpdateCc() *MsgUpsert {
- u.SetExcluded(msg.FieldCc)
- return u
- }
- // SetPhone sets the "phone" field.
- func (u *MsgUpsert) SetPhone(v string) *MsgUpsert {
- u.Set(msg.FieldPhone, v)
- return u
- }
- // UpdatePhone sets the "phone" field to the value that was provided on create.
- func (u *MsgUpsert) UpdatePhone() *MsgUpsert {
- u.SetExcluded(msg.FieldPhone)
- 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()
- })
- }
- // SetCc sets the "cc" field.
- func (u *MsgUpsertOne) SetCc(v string) *MsgUpsertOne {
- return u.Update(func(s *MsgUpsert) {
- s.SetCc(v)
- })
- }
- // UpdateCc sets the "cc" field to the value that was provided on create.
- func (u *MsgUpsertOne) UpdateCc() *MsgUpsertOne {
- return u.Update(func(s *MsgUpsert) {
- s.UpdateCc()
- })
- }
- // SetPhone sets the "phone" field.
- func (u *MsgUpsertOne) SetPhone(v string) *MsgUpsertOne {
- return u.Update(func(s *MsgUpsert) {
- s.SetPhone(v)
- })
- }
- // UpdatePhone sets the "phone" field to the value that was provided on create.
- func (u *MsgUpsertOne) UpdatePhone() *MsgUpsertOne {
- return u.Update(func(s *MsgUpsert) {
- s.UpdatePhone()
- })
- }
- // 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()
- })
- }
- // SetCc sets the "cc" field.
- func (u *MsgUpsertBulk) SetCc(v string) *MsgUpsertBulk {
- return u.Update(func(s *MsgUpsert) {
- s.SetCc(v)
- })
- }
- // UpdateCc sets the "cc" field to the value that was provided on create.
- func (u *MsgUpsertBulk) UpdateCc() *MsgUpsertBulk {
- return u.Update(func(s *MsgUpsert) {
- s.UpdateCc()
- })
- }
- // SetPhone sets the "phone" field.
- func (u *MsgUpsertBulk) SetPhone(v string) *MsgUpsertBulk {
- return u.Update(func(s *MsgUpsert) {
- s.SetPhone(v)
- })
- }
- // UpdatePhone sets the "phone" field to the value that was provided on create.
- func (u *MsgUpsertBulk) UpdatePhone() *MsgUpsertBulk {
- return u.Update(func(s *MsgUpsert) {
- s.UpdatePhone()
- })
- }
- // 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)
- }
- }
|