batchmsg_create.go 45 KB

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