123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743 |
- // Code generated by ent, DO NOT EDIT.
- package ent
- import (
- "context"
- "errors"
- "fmt"
- "time"
- "wechat-api/ent/wxcard"
- "entgo.io/ent/dialect/sql"
- "entgo.io/ent/dialect/sql/sqlgraph"
- "entgo.io/ent/schema/field"
- )
- // WxCardCreate is the builder for creating a WxCard entity.
- type WxCardCreate struct {
- config
- mutation *WxCardMutation
- hooks []Hook
- conflict []sql.ConflictOption
- }
- // SetCreatedAt sets the "created_at" field.
- func (wcc *WxCardCreate) SetCreatedAt(t time.Time) *WxCardCreate {
- wcc.mutation.SetCreatedAt(t)
- return wcc
- }
- // SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
- func (wcc *WxCardCreate) SetNillableCreatedAt(t *time.Time) *WxCardCreate {
- if t != nil {
- wcc.SetCreatedAt(*t)
- }
- return wcc
- }
- // SetUpdatedAt sets the "updated_at" field.
- func (wcc *WxCardCreate) SetUpdatedAt(t time.Time) *WxCardCreate {
- wcc.mutation.SetUpdatedAt(t)
- return wcc
- }
- // SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
- func (wcc *WxCardCreate) SetNillableUpdatedAt(t *time.Time) *WxCardCreate {
- if t != nil {
- wcc.SetUpdatedAt(*t)
- }
- return wcc
- }
- // SetDeletedAt sets the "deleted_at" field.
- func (wcc *WxCardCreate) SetDeletedAt(t time.Time) *WxCardCreate {
- wcc.mutation.SetDeletedAt(t)
- return wcc
- }
- // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
- func (wcc *WxCardCreate) SetNillableDeletedAt(t *time.Time) *WxCardCreate {
- if t != nil {
- wcc.SetDeletedAt(*t)
- }
- return wcc
- }
- // SetUserID sets the "user_id" field.
- func (wcc *WxCardCreate) SetUserID(u uint64) *WxCardCreate {
- wcc.mutation.SetUserID(u)
- return wcc
- }
- // SetNillableUserID sets the "user_id" field if the given value is not nil.
- func (wcc *WxCardCreate) SetNillableUserID(u *uint64) *WxCardCreate {
- if u != nil {
- wcc.SetUserID(*u)
- }
- return wcc
- }
- // SetWxUserID sets the "wx_user_id" field.
- func (wcc *WxCardCreate) SetWxUserID(u uint64) *WxCardCreate {
- wcc.mutation.SetWxUserID(u)
- return wcc
- }
- // SetNillableWxUserID sets the "wx_user_id" field if the given value is not nil.
- func (wcc *WxCardCreate) SetNillableWxUserID(u *uint64) *WxCardCreate {
- if u != nil {
- wcc.SetWxUserID(*u)
- }
- return wcc
- }
- // SetAvatar sets the "avatar" field.
- func (wcc *WxCardCreate) SetAvatar(s string) *WxCardCreate {
- wcc.mutation.SetAvatar(s)
- return wcc
- }
- // SetNillableAvatar sets the "avatar" field if the given value is not nil.
- func (wcc *WxCardCreate) SetNillableAvatar(s *string) *WxCardCreate {
- if s != nil {
- wcc.SetAvatar(*s)
- }
- return wcc
- }
- // SetLogo sets the "logo" field.
- func (wcc *WxCardCreate) SetLogo(s string) *WxCardCreate {
- wcc.mutation.SetLogo(s)
- return wcc
- }
- // SetNillableLogo sets the "logo" field if the given value is not nil.
- func (wcc *WxCardCreate) SetNillableLogo(s *string) *WxCardCreate {
- if s != nil {
- wcc.SetLogo(*s)
- }
- return wcc
- }
- // SetName sets the "name" field.
- func (wcc *WxCardCreate) SetName(s string) *WxCardCreate {
- wcc.mutation.SetName(s)
- return wcc
- }
- // SetNillableName sets the "name" field if the given value is not nil.
- func (wcc *WxCardCreate) SetNillableName(s *string) *WxCardCreate {
- if s != nil {
- wcc.SetName(*s)
- }
- return wcc
- }
- // SetCompany sets the "company" field.
- func (wcc *WxCardCreate) SetCompany(s string) *WxCardCreate {
- wcc.mutation.SetCompany(s)
- return wcc
- }
- // SetNillableCompany sets the "company" field if the given value is not nil.
- func (wcc *WxCardCreate) SetNillableCompany(s *string) *WxCardCreate {
- if s != nil {
- wcc.SetCompany(*s)
- }
- return wcc
- }
- // SetAddress sets the "address" field.
- func (wcc *WxCardCreate) SetAddress(s string) *WxCardCreate {
- wcc.mutation.SetAddress(s)
- return wcc
- }
- // SetNillableAddress sets the "address" field if the given value is not nil.
- func (wcc *WxCardCreate) SetNillableAddress(s *string) *WxCardCreate {
- if s != nil {
- wcc.SetAddress(*s)
- }
- return wcc
- }
- // SetPhone sets the "phone" field.
- func (wcc *WxCardCreate) SetPhone(s string) *WxCardCreate {
- wcc.mutation.SetPhone(s)
- return wcc
- }
- // SetNillablePhone sets the "phone" field if the given value is not nil.
- func (wcc *WxCardCreate) SetNillablePhone(s *string) *WxCardCreate {
- if s != nil {
- wcc.SetPhone(*s)
- }
- return wcc
- }
- // SetOfficialAccount sets the "official_account" field.
- func (wcc *WxCardCreate) SetOfficialAccount(s string) *WxCardCreate {
- wcc.mutation.SetOfficialAccount(s)
- return wcc
- }
- // SetNillableOfficialAccount sets the "official_account" field if the given value is not nil.
- func (wcc *WxCardCreate) SetNillableOfficialAccount(s *string) *WxCardCreate {
- if s != nil {
- wcc.SetOfficialAccount(*s)
- }
- return wcc
- }
- // SetWechatAccount sets the "wechat_account" field.
- func (wcc *WxCardCreate) SetWechatAccount(s string) *WxCardCreate {
- wcc.mutation.SetWechatAccount(s)
- return wcc
- }
- // SetNillableWechatAccount sets the "wechat_account" field if the given value is not nil.
- func (wcc *WxCardCreate) SetNillableWechatAccount(s *string) *WxCardCreate {
- if s != nil {
- wcc.SetWechatAccount(*s)
- }
- return wcc
- }
- // SetEmail sets the "email" field.
- func (wcc *WxCardCreate) SetEmail(s string) *WxCardCreate {
- wcc.mutation.SetEmail(s)
- return wcc
- }
- // SetNillableEmail sets the "email" field if the given value is not nil.
- func (wcc *WxCardCreate) SetNillableEmail(s *string) *WxCardCreate {
- if s != nil {
- wcc.SetEmail(*s)
- }
- return wcc
- }
- // SetAPIBase sets the "api_base" field.
- func (wcc *WxCardCreate) SetAPIBase(s string) *WxCardCreate {
- wcc.mutation.SetAPIBase(s)
- return wcc
- }
- // SetNillableAPIBase sets the "api_base" field if the given value is not nil.
- func (wcc *WxCardCreate) SetNillableAPIBase(s *string) *WxCardCreate {
- if s != nil {
- wcc.SetAPIBase(*s)
- }
- return wcc
- }
- // SetAPIKey sets the "api_key" field.
- func (wcc *WxCardCreate) SetAPIKey(s string) *WxCardCreate {
- wcc.mutation.SetAPIKey(s)
- return wcc
- }
- // SetNillableAPIKey sets the "api_key" field if the given value is not nil.
- func (wcc *WxCardCreate) SetNillableAPIKey(s *string) *WxCardCreate {
- if s != nil {
- wcc.SetAPIKey(*s)
- }
- return wcc
- }
- // SetAiInfo sets the "ai_info" field.
- func (wcc *WxCardCreate) SetAiInfo(s string) *WxCardCreate {
- wcc.mutation.SetAiInfo(s)
- return wcc
- }
- // SetNillableAiInfo sets the "ai_info" field if the given value is not nil.
- func (wcc *WxCardCreate) SetNillableAiInfo(s *string) *WxCardCreate {
- if s != nil {
- wcc.SetAiInfo(*s)
- }
- return wcc
- }
- // SetIntro sets the "intro" field.
- func (wcc *WxCardCreate) SetIntro(s string) *WxCardCreate {
- wcc.mutation.SetIntro(s)
- return wcc
- }
- // SetNillableIntro sets the "intro" field if the given value is not nil.
- func (wcc *WxCardCreate) SetNillableIntro(s *string) *WxCardCreate {
- if s != nil {
- wcc.SetIntro(*s)
- }
- return wcc
- }
- // SetID sets the "id" field.
- func (wcc *WxCardCreate) SetID(u uint64) *WxCardCreate {
- wcc.mutation.SetID(u)
- return wcc
- }
- // Mutation returns the WxCardMutation object of the builder.
- func (wcc *WxCardCreate) Mutation() *WxCardMutation {
- return wcc.mutation
- }
- // Save creates the WxCard in the database.
- func (wcc *WxCardCreate) Save(ctx context.Context) (*WxCard, error) {
- if err := wcc.defaults(); err != nil {
- return nil, err
- }
- return withHooks(ctx, wcc.sqlSave, wcc.mutation, wcc.hooks)
- }
- // SaveX calls Save and panics if Save returns an error.
- func (wcc *WxCardCreate) SaveX(ctx context.Context) *WxCard {
- v, err := wcc.Save(ctx)
- if err != nil {
- panic(err)
- }
- return v
- }
- // Exec executes the query.
- func (wcc *WxCardCreate) Exec(ctx context.Context) error {
- _, err := wcc.Save(ctx)
- return err
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (wcc *WxCardCreate) ExecX(ctx context.Context) {
- if err := wcc.Exec(ctx); err != nil {
- panic(err)
- }
- }
- // defaults sets the default values of the builder before save.
- func (wcc *WxCardCreate) defaults() error {
- if _, ok := wcc.mutation.CreatedAt(); !ok {
- if wxcard.DefaultCreatedAt == nil {
- return fmt.Errorf("ent: uninitialized wxcard.DefaultCreatedAt (forgotten import ent/runtime?)")
- }
- v := wxcard.DefaultCreatedAt()
- wcc.mutation.SetCreatedAt(v)
- }
- if _, ok := wcc.mutation.UpdatedAt(); !ok {
- if wxcard.DefaultUpdatedAt == nil {
- return fmt.Errorf("ent: uninitialized wxcard.DefaultUpdatedAt (forgotten import ent/runtime?)")
- }
- v := wxcard.DefaultUpdatedAt()
- wcc.mutation.SetUpdatedAt(v)
- }
- if _, ok := wcc.mutation.UserID(); !ok {
- v := wxcard.DefaultUserID
- wcc.mutation.SetUserID(v)
- }
- if _, ok := wcc.mutation.WxUserID(); !ok {
- v := wxcard.DefaultWxUserID
- wcc.mutation.SetWxUserID(v)
- }
- if _, ok := wcc.mutation.Avatar(); !ok {
- v := wxcard.DefaultAvatar
- wcc.mutation.SetAvatar(v)
- }
- if _, ok := wcc.mutation.Logo(); !ok {
- v := wxcard.DefaultLogo
- wcc.mutation.SetLogo(v)
- }
- if _, ok := wcc.mutation.Name(); !ok {
- v := wxcard.DefaultName
- wcc.mutation.SetName(v)
- }
- if _, ok := wcc.mutation.Company(); !ok {
- v := wxcard.DefaultCompany
- wcc.mutation.SetCompany(v)
- }
- if _, ok := wcc.mutation.Address(); !ok {
- v := wxcard.DefaultAddress
- wcc.mutation.SetAddress(v)
- }
- if _, ok := wcc.mutation.Phone(); !ok {
- v := wxcard.DefaultPhone
- wcc.mutation.SetPhone(v)
- }
- if _, ok := wcc.mutation.OfficialAccount(); !ok {
- v := wxcard.DefaultOfficialAccount
- wcc.mutation.SetOfficialAccount(v)
- }
- if _, ok := wcc.mutation.WechatAccount(); !ok {
- v := wxcard.DefaultWechatAccount
- wcc.mutation.SetWechatAccount(v)
- }
- if _, ok := wcc.mutation.Email(); !ok {
- v := wxcard.DefaultEmail
- wcc.mutation.SetEmail(v)
- }
- if _, ok := wcc.mutation.Intro(); !ok {
- v := wxcard.DefaultIntro
- wcc.mutation.SetIntro(v)
- }
- return nil
- }
- // check runs all checks and user-defined validators on the builder.
- func (wcc *WxCardCreate) check() error {
- if _, ok := wcc.mutation.CreatedAt(); !ok {
- return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "WxCard.created_at"`)}
- }
- if _, ok := wcc.mutation.UpdatedAt(); !ok {
- return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "WxCard.updated_at"`)}
- }
- if _, ok := wcc.mutation.Avatar(); !ok {
- return &ValidationError{Name: "avatar", err: errors.New(`ent: missing required field "WxCard.avatar"`)}
- }
- if _, ok := wcc.mutation.Logo(); !ok {
- return &ValidationError{Name: "logo", err: errors.New(`ent: missing required field "WxCard.logo"`)}
- }
- if _, ok := wcc.mutation.Name(); !ok {
- return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "WxCard.name"`)}
- }
- if _, ok := wcc.mutation.Company(); !ok {
- return &ValidationError{Name: "company", err: errors.New(`ent: missing required field "WxCard.company"`)}
- }
- if _, ok := wcc.mutation.Address(); !ok {
- return &ValidationError{Name: "address", err: errors.New(`ent: missing required field "WxCard.address"`)}
- }
- if _, ok := wcc.mutation.Phone(); !ok {
- return &ValidationError{Name: "phone", err: errors.New(`ent: missing required field "WxCard.phone"`)}
- }
- if _, ok := wcc.mutation.OfficialAccount(); !ok {
- return &ValidationError{Name: "official_account", err: errors.New(`ent: missing required field "WxCard.official_account"`)}
- }
- if _, ok := wcc.mutation.WechatAccount(); !ok {
- return &ValidationError{Name: "wechat_account", err: errors.New(`ent: missing required field "WxCard.wechat_account"`)}
- }
- return nil
- }
- func (wcc *WxCardCreate) sqlSave(ctx context.Context) (*WxCard, error) {
- if err := wcc.check(); err != nil {
- return nil, err
- }
- _node, _spec := wcc.createSpec()
- if err := sqlgraph.CreateNode(ctx, wcc.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)
- }
- wcc.mutation.id = &_node.ID
- wcc.mutation.done = true
- return _node, nil
- }
- func (wcc *WxCardCreate) createSpec() (*WxCard, *sqlgraph.CreateSpec) {
- var (
- _node = &WxCard{config: wcc.config}
- _spec = sqlgraph.NewCreateSpec(wxcard.Table, sqlgraph.NewFieldSpec(wxcard.FieldID, field.TypeUint64))
- )
- _spec.OnConflict = wcc.conflict
- if id, ok := wcc.mutation.ID(); ok {
- _node.ID = id
- _spec.ID.Value = id
- }
- if value, ok := wcc.mutation.CreatedAt(); ok {
- _spec.SetField(wxcard.FieldCreatedAt, field.TypeTime, value)
- _node.CreatedAt = value
- }
- if value, ok := wcc.mutation.UpdatedAt(); ok {
- _spec.SetField(wxcard.FieldUpdatedAt, field.TypeTime, value)
- _node.UpdatedAt = value
- }
- if value, ok := wcc.mutation.DeletedAt(); ok {
- _spec.SetField(wxcard.FieldDeletedAt, field.TypeTime, value)
- _node.DeletedAt = value
- }
- if value, ok := wcc.mutation.UserID(); ok {
- _spec.SetField(wxcard.FieldUserID, field.TypeUint64, value)
- _node.UserID = value
- }
- if value, ok := wcc.mutation.WxUserID(); ok {
- _spec.SetField(wxcard.FieldWxUserID, field.TypeUint64, value)
- _node.WxUserID = value
- }
- if value, ok := wcc.mutation.Avatar(); ok {
- _spec.SetField(wxcard.FieldAvatar, field.TypeString, value)
- _node.Avatar = value
- }
- if value, ok := wcc.mutation.Logo(); ok {
- _spec.SetField(wxcard.FieldLogo, field.TypeString, value)
- _node.Logo = value
- }
- if value, ok := wcc.mutation.Name(); ok {
- _spec.SetField(wxcard.FieldName, field.TypeString, value)
- _node.Name = value
- }
- if value, ok := wcc.mutation.Company(); ok {
- _spec.SetField(wxcard.FieldCompany, field.TypeString, value)
- _node.Company = value
- }
- if value, ok := wcc.mutation.Address(); ok {
- _spec.SetField(wxcard.FieldAddress, field.TypeString, value)
- _node.Address = value
- }
- if value, ok := wcc.mutation.Phone(); ok {
- _spec.SetField(wxcard.FieldPhone, field.TypeString, value)
- _node.Phone = value
- }
- if value, ok := wcc.mutation.OfficialAccount(); ok {
- _spec.SetField(wxcard.FieldOfficialAccount, field.TypeString, value)
- _node.OfficialAccount = value
- }
- if value, ok := wcc.mutation.WechatAccount(); ok {
- _spec.SetField(wxcard.FieldWechatAccount, field.TypeString, value)
- _node.WechatAccount = value
- }
- if value, ok := wcc.mutation.Email(); ok {
- _spec.SetField(wxcard.FieldEmail, field.TypeString, value)
- _node.Email = value
- }
- if value, ok := wcc.mutation.APIBase(); ok {
- _spec.SetField(wxcard.FieldAPIBase, field.TypeString, value)
- _node.APIBase = value
- }
- if value, ok := wcc.mutation.APIKey(); ok {
- _spec.SetField(wxcard.FieldAPIKey, field.TypeString, value)
- _node.APIKey = value
- }
- if value, ok := wcc.mutation.AiInfo(); ok {
- _spec.SetField(wxcard.FieldAiInfo, field.TypeString, value)
- _node.AiInfo = value
- }
- if value, ok := wcc.mutation.Intro(); ok {
- _spec.SetField(wxcard.FieldIntro, field.TypeString, value)
- _node.Intro = value
- }
- return _node, _spec
- }
- // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
- // of the `INSERT` statement. For example:
- //
- // client.WxCard.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.WxCardUpsert) {
- // SetCreatedAt(v+v).
- // }).
- // Exec(ctx)
- func (wcc *WxCardCreate) OnConflict(opts ...sql.ConflictOption) *WxCardUpsertOne {
- wcc.conflict = opts
- return &WxCardUpsertOne{
- create: wcc,
- }
- }
- // OnConflictColumns calls `OnConflict` and configures the columns
- // as conflict target. Using this option is equivalent to using:
- //
- // client.WxCard.Create().
- // OnConflict(sql.ConflictColumns(columns...)).
- // Exec(ctx)
- func (wcc *WxCardCreate) OnConflictColumns(columns ...string) *WxCardUpsertOne {
- wcc.conflict = append(wcc.conflict, sql.ConflictColumns(columns...))
- return &WxCardUpsertOne{
- create: wcc,
- }
- }
- type (
- // WxCardUpsertOne is the builder for "upsert"-ing
- // one WxCard node.
- WxCardUpsertOne struct {
- create *WxCardCreate
- }
- // WxCardUpsert is the "OnConflict" setter.
- WxCardUpsert struct {
- *sql.UpdateSet
- }
- )
- // SetUpdatedAt sets the "updated_at" field.
- func (u *WxCardUpsert) SetUpdatedAt(v time.Time) *WxCardUpsert {
- u.Set(wxcard.FieldUpdatedAt, v)
- return u
- }
- // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
- func (u *WxCardUpsert) UpdateUpdatedAt() *WxCardUpsert {
- u.SetExcluded(wxcard.FieldUpdatedAt)
- return u
- }
- // SetDeletedAt sets the "deleted_at" field.
- func (u *WxCardUpsert) SetDeletedAt(v time.Time) *WxCardUpsert {
- u.Set(wxcard.FieldDeletedAt, v)
- return u
- }
- // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
- func (u *WxCardUpsert) UpdateDeletedAt() *WxCardUpsert {
- u.SetExcluded(wxcard.FieldDeletedAt)
- return u
- }
- // ClearDeletedAt clears the value of the "deleted_at" field.
- func (u *WxCardUpsert) ClearDeletedAt() *WxCardUpsert {
- u.SetNull(wxcard.FieldDeletedAt)
- return u
- }
- // SetUserID sets the "user_id" field.
- func (u *WxCardUpsert) SetUserID(v uint64) *WxCardUpsert {
- u.Set(wxcard.FieldUserID, v)
- return u
- }
- // UpdateUserID sets the "user_id" field to the value that was provided on create.
- func (u *WxCardUpsert) UpdateUserID() *WxCardUpsert {
- u.SetExcluded(wxcard.FieldUserID)
- return u
- }
- // AddUserID adds v to the "user_id" field.
- func (u *WxCardUpsert) AddUserID(v uint64) *WxCardUpsert {
- u.Add(wxcard.FieldUserID, v)
- return u
- }
- // ClearUserID clears the value of the "user_id" field.
- func (u *WxCardUpsert) ClearUserID() *WxCardUpsert {
- u.SetNull(wxcard.FieldUserID)
- return u
- }
- // SetWxUserID sets the "wx_user_id" field.
- func (u *WxCardUpsert) SetWxUserID(v uint64) *WxCardUpsert {
- u.Set(wxcard.FieldWxUserID, v)
- return u
- }
- // UpdateWxUserID sets the "wx_user_id" field to the value that was provided on create.
- func (u *WxCardUpsert) UpdateWxUserID() *WxCardUpsert {
- u.SetExcluded(wxcard.FieldWxUserID)
- return u
- }
- // AddWxUserID adds v to the "wx_user_id" field.
- func (u *WxCardUpsert) AddWxUserID(v uint64) *WxCardUpsert {
- u.Add(wxcard.FieldWxUserID, v)
- return u
- }
- // ClearWxUserID clears the value of the "wx_user_id" field.
- func (u *WxCardUpsert) ClearWxUserID() *WxCardUpsert {
- u.SetNull(wxcard.FieldWxUserID)
- return u
- }
- // SetAvatar sets the "avatar" field.
- func (u *WxCardUpsert) SetAvatar(v string) *WxCardUpsert {
- u.Set(wxcard.FieldAvatar, v)
- return u
- }
- // UpdateAvatar sets the "avatar" field to the value that was provided on create.
- func (u *WxCardUpsert) UpdateAvatar() *WxCardUpsert {
- u.SetExcluded(wxcard.FieldAvatar)
- return u
- }
- // SetLogo sets the "logo" field.
- func (u *WxCardUpsert) SetLogo(v string) *WxCardUpsert {
- u.Set(wxcard.FieldLogo, v)
- return u
- }
- // UpdateLogo sets the "logo" field to the value that was provided on create.
- func (u *WxCardUpsert) UpdateLogo() *WxCardUpsert {
- u.SetExcluded(wxcard.FieldLogo)
- return u
- }
- // SetName sets the "name" field.
- func (u *WxCardUpsert) SetName(v string) *WxCardUpsert {
- u.Set(wxcard.FieldName, v)
- return u
- }
- // UpdateName sets the "name" field to the value that was provided on create.
- func (u *WxCardUpsert) UpdateName() *WxCardUpsert {
- u.SetExcluded(wxcard.FieldName)
- return u
- }
- // SetCompany sets the "company" field.
- func (u *WxCardUpsert) SetCompany(v string) *WxCardUpsert {
- u.Set(wxcard.FieldCompany, v)
- return u
- }
- // UpdateCompany sets the "company" field to the value that was provided on create.
- func (u *WxCardUpsert) UpdateCompany() *WxCardUpsert {
- u.SetExcluded(wxcard.FieldCompany)
- return u
- }
- // SetAddress sets the "address" field.
- func (u *WxCardUpsert) SetAddress(v string) *WxCardUpsert {
- u.Set(wxcard.FieldAddress, v)
- return u
- }
- // UpdateAddress sets the "address" field to the value that was provided on create.
- func (u *WxCardUpsert) UpdateAddress() *WxCardUpsert {
- u.SetExcluded(wxcard.FieldAddress)
- return u
- }
- // SetPhone sets the "phone" field.
- func (u *WxCardUpsert) SetPhone(v string) *WxCardUpsert {
- u.Set(wxcard.FieldPhone, v)
- return u
- }
- // UpdatePhone sets the "phone" field to the value that was provided on create.
- func (u *WxCardUpsert) UpdatePhone() *WxCardUpsert {
- u.SetExcluded(wxcard.FieldPhone)
- return u
- }
- // SetOfficialAccount sets the "official_account" field.
- func (u *WxCardUpsert) SetOfficialAccount(v string) *WxCardUpsert {
- u.Set(wxcard.FieldOfficialAccount, v)
- return u
- }
- // UpdateOfficialAccount sets the "official_account" field to the value that was provided on create.
- func (u *WxCardUpsert) UpdateOfficialAccount() *WxCardUpsert {
- u.SetExcluded(wxcard.FieldOfficialAccount)
- return u
- }
- // SetWechatAccount sets the "wechat_account" field.
- func (u *WxCardUpsert) SetWechatAccount(v string) *WxCardUpsert {
- u.Set(wxcard.FieldWechatAccount, v)
- return u
- }
- // UpdateWechatAccount sets the "wechat_account" field to the value that was provided on create.
- func (u *WxCardUpsert) UpdateWechatAccount() *WxCardUpsert {
- u.SetExcluded(wxcard.FieldWechatAccount)
- return u
- }
- // SetEmail sets the "email" field.
- func (u *WxCardUpsert) SetEmail(v string) *WxCardUpsert {
- u.Set(wxcard.FieldEmail, v)
- return u
- }
- // UpdateEmail sets the "email" field to the value that was provided on create.
- func (u *WxCardUpsert) UpdateEmail() *WxCardUpsert {
- u.SetExcluded(wxcard.FieldEmail)
- return u
- }
- // ClearEmail clears the value of the "email" field.
- func (u *WxCardUpsert) ClearEmail() *WxCardUpsert {
- u.SetNull(wxcard.FieldEmail)
- return u
- }
- // SetAPIBase sets the "api_base" field.
- func (u *WxCardUpsert) SetAPIBase(v string) *WxCardUpsert {
- u.Set(wxcard.FieldAPIBase, v)
- return u
- }
- // UpdateAPIBase sets the "api_base" field to the value that was provided on create.
- func (u *WxCardUpsert) UpdateAPIBase() *WxCardUpsert {
- u.SetExcluded(wxcard.FieldAPIBase)
- return u
- }
- // ClearAPIBase clears the value of the "api_base" field.
- func (u *WxCardUpsert) ClearAPIBase() *WxCardUpsert {
- u.SetNull(wxcard.FieldAPIBase)
- return u
- }
- // SetAPIKey sets the "api_key" field.
- func (u *WxCardUpsert) SetAPIKey(v string) *WxCardUpsert {
- u.Set(wxcard.FieldAPIKey, v)
- return u
- }
- // UpdateAPIKey sets the "api_key" field to the value that was provided on create.
- func (u *WxCardUpsert) UpdateAPIKey() *WxCardUpsert {
- u.SetExcluded(wxcard.FieldAPIKey)
- return u
- }
- // ClearAPIKey clears the value of the "api_key" field.
- func (u *WxCardUpsert) ClearAPIKey() *WxCardUpsert {
- u.SetNull(wxcard.FieldAPIKey)
- return u
- }
- // SetAiInfo sets the "ai_info" field.
- func (u *WxCardUpsert) SetAiInfo(v string) *WxCardUpsert {
- u.Set(wxcard.FieldAiInfo, v)
- return u
- }
- // UpdateAiInfo sets the "ai_info" field to the value that was provided on create.
- func (u *WxCardUpsert) UpdateAiInfo() *WxCardUpsert {
- u.SetExcluded(wxcard.FieldAiInfo)
- return u
- }
- // ClearAiInfo clears the value of the "ai_info" field.
- func (u *WxCardUpsert) ClearAiInfo() *WxCardUpsert {
- u.SetNull(wxcard.FieldAiInfo)
- return u
- }
- // SetIntro sets the "intro" field.
- func (u *WxCardUpsert) SetIntro(v string) *WxCardUpsert {
- u.Set(wxcard.FieldIntro, v)
- return u
- }
- // UpdateIntro sets the "intro" field to the value that was provided on create.
- func (u *WxCardUpsert) UpdateIntro() *WxCardUpsert {
- u.SetExcluded(wxcard.FieldIntro)
- return u
- }
- // ClearIntro clears the value of the "intro" field.
- func (u *WxCardUpsert) ClearIntro() *WxCardUpsert {
- u.SetNull(wxcard.FieldIntro)
- 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.WxCard.Create().
- // OnConflict(
- // sql.ResolveWithNewValues(),
- // sql.ResolveWith(func(u *sql.UpdateSet) {
- // u.SetIgnore(wxcard.FieldID)
- // }),
- // ).
- // Exec(ctx)
- func (u *WxCardUpsertOne) UpdateNewValues() *WxCardUpsertOne {
- 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(wxcard.FieldID)
- }
- if _, exists := u.create.mutation.CreatedAt(); exists {
- s.SetIgnore(wxcard.FieldCreatedAt)
- }
- }))
- return u
- }
- // Ignore sets each column to itself in case of conflict.
- // Using this option is equivalent to using:
- //
- // client.WxCard.Create().
- // OnConflict(sql.ResolveWithIgnore()).
- // Exec(ctx)
- func (u *WxCardUpsertOne) Ignore() *WxCardUpsertOne {
- 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 *WxCardUpsertOne) DoNothing() *WxCardUpsertOne {
- u.create.conflict = append(u.create.conflict, sql.DoNothing())
- return u
- }
- // Update allows overriding fields `UPDATE` values. See the WxCardCreate.OnConflict
- // documentation for more info.
- func (u *WxCardUpsertOne) Update(set func(*WxCardUpsert)) *WxCardUpsertOne {
- u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
- set(&WxCardUpsert{UpdateSet: update})
- }))
- return u
- }
- // SetUpdatedAt sets the "updated_at" field.
- func (u *WxCardUpsertOne) SetUpdatedAt(v time.Time) *WxCardUpsertOne {
- return u.Update(func(s *WxCardUpsert) {
- s.SetUpdatedAt(v)
- })
- }
- // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
- func (u *WxCardUpsertOne) UpdateUpdatedAt() *WxCardUpsertOne {
- return u.Update(func(s *WxCardUpsert) {
- s.UpdateUpdatedAt()
- })
- }
- // SetDeletedAt sets the "deleted_at" field.
- func (u *WxCardUpsertOne) SetDeletedAt(v time.Time) *WxCardUpsertOne {
- return u.Update(func(s *WxCardUpsert) {
- s.SetDeletedAt(v)
- })
- }
- // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
- func (u *WxCardUpsertOne) UpdateDeletedAt() *WxCardUpsertOne {
- return u.Update(func(s *WxCardUpsert) {
- s.UpdateDeletedAt()
- })
- }
- // ClearDeletedAt clears the value of the "deleted_at" field.
- func (u *WxCardUpsertOne) ClearDeletedAt() *WxCardUpsertOne {
- return u.Update(func(s *WxCardUpsert) {
- s.ClearDeletedAt()
- })
- }
- // SetUserID sets the "user_id" field.
- func (u *WxCardUpsertOne) SetUserID(v uint64) *WxCardUpsertOne {
- return u.Update(func(s *WxCardUpsert) {
- s.SetUserID(v)
- })
- }
- // AddUserID adds v to the "user_id" field.
- func (u *WxCardUpsertOne) AddUserID(v uint64) *WxCardUpsertOne {
- return u.Update(func(s *WxCardUpsert) {
- s.AddUserID(v)
- })
- }
- // UpdateUserID sets the "user_id" field to the value that was provided on create.
- func (u *WxCardUpsertOne) UpdateUserID() *WxCardUpsertOne {
- return u.Update(func(s *WxCardUpsert) {
- s.UpdateUserID()
- })
- }
- // ClearUserID clears the value of the "user_id" field.
- func (u *WxCardUpsertOne) ClearUserID() *WxCardUpsertOne {
- return u.Update(func(s *WxCardUpsert) {
- s.ClearUserID()
- })
- }
- // SetWxUserID sets the "wx_user_id" field.
- func (u *WxCardUpsertOne) SetWxUserID(v uint64) *WxCardUpsertOne {
- return u.Update(func(s *WxCardUpsert) {
- s.SetWxUserID(v)
- })
- }
- // AddWxUserID adds v to the "wx_user_id" field.
- func (u *WxCardUpsertOne) AddWxUserID(v uint64) *WxCardUpsertOne {
- return u.Update(func(s *WxCardUpsert) {
- s.AddWxUserID(v)
- })
- }
- // UpdateWxUserID sets the "wx_user_id" field to the value that was provided on create.
- func (u *WxCardUpsertOne) UpdateWxUserID() *WxCardUpsertOne {
- return u.Update(func(s *WxCardUpsert) {
- s.UpdateWxUserID()
- })
- }
- // ClearWxUserID clears the value of the "wx_user_id" field.
- func (u *WxCardUpsertOne) ClearWxUserID() *WxCardUpsertOne {
- return u.Update(func(s *WxCardUpsert) {
- s.ClearWxUserID()
- })
- }
- // SetAvatar sets the "avatar" field.
- func (u *WxCardUpsertOne) SetAvatar(v string) *WxCardUpsertOne {
- return u.Update(func(s *WxCardUpsert) {
- s.SetAvatar(v)
- })
- }
- // UpdateAvatar sets the "avatar" field to the value that was provided on create.
- func (u *WxCardUpsertOne) UpdateAvatar() *WxCardUpsertOne {
- return u.Update(func(s *WxCardUpsert) {
- s.UpdateAvatar()
- })
- }
- // SetLogo sets the "logo" field.
- func (u *WxCardUpsertOne) SetLogo(v string) *WxCardUpsertOne {
- return u.Update(func(s *WxCardUpsert) {
- s.SetLogo(v)
- })
- }
- // UpdateLogo sets the "logo" field to the value that was provided on create.
- func (u *WxCardUpsertOne) UpdateLogo() *WxCardUpsertOne {
- return u.Update(func(s *WxCardUpsert) {
- s.UpdateLogo()
- })
- }
- // SetName sets the "name" field.
- func (u *WxCardUpsertOne) SetName(v string) *WxCardUpsertOne {
- return u.Update(func(s *WxCardUpsert) {
- s.SetName(v)
- })
- }
- // UpdateName sets the "name" field to the value that was provided on create.
- func (u *WxCardUpsertOne) UpdateName() *WxCardUpsertOne {
- return u.Update(func(s *WxCardUpsert) {
- s.UpdateName()
- })
- }
- // SetCompany sets the "company" field.
- func (u *WxCardUpsertOne) SetCompany(v string) *WxCardUpsertOne {
- return u.Update(func(s *WxCardUpsert) {
- s.SetCompany(v)
- })
- }
- // UpdateCompany sets the "company" field to the value that was provided on create.
- func (u *WxCardUpsertOne) UpdateCompany() *WxCardUpsertOne {
- return u.Update(func(s *WxCardUpsert) {
- s.UpdateCompany()
- })
- }
- // SetAddress sets the "address" field.
- func (u *WxCardUpsertOne) SetAddress(v string) *WxCardUpsertOne {
- return u.Update(func(s *WxCardUpsert) {
- s.SetAddress(v)
- })
- }
- // UpdateAddress sets the "address" field to the value that was provided on create.
- func (u *WxCardUpsertOne) UpdateAddress() *WxCardUpsertOne {
- return u.Update(func(s *WxCardUpsert) {
- s.UpdateAddress()
- })
- }
- // SetPhone sets the "phone" field.
- func (u *WxCardUpsertOne) SetPhone(v string) *WxCardUpsertOne {
- return u.Update(func(s *WxCardUpsert) {
- s.SetPhone(v)
- })
- }
- // UpdatePhone sets the "phone" field to the value that was provided on create.
- func (u *WxCardUpsertOne) UpdatePhone() *WxCardUpsertOne {
- return u.Update(func(s *WxCardUpsert) {
- s.UpdatePhone()
- })
- }
- // SetOfficialAccount sets the "official_account" field.
- func (u *WxCardUpsertOne) SetOfficialAccount(v string) *WxCardUpsertOne {
- return u.Update(func(s *WxCardUpsert) {
- s.SetOfficialAccount(v)
- })
- }
- // UpdateOfficialAccount sets the "official_account" field to the value that was provided on create.
- func (u *WxCardUpsertOne) UpdateOfficialAccount() *WxCardUpsertOne {
- return u.Update(func(s *WxCardUpsert) {
- s.UpdateOfficialAccount()
- })
- }
- // SetWechatAccount sets the "wechat_account" field.
- func (u *WxCardUpsertOne) SetWechatAccount(v string) *WxCardUpsertOne {
- return u.Update(func(s *WxCardUpsert) {
- s.SetWechatAccount(v)
- })
- }
- // UpdateWechatAccount sets the "wechat_account" field to the value that was provided on create.
- func (u *WxCardUpsertOne) UpdateWechatAccount() *WxCardUpsertOne {
- return u.Update(func(s *WxCardUpsert) {
- s.UpdateWechatAccount()
- })
- }
- // SetEmail sets the "email" field.
- func (u *WxCardUpsertOne) SetEmail(v string) *WxCardUpsertOne {
- return u.Update(func(s *WxCardUpsert) {
- s.SetEmail(v)
- })
- }
- // UpdateEmail sets the "email" field to the value that was provided on create.
- func (u *WxCardUpsertOne) UpdateEmail() *WxCardUpsertOne {
- return u.Update(func(s *WxCardUpsert) {
- s.UpdateEmail()
- })
- }
- // ClearEmail clears the value of the "email" field.
- func (u *WxCardUpsertOne) ClearEmail() *WxCardUpsertOne {
- return u.Update(func(s *WxCardUpsert) {
- s.ClearEmail()
- })
- }
- // SetAPIBase sets the "api_base" field.
- func (u *WxCardUpsertOne) SetAPIBase(v string) *WxCardUpsertOne {
- return u.Update(func(s *WxCardUpsert) {
- s.SetAPIBase(v)
- })
- }
- // UpdateAPIBase sets the "api_base" field to the value that was provided on create.
- func (u *WxCardUpsertOne) UpdateAPIBase() *WxCardUpsertOne {
- return u.Update(func(s *WxCardUpsert) {
- s.UpdateAPIBase()
- })
- }
- // ClearAPIBase clears the value of the "api_base" field.
- func (u *WxCardUpsertOne) ClearAPIBase() *WxCardUpsertOne {
- return u.Update(func(s *WxCardUpsert) {
- s.ClearAPIBase()
- })
- }
- // SetAPIKey sets the "api_key" field.
- func (u *WxCardUpsertOne) SetAPIKey(v string) *WxCardUpsertOne {
- return u.Update(func(s *WxCardUpsert) {
- s.SetAPIKey(v)
- })
- }
- // UpdateAPIKey sets the "api_key" field to the value that was provided on create.
- func (u *WxCardUpsertOne) UpdateAPIKey() *WxCardUpsertOne {
- return u.Update(func(s *WxCardUpsert) {
- s.UpdateAPIKey()
- })
- }
- // ClearAPIKey clears the value of the "api_key" field.
- func (u *WxCardUpsertOne) ClearAPIKey() *WxCardUpsertOne {
- return u.Update(func(s *WxCardUpsert) {
- s.ClearAPIKey()
- })
- }
- // SetAiInfo sets the "ai_info" field.
- func (u *WxCardUpsertOne) SetAiInfo(v string) *WxCardUpsertOne {
- return u.Update(func(s *WxCardUpsert) {
- s.SetAiInfo(v)
- })
- }
- // UpdateAiInfo sets the "ai_info" field to the value that was provided on create.
- func (u *WxCardUpsertOne) UpdateAiInfo() *WxCardUpsertOne {
- return u.Update(func(s *WxCardUpsert) {
- s.UpdateAiInfo()
- })
- }
- // ClearAiInfo clears the value of the "ai_info" field.
- func (u *WxCardUpsertOne) ClearAiInfo() *WxCardUpsertOne {
- return u.Update(func(s *WxCardUpsert) {
- s.ClearAiInfo()
- })
- }
- // SetIntro sets the "intro" field.
- func (u *WxCardUpsertOne) SetIntro(v string) *WxCardUpsertOne {
- return u.Update(func(s *WxCardUpsert) {
- s.SetIntro(v)
- })
- }
- // UpdateIntro sets the "intro" field to the value that was provided on create.
- func (u *WxCardUpsertOne) UpdateIntro() *WxCardUpsertOne {
- return u.Update(func(s *WxCardUpsert) {
- s.UpdateIntro()
- })
- }
- // ClearIntro clears the value of the "intro" field.
- func (u *WxCardUpsertOne) ClearIntro() *WxCardUpsertOne {
- return u.Update(func(s *WxCardUpsert) {
- s.ClearIntro()
- })
- }
- // Exec executes the query.
- func (u *WxCardUpsertOne) Exec(ctx context.Context) error {
- if len(u.create.conflict) == 0 {
- return errors.New("ent: missing options for WxCardCreate.OnConflict")
- }
- return u.create.Exec(ctx)
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (u *WxCardUpsertOne) 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 *WxCardUpsertOne) 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 *WxCardUpsertOne) IDX(ctx context.Context) uint64 {
- id, err := u.ID(ctx)
- if err != nil {
- panic(err)
- }
- return id
- }
- // WxCardCreateBulk is the builder for creating many WxCard entities in bulk.
- type WxCardCreateBulk struct {
- config
- err error
- builders []*WxCardCreate
- conflict []sql.ConflictOption
- }
- // Save creates the WxCard entities in the database.
- func (wccb *WxCardCreateBulk) Save(ctx context.Context) ([]*WxCard, error) {
- if wccb.err != nil {
- return nil, wccb.err
- }
- specs := make([]*sqlgraph.CreateSpec, len(wccb.builders))
- nodes := make([]*WxCard, len(wccb.builders))
- mutators := make([]Mutator, len(wccb.builders))
- for i := range wccb.builders {
- func(i int, root context.Context) {
- builder := wccb.builders[i]
- builder.defaults()
- var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
- mutation, ok := m.(*WxCardMutation)
- 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, wccb.builders[i+1].mutation)
- } else {
- spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
- spec.OnConflict = wccb.conflict
- // Invoke the actual operation on the latest mutation in the chain.
- if err = sqlgraph.BatchCreate(ctx, wccb.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, wccb.builders[0].mutation); err != nil {
- return nil, err
- }
- }
- return nodes, nil
- }
- // SaveX is like Save, but panics if an error occurs.
- func (wccb *WxCardCreateBulk) SaveX(ctx context.Context) []*WxCard {
- v, err := wccb.Save(ctx)
- if err != nil {
- panic(err)
- }
- return v
- }
- // Exec executes the query.
- func (wccb *WxCardCreateBulk) Exec(ctx context.Context) error {
- _, err := wccb.Save(ctx)
- return err
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (wccb *WxCardCreateBulk) ExecX(ctx context.Context) {
- if err := wccb.Exec(ctx); err != nil {
- panic(err)
- }
- }
- // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
- // of the `INSERT` statement. For example:
- //
- // client.WxCard.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.WxCardUpsert) {
- // SetCreatedAt(v+v).
- // }).
- // Exec(ctx)
- func (wccb *WxCardCreateBulk) OnConflict(opts ...sql.ConflictOption) *WxCardUpsertBulk {
- wccb.conflict = opts
- return &WxCardUpsertBulk{
- create: wccb,
- }
- }
- // OnConflictColumns calls `OnConflict` and configures the columns
- // as conflict target. Using this option is equivalent to using:
- //
- // client.WxCard.Create().
- // OnConflict(sql.ConflictColumns(columns...)).
- // Exec(ctx)
- func (wccb *WxCardCreateBulk) OnConflictColumns(columns ...string) *WxCardUpsertBulk {
- wccb.conflict = append(wccb.conflict, sql.ConflictColumns(columns...))
- return &WxCardUpsertBulk{
- create: wccb,
- }
- }
- // WxCardUpsertBulk is the builder for "upsert"-ing
- // a bulk of WxCard nodes.
- type WxCardUpsertBulk struct {
- create *WxCardCreateBulk
- }
- // UpdateNewValues updates the mutable fields using the new values that
- // were set on create. Using this option is equivalent to using:
- //
- // client.WxCard.Create().
- // OnConflict(
- // sql.ResolveWithNewValues(),
- // sql.ResolveWith(func(u *sql.UpdateSet) {
- // u.SetIgnore(wxcard.FieldID)
- // }),
- // ).
- // Exec(ctx)
- func (u *WxCardUpsertBulk) UpdateNewValues() *WxCardUpsertBulk {
- 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(wxcard.FieldID)
- }
- if _, exists := b.mutation.CreatedAt(); exists {
- s.SetIgnore(wxcard.FieldCreatedAt)
- }
- }
- }))
- return u
- }
- // Ignore sets each column to itself in case of conflict.
- // Using this option is equivalent to using:
- //
- // client.WxCard.Create().
- // OnConflict(sql.ResolveWithIgnore()).
- // Exec(ctx)
- func (u *WxCardUpsertBulk) Ignore() *WxCardUpsertBulk {
- 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 *WxCardUpsertBulk) DoNothing() *WxCardUpsertBulk {
- u.create.conflict = append(u.create.conflict, sql.DoNothing())
- return u
- }
- // Update allows overriding fields `UPDATE` values. See the WxCardCreateBulk.OnConflict
- // documentation for more info.
- func (u *WxCardUpsertBulk) Update(set func(*WxCardUpsert)) *WxCardUpsertBulk {
- u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
- set(&WxCardUpsert{UpdateSet: update})
- }))
- return u
- }
- // SetUpdatedAt sets the "updated_at" field.
- func (u *WxCardUpsertBulk) SetUpdatedAt(v time.Time) *WxCardUpsertBulk {
- return u.Update(func(s *WxCardUpsert) {
- s.SetUpdatedAt(v)
- })
- }
- // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
- func (u *WxCardUpsertBulk) UpdateUpdatedAt() *WxCardUpsertBulk {
- return u.Update(func(s *WxCardUpsert) {
- s.UpdateUpdatedAt()
- })
- }
- // SetDeletedAt sets the "deleted_at" field.
- func (u *WxCardUpsertBulk) SetDeletedAt(v time.Time) *WxCardUpsertBulk {
- return u.Update(func(s *WxCardUpsert) {
- s.SetDeletedAt(v)
- })
- }
- // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
- func (u *WxCardUpsertBulk) UpdateDeletedAt() *WxCardUpsertBulk {
- return u.Update(func(s *WxCardUpsert) {
- s.UpdateDeletedAt()
- })
- }
- // ClearDeletedAt clears the value of the "deleted_at" field.
- func (u *WxCardUpsertBulk) ClearDeletedAt() *WxCardUpsertBulk {
- return u.Update(func(s *WxCardUpsert) {
- s.ClearDeletedAt()
- })
- }
- // SetUserID sets the "user_id" field.
- func (u *WxCardUpsertBulk) SetUserID(v uint64) *WxCardUpsertBulk {
- return u.Update(func(s *WxCardUpsert) {
- s.SetUserID(v)
- })
- }
- // AddUserID adds v to the "user_id" field.
- func (u *WxCardUpsertBulk) AddUserID(v uint64) *WxCardUpsertBulk {
- return u.Update(func(s *WxCardUpsert) {
- s.AddUserID(v)
- })
- }
- // UpdateUserID sets the "user_id" field to the value that was provided on create.
- func (u *WxCardUpsertBulk) UpdateUserID() *WxCardUpsertBulk {
- return u.Update(func(s *WxCardUpsert) {
- s.UpdateUserID()
- })
- }
- // ClearUserID clears the value of the "user_id" field.
- func (u *WxCardUpsertBulk) ClearUserID() *WxCardUpsertBulk {
- return u.Update(func(s *WxCardUpsert) {
- s.ClearUserID()
- })
- }
- // SetWxUserID sets the "wx_user_id" field.
- func (u *WxCardUpsertBulk) SetWxUserID(v uint64) *WxCardUpsertBulk {
- return u.Update(func(s *WxCardUpsert) {
- s.SetWxUserID(v)
- })
- }
- // AddWxUserID adds v to the "wx_user_id" field.
- func (u *WxCardUpsertBulk) AddWxUserID(v uint64) *WxCardUpsertBulk {
- return u.Update(func(s *WxCardUpsert) {
- s.AddWxUserID(v)
- })
- }
- // UpdateWxUserID sets the "wx_user_id" field to the value that was provided on create.
- func (u *WxCardUpsertBulk) UpdateWxUserID() *WxCardUpsertBulk {
- return u.Update(func(s *WxCardUpsert) {
- s.UpdateWxUserID()
- })
- }
- // ClearWxUserID clears the value of the "wx_user_id" field.
- func (u *WxCardUpsertBulk) ClearWxUserID() *WxCardUpsertBulk {
- return u.Update(func(s *WxCardUpsert) {
- s.ClearWxUserID()
- })
- }
- // SetAvatar sets the "avatar" field.
- func (u *WxCardUpsertBulk) SetAvatar(v string) *WxCardUpsertBulk {
- return u.Update(func(s *WxCardUpsert) {
- s.SetAvatar(v)
- })
- }
- // UpdateAvatar sets the "avatar" field to the value that was provided on create.
- func (u *WxCardUpsertBulk) UpdateAvatar() *WxCardUpsertBulk {
- return u.Update(func(s *WxCardUpsert) {
- s.UpdateAvatar()
- })
- }
- // SetLogo sets the "logo" field.
- func (u *WxCardUpsertBulk) SetLogo(v string) *WxCardUpsertBulk {
- return u.Update(func(s *WxCardUpsert) {
- s.SetLogo(v)
- })
- }
- // UpdateLogo sets the "logo" field to the value that was provided on create.
- func (u *WxCardUpsertBulk) UpdateLogo() *WxCardUpsertBulk {
- return u.Update(func(s *WxCardUpsert) {
- s.UpdateLogo()
- })
- }
- // SetName sets the "name" field.
- func (u *WxCardUpsertBulk) SetName(v string) *WxCardUpsertBulk {
- return u.Update(func(s *WxCardUpsert) {
- s.SetName(v)
- })
- }
- // UpdateName sets the "name" field to the value that was provided on create.
- func (u *WxCardUpsertBulk) UpdateName() *WxCardUpsertBulk {
- return u.Update(func(s *WxCardUpsert) {
- s.UpdateName()
- })
- }
- // SetCompany sets the "company" field.
- func (u *WxCardUpsertBulk) SetCompany(v string) *WxCardUpsertBulk {
- return u.Update(func(s *WxCardUpsert) {
- s.SetCompany(v)
- })
- }
- // UpdateCompany sets the "company" field to the value that was provided on create.
- func (u *WxCardUpsertBulk) UpdateCompany() *WxCardUpsertBulk {
- return u.Update(func(s *WxCardUpsert) {
- s.UpdateCompany()
- })
- }
- // SetAddress sets the "address" field.
- func (u *WxCardUpsertBulk) SetAddress(v string) *WxCardUpsertBulk {
- return u.Update(func(s *WxCardUpsert) {
- s.SetAddress(v)
- })
- }
- // UpdateAddress sets the "address" field to the value that was provided on create.
- func (u *WxCardUpsertBulk) UpdateAddress() *WxCardUpsertBulk {
- return u.Update(func(s *WxCardUpsert) {
- s.UpdateAddress()
- })
- }
- // SetPhone sets the "phone" field.
- func (u *WxCardUpsertBulk) SetPhone(v string) *WxCardUpsertBulk {
- return u.Update(func(s *WxCardUpsert) {
- s.SetPhone(v)
- })
- }
- // UpdatePhone sets the "phone" field to the value that was provided on create.
- func (u *WxCardUpsertBulk) UpdatePhone() *WxCardUpsertBulk {
- return u.Update(func(s *WxCardUpsert) {
- s.UpdatePhone()
- })
- }
- // SetOfficialAccount sets the "official_account" field.
- func (u *WxCardUpsertBulk) SetOfficialAccount(v string) *WxCardUpsertBulk {
- return u.Update(func(s *WxCardUpsert) {
- s.SetOfficialAccount(v)
- })
- }
- // UpdateOfficialAccount sets the "official_account" field to the value that was provided on create.
- func (u *WxCardUpsertBulk) UpdateOfficialAccount() *WxCardUpsertBulk {
- return u.Update(func(s *WxCardUpsert) {
- s.UpdateOfficialAccount()
- })
- }
- // SetWechatAccount sets the "wechat_account" field.
- func (u *WxCardUpsertBulk) SetWechatAccount(v string) *WxCardUpsertBulk {
- return u.Update(func(s *WxCardUpsert) {
- s.SetWechatAccount(v)
- })
- }
- // UpdateWechatAccount sets the "wechat_account" field to the value that was provided on create.
- func (u *WxCardUpsertBulk) UpdateWechatAccount() *WxCardUpsertBulk {
- return u.Update(func(s *WxCardUpsert) {
- s.UpdateWechatAccount()
- })
- }
- // SetEmail sets the "email" field.
- func (u *WxCardUpsertBulk) SetEmail(v string) *WxCardUpsertBulk {
- return u.Update(func(s *WxCardUpsert) {
- s.SetEmail(v)
- })
- }
- // UpdateEmail sets the "email" field to the value that was provided on create.
- func (u *WxCardUpsertBulk) UpdateEmail() *WxCardUpsertBulk {
- return u.Update(func(s *WxCardUpsert) {
- s.UpdateEmail()
- })
- }
- // ClearEmail clears the value of the "email" field.
- func (u *WxCardUpsertBulk) ClearEmail() *WxCardUpsertBulk {
- return u.Update(func(s *WxCardUpsert) {
- s.ClearEmail()
- })
- }
- // SetAPIBase sets the "api_base" field.
- func (u *WxCardUpsertBulk) SetAPIBase(v string) *WxCardUpsertBulk {
- return u.Update(func(s *WxCardUpsert) {
- s.SetAPIBase(v)
- })
- }
- // UpdateAPIBase sets the "api_base" field to the value that was provided on create.
- func (u *WxCardUpsertBulk) UpdateAPIBase() *WxCardUpsertBulk {
- return u.Update(func(s *WxCardUpsert) {
- s.UpdateAPIBase()
- })
- }
- // ClearAPIBase clears the value of the "api_base" field.
- func (u *WxCardUpsertBulk) ClearAPIBase() *WxCardUpsertBulk {
- return u.Update(func(s *WxCardUpsert) {
- s.ClearAPIBase()
- })
- }
- // SetAPIKey sets the "api_key" field.
- func (u *WxCardUpsertBulk) SetAPIKey(v string) *WxCardUpsertBulk {
- return u.Update(func(s *WxCardUpsert) {
- s.SetAPIKey(v)
- })
- }
- // UpdateAPIKey sets the "api_key" field to the value that was provided on create.
- func (u *WxCardUpsertBulk) UpdateAPIKey() *WxCardUpsertBulk {
- return u.Update(func(s *WxCardUpsert) {
- s.UpdateAPIKey()
- })
- }
- // ClearAPIKey clears the value of the "api_key" field.
- func (u *WxCardUpsertBulk) ClearAPIKey() *WxCardUpsertBulk {
- return u.Update(func(s *WxCardUpsert) {
- s.ClearAPIKey()
- })
- }
- // SetAiInfo sets the "ai_info" field.
- func (u *WxCardUpsertBulk) SetAiInfo(v string) *WxCardUpsertBulk {
- return u.Update(func(s *WxCardUpsert) {
- s.SetAiInfo(v)
- })
- }
- // UpdateAiInfo sets the "ai_info" field to the value that was provided on create.
- func (u *WxCardUpsertBulk) UpdateAiInfo() *WxCardUpsertBulk {
- return u.Update(func(s *WxCardUpsert) {
- s.UpdateAiInfo()
- })
- }
- // ClearAiInfo clears the value of the "ai_info" field.
- func (u *WxCardUpsertBulk) ClearAiInfo() *WxCardUpsertBulk {
- return u.Update(func(s *WxCardUpsert) {
- s.ClearAiInfo()
- })
- }
- // SetIntro sets the "intro" field.
- func (u *WxCardUpsertBulk) SetIntro(v string) *WxCardUpsertBulk {
- return u.Update(func(s *WxCardUpsert) {
- s.SetIntro(v)
- })
- }
- // UpdateIntro sets the "intro" field to the value that was provided on create.
- func (u *WxCardUpsertBulk) UpdateIntro() *WxCardUpsertBulk {
- return u.Update(func(s *WxCardUpsert) {
- s.UpdateIntro()
- })
- }
- // ClearIntro clears the value of the "intro" field.
- func (u *WxCardUpsertBulk) ClearIntro() *WxCardUpsertBulk {
- return u.Update(func(s *WxCardUpsert) {
- s.ClearIntro()
- })
- }
- // Exec executes the query.
- func (u *WxCardUpsertBulk) 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 WxCardCreateBulk instead", i)
- }
- }
- if len(u.create.conflict) == 0 {
- return errors.New("ent: missing options for WxCardCreateBulk.OnConflict")
- }
- return u.create.Exec(ctx)
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (u *WxCardUpsertBulk) ExecX(ctx context.Context) {
- if err := u.create.Exec(ctx); err != nil {
- panic(err)
- }
- }
|