wxcarduser_create.go 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206
  1. // Code generated by ent, DO NOT EDIT.
  2. package ent
  3. import (
  4. "context"
  5. "errors"
  6. "fmt"
  7. "time"
  8. "wechat-api/ent/wxcarduser"
  9. "entgo.io/ent/dialect/sql"
  10. "entgo.io/ent/dialect/sql/sqlgraph"
  11. "entgo.io/ent/schema/field"
  12. )
  13. // WxCardUserCreate is the builder for creating a WxCardUser entity.
  14. type WxCardUserCreate struct {
  15. config
  16. mutation *WxCardUserMutation
  17. hooks []Hook
  18. conflict []sql.ConflictOption
  19. }
  20. // SetCreatedAt sets the "created_at" field.
  21. func (wcuc *WxCardUserCreate) SetCreatedAt(t time.Time) *WxCardUserCreate {
  22. wcuc.mutation.SetCreatedAt(t)
  23. return wcuc
  24. }
  25. // SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
  26. func (wcuc *WxCardUserCreate) SetNillableCreatedAt(t *time.Time) *WxCardUserCreate {
  27. if t != nil {
  28. wcuc.SetCreatedAt(*t)
  29. }
  30. return wcuc
  31. }
  32. // SetUpdatedAt sets the "updated_at" field.
  33. func (wcuc *WxCardUserCreate) SetUpdatedAt(t time.Time) *WxCardUserCreate {
  34. wcuc.mutation.SetUpdatedAt(t)
  35. return wcuc
  36. }
  37. // SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
  38. func (wcuc *WxCardUserCreate) SetNillableUpdatedAt(t *time.Time) *WxCardUserCreate {
  39. if t != nil {
  40. wcuc.SetUpdatedAt(*t)
  41. }
  42. return wcuc
  43. }
  44. // SetDeletedAt sets the "deleted_at" field.
  45. func (wcuc *WxCardUserCreate) SetDeletedAt(t time.Time) *WxCardUserCreate {
  46. wcuc.mutation.SetDeletedAt(t)
  47. return wcuc
  48. }
  49. // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
  50. func (wcuc *WxCardUserCreate) SetNillableDeletedAt(t *time.Time) *WxCardUserCreate {
  51. if t != nil {
  52. wcuc.SetDeletedAt(*t)
  53. }
  54. return wcuc
  55. }
  56. // SetWxid sets the "wxid" field.
  57. func (wcuc *WxCardUserCreate) SetWxid(s string) *WxCardUserCreate {
  58. wcuc.mutation.SetWxid(s)
  59. return wcuc
  60. }
  61. // SetNillableWxid sets the "wxid" field if the given value is not nil.
  62. func (wcuc *WxCardUserCreate) SetNillableWxid(s *string) *WxCardUserCreate {
  63. if s != nil {
  64. wcuc.SetWxid(*s)
  65. }
  66. return wcuc
  67. }
  68. // SetAccount sets the "account" field.
  69. func (wcuc *WxCardUserCreate) SetAccount(s string) *WxCardUserCreate {
  70. wcuc.mutation.SetAccount(s)
  71. return wcuc
  72. }
  73. // SetNillableAccount sets the "account" field if the given value is not nil.
  74. func (wcuc *WxCardUserCreate) SetNillableAccount(s *string) *WxCardUserCreate {
  75. if s != nil {
  76. wcuc.SetAccount(*s)
  77. }
  78. return wcuc
  79. }
  80. // SetAvatar sets the "avatar" field.
  81. func (wcuc *WxCardUserCreate) SetAvatar(s string) *WxCardUserCreate {
  82. wcuc.mutation.SetAvatar(s)
  83. return wcuc
  84. }
  85. // SetNillableAvatar sets the "avatar" field if the given value is not nil.
  86. func (wcuc *WxCardUserCreate) SetNillableAvatar(s *string) *WxCardUserCreate {
  87. if s != nil {
  88. wcuc.SetAvatar(*s)
  89. }
  90. return wcuc
  91. }
  92. // SetNickname sets the "nickname" field.
  93. func (wcuc *WxCardUserCreate) SetNickname(s string) *WxCardUserCreate {
  94. wcuc.mutation.SetNickname(s)
  95. return wcuc
  96. }
  97. // SetNillableNickname sets the "nickname" field if the given value is not nil.
  98. func (wcuc *WxCardUserCreate) SetNillableNickname(s *string) *WxCardUserCreate {
  99. if s != nil {
  100. wcuc.SetNickname(*s)
  101. }
  102. return wcuc
  103. }
  104. // SetRemark sets the "remark" field.
  105. func (wcuc *WxCardUserCreate) SetRemark(s string) *WxCardUserCreate {
  106. wcuc.mutation.SetRemark(s)
  107. return wcuc
  108. }
  109. // SetNillableRemark sets the "remark" field if the given value is not nil.
  110. func (wcuc *WxCardUserCreate) SetNillableRemark(s *string) *WxCardUserCreate {
  111. if s != nil {
  112. wcuc.SetRemark(*s)
  113. }
  114. return wcuc
  115. }
  116. // SetPhone sets the "phone" field.
  117. func (wcuc *WxCardUserCreate) SetPhone(s string) *WxCardUserCreate {
  118. wcuc.mutation.SetPhone(s)
  119. return wcuc
  120. }
  121. // SetNillablePhone sets the "phone" field if the given value is not nil.
  122. func (wcuc *WxCardUserCreate) SetNillablePhone(s *string) *WxCardUserCreate {
  123. if s != nil {
  124. wcuc.SetPhone(*s)
  125. }
  126. return wcuc
  127. }
  128. // SetOpenID sets the "open_id" field.
  129. func (wcuc *WxCardUserCreate) SetOpenID(s string) *WxCardUserCreate {
  130. wcuc.mutation.SetOpenID(s)
  131. return wcuc
  132. }
  133. // SetNillableOpenID sets the "open_id" field if the given value is not nil.
  134. func (wcuc *WxCardUserCreate) SetNillableOpenID(s *string) *WxCardUserCreate {
  135. if s != nil {
  136. wcuc.SetOpenID(*s)
  137. }
  138. return wcuc
  139. }
  140. // SetUnionID sets the "union_id" field.
  141. func (wcuc *WxCardUserCreate) SetUnionID(s string) *WxCardUserCreate {
  142. wcuc.mutation.SetUnionID(s)
  143. return wcuc
  144. }
  145. // SetNillableUnionID sets the "union_id" field if the given value is not nil.
  146. func (wcuc *WxCardUserCreate) SetNillableUnionID(s *string) *WxCardUserCreate {
  147. if s != nil {
  148. wcuc.SetUnionID(*s)
  149. }
  150. return wcuc
  151. }
  152. // SetSessionKey sets the "session_key" field.
  153. func (wcuc *WxCardUserCreate) SetSessionKey(s string) *WxCardUserCreate {
  154. wcuc.mutation.SetSessionKey(s)
  155. return wcuc
  156. }
  157. // SetNillableSessionKey sets the "session_key" field if the given value is not nil.
  158. func (wcuc *WxCardUserCreate) SetNillableSessionKey(s *string) *WxCardUserCreate {
  159. if s != nil {
  160. wcuc.SetSessionKey(*s)
  161. }
  162. return wcuc
  163. }
  164. // SetID sets the "id" field.
  165. func (wcuc *WxCardUserCreate) SetID(u uint64) *WxCardUserCreate {
  166. wcuc.mutation.SetID(u)
  167. return wcuc
  168. }
  169. // Mutation returns the WxCardUserMutation object of the builder.
  170. func (wcuc *WxCardUserCreate) Mutation() *WxCardUserMutation {
  171. return wcuc.mutation
  172. }
  173. // Save creates the WxCardUser in the database.
  174. func (wcuc *WxCardUserCreate) Save(ctx context.Context) (*WxCardUser, error) {
  175. if err := wcuc.defaults(); err != nil {
  176. return nil, err
  177. }
  178. return withHooks(ctx, wcuc.sqlSave, wcuc.mutation, wcuc.hooks)
  179. }
  180. // SaveX calls Save and panics if Save returns an error.
  181. func (wcuc *WxCardUserCreate) SaveX(ctx context.Context) *WxCardUser {
  182. v, err := wcuc.Save(ctx)
  183. if err != nil {
  184. panic(err)
  185. }
  186. return v
  187. }
  188. // Exec executes the query.
  189. func (wcuc *WxCardUserCreate) Exec(ctx context.Context) error {
  190. _, err := wcuc.Save(ctx)
  191. return err
  192. }
  193. // ExecX is like Exec, but panics if an error occurs.
  194. func (wcuc *WxCardUserCreate) ExecX(ctx context.Context) {
  195. if err := wcuc.Exec(ctx); err != nil {
  196. panic(err)
  197. }
  198. }
  199. // defaults sets the default values of the builder before save.
  200. func (wcuc *WxCardUserCreate) defaults() error {
  201. if _, ok := wcuc.mutation.CreatedAt(); !ok {
  202. if wxcarduser.DefaultCreatedAt == nil {
  203. return fmt.Errorf("ent: uninitialized wxcarduser.DefaultCreatedAt (forgotten import ent/runtime?)")
  204. }
  205. v := wxcarduser.DefaultCreatedAt()
  206. wcuc.mutation.SetCreatedAt(v)
  207. }
  208. if _, ok := wcuc.mutation.UpdatedAt(); !ok {
  209. if wxcarduser.DefaultUpdatedAt == nil {
  210. return fmt.Errorf("ent: uninitialized wxcarduser.DefaultUpdatedAt (forgotten import ent/runtime?)")
  211. }
  212. v := wxcarduser.DefaultUpdatedAt()
  213. wcuc.mutation.SetUpdatedAt(v)
  214. }
  215. if _, ok := wcuc.mutation.Wxid(); !ok {
  216. v := wxcarduser.DefaultWxid
  217. wcuc.mutation.SetWxid(v)
  218. }
  219. if _, ok := wcuc.mutation.Account(); !ok {
  220. v := wxcarduser.DefaultAccount
  221. wcuc.mutation.SetAccount(v)
  222. }
  223. if _, ok := wcuc.mutation.Avatar(); !ok {
  224. v := wxcarduser.DefaultAvatar
  225. wcuc.mutation.SetAvatar(v)
  226. }
  227. if _, ok := wcuc.mutation.Nickname(); !ok {
  228. v := wxcarduser.DefaultNickname
  229. wcuc.mutation.SetNickname(v)
  230. }
  231. if _, ok := wcuc.mutation.Remark(); !ok {
  232. v := wxcarduser.DefaultRemark
  233. wcuc.mutation.SetRemark(v)
  234. }
  235. if _, ok := wcuc.mutation.Phone(); !ok {
  236. v := wxcarduser.DefaultPhone
  237. wcuc.mutation.SetPhone(v)
  238. }
  239. if _, ok := wcuc.mutation.OpenID(); !ok {
  240. v := wxcarduser.DefaultOpenID
  241. wcuc.mutation.SetOpenID(v)
  242. }
  243. if _, ok := wcuc.mutation.UnionID(); !ok {
  244. v := wxcarduser.DefaultUnionID
  245. wcuc.mutation.SetUnionID(v)
  246. }
  247. if _, ok := wcuc.mutation.SessionKey(); !ok {
  248. v := wxcarduser.DefaultSessionKey
  249. wcuc.mutation.SetSessionKey(v)
  250. }
  251. return nil
  252. }
  253. // check runs all checks and user-defined validators on the builder.
  254. func (wcuc *WxCardUserCreate) check() error {
  255. if _, ok := wcuc.mutation.CreatedAt(); !ok {
  256. return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "WxCardUser.created_at"`)}
  257. }
  258. if _, ok := wcuc.mutation.UpdatedAt(); !ok {
  259. return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "WxCardUser.updated_at"`)}
  260. }
  261. if _, ok := wcuc.mutation.Wxid(); !ok {
  262. return &ValidationError{Name: "wxid", err: errors.New(`ent: missing required field "WxCardUser.wxid"`)}
  263. }
  264. if _, ok := wcuc.mutation.Account(); !ok {
  265. return &ValidationError{Name: "account", err: errors.New(`ent: missing required field "WxCardUser.account"`)}
  266. }
  267. if _, ok := wcuc.mutation.Avatar(); !ok {
  268. return &ValidationError{Name: "avatar", err: errors.New(`ent: missing required field "WxCardUser.avatar"`)}
  269. }
  270. if _, ok := wcuc.mutation.Nickname(); !ok {
  271. return &ValidationError{Name: "nickname", err: errors.New(`ent: missing required field "WxCardUser.nickname"`)}
  272. }
  273. if _, ok := wcuc.mutation.Remark(); !ok {
  274. return &ValidationError{Name: "remark", err: errors.New(`ent: missing required field "WxCardUser.remark"`)}
  275. }
  276. if _, ok := wcuc.mutation.Phone(); !ok {
  277. return &ValidationError{Name: "phone", err: errors.New(`ent: missing required field "WxCardUser.phone"`)}
  278. }
  279. if _, ok := wcuc.mutation.OpenID(); !ok {
  280. return &ValidationError{Name: "open_id", err: errors.New(`ent: missing required field "WxCardUser.open_id"`)}
  281. }
  282. if _, ok := wcuc.mutation.UnionID(); !ok {
  283. return &ValidationError{Name: "union_id", err: errors.New(`ent: missing required field "WxCardUser.union_id"`)}
  284. }
  285. if _, ok := wcuc.mutation.SessionKey(); !ok {
  286. return &ValidationError{Name: "session_key", err: errors.New(`ent: missing required field "WxCardUser.session_key"`)}
  287. }
  288. return nil
  289. }
  290. func (wcuc *WxCardUserCreate) sqlSave(ctx context.Context) (*WxCardUser, error) {
  291. if err := wcuc.check(); err != nil {
  292. return nil, err
  293. }
  294. _node, _spec := wcuc.createSpec()
  295. if err := sqlgraph.CreateNode(ctx, wcuc.driver, _spec); err != nil {
  296. if sqlgraph.IsConstraintError(err) {
  297. err = &ConstraintError{msg: err.Error(), wrap: err}
  298. }
  299. return nil, err
  300. }
  301. if _spec.ID.Value != _node.ID {
  302. id := _spec.ID.Value.(int64)
  303. _node.ID = uint64(id)
  304. }
  305. wcuc.mutation.id = &_node.ID
  306. wcuc.mutation.done = true
  307. return _node, nil
  308. }
  309. func (wcuc *WxCardUserCreate) createSpec() (*WxCardUser, *sqlgraph.CreateSpec) {
  310. var (
  311. _node = &WxCardUser{config: wcuc.config}
  312. _spec = sqlgraph.NewCreateSpec(wxcarduser.Table, sqlgraph.NewFieldSpec(wxcarduser.FieldID, field.TypeUint64))
  313. )
  314. _spec.OnConflict = wcuc.conflict
  315. if id, ok := wcuc.mutation.ID(); ok {
  316. _node.ID = id
  317. _spec.ID.Value = id
  318. }
  319. if value, ok := wcuc.mutation.CreatedAt(); ok {
  320. _spec.SetField(wxcarduser.FieldCreatedAt, field.TypeTime, value)
  321. _node.CreatedAt = value
  322. }
  323. if value, ok := wcuc.mutation.UpdatedAt(); ok {
  324. _spec.SetField(wxcarduser.FieldUpdatedAt, field.TypeTime, value)
  325. _node.UpdatedAt = value
  326. }
  327. if value, ok := wcuc.mutation.DeletedAt(); ok {
  328. _spec.SetField(wxcarduser.FieldDeletedAt, field.TypeTime, value)
  329. _node.DeletedAt = value
  330. }
  331. if value, ok := wcuc.mutation.Wxid(); ok {
  332. _spec.SetField(wxcarduser.FieldWxid, field.TypeString, value)
  333. _node.Wxid = value
  334. }
  335. if value, ok := wcuc.mutation.Account(); ok {
  336. _spec.SetField(wxcarduser.FieldAccount, field.TypeString, value)
  337. _node.Account = value
  338. }
  339. if value, ok := wcuc.mutation.Avatar(); ok {
  340. _spec.SetField(wxcarduser.FieldAvatar, field.TypeString, value)
  341. _node.Avatar = value
  342. }
  343. if value, ok := wcuc.mutation.Nickname(); ok {
  344. _spec.SetField(wxcarduser.FieldNickname, field.TypeString, value)
  345. _node.Nickname = value
  346. }
  347. if value, ok := wcuc.mutation.Remark(); ok {
  348. _spec.SetField(wxcarduser.FieldRemark, field.TypeString, value)
  349. _node.Remark = value
  350. }
  351. if value, ok := wcuc.mutation.Phone(); ok {
  352. _spec.SetField(wxcarduser.FieldPhone, field.TypeString, value)
  353. _node.Phone = value
  354. }
  355. if value, ok := wcuc.mutation.OpenID(); ok {
  356. _spec.SetField(wxcarduser.FieldOpenID, field.TypeString, value)
  357. _node.OpenID = value
  358. }
  359. if value, ok := wcuc.mutation.UnionID(); ok {
  360. _spec.SetField(wxcarduser.FieldUnionID, field.TypeString, value)
  361. _node.UnionID = value
  362. }
  363. if value, ok := wcuc.mutation.SessionKey(); ok {
  364. _spec.SetField(wxcarduser.FieldSessionKey, field.TypeString, value)
  365. _node.SessionKey = value
  366. }
  367. return _node, _spec
  368. }
  369. // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
  370. // of the `INSERT` statement. For example:
  371. //
  372. // client.WxCardUser.Create().
  373. // SetCreatedAt(v).
  374. // OnConflict(
  375. // // Update the row with the new values
  376. // // the was proposed for insertion.
  377. // sql.ResolveWithNewValues(),
  378. // ).
  379. // // Override some of the fields with custom
  380. // // update values.
  381. // Update(func(u *ent.WxCardUserUpsert) {
  382. // SetCreatedAt(v+v).
  383. // }).
  384. // Exec(ctx)
  385. func (wcuc *WxCardUserCreate) OnConflict(opts ...sql.ConflictOption) *WxCardUserUpsertOne {
  386. wcuc.conflict = opts
  387. return &WxCardUserUpsertOne{
  388. create: wcuc,
  389. }
  390. }
  391. // OnConflictColumns calls `OnConflict` and configures the columns
  392. // as conflict target. Using this option is equivalent to using:
  393. //
  394. // client.WxCardUser.Create().
  395. // OnConflict(sql.ConflictColumns(columns...)).
  396. // Exec(ctx)
  397. func (wcuc *WxCardUserCreate) OnConflictColumns(columns ...string) *WxCardUserUpsertOne {
  398. wcuc.conflict = append(wcuc.conflict, sql.ConflictColumns(columns...))
  399. return &WxCardUserUpsertOne{
  400. create: wcuc,
  401. }
  402. }
  403. type (
  404. // WxCardUserUpsertOne is the builder for "upsert"-ing
  405. // one WxCardUser node.
  406. WxCardUserUpsertOne struct {
  407. create *WxCardUserCreate
  408. }
  409. // WxCardUserUpsert is the "OnConflict" setter.
  410. WxCardUserUpsert struct {
  411. *sql.UpdateSet
  412. }
  413. )
  414. // SetUpdatedAt sets the "updated_at" field.
  415. func (u *WxCardUserUpsert) SetUpdatedAt(v time.Time) *WxCardUserUpsert {
  416. u.Set(wxcarduser.FieldUpdatedAt, v)
  417. return u
  418. }
  419. // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
  420. func (u *WxCardUserUpsert) UpdateUpdatedAt() *WxCardUserUpsert {
  421. u.SetExcluded(wxcarduser.FieldUpdatedAt)
  422. return u
  423. }
  424. // SetDeletedAt sets the "deleted_at" field.
  425. func (u *WxCardUserUpsert) SetDeletedAt(v time.Time) *WxCardUserUpsert {
  426. u.Set(wxcarduser.FieldDeletedAt, v)
  427. return u
  428. }
  429. // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
  430. func (u *WxCardUserUpsert) UpdateDeletedAt() *WxCardUserUpsert {
  431. u.SetExcluded(wxcarduser.FieldDeletedAt)
  432. return u
  433. }
  434. // ClearDeletedAt clears the value of the "deleted_at" field.
  435. func (u *WxCardUserUpsert) ClearDeletedAt() *WxCardUserUpsert {
  436. u.SetNull(wxcarduser.FieldDeletedAt)
  437. return u
  438. }
  439. // SetWxid sets the "wxid" field.
  440. func (u *WxCardUserUpsert) SetWxid(v string) *WxCardUserUpsert {
  441. u.Set(wxcarduser.FieldWxid, v)
  442. return u
  443. }
  444. // UpdateWxid sets the "wxid" field to the value that was provided on create.
  445. func (u *WxCardUserUpsert) UpdateWxid() *WxCardUserUpsert {
  446. u.SetExcluded(wxcarduser.FieldWxid)
  447. return u
  448. }
  449. // SetAccount sets the "account" field.
  450. func (u *WxCardUserUpsert) SetAccount(v string) *WxCardUserUpsert {
  451. u.Set(wxcarduser.FieldAccount, v)
  452. return u
  453. }
  454. // UpdateAccount sets the "account" field to the value that was provided on create.
  455. func (u *WxCardUserUpsert) UpdateAccount() *WxCardUserUpsert {
  456. u.SetExcluded(wxcarduser.FieldAccount)
  457. return u
  458. }
  459. // SetAvatar sets the "avatar" field.
  460. func (u *WxCardUserUpsert) SetAvatar(v string) *WxCardUserUpsert {
  461. u.Set(wxcarduser.FieldAvatar, v)
  462. return u
  463. }
  464. // UpdateAvatar sets the "avatar" field to the value that was provided on create.
  465. func (u *WxCardUserUpsert) UpdateAvatar() *WxCardUserUpsert {
  466. u.SetExcluded(wxcarduser.FieldAvatar)
  467. return u
  468. }
  469. // SetNickname sets the "nickname" field.
  470. func (u *WxCardUserUpsert) SetNickname(v string) *WxCardUserUpsert {
  471. u.Set(wxcarduser.FieldNickname, v)
  472. return u
  473. }
  474. // UpdateNickname sets the "nickname" field to the value that was provided on create.
  475. func (u *WxCardUserUpsert) UpdateNickname() *WxCardUserUpsert {
  476. u.SetExcluded(wxcarduser.FieldNickname)
  477. return u
  478. }
  479. // SetRemark sets the "remark" field.
  480. func (u *WxCardUserUpsert) SetRemark(v string) *WxCardUserUpsert {
  481. u.Set(wxcarduser.FieldRemark, v)
  482. return u
  483. }
  484. // UpdateRemark sets the "remark" field to the value that was provided on create.
  485. func (u *WxCardUserUpsert) UpdateRemark() *WxCardUserUpsert {
  486. u.SetExcluded(wxcarduser.FieldRemark)
  487. return u
  488. }
  489. // SetPhone sets the "phone" field.
  490. func (u *WxCardUserUpsert) SetPhone(v string) *WxCardUserUpsert {
  491. u.Set(wxcarduser.FieldPhone, v)
  492. return u
  493. }
  494. // UpdatePhone sets the "phone" field to the value that was provided on create.
  495. func (u *WxCardUserUpsert) UpdatePhone() *WxCardUserUpsert {
  496. u.SetExcluded(wxcarduser.FieldPhone)
  497. return u
  498. }
  499. // SetOpenID sets the "open_id" field.
  500. func (u *WxCardUserUpsert) SetOpenID(v string) *WxCardUserUpsert {
  501. u.Set(wxcarduser.FieldOpenID, v)
  502. return u
  503. }
  504. // UpdateOpenID sets the "open_id" field to the value that was provided on create.
  505. func (u *WxCardUserUpsert) UpdateOpenID() *WxCardUserUpsert {
  506. u.SetExcluded(wxcarduser.FieldOpenID)
  507. return u
  508. }
  509. // SetUnionID sets the "union_id" field.
  510. func (u *WxCardUserUpsert) SetUnionID(v string) *WxCardUserUpsert {
  511. u.Set(wxcarduser.FieldUnionID, v)
  512. return u
  513. }
  514. // UpdateUnionID sets the "union_id" field to the value that was provided on create.
  515. func (u *WxCardUserUpsert) UpdateUnionID() *WxCardUserUpsert {
  516. u.SetExcluded(wxcarduser.FieldUnionID)
  517. return u
  518. }
  519. // SetSessionKey sets the "session_key" field.
  520. func (u *WxCardUserUpsert) SetSessionKey(v string) *WxCardUserUpsert {
  521. u.Set(wxcarduser.FieldSessionKey, v)
  522. return u
  523. }
  524. // UpdateSessionKey sets the "session_key" field to the value that was provided on create.
  525. func (u *WxCardUserUpsert) UpdateSessionKey() *WxCardUserUpsert {
  526. u.SetExcluded(wxcarduser.FieldSessionKey)
  527. return u
  528. }
  529. // UpdateNewValues updates the mutable fields using the new values that were set on create except the ID field.
  530. // Using this option is equivalent to using:
  531. //
  532. // client.WxCardUser.Create().
  533. // OnConflict(
  534. // sql.ResolveWithNewValues(),
  535. // sql.ResolveWith(func(u *sql.UpdateSet) {
  536. // u.SetIgnore(wxcarduser.FieldID)
  537. // }),
  538. // ).
  539. // Exec(ctx)
  540. func (u *WxCardUserUpsertOne) UpdateNewValues() *WxCardUserUpsertOne {
  541. u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
  542. u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
  543. if _, exists := u.create.mutation.ID(); exists {
  544. s.SetIgnore(wxcarduser.FieldID)
  545. }
  546. if _, exists := u.create.mutation.CreatedAt(); exists {
  547. s.SetIgnore(wxcarduser.FieldCreatedAt)
  548. }
  549. }))
  550. return u
  551. }
  552. // Ignore sets each column to itself in case of conflict.
  553. // Using this option is equivalent to using:
  554. //
  555. // client.WxCardUser.Create().
  556. // OnConflict(sql.ResolveWithIgnore()).
  557. // Exec(ctx)
  558. func (u *WxCardUserUpsertOne) Ignore() *WxCardUserUpsertOne {
  559. u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
  560. return u
  561. }
  562. // DoNothing configures the conflict_action to `DO NOTHING`.
  563. // Supported only by SQLite and PostgreSQL.
  564. func (u *WxCardUserUpsertOne) DoNothing() *WxCardUserUpsertOne {
  565. u.create.conflict = append(u.create.conflict, sql.DoNothing())
  566. return u
  567. }
  568. // Update allows overriding fields `UPDATE` values. See the WxCardUserCreate.OnConflict
  569. // documentation for more info.
  570. func (u *WxCardUserUpsertOne) Update(set func(*WxCardUserUpsert)) *WxCardUserUpsertOne {
  571. u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
  572. set(&WxCardUserUpsert{UpdateSet: update})
  573. }))
  574. return u
  575. }
  576. // SetUpdatedAt sets the "updated_at" field.
  577. func (u *WxCardUserUpsertOne) SetUpdatedAt(v time.Time) *WxCardUserUpsertOne {
  578. return u.Update(func(s *WxCardUserUpsert) {
  579. s.SetUpdatedAt(v)
  580. })
  581. }
  582. // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
  583. func (u *WxCardUserUpsertOne) UpdateUpdatedAt() *WxCardUserUpsertOne {
  584. return u.Update(func(s *WxCardUserUpsert) {
  585. s.UpdateUpdatedAt()
  586. })
  587. }
  588. // SetDeletedAt sets the "deleted_at" field.
  589. func (u *WxCardUserUpsertOne) SetDeletedAt(v time.Time) *WxCardUserUpsertOne {
  590. return u.Update(func(s *WxCardUserUpsert) {
  591. s.SetDeletedAt(v)
  592. })
  593. }
  594. // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
  595. func (u *WxCardUserUpsertOne) UpdateDeletedAt() *WxCardUserUpsertOne {
  596. return u.Update(func(s *WxCardUserUpsert) {
  597. s.UpdateDeletedAt()
  598. })
  599. }
  600. // ClearDeletedAt clears the value of the "deleted_at" field.
  601. func (u *WxCardUserUpsertOne) ClearDeletedAt() *WxCardUserUpsertOne {
  602. return u.Update(func(s *WxCardUserUpsert) {
  603. s.ClearDeletedAt()
  604. })
  605. }
  606. // SetWxid sets the "wxid" field.
  607. func (u *WxCardUserUpsertOne) SetWxid(v string) *WxCardUserUpsertOne {
  608. return u.Update(func(s *WxCardUserUpsert) {
  609. s.SetWxid(v)
  610. })
  611. }
  612. // UpdateWxid sets the "wxid" field to the value that was provided on create.
  613. func (u *WxCardUserUpsertOne) UpdateWxid() *WxCardUserUpsertOne {
  614. return u.Update(func(s *WxCardUserUpsert) {
  615. s.UpdateWxid()
  616. })
  617. }
  618. // SetAccount sets the "account" field.
  619. func (u *WxCardUserUpsertOne) SetAccount(v string) *WxCardUserUpsertOne {
  620. return u.Update(func(s *WxCardUserUpsert) {
  621. s.SetAccount(v)
  622. })
  623. }
  624. // UpdateAccount sets the "account" field to the value that was provided on create.
  625. func (u *WxCardUserUpsertOne) UpdateAccount() *WxCardUserUpsertOne {
  626. return u.Update(func(s *WxCardUserUpsert) {
  627. s.UpdateAccount()
  628. })
  629. }
  630. // SetAvatar sets the "avatar" field.
  631. func (u *WxCardUserUpsertOne) SetAvatar(v string) *WxCardUserUpsertOne {
  632. return u.Update(func(s *WxCardUserUpsert) {
  633. s.SetAvatar(v)
  634. })
  635. }
  636. // UpdateAvatar sets the "avatar" field to the value that was provided on create.
  637. func (u *WxCardUserUpsertOne) UpdateAvatar() *WxCardUserUpsertOne {
  638. return u.Update(func(s *WxCardUserUpsert) {
  639. s.UpdateAvatar()
  640. })
  641. }
  642. // SetNickname sets the "nickname" field.
  643. func (u *WxCardUserUpsertOne) SetNickname(v string) *WxCardUserUpsertOne {
  644. return u.Update(func(s *WxCardUserUpsert) {
  645. s.SetNickname(v)
  646. })
  647. }
  648. // UpdateNickname sets the "nickname" field to the value that was provided on create.
  649. func (u *WxCardUserUpsertOne) UpdateNickname() *WxCardUserUpsertOne {
  650. return u.Update(func(s *WxCardUserUpsert) {
  651. s.UpdateNickname()
  652. })
  653. }
  654. // SetRemark sets the "remark" field.
  655. func (u *WxCardUserUpsertOne) SetRemark(v string) *WxCardUserUpsertOne {
  656. return u.Update(func(s *WxCardUserUpsert) {
  657. s.SetRemark(v)
  658. })
  659. }
  660. // UpdateRemark sets the "remark" field to the value that was provided on create.
  661. func (u *WxCardUserUpsertOne) UpdateRemark() *WxCardUserUpsertOne {
  662. return u.Update(func(s *WxCardUserUpsert) {
  663. s.UpdateRemark()
  664. })
  665. }
  666. // SetPhone sets the "phone" field.
  667. func (u *WxCardUserUpsertOne) SetPhone(v string) *WxCardUserUpsertOne {
  668. return u.Update(func(s *WxCardUserUpsert) {
  669. s.SetPhone(v)
  670. })
  671. }
  672. // UpdatePhone sets the "phone" field to the value that was provided on create.
  673. func (u *WxCardUserUpsertOne) UpdatePhone() *WxCardUserUpsertOne {
  674. return u.Update(func(s *WxCardUserUpsert) {
  675. s.UpdatePhone()
  676. })
  677. }
  678. // SetOpenID sets the "open_id" field.
  679. func (u *WxCardUserUpsertOne) SetOpenID(v string) *WxCardUserUpsertOne {
  680. return u.Update(func(s *WxCardUserUpsert) {
  681. s.SetOpenID(v)
  682. })
  683. }
  684. // UpdateOpenID sets the "open_id" field to the value that was provided on create.
  685. func (u *WxCardUserUpsertOne) UpdateOpenID() *WxCardUserUpsertOne {
  686. return u.Update(func(s *WxCardUserUpsert) {
  687. s.UpdateOpenID()
  688. })
  689. }
  690. // SetUnionID sets the "union_id" field.
  691. func (u *WxCardUserUpsertOne) SetUnionID(v string) *WxCardUserUpsertOne {
  692. return u.Update(func(s *WxCardUserUpsert) {
  693. s.SetUnionID(v)
  694. })
  695. }
  696. // UpdateUnionID sets the "union_id" field to the value that was provided on create.
  697. func (u *WxCardUserUpsertOne) UpdateUnionID() *WxCardUserUpsertOne {
  698. return u.Update(func(s *WxCardUserUpsert) {
  699. s.UpdateUnionID()
  700. })
  701. }
  702. // SetSessionKey sets the "session_key" field.
  703. func (u *WxCardUserUpsertOne) SetSessionKey(v string) *WxCardUserUpsertOne {
  704. return u.Update(func(s *WxCardUserUpsert) {
  705. s.SetSessionKey(v)
  706. })
  707. }
  708. // UpdateSessionKey sets the "session_key" field to the value that was provided on create.
  709. func (u *WxCardUserUpsertOne) UpdateSessionKey() *WxCardUserUpsertOne {
  710. return u.Update(func(s *WxCardUserUpsert) {
  711. s.UpdateSessionKey()
  712. })
  713. }
  714. // Exec executes the query.
  715. func (u *WxCardUserUpsertOne) Exec(ctx context.Context) error {
  716. if len(u.create.conflict) == 0 {
  717. return errors.New("ent: missing options for WxCardUserCreate.OnConflict")
  718. }
  719. return u.create.Exec(ctx)
  720. }
  721. // ExecX is like Exec, but panics if an error occurs.
  722. func (u *WxCardUserUpsertOne) ExecX(ctx context.Context) {
  723. if err := u.create.Exec(ctx); err != nil {
  724. panic(err)
  725. }
  726. }
  727. // Exec executes the UPSERT query and returns the inserted/updated ID.
  728. func (u *WxCardUserUpsertOne) ID(ctx context.Context) (id uint64, err error) {
  729. node, err := u.create.Save(ctx)
  730. if err != nil {
  731. return id, err
  732. }
  733. return node.ID, nil
  734. }
  735. // IDX is like ID, but panics if an error occurs.
  736. func (u *WxCardUserUpsertOne) IDX(ctx context.Context) uint64 {
  737. id, err := u.ID(ctx)
  738. if err != nil {
  739. panic(err)
  740. }
  741. return id
  742. }
  743. // WxCardUserCreateBulk is the builder for creating many WxCardUser entities in bulk.
  744. type WxCardUserCreateBulk struct {
  745. config
  746. err error
  747. builders []*WxCardUserCreate
  748. conflict []sql.ConflictOption
  749. }
  750. // Save creates the WxCardUser entities in the database.
  751. func (wcucb *WxCardUserCreateBulk) Save(ctx context.Context) ([]*WxCardUser, error) {
  752. if wcucb.err != nil {
  753. return nil, wcucb.err
  754. }
  755. specs := make([]*sqlgraph.CreateSpec, len(wcucb.builders))
  756. nodes := make([]*WxCardUser, len(wcucb.builders))
  757. mutators := make([]Mutator, len(wcucb.builders))
  758. for i := range wcucb.builders {
  759. func(i int, root context.Context) {
  760. builder := wcucb.builders[i]
  761. builder.defaults()
  762. var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
  763. mutation, ok := m.(*WxCardUserMutation)
  764. if !ok {
  765. return nil, fmt.Errorf("unexpected mutation type %T", m)
  766. }
  767. if err := builder.check(); err != nil {
  768. return nil, err
  769. }
  770. builder.mutation = mutation
  771. var err error
  772. nodes[i], specs[i] = builder.createSpec()
  773. if i < len(mutators)-1 {
  774. _, err = mutators[i+1].Mutate(root, wcucb.builders[i+1].mutation)
  775. } else {
  776. spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
  777. spec.OnConflict = wcucb.conflict
  778. // Invoke the actual operation on the latest mutation in the chain.
  779. if err = sqlgraph.BatchCreate(ctx, wcucb.driver, spec); err != nil {
  780. if sqlgraph.IsConstraintError(err) {
  781. err = &ConstraintError{msg: err.Error(), wrap: err}
  782. }
  783. }
  784. }
  785. if err != nil {
  786. return nil, err
  787. }
  788. mutation.id = &nodes[i].ID
  789. if specs[i].ID.Value != nil && nodes[i].ID == 0 {
  790. id := specs[i].ID.Value.(int64)
  791. nodes[i].ID = uint64(id)
  792. }
  793. mutation.done = true
  794. return nodes[i], nil
  795. })
  796. for i := len(builder.hooks) - 1; i >= 0; i-- {
  797. mut = builder.hooks[i](mut)
  798. }
  799. mutators[i] = mut
  800. }(i, ctx)
  801. }
  802. if len(mutators) > 0 {
  803. if _, err := mutators[0].Mutate(ctx, wcucb.builders[0].mutation); err != nil {
  804. return nil, err
  805. }
  806. }
  807. return nodes, nil
  808. }
  809. // SaveX is like Save, but panics if an error occurs.
  810. func (wcucb *WxCardUserCreateBulk) SaveX(ctx context.Context) []*WxCardUser {
  811. v, err := wcucb.Save(ctx)
  812. if err != nil {
  813. panic(err)
  814. }
  815. return v
  816. }
  817. // Exec executes the query.
  818. func (wcucb *WxCardUserCreateBulk) Exec(ctx context.Context) error {
  819. _, err := wcucb.Save(ctx)
  820. return err
  821. }
  822. // ExecX is like Exec, but panics if an error occurs.
  823. func (wcucb *WxCardUserCreateBulk) ExecX(ctx context.Context) {
  824. if err := wcucb.Exec(ctx); err != nil {
  825. panic(err)
  826. }
  827. }
  828. // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
  829. // of the `INSERT` statement. For example:
  830. //
  831. // client.WxCardUser.CreateBulk(builders...).
  832. // OnConflict(
  833. // // Update the row with the new values
  834. // // the was proposed for insertion.
  835. // sql.ResolveWithNewValues(),
  836. // ).
  837. // // Override some of the fields with custom
  838. // // update values.
  839. // Update(func(u *ent.WxCardUserUpsert) {
  840. // SetCreatedAt(v+v).
  841. // }).
  842. // Exec(ctx)
  843. func (wcucb *WxCardUserCreateBulk) OnConflict(opts ...sql.ConflictOption) *WxCardUserUpsertBulk {
  844. wcucb.conflict = opts
  845. return &WxCardUserUpsertBulk{
  846. create: wcucb,
  847. }
  848. }
  849. // OnConflictColumns calls `OnConflict` and configures the columns
  850. // as conflict target. Using this option is equivalent to using:
  851. //
  852. // client.WxCardUser.Create().
  853. // OnConflict(sql.ConflictColumns(columns...)).
  854. // Exec(ctx)
  855. func (wcucb *WxCardUserCreateBulk) OnConflictColumns(columns ...string) *WxCardUserUpsertBulk {
  856. wcucb.conflict = append(wcucb.conflict, sql.ConflictColumns(columns...))
  857. return &WxCardUserUpsertBulk{
  858. create: wcucb,
  859. }
  860. }
  861. // WxCardUserUpsertBulk is the builder for "upsert"-ing
  862. // a bulk of WxCardUser nodes.
  863. type WxCardUserUpsertBulk struct {
  864. create *WxCardUserCreateBulk
  865. }
  866. // UpdateNewValues updates the mutable fields using the new values that
  867. // were set on create. Using this option is equivalent to using:
  868. //
  869. // client.WxCardUser.Create().
  870. // OnConflict(
  871. // sql.ResolveWithNewValues(),
  872. // sql.ResolveWith(func(u *sql.UpdateSet) {
  873. // u.SetIgnore(wxcarduser.FieldID)
  874. // }),
  875. // ).
  876. // Exec(ctx)
  877. func (u *WxCardUserUpsertBulk) UpdateNewValues() *WxCardUserUpsertBulk {
  878. u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
  879. u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
  880. for _, b := range u.create.builders {
  881. if _, exists := b.mutation.ID(); exists {
  882. s.SetIgnore(wxcarduser.FieldID)
  883. }
  884. if _, exists := b.mutation.CreatedAt(); exists {
  885. s.SetIgnore(wxcarduser.FieldCreatedAt)
  886. }
  887. }
  888. }))
  889. return u
  890. }
  891. // Ignore sets each column to itself in case of conflict.
  892. // Using this option is equivalent to using:
  893. //
  894. // client.WxCardUser.Create().
  895. // OnConflict(sql.ResolveWithIgnore()).
  896. // Exec(ctx)
  897. func (u *WxCardUserUpsertBulk) Ignore() *WxCardUserUpsertBulk {
  898. u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
  899. return u
  900. }
  901. // DoNothing configures the conflict_action to `DO NOTHING`.
  902. // Supported only by SQLite and PostgreSQL.
  903. func (u *WxCardUserUpsertBulk) DoNothing() *WxCardUserUpsertBulk {
  904. u.create.conflict = append(u.create.conflict, sql.DoNothing())
  905. return u
  906. }
  907. // Update allows overriding fields `UPDATE` values. See the WxCardUserCreateBulk.OnConflict
  908. // documentation for more info.
  909. func (u *WxCardUserUpsertBulk) Update(set func(*WxCardUserUpsert)) *WxCardUserUpsertBulk {
  910. u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
  911. set(&WxCardUserUpsert{UpdateSet: update})
  912. }))
  913. return u
  914. }
  915. // SetUpdatedAt sets the "updated_at" field.
  916. func (u *WxCardUserUpsertBulk) SetUpdatedAt(v time.Time) *WxCardUserUpsertBulk {
  917. return u.Update(func(s *WxCardUserUpsert) {
  918. s.SetUpdatedAt(v)
  919. })
  920. }
  921. // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
  922. func (u *WxCardUserUpsertBulk) UpdateUpdatedAt() *WxCardUserUpsertBulk {
  923. return u.Update(func(s *WxCardUserUpsert) {
  924. s.UpdateUpdatedAt()
  925. })
  926. }
  927. // SetDeletedAt sets the "deleted_at" field.
  928. func (u *WxCardUserUpsertBulk) SetDeletedAt(v time.Time) *WxCardUserUpsertBulk {
  929. return u.Update(func(s *WxCardUserUpsert) {
  930. s.SetDeletedAt(v)
  931. })
  932. }
  933. // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
  934. func (u *WxCardUserUpsertBulk) UpdateDeletedAt() *WxCardUserUpsertBulk {
  935. return u.Update(func(s *WxCardUserUpsert) {
  936. s.UpdateDeletedAt()
  937. })
  938. }
  939. // ClearDeletedAt clears the value of the "deleted_at" field.
  940. func (u *WxCardUserUpsertBulk) ClearDeletedAt() *WxCardUserUpsertBulk {
  941. return u.Update(func(s *WxCardUserUpsert) {
  942. s.ClearDeletedAt()
  943. })
  944. }
  945. // SetWxid sets the "wxid" field.
  946. func (u *WxCardUserUpsertBulk) SetWxid(v string) *WxCardUserUpsertBulk {
  947. return u.Update(func(s *WxCardUserUpsert) {
  948. s.SetWxid(v)
  949. })
  950. }
  951. // UpdateWxid sets the "wxid" field to the value that was provided on create.
  952. func (u *WxCardUserUpsertBulk) UpdateWxid() *WxCardUserUpsertBulk {
  953. return u.Update(func(s *WxCardUserUpsert) {
  954. s.UpdateWxid()
  955. })
  956. }
  957. // SetAccount sets the "account" field.
  958. func (u *WxCardUserUpsertBulk) SetAccount(v string) *WxCardUserUpsertBulk {
  959. return u.Update(func(s *WxCardUserUpsert) {
  960. s.SetAccount(v)
  961. })
  962. }
  963. // UpdateAccount sets the "account" field to the value that was provided on create.
  964. func (u *WxCardUserUpsertBulk) UpdateAccount() *WxCardUserUpsertBulk {
  965. return u.Update(func(s *WxCardUserUpsert) {
  966. s.UpdateAccount()
  967. })
  968. }
  969. // SetAvatar sets the "avatar" field.
  970. func (u *WxCardUserUpsertBulk) SetAvatar(v string) *WxCardUserUpsertBulk {
  971. return u.Update(func(s *WxCardUserUpsert) {
  972. s.SetAvatar(v)
  973. })
  974. }
  975. // UpdateAvatar sets the "avatar" field to the value that was provided on create.
  976. func (u *WxCardUserUpsertBulk) UpdateAvatar() *WxCardUserUpsertBulk {
  977. return u.Update(func(s *WxCardUserUpsert) {
  978. s.UpdateAvatar()
  979. })
  980. }
  981. // SetNickname sets the "nickname" field.
  982. func (u *WxCardUserUpsertBulk) SetNickname(v string) *WxCardUserUpsertBulk {
  983. return u.Update(func(s *WxCardUserUpsert) {
  984. s.SetNickname(v)
  985. })
  986. }
  987. // UpdateNickname sets the "nickname" field to the value that was provided on create.
  988. func (u *WxCardUserUpsertBulk) UpdateNickname() *WxCardUserUpsertBulk {
  989. return u.Update(func(s *WxCardUserUpsert) {
  990. s.UpdateNickname()
  991. })
  992. }
  993. // SetRemark sets the "remark" field.
  994. func (u *WxCardUserUpsertBulk) SetRemark(v string) *WxCardUserUpsertBulk {
  995. return u.Update(func(s *WxCardUserUpsert) {
  996. s.SetRemark(v)
  997. })
  998. }
  999. // UpdateRemark sets the "remark" field to the value that was provided on create.
  1000. func (u *WxCardUserUpsertBulk) UpdateRemark() *WxCardUserUpsertBulk {
  1001. return u.Update(func(s *WxCardUserUpsert) {
  1002. s.UpdateRemark()
  1003. })
  1004. }
  1005. // SetPhone sets the "phone" field.
  1006. func (u *WxCardUserUpsertBulk) SetPhone(v string) *WxCardUserUpsertBulk {
  1007. return u.Update(func(s *WxCardUserUpsert) {
  1008. s.SetPhone(v)
  1009. })
  1010. }
  1011. // UpdatePhone sets the "phone" field to the value that was provided on create.
  1012. func (u *WxCardUserUpsertBulk) UpdatePhone() *WxCardUserUpsertBulk {
  1013. return u.Update(func(s *WxCardUserUpsert) {
  1014. s.UpdatePhone()
  1015. })
  1016. }
  1017. // SetOpenID sets the "open_id" field.
  1018. func (u *WxCardUserUpsertBulk) SetOpenID(v string) *WxCardUserUpsertBulk {
  1019. return u.Update(func(s *WxCardUserUpsert) {
  1020. s.SetOpenID(v)
  1021. })
  1022. }
  1023. // UpdateOpenID sets the "open_id" field to the value that was provided on create.
  1024. func (u *WxCardUserUpsertBulk) UpdateOpenID() *WxCardUserUpsertBulk {
  1025. return u.Update(func(s *WxCardUserUpsert) {
  1026. s.UpdateOpenID()
  1027. })
  1028. }
  1029. // SetUnionID sets the "union_id" field.
  1030. func (u *WxCardUserUpsertBulk) SetUnionID(v string) *WxCardUserUpsertBulk {
  1031. return u.Update(func(s *WxCardUserUpsert) {
  1032. s.SetUnionID(v)
  1033. })
  1034. }
  1035. // UpdateUnionID sets the "union_id" field to the value that was provided on create.
  1036. func (u *WxCardUserUpsertBulk) UpdateUnionID() *WxCardUserUpsertBulk {
  1037. return u.Update(func(s *WxCardUserUpsert) {
  1038. s.UpdateUnionID()
  1039. })
  1040. }
  1041. // SetSessionKey sets the "session_key" field.
  1042. func (u *WxCardUserUpsertBulk) SetSessionKey(v string) *WxCardUserUpsertBulk {
  1043. return u.Update(func(s *WxCardUserUpsert) {
  1044. s.SetSessionKey(v)
  1045. })
  1046. }
  1047. // UpdateSessionKey sets the "session_key" field to the value that was provided on create.
  1048. func (u *WxCardUserUpsertBulk) UpdateSessionKey() *WxCardUserUpsertBulk {
  1049. return u.Update(func(s *WxCardUserUpsert) {
  1050. s.UpdateSessionKey()
  1051. })
  1052. }
  1053. // Exec executes the query.
  1054. func (u *WxCardUserUpsertBulk) Exec(ctx context.Context) error {
  1055. if u.create.err != nil {
  1056. return u.create.err
  1057. }
  1058. for i, b := range u.create.builders {
  1059. if len(b.conflict) != 0 {
  1060. return fmt.Errorf("ent: OnConflict was set for builder %d. Set it on the WxCardUserCreateBulk instead", i)
  1061. }
  1062. }
  1063. if len(u.create.conflict) == 0 {
  1064. return errors.New("ent: missing options for WxCardUserCreateBulk.OnConflict")
  1065. }
  1066. return u.create.Exec(ctx)
  1067. }
  1068. // ExecX is like Exec, but panics if an error occurs.
  1069. func (u *WxCardUserUpsertBulk) ExecX(ctx context.Context) {
  1070. if err := u.create.Exec(ctx); err != nil {
  1071. panic(err)
  1072. }
  1073. }