msg_update.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696
  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. // SetCc sets the "cc" field.
  162. func (mu *MsgUpdate) SetCc(s string) *MsgUpdate {
  163. mu.mutation.SetCc(s)
  164. return mu
  165. }
  166. // SetNillableCc sets the "cc" field if the given value is not nil.
  167. func (mu *MsgUpdate) SetNillableCc(s *string) *MsgUpdate {
  168. if s != nil {
  169. mu.SetCc(*s)
  170. }
  171. return mu
  172. }
  173. // SetPhone sets the "phone" field.
  174. func (mu *MsgUpdate) SetPhone(s string) *MsgUpdate {
  175. mu.mutation.SetPhone(s)
  176. return mu
  177. }
  178. // SetNillablePhone sets the "phone" field if the given value is not nil.
  179. func (mu *MsgUpdate) SetNillablePhone(s *string) *MsgUpdate {
  180. if s != nil {
  181. mu.SetPhone(*s)
  182. }
  183. return mu
  184. }
  185. // Mutation returns the MsgMutation object of the builder.
  186. func (mu *MsgUpdate) Mutation() *MsgMutation {
  187. return mu.mutation
  188. }
  189. // Save executes the query and returns the number of nodes affected by the update operation.
  190. func (mu *MsgUpdate) Save(ctx context.Context) (int, error) {
  191. if err := mu.defaults(); err != nil {
  192. return 0, err
  193. }
  194. return withHooks(ctx, mu.sqlSave, mu.mutation, mu.hooks)
  195. }
  196. // SaveX is like Save, but panics if an error occurs.
  197. func (mu *MsgUpdate) SaveX(ctx context.Context) int {
  198. affected, err := mu.Save(ctx)
  199. if err != nil {
  200. panic(err)
  201. }
  202. return affected
  203. }
  204. // Exec executes the query.
  205. func (mu *MsgUpdate) Exec(ctx context.Context) error {
  206. _, err := mu.Save(ctx)
  207. return err
  208. }
  209. // ExecX is like Exec, but panics if an error occurs.
  210. func (mu *MsgUpdate) ExecX(ctx context.Context) {
  211. if err := mu.Exec(ctx); err != nil {
  212. panic(err)
  213. }
  214. }
  215. // defaults sets the default values of the builder before save.
  216. func (mu *MsgUpdate) defaults() error {
  217. if _, ok := mu.mutation.UpdatedAt(); !ok {
  218. if msg.UpdateDefaultUpdatedAt == nil {
  219. return fmt.Errorf("ent: uninitialized msg.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
  220. }
  221. v := msg.UpdateDefaultUpdatedAt()
  222. mu.mutation.SetUpdatedAt(v)
  223. }
  224. return nil
  225. }
  226. func (mu *MsgUpdate) sqlSave(ctx context.Context) (n int, err error) {
  227. _spec := sqlgraph.NewUpdateSpec(msg.Table, msg.Columns, sqlgraph.NewFieldSpec(msg.FieldID, field.TypeUint64))
  228. if ps := mu.mutation.predicates; len(ps) > 0 {
  229. _spec.Predicate = func(selector *sql.Selector) {
  230. for i := range ps {
  231. ps[i](selector)
  232. }
  233. }
  234. }
  235. if value, ok := mu.mutation.UpdatedAt(); ok {
  236. _spec.SetField(msg.FieldUpdatedAt, field.TypeTime, value)
  237. }
  238. if value, ok := mu.mutation.DeletedAt(); ok {
  239. _spec.SetField(msg.FieldDeletedAt, field.TypeTime, value)
  240. }
  241. if mu.mutation.DeletedAtCleared() {
  242. _spec.ClearField(msg.FieldDeletedAt, field.TypeTime)
  243. }
  244. if value, ok := mu.mutation.Status(); ok {
  245. _spec.SetField(msg.FieldStatus, field.TypeUint8, value)
  246. }
  247. if value, ok := mu.mutation.AddedStatus(); ok {
  248. _spec.AddField(msg.FieldStatus, field.TypeUint8, value)
  249. }
  250. if mu.mutation.StatusCleared() {
  251. _spec.ClearField(msg.FieldStatus, field.TypeUint8)
  252. }
  253. if value, ok := mu.mutation.Fromwxid(); ok {
  254. _spec.SetField(msg.FieldFromwxid, field.TypeString, value)
  255. }
  256. if mu.mutation.FromwxidCleared() {
  257. _spec.ClearField(msg.FieldFromwxid, field.TypeString)
  258. }
  259. if value, ok := mu.mutation.Toid(); ok {
  260. _spec.SetField(msg.FieldToid, field.TypeString, value)
  261. }
  262. if mu.mutation.ToidCleared() {
  263. _spec.ClearField(msg.FieldToid, field.TypeString)
  264. }
  265. if value, ok := mu.mutation.Msgtype(); ok {
  266. _spec.SetField(msg.FieldMsgtype, field.TypeInt32, value)
  267. }
  268. if value, ok := mu.mutation.AddedMsgtype(); ok {
  269. _spec.AddField(msg.FieldMsgtype, field.TypeInt32, value)
  270. }
  271. if mu.mutation.MsgtypeCleared() {
  272. _spec.ClearField(msg.FieldMsgtype, field.TypeInt32)
  273. }
  274. if value, ok := mu.mutation.Msg(); ok {
  275. _spec.SetField(msg.FieldMsg, field.TypeString, value)
  276. }
  277. if mu.mutation.MsgCleared() {
  278. _spec.ClearField(msg.FieldMsg, field.TypeString)
  279. }
  280. if value, ok := mu.mutation.BatchNo(); ok {
  281. _spec.SetField(msg.FieldBatchNo, field.TypeString, value)
  282. }
  283. if mu.mutation.BatchNoCleared() {
  284. _spec.ClearField(msg.FieldBatchNo, field.TypeString)
  285. }
  286. if value, ok := mu.mutation.Cc(); ok {
  287. _spec.SetField(msg.FieldCc, field.TypeString, value)
  288. }
  289. if value, ok := mu.mutation.Phone(); ok {
  290. _spec.SetField(msg.FieldPhone, field.TypeString, value)
  291. }
  292. if n, err = sqlgraph.UpdateNodes(ctx, mu.driver, _spec); err != nil {
  293. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  294. err = &NotFoundError{msg.Label}
  295. } else if sqlgraph.IsConstraintError(err) {
  296. err = &ConstraintError{msg: err.Error(), wrap: err}
  297. }
  298. return 0, err
  299. }
  300. mu.mutation.done = true
  301. return n, nil
  302. }
  303. // MsgUpdateOne is the builder for updating a single Msg entity.
  304. type MsgUpdateOne struct {
  305. config
  306. fields []string
  307. hooks []Hook
  308. mutation *MsgMutation
  309. }
  310. // SetUpdatedAt sets the "updated_at" field.
  311. func (muo *MsgUpdateOne) SetUpdatedAt(t time.Time) *MsgUpdateOne {
  312. muo.mutation.SetUpdatedAt(t)
  313. return muo
  314. }
  315. // SetDeletedAt sets the "deleted_at" field.
  316. func (muo *MsgUpdateOne) SetDeletedAt(t time.Time) *MsgUpdateOne {
  317. muo.mutation.SetDeletedAt(t)
  318. return muo
  319. }
  320. // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
  321. func (muo *MsgUpdateOne) SetNillableDeletedAt(t *time.Time) *MsgUpdateOne {
  322. if t != nil {
  323. muo.SetDeletedAt(*t)
  324. }
  325. return muo
  326. }
  327. // ClearDeletedAt clears the value of the "deleted_at" field.
  328. func (muo *MsgUpdateOne) ClearDeletedAt() *MsgUpdateOne {
  329. muo.mutation.ClearDeletedAt()
  330. return muo
  331. }
  332. // SetStatus sets the "status" field.
  333. func (muo *MsgUpdateOne) SetStatus(u uint8) *MsgUpdateOne {
  334. muo.mutation.ResetStatus()
  335. muo.mutation.SetStatus(u)
  336. return muo
  337. }
  338. // SetNillableStatus sets the "status" field if the given value is not nil.
  339. func (muo *MsgUpdateOne) SetNillableStatus(u *uint8) *MsgUpdateOne {
  340. if u != nil {
  341. muo.SetStatus(*u)
  342. }
  343. return muo
  344. }
  345. // AddStatus adds u to the "status" field.
  346. func (muo *MsgUpdateOne) AddStatus(u int8) *MsgUpdateOne {
  347. muo.mutation.AddStatus(u)
  348. return muo
  349. }
  350. // ClearStatus clears the value of the "status" field.
  351. func (muo *MsgUpdateOne) ClearStatus() *MsgUpdateOne {
  352. muo.mutation.ClearStatus()
  353. return muo
  354. }
  355. // SetFromwxid sets the "fromwxid" field.
  356. func (muo *MsgUpdateOne) SetFromwxid(s string) *MsgUpdateOne {
  357. muo.mutation.SetFromwxid(s)
  358. return muo
  359. }
  360. // SetNillableFromwxid sets the "fromwxid" field if the given value is not nil.
  361. func (muo *MsgUpdateOne) SetNillableFromwxid(s *string) *MsgUpdateOne {
  362. if s != nil {
  363. muo.SetFromwxid(*s)
  364. }
  365. return muo
  366. }
  367. // ClearFromwxid clears the value of the "fromwxid" field.
  368. func (muo *MsgUpdateOne) ClearFromwxid() *MsgUpdateOne {
  369. muo.mutation.ClearFromwxid()
  370. return muo
  371. }
  372. // SetToid sets the "toid" field.
  373. func (muo *MsgUpdateOne) SetToid(s string) *MsgUpdateOne {
  374. muo.mutation.SetToid(s)
  375. return muo
  376. }
  377. // SetNillableToid sets the "toid" field if the given value is not nil.
  378. func (muo *MsgUpdateOne) SetNillableToid(s *string) *MsgUpdateOne {
  379. if s != nil {
  380. muo.SetToid(*s)
  381. }
  382. return muo
  383. }
  384. // ClearToid clears the value of the "toid" field.
  385. func (muo *MsgUpdateOne) ClearToid() *MsgUpdateOne {
  386. muo.mutation.ClearToid()
  387. return muo
  388. }
  389. // SetMsgtype sets the "msgtype" field.
  390. func (muo *MsgUpdateOne) SetMsgtype(i int32) *MsgUpdateOne {
  391. muo.mutation.ResetMsgtype()
  392. muo.mutation.SetMsgtype(i)
  393. return muo
  394. }
  395. // SetNillableMsgtype sets the "msgtype" field if the given value is not nil.
  396. func (muo *MsgUpdateOne) SetNillableMsgtype(i *int32) *MsgUpdateOne {
  397. if i != nil {
  398. muo.SetMsgtype(*i)
  399. }
  400. return muo
  401. }
  402. // AddMsgtype adds i to the "msgtype" field.
  403. func (muo *MsgUpdateOne) AddMsgtype(i int32) *MsgUpdateOne {
  404. muo.mutation.AddMsgtype(i)
  405. return muo
  406. }
  407. // ClearMsgtype clears the value of the "msgtype" field.
  408. func (muo *MsgUpdateOne) ClearMsgtype() *MsgUpdateOne {
  409. muo.mutation.ClearMsgtype()
  410. return muo
  411. }
  412. // SetMsg sets the "msg" field.
  413. func (muo *MsgUpdateOne) SetMsg(s string) *MsgUpdateOne {
  414. muo.mutation.SetMsg(s)
  415. return muo
  416. }
  417. // SetNillableMsg sets the "msg" field if the given value is not nil.
  418. func (muo *MsgUpdateOne) SetNillableMsg(s *string) *MsgUpdateOne {
  419. if s != nil {
  420. muo.SetMsg(*s)
  421. }
  422. return muo
  423. }
  424. // ClearMsg clears the value of the "msg" field.
  425. func (muo *MsgUpdateOne) ClearMsg() *MsgUpdateOne {
  426. muo.mutation.ClearMsg()
  427. return muo
  428. }
  429. // SetBatchNo sets the "batch_no" field.
  430. func (muo *MsgUpdateOne) SetBatchNo(s string) *MsgUpdateOne {
  431. muo.mutation.SetBatchNo(s)
  432. return muo
  433. }
  434. // SetNillableBatchNo sets the "batch_no" field if the given value is not nil.
  435. func (muo *MsgUpdateOne) SetNillableBatchNo(s *string) *MsgUpdateOne {
  436. if s != nil {
  437. muo.SetBatchNo(*s)
  438. }
  439. return muo
  440. }
  441. // ClearBatchNo clears the value of the "batch_no" field.
  442. func (muo *MsgUpdateOne) ClearBatchNo() *MsgUpdateOne {
  443. muo.mutation.ClearBatchNo()
  444. return muo
  445. }
  446. // SetCc sets the "cc" field.
  447. func (muo *MsgUpdateOne) SetCc(s string) *MsgUpdateOne {
  448. muo.mutation.SetCc(s)
  449. return muo
  450. }
  451. // SetNillableCc sets the "cc" field if the given value is not nil.
  452. func (muo *MsgUpdateOne) SetNillableCc(s *string) *MsgUpdateOne {
  453. if s != nil {
  454. muo.SetCc(*s)
  455. }
  456. return muo
  457. }
  458. // SetPhone sets the "phone" field.
  459. func (muo *MsgUpdateOne) SetPhone(s string) *MsgUpdateOne {
  460. muo.mutation.SetPhone(s)
  461. return muo
  462. }
  463. // SetNillablePhone sets the "phone" field if the given value is not nil.
  464. func (muo *MsgUpdateOne) SetNillablePhone(s *string) *MsgUpdateOne {
  465. if s != nil {
  466. muo.SetPhone(*s)
  467. }
  468. return muo
  469. }
  470. // Mutation returns the MsgMutation object of the builder.
  471. func (muo *MsgUpdateOne) Mutation() *MsgMutation {
  472. return muo.mutation
  473. }
  474. // Where appends a list predicates to the MsgUpdate builder.
  475. func (muo *MsgUpdateOne) Where(ps ...predicate.Msg) *MsgUpdateOne {
  476. muo.mutation.Where(ps...)
  477. return muo
  478. }
  479. // Select allows selecting one or more fields (columns) of the returned entity.
  480. // The default is selecting all fields defined in the entity schema.
  481. func (muo *MsgUpdateOne) Select(field string, fields ...string) *MsgUpdateOne {
  482. muo.fields = append([]string{field}, fields...)
  483. return muo
  484. }
  485. // Save executes the query and returns the updated Msg entity.
  486. func (muo *MsgUpdateOne) Save(ctx context.Context) (*Msg, error) {
  487. if err := muo.defaults(); err != nil {
  488. return nil, err
  489. }
  490. return withHooks(ctx, muo.sqlSave, muo.mutation, muo.hooks)
  491. }
  492. // SaveX is like Save, but panics if an error occurs.
  493. func (muo *MsgUpdateOne) SaveX(ctx context.Context) *Msg {
  494. node, err := muo.Save(ctx)
  495. if err != nil {
  496. panic(err)
  497. }
  498. return node
  499. }
  500. // Exec executes the query on the entity.
  501. func (muo *MsgUpdateOne) Exec(ctx context.Context) error {
  502. _, err := muo.Save(ctx)
  503. return err
  504. }
  505. // ExecX is like Exec, but panics if an error occurs.
  506. func (muo *MsgUpdateOne) ExecX(ctx context.Context) {
  507. if err := muo.Exec(ctx); err != nil {
  508. panic(err)
  509. }
  510. }
  511. // defaults sets the default values of the builder before save.
  512. func (muo *MsgUpdateOne) defaults() error {
  513. if _, ok := muo.mutation.UpdatedAt(); !ok {
  514. if msg.UpdateDefaultUpdatedAt == nil {
  515. return fmt.Errorf("ent: uninitialized msg.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
  516. }
  517. v := msg.UpdateDefaultUpdatedAt()
  518. muo.mutation.SetUpdatedAt(v)
  519. }
  520. return nil
  521. }
  522. func (muo *MsgUpdateOne) sqlSave(ctx context.Context) (_node *Msg, err error) {
  523. _spec := sqlgraph.NewUpdateSpec(msg.Table, msg.Columns, sqlgraph.NewFieldSpec(msg.FieldID, field.TypeUint64))
  524. id, ok := muo.mutation.ID()
  525. if !ok {
  526. return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Msg.id" for update`)}
  527. }
  528. _spec.Node.ID.Value = id
  529. if fields := muo.fields; len(fields) > 0 {
  530. _spec.Node.Columns = make([]string, 0, len(fields))
  531. _spec.Node.Columns = append(_spec.Node.Columns, msg.FieldID)
  532. for _, f := range fields {
  533. if !msg.ValidColumn(f) {
  534. return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
  535. }
  536. if f != msg.FieldID {
  537. _spec.Node.Columns = append(_spec.Node.Columns, f)
  538. }
  539. }
  540. }
  541. if ps := muo.mutation.predicates; len(ps) > 0 {
  542. _spec.Predicate = func(selector *sql.Selector) {
  543. for i := range ps {
  544. ps[i](selector)
  545. }
  546. }
  547. }
  548. if value, ok := muo.mutation.UpdatedAt(); ok {
  549. _spec.SetField(msg.FieldUpdatedAt, field.TypeTime, value)
  550. }
  551. if value, ok := muo.mutation.DeletedAt(); ok {
  552. _spec.SetField(msg.FieldDeletedAt, field.TypeTime, value)
  553. }
  554. if muo.mutation.DeletedAtCleared() {
  555. _spec.ClearField(msg.FieldDeletedAt, field.TypeTime)
  556. }
  557. if value, ok := muo.mutation.Status(); ok {
  558. _spec.SetField(msg.FieldStatus, field.TypeUint8, value)
  559. }
  560. if value, ok := muo.mutation.AddedStatus(); ok {
  561. _spec.AddField(msg.FieldStatus, field.TypeUint8, value)
  562. }
  563. if muo.mutation.StatusCleared() {
  564. _spec.ClearField(msg.FieldStatus, field.TypeUint8)
  565. }
  566. if value, ok := muo.mutation.Fromwxid(); ok {
  567. _spec.SetField(msg.FieldFromwxid, field.TypeString, value)
  568. }
  569. if muo.mutation.FromwxidCleared() {
  570. _spec.ClearField(msg.FieldFromwxid, field.TypeString)
  571. }
  572. if value, ok := muo.mutation.Toid(); ok {
  573. _spec.SetField(msg.FieldToid, field.TypeString, value)
  574. }
  575. if muo.mutation.ToidCleared() {
  576. _spec.ClearField(msg.FieldToid, field.TypeString)
  577. }
  578. if value, ok := muo.mutation.Msgtype(); ok {
  579. _spec.SetField(msg.FieldMsgtype, field.TypeInt32, value)
  580. }
  581. if value, ok := muo.mutation.AddedMsgtype(); ok {
  582. _spec.AddField(msg.FieldMsgtype, field.TypeInt32, value)
  583. }
  584. if muo.mutation.MsgtypeCleared() {
  585. _spec.ClearField(msg.FieldMsgtype, field.TypeInt32)
  586. }
  587. if value, ok := muo.mutation.Msg(); ok {
  588. _spec.SetField(msg.FieldMsg, field.TypeString, value)
  589. }
  590. if muo.mutation.MsgCleared() {
  591. _spec.ClearField(msg.FieldMsg, field.TypeString)
  592. }
  593. if value, ok := muo.mutation.BatchNo(); ok {
  594. _spec.SetField(msg.FieldBatchNo, field.TypeString, value)
  595. }
  596. if muo.mutation.BatchNoCleared() {
  597. _spec.ClearField(msg.FieldBatchNo, field.TypeString)
  598. }
  599. if value, ok := muo.mutation.Cc(); ok {
  600. _spec.SetField(msg.FieldCc, field.TypeString, value)
  601. }
  602. if value, ok := muo.mutation.Phone(); ok {
  603. _spec.SetField(msg.FieldPhone, field.TypeString, value)
  604. }
  605. _node = &Msg{config: muo.config}
  606. _spec.Assign = _node.assignValues
  607. _spec.ScanValues = _node.scanValues
  608. if err = sqlgraph.UpdateNode(ctx, muo.driver, _spec); err != nil {
  609. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  610. err = &NotFoundError{msg.Label}
  611. } else if sqlgraph.IsConstraintError(err) {
  612. err = &ConstraintError{msg: err.Error(), wrap: err}
  613. }
  614. return nil, err
  615. }
  616. muo.mutation.done = true
  617. return _node, nil
  618. }