wxcardvisit_create.go 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893
  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/wxcardvisit"
  9. "entgo.io/ent/dialect/sql"
  10. "entgo.io/ent/dialect/sql/sqlgraph"
  11. "entgo.io/ent/schema/field"
  12. )
  13. // WxCardVisitCreate is the builder for creating a WxCardVisit entity.
  14. type WxCardVisitCreate struct {
  15. config
  16. mutation *WxCardVisitMutation
  17. hooks []Hook
  18. conflict []sql.ConflictOption
  19. }
  20. // SetCreatedAt sets the "created_at" field.
  21. func (wcvc *WxCardVisitCreate) SetCreatedAt(t time.Time) *WxCardVisitCreate {
  22. wcvc.mutation.SetCreatedAt(t)
  23. return wcvc
  24. }
  25. // SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
  26. func (wcvc *WxCardVisitCreate) SetNillableCreatedAt(t *time.Time) *WxCardVisitCreate {
  27. if t != nil {
  28. wcvc.SetCreatedAt(*t)
  29. }
  30. return wcvc
  31. }
  32. // SetUpdatedAt sets the "updated_at" field.
  33. func (wcvc *WxCardVisitCreate) SetUpdatedAt(t time.Time) *WxCardVisitCreate {
  34. wcvc.mutation.SetUpdatedAt(t)
  35. return wcvc
  36. }
  37. // SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
  38. func (wcvc *WxCardVisitCreate) SetNillableUpdatedAt(t *time.Time) *WxCardVisitCreate {
  39. if t != nil {
  40. wcvc.SetUpdatedAt(*t)
  41. }
  42. return wcvc
  43. }
  44. // SetDeletedAt sets the "deleted_at" field.
  45. func (wcvc *WxCardVisitCreate) SetDeletedAt(t time.Time) *WxCardVisitCreate {
  46. wcvc.mutation.SetDeletedAt(t)
  47. return wcvc
  48. }
  49. // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
  50. func (wcvc *WxCardVisitCreate) SetNillableDeletedAt(t *time.Time) *WxCardVisitCreate {
  51. if t != nil {
  52. wcvc.SetDeletedAt(*t)
  53. }
  54. return wcvc
  55. }
  56. // SetUserID sets the "user_id" field.
  57. func (wcvc *WxCardVisitCreate) SetUserID(u uint64) *WxCardVisitCreate {
  58. wcvc.mutation.SetUserID(u)
  59. return wcvc
  60. }
  61. // SetNillableUserID sets the "user_id" field if the given value is not nil.
  62. func (wcvc *WxCardVisitCreate) SetNillableUserID(u *uint64) *WxCardVisitCreate {
  63. if u != nil {
  64. wcvc.SetUserID(*u)
  65. }
  66. return wcvc
  67. }
  68. // SetBotID sets the "bot_id" field.
  69. func (wcvc *WxCardVisitCreate) SetBotID(u uint64) *WxCardVisitCreate {
  70. wcvc.mutation.SetBotID(u)
  71. return wcvc
  72. }
  73. // SetNillableBotID sets the "bot_id" field if the given value is not nil.
  74. func (wcvc *WxCardVisitCreate) SetNillableBotID(u *uint64) *WxCardVisitCreate {
  75. if u != nil {
  76. wcvc.SetBotID(*u)
  77. }
  78. return wcvc
  79. }
  80. // SetBotType sets the "bot_type" field.
  81. func (wcvc *WxCardVisitCreate) SetBotType(u uint8) *WxCardVisitCreate {
  82. wcvc.mutation.SetBotType(u)
  83. return wcvc
  84. }
  85. // SetNillableBotType sets the "bot_type" field if the given value is not nil.
  86. func (wcvc *WxCardVisitCreate) SetNillableBotType(u *uint8) *WxCardVisitCreate {
  87. if u != nil {
  88. wcvc.SetBotType(*u)
  89. }
  90. return wcvc
  91. }
  92. // SetID sets the "id" field.
  93. func (wcvc *WxCardVisitCreate) SetID(u uint64) *WxCardVisitCreate {
  94. wcvc.mutation.SetID(u)
  95. return wcvc
  96. }
  97. // Mutation returns the WxCardVisitMutation object of the builder.
  98. func (wcvc *WxCardVisitCreate) Mutation() *WxCardVisitMutation {
  99. return wcvc.mutation
  100. }
  101. // Save creates the WxCardVisit in the database.
  102. func (wcvc *WxCardVisitCreate) Save(ctx context.Context) (*WxCardVisit, error) {
  103. if err := wcvc.defaults(); err != nil {
  104. return nil, err
  105. }
  106. return withHooks(ctx, wcvc.sqlSave, wcvc.mutation, wcvc.hooks)
  107. }
  108. // SaveX calls Save and panics if Save returns an error.
  109. func (wcvc *WxCardVisitCreate) SaveX(ctx context.Context) *WxCardVisit {
  110. v, err := wcvc.Save(ctx)
  111. if err != nil {
  112. panic(err)
  113. }
  114. return v
  115. }
  116. // Exec executes the query.
  117. func (wcvc *WxCardVisitCreate) Exec(ctx context.Context) error {
  118. _, err := wcvc.Save(ctx)
  119. return err
  120. }
  121. // ExecX is like Exec, but panics if an error occurs.
  122. func (wcvc *WxCardVisitCreate) ExecX(ctx context.Context) {
  123. if err := wcvc.Exec(ctx); err != nil {
  124. panic(err)
  125. }
  126. }
  127. // defaults sets the default values of the builder before save.
  128. func (wcvc *WxCardVisitCreate) defaults() error {
  129. if _, ok := wcvc.mutation.CreatedAt(); !ok {
  130. if wxcardvisit.DefaultCreatedAt == nil {
  131. return fmt.Errorf("ent: uninitialized wxcardvisit.DefaultCreatedAt (forgotten import ent/runtime?)")
  132. }
  133. v := wxcardvisit.DefaultCreatedAt()
  134. wcvc.mutation.SetCreatedAt(v)
  135. }
  136. if _, ok := wcvc.mutation.UpdatedAt(); !ok {
  137. if wxcardvisit.DefaultUpdatedAt == nil {
  138. return fmt.Errorf("ent: uninitialized wxcardvisit.DefaultUpdatedAt (forgotten import ent/runtime?)")
  139. }
  140. v := wxcardvisit.DefaultUpdatedAt()
  141. wcvc.mutation.SetUpdatedAt(v)
  142. }
  143. if _, ok := wcvc.mutation.UserID(); !ok {
  144. v := wxcardvisit.DefaultUserID
  145. wcvc.mutation.SetUserID(v)
  146. }
  147. if _, ok := wcvc.mutation.BotID(); !ok {
  148. v := wxcardvisit.DefaultBotID
  149. wcvc.mutation.SetBotID(v)
  150. }
  151. if _, ok := wcvc.mutation.BotType(); !ok {
  152. v := wxcardvisit.DefaultBotType
  153. wcvc.mutation.SetBotType(v)
  154. }
  155. return nil
  156. }
  157. // check runs all checks and user-defined validators on the builder.
  158. func (wcvc *WxCardVisitCreate) check() error {
  159. if _, ok := wcvc.mutation.CreatedAt(); !ok {
  160. return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "WxCardVisit.created_at"`)}
  161. }
  162. if _, ok := wcvc.mutation.UpdatedAt(); !ok {
  163. return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "WxCardVisit.updated_at"`)}
  164. }
  165. if _, ok := wcvc.mutation.BotID(); !ok {
  166. return &ValidationError{Name: "bot_id", err: errors.New(`ent: missing required field "WxCardVisit.bot_id"`)}
  167. }
  168. if _, ok := wcvc.mutation.BotType(); !ok {
  169. return &ValidationError{Name: "bot_type", err: errors.New(`ent: missing required field "WxCardVisit.bot_type"`)}
  170. }
  171. return nil
  172. }
  173. func (wcvc *WxCardVisitCreate) sqlSave(ctx context.Context) (*WxCardVisit, error) {
  174. if err := wcvc.check(); err != nil {
  175. return nil, err
  176. }
  177. _node, _spec := wcvc.createSpec()
  178. if err := sqlgraph.CreateNode(ctx, wcvc.driver, _spec); err != nil {
  179. if sqlgraph.IsConstraintError(err) {
  180. err = &ConstraintError{msg: err.Error(), wrap: err}
  181. }
  182. return nil, err
  183. }
  184. if _spec.ID.Value != _node.ID {
  185. id := _spec.ID.Value.(int64)
  186. _node.ID = uint64(id)
  187. }
  188. wcvc.mutation.id = &_node.ID
  189. wcvc.mutation.done = true
  190. return _node, nil
  191. }
  192. func (wcvc *WxCardVisitCreate) createSpec() (*WxCardVisit, *sqlgraph.CreateSpec) {
  193. var (
  194. _node = &WxCardVisit{config: wcvc.config}
  195. _spec = sqlgraph.NewCreateSpec(wxcardvisit.Table, sqlgraph.NewFieldSpec(wxcardvisit.FieldID, field.TypeUint64))
  196. )
  197. _spec.OnConflict = wcvc.conflict
  198. if id, ok := wcvc.mutation.ID(); ok {
  199. _node.ID = id
  200. _spec.ID.Value = id
  201. }
  202. if value, ok := wcvc.mutation.CreatedAt(); ok {
  203. _spec.SetField(wxcardvisit.FieldCreatedAt, field.TypeTime, value)
  204. _node.CreatedAt = value
  205. }
  206. if value, ok := wcvc.mutation.UpdatedAt(); ok {
  207. _spec.SetField(wxcardvisit.FieldUpdatedAt, field.TypeTime, value)
  208. _node.UpdatedAt = value
  209. }
  210. if value, ok := wcvc.mutation.DeletedAt(); ok {
  211. _spec.SetField(wxcardvisit.FieldDeletedAt, field.TypeTime, value)
  212. _node.DeletedAt = value
  213. }
  214. if value, ok := wcvc.mutation.UserID(); ok {
  215. _spec.SetField(wxcardvisit.FieldUserID, field.TypeUint64, value)
  216. _node.UserID = value
  217. }
  218. if value, ok := wcvc.mutation.BotID(); ok {
  219. _spec.SetField(wxcardvisit.FieldBotID, field.TypeUint64, value)
  220. _node.BotID = value
  221. }
  222. if value, ok := wcvc.mutation.BotType(); ok {
  223. _spec.SetField(wxcardvisit.FieldBotType, field.TypeUint8, value)
  224. _node.BotType = value
  225. }
  226. return _node, _spec
  227. }
  228. // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
  229. // of the `INSERT` statement. For example:
  230. //
  231. // client.WxCardVisit.Create().
  232. // SetCreatedAt(v).
  233. // OnConflict(
  234. // // Update the row with the new values
  235. // // the was proposed for insertion.
  236. // sql.ResolveWithNewValues(),
  237. // ).
  238. // // Override some of the fields with custom
  239. // // update values.
  240. // Update(func(u *ent.WxCardVisitUpsert) {
  241. // SetCreatedAt(v+v).
  242. // }).
  243. // Exec(ctx)
  244. func (wcvc *WxCardVisitCreate) OnConflict(opts ...sql.ConflictOption) *WxCardVisitUpsertOne {
  245. wcvc.conflict = opts
  246. return &WxCardVisitUpsertOne{
  247. create: wcvc,
  248. }
  249. }
  250. // OnConflictColumns calls `OnConflict` and configures the columns
  251. // as conflict target. Using this option is equivalent to using:
  252. //
  253. // client.WxCardVisit.Create().
  254. // OnConflict(sql.ConflictColumns(columns...)).
  255. // Exec(ctx)
  256. func (wcvc *WxCardVisitCreate) OnConflictColumns(columns ...string) *WxCardVisitUpsertOne {
  257. wcvc.conflict = append(wcvc.conflict, sql.ConflictColumns(columns...))
  258. return &WxCardVisitUpsertOne{
  259. create: wcvc,
  260. }
  261. }
  262. type (
  263. // WxCardVisitUpsertOne is the builder for "upsert"-ing
  264. // one WxCardVisit node.
  265. WxCardVisitUpsertOne struct {
  266. create *WxCardVisitCreate
  267. }
  268. // WxCardVisitUpsert is the "OnConflict" setter.
  269. WxCardVisitUpsert struct {
  270. *sql.UpdateSet
  271. }
  272. )
  273. // SetUpdatedAt sets the "updated_at" field.
  274. func (u *WxCardVisitUpsert) SetUpdatedAt(v time.Time) *WxCardVisitUpsert {
  275. u.Set(wxcardvisit.FieldUpdatedAt, v)
  276. return u
  277. }
  278. // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
  279. func (u *WxCardVisitUpsert) UpdateUpdatedAt() *WxCardVisitUpsert {
  280. u.SetExcluded(wxcardvisit.FieldUpdatedAt)
  281. return u
  282. }
  283. // SetDeletedAt sets the "deleted_at" field.
  284. func (u *WxCardVisitUpsert) SetDeletedAt(v time.Time) *WxCardVisitUpsert {
  285. u.Set(wxcardvisit.FieldDeletedAt, v)
  286. return u
  287. }
  288. // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
  289. func (u *WxCardVisitUpsert) UpdateDeletedAt() *WxCardVisitUpsert {
  290. u.SetExcluded(wxcardvisit.FieldDeletedAt)
  291. return u
  292. }
  293. // ClearDeletedAt clears the value of the "deleted_at" field.
  294. func (u *WxCardVisitUpsert) ClearDeletedAt() *WxCardVisitUpsert {
  295. u.SetNull(wxcardvisit.FieldDeletedAt)
  296. return u
  297. }
  298. // SetUserID sets the "user_id" field.
  299. func (u *WxCardVisitUpsert) SetUserID(v uint64) *WxCardVisitUpsert {
  300. u.Set(wxcardvisit.FieldUserID, v)
  301. return u
  302. }
  303. // UpdateUserID sets the "user_id" field to the value that was provided on create.
  304. func (u *WxCardVisitUpsert) UpdateUserID() *WxCardVisitUpsert {
  305. u.SetExcluded(wxcardvisit.FieldUserID)
  306. return u
  307. }
  308. // AddUserID adds v to the "user_id" field.
  309. func (u *WxCardVisitUpsert) AddUserID(v uint64) *WxCardVisitUpsert {
  310. u.Add(wxcardvisit.FieldUserID, v)
  311. return u
  312. }
  313. // ClearUserID clears the value of the "user_id" field.
  314. func (u *WxCardVisitUpsert) ClearUserID() *WxCardVisitUpsert {
  315. u.SetNull(wxcardvisit.FieldUserID)
  316. return u
  317. }
  318. // SetBotID sets the "bot_id" field.
  319. func (u *WxCardVisitUpsert) SetBotID(v uint64) *WxCardVisitUpsert {
  320. u.Set(wxcardvisit.FieldBotID, v)
  321. return u
  322. }
  323. // UpdateBotID sets the "bot_id" field to the value that was provided on create.
  324. func (u *WxCardVisitUpsert) UpdateBotID() *WxCardVisitUpsert {
  325. u.SetExcluded(wxcardvisit.FieldBotID)
  326. return u
  327. }
  328. // AddBotID adds v to the "bot_id" field.
  329. func (u *WxCardVisitUpsert) AddBotID(v uint64) *WxCardVisitUpsert {
  330. u.Add(wxcardvisit.FieldBotID, v)
  331. return u
  332. }
  333. // SetBotType sets the "bot_type" field.
  334. func (u *WxCardVisitUpsert) SetBotType(v uint8) *WxCardVisitUpsert {
  335. u.Set(wxcardvisit.FieldBotType, v)
  336. return u
  337. }
  338. // UpdateBotType sets the "bot_type" field to the value that was provided on create.
  339. func (u *WxCardVisitUpsert) UpdateBotType() *WxCardVisitUpsert {
  340. u.SetExcluded(wxcardvisit.FieldBotType)
  341. return u
  342. }
  343. // AddBotType adds v to the "bot_type" field.
  344. func (u *WxCardVisitUpsert) AddBotType(v uint8) *WxCardVisitUpsert {
  345. u.Add(wxcardvisit.FieldBotType, v)
  346. return u
  347. }
  348. // UpdateNewValues updates the mutable fields using the new values that were set on create except the ID field.
  349. // Using this option is equivalent to using:
  350. //
  351. // client.WxCardVisit.Create().
  352. // OnConflict(
  353. // sql.ResolveWithNewValues(),
  354. // sql.ResolveWith(func(u *sql.UpdateSet) {
  355. // u.SetIgnore(wxcardvisit.FieldID)
  356. // }),
  357. // ).
  358. // Exec(ctx)
  359. func (u *WxCardVisitUpsertOne) UpdateNewValues() *WxCardVisitUpsertOne {
  360. u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
  361. u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
  362. if _, exists := u.create.mutation.ID(); exists {
  363. s.SetIgnore(wxcardvisit.FieldID)
  364. }
  365. if _, exists := u.create.mutation.CreatedAt(); exists {
  366. s.SetIgnore(wxcardvisit.FieldCreatedAt)
  367. }
  368. }))
  369. return u
  370. }
  371. // Ignore sets each column to itself in case of conflict.
  372. // Using this option is equivalent to using:
  373. //
  374. // client.WxCardVisit.Create().
  375. // OnConflict(sql.ResolveWithIgnore()).
  376. // Exec(ctx)
  377. func (u *WxCardVisitUpsertOne) Ignore() *WxCardVisitUpsertOne {
  378. u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
  379. return u
  380. }
  381. // DoNothing configures the conflict_action to `DO NOTHING`.
  382. // Supported only by SQLite and PostgreSQL.
  383. func (u *WxCardVisitUpsertOne) DoNothing() *WxCardVisitUpsertOne {
  384. u.create.conflict = append(u.create.conflict, sql.DoNothing())
  385. return u
  386. }
  387. // Update allows overriding fields `UPDATE` values. See the WxCardVisitCreate.OnConflict
  388. // documentation for more info.
  389. func (u *WxCardVisitUpsertOne) Update(set func(*WxCardVisitUpsert)) *WxCardVisitUpsertOne {
  390. u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
  391. set(&WxCardVisitUpsert{UpdateSet: update})
  392. }))
  393. return u
  394. }
  395. // SetUpdatedAt sets the "updated_at" field.
  396. func (u *WxCardVisitUpsertOne) SetUpdatedAt(v time.Time) *WxCardVisitUpsertOne {
  397. return u.Update(func(s *WxCardVisitUpsert) {
  398. s.SetUpdatedAt(v)
  399. })
  400. }
  401. // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
  402. func (u *WxCardVisitUpsertOne) UpdateUpdatedAt() *WxCardVisitUpsertOne {
  403. return u.Update(func(s *WxCardVisitUpsert) {
  404. s.UpdateUpdatedAt()
  405. })
  406. }
  407. // SetDeletedAt sets the "deleted_at" field.
  408. func (u *WxCardVisitUpsertOne) SetDeletedAt(v time.Time) *WxCardVisitUpsertOne {
  409. return u.Update(func(s *WxCardVisitUpsert) {
  410. s.SetDeletedAt(v)
  411. })
  412. }
  413. // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
  414. func (u *WxCardVisitUpsertOne) UpdateDeletedAt() *WxCardVisitUpsertOne {
  415. return u.Update(func(s *WxCardVisitUpsert) {
  416. s.UpdateDeletedAt()
  417. })
  418. }
  419. // ClearDeletedAt clears the value of the "deleted_at" field.
  420. func (u *WxCardVisitUpsertOne) ClearDeletedAt() *WxCardVisitUpsertOne {
  421. return u.Update(func(s *WxCardVisitUpsert) {
  422. s.ClearDeletedAt()
  423. })
  424. }
  425. // SetUserID sets the "user_id" field.
  426. func (u *WxCardVisitUpsertOne) SetUserID(v uint64) *WxCardVisitUpsertOne {
  427. return u.Update(func(s *WxCardVisitUpsert) {
  428. s.SetUserID(v)
  429. })
  430. }
  431. // AddUserID adds v to the "user_id" field.
  432. func (u *WxCardVisitUpsertOne) AddUserID(v uint64) *WxCardVisitUpsertOne {
  433. return u.Update(func(s *WxCardVisitUpsert) {
  434. s.AddUserID(v)
  435. })
  436. }
  437. // UpdateUserID sets the "user_id" field to the value that was provided on create.
  438. func (u *WxCardVisitUpsertOne) UpdateUserID() *WxCardVisitUpsertOne {
  439. return u.Update(func(s *WxCardVisitUpsert) {
  440. s.UpdateUserID()
  441. })
  442. }
  443. // ClearUserID clears the value of the "user_id" field.
  444. func (u *WxCardVisitUpsertOne) ClearUserID() *WxCardVisitUpsertOne {
  445. return u.Update(func(s *WxCardVisitUpsert) {
  446. s.ClearUserID()
  447. })
  448. }
  449. // SetBotID sets the "bot_id" field.
  450. func (u *WxCardVisitUpsertOne) SetBotID(v uint64) *WxCardVisitUpsertOne {
  451. return u.Update(func(s *WxCardVisitUpsert) {
  452. s.SetBotID(v)
  453. })
  454. }
  455. // AddBotID adds v to the "bot_id" field.
  456. func (u *WxCardVisitUpsertOne) AddBotID(v uint64) *WxCardVisitUpsertOne {
  457. return u.Update(func(s *WxCardVisitUpsert) {
  458. s.AddBotID(v)
  459. })
  460. }
  461. // UpdateBotID sets the "bot_id" field to the value that was provided on create.
  462. func (u *WxCardVisitUpsertOne) UpdateBotID() *WxCardVisitUpsertOne {
  463. return u.Update(func(s *WxCardVisitUpsert) {
  464. s.UpdateBotID()
  465. })
  466. }
  467. // SetBotType sets the "bot_type" field.
  468. func (u *WxCardVisitUpsertOne) SetBotType(v uint8) *WxCardVisitUpsertOne {
  469. return u.Update(func(s *WxCardVisitUpsert) {
  470. s.SetBotType(v)
  471. })
  472. }
  473. // AddBotType adds v to the "bot_type" field.
  474. func (u *WxCardVisitUpsertOne) AddBotType(v uint8) *WxCardVisitUpsertOne {
  475. return u.Update(func(s *WxCardVisitUpsert) {
  476. s.AddBotType(v)
  477. })
  478. }
  479. // UpdateBotType sets the "bot_type" field to the value that was provided on create.
  480. func (u *WxCardVisitUpsertOne) UpdateBotType() *WxCardVisitUpsertOne {
  481. return u.Update(func(s *WxCardVisitUpsert) {
  482. s.UpdateBotType()
  483. })
  484. }
  485. // Exec executes the query.
  486. func (u *WxCardVisitUpsertOne) Exec(ctx context.Context) error {
  487. if len(u.create.conflict) == 0 {
  488. return errors.New("ent: missing options for WxCardVisitCreate.OnConflict")
  489. }
  490. return u.create.Exec(ctx)
  491. }
  492. // ExecX is like Exec, but panics if an error occurs.
  493. func (u *WxCardVisitUpsertOne) ExecX(ctx context.Context) {
  494. if err := u.create.Exec(ctx); err != nil {
  495. panic(err)
  496. }
  497. }
  498. // Exec executes the UPSERT query and returns the inserted/updated ID.
  499. func (u *WxCardVisitUpsertOne) ID(ctx context.Context) (id uint64, err error) {
  500. node, err := u.create.Save(ctx)
  501. if err != nil {
  502. return id, err
  503. }
  504. return node.ID, nil
  505. }
  506. // IDX is like ID, but panics if an error occurs.
  507. func (u *WxCardVisitUpsertOne) IDX(ctx context.Context) uint64 {
  508. id, err := u.ID(ctx)
  509. if err != nil {
  510. panic(err)
  511. }
  512. return id
  513. }
  514. // WxCardVisitCreateBulk is the builder for creating many WxCardVisit entities in bulk.
  515. type WxCardVisitCreateBulk struct {
  516. config
  517. err error
  518. builders []*WxCardVisitCreate
  519. conflict []sql.ConflictOption
  520. }
  521. // Save creates the WxCardVisit entities in the database.
  522. func (wcvcb *WxCardVisitCreateBulk) Save(ctx context.Context) ([]*WxCardVisit, error) {
  523. if wcvcb.err != nil {
  524. return nil, wcvcb.err
  525. }
  526. specs := make([]*sqlgraph.CreateSpec, len(wcvcb.builders))
  527. nodes := make([]*WxCardVisit, len(wcvcb.builders))
  528. mutators := make([]Mutator, len(wcvcb.builders))
  529. for i := range wcvcb.builders {
  530. func(i int, root context.Context) {
  531. builder := wcvcb.builders[i]
  532. builder.defaults()
  533. var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
  534. mutation, ok := m.(*WxCardVisitMutation)
  535. if !ok {
  536. return nil, fmt.Errorf("unexpected mutation type %T", m)
  537. }
  538. if err := builder.check(); err != nil {
  539. return nil, err
  540. }
  541. builder.mutation = mutation
  542. var err error
  543. nodes[i], specs[i] = builder.createSpec()
  544. if i < len(mutators)-1 {
  545. _, err = mutators[i+1].Mutate(root, wcvcb.builders[i+1].mutation)
  546. } else {
  547. spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
  548. spec.OnConflict = wcvcb.conflict
  549. // Invoke the actual operation on the latest mutation in the chain.
  550. if err = sqlgraph.BatchCreate(ctx, wcvcb.driver, spec); err != nil {
  551. if sqlgraph.IsConstraintError(err) {
  552. err = &ConstraintError{msg: err.Error(), wrap: err}
  553. }
  554. }
  555. }
  556. if err != nil {
  557. return nil, err
  558. }
  559. mutation.id = &nodes[i].ID
  560. if specs[i].ID.Value != nil && nodes[i].ID == 0 {
  561. id := specs[i].ID.Value.(int64)
  562. nodes[i].ID = uint64(id)
  563. }
  564. mutation.done = true
  565. return nodes[i], nil
  566. })
  567. for i := len(builder.hooks) - 1; i >= 0; i-- {
  568. mut = builder.hooks[i](mut)
  569. }
  570. mutators[i] = mut
  571. }(i, ctx)
  572. }
  573. if len(mutators) > 0 {
  574. if _, err := mutators[0].Mutate(ctx, wcvcb.builders[0].mutation); err != nil {
  575. return nil, err
  576. }
  577. }
  578. return nodes, nil
  579. }
  580. // SaveX is like Save, but panics if an error occurs.
  581. func (wcvcb *WxCardVisitCreateBulk) SaveX(ctx context.Context) []*WxCardVisit {
  582. v, err := wcvcb.Save(ctx)
  583. if err != nil {
  584. panic(err)
  585. }
  586. return v
  587. }
  588. // Exec executes the query.
  589. func (wcvcb *WxCardVisitCreateBulk) Exec(ctx context.Context) error {
  590. _, err := wcvcb.Save(ctx)
  591. return err
  592. }
  593. // ExecX is like Exec, but panics if an error occurs.
  594. func (wcvcb *WxCardVisitCreateBulk) ExecX(ctx context.Context) {
  595. if err := wcvcb.Exec(ctx); err != nil {
  596. panic(err)
  597. }
  598. }
  599. // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
  600. // of the `INSERT` statement. For example:
  601. //
  602. // client.WxCardVisit.CreateBulk(builders...).
  603. // OnConflict(
  604. // // Update the row with the new values
  605. // // the was proposed for insertion.
  606. // sql.ResolveWithNewValues(),
  607. // ).
  608. // // Override some of the fields with custom
  609. // // update values.
  610. // Update(func(u *ent.WxCardVisitUpsert) {
  611. // SetCreatedAt(v+v).
  612. // }).
  613. // Exec(ctx)
  614. func (wcvcb *WxCardVisitCreateBulk) OnConflict(opts ...sql.ConflictOption) *WxCardVisitUpsertBulk {
  615. wcvcb.conflict = opts
  616. return &WxCardVisitUpsertBulk{
  617. create: wcvcb,
  618. }
  619. }
  620. // OnConflictColumns calls `OnConflict` and configures the columns
  621. // as conflict target. Using this option is equivalent to using:
  622. //
  623. // client.WxCardVisit.Create().
  624. // OnConflict(sql.ConflictColumns(columns...)).
  625. // Exec(ctx)
  626. func (wcvcb *WxCardVisitCreateBulk) OnConflictColumns(columns ...string) *WxCardVisitUpsertBulk {
  627. wcvcb.conflict = append(wcvcb.conflict, sql.ConflictColumns(columns...))
  628. return &WxCardVisitUpsertBulk{
  629. create: wcvcb,
  630. }
  631. }
  632. // WxCardVisitUpsertBulk is the builder for "upsert"-ing
  633. // a bulk of WxCardVisit nodes.
  634. type WxCardVisitUpsertBulk struct {
  635. create *WxCardVisitCreateBulk
  636. }
  637. // UpdateNewValues updates the mutable fields using the new values that
  638. // were set on create. Using this option is equivalent to using:
  639. //
  640. // client.WxCardVisit.Create().
  641. // OnConflict(
  642. // sql.ResolveWithNewValues(),
  643. // sql.ResolveWith(func(u *sql.UpdateSet) {
  644. // u.SetIgnore(wxcardvisit.FieldID)
  645. // }),
  646. // ).
  647. // Exec(ctx)
  648. func (u *WxCardVisitUpsertBulk) UpdateNewValues() *WxCardVisitUpsertBulk {
  649. u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
  650. u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
  651. for _, b := range u.create.builders {
  652. if _, exists := b.mutation.ID(); exists {
  653. s.SetIgnore(wxcardvisit.FieldID)
  654. }
  655. if _, exists := b.mutation.CreatedAt(); exists {
  656. s.SetIgnore(wxcardvisit.FieldCreatedAt)
  657. }
  658. }
  659. }))
  660. return u
  661. }
  662. // Ignore sets each column to itself in case of conflict.
  663. // Using this option is equivalent to using:
  664. //
  665. // client.WxCardVisit.Create().
  666. // OnConflict(sql.ResolveWithIgnore()).
  667. // Exec(ctx)
  668. func (u *WxCardVisitUpsertBulk) Ignore() *WxCardVisitUpsertBulk {
  669. u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
  670. return u
  671. }
  672. // DoNothing configures the conflict_action to `DO NOTHING`.
  673. // Supported only by SQLite and PostgreSQL.
  674. func (u *WxCardVisitUpsertBulk) DoNothing() *WxCardVisitUpsertBulk {
  675. u.create.conflict = append(u.create.conflict, sql.DoNothing())
  676. return u
  677. }
  678. // Update allows overriding fields `UPDATE` values. See the WxCardVisitCreateBulk.OnConflict
  679. // documentation for more info.
  680. func (u *WxCardVisitUpsertBulk) Update(set func(*WxCardVisitUpsert)) *WxCardVisitUpsertBulk {
  681. u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
  682. set(&WxCardVisitUpsert{UpdateSet: update})
  683. }))
  684. return u
  685. }
  686. // SetUpdatedAt sets the "updated_at" field.
  687. func (u *WxCardVisitUpsertBulk) SetUpdatedAt(v time.Time) *WxCardVisitUpsertBulk {
  688. return u.Update(func(s *WxCardVisitUpsert) {
  689. s.SetUpdatedAt(v)
  690. })
  691. }
  692. // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
  693. func (u *WxCardVisitUpsertBulk) UpdateUpdatedAt() *WxCardVisitUpsertBulk {
  694. return u.Update(func(s *WxCardVisitUpsert) {
  695. s.UpdateUpdatedAt()
  696. })
  697. }
  698. // SetDeletedAt sets the "deleted_at" field.
  699. func (u *WxCardVisitUpsertBulk) SetDeletedAt(v time.Time) *WxCardVisitUpsertBulk {
  700. return u.Update(func(s *WxCardVisitUpsert) {
  701. s.SetDeletedAt(v)
  702. })
  703. }
  704. // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
  705. func (u *WxCardVisitUpsertBulk) UpdateDeletedAt() *WxCardVisitUpsertBulk {
  706. return u.Update(func(s *WxCardVisitUpsert) {
  707. s.UpdateDeletedAt()
  708. })
  709. }
  710. // ClearDeletedAt clears the value of the "deleted_at" field.
  711. func (u *WxCardVisitUpsertBulk) ClearDeletedAt() *WxCardVisitUpsertBulk {
  712. return u.Update(func(s *WxCardVisitUpsert) {
  713. s.ClearDeletedAt()
  714. })
  715. }
  716. // SetUserID sets the "user_id" field.
  717. func (u *WxCardVisitUpsertBulk) SetUserID(v uint64) *WxCardVisitUpsertBulk {
  718. return u.Update(func(s *WxCardVisitUpsert) {
  719. s.SetUserID(v)
  720. })
  721. }
  722. // AddUserID adds v to the "user_id" field.
  723. func (u *WxCardVisitUpsertBulk) AddUserID(v uint64) *WxCardVisitUpsertBulk {
  724. return u.Update(func(s *WxCardVisitUpsert) {
  725. s.AddUserID(v)
  726. })
  727. }
  728. // UpdateUserID sets the "user_id" field to the value that was provided on create.
  729. func (u *WxCardVisitUpsertBulk) UpdateUserID() *WxCardVisitUpsertBulk {
  730. return u.Update(func(s *WxCardVisitUpsert) {
  731. s.UpdateUserID()
  732. })
  733. }
  734. // ClearUserID clears the value of the "user_id" field.
  735. func (u *WxCardVisitUpsertBulk) ClearUserID() *WxCardVisitUpsertBulk {
  736. return u.Update(func(s *WxCardVisitUpsert) {
  737. s.ClearUserID()
  738. })
  739. }
  740. // SetBotID sets the "bot_id" field.
  741. func (u *WxCardVisitUpsertBulk) SetBotID(v uint64) *WxCardVisitUpsertBulk {
  742. return u.Update(func(s *WxCardVisitUpsert) {
  743. s.SetBotID(v)
  744. })
  745. }
  746. // AddBotID adds v to the "bot_id" field.
  747. func (u *WxCardVisitUpsertBulk) AddBotID(v uint64) *WxCardVisitUpsertBulk {
  748. return u.Update(func(s *WxCardVisitUpsert) {
  749. s.AddBotID(v)
  750. })
  751. }
  752. // UpdateBotID sets the "bot_id" field to the value that was provided on create.
  753. func (u *WxCardVisitUpsertBulk) UpdateBotID() *WxCardVisitUpsertBulk {
  754. return u.Update(func(s *WxCardVisitUpsert) {
  755. s.UpdateBotID()
  756. })
  757. }
  758. // SetBotType sets the "bot_type" field.
  759. func (u *WxCardVisitUpsertBulk) SetBotType(v uint8) *WxCardVisitUpsertBulk {
  760. return u.Update(func(s *WxCardVisitUpsert) {
  761. s.SetBotType(v)
  762. })
  763. }
  764. // AddBotType adds v to the "bot_type" field.
  765. func (u *WxCardVisitUpsertBulk) AddBotType(v uint8) *WxCardVisitUpsertBulk {
  766. return u.Update(func(s *WxCardVisitUpsert) {
  767. s.AddBotType(v)
  768. })
  769. }
  770. // UpdateBotType sets the "bot_type" field to the value that was provided on create.
  771. func (u *WxCardVisitUpsertBulk) UpdateBotType() *WxCardVisitUpsertBulk {
  772. return u.Update(func(s *WxCardVisitUpsert) {
  773. s.UpdateBotType()
  774. })
  775. }
  776. // Exec executes the query.
  777. func (u *WxCardVisitUpsertBulk) Exec(ctx context.Context) error {
  778. if u.create.err != nil {
  779. return u.create.err
  780. }
  781. for i, b := range u.create.builders {
  782. if len(b.conflict) != 0 {
  783. return fmt.Errorf("ent: OnConflict was set for builder %d. Set it on the WxCardVisitCreateBulk instead", i)
  784. }
  785. }
  786. if len(u.create.conflict) == 0 {
  787. return errors.New("ent: missing options for WxCardVisitCreateBulk.OnConflict")
  788. }
  789. return u.create.Exec(ctx)
  790. }
  791. // ExecX is like Exec, but panics if an error occurs.
  792. func (u *WxCardVisitUpsertBulk) ExecX(ctx context.Context) {
  793. if err := u.create.Exec(ctx); err != nil {
  794. panic(err)
  795. }
  796. }