messagerecords_update.go 26 KB

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