batchmsg_create.go 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481
  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/batchmsg"
  9. "entgo.io/ent/dialect/sql"
  10. "entgo.io/ent/dialect/sql/sqlgraph"
  11. "entgo.io/ent/schema/field"
  12. )
  13. // BatchMsgCreate is the builder for creating a BatchMsg entity.
  14. type BatchMsgCreate struct {
  15. config
  16. mutation *BatchMsgMutation
  17. hooks []Hook
  18. conflict []sql.ConflictOption
  19. }
  20. // SetCreatedAt sets the "created_at" field.
  21. func (bmc *BatchMsgCreate) SetCreatedAt(t time.Time) *BatchMsgCreate {
  22. bmc.mutation.SetCreatedAt(t)
  23. return bmc
  24. }
  25. // SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
  26. func (bmc *BatchMsgCreate) SetNillableCreatedAt(t *time.Time) *BatchMsgCreate {
  27. if t != nil {
  28. bmc.SetCreatedAt(*t)
  29. }
  30. return bmc
  31. }
  32. // SetUpdatedAt sets the "updated_at" field.
  33. func (bmc *BatchMsgCreate) SetUpdatedAt(t time.Time) *BatchMsgCreate {
  34. bmc.mutation.SetUpdatedAt(t)
  35. return bmc
  36. }
  37. // SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
  38. func (bmc *BatchMsgCreate) SetNillableUpdatedAt(t *time.Time) *BatchMsgCreate {
  39. if t != nil {
  40. bmc.SetUpdatedAt(*t)
  41. }
  42. return bmc
  43. }
  44. // SetDeletedAt sets the "deleted_at" field.
  45. func (bmc *BatchMsgCreate) SetDeletedAt(t time.Time) *BatchMsgCreate {
  46. bmc.mutation.SetDeletedAt(t)
  47. return bmc
  48. }
  49. // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
  50. func (bmc *BatchMsgCreate) SetNillableDeletedAt(t *time.Time) *BatchMsgCreate {
  51. if t != nil {
  52. bmc.SetDeletedAt(*t)
  53. }
  54. return bmc
  55. }
  56. // SetStatus sets the "status" field.
  57. func (bmc *BatchMsgCreate) SetStatus(u uint8) *BatchMsgCreate {
  58. bmc.mutation.SetStatus(u)
  59. return bmc
  60. }
  61. // SetNillableStatus sets the "status" field if the given value is not nil.
  62. func (bmc *BatchMsgCreate) SetNillableStatus(u *uint8) *BatchMsgCreate {
  63. if u != nil {
  64. bmc.SetStatus(*u)
  65. }
  66. return bmc
  67. }
  68. // SetBatchNo sets the "batch_no" field.
  69. func (bmc *BatchMsgCreate) SetBatchNo(s string) *BatchMsgCreate {
  70. bmc.mutation.SetBatchNo(s)
  71. return bmc
  72. }
  73. // SetNillableBatchNo sets the "batch_no" field if the given value is not nil.
  74. func (bmc *BatchMsgCreate) SetNillableBatchNo(s *string) *BatchMsgCreate {
  75. if s != nil {
  76. bmc.SetBatchNo(*s)
  77. }
  78. return bmc
  79. }
  80. // SetFromwxid sets the "fromwxid" field.
  81. func (bmc *BatchMsgCreate) SetFromwxid(s string) *BatchMsgCreate {
  82. bmc.mutation.SetFromwxid(s)
  83. return bmc
  84. }
  85. // SetNillableFromwxid sets the "fromwxid" field if the given value is not nil.
  86. func (bmc *BatchMsgCreate) SetNillableFromwxid(s *string) *BatchMsgCreate {
  87. if s != nil {
  88. bmc.SetFromwxid(*s)
  89. }
  90. return bmc
  91. }
  92. // SetMsg sets the "msg" field.
  93. func (bmc *BatchMsgCreate) SetMsg(s string) *BatchMsgCreate {
  94. bmc.mutation.SetMsg(s)
  95. return bmc
  96. }
  97. // SetNillableMsg sets the "msg" field if the given value is not nil.
  98. func (bmc *BatchMsgCreate) SetNillableMsg(s *string) *BatchMsgCreate {
  99. if s != nil {
  100. bmc.SetMsg(*s)
  101. }
  102. return bmc
  103. }
  104. // SetTag sets the "tag" field.
  105. func (bmc *BatchMsgCreate) SetTag(s string) *BatchMsgCreate {
  106. bmc.mutation.SetTag(s)
  107. return bmc
  108. }
  109. // SetNillableTag sets the "tag" field if the given value is not nil.
  110. func (bmc *BatchMsgCreate) SetNillableTag(s *string) *BatchMsgCreate {
  111. if s != nil {
  112. bmc.SetTag(*s)
  113. }
  114. return bmc
  115. }
  116. // SetTotal sets the "total" field.
  117. func (bmc *BatchMsgCreate) SetTotal(i int32) *BatchMsgCreate {
  118. bmc.mutation.SetTotal(i)
  119. return bmc
  120. }
  121. // SetNillableTotal sets the "total" field if the given value is not nil.
  122. func (bmc *BatchMsgCreate) SetNillableTotal(i *int32) *BatchMsgCreate {
  123. if i != nil {
  124. bmc.SetTotal(*i)
  125. }
  126. return bmc
  127. }
  128. // SetSuccess sets the "success" field.
  129. func (bmc *BatchMsgCreate) SetSuccess(i int32) *BatchMsgCreate {
  130. bmc.mutation.SetSuccess(i)
  131. return bmc
  132. }
  133. // SetNillableSuccess sets the "success" field if the given value is not nil.
  134. func (bmc *BatchMsgCreate) SetNillableSuccess(i *int32) *BatchMsgCreate {
  135. if i != nil {
  136. bmc.SetSuccess(*i)
  137. }
  138. return bmc
  139. }
  140. // SetFail sets the "fail" field.
  141. func (bmc *BatchMsgCreate) SetFail(i int32) *BatchMsgCreate {
  142. bmc.mutation.SetFail(i)
  143. return bmc
  144. }
  145. // SetNillableFail sets the "fail" field if the given value is not nil.
  146. func (bmc *BatchMsgCreate) SetNillableFail(i *int32) *BatchMsgCreate {
  147. if i != nil {
  148. bmc.SetFail(*i)
  149. }
  150. return bmc
  151. }
  152. // SetStartTime sets the "start_time" field.
  153. func (bmc *BatchMsgCreate) SetStartTime(t time.Time) *BatchMsgCreate {
  154. bmc.mutation.SetStartTime(t)
  155. return bmc
  156. }
  157. // SetNillableStartTime sets the "start_time" field if the given value is not nil.
  158. func (bmc *BatchMsgCreate) SetNillableStartTime(t *time.Time) *BatchMsgCreate {
  159. if t != nil {
  160. bmc.SetStartTime(*t)
  161. }
  162. return bmc
  163. }
  164. // SetStopTime sets the "stop_time" field.
  165. func (bmc *BatchMsgCreate) SetStopTime(t time.Time) *BatchMsgCreate {
  166. bmc.mutation.SetStopTime(t)
  167. return bmc
  168. }
  169. // SetNillableStopTime sets the "stop_time" field if the given value is not nil.
  170. func (bmc *BatchMsgCreate) SetNillableStopTime(t *time.Time) *BatchMsgCreate {
  171. if t != nil {
  172. bmc.SetStopTime(*t)
  173. }
  174. return bmc
  175. }
  176. // SetID sets the "id" field.
  177. func (bmc *BatchMsgCreate) SetID(u uint64) *BatchMsgCreate {
  178. bmc.mutation.SetID(u)
  179. return bmc
  180. }
  181. // Mutation returns the BatchMsgMutation object of the builder.
  182. func (bmc *BatchMsgCreate) Mutation() *BatchMsgMutation {
  183. return bmc.mutation
  184. }
  185. // Save creates the BatchMsg in the database.
  186. func (bmc *BatchMsgCreate) Save(ctx context.Context) (*BatchMsg, error) {
  187. if err := bmc.defaults(); err != nil {
  188. return nil, err
  189. }
  190. return withHooks(ctx, bmc.sqlSave, bmc.mutation, bmc.hooks)
  191. }
  192. // SaveX calls Save and panics if Save returns an error.
  193. func (bmc *BatchMsgCreate) SaveX(ctx context.Context) *BatchMsg {
  194. v, err := bmc.Save(ctx)
  195. if err != nil {
  196. panic(err)
  197. }
  198. return v
  199. }
  200. // Exec executes the query.
  201. func (bmc *BatchMsgCreate) Exec(ctx context.Context) error {
  202. _, err := bmc.Save(ctx)
  203. return err
  204. }
  205. // ExecX is like Exec, but panics if an error occurs.
  206. func (bmc *BatchMsgCreate) ExecX(ctx context.Context) {
  207. if err := bmc.Exec(ctx); err != nil {
  208. panic(err)
  209. }
  210. }
  211. // defaults sets the default values of the builder before save.
  212. func (bmc *BatchMsgCreate) defaults() error {
  213. if _, ok := bmc.mutation.CreatedAt(); !ok {
  214. if batchmsg.DefaultCreatedAt == nil {
  215. return fmt.Errorf("ent: uninitialized batchmsg.DefaultCreatedAt (forgotten import ent/runtime?)")
  216. }
  217. v := batchmsg.DefaultCreatedAt()
  218. bmc.mutation.SetCreatedAt(v)
  219. }
  220. if _, ok := bmc.mutation.UpdatedAt(); !ok {
  221. if batchmsg.DefaultUpdatedAt == nil {
  222. return fmt.Errorf("ent: uninitialized batchmsg.DefaultUpdatedAt (forgotten import ent/runtime?)")
  223. }
  224. v := batchmsg.DefaultUpdatedAt()
  225. bmc.mutation.SetUpdatedAt(v)
  226. }
  227. return nil
  228. }
  229. // check runs all checks and user-defined validators on the builder.
  230. func (bmc *BatchMsgCreate) check() error {
  231. if _, ok := bmc.mutation.CreatedAt(); !ok {
  232. return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "BatchMsg.created_at"`)}
  233. }
  234. if _, ok := bmc.mutation.UpdatedAt(); !ok {
  235. return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "BatchMsg.updated_at"`)}
  236. }
  237. return nil
  238. }
  239. func (bmc *BatchMsgCreate) sqlSave(ctx context.Context) (*BatchMsg, error) {
  240. if err := bmc.check(); err != nil {
  241. return nil, err
  242. }
  243. _node, _spec := bmc.createSpec()
  244. if err := sqlgraph.CreateNode(ctx, bmc.driver, _spec); err != nil {
  245. if sqlgraph.IsConstraintError(err) {
  246. err = &ConstraintError{msg: err.Error(), wrap: err}
  247. }
  248. return nil, err
  249. }
  250. if _spec.ID.Value != _node.ID {
  251. id := _spec.ID.Value.(int64)
  252. _node.ID = uint64(id)
  253. }
  254. bmc.mutation.id = &_node.ID
  255. bmc.mutation.done = true
  256. return _node, nil
  257. }
  258. func (bmc *BatchMsgCreate) createSpec() (*BatchMsg, *sqlgraph.CreateSpec) {
  259. var (
  260. _node = &BatchMsg{config: bmc.config}
  261. _spec = sqlgraph.NewCreateSpec(batchmsg.Table, sqlgraph.NewFieldSpec(batchmsg.FieldID, field.TypeUint64))
  262. )
  263. _spec.OnConflict = bmc.conflict
  264. if id, ok := bmc.mutation.ID(); ok {
  265. _node.ID = id
  266. _spec.ID.Value = id
  267. }
  268. if value, ok := bmc.mutation.CreatedAt(); ok {
  269. _spec.SetField(batchmsg.FieldCreatedAt, field.TypeTime, value)
  270. _node.CreatedAt = value
  271. }
  272. if value, ok := bmc.mutation.UpdatedAt(); ok {
  273. _spec.SetField(batchmsg.FieldUpdatedAt, field.TypeTime, value)
  274. _node.UpdatedAt = value
  275. }
  276. if value, ok := bmc.mutation.DeletedAt(); ok {
  277. _spec.SetField(batchmsg.FieldDeletedAt, field.TypeTime, value)
  278. _node.DeletedAt = value
  279. }
  280. if value, ok := bmc.mutation.Status(); ok {
  281. _spec.SetField(batchmsg.FieldStatus, field.TypeUint8, value)
  282. _node.Status = value
  283. }
  284. if value, ok := bmc.mutation.BatchNo(); ok {
  285. _spec.SetField(batchmsg.FieldBatchNo, field.TypeString, value)
  286. _node.BatchNo = value
  287. }
  288. if value, ok := bmc.mutation.Fromwxid(); ok {
  289. _spec.SetField(batchmsg.FieldFromwxid, field.TypeString, value)
  290. _node.Fromwxid = value
  291. }
  292. if value, ok := bmc.mutation.Msg(); ok {
  293. _spec.SetField(batchmsg.FieldMsg, field.TypeString, value)
  294. _node.Msg = value
  295. }
  296. if value, ok := bmc.mutation.Tag(); ok {
  297. _spec.SetField(batchmsg.FieldTag, field.TypeString, value)
  298. _node.Tag = value
  299. }
  300. if value, ok := bmc.mutation.Total(); ok {
  301. _spec.SetField(batchmsg.FieldTotal, field.TypeInt32, value)
  302. _node.Total = value
  303. }
  304. if value, ok := bmc.mutation.Success(); ok {
  305. _spec.SetField(batchmsg.FieldSuccess, field.TypeInt32, value)
  306. _node.Success = value
  307. }
  308. if value, ok := bmc.mutation.Fail(); ok {
  309. _spec.SetField(batchmsg.FieldFail, field.TypeInt32, value)
  310. _node.Fail = value
  311. }
  312. if value, ok := bmc.mutation.StartTime(); ok {
  313. _spec.SetField(batchmsg.FieldStartTime, field.TypeTime, value)
  314. _node.StartTime = value
  315. }
  316. if value, ok := bmc.mutation.StopTime(); ok {
  317. _spec.SetField(batchmsg.FieldStopTime, field.TypeTime, value)
  318. _node.StopTime = value
  319. }
  320. return _node, _spec
  321. }
  322. // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
  323. // of the `INSERT` statement. For example:
  324. //
  325. // client.BatchMsg.Create().
  326. // SetCreatedAt(v).
  327. // OnConflict(
  328. // // Update the row with the new values
  329. // // the was proposed for insertion.
  330. // sql.ResolveWithNewValues(),
  331. // ).
  332. // // Override some of the fields with custom
  333. // // update values.
  334. // Update(func(u *ent.BatchMsgUpsert) {
  335. // SetCreatedAt(v+v).
  336. // }).
  337. // Exec(ctx)
  338. func (bmc *BatchMsgCreate) OnConflict(opts ...sql.ConflictOption) *BatchMsgUpsertOne {
  339. bmc.conflict = opts
  340. return &BatchMsgUpsertOne{
  341. create: bmc,
  342. }
  343. }
  344. // OnConflictColumns calls `OnConflict` and configures the columns
  345. // as conflict target. Using this option is equivalent to using:
  346. //
  347. // client.BatchMsg.Create().
  348. // OnConflict(sql.ConflictColumns(columns...)).
  349. // Exec(ctx)
  350. func (bmc *BatchMsgCreate) OnConflictColumns(columns ...string) *BatchMsgUpsertOne {
  351. bmc.conflict = append(bmc.conflict, sql.ConflictColumns(columns...))
  352. return &BatchMsgUpsertOne{
  353. create: bmc,
  354. }
  355. }
  356. type (
  357. // BatchMsgUpsertOne is the builder for "upsert"-ing
  358. // one BatchMsg node.
  359. BatchMsgUpsertOne struct {
  360. create *BatchMsgCreate
  361. }
  362. // BatchMsgUpsert is the "OnConflict" setter.
  363. BatchMsgUpsert struct {
  364. *sql.UpdateSet
  365. }
  366. )
  367. // SetUpdatedAt sets the "updated_at" field.
  368. func (u *BatchMsgUpsert) SetUpdatedAt(v time.Time) *BatchMsgUpsert {
  369. u.Set(batchmsg.FieldUpdatedAt, v)
  370. return u
  371. }
  372. // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
  373. func (u *BatchMsgUpsert) UpdateUpdatedAt() *BatchMsgUpsert {
  374. u.SetExcluded(batchmsg.FieldUpdatedAt)
  375. return u
  376. }
  377. // SetDeletedAt sets the "deleted_at" field.
  378. func (u *BatchMsgUpsert) SetDeletedAt(v time.Time) *BatchMsgUpsert {
  379. u.Set(batchmsg.FieldDeletedAt, v)
  380. return u
  381. }
  382. // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
  383. func (u *BatchMsgUpsert) UpdateDeletedAt() *BatchMsgUpsert {
  384. u.SetExcluded(batchmsg.FieldDeletedAt)
  385. return u
  386. }
  387. // ClearDeletedAt clears the value of the "deleted_at" field.
  388. func (u *BatchMsgUpsert) ClearDeletedAt() *BatchMsgUpsert {
  389. u.SetNull(batchmsg.FieldDeletedAt)
  390. return u
  391. }
  392. // SetStatus sets the "status" field.
  393. func (u *BatchMsgUpsert) SetStatus(v uint8) *BatchMsgUpsert {
  394. u.Set(batchmsg.FieldStatus, v)
  395. return u
  396. }
  397. // UpdateStatus sets the "status" field to the value that was provided on create.
  398. func (u *BatchMsgUpsert) UpdateStatus() *BatchMsgUpsert {
  399. u.SetExcluded(batchmsg.FieldStatus)
  400. return u
  401. }
  402. // AddStatus adds v to the "status" field.
  403. func (u *BatchMsgUpsert) AddStatus(v uint8) *BatchMsgUpsert {
  404. u.Add(batchmsg.FieldStatus, v)
  405. return u
  406. }
  407. // ClearStatus clears the value of the "status" field.
  408. func (u *BatchMsgUpsert) ClearStatus() *BatchMsgUpsert {
  409. u.SetNull(batchmsg.FieldStatus)
  410. return u
  411. }
  412. // SetBatchNo sets the "batch_no" field.
  413. func (u *BatchMsgUpsert) SetBatchNo(v string) *BatchMsgUpsert {
  414. u.Set(batchmsg.FieldBatchNo, v)
  415. return u
  416. }
  417. // UpdateBatchNo sets the "batch_no" field to the value that was provided on create.
  418. func (u *BatchMsgUpsert) UpdateBatchNo() *BatchMsgUpsert {
  419. u.SetExcluded(batchmsg.FieldBatchNo)
  420. return u
  421. }
  422. // ClearBatchNo clears the value of the "batch_no" field.
  423. func (u *BatchMsgUpsert) ClearBatchNo() *BatchMsgUpsert {
  424. u.SetNull(batchmsg.FieldBatchNo)
  425. return u
  426. }
  427. // SetFromwxid sets the "fromwxid" field.
  428. func (u *BatchMsgUpsert) SetFromwxid(v string) *BatchMsgUpsert {
  429. u.Set(batchmsg.FieldFromwxid, v)
  430. return u
  431. }
  432. // UpdateFromwxid sets the "fromwxid" field to the value that was provided on create.
  433. func (u *BatchMsgUpsert) UpdateFromwxid() *BatchMsgUpsert {
  434. u.SetExcluded(batchmsg.FieldFromwxid)
  435. return u
  436. }
  437. // ClearFromwxid clears the value of the "fromwxid" field.
  438. func (u *BatchMsgUpsert) ClearFromwxid() *BatchMsgUpsert {
  439. u.SetNull(batchmsg.FieldFromwxid)
  440. return u
  441. }
  442. // SetMsg sets the "msg" field.
  443. func (u *BatchMsgUpsert) SetMsg(v string) *BatchMsgUpsert {
  444. u.Set(batchmsg.FieldMsg, v)
  445. return u
  446. }
  447. // UpdateMsg sets the "msg" field to the value that was provided on create.
  448. func (u *BatchMsgUpsert) UpdateMsg() *BatchMsgUpsert {
  449. u.SetExcluded(batchmsg.FieldMsg)
  450. return u
  451. }
  452. // ClearMsg clears the value of the "msg" field.
  453. func (u *BatchMsgUpsert) ClearMsg() *BatchMsgUpsert {
  454. u.SetNull(batchmsg.FieldMsg)
  455. return u
  456. }
  457. // SetTag sets the "tag" field.
  458. func (u *BatchMsgUpsert) SetTag(v string) *BatchMsgUpsert {
  459. u.Set(batchmsg.FieldTag, v)
  460. return u
  461. }
  462. // UpdateTag sets the "tag" field to the value that was provided on create.
  463. func (u *BatchMsgUpsert) UpdateTag() *BatchMsgUpsert {
  464. u.SetExcluded(batchmsg.FieldTag)
  465. return u
  466. }
  467. // ClearTag clears the value of the "tag" field.
  468. func (u *BatchMsgUpsert) ClearTag() *BatchMsgUpsert {
  469. u.SetNull(batchmsg.FieldTag)
  470. return u
  471. }
  472. // SetTotal sets the "total" field.
  473. func (u *BatchMsgUpsert) SetTotal(v int32) *BatchMsgUpsert {
  474. u.Set(batchmsg.FieldTotal, v)
  475. return u
  476. }
  477. // UpdateTotal sets the "total" field to the value that was provided on create.
  478. func (u *BatchMsgUpsert) UpdateTotal() *BatchMsgUpsert {
  479. u.SetExcluded(batchmsg.FieldTotal)
  480. return u
  481. }
  482. // AddTotal adds v to the "total" field.
  483. func (u *BatchMsgUpsert) AddTotal(v int32) *BatchMsgUpsert {
  484. u.Add(batchmsg.FieldTotal, v)
  485. return u
  486. }
  487. // ClearTotal clears the value of the "total" field.
  488. func (u *BatchMsgUpsert) ClearTotal() *BatchMsgUpsert {
  489. u.SetNull(batchmsg.FieldTotal)
  490. return u
  491. }
  492. // SetSuccess sets the "success" field.
  493. func (u *BatchMsgUpsert) SetSuccess(v int32) *BatchMsgUpsert {
  494. u.Set(batchmsg.FieldSuccess, v)
  495. return u
  496. }
  497. // UpdateSuccess sets the "success" field to the value that was provided on create.
  498. func (u *BatchMsgUpsert) UpdateSuccess() *BatchMsgUpsert {
  499. u.SetExcluded(batchmsg.FieldSuccess)
  500. return u
  501. }
  502. // AddSuccess adds v to the "success" field.
  503. func (u *BatchMsgUpsert) AddSuccess(v int32) *BatchMsgUpsert {
  504. u.Add(batchmsg.FieldSuccess, v)
  505. return u
  506. }
  507. // ClearSuccess clears the value of the "success" field.
  508. func (u *BatchMsgUpsert) ClearSuccess() *BatchMsgUpsert {
  509. u.SetNull(batchmsg.FieldSuccess)
  510. return u
  511. }
  512. // SetFail sets the "fail" field.
  513. func (u *BatchMsgUpsert) SetFail(v int32) *BatchMsgUpsert {
  514. u.Set(batchmsg.FieldFail, v)
  515. return u
  516. }
  517. // UpdateFail sets the "fail" field to the value that was provided on create.
  518. func (u *BatchMsgUpsert) UpdateFail() *BatchMsgUpsert {
  519. u.SetExcluded(batchmsg.FieldFail)
  520. return u
  521. }
  522. // AddFail adds v to the "fail" field.
  523. func (u *BatchMsgUpsert) AddFail(v int32) *BatchMsgUpsert {
  524. u.Add(batchmsg.FieldFail, v)
  525. return u
  526. }
  527. // ClearFail clears the value of the "fail" field.
  528. func (u *BatchMsgUpsert) ClearFail() *BatchMsgUpsert {
  529. u.SetNull(batchmsg.FieldFail)
  530. return u
  531. }
  532. // SetStartTime sets the "start_time" field.
  533. func (u *BatchMsgUpsert) SetStartTime(v time.Time) *BatchMsgUpsert {
  534. u.Set(batchmsg.FieldStartTime, v)
  535. return u
  536. }
  537. // UpdateStartTime sets the "start_time" field to the value that was provided on create.
  538. func (u *BatchMsgUpsert) UpdateStartTime() *BatchMsgUpsert {
  539. u.SetExcluded(batchmsg.FieldStartTime)
  540. return u
  541. }
  542. // ClearStartTime clears the value of the "start_time" field.
  543. func (u *BatchMsgUpsert) ClearStartTime() *BatchMsgUpsert {
  544. u.SetNull(batchmsg.FieldStartTime)
  545. return u
  546. }
  547. // SetStopTime sets the "stop_time" field.
  548. func (u *BatchMsgUpsert) SetStopTime(v time.Time) *BatchMsgUpsert {
  549. u.Set(batchmsg.FieldStopTime, v)
  550. return u
  551. }
  552. // UpdateStopTime sets the "stop_time" field to the value that was provided on create.
  553. func (u *BatchMsgUpsert) UpdateStopTime() *BatchMsgUpsert {
  554. u.SetExcluded(batchmsg.FieldStopTime)
  555. return u
  556. }
  557. // ClearStopTime clears the value of the "stop_time" field.
  558. func (u *BatchMsgUpsert) ClearStopTime() *BatchMsgUpsert {
  559. u.SetNull(batchmsg.FieldStopTime)
  560. return u
  561. }
  562. // UpdateNewValues updates the mutable fields using the new values that were set on create except the ID field.
  563. // Using this option is equivalent to using:
  564. //
  565. // client.BatchMsg.Create().
  566. // OnConflict(
  567. // sql.ResolveWithNewValues(),
  568. // sql.ResolveWith(func(u *sql.UpdateSet) {
  569. // u.SetIgnore(batchmsg.FieldID)
  570. // }),
  571. // ).
  572. // Exec(ctx)
  573. func (u *BatchMsgUpsertOne) UpdateNewValues() *BatchMsgUpsertOne {
  574. u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
  575. u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
  576. if _, exists := u.create.mutation.ID(); exists {
  577. s.SetIgnore(batchmsg.FieldID)
  578. }
  579. if _, exists := u.create.mutation.CreatedAt(); exists {
  580. s.SetIgnore(batchmsg.FieldCreatedAt)
  581. }
  582. }))
  583. return u
  584. }
  585. // Ignore sets each column to itself in case of conflict.
  586. // Using this option is equivalent to using:
  587. //
  588. // client.BatchMsg.Create().
  589. // OnConflict(sql.ResolveWithIgnore()).
  590. // Exec(ctx)
  591. func (u *BatchMsgUpsertOne) Ignore() *BatchMsgUpsertOne {
  592. u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
  593. return u
  594. }
  595. // DoNothing configures the conflict_action to `DO NOTHING`.
  596. // Supported only by SQLite and PostgreSQL.
  597. func (u *BatchMsgUpsertOne) DoNothing() *BatchMsgUpsertOne {
  598. u.create.conflict = append(u.create.conflict, sql.DoNothing())
  599. return u
  600. }
  601. // Update allows overriding fields `UPDATE` values. See the BatchMsgCreate.OnConflict
  602. // documentation for more info.
  603. func (u *BatchMsgUpsertOne) Update(set func(*BatchMsgUpsert)) *BatchMsgUpsertOne {
  604. u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
  605. set(&BatchMsgUpsert{UpdateSet: update})
  606. }))
  607. return u
  608. }
  609. // SetUpdatedAt sets the "updated_at" field.
  610. func (u *BatchMsgUpsertOne) SetUpdatedAt(v time.Time) *BatchMsgUpsertOne {
  611. return u.Update(func(s *BatchMsgUpsert) {
  612. s.SetUpdatedAt(v)
  613. })
  614. }
  615. // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
  616. func (u *BatchMsgUpsertOne) UpdateUpdatedAt() *BatchMsgUpsertOne {
  617. return u.Update(func(s *BatchMsgUpsert) {
  618. s.UpdateUpdatedAt()
  619. })
  620. }
  621. // SetDeletedAt sets the "deleted_at" field.
  622. func (u *BatchMsgUpsertOne) SetDeletedAt(v time.Time) *BatchMsgUpsertOne {
  623. return u.Update(func(s *BatchMsgUpsert) {
  624. s.SetDeletedAt(v)
  625. })
  626. }
  627. // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
  628. func (u *BatchMsgUpsertOne) UpdateDeletedAt() *BatchMsgUpsertOne {
  629. return u.Update(func(s *BatchMsgUpsert) {
  630. s.UpdateDeletedAt()
  631. })
  632. }
  633. // ClearDeletedAt clears the value of the "deleted_at" field.
  634. func (u *BatchMsgUpsertOne) ClearDeletedAt() *BatchMsgUpsertOne {
  635. return u.Update(func(s *BatchMsgUpsert) {
  636. s.ClearDeletedAt()
  637. })
  638. }
  639. // SetStatus sets the "status" field.
  640. func (u *BatchMsgUpsertOne) SetStatus(v uint8) *BatchMsgUpsertOne {
  641. return u.Update(func(s *BatchMsgUpsert) {
  642. s.SetStatus(v)
  643. })
  644. }
  645. // AddStatus adds v to the "status" field.
  646. func (u *BatchMsgUpsertOne) AddStatus(v uint8) *BatchMsgUpsertOne {
  647. return u.Update(func(s *BatchMsgUpsert) {
  648. s.AddStatus(v)
  649. })
  650. }
  651. // UpdateStatus sets the "status" field to the value that was provided on create.
  652. func (u *BatchMsgUpsertOne) UpdateStatus() *BatchMsgUpsertOne {
  653. return u.Update(func(s *BatchMsgUpsert) {
  654. s.UpdateStatus()
  655. })
  656. }
  657. // ClearStatus clears the value of the "status" field.
  658. func (u *BatchMsgUpsertOne) ClearStatus() *BatchMsgUpsertOne {
  659. return u.Update(func(s *BatchMsgUpsert) {
  660. s.ClearStatus()
  661. })
  662. }
  663. // SetBatchNo sets the "batch_no" field.
  664. func (u *BatchMsgUpsertOne) SetBatchNo(v string) *BatchMsgUpsertOne {
  665. return u.Update(func(s *BatchMsgUpsert) {
  666. s.SetBatchNo(v)
  667. })
  668. }
  669. // UpdateBatchNo sets the "batch_no" field to the value that was provided on create.
  670. func (u *BatchMsgUpsertOne) UpdateBatchNo() *BatchMsgUpsertOne {
  671. return u.Update(func(s *BatchMsgUpsert) {
  672. s.UpdateBatchNo()
  673. })
  674. }
  675. // ClearBatchNo clears the value of the "batch_no" field.
  676. func (u *BatchMsgUpsertOne) ClearBatchNo() *BatchMsgUpsertOne {
  677. return u.Update(func(s *BatchMsgUpsert) {
  678. s.ClearBatchNo()
  679. })
  680. }
  681. // SetFromwxid sets the "fromwxid" field.
  682. func (u *BatchMsgUpsertOne) SetFromwxid(v string) *BatchMsgUpsertOne {
  683. return u.Update(func(s *BatchMsgUpsert) {
  684. s.SetFromwxid(v)
  685. })
  686. }
  687. // UpdateFromwxid sets the "fromwxid" field to the value that was provided on create.
  688. func (u *BatchMsgUpsertOne) UpdateFromwxid() *BatchMsgUpsertOne {
  689. return u.Update(func(s *BatchMsgUpsert) {
  690. s.UpdateFromwxid()
  691. })
  692. }
  693. // ClearFromwxid clears the value of the "fromwxid" field.
  694. func (u *BatchMsgUpsertOne) ClearFromwxid() *BatchMsgUpsertOne {
  695. return u.Update(func(s *BatchMsgUpsert) {
  696. s.ClearFromwxid()
  697. })
  698. }
  699. // SetMsg sets the "msg" field.
  700. func (u *BatchMsgUpsertOne) SetMsg(v string) *BatchMsgUpsertOne {
  701. return u.Update(func(s *BatchMsgUpsert) {
  702. s.SetMsg(v)
  703. })
  704. }
  705. // UpdateMsg sets the "msg" field to the value that was provided on create.
  706. func (u *BatchMsgUpsertOne) UpdateMsg() *BatchMsgUpsertOne {
  707. return u.Update(func(s *BatchMsgUpsert) {
  708. s.UpdateMsg()
  709. })
  710. }
  711. // ClearMsg clears the value of the "msg" field.
  712. func (u *BatchMsgUpsertOne) ClearMsg() *BatchMsgUpsertOne {
  713. return u.Update(func(s *BatchMsgUpsert) {
  714. s.ClearMsg()
  715. })
  716. }
  717. // SetTag sets the "tag" field.
  718. func (u *BatchMsgUpsertOne) SetTag(v string) *BatchMsgUpsertOne {
  719. return u.Update(func(s *BatchMsgUpsert) {
  720. s.SetTag(v)
  721. })
  722. }
  723. // UpdateTag sets the "tag" field to the value that was provided on create.
  724. func (u *BatchMsgUpsertOne) UpdateTag() *BatchMsgUpsertOne {
  725. return u.Update(func(s *BatchMsgUpsert) {
  726. s.UpdateTag()
  727. })
  728. }
  729. // ClearTag clears the value of the "tag" field.
  730. func (u *BatchMsgUpsertOne) ClearTag() *BatchMsgUpsertOne {
  731. return u.Update(func(s *BatchMsgUpsert) {
  732. s.ClearTag()
  733. })
  734. }
  735. // SetTotal sets the "total" field.
  736. func (u *BatchMsgUpsertOne) SetTotal(v int32) *BatchMsgUpsertOne {
  737. return u.Update(func(s *BatchMsgUpsert) {
  738. s.SetTotal(v)
  739. })
  740. }
  741. // AddTotal adds v to the "total" field.
  742. func (u *BatchMsgUpsertOne) AddTotal(v int32) *BatchMsgUpsertOne {
  743. return u.Update(func(s *BatchMsgUpsert) {
  744. s.AddTotal(v)
  745. })
  746. }
  747. // UpdateTotal sets the "total" field to the value that was provided on create.
  748. func (u *BatchMsgUpsertOne) UpdateTotal() *BatchMsgUpsertOne {
  749. return u.Update(func(s *BatchMsgUpsert) {
  750. s.UpdateTotal()
  751. })
  752. }
  753. // ClearTotal clears the value of the "total" field.
  754. func (u *BatchMsgUpsertOne) ClearTotal() *BatchMsgUpsertOne {
  755. return u.Update(func(s *BatchMsgUpsert) {
  756. s.ClearTotal()
  757. })
  758. }
  759. // SetSuccess sets the "success" field.
  760. func (u *BatchMsgUpsertOne) SetSuccess(v int32) *BatchMsgUpsertOne {
  761. return u.Update(func(s *BatchMsgUpsert) {
  762. s.SetSuccess(v)
  763. })
  764. }
  765. // AddSuccess adds v to the "success" field.
  766. func (u *BatchMsgUpsertOne) AddSuccess(v int32) *BatchMsgUpsertOne {
  767. return u.Update(func(s *BatchMsgUpsert) {
  768. s.AddSuccess(v)
  769. })
  770. }
  771. // UpdateSuccess sets the "success" field to the value that was provided on create.
  772. func (u *BatchMsgUpsertOne) UpdateSuccess() *BatchMsgUpsertOne {
  773. return u.Update(func(s *BatchMsgUpsert) {
  774. s.UpdateSuccess()
  775. })
  776. }
  777. // ClearSuccess clears the value of the "success" field.
  778. func (u *BatchMsgUpsertOne) ClearSuccess() *BatchMsgUpsertOne {
  779. return u.Update(func(s *BatchMsgUpsert) {
  780. s.ClearSuccess()
  781. })
  782. }
  783. // SetFail sets the "fail" field.
  784. func (u *BatchMsgUpsertOne) SetFail(v int32) *BatchMsgUpsertOne {
  785. return u.Update(func(s *BatchMsgUpsert) {
  786. s.SetFail(v)
  787. })
  788. }
  789. // AddFail adds v to the "fail" field.
  790. func (u *BatchMsgUpsertOne) AddFail(v int32) *BatchMsgUpsertOne {
  791. return u.Update(func(s *BatchMsgUpsert) {
  792. s.AddFail(v)
  793. })
  794. }
  795. // UpdateFail sets the "fail" field to the value that was provided on create.
  796. func (u *BatchMsgUpsertOne) UpdateFail() *BatchMsgUpsertOne {
  797. return u.Update(func(s *BatchMsgUpsert) {
  798. s.UpdateFail()
  799. })
  800. }
  801. // ClearFail clears the value of the "fail" field.
  802. func (u *BatchMsgUpsertOne) ClearFail() *BatchMsgUpsertOne {
  803. return u.Update(func(s *BatchMsgUpsert) {
  804. s.ClearFail()
  805. })
  806. }
  807. // SetStartTime sets the "start_time" field.
  808. func (u *BatchMsgUpsertOne) SetStartTime(v time.Time) *BatchMsgUpsertOne {
  809. return u.Update(func(s *BatchMsgUpsert) {
  810. s.SetStartTime(v)
  811. })
  812. }
  813. // UpdateStartTime sets the "start_time" field to the value that was provided on create.
  814. func (u *BatchMsgUpsertOne) UpdateStartTime() *BatchMsgUpsertOne {
  815. return u.Update(func(s *BatchMsgUpsert) {
  816. s.UpdateStartTime()
  817. })
  818. }
  819. // ClearStartTime clears the value of the "start_time" field.
  820. func (u *BatchMsgUpsertOne) ClearStartTime() *BatchMsgUpsertOne {
  821. return u.Update(func(s *BatchMsgUpsert) {
  822. s.ClearStartTime()
  823. })
  824. }
  825. // SetStopTime sets the "stop_time" field.
  826. func (u *BatchMsgUpsertOne) SetStopTime(v time.Time) *BatchMsgUpsertOne {
  827. return u.Update(func(s *BatchMsgUpsert) {
  828. s.SetStopTime(v)
  829. })
  830. }
  831. // UpdateStopTime sets the "stop_time" field to the value that was provided on create.
  832. func (u *BatchMsgUpsertOne) UpdateStopTime() *BatchMsgUpsertOne {
  833. return u.Update(func(s *BatchMsgUpsert) {
  834. s.UpdateStopTime()
  835. })
  836. }
  837. // ClearStopTime clears the value of the "stop_time" field.
  838. func (u *BatchMsgUpsertOne) ClearStopTime() *BatchMsgUpsertOne {
  839. return u.Update(func(s *BatchMsgUpsert) {
  840. s.ClearStopTime()
  841. })
  842. }
  843. // Exec executes the query.
  844. func (u *BatchMsgUpsertOne) Exec(ctx context.Context) error {
  845. if len(u.create.conflict) == 0 {
  846. return errors.New("ent: missing options for BatchMsgCreate.OnConflict")
  847. }
  848. return u.create.Exec(ctx)
  849. }
  850. // ExecX is like Exec, but panics if an error occurs.
  851. func (u *BatchMsgUpsertOne) ExecX(ctx context.Context) {
  852. if err := u.create.Exec(ctx); err != nil {
  853. panic(err)
  854. }
  855. }
  856. // Exec executes the UPSERT query and returns the inserted/updated ID.
  857. func (u *BatchMsgUpsertOne) ID(ctx context.Context) (id uint64, err error) {
  858. node, err := u.create.Save(ctx)
  859. if err != nil {
  860. return id, err
  861. }
  862. return node.ID, nil
  863. }
  864. // IDX is like ID, but panics if an error occurs.
  865. func (u *BatchMsgUpsertOne) IDX(ctx context.Context) uint64 {
  866. id, err := u.ID(ctx)
  867. if err != nil {
  868. panic(err)
  869. }
  870. return id
  871. }
  872. // BatchMsgCreateBulk is the builder for creating many BatchMsg entities in bulk.
  873. type BatchMsgCreateBulk struct {
  874. config
  875. err error
  876. builders []*BatchMsgCreate
  877. conflict []sql.ConflictOption
  878. }
  879. // Save creates the BatchMsg entities in the database.
  880. func (bmcb *BatchMsgCreateBulk) Save(ctx context.Context) ([]*BatchMsg, error) {
  881. if bmcb.err != nil {
  882. return nil, bmcb.err
  883. }
  884. specs := make([]*sqlgraph.CreateSpec, len(bmcb.builders))
  885. nodes := make([]*BatchMsg, len(bmcb.builders))
  886. mutators := make([]Mutator, len(bmcb.builders))
  887. for i := range bmcb.builders {
  888. func(i int, root context.Context) {
  889. builder := bmcb.builders[i]
  890. builder.defaults()
  891. var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
  892. mutation, ok := m.(*BatchMsgMutation)
  893. if !ok {
  894. return nil, fmt.Errorf("unexpected mutation type %T", m)
  895. }
  896. if err := builder.check(); err != nil {
  897. return nil, err
  898. }
  899. builder.mutation = mutation
  900. var err error
  901. nodes[i], specs[i] = builder.createSpec()
  902. if i < len(mutators)-1 {
  903. _, err = mutators[i+1].Mutate(root, bmcb.builders[i+1].mutation)
  904. } else {
  905. spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
  906. spec.OnConflict = bmcb.conflict
  907. // Invoke the actual operation on the latest mutation in the chain.
  908. if err = sqlgraph.BatchCreate(ctx, bmcb.driver, spec); err != nil {
  909. if sqlgraph.IsConstraintError(err) {
  910. err = &ConstraintError{msg: err.Error(), wrap: err}
  911. }
  912. }
  913. }
  914. if err != nil {
  915. return nil, err
  916. }
  917. mutation.id = &nodes[i].ID
  918. if specs[i].ID.Value != nil && nodes[i].ID == 0 {
  919. id := specs[i].ID.Value.(int64)
  920. nodes[i].ID = uint64(id)
  921. }
  922. mutation.done = true
  923. return nodes[i], nil
  924. })
  925. for i := len(builder.hooks) - 1; i >= 0; i-- {
  926. mut = builder.hooks[i](mut)
  927. }
  928. mutators[i] = mut
  929. }(i, ctx)
  930. }
  931. if len(mutators) > 0 {
  932. if _, err := mutators[0].Mutate(ctx, bmcb.builders[0].mutation); err != nil {
  933. return nil, err
  934. }
  935. }
  936. return nodes, nil
  937. }
  938. // SaveX is like Save, but panics if an error occurs.
  939. func (bmcb *BatchMsgCreateBulk) SaveX(ctx context.Context) []*BatchMsg {
  940. v, err := bmcb.Save(ctx)
  941. if err != nil {
  942. panic(err)
  943. }
  944. return v
  945. }
  946. // Exec executes the query.
  947. func (bmcb *BatchMsgCreateBulk) Exec(ctx context.Context) error {
  948. _, err := bmcb.Save(ctx)
  949. return err
  950. }
  951. // ExecX is like Exec, but panics if an error occurs.
  952. func (bmcb *BatchMsgCreateBulk) ExecX(ctx context.Context) {
  953. if err := bmcb.Exec(ctx); err != nil {
  954. panic(err)
  955. }
  956. }
  957. // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
  958. // of the `INSERT` statement. For example:
  959. //
  960. // client.BatchMsg.CreateBulk(builders...).
  961. // OnConflict(
  962. // // Update the row with the new values
  963. // // the was proposed for insertion.
  964. // sql.ResolveWithNewValues(),
  965. // ).
  966. // // Override some of the fields with custom
  967. // // update values.
  968. // Update(func(u *ent.BatchMsgUpsert) {
  969. // SetCreatedAt(v+v).
  970. // }).
  971. // Exec(ctx)
  972. func (bmcb *BatchMsgCreateBulk) OnConflict(opts ...sql.ConflictOption) *BatchMsgUpsertBulk {
  973. bmcb.conflict = opts
  974. return &BatchMsgUpsertBulk{
  975. create: bmcb,
  976. }
  977. }
  978. // OnConflictColumns calls `OnConflict` and configures the columns
  979. // as conflict target. Using this option is equivalent to using:
  980. //
  981. // client.BatchMsg.Create().
  982. // OnConflict(sql.ConflictColumns(columns...)).
  983. // Exec(ctx)
  984. func (bmcb *BatchMsgCreateBulk) OnConflictColumns(columns ...string) *BatchMsgUpsertBulk {
  985. bmcb.conflict = append(bmcb.conflict, sql.ConflictColumns(columns...))
  986. return &BatchMsgUpsertBulk{
  987. create: bmcb,
  988. }
  989. }
  990. // BatchMsgUpsertBulk is the builder for "upsert"-ing
  991. // a bulk of BatchMsg nodes.
  992. type BatchMsgUpsertBulk struct {
  993. create *BatchMsgCreateBulk
  994. }
  995. // UpdateNewValues updates the mutable fields using the new values that
  996. // were set on create. Using this option is equivalent to using:
  997. //
  998. // client.BatchMsg.Create().
  999. // OnConflict(
  1000. // sql.ResolveWithNewValues(),
  1001. // sql.ResolveWith(func(u *sql.UpdateSet) {
  1002. // u.SetIgnore(batchmsg.FieldID)
  1003. // }),
  1004. // ).
  1005. // Exec(ctx)
  1006. func (u *BatchMsgUpsertBulk) UpdateNewValues() *BatchMsgUpsertBulk {
  1007. u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
  1008. u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
  1009. for _, b := range u.create.builders {
  1010. if _, exists := b.mutation.ID(); exists {
  1011. s.SetIgnore(batchmsg.FieldID)
  1012. }
  1013. if _, exists := b.mutation.CreatedAt(); exists {
  1014. s.SetIgnore(batchmsg.FieldCreatedAt)
  1015. }
  1016. }
  1017. }))
  1018. return u
  1019. }
  1020. // Ignore sets each column to itself in case of conflict.
  1021. // Using this option is equivalent to using:
  1022. //
  1023. // client.BatchMsg.Create().
  1024. // OnConflict(sql.ResolveWithIgnore()).
  1025. // Exec(ctx)
  1026. func (u *BatchMsgUpsertBulk) Ignore() *BatchMsgUpsertBulk {
  1027. u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
  1028. return u
  1029. }
  1030. // DoNothing configures the conflict_action to `DO NOTHING`.
  1031. // Supported only by SQLite and PostgreSQL.
  1032. func (u *BatchMsgUpsertBulk) DoNothing() *BatchMsgUpsertBulk {
  1033. u.create.conflict = append(u.create.conflict, sql.DoNothing())
  1034. return u
  1035. }
  1036. // Update allows overriding fields `UPDATE` values. See the BatchMsgCreateBulk.OnConflict
  1037. // documentation for more info.
  1038. func (u *BatchMsgUpsertBulk) Update(set func(*BatchMsgUpsert)) *BatchMsgUpsertBulk {
  1039. u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
  1040. set(&BatchMsgUpsert{UpdateSet: update})
  1041. }))
  1042. return u
  1043. }
  1044. // SetUpdatedAt sets the "updated_at" field.
  1045. func (u *BatchMsgUpsertBulk) SetUpdatedAt(v time.Time) *BatchMsgUpsertBulk {
  1046. return u.Update(func(s *BatchMsgUpsert) {
  1047. s.SetUpdatedAt(v)
  1048. })
  1049. }
  1050. // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
  1051. func (u *BatchMsgUpsertBulk) UpdateUpdatedAt() *BatchMsgUpsertBulk {
  1052. return u.Update(func(s *BatchMsgUpsert) {
  1053. s.UpdateUpdatedAt()
  1054. })
  1055. }
  1056. // SetDeletedAt sets the "deleted_at" field.
  1057. func (u *BatchMsgUpsertBulk) SetDeletedAt(v time.Time) *BatchMsgUpsertBulk {
  1058. return u.Update(func(s *BatchMsgUpsert) {
  1059. s.SetDeletedAt(v)
  1060. })
  1061. }
  1062. // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
  1063. func (u *BatchMsgUpsertBulk) UpdateDeletedAt() *BatchMsgUpsertBulk {
  1064. return u.Update(func(s *BatchMsgUpsert) {
  1065. s.UpdateDeletedAt()
  1066. })
  1067. }
  1068. // ClearDeletedAt clears the value of the "deleted_at" field.
  1069. func (u *BatchMsgUpsertBulk) ClearDeletedAt() *BatchMsgUpsertBulk {
  1070. return u.Update(func(s *BatchMsgUpsert) {
  1071. s.ClearDeletedAt()
  1072. })
  1073. }
  1074. // SetStatus sets the "status" field.
  1075. func (u *BatchMsgUpsertBulk) SetStatus(v uint8) *BatchMsgUpsertBulk {
  1076. return u.Update(func(s *BatchMsgUpsert) {
  1077. s.SetStatus(v)
  1078. })
  1079. }
  1080. // AddStatus adds v to the "status" field.
  1081. func (u *BatchMsgUpsertBulk) AddStatus(v uint8) *BatchMsgUpsertBulk {
  1082. return u.Update(func(s *BatchMsgUpsert) {
  1083. s.AddStatus(v)
  1084. })
  1085. }
  1086. // UpdateStatus sets the "status" field to the value that was provided on create.
  1087. func (u *BatchMsgUpsertBulk) UpdateStatus() *BatchMsgUpsertBulk {
  1088. return u.Update(func(s *BatchMsgUpsert) {
  1089. s.UpdateStatus()
  1090. })
  1091. }
  1092. // ClearStatus clears the value of the "status" field.
  1093. func (u *BatchMsgUpsertBulk) ClearStatus() *BatchMsgUpsertBulk {
  1094. return u.Update(func(s *BatchMsgUpsert) {
  1095. s.ClearStatus()
  1096. })
  1097. }
  1098. // SetBatchNo sets the "batch_no" field.
  1099. func (u *BatchMsgUpsertBulk) SetBatchNo(v string) *BatchMsgUpsertBulk {
  1100. return u.Update(func(s *BatchMsgUpsert) {
  1101. s.SetBatchNo(v)
  1102. })
  1103. }
  1104. // UpdateBatchNo sets the "batch_no" field to the value that was provided on create.
  1105. func (u *BatchMsgUpsertBulk) UpdateBatchNo() *BatchMsgUpsertBulk {
  1106. return u.Update(func(s *BatchMsgUpsert) {
  1107. s.UpdateBatchNo()
  1108. })
  1109. }
  1110. // ClearBatchNo clears the value of the "batch_no" field.
  1111. func (u *BatchMsgUpsertBulk) ClearBatchNo() *BatchMsgUpsertBulk {
  1112. return u.Update(func(s *BatchMsgUpsert) {
  1113. s.ClearBatchNo()
  1114. })
  1115. }
  1116. // SetFromwxid sets the "fromwxid" field.
  1117. func (u *BatchMsgUpsertBulk) SetFromwxid(v string) *BatchMsgUpsertBulk {
  1118. return u.Update(func(s *BatchMsgUpsert) {
  1119. s.SetFromwxid(v)
  1120. })
  1121. }
  1122. // UpdateFromwxid sets the "fromwxid" field to the value that was provided on create.
  1123. func (u *BatchMsgUpsertBulk) UpdateFromwxid() *BatchMsgUpsertBulk {
  1124. return u.Update(func(s *BatchMsgUpsert) {
  1125. s.UpdateFromwxid()
  1126. })
  1127. }
  1128. // ClearFromwxid clears the value of the "fromwxid" field.
  1129. func (u *BatchMsgUpsertBulk) ClearFromwxid() *BatchMsgUpsertBulk {
  1130. return u.Update(func(s *BatchMsgUpsert) {
  1131. s.ClearFromwxid()
  1132. })
  1133. }
  1134. // SetMsg sets the "msg" field.
  1135. func (u *BatchMsgUpsertBulk) SetMsg(v string) *BatchMsgUpsertBulk {
  1136. return u.Update(func(s *BatchMsgUpsert) {
  1137. s.SetMsg(v)
  1138. })
  1139. }
  1140. // UpdateMsg sets the "msg" field to the value that was provided on create.
  1141. func (u *BatchMsgUpsertBulk) UpdateMsg() *BatchMsgUpsertBulk {
  1142. return u.Update(func(s *BatchMsgUpsert) {
  1143. s.UpdateMsg()
  1144. })
  1145. }
  1146. // ClearMsg clears the value of the "msg" field.
  1147. func (u *BatchMsgUpsertBulk) ClearMsg() *BatchMsgUpsertBulk {
  1148. return u.Update(func(s *BatchMsgUpsert) {
  1149. s.ClearMsg()
  1150. })
  1151. }
  1152. // SetTag sets the "tag" field.
  1153. func (u *BatchMsgUpsertBulk) SetTag(v string) *BatchMsgUpsertBulk {
  1154. return u.Update(func(s *BatchMsgUpsert) {
  1155. s.SetTag(v)
  1156. })
  1157. }
  1158. // UpdateTag sets the "tag" field to the value that was provided on create.
  1159. func (u *BatchMsgUpsertBulk) UpdateTag() *BatchMsgUpsertBulk {
  1160. return u.Update(func(s *BatchMsgUpsert) {
  1161. s.UpdateTag()
  1162. })
  1163. }
  1164. // ClearTag clears the value of the "tag" field.
  1165. func (u *BatchMsgUpsertBulk) ClearTag() *BatchMsgUpsertBulk {
  1166. return u.Update(func(s *BatchMsgUpsert) {
  1167. s.ClearTag()
  1168. })
  1169. }
  1170. // SetTotal sets the "total" field.
  1171. func (u *BatchMsgUpsertBulk) SetTotal(v int32) *BatchMsgUpsertBulk {
  1172. return u.Update(func(s *BatchMsgUpsert) {
  1173. s.SetTotal(v)
  1174. })
  1175. }
  1176. // AddTotal adds v to the "total" field.
  1177. func (u *BatchMsgUpsertBulk) AddTotal(v int32) *BatchMsgUpsertBulk {
  1178. return u.Update(func(s *BatchMsgUpsert) {
  1179. s.AddTotal(v)
  1180. })
  1181. }
  1182. // UpdateTotal sets the "total" field to the value that was provided on create.
  1183. func (u *BatchMsgUpsertBulk) UpdateTotal() *BatchMsgUpsertBulk {
  1184. return u.Update(func(s *BatchMsgUpsert) {
  1185. s.UpdateTotal()
  1186. })
  1187. }
  1188. // ClearTotal clears the value of the "total" field.
  1189. func (u *BatchMsgUpsertBulk) ClearTotal() *BatchMsgUpsertBulk {
  1190. return u.Update(func(s *BatchMsgUpsert) {
  1191. s.ClearTotal()
  1192. })
  1193. }
  1194. // SetSuccess sets the "success" field.
  1195. func (u *BatchMsgUpsertBulk) SetSuccess(v int32) *BatchMsgUpsertBulk {
  1196. return u.Update(func(s *BatchMsgUpsert) {
  1197. s.SetSuccess(v)
  1198. })
  1199. }
  1200. // AddSuccess adds v to the "success" field.
  1201. func (u *BatchMsgUpsertBulk) AddSuccess(v int32) *BatchMsgUpsertBulk {
  1202. return u.Update(func(s *BatchMsgUpsert) {
  1203. s.AddSuccess(v)
  1204. })
  1205. }
  1206. // UpdateSuccess sets the "success" field to the value that was provided on create.
  1207. func (u *BatchMsgUpsertBulk) UpdateSuccess() *BatchMsgUpsertBulk {
  1208. return u.Update(func(s *BatchMsgUpsert) {
  1209. s.UpdateSuccess()
  1210. })
  1211. }
  1212. // ClearSuccess clears the value of the "success" field.
  1213. func (u *BatchMsgUpsertBulk) ClearSuccess() *BatchMsgUpsertBulk {
  1214. return u.Update(func(s *BatchMsgUpsert) {
  1215. s.ClearSuccess()
  1216. })
  1217. }
  1218. // SetFail sets the "fail" field.
  1219. func (u *BatchMsgUpsertBulk) SetFail(v int32) *BatchMsgUpsertBulk {
  1220. return u.Update(func(s *BatchMsgUpsert) {
  1221. s.SetFail(v)
  1222. })
  1223. }
  1224. // AddFail adds v to the "fail" field.
  1225. func (u *BatchMsgUpsertBulk) AddFail(v int32) *BatchMsgUpsertBulk {
  1226. return u.Update(func(s *BatchMsgUpsert) {
  1227. s.AddFail(v)
  1228. })
  1229. }
  1230. // UpdateFail sets the "fail" field to the value that was provided on create.
  1231. func (u *BatchMsgUpsertBulk) UpdateFail() *BatchMsgUpsertBulk {
  1232. return u.Update(func(s *BatchMsgUpsert) {
  1233. s.UpdateFail()
  1234. })
  1235. }
  1236. // ClearFail clears the value of the "fail" field.
  1237. func (u *BatchMsgUpsertBulk) ClearFail() *BatchMsgUpsertBulk {
  1238. return u.Update(func(s *BatchMsgUpsert) {
  1239. s.ClearFail()
  1240. })
  1241. }
  1242. // SetStartTime sets the "start_time" field.
  1243. func (u *BatchMsgUpsertBulk) SetStartTime(v time.Time) *BatchMsgUpsertBulk {
  1244. return u.Update(func(s *BatchMsgUpsert) {
  1245. s.SetStartTime(v)
  1246. })
  1247. }
  1248. // UpdateStartTime sets the "start_time" field to the value that was provided on create.
  1249. func (u *BatchMsgUpsertBulk) UpdateStartTime() *BatchMsgUpsertBulk {
  1250. return u.Update(func(s *BatchMsgUpsert) {
  1251. s.UpdateStartTime()
  1252. })
  1253. }
  1254. // ClearStartTime clears the value of the "start_time" field.
  1255. func (u *BatchMsgUpsertBulk) ClearStartTime() *BatchMsgUpsertBulk {
  1256. return u.Update(func(s *BatchMsgUpsert) {
  1257. s.ClearStartTime()
  1258. })
  1259. }
  1260. // SetStopTime sets the "stop_time" field.
  1261. func (u *BatchMsgUpsertBulk) SetStopTime(v time.Time) *BatchMsgUpsertBulk {
  1262. return u.Update(func(s *BatchMsgUpsert) {
  1263. s.SetStopTime(v)
  1264. })
  1265. }
  1266. // UpdateStopTime sets the "stop_time" field to the value that was provided on create.
  1267. func (u *BatchMsgUpsertBulk) UpdateStopTime() *BatchMsgUpsertBulk {
  1268. return u.Update(func(s *BatchMsgUpsert) {
  1269. s.UpdateStopTime()
  1270. })
  1271. }
  1272. // ClearStopTime clears the value of the "stop_time" field.
  1273. func (u *BatchMsgUpsertBulk) ClearStopTime() *BatchMsgUpsertBulk {
  1274. return u.Update(func(s *BatchMsgUpsert) {
  1275. s.ClearStopTime()
  1276. })
  1277. }
  1278. // Exec executes the query.
  1279. func (u *BatchMsgUpsertBulk) Exec(ctx context.Context) error {
  1280. if u.create.err != nil {
  1281. return u.create.err
  1282. }
  1283. for i, b := range u.create.builders {
  1284. if len(b.conflict) != 0 {
  1285. return fmt.Errorf("ent: OnConflict was set for builder %d. Set it on the BatchMsgCreateBulk instead", i)
  1286. }
  1287. }
  1288. if len(u.create.conflict) == 0 {
  1289. return errors.New("ent: missing options for BatchMsgCreateBulk.OnConflict")
  1290. }
  1291. return u.create.Exec(ctx)
  1292. }
  1293. // ExecX is like Exec, but panics if an error occurs.
  1294. func (u *BatchMsgUpsertBulk) ExecX(ctx context.Context) {
  1295. if err := u.create.Exec(ctx); err != nil {
  1296. panic(err)
  1297. }
  1298. }