msg_update.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750
  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/msg"
  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. // MsgUpdate is the builder for updating Msg entities.
  15. type MsgUpdate struct {
  16. config
  17. hooks []Hook
  18. mutation *MsgMutation
  19. }
  20. // Where appends a list predicates to the MsgUpdate builder.
  21. func (mu *MsgUpdate) Where(ps ...predicate.Msg) *MsgUpdate {
  22. mu.mutation.Where(ps...)
  23. return mu
  24. }
  25. // SetUpdatedAt sets the "updated_at" field.
  26. func (mu *MsgUpdate) SetUpdatedAt(t time.Time) *MsgUpdate {
  27. mu.mutation.SetUpdatedAt(t)
  28. return mu
  29. }
  30. // SetDeletedAt sets the "deleted_at" field.
  31. func (mu *MsgUpdate) SetDeletedAt(t time.Time) *MsgUpdate {
  32. mu.mutation.SetDeletedAt(t)
  33. return mu
  34. }
  35. // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
  36. func (mu *MsgUpdate) SetNillableDeletedAt(t *time.Time) *MsgUpdate {
  37. if t != nil {
  38. mu.SetDeletedAt(*t)
  39. }
  40. return mu
  41. }
  42. // ClearDeletedAt clears the value of the "deleted_at" field.
  43. func (mu *MsgUpdate) ClearDeletedAt() *MsgUpdate {
  44. mu.mutation.ClearDeletedAt()
  45. return mu
  46. }
  47. // SetStatus sets the "status" field.
  48. func (mu *MsgUpdate) SetStatus(u uint8) *MsgUpdate {
  49. mu.mutation.ResetStatus()
  50. mu.mutation.SetStatus(u)
  51. return mu
  52. }
  53. // SetNillableStatus sets the "status" field if the given value is not nil.
  54. func (mu *MsgUpdate) SetNillableStatus(u *uint8) *MsgUpdate {
  55. if u != nil {
  56. mu.SetStatus(*u)
  57. }
  58. return mu
  59. }
  60. // AddStatus adds u to the "status" field.
  61. func (mu *MsgUpdate) AddStatus(u int8) *MsgUpdate {
  62. mu.mutation.AddStatus(u)
  63. return mu
  64. }
  65. // ClearStatus clears the value of the "status" field.
  66. func (mu *MsgUpdate) ClearStatus() *MsgUpdate {
  67. mu.mutation.ClearStatus()
  68. return mu
  69. }
  70. // SetFromwxid sets the "fromwxid" field.
  71. func (mu *MsgUpdate) SetFromwxid(s string) *MsgUpdate {
  72. mu.mutation.SetFromwxid(s)
  73. return mu
  74. }
  75. // SetNillableFromwxid sets the "fromwxid" field if the given value is not nil.
  76. func (mu *MsgUpdate) SetNillableFromwxid(s *string) *MsgUpdate {
  77. if s != nil {
  78. mu.SetFromwxid(*s)
  79. }
  80. return mu
  81. }
  82. // ClearFromwxid clears the value of the "fromwxid" field.
  83. func (mu *MsgUpdate) ClearFromwxid() *MsgUpdate {
  84. mu.mutation.ClearFromwxid()
  85. return mu
  86. }
  87. // SetToid sets the "toid" field.
  88. func (mu *MsgUpdate) SetToid(s string) *MsgUpdate {
  89. mu.mutation.SetToid(s)
  90. return mu
  91. }
  92. // SetNillableToid sets the "toid" field if the given value is not nil.
  93. func (mu *MsgUpdate) SetNillableToid(s *string) *MsgUpdate {
  94. if s != nil {
  95. mu.SetToid(*s)
  96. }
  97. return mu
  98. }
  99. // ClearToid clears the value of the "toid" field.
  100. func (mu *MsgUpdate) ClearToid() *MsgUpdate {
  101. mu.mutation.ClearToid()
  102. return mu
  103. }
  104. // SetMsgtype sets the "msgtype" field.
  105. func (mu *MsgUpdate) SetMsgtype(i int32) *MsgUpdate {
  106. mu.mutation.ResetMsgtype()
  107. mu.mutation.SetMsgtype(i)
  108. return mu
  109. }
  110. // SetNillableMsgtype sets the "msgtype" field if the given value is not nil.
  111. func (mu *MsgUpdate) SetNillableMsgtype(i *int32) *MsgUpdate {
  112. if i != nil {
  113. mu.SetMsgtype(*i)
  114. }
  115. return mu
  116. }
  117. // AddMsgtype adds i to the "msgtype" field.
  118. func (mu *MsgUpdate) AddMsgtype(i int32) *MsgUpdate {
  119. mu.mutation.AddMsgtype(i)
  120. return mu
  121. }
  122. // ClearMsgtype clears the value of the "msgtype" field.
  123. func (mu *MsgUpdate) ClearMsgtype() *MsgUpdate {
  124. mu.mutation.ClearMsgtype()
  125. return mu
  126. }
  127. // SetMsg sets the "msg" field.
  128. func (mu *MsgUpdate) SetMsg(s string) *MsgUpdate {
  129. mu.mutation.SetMsg(s)
  130. return mu
  131. }
  132. // SetNillableMsg sets the "msg" field if the given value is not nil.
  133. func (mu *MsgUpdate) SetNillableMsg(s *string) *MsgUpdate {
  134. if s != nil {
  135. mu.SetMsg(*s)
  136. }
  137. return mu
  138. }
  139. // ClearMsg clears the value of the "msg" field.
  140. func (mu *MsgUpdate) ClearMsg() *MsgUpdate {
  141. mu.mutation.ClearMsg()
  142. return mu
  143. }
  144. // SetBatchNo sets the "batch_no" field.
  145. func (mu *MsgUpdate) SetBatchNo(s string) *MsgUpdate {
  146. mu.mutation.SetBatchNo(s)
  147. return mu
  148. }
  149. // SetNillableBatchNo sets the "batch_no" field if the given value is not nil.
  150. func (mu *MsgUpdate) SetNillableBatchNo(s *string) *MsgUpdate {
  151. if s != nil {
  152. mu.SetBatchNo(*s)
  153. }
  154. return mu
  155. }
  156. // ClearBatchNo clears the value of the "batch_no" field.
  157. func (mu *MsgUpdate) ClearBatchNo() *MsgUpdate {
  158. mu.mutation.ClearBatchNo()
  159. return mu
  160. }
  161. // SetCtype sets the "ctype" field.
  162. func (mu *MsgUpdate) SetCtype(u uint64) *MsgUpdate {
  163. mu.mutation.ResetCtype()
  164. mu.mutation.SetCtype(u)
  165. return mu
  166. }
  167. // SetNillableCtype sets the "ctype" field if the given value is not nil.
  168. func (mu *MsgUpdate) SetNillableCtype(u *uint64) *MsgUpdate {
  169. if u != nil {
  170. mu.SetCtype(*u)
  171. }
  172. return mu
  173. }
  174. // AddCtype adds u to the "ctype" field.
  175. func (mu *MsgUpdate) AddCtype(u int64) *MsgUpdate {
  176. mu.mutation.AddCtype(u)
  177. return mu
  178. }
  179. // SetCc sets the "cc" field.
  180. func (mu *MsgUpdate) SetCc(s string) *MsgUpdate {
  181. mu.mutation.SetCc(s)
  182. return mu
  183. }
  184. // SetNillableCc sets the "cc" field if the given value is not nil.
  185. func (mu *MsgUpdate) SetNillableCc(s *string) *MsgUpdate {
  186. if s != nil {
  187. mu.SetCc(*s)
  188. }
  189. return mu
  190. }
  191. // SetPhone sets the "phone" field.
  192. func (mu *MsgUpdate) SetPhone(s string) *MsgUpdate {
  193. mu.mutation.SetPhone(s)
  194. return mu
  195. }
  196. // SetNillablePhone sets the "phone" field if the given value is not nil.
  197. func (mu *MsgUpdate) SetNillablePhone(s *string) *MsgUpdate {
  198. if s != nil {
  199. mu.SetPhone(*s)
  200. }
  201. return mu
  202. }
  203. // Mutation returns the MsgMutation object of the builder.
  204. func (mu *MsgUpdate) Mutation() *MsgMutation {
  205. return mu.mutation
  206. }
  207. // Save executes the query and returns the number of nodes affected by the update operation.
  208. func (mu *MsgUpdate) Save(ctx context.Context) (int, error) {
  209. if err := mu.defaults(); err != nil {
  210. return 0, err
  211. }
  212. return withHooks(ctx, mu.sqlSave, mu.mutation, mu.hooks)
  213. }
  214. // SaveX is like Save, but panics if an error occurs.
  215. func (mu *MsgUpdate) SaveX(ctx context.Context) int {
  216. affected, err := mu.Save(ctx)
  217. if err != nil {
  218. panic(err)
  219. }
  220. return affected
  221. }
  222. // Exec executes the query.
  223. func (mu *MsgUpdate) Exec(ctx context.Context) error {
  224. _, err := mu.Save(ctx)
  225. return err
  226. }
  227. // ExecX is like Exec, but panics if an error occurs.
  228. func (mu *MsgUpdate) ExecX(ctx context.Context) {
  229. if err := mu.Exec(ctx); err != nil {
  230. panic(err)
  231. }
  232. }
  233. // defaults sets the default values of the builder before save.
  234. func (mu *MsgUpdate) defaults() error {
  235. if _, ok := mu.mutation.UpdatedAt(); !ok {
  236. if msg.UpdateDefaultUpdatedAt == nil {
  237. return fmt.Errorf("ent: uninitialized msg.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
  238. }
  239. v := msg.UpdateDefaultUpdatedAt()
  240. mu.mutation.SetUpdatedAt(v)
  241. }
  242. return nil
  243. }
  244. func (mu *MsgUpdate) sqlSave(ctx context.Context) (n int, err error) {
  245. _spec := sqlgraph.NewUpdateSpec(msg.Table, msg.Columns, sqlgraph.NewFieldSpec(msg.FieldID, field.TypeUint64))
  246. if ps := mu.mutation.predicates; len(ps) > 0 {
  247. _spec.Predicate = func(selector *sql.Selector) {
  248. for i := range ps {
  249. ps[i](selector)
  250. }
  251. }
  252. }
  253. if value, ok := mu.mutation.UpdatedAt(); ok {
  254. _spec.SetField(msg.FieldUpdatedAt, field.TypeTime, value)
  255. }
  256. if value, ok := mu.mutation.DeletedAt(); ok {
  257. _spec.SetField(msg.FieldDeletedAt, field.TypeTime, value)
  258. }
  259. if mu.mutation.DeletedAtCleared() {
  260. _spec.ClearField(msg.FieldDeletedAt, field.TypeTime)
  261. }
  262. if value, ok := mu.mutation.Status(); ok {
  263. _spec.SetField(msg.FieldStatus, field.TypeUint8, value)
  264. }
  265. if value, ok := mu.mutation.AddedStatus(); ok {
  266. _spec.AddField(msg.FieldStatus, field.TypeUint8, value)
  267. }
  268. if mu.mutation.StatusCleared() {
  269. _spec.ClearField(msg.FieldStatus, field.TypeUint8)
  270. }
  271. if value, ok := mu.mutation.Fromwxid(); ok {
  272. _spec.SetField(msg.FieldFromwxid, field.TypeString, value)
  273. }
  274. if mu.mutation.FromwxidCleared() {
  275. _spec.ClearField(msg.FieldFromwxid, field.TypeString)
  276. }
  277. if value, ok := mu.mutation.Toid(); ok {
  278. _spec.SetField(msg.FieldToid, field.TypeString, value)
  279. }
  280. if mu.mutation.ToidCleared() {
  281. _spec.ClearField(msg.FieldToid, field.TypeString)
  282. }
  283. if value, ok := mu.mutation.Msgtype(); ok {
  284. _spec.SetField(msg.FieldMsgtype, field.TypeInt32, value)
  285. }
  286. if value, ok := mu.mutation.AddedMsgtype(); ok {
  287. _spec.AddField(msg.FieldMsgtype, field.TypeInt32, value)
  288. }
  289. if mu.mutation.MsgtypeCleared() {
  290. _spec.ClearField(msg.FieldMsgtype, field.TypeInt32)
  291. }
  292. if value, ok := mu.mutation.Msg(); ok {
  293. _spec.SetField(msg.FieldMsg, field.TypeString, value)
  294. }
  295. if mu.mutation.MsgCleared() {
  296. _spec.ClearField(msg.FieldMsg, field.TypeString)
  297. }
  298. if value, ok := mu.mutation.BatchNo(); ok {
  299. _spec.SetField(msg.FieldBatchNo, field.TypeString, value)
  300. }
  301. if mu.mutation.BatchNoCleared() {
  302. _spec.ClearField(msg.FieldBatchNo, field.TypeString)
  303. }
  304. if value, ok := mu.mutation.Ctype(); ok {
  305. _spec.SetField(msg.FieldCtype, field.TypeUint64, value)
  306. }
  307. if value, ok := mu.mutation.AddedCtype(); ok {
  308. _spec.AddField(msg.FieldCtype, field.TypeUint64, value)
  309. }
  310. if value, ok := mu.mutation.Cc(); ok {
  311. _spec.SetField(msg.FieldCc, field.TypeString, value)
  312. }
  313. if value, ok := mu.mutation.Phone(); ok {
  314. _spec.SetField(msg.FieldPhone, field.TypeString, value)
  315. }
  316. if n, err = sqlgraph.UpdateNodes(ctx, mu.driver, _spec); err != nil {
  317. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  318. err = &NotFoundError{msg.Label}
  319. } else if sqlgraph.IsConstraintError(err) {
  320. err = &ConstraintError{msg: err.Error(), wrap: err}
  321. }
  322. return 0, err
  323. }
  324. mu.mutation.done = true
  325. return n, nil
  326. }
  327. // MsgUpdateOne is the builder for updating a single Msg entity.
  328. type MsgUpdateOne struct {
  329. config
  330. fields []string
  331. hooks []Hook
  332. mutation *MsgMutation
  333. }
  334. // SetUpdatedAt sets the "updated_at" field.
  335. func (muo *MsgUpdateOne) SetUpdatedAt(t time.Time) *MsgUpdateOne {
  336. muo.mutation.SetUpdatedAt(t)
  337. return muo
  338. }
  339. // SetDeletedAt sets the "deleted_at" field.
  340. func (muo *MsgUpdateOne) SetDeletedAt(t time.Time) *MsgUpdateOne {
  341. muo.mutation.SetDeletedAt(t)
  342. return muo
  343. }
  344. // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
  345. func (muo *MsgUpdateOne) SetNillableDeletedAt(t *time.Time) *MsgUpdateOne {
  346. if t != nil {
  347. muo.SetDeletedAt(*t)
  348. }
  349. return muo
  350. }
  351. // ClearDeletedAt clears the value of the "deleted_at" field.
  352. func (muo *MsgUpdateOne) ClearDeletedAt() *MsgUpdateOne {
  353. muo.mutation.ClearDeletedAt()
  354. return muo
  355. }
  356. // SetStatus sets the "status" field.
  357. func (muo *MsgUpdateOne) SetStatus(u uint8) *MsgUpdateOne {
  358. muo.mutation.ResetStatus()
  359. muo.mutation.SetStatus(u)
  360. return muo
  361. }
  362. // SetNillableStatus sets the "status" field if the given value is not nil.
  363. func (muo *MsgUpdateOne) SetNillableStatus(u *uint8) *MsgUpdateOne {
  364. if u != nil {
  365. muo.SetStatus(*u)
  366. }
  367. return muo
  368. }
  369. // AddStatus adds u to the "status" field.
  370. func (muo *MsgUpdateOne) AddStatus(u int8) *MsgUpdateOne {
  371. muo.mutation.AddStatus(u)
  372. return muo
  373. }
  374. // ClearStatus clears the value of the "status" field.
  375. func (muo *MsgUpdateOne) ClearStatus() *MsgUpdateOne {
  376. muo.mutation.ClearStatus()
  377. return muo
  378. }
  379. // SetFromwxid sets the "fromwxid" field.
  380. func (muo *MsgUpdateOne) SetFromwxid(s string) *MsgUpdateOne {
  381. muo.mutation.SetFromwxid(s)
  382. return muo
  383. }
  384. // SetNillableFromwxid sets the "fromwxid" field if the given value is not nil.
  385. func (muo *MsgUpdateOne) SetNillableFromwxid(s *string) *MsgUpdateOne {
  386. if s != nil {
  387. muo.SetFromwxid(*s)
  388. }
  389. return muo
  390. }
  391. // ClearFromwxid clears the value of the "fromwxid" field.
  392. func (muo *MsgUpdateOne) ClearFromwxid() *MsgUpdateOne {
  393. muo.mutation.ClearFromwxid()
  394. return muo
  395. }
  396. // SetToid sets the "toid" field.
  397. func (muo *MsgUpdateOne) SetToid(s string) *MsgUpdateOne {
  398. muo.mutation.SetToid(s)
  399. return muo
  400. }
  401. // SetNillableToid sets the "toid" field if the given value is not nil.
  402. func (muo *MsgUpdateOne) SetNillableToid(s *string) *MsgUpdateOne {
  403. if s != nil {
  404. muo.SetToid(*s)
  405. }
  406. return muo
  407. }
  408. // ClearToid clears the value of the "toid" field.
  409. func (muo *MsgUpdateOne) ClearToid() *MsgUpdateOne {
  410. muo.mutation.ClearToid()
  411. return muo
  412. }
  413. // SetMsgtype sets the "msgtype" field.
  414. func (muo *MsgUpdateOne) SetMsgtype(i int32) *MsgUpdateOne {
  415. muo.mutation.ResetMsgtype()
  416. muo.mutation.SetMsgtype(i)
  417. return muo
  418. }
  419. // SetNillableMsgtype sets the "msgtype" field if the given value is not nil.
  420. func (muo *MsgUpdateOne) SetNillableMsgtype(i *int32) *MsgUpdateOne {
  421. if i != nil {
  422. muo.SetMsgtype(*i)
  423. }
  424. return muo
  425. }
  426. // AddMsgtype adds i to the "msgtype" field.
  427. func (muo *MsgUpdateOne) AddMsgtype(i int32) *MsgUpdateOne {
  428. muo.mutation.AddMsgtype(i)
  429. return muo
  430. }
  431. // ClearMsgtype clears the value of the "msgtype" field.
  432. func (muo *MsgUpdateOne) ClearMsgtype() *MsgUpdateOne {
  433. muo.mutation.ClearMsgtype()
  434. return muo
  435. }
  436. // SetMsg sets the "msg" field.
  437. func (muo *MsgUpdateOne) SetMsg(s string) *MsgUpdateOne {
  438. muo.mutation.SetMsg(s)
  439. return muo
  440. }
  441. // SetNillableMsg sets the "msg" field if the given value is not nil.
  442. func (muo *MsgUpdateOne) SetNillableMsg(s *string) *MsgUpdateOne {
  443. if s != nil {
  444. muo.SetMsg(*s)
  445. }
  446. return muo
  447. }
  448. // ClearMsg clears the value of the "msg" field.
  449. func (muo *MsgUpdateOne) ClearMsg() *MsgUpdateOne {
  450. muo.mutation.ClearMsg()
  451. return muo
  452. }
  453. // SetBatchNo sets the "batch_no" field.
  454. func (muo *MsgUpdateOne) SetBatchNo(s string) *MsgUpdateOne {
  455. muo.mutation.SetBatchNo(s)
  456. return muo
  457. }
  458. // SetNillableBatchNo sets the "batch_no" field if the given value is not nil.
  459. func (muo *MsgUpdateOne) SetNillableBatchNo(s *string) *MsgUpdateOne {
  460. if s != nil {
  461. muo.SetBatchNo(*s)
  462. }
  463. return muo
  464. }
  465. // ClearBatchNo clears the value of the "batch_no" field.
  466. func (muo *MsgUpdateOne) ClearBatchNo() *MsgUpdateOne {
  467. muo.mutation.ClearBatchNo()
  468. return muo
  469. }
  470. // SetCtype sets the "ctype" field.
  471. func (muo *MsgUpdateOne) SetCtype(u uint64) *MsgUpdateOne {
  472. muo.mutation.ResetCtype()
  473. muo.mutation.SetCtype(u)
  474. return muo
  475. }
  476. // SetNillableCtype sets the "ctype" field if the given value is not nil.
  477. func (muo *MsgUpdateOne) SetNillableCtype(u *uint64) *MsgUpdateOne {
  478. if u != nil {
  479. muo.SetCtype(*u)
  480. }
  481. return muo
  482. }
  483. // AddCtype adds u to the "ctype" field.
  484. func (muo *MsgUpdateOne) AddCtype(u int64) *MsgUpdateOne {
  485. muo.mutation.AddCtype(u)
  486. return muo
  487. }
  488. // SetCc sets the "cc" field.
  489. func (muo *MsgUpdateOne) SetCc(s string) *MsgUpdateOne {
  490. muo.mutation.SetCc(s)
  491. return muo
  492. }
  493. // SetNillableCc sets the "cc" field if the given value is not nil.
  494. func (muo *MsgUpdateOne) SetNillableCc(s *string) *MsgUpdateOne {
  495. if s != nil {
  496. muo.SetCc(*s)
  497. }
  498. return muo
  499. }
  500. // SetPhone sets the "phone" field.
  501. func (muo *MsgUpdateOne) SetPhone(s string) *MsgUpdateOne {
  502. muo.mutation.SetPhone(s)
  503. return muo
  504. }
  505. // SetNillablePhone sets the "phone" field if the given value is not nil.
  506. func (muo *MsgUpdateOne) SetNillablePhone(s *string) *MsgUpdateOne {
  507. if s != nil {
  508. muo.SetPhone(*s)
  509. }
  510. return muo
  511. }
  512. // Mutation returns the MsgMutation object of the builder.
  513. func (muo *MsgUpdateOne) Mutation() *MsgMutation {
  514. return muo.mutation
  515. }
  516. // Where appends a list predicates to the MsgUpdate builder.
  517. func (muo *MsgUpdateOne) Where(ps ...predicate.Msg) *MsgUpdateOne {
  518. muo.mutation.Where(ps...)
  519. return muo
  520. }
  521. // Select allows selecting one or more fields (columns) of the returned entity.
  522. // The default is selecting all fields defined in the entity schema.
  523. func (muo *MsgUpdateOne) Select(field string, fields ...string) *MsgUpdateOne {
  524. muo.fields = append([]string{field}, fields...)
  525. return muo
  526. }
  527. // Save executes the query and returns the updated Msg entity.
  528. func (muo *MsgUpdateOne) Save(ctx context.Context) (*Msg, error) {
  529. if err := muo.defaults(); err != nil {
  530. return nil, err
  531. }
  532. return withHooks(ctx, muo.sqlSave, muo.mutation, muo.hooks)
  533. }
  534. // SaveX is like Save, but panics if an error occurs.
  535. func (muo *MsgUpdateOne) SaveX(ctx context.Context) *Msg {
  536. node, err := muo.Save(ctx)
  537. if err != nil {
  538. panic(err)
  539. }
  540. return node
  541. }
  542. // Exec executes the query on the entity.
  543. func (muo *MsgUpdateOne) Exec(ctx context.Context) error {
  544. _, err := muo.Save(ctx)
  545. return err
  546. }
  547. // ExecX is like Exec, but panics if an error occurs.
  548. func (muo *MsgUpdateOne) ExecX(ctx context.Context) {
  549. if err := muo.Exec(ctx); err != nil {
  550. panic(err)
  551. }
  552. }
  553. // defaults sets the default values of the builder before save.
  554. func (muo *MsgUpdateOne) defaults() error {
  555. if _, ok := muo.mutation.UpdatedAt(); !ok {
  556. if msg.UpdateDefaultUpdatedAt == nil {
  557. return fmt.Errorf("ent: uninitialized msg.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
  558. }
  559. v := msg.UpdateDefaultUpdatedAt()
  560. muo.mutation.SetUpdatedAt(v)
  561. }
  562. return nil
  563. }
  564. func (muo *MsgUpdateOne) sqlSave(ctx context.Context) (_node *Msg, err error) {
  565. _spec := sqlgraph.NewUpdateSpec(msg.Table, msg.Columns, sqlgraph.NewFieldSpec(msg.FieldID, field.TypeUint64))
  566. id, ok := muo.mutation.ID()
  567. if !ok {
  568. return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Msg.id" for update`)}
  569. }
  570. _spec.Node.ID.Value = id
  571. if fields := muo.fields; len(fields) > 0 {
  572. _spec.Node.Columns = make([]string, 0, len(fields))
  573. _spec.Node.Columns = append(_spec.Node.Columns, msg.FieldID)
  574. for _, f := range fields {
  575. if !msg.ValidColumn(f) {
  576. return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
  577. }
  578. if f != msg.FieldID {
  579. _spec.Node.Columns = append(_spec.Node.Columns, f)
  580. }
  581. }
  582. }
  583. if ps := muo.mutation.predicates; len(ps) > 0 {
  584. _spec.Predicate = func(selector *sql.Selector) {
  585. for i := range ps {
  586. ps[i](selector)
  587. }
  588. }
  589. }
  590. if value, ok := muo.mutation.UpdatedAt(); ok {
  591. _spec.SetField(msg.FieldUpdatedAt, field.TypeTime, value)
  592. }
  593. if value, ok := muo.mutation.DeletedAt(); ok {
  594. _spec.SetField(msg.FieldDeletedAt, field.TypeTime, value)
  595. }
  596. if muo.mutation.DeletedAtCleared() {
  597. _spec.ClearField(msg.FieldDeletedAt, field.TypeTime)
  598. }
  599. if value, ok := muo.mutation.Status(); ok {
  600. _spec.SetField(msg.FieldStatus, field.TypeUint8, value)
  601. }
  602. if value, ok := muo.mutation.AddedStatus(); ok {
  603. _spec.AddField(msg.FieldStatus, field.TypeUint8, value)
  604. }
  605. if muo.mutation.StatusCleared() {
  606. _spec.ClearField(msg.FieldStatus, field.TypeUint8)
  607. }
  608. if value, ok := muo.mutation.Fromwxid(); ok {
  609. _spec.SetField(msg.FieldFromwxid, field.TypeString, value)
  610. }
  611. if muo.mutation.FromwxidCleared() {
  612. _spec.ClearField(msg.FieldFromwxid, field.TypeString)
  613. }
  614. if value, ok := muo.mutation.Toid(); ok {
  615. _spec.SetField(msg.FieldToid, field.TypeString, value)
  616. }
  617. if muo.mutation.ToidCleared() {
  618. _spec.ClearField(msg.FieldToid, field.TypeString)
  619. }
  620. if value, ok := muo.mutation.Msgtype(); ok {
  621. _spec.SetField(msg.FieldMsgtype, field.TypeInt32, value)
  622. }
  623. if value, ok := muo.mutation.AddedMsgtype(); ok {
  624. _spec.AddField(msg.FieldMsgtype, field.TypeInt32, value)
  625. }
  626. if muo.mutation.MsgtypeCleared() {
  627. _spec.ClearField(msg.FieldMsgtype, field.TypeInt32)
  628. }
  629. if value, ok := muo.mutation.Msg(); ok {
  630. _spec.SetField(msg.FieldMsg, field.TypeString, value)
  631. }
  632. if muo.mutation.MsgCleared() {
  633. _spec.ClearField(msg.FieldMsg, field.TypeString)
  634. }
  635. if value, ok := muo.mutation.BatchNo(); ok {
  636. _spec.SetField(msg.FieldBatchNo, field.TypeString, value)
  637. }
  638. if muo.mutation.BatchNoCleared() {
  639. _spec.ClearField(msg.FieldBatchNo, field.TypeString)
  640. }
  641. if value, ok := muo.mutation.Ctype(); ok {
  642. _spec.SetField(msg.FieldCtype, field.TypeUint64, value)
  643. }
  644. if value, ok := muo.mutation.AddedCtype(); ok {
  645. _spec.AddField(msg.FieldCtype, field.TypeUint64, value)
  646. }
  647. if value, ok := muo.mutation.Cc(); ok {
  648. _spec.SetField(msg.FieldCc, field.TypeString, value)
  649. }
  650. if value, ok := muo.mutation.Phone(); ok {
  651. _spec.SetField(msg.FieldPhone, field.TypeString, value)
  652. }
  653. _node = &Msg{config: muo.config}
  654. _spec.Assign = _node.assignValues
  655. _spec.ScanValues = _node.scanValues
  656. if err = sqlgraph.UpdateNode(ctx, muo.driver, _spec); err != nil {
  657. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  658. err = &NotFoundError{msg.Label}
  659. } else if sqlgraph.IsConstraintError(err) {
  660. err = &ConstraintError{msg: err.Error(), wrap: err}
  661. }
  662. return nil, err
  663. }
  664. muo.mutation.done = true
  665. return _node, nil
  666. }