batchmsg_update.go 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876
  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. "wechat-api/ent/predicate"
  10. "entgo.io/ent/dialect/sql"
  11. "entgo.io/ent/dialect/sql/sqlgraph"
  12. "entgo.io/ent/schema/field"
  13. )
  14. // BatchMsgUpdate is the builder for updating BatchMsg entities.
  15. type BatchMsgUpdate struct {
  16. config
  17. hooks []Hook
  18. mutation *BatchMsgMutation
  19. }
  20. // Where appends a list predicates to the BatchMsgUpdate builder.
  21. func (bmu *BatchMsgUpdate) Where(ps ...predicate.BatchMsg) *BatchMsgUpdate {
  22. bmu.mutation.Where(ps...)
  23. return bmu
  24. }
  25. // SetUpdatedAt sets the "updated_at" field.
  26. func (bmu *BatchMsgUpdate) SetUpdatedAt(t time.Time) *BatchMsgUpdate {
  27. bmu.mutation.SetUpdatedAt(t)
  28. return bmu
  29. }
  30. // SetDeletedAt sets the "deleted_at" field.
  31. func (bmu *BatchMsgUpdate) SetDeletedAt(t time.Time) *BatchMsgUpdate {
  32. bmu.mutation.SetDeletedAt(t)
  33. return bmu
  34. }
  35. // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
  36. func (bmu *BatchMsgUpdate) SetNillableDeletedAt(t *time.Time) *BatchMsgUpdate {
  37. if t != nil {
  38. bmu.SetDeletedAt(*t)
  39. }
  40. return bmu
  41. }
  42. // ClearDeletedAt clears the value of the "deleted_at" field.
  43. func (bmu *BatchMsgUpdate) ClearDeletedAt() *BatchMsgUpdate {
  44. bmu.mutation.ClearDeletedAt()
  45. return bmu
  46. }
  47. // SetStatus sets the "status" field.
  48. func (bmu *BatchMsgUpdate) SetStatus(u uint8) *BatchMsgUpdate {
  49. bmu.mutation.ResetStatus()
  50. bmu.mutation.SetStatus(u)
  51. return bmu
  52. }
  53. // SetNillableStatus sets the "status" field if the given value is not nil.
  54. func (bmu *BatchMsgUpdate) SetNillableStatus(u *uint8) *BatchMsgUpdate {
  55. if u != nil {
  56. bmu.SetStatus(*u)
  57. }
  58. return bmu
  59. }
  60. // AddStatus adds u to the "status" field.
  61. func (bmu *BatchMsgUpdate) AddStatus(u int8) *BatchMsgUpdate {
  62. bmu.mutation.AddStatus(u)
  63. return bmu
  64. }
  65. // ClearStatus clears the value of the "status" field.
  66. func (bmu *BatchMsgUpdate) ClearStatus() *BatchMsgUpdate {
  67. bmu.mutation.ClearStatus()
  68. return bmu
  69. }
  70. // SetBatchNo sets the "batch_no" field.
  71. func (bmu *BatchMsgUpdate) SetBatchNo(s string) *BatchMsgUpdate {
  72. bmu.mutation.SetBatchNo(s)
  73. return bmu
  74. }
  75. // SetNillableBatchNo sets the "batch_no" field if the given value is not nil.
  76. func (bmu *BatchMsgUpdate) SetNillableBatchNo(s *string) *BatchMsgUpdate {
  77. if s != nil {
  78. bmu.SetBatchNo(*s)
  79. }
  80. return bmu
  81. }
  82. // ClearBatchNo clears the value of the "batch_no" field.
  83. func (bmu *BatchMsgUpdate) ClearBatchNo() *BatchMsgUpdate {
  84. bmu.mutation.ClearBatchNo()
  85. return bmu
  86. }
  87. // SetFromwxid sets the "fromwxid" field.
  88. func (bmu *BatchMsgUpdate) SetFromwxid(s string) *BatchMsgUpdate {
  89. bmu.mutation.SetFromwxid(s)
  90. return bmu
  91. }
  92. // SetNillableFromwxid sets the "fromwxid" field if the given value is not nil.
  93. func (bmu *BatchMsgUpdate) SetNillableFromwxid(s *string) *BatchMsgUpdate {
  94. if s != nil {
  95. bmu.SetFromwxid(*s)
  96. }
  97. return bmu
  98. }
  99. // ClearFromwxid clears the value of the "fromwxid" field.
  100. func (bmu *BatchMsgUpdate) ClearFromwxid() *BatchMsgUpdate {
  101. bmu.mutation.ClearFromwxid()
  102. return bmu
  103. }
  104. // SetMsg sets the "msg" field.
  105. func (bmu *BatchMsgUpdate) SetMsg(s string) *BatchMsgUpdate {
  106. bmu.mutation.SetMsg(s)
  107. return bmu
  108. }
  109. // SetNillableMsg sets the "msg" field if the given value is not nil.
  110. func (bmu *BatchMsgUpdate) SetNillableMsg(s *string) *BatchMsgUpdate {
  111. if s != nil {
  112. bmu.SetMsg(*s)
  113. }
  114. return bmu
  115. }
  116. // ClearMsg clears the value of the "msg" field.
  117. func (bmu *BatchMsgUpdate) ClearMsg() *BatchMsgUpdate {
  118. bmu.mutation.ClearMsg()
  119. return bmu
  120. }
  121. // SetTag sets the "tag" field.
  122. func (bmu *BatchMsgUpdate) SetTag(s string) *BatchMsgUpdate {
  123. bmu.mutation.SetTag(s)
  124. return bmu
  125. }
  126. // SetNillableTag sets the "tag" field if the given value is not nil.
  127. func (bmu *BatchMsgUpdate) SetNillableTag(s *string) *BatchMsgUpdate {
  128. if s != nil {
  129. bmu.SetTag(*s)
  130. }
  131. return bmu
  132. }
  133. // ClearTag clears the value of the "tag" field.
  134. func (bmu *BatchMsgUpdate) ClearTag() *BatchMsgUpdate {
  135. bmu.mutation.ClearTag()
  136. return bmu
  137. }
  138. // SetTotal sets the "total" field.
  139. func (bmu *BatchMsgUpdate) SetTotal(i int32) *BatchMsgUpdate {
  140. bmu.mutation.ResetTotal()
  141. bmu.mutation.SetTotal(i)
  142. return bmu
  143. }
  144. // SetNillableTotal sets the "total" field if the given value is not nil.
  145. func (bmu *BatchMsgUpdate) SetNillableTotal(i *int32) *BatchMsgUpdate {
  146. if i != nil {
  147. bmu.SetTotal(*i)
  148. }
  149. return bmu
  150. }
  151. // AddTotal adds i to the "total" field.
  152. func (bmu *BatchMsgUpdate) AddTotal(i int32) *BatchMsgUpdate {
  153. bmu.mutation.AddTotal(i)
  154. return bmu
  155. }
  156. // ClearTotal clears the value of the "total" field.
  157. func (bmu *BatchMsgUpdate) ClearTotal() *BatchMsgUpdate {
  158. bmu.mutation.ClearTotal()
  159. return bmu
  160. }
  161. // SetSuccess sets the "success" field.
  162. func (bmu *BatchMsgUpdate) SetSuccess(i int32) *BatchMsgUpdate {
  163. bmu.mutation.ResetSuccess()
  164. bmu.mutation.SetSuccess(i)
  165. return bmu
  166. }
  167. // SetNillableSuccess sets the "success" field if the given value is not nil.
  168. func (bmu *BatchMsgUpdate) SetNillableSuccess(i *int32) *BatchMsgUpdate {
  169. if i != nil {
  170. bmu.SetSuccess(*i)
  171. }
  172. return bmu
  173. }
  174. // AddSuccess adds i to the "success" field.
  175. func (bmu *BatchMsgUpdate) AddSuccess(i int32) *BatchMsgUpdate {
  176. bmu.mutation.AddSuccess(i)
  177. return bmu
  178. }
  179. // ClearSuccess clears the value of the "success" field.
  180. func (bmu *BatchMsgUpdate) ClearSuccess() *BatchMsgUpdate {
  181. bmu.mutation.ClearSuccess()
  182. return bmu
  183. }
  184. // SetFail sets the "fail" field.
  185. func (bmu *BatchMsgUpdate) SetFail(i int32) *BatchMsgUpdate {
  186. bmu.mutation.ResetFail()
  187. bmu.mutation.SetFail(i)
  188. return bmu
  189. }
  190. // SetNillableFail sets the "fail" field if the given value is not nil.
  191. func (bmu *BatchMsgUpdate) SetNillableFail(i *int32) *BatchMsgUpdate {
  192. if i != nil {
  193. bmu.SetFail(*i)
  194. }
  195. return bmu
  196. }
  197. // AddFail adds i to the "fail" field.
  198. func (bmu *BatchMsgUpdate) AddFail(i int32) *BatchMsgUpdate {
  199. bmu.mutation.AddFail(i)
  200. return bmu
  201. }
  202. // ClearFail clears the value of the "fail" field.
  203. func (bmu *BatchMsgUpdate) ClearFail() *BatchMsgUpdate {
  204. bmu.mutation.ClearFail()
  205. return bmu
  206. }
  207. // SetStartTime sets the "start_time" field.
  208. func (bmu *BatchMsgUpdate) SetStartTime(t time.Time) *BatchMsgUpdate {
  209. bmu.mutation.SetStartTime(t)
  210. return bmu
  211. }
  212. // SetNillableStartTime sets the "start_time" field if the given value is not nil.
  213. func (bmu *BatchMsgUpdate) SetNillableStartTime(t *time.Time) *BatchMsgUpdate {
  214. if t != nil {
  215. bmu.SetStartTime(*t)
  216. }
  217. return bmu
  218. }
  219. // ClearStartTime clears the value of the "start_time" field.
  220. func (bmu *BatchMsgUpdate) ClearStartTime() *BatchMsgUpdate {
  221. bmu.mutation.ClearStartTime()
  222. return bmu
  223. }
  224. // SetStopTime sets the "stop_time" field.
  225. func (bmu *BatchMsgUpdate) SetStopTime(t time.Time) *BatchMsgUpdate {
  226. bmu.mutation.SetStopTime(t)
  227. return bmu
  228. }
  229. // SetNillableStopTime sets the "stop_time" field if the given value is not nil.
  230. func (bmu *BatchMsgUpdate) SetNillableStopTime(t *time.Time) *BatchMsgUpdate {
  231. if t != nil {
  232. bmu.SetStopTime(*t)
  233. }
  234. return bmu
  235. }
  236. // ClearStopTime clears the value of the "stop_time" field.
  237. func (bmu *BatchMsgUpdate) ClearStopTime() *BatchMsgUpdate {
  238. bmu.mutation.ClearStopTime()
  239. return bmu
  240. }
  241. // Mutation returns the BatchMsgMutation object of the builder.
  242. func (bmu *BatchMsgUpdate) Mutation() *BatchMsgMutation {
  243. return bmu.mutation
  244. }
  245. // Save executes the query and returns the number of nodes affected by the update operation.
  246. func (bmu *BatchMsgUpdate) Save(ctx context.Context) (int, error) {
  247. if err := bmu.defaults(); err != nil {
  248. return 0, err
  249. }
  250. return withHooks(ctx, bmu.sqlSave, bmu.mutation, bmu.hooks)
  251. }
  252. // SaveX is like Save, but panics if an error occurs.
  253. func (bmu *BatchMsgUpdate) SaveX(ctx context.Context) int {
  254. affected, err := bmu.Save(ctx)
  255. if err != nil {
  256. panic(err)
  257. }
  258. return affected
  259. }
  260. // Exec executes the query.
  261. func (bmu *BatchMsgUpdate) Exec(ctx context.Context) error {
  262. _, err := bmu.Save(ctx)
  263. return err
  264. }
  265. // ExecX is like Exec, but panics if an error occurs.
  266. func (bmu *BatchMsgUpdate) ExecX(ctx context.Context) {
  267. if err := bmu.Exec(ctx); err != nil {
  268. panic(err)
  269. }
  270. }
  271. // defaults sets the default values of the builder before save.
  272. func (bmu *BatchMsgUpdate) defaults() error {
  273. if _, ok := bmu.mutation.UpdatedAt(); !ok {
  274. if batchmsg.UpdateDefaultUpdatedAt == nil {
  275. return fmt.Errorf("ent: uninitialized batchmsg.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
  276. }
  277. v := batchmsg.UpdateDefaultUpdatedAt()
  278. bmu.mutation.SetUpdatedAt(v)
  279. }
  280. return nil
  281. }
  282. func (bmu *BatchMsgUpdate) sqlSave(ctx context.Context) (n int, err error) {
  283. _spec := sqlgraph.NewUpdateSpec(batchmsg.Table, batchmsg.Columns, sqlgraph.NewFieldSpec(batchmsg.FieldID, field.TypeUint64))
  284. if ps := bmu.mutation.predicates; len(ps) > 0 {
  285. _spec.Predicate = func(selector *sql.Selector) {
  286. for i := range ps {
  287. ps[i](selector)
  288. }
  289. }
  290. }
  291. if value, ok := bmu.mutation.UpdatedAt(); ok {
  292. _spec.SetField(batchmsg.FieldUpdatedAt, field.TypeTime, value)
  293. }
  294. if value, ok := bmu.mutation.DeletedAt(); ok {
  295. _spec.SetField(batchmsg.FieldDeletedAt, field.TypeTime, value)
  296. }
  297. if bmu.mutation.DeletedAtCleared() {
  298. _spec.ClearField(batchmsg.FieldDeletedAt, field.TypeTime)
  299. }
  300. if value, ok := bmu.mutation.Status(); ok {
  301. _spec.SetField(batchmsg.FieldStatus, field.TypeUint8, value)
  302. }
  303. if value, ok := bmu.mutation.AddedStatus(); ok {
  304. _spec.AddField(batchmsg.FieldStatus, field.TypeUint8, value)
  305. }
  306. if bmu.mutation.StatusCleared() {
  307. _spec.ClearField(batchmsg.FieldStatus, field.TypeUint8)
  308. }
  309. if value, ok := bmu.mutation.BatchNo(); ok {
  310. _spec.SetField(batchmsg.FieldBatchNo, field.TypeString, value)
  311. }
  312. if bmu.mutation.BatchNoCleared() {
  313. _spec.ClearField(batchmsg.FieldBatchNo, field.TypeString)
  314. }
  315. if value, ok := bmu.mutation.Fromwxid(); ok {
  316. _spec.SetField(batchmsg.FieldFromwxid, field.TypeString, value)
  317. }
  318. if bmu.mutation.FromwxidCleared() {
  319. _spec.ClearField(batchmsg.FieldFromwxid, field.TypeString)
  320. }
  321. if value, ok := bmu.mutation.Msg(); ok {
  322. _spec.SetField(batchmsg.FieldMsg, field.TypeString, value)
  323. }
  324. if bmu.mutation.MsgCleared() {
  325. _spec.ClearField(batchmsg.FieldMsg, field.TypeString)
  326. }
  327. if value, ok := bmu.mutation.Tag(); ok {
  328. _spec.SetField(batchmsg.FieldTag, field.TypeString, value)
  329. }
  330. if bmu.mutation.TagCleared() {
  331. _spec.ClearField(batchmsg.FieldTag, field.TypeString)
  332. }
  333. if value, ok := bmu.mutation.Total(); ok {
  334. _spec.SetField(batchmsg.FieldTotal, field.TypeInt32, value)
  335. }
  336. if value, ok := bmu.mutation.AddedTotal(); ok {
  337. _spec.AddField(batchmsg.FieldTotal, field.TypeInt32, value)
  338. }
  339. if bmu.mutation.TotalCleared() {
  340. _spec.ClearField(batchmsg.FieldTotal, field.TypeInt32)
  341. }
  342. if value, ok := bmu.mutation.Success(); ok {
  343. _spec.SetField(batchmsg.FieldSuccess, field.TypeInt32, value)
  344. }
  345. if value, ok := bmu.mutation.AddedSuccess(); ok {
  346. _spec.AddField(batchmsg.FieldSuccess, field.TypeInt32, value)
  347. }
  348. if bmu.mutation.SuccessCleared() {
  349. _spec.ClearField(batchmsg.FieldSuccess, field.TypeInt32)
  350. }
  351. if value, ok := bmu.mutation.Fail(); ok {
  352. _spec.SetField(batchmsg.FieldFail, field.TypeInt32, value)
  353. }
  354. if value, ok := bmu.mutation.AddedFail(); ok {
  355. _spec.AddField(batchmsg.FieldFail, field.TypeInt32, value)
  356. }
  357. if bmu.mutation.FailCleared() {
  358. _spec.ClearField(batchmsg.FieldFail, field.TypeInt32)
  359. }
  360. if value, ok := bmu.mutation.StartTime(); ok {
  361. _spec.SetField(batchmsg.FieldStartTime, field.TypeTime, value)
  362. }
  363. if bmu.mutation.StartTimeCleared() {
  364. _spec.ClearField(batchmsg.FieldStartTime, field.TypeTime)
  365. }
  366. if value, ok := bmu.mutation.StopTime(); ok {
  367. _spec.SetField(batchmsg.FieldStopTime, field.TypeTime, value)
  368. }
  369. if bmu.mutation.StopTimeCleared() {
  370. _spec.ClearField(batchmsg.FieldStopTime, field.TypeTime)
  371. }
  372. if n, err = sqlgraph.UpdateNodes(ctx, bmu.driver, _spec); err != nil {
  373. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  374. err = &NotFoundError{batchmsg.Label}
  375. } else if sqlgraph.IsConstraintError(err) {
  376. err = &ConstraintError{msg: err.Error(), wrap: err}
  377. }
  378. return 0, err
  379. }
  380. bmu.mutation.done = true
  381. return n, nil
  382. }
  383. // BatchMsgUpdateOne is the builder for updating a single BatchMsg entity.
  384. type BatchMsgUpdateOne struct {
  385. config
  386. fields []string
  387. hooks []Hook
  388. mutation *BatchMsgMutation
  389. }
  390. // SetUpdatedAt sets the "updated_at" field.
  391. func (bmuo *BatchMsgUpdateOne) SetUpdatedAt(t time.Time) *BatchMsgUpdateOne {
  392. bmuo.mutation.SetUpdatedAt(t)
  393. return bmuo
  394. }
  395. // SetDeletedAt sets the "deleted_at" field.
  396. func (bmuo *BatchMsgUpdateOne) SetDeletedAt(t time.Time) *BatchMsgUpdateOne {
  397. bmuo.mutation.SetDeletedAt(t)
  398. return bmuo
  399. }
  400. // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
  401. func (bmuo *BatchMsgUpdateOne) SetNillableDeletedAt(t *time.Time) *BatchMsgUpdateOne {
  402. if t != nil {
  403. bmuo.SetDeletedAt(*t)
  404. }
  405. return bmuo
  406. }
  407. // ClearDeletedAt clears the value of the "deleted_at" field.
  408. func (bmuo *BatchMsgUpdateOne) ClearDeletedAt() *BatchMsgUpdateOne {
  409. bmuo.mutation.ClearDeletedAt()
  410. return bmuo
  411. }
  412. // SetStatus sets the "status" field.
  413. func (bmuo *BatchMsgUpdateOne) SetStatus(u uint8) *BatchMsgUpdateOne {
  414. bmuo.mutation.ResetStatus()
  415. bmuo.mutation.SetStatus(u)
  416. return bmuo
  417. }
  418. // SetNillableStatus sets the "status" field if the given value is not nil.
  419. func (bmuo *BatchMsgUpdateOne) SetNillableStatus(u *uint8) *BatchMsgUpdateOne {
  420. if u != nil {
  421. bmuo.SetStatus(*u)
  422. }
  423. return bmuo
  424. }
  425. // AddStatus adds u to the "status" field.
  426. func (bmuo *BatchMsgUpdateOne) AddStatus(u int8) *BatchMsgUpdateOne {
  427. bmuo.mutation.AddStatus(u)
  428. return bmuo
  429. }
  430. // ClearStatus clears the value of the "status" field.
  431. func (bmuo *BatchMsgUpdateOne) ClearStatus() *BatchMsgUpdateOne {
  432. bmuo.mutation.ClearStatus()
  433. return bmuo
  434. }
  435. // SetBatchNo sets the "batch_no" field.
  436. func (bmuo *BatchMsgUpdateOne) SetBatchNo(s string) *BatchMsgUpdateOne {
  437. bmuo.mutation.SetBatchNo(s)
  438. return bmuo
  439. }
  440. // SetNillableBatchNo sets the "batch_no" field if the given value is not nil.
  441. func (bmuo *BatchMsgUpdateOne) SetNillableBatchNo(s *string) *BatchMsgUpdateOne {
  442. if s != nil {
  443. bmuo.SetBatchNo(*s)
  444. }
  445. return bmuo
  446. }
  447. // ClearBatchNo clears the value of the "batch_no" field.
  448. func (bmuo *BatchMsgUpdateOne) ClearBatchNo() *BatchMsgUpdateOne {
  449. bmuo.mutation.ClearBatchNo()
  450. return bmuo
  451. }
  452. // SetFromwxid sets the "fromwxid" field.
  453. func (bmuo *BatchMsgUpdateOne) SetFromwxid(s string) *BatchMsgUpdateOne {
  454. bmuo.mutation.SetFromwxid(s)
  455. return bmuo
  456. }
  457. // SetNillableFromwxid sets the "fromwxid" field if the given value is not nil.
  458. func (bmuo *BatchMsgUpdateOne) SetNillableFromwxid(s *string) *BatchMsgUpdateOne {
  459. if s != nil {
  460. bmuo.SetFromwxid(*s)
  461. }
  462. return bmuo
  463. }
  464. // ClearFromwxid clears the value of the "fromwxid" field.
  465. func (bmuo *BatchMsgUpdateOne) ClearFromwxid() *BatchMsgUpdateOne {
  466. bmuo.mutation.ClearFromwxid()
  467. return bmuo
  468. }
  469. // SetMsg sets the "msg" field.
  470. func (bmuo *BatchMsgUpdateOne) SetMsg(s string) *BatchMsgUpdateOne {
  471. bmuo.mutation.SetMsg(s)
  472. return bmuo
  473. }
  474. // SetNillableMsg sets the "msg" field if the given value is not nil.
  475. func (bmuo *BatchMsgUpdateOne) SetNillableMsg(s *string) *BatchMsgUpdateOne {
  476. if s != nil {
  477. bmuo.SetMsg(*s)
  478. }
  479. return bmuo
  480. }
  481. // ClearMsg clears the value of the "msg" field.
  482. func (bmuo *BatchMsgUpdateOne) ClearMsg() *BatchMsgUpdateOne {
  483. bmuo.mutation.ClearMsg()
  484. return bmuo
  485. }
  486. // SetTag sets the "tag" field.
  487. func (bmuo *BatchMsgUpdateOne) SetTag(s string) *BatchMsgUpdateOne {
  488. bmuo.mutation.SetTag(s)
  489. return bmuo
  490. }
  491. // SetNillableTag sets the "tag" field if the given value is not nil.
  492. func (bmuo *BatchMsgUpdateOne) SetNillableTag(s *string) *BatchMsgUpdateOne {
  493. if s != nil {
  494. bmuo.SetTag(*s)
  495. }
  496. return bmuo
  497. }
  498. // ClearTag clears the value of the "tag" field.
  499. func (bmuo *BatchMsgUpdateOne) ClearTag() *BatchMsgUpdateOne {
  500. bmuo.mutation.ClearTag()
  501. return bmuo
  502. }
  503. // SetTotal sets the "total" field.
  504. func (bmuo *BatchMsgUpdateOne) SetTotal(i int32) *BatchMsgUpdateOne {
  505. bmuo.mutation.ResetTotal()
  506. bmuo.mutation.SetTotal(i)
  507. return bmuo
  508. }
  509. // SetNillableTotal sets the "total" field if the given value is not nil.
  510. func (bmuo *BatchMsgUpdateOne) SetNillableTotal(i *int32) *BatchMsgUpdateOne {
  511. if i != nil {
  512. bmuo.SetTotal(*i)
  513. }
  514. return bmuo
  515. }
  516. // AddTotal adds i to the "total" field.
  517. func (bmuo *BatchMsgUpdateOne) AddTotal(i int32) *BatchMsgUpdateOne {
  518. bmuo.mutation.AddTotal(i)
  519. return bmuo
  520. }
  521. // ClearTotal clears the value of the "total" field.
  522. func (bmuo *BatchMsgUpdateOne) ClearTotal() *BatchMsgUpdateOne {
  523. bmuo.mutation.ClearTotal()
  524. return bmuo
  525. }
  526. // SetSuccess sets the "success" field.
  527. func (bmuo *BatchMsgUpdateOne) SetSuccess(i int32) *BatchMsgUpdateOne {
  528. bmuo.mutation.ResetSuccess()
  529. bmuo.mutation.SetSuccess(i)
  530. return bmuo
  531. }
  532. // SetNillableSuccess sets the "success" field if the given value is not nil.
  533. func (bmuo *BatchMsgUpdateOne) SetNillableSuccess(i *int32) *BatchMsgUpdateOne {
  534. if i != nil {
  535. bmuo.SetSuccess(*i)
  536. }
  537. return bmuo
  538. }
  539. // AddSuccess adds i to the "success" field.
  540. func (bmuo *BatchMsgUpdateOne) AddSuccess(i int32) *BatchMsgUpdateOne {
  541. bmuo.mutation.AddSuccess(i)
  542. return bmuo
  543. }
  544. // ClearSuccess clears the value of the "success" field.
  545. func (bmuo *BatchMsgUpdateOne) ClearSuccess() *BatchMsgUpdateOne {
  546. bmuo.mutation.ClearSuccess()
  547. return bmuo
  548. }
  549. // SetFail sets the "fail" field.
  550. func (bmuo *BatchMsgUpdateOne) SetFail(i int32) *BatchMsgUpdateOne {
  551. bmuo.mutation.ResetFail()
  552. bmuo.mutation.SetFail(i)
  553. return bmuo
  554. }
  555. // SetNillableFail sets the "fail" field if the given value is not nil.
  556. func (bmuo *BatchMsgUpdateOne) SetNillableFail(i *int32) *BatchMsgUpdateOne {
  557. if i != nil {
  558. bmuo.SetFail(*i)
  559. }
  560. return bmuo
  561. }
  562. // AddFail adds i to the "fail" field.
  563. func (bmuo *BatchMsgUpdateOne) AddFail(i int32) *BatchMsgUpdateOne {
  564. bmuo.mutation.AddFail(i)
  565. return bmuo
  566. }
  567. // ClearFail clears the value of the "fail" field.
  568. func (bmuo *BatchMsgUpdateOne) ClearFail() *BatchMsgUpdateOne {
  569. bmuo.mutation.ClearFail()
  570. return bmuo
  571. }
  572. // SetStartTime sets the "start_time" field.
  573. func (bmuo *BatchMsgUpdateOne) SetStartTime(t time.Time) *BatchMsgUpdateOne {
  574. bmuo.mutation.SetStartTime(t)
  575. return bmuo
  576. }
  577. // SetNillableStartTime sets the "start_time" field if the given value is not nil.
  578. func (bmuo *BatchMsgUpdateOne) SetNillableStartTime(t *time.Time) *BatchMsgUpdateOne {
  579. if t != nil {
  580. bmuo.SetStartTime(*t)
  581. }
  582. return bmuo
  583. }
  584. // ClearStartTime clears the value of the "start_time" field.
  585. func (bmuo *BatchMsgUpdateOne) ClearStartTime() *BatchMsgUpdateOne {
  586. bmuo.mutation.ClearStartTime()
  587. return bmuo
  588. }
  589. // SetStopTime sets the "stop_time" field.
  590. func (bmuo *BatchMsgUpdateOne) SetStopTime(t time.Time) *BatchMsgUpdateOne {
  591. bmuo.mutation.SetStopTime(t)
  592. return bmuo
  593. }
  594. // SetNillableStopTime sets the "stop_time" field if the given value is not nil.
  595. func (bmuo *BatchMsgUpdateOne) SetNillableStopTime(t *time.Time) *BatchMsgUpdateOne {
  596. if t != nil {
  597. bmuo.SetStopTime(*t)
  598. }
  599. return bmuo
  600. }
  601. // ClearStopTime clears the value of the "stop_time" field.
  602. func (bmuo *BatchMsgUpdateOne) ClearStopTime() *BatchMsgUpdateOne {
  603. bmuo.mutation.ClearStopTime()
  604. return bmuo
  605. }
  606. // Mutation returns the BatchMsgMutation object of the builder.
  607. func (bmuo *BatchMsgUpdateOne) Mutation() *BatchMsgMutation {
  608. return bmuo.mutation
  609. }
  610. // Where appends a list predicates to the BatchMsgUpdate builder.
  611. func (bmuo *BatchMsgUpdateOne) Where(ps ...predicate.BatchMsg) *BatchMsgUpdateOne {
  612. bmuo.mutation.Where(ps...)
  613. return bmuo
  614. }
  615. // Select allows selecting one or more fields (columns) of the returned entity.
  616. // The default is selecting all fields defined in the entity schema.
  617. func (bmuo *BatchMsgUpdateOne) Select(field string, fields ...string) *BatchMsgUpdateOne {
  618. bmuo.fields = append([]string{field}, fields...)
  619. return bmuo
  620. }
  621. // Save executes the query and returns the updated BatchMsg entity.
  622. func (bmuo *BatchMsgUpdateOne) Save(ctx context.Context) (*BatchMsg, error) {
  623. if err := bmuo.defaults(); err != nil {
  624. return nil, err
  625. }
  626. return withHooks(ctx, bmuo.sqlSave, bmuo.mutation, bmuo.hooks)
  627. }
  628. // SaveX is like Save, but panics if an error occurs.
  629. func (bmuo *BatchMsgUpdateOne) SaveX(ctx context.Context) *BatchMsg {
  630. node, err := bmuo.Save(ctx)
  631. if err != nil {
  632. panic(err)
  633. }
  634. return node
  635. }
  636. // Exec executes the query on the entity.
  637. func (bmuo *BatchMsgUpdateOne) Exec(ctx context.Context) error {
  638. _, err := bmuo.Save(ctx)
  639. return err
  640. }
  641. // ExecX is like Exec, but panics if an error occurs.
  642. func (bmuo *BatchMsgUpdateOne) ExecX(ctx context.Context) {
  643. if err := bmuo.Exec(ctx); err != nil {
  644. panic(err)
  645. }
  646. }
  647. // defaults sets the default values of the builder before save.
  648. func (bmuo *BatchMsgUpdateOne) defaults() error {
  649. if _, ok := bmuo.mutation.UpdatedAt(); !ok {
  650. if batchmsg.UpdateDefaultUpdatedAt == nil {
  651. return fmt.Errorf("ent: uninitialized batchmsg.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
  652. }
  653. v := batchmsg.UpdateDefaultUpdatedAt()
  654. bmuo.mutation.SetUpdatedAt(v)
  655. }
  656. return nil
  657. }
  658. func (bmuo *BatchMsgUpdateOne) sqlSave(ctx context.Context) (_node *BatchMsg, err error) {
  659. _spec := sqlgraph.NewUpdateSpec(batchmsg.Table, batchmsg.Columns, sqlgraph.NewFieldSpec(batchmsg.FieldID, field.TypeUint64))
  660. id, ok := bmuo.mutation.ID()
  661. if !ok {
  662. return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "BatchMsg.id" for update`)}
  663. }
  664. _spec.Node.ID.Value = id
  665. if fields := bmuo.fields; len(fields) > 0 {
  666. _spec.Node.Columns = make([]string, 0, len(fields))
  667. _spec.Node.Columns = append(_spec.Node.Columns, batchmsg.FieldID)
  668. for _, f := range fields {
  669. if !batchmsg.ValidColumn(f) {
  670. return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
  671. }
  672. if f != batchmsg.FieldID {
  673. _spec.Node.Columns = append(_spec.Node.Columns, f)
  674. }
  675. }
  676. }
  677. if ps := bmuo.mutation.predicates; len(ps) > 0 {
  678. _spec.Predicate = func(selector *sql.Selector) {
  679. for i := range ps {
  680. ps[i](selector)
  681. }
  682. }
  683. }
  684. if value, ok := bmuo.mutation.UpdatedAt(); ok {
  685. _spec.SetField(batchmsg.FieldUpdatedAt, field.TypeTime, value)
  686. }
  687. if value, ok := bmuo.mutation.DeletedAt(); ok {
  688. _spec.SetField(batchmsg.FieldDeletedAt, field.TypeTime, value)
  689. }
  690. if bmuo.mutation.DeletedAtCleared() {
  691. _spec.ClearField(batchmsg.FieldDeletedAt, field.TypeTime)
  692. }
  693. if value, ok := bmuo.mutation.Status(); ok {
  694. _spec.SetField(batchmsg.FieldStatus, field.TypeUint8, value)
  695. }
  696. if value, ok := bmuo.mutation.AddedStatus(); ok {
  697. _spec.AddField(batchmsg.FieldStatus, field.TypeUint8, value)
  698. }
  699. if bmuo.mutation.StatusCleared() {
  700. _spec.ClearField(batchmsg.FieldStatus, field.TypeUint8)
  701. }
  702. if value, ok := bmuo.mutation.BatchNo(); ok {
  703. _spec.SetField(batchmsg.FieldBatchNo, field.TypeString, value)
  704. }
  705. if bmuo.mutation.BatchNoCleared() {
  706. _spec.ClearField(batchmsg.FieldBatchNo, field.TypeString)
  707. }
  708. if value, ok := bmuo.mutation.Fromwxid(); ok {
  709. _spec.SetField(batchmsg.FieldFromwxid, field.TypeString, value)
  710. }
  711. if bmuo.mutation.FromwxidCleared() {
  712. _spec.ClearField(batchmsg.FieldFromwxid, field.TypeString)
  713. }
  714. if value, ok := bmuo.mutation.Msg(); ok {
  715. _spec.SetField(batchmsg.FieldMsg, field.TypeString, value)
  716. }
  717. if bmuo.mutation.MsgCleared() {
  718. _spec.ClearField(batchmsg.FieldMsg, field.TypeString)
  719. }
  720. if value, ok := bmuo.mutation.Tag(); ok {
  721. _spec.SetField(batchmsg.FieldTag, field.TypeString, value)
  722. }
  723. if bmuo.mutation.TagCleared() {
  724. _spec.ClearField(batchmsg.FieldTag, field.TypeString)
  725. }
  726. if value, ok := bmuo.mutation.Total(); ok {
  727. _spec.SetField(batchmsg.FieldTotal, field.TypeInt32, value)
  728. }
  729. if value, ok := bmuo.mutation.AddedTotal(); ok {
  730. _spec.AddField(batchmsg.FieldTotal, field.TypeInt32, value)
  731. }
  732. if bmuo.mutation.TotalCleared() {
  733. _spec.ClearField(batchmsg.FieldTotal, field.TypeInt32)
  734. }
  735. if value, ok := bmuo.mutation.Success(); ok {
  736. _spec.SetField(batchmsg.FieldSuccess, field.TypeInt32, value)
  737. }
  738. if value, ok := bmuo.mutation.AddedSuccess(); ok {
  739. _spec.AddField(batchmsg.FieldSuccess, field.TypeInt32, value)
  740. }
  741. if bmuo.mutation.SuccessCleared() {
  742. _spec.ClearField(batchmsg.FieldSuccess, field.TypeInt32)
  743. }
  744. if value, ok := bmuo.mutation.Fail(); ok {
  745. _spec.SetField(batchmsg.FieldFail, field.TypeInt32, value)
  746. }
  747. if value, ok := bmuo.mutation.AddedFail(); ok {
  748. _spec.AddField(batchmsg.FieldFail, field.TypeInt32, value)
  749. }
  750. if bmuo.mutation.FailCleared() {
  751. _spec.ClearField(batchmsg.FieldFail, field.TypeInt32)
  752. }
  753. if value, ok := bmuo.mutation.StartTime(); ok {
  754. _spec.SetField(batchmsg.FieldStartTime, field.TypeTime, value)
  755. }
  756. if bmuo.mutation.StartTimeCleared() {
  757. _spec.ClearField(batchmsg.FieldStartTime, field.TypeTime)
  758. }
  759. if value, ok := bmuo.mutation.StopTime(); ok {
  760. _spec.SetField(batchmsg.FieldStopTime, field.TypeTime, value)
  761. }
  762. if bmuo.mutation.StopTimeCleared() {
  763. _spec.ClearField(batchmsg.FieldStopTime, field.TypeTime)
  764. }
  765. _node = &BatchMsg{config: bmuo.config}
  766. _spec.Assign = _node.assignValues
  767. _spec.ScanValues = _node.scanValues
  768. if err = sqlgraph.UpdateNode(ctx, bmuo.driver, _spec); err != nil {
  769. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  770. err = &NotFoundError{batchmsg.Label}
  771. } else if sqlgraph.IsConstraintError(err) {
  772. err = &ConstraintError{msg: err.Error(), wrap: err}
  773. }
  774. return nil, err
  775. }
  776. bmuo.mutation.done = true
  777. return _node, nil
  778. }