wxcarduser_create.go 37 KB

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