messagerecords_update.go 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270
  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/contact"
  9. "wechat-api/ent/custom_types"
  10. "wechat-api/ent/messagerecords"
  11. "wechat-api/ent/predicate"
  12. "wechat-api/ent/sopnode"
  13. "wechat-api/ent/sopstage"
  14. "entgo.io/ent/dialect/sql"
  15. "entgo.io/ent/dialect/sql/sqlgraph"
  16. "entgo.io/ent/schema/field"
  17. )
  18. // MessageRecordsUpdate is the builder for updating MessageRecords entities.
  19. type MessageRecordsUpdate struct {
  20. config
  21. hooks []Hook
  22. mutation *MessageRecordsMutation
  23. }
  24. // Where appends a list predicates to the MessageRecordsUpdate builder.
  25. func (mru *MessageRecordsUpdate) Where(ps ...predicate.MessageRecords) *MessageRecordsUpdate {
  26. mru.mutation.Where(ps...)
  27. return mru
  28. }
  29. // SetUpdatedAt sets the "updated_at" field.
  30. func (mru *MessageRecordsUpdate) SetUpdatedAt(t time.Time) *MessageRecordsUpdate {
  31. mru.mutation.SetUpdatedAt(t)
  32. return mru
  33. }
  34. // SetStatus sets the "status" field.
  35. func (mru *MessageRecordsUpdate) SetStatus(u uint8) *MessageRecordsUpdate {
  36. mru.mutation.ResetStatus()
  37. mru.mutation.SetStatus(u)
  38. return mru
  39. }
  40. // SetNillableStatus sets the "status" field if the given value is not nil.
  41. func (mru *MessageRecordsUpdate) SetNillableStatus(u *uint8) *MessageRecordsUpdate {
  42. if u != nil {
  43. mru.SetStatus(*u)
  44. }
  45. return mru
  46. }
  47. // AddStatus adds u to the "status" field.
  48. func (mru *MessageRecordsUpdate) AddStatus(u int8) *MessageRecordsUpdate {
  49. mru.mutation.AddStatus(u)
  50. return mru
  51. }
  52. // ClearStatus clears the value of the "status" field.
  53. func (mru *MessageRecordsUpdate) ClearStatus() *MessageRecordsUpdate {
  54. mru.mutation.ClearStatus()
  55. return mru
  56. }
  57. // SetDeletedAt sets the "deleted_at" field.
  58. func (mru *MessageRecordsUpdate) SetDeletedAt(t time.Time) *MessageRecordsUpdate {
  59. mru.mutation.SetDeletedAt(t)
  60. return mru
  61. }
  62. // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
  63. func (mru *MessageRecordsUpdate) SetNillableDeletedAt(t *time.Time) *MessageRecordsUpdate {
  64. if t != nil {
  65. mru.SetDeletedAt(*t)
  66. }
  67. return mru
  68. }
  69. // ClearDeletedAt clears the value of the "deleted_at" field.
  70. func (mru *MessageRecordsUpdate) ClearDeletedAt() *MessageRecordsUpdate {
  71. mru.mutation.ClearDeletedAt()
  72. return mru
  73. }
  74. // SetBotWxid sets the "bot_wxid" field.
  75. func (mru *MessageRecordsUpdate) SetBotWxid(s string) *MessageRecordsUpdate {
  76. mru.mutation.SetBotWxid(s)
  77. return mru
  78. }
  79. // SetNillableBotWxid sets the "bot_wxid" field if the given value is not nil.
  80. func (mru *MessageRecordsUpdate) SetNillableBotWxid(s *string) *MessageRecordsUpdate {
  81. if s != nil {
  82. mru.SetBotWxid(*s)
  83. }
  84. return mru
  85. }
  86. // SetContactID sets the "contact_id" field.
  87. func (mru *MessageRecordsUpdate) SetContactID(u uint64) *MessageRecordsUpdate {
  88. mru.mutation.SetContactID(u)
  89. return mru
  90. }
  91. // SetNillableContactID sets the "contact_id" field if the given value is not nil.
  92. func (mru *MessageRecordsUpdate) SetNillableContactID(u *uint64) *MessageRecordsUpdate {
  93. if u != nil {
  94. mru.SetContactID(*u)
  95. }
  96. return mru
  97. }
  98. // ClearContactID clears the value of the "contact_id" field.
  99. func (mru *MessageRecordsUpdate) ClearContactID() *MessageRecordsUpdate {
  100. mru.mutation.ClearContactID()
  101. return mru
  102. }
  103. // SetContactType sets the "contact_type" field.
  104. func (mru *MessageRecordsUpdate) SetContactType(i int) *MessageRecordsUpdate {
  105. mru.mutation.ResetContactType()
  106. mru.mutation.SetContactType(i)
  107. return mru
  108. }
  109. // SetNillableContactType sets the "contact_type" field if the given value is not nil.
  110. func (mru *MessageRecordsUpdate) SetNillableContactType(i *int) *MessageRecordsUpdate {
  111. if i != nil {
  112. mru.SetContactType(*i)
  113. }
  114. return mru
  115. }
  116. // AddContactType adds i to the "contact_type" field.
  117. func (mru *MessageRecordsUpdate) AddContactType(i int) *MessageRecordsUpdate {
  118. mru.mutation.AddContactType(i)
  119. return mru
  120. }
  121. // SetContactWxid sets the "contact_wxid" field.
  122. func (mru *MessageRecordsUpdate) SetContactWxid(s string) *MessageRecordsUpdate {
  123. mru.mutation.SetContactWxid(s)
  124. return mru
  125. }
  126. // SetNillableContactWxid sets the "contact_wxid" field if the given value is not nil.
  127. func (mru *MessageRecordsUpdate) SetNillableContactWxid(s *string) *MessageRecordsUpdate {
  128. if s != nil {
  129. mru.SetContactWxid(*s)
  130. }
  131. return mru
  132. }
  133. // SetContentType sets the "content_type" field.
  134. func (mru *MessageRecordsUpdate) SetContentType(i int) *MessageRecordsUpdate {
  135. mru.mutation.ResetContentType()
  136. mru.mutation.SetContentType(i)
  137. return mru
  138. }
  139. // SetNillableContentType sets the "content_type" field if the given value is not nil.
  140. func (mru *MessageRecordsUpdate) SetNillableContentType(i *int) *MessageRecordsUpdate {
  141. if i != nil {
  142. mru.SetContentType(*i)
  143. }
  144. return mru
  145. }
  146. // AddContentType adds i to the "content_type" field.
  147. func (mru *MessageRecordsUpdate) AddContentType(i int) *MessageRecordsUpdate {
  148. mru.mutation.AddContentType(i)
  149. return mru
  150. }
  151. // SetContent sets the "content" field.
  152. func (mru *MessageRecordsUpdate) SetContent(s string) *MessageRecordsUpdate {
  153. mru.mutation.SetContent(s)
  154. return mru
  155. }
  156. // SetNillableContent sets the "content" field if the given value is not nil.
  157. func (mru *MessageRecordsUpdate) SetNillableContent(s *string) *MessageRecordsUpdate {
  158. if s != nil {
  159. mru.SetContent(*s)
  160. }
  161. return mru
  162. }
  163. // SetMeta sets the "meta" field.
  164. func (mru *MessageRecordsUpdate) SetMeta(ct custom_types.Meta) *MessageRecordsUpdate {
  165. mru.mutation.SetMeta(ct)
  166. return mru
  167. }
  168. // SetNillableMeta sets the "meta" field if the given value is not nil.
  169. func (mru *MessageRecordsUpdate) SetNillableMeta(ct *custom_types.Meta) *MessageRecordsUpdate {
  170. if ct != nil {
  171. mru.SetMeta(*ct)
  172. }
  173. return mru
  174. }
  175. // ClearMeta clears the value of the "meta" field.
  176. func (mru *MessageRecordsUpdate) ClearMeta() *MessageRecordsUpdate {
  177. mru.mutation.ClearMeta()
  178. return mru
  179. }
  180. // SetErrorDetail sets the "error_detail" field.
  181. func (mru *MessageRecordsUpdate) SetErrorDetail(s string) *MessageRecordsUpdate {
  182. mru.mutation.SetErrorDetail(s)
  183. return mru
  184. }
  185. // SetNillableErrorDetail sets the "error_detail" field if the given value is not nil.
  186. func (mru *MessageRecordsUpdate) SetNillableErrorDetail(s *string) *MessageRecordsUpdate {
  187. if s != nil {
  188. mru.SetErrorDetail(*s)
  189. }
  190. return mru
  191. }
  192. // SetSendTime sets the "send_time" field.
  193. func (mru *MessageRecordsUpdate) SetSendTime(t time.Time) *MessageRecordsUpdate {
  194. mru.mutation.SetSendTime(t)
  195. return mru
  196. }
  197. // SetNillableSendTime sets the "send_time" field if the given value is not nil.
  198. func (mru *MessageRecordsUpdate) SetNillableSendTime(t *time.Time) *MessageRecordsUpdate {
  199. if t != nil {
  200. mru.SetSendTime(*t)
  201. }
  202. return mru
  203. }
  204. // ClearSendTime clears the value of the "send_time" field.
  205. func (mru *MessageRecordsUpdate) ClearSendTime() *MessageRecordsUpdate {
  206. mru.mutation.ClearSendTime()
  207. return mru
  208. }
  209. // SetSourceType sets the "source_type" field.
  210. func (mru *MessageRecordsUpdate) SetSourceType(i int) *MessageRecordsUpdate {
  211. mru.mutation.ResetSourceType()
  212. mru.mutation.SetSourceType(i)
  213. return mru
  214. }
  215. // SetNillableSourceType sets the "source_type" field if the given value is not nil.
  216. func (mru *MessageRecordsUpdate) SetNillableSourceType(i *int) *MessageRecordsUpdate {
  217. if i != nil {
  218. mru.SetSourceType(*i)
  219. }
  220. return mru
  221. }
  222. // AddSourceType adds i to the "source_type" field.
  223. func (mru *MessageRecordsUpdate) AddSourceType(i int) *MessageRecordsUpdate {
  224. mru.mutation.AddSourceType(i)
  225. return mru
  226. }
  227. // SetSourceID sets the "source_id" field.
  228. func (mru *MessageRecordsUpdate) SetSourceID(u uint64) *MessageRecordsUpdate {
  229. mru.mutation.SetSourceID(u)
  230. return mru
  231. }
  232. // SetNillableSourceID sets the "source_id" field if the given value is not nil.
  233. func (mru *MessageRecordsUpdate) SetNillableSourceID(u *uint64) *MessageRecordsUpdate {
  234. if u != nil {
  235. mru.SetSourceID(*u)
  236. }
  237. return mru
  238. }
  239. // ClearSourceID clears the value of the "source_id" field.
  240. func (mru *MessageRecordsUpdate) ClearSourceID() *MessageRecordsUpdate {
  241. mru.mutation.ClearSourceID()
  242. return mru
  243. }
  244. // SetSubSourceID sets the "sub_source_id" field.
  245. func (mru *MessageRecordsUpdate) SetSubSourceID(u uint64) *MessageRecordsUpdate {
  246. mru.mutation.SetSubSourceID(u)
  247. return mru
  248. }
  249. // SetNillableSubSourceID sets the "sub_source_id" field if the given value is not nil.
  250. func (mru *MessageRecordsUpdate) SetNillableSubSourceID(u *uint64) *MessageRecordsUpdate {
  251. if u != nil {
  252. mru.SetSubSourceID(*u)
  253. }
  254. return mru
  255. }
  256. // ClearSubSourceID clears the value of the "sub_source_id" field.
  257. func (mru *MessageRecordsUpdate) ClearSubSourceID() *MessageRecordsUpdate {
  258. mru.mutation.ClearSubSourceID()
  259. return mru
  260. }
  261. // SetOrganizationID sets the "organization_id" field.
  262. func (mru *MessageRecordsUpdate) SetOrganizationID(u uint64) *MessageRecordsUpdate {
  263. mru.mutation.ResetOrganizationID()
  264. mru.mutation.SetOrganizationID(u)
  265. return mru
  266. }
  267. // SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
  268. func (mru *MessageRecordsUpdate) SetNillableOrganizationID(u *uint64) *MessageRecordsUpdate {
  269. if u != nil {
  270. mru.SetOrganizationID(*u)
  271. }
  272. return mru
  273. }
  274. // AddOrganizationID adds u to the "organization_id" field.
  275. func (mru *MessageRecordsUpdate) AddOrganizationID(u int64) *MessageRecordsUpdate {
  276. mru.mutation.AddOrganizationID(u)
  277. return mru
  278. }
  279. // ClearOrganizationID clears the value of the "organization_id" field.
  280. func (mru *MessageRecordsUpdate) ClearOrganizationID() *MessageRecordsUpdate {
  281. mru.mutation.ClearOrganizationID()
  282. return mru
  283. }
  284. // SetSopStageID sets the "sop_stage" edge to the SopStage entity by ID.
  285. func (mru *MessageRecordsUpdate) SetSopStageID(id uint64) *MessageRecordsUpdate {
  286. mru.mutation.SetSopStageID(id)
  287. return mru
  288. }
  289. // SetNillableSopStageID sets the "sop_stage" edge to the SopStage entity by ID if the given value is not nil.
  290. func (mru *MessageRecordsUpdate) SetNillableSopStageID(id *uint64) *MessageRecordsUpdate {
  291. if id != nil {
  292. mru = mru.SetSopStageID(*id)
  293. }
  294. return mru
  295. }
  296. // SetSopStage sets the "sop_stage" edge to the SopStage entity.
  297. func (mru *MessageRecordsUpdate) SetSopStage(s *SopStage) *MessageRecordsUpdate {
  298. return mru.SetSopStageID(s.ID)
  299. }
  300. // SetSopNodeID sets the "sop_node" edge to the SopNode entity by ID.
  301. func (mru *MessageRecordsUpdate) SetSopNodeID(id uint64) *MessageRecordsUpdate {
  302. mru.mutation.SetSopNodeID(id)
  303. return mru
  304. }
  305. // SetNillableSopNodeID sets the "sop_node" edge to the SopNode entity by ID if the given value is not nil.
  306. func (mru *MessageRecordsUpdate) SetNillableSopNodeID(id *uint64) *MessageRecordsUpdate {
  307. if id != nil {
  308. mru = mru.SetSopNodeID(*id)
  309. }
  310. return mru
  311. }
  312. // SetSopNode sets the "sop_node" edge to the SopNode entity.
  313. func (mru *MessageRecordsUpdate) SetSopNode(s *SopNode) *MessageRecordsUpdate {
  314. return mru.SetSopNodeID(s.ID)
  315. }
  316. // SetMessageContactID sets the "message_contact" edge to the Contact entity by ID.
  317. func (mru *MessageRecordsUpdate) SetMessageContactID(id uint64) *MessageRecordsUpdate {
  318. mru.mutation.SetMessageContactID(id)
  319. return mru
  320. }
  321. // SetNillableMessageContactID sets the "message_contact" edge to the Contact entity by ID if the given value is not nil.
  322. func (mru *MessageRecordsUpdate) SetNillableMessageContactID(id *uint64) *MessageRecordsUpdate {
  323. if id != nil {
  324. mru = mru.SetMessageContactID(*id)
  325. }
  326. return mru
  327. }
  328. // SetMessageContact sets the "message_contact" edge to the Contact entity.
  329. func (mru *MessageRecordsUpdate) SetMessageContact(c *Contact) *MessageRecordsUpdate {
  330. return mru.SetMessageContactID(c.ID)
  331. }
  332. // Mutation returns the MessageRecordsMutation object of the builder.
  333. func (mru *MessageRecordsUpdate) Mutation() *MessageRecordsMutation {
  334. return mru.mutation
  335. }
  336. // ClearSopStage clears the "sop_stage" edge to the SopStage entity.
  337. func (mru *MessageRecordsUpdate) ClearSopStage() *MessageRecordsUpdate {
  338. mru.mutation.ClearSopStage()
  339. return mru
  340. }
  341. // ClearSopNode clears the "sop_node" edge to the SopNode entity.
  342. func (mru *MessageRecordsUpdate) ClearSopNode() *MessageRecordsUpdate {
  343. mru.mutation.ClearSopNode()
  344. return mru
  345. }
  346. // ClearMessageContact clears the "message_contact" edge to the Contact entity.
  347. func (mru *MessageRecordsUpdate) ClearMessageContact() *MessageRecordsUpdate {
  348. mru.mutation.ClearMessageContact()
  349. return mru
  350. }
  351. // Save executes the query and returns the number of nodes affected by the update operation.
  352. func (mru *MessageRecordsUpdate) Save(ctx context.Context) (int, error) {
  353. if err := mru.defaults(); err != nil {
  354. return 0, err
  355. }
  356. return withHooks(ctx, mru.sqlSave, mru.mutation, mru.hooks)
  357. }
  358. // SaveX is like Save, but panics if an error occurs.
  359. func (mru *MessageRecordsUpdate) SaveX(ctx context.Context) int {
  360. affected, err := mru.Save(ctx)
  361. if err != nil {
  362. panic(err)
  363. }
  364. return affected
  365. }
  366. // Exec executes the query.
  367. func (mru *MessageRecordsUpdate) Exec(ctx context.Context) error {
  368. _, err := mru.Save(ctx)
  369. return err
  370. }
  371. // ExecX is like Exec, but panics if an error occurs.
  372. func (mru *MessageRecordsUpdate) ExecX(ctx context.Context) {
  373. if err := mru.Exec(ctx); err != nil {
  374. panic(err)
  375. }
  376. }
  377. // defaults sets the default values of the builder before save.
  378. func (mru *MessageRecordsUpdate) defaults() error {
  379. if _, ok := mru.mutation.UpdatedAt(); !ok {
  380. if messagerecords.UpdateDefaultUpdatedAt == nil {
  381. return fmt.Errorf("ent: uninitialized messagerecords.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
  382. }
  383. v := messagerecords.UpdateDefaultUpdatedAt()
  384. mru.mutation.SetUpdatedAt(v)
  385. }
  386. return nil
  387. }
  388. func (mru *MessageRecordsUpdate) sqlSave(ctx context.Context) (n int, err error) {
  389. _spec := sqlgraph.NewUpdateSpec(messagerecords.Table, messagerecords.Columns, sqlgraph.NewFieldSpec(messagerecords.FieldID, field.TypeUint64))
  390. if ps := mru.mutation.predicates; len(ps) > 0 {
  391. _spec.Predicate = func(selector *sql.Selector) {
  392. for i := range ps {
  393. ps[i](selector)
  394. }
  395. }
  396. }
  397. if value, ok := mru.mutation.UpdatedAt(); ok {
  398. _spec.SetField(messagerecords.FieldUpdatedAt, field.TypeTime, value)
  399. }
  400. if value, ok := mru.mutation.Status(); ok {
  401. _spec.SetField(messagerecords.FieldStatus, field.TypeUint8, value)
  402. }
  403. if value, ok := mru.mutation.AddedStatus(); ok {
  404. _spec.AddField(messagerecords.FieldStatus, field.TypeUint8, value)
  405. }
  406. if mru.mutation.StatusCleared() {
  407. _spec.ClearField(messagerecords.FieldStatus, field.TypeUint8)
  408. }
  409. if value, ok := mru.mutation.DeletedAt(); ok {
  410. _spec.SetField(messagerecords.FieldDeletedAt, field.TypeTime, value)
  411. }
  412. if mru.mutation.DeletedAtCleared() {
  413. _spec.ClearField(messagerecords.FieldDeletedAt, field.TypeTime)
  414. }
  415. if value, ok := mru.mutation.BotWxid(); ok {
  416. _spec.SetField(messagerecords.FieldBotWxid, field.TypeString, value)
  417. }
  418. if value, ok := mru.mutation.ContactType(); ok {
  419. _spec.SetField(messagerecords.FieldContactType, field.TypeInt, value)
  420. }
  421. if value, ok := mru.mutation.AddedContactType(); ok {
  422. _spec.AddField(messagerecords.FieldContactType, field.TypeInt, value)
  423. }
  424. if value, ok := mru.mutation.ContactWxid(); ok {
  425. _spec.SetField(messagerecords.FieldContactWxid, field.TypeString, value)
  426. }
  427. if value, ok := mru.mutation.ContentType(); ok {
  428. _spec.SetField(messagerecords.FieldContentType, field.TypeInt, value)
  429. }
  430. if value, ok := mru.mutation.AddedContentType(); ok {
  431. _spec.AddField(messagerecords.FieldContentType, field.TypeInt, value)
  432. }
  433. if value, ok := mru.mutation.Content(); ok {
  434. _spec.SetField(messagerecords.FieldContent, field.TypeString, value)
  435. }
  436. if value, ok := mru.mutation.Meta(); ok {
  437. _spec.SetField(messagerecords.FieldMeta, field.TypeJSON, value)
  438. }
  439. if mru.mutation.MetaCleared() {
  440. _spec.ClearField(messagerecords.FieldMeta, field.TypeJSON)
  441. }
  442. if value, ok := mru.mutation.ErrorDetail(); ok {
  443. _spec.SetField(messagerecords.FieldErrorDetail, field.TypeString, value)
  444. }
  445. if value, ok := mru.mutation.SendTime(); ok {
  446. _spec.SetField(messagerecords.FieldSendTime, field.TypeTime, value)
  447. }
  448. if mru.mutation.SendTimeCleared() {
  449. _spec.ClearField(messagerecords.FieldSendTime, field.TypeTime)
  450. }
  451. if value, ok := mru.mutation.SourceType(); ok {
  452. _spec.SetField(messagerecords.FieldSourceType, field.TypeInt, value)
  453. }
  454. if value, ok := mru.mutation.AddedSourceType(); ok {
  455. _spec.AddField(messagerecords.FieldSourceType, field.TypeInt, value)
  456. }
  457. if value, ok := mru.mutation.OrganizationID(); ok {
  458. _spec.SetField(messagerecords.FieldOrganizationID, field.TypeUint64, value)
  459. }
  460. if value, ok := mru.mutation.AddedOrganizationID(); ok {
  461. _spec.AddField(messagerecords.FieldOrganizationID, field.TypeUint64, value)
  462. }
  463. if mru.mutation.OrganizationIDCleared() {
  464. _spec.ClearField(messagerecords.FieldOrganizationID, field.TypeUint64)
  465. }
  466. if mru.mutation.SopStageCleared() {
  467. edge := &sqlgraph.EdgeSpec{
  468. Rel: sqlgraph.M2O,
  469. Inverse: true,
  470. Table: messagerecords.SopStageTable,
  471. Columns: []string{messagerecords.SopStageColumn},
  472. Bidi: false,
  473. Target: &sqlgraph.EdgeTarget{
  474. IDSpec: sqlgraph.NewFieldSpec(sopstage.FieldID, field.TypeUint64),
  475. },
  476. }
  477. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  478. }
  479. if nodes := mru.mutation.SopStageIDs(); len(nodes) > 0 {
  480. edge := &sqlgraph.EdgeSpec{
  481. Rel: sqlgraph.M2O,
  482. Inverse: true,
  483. Table: messagerecords.SopStageTable,
  484. Columns: []string{messagerecords.SopStageColumn},
  485. Bidi: false,
  486. Target: &sqlgraph.EdgeTarget{
  487. IDSpec: sqlgraph.NewFieldSpec(sopstage.FieldID, field.TypeUint64),
  488. },
  489. }
  490. for _, k := range nodes {
  491. edge.Target.Nodes = append(edge.Target.Nodes, k)
  492. }
  493. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  494. }
  495. if mru.mutation.SopNodeCleared() {
  496. edge := &sqlgraph.EdgeSpec{
  497. Rel: sqlgraph.M2O,
  498. Inverse: true,
  499. Table: messagerecords.SopNodeTable,
  500. Columns: []string{messagerecords.SopNodeColumn},
  501. Bidi: false,
  502. Target: &sqlgraph.EdgeTarget{
  503. IDSpec: sqlgraph.NewFieldSpec(sopnode.FieldID, field.TypeUint64),
  504. },
  505. }
  506. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  507. }
  508. if nodes := mru.mutation.SopNodeIDs(); len(nodes) > 0 {
  509. edge := &sqlgraph.EdgeSpec{
  510. Rel: sqlgraph.M2O,
  511. Inverse: true,
  512. Table: messagerecords.SopNodeTable,
  513. Columns: []string{messagerecords.SopNodeColumn},
  514. Bidi: false,
  515. Target: &sqlgraph.EdgeTarget{
  516. IDSpec: sqlgraph.NewFieldSpec(sopnode.FieldID, field.TypeUint64),
  517. },
  518. }
  519. for _, k := range nodes {
  520. edge.Target.Nodes = append(edge.Target.Nodes, k)
  521. }
  522. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  523. }
  524. if mru.mutation.MessageContactCleared() {
  525. edge := &sqlgraph.EdgeSpec{
  526. Rel: sqlgraph.M2O,
  527. Inverse: true,
  528. Table: messagerecords.MessageContactTable,
  529. Columns: []string{messagerecords.MessageContactColumn},
  530. Bidi: false,
  531. Target: &sqlgraph.EdgeTarget{
  532. IDSpec: sqlgraph.NewFieldSpec(contact.FieldID, field.TypeUint64),
  533. },
  534. }
  535. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  536. }
  537. if nodes := mru.mutation.MessageContactIDs(); len(nodes) > 0 {
  538. edge := &sqlgraph.EdgeSpec{
  539. Rel: sqlgraph.M2O,
  540. Inverse: true,
  541. Table: messagerecords.MessageContactTable,
  542. Columns: []string{messagerecords.MessageContactColumn},
  543. Bidi: false,
  544. Target: &sqlgraph.EdgeTarget{
  545. IDSpec: sqlgraph.NewFieldSpec(contact.FieldID, field.TypeUint64),
  546. },
  547. }
  548. for _, k := range nodes {
  549. edge.Target.Nodes = append(edge.Target.Nodes, k)
  550. }
  551. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  552. }
  553. if n, err = sqlgraph.UpdateNodes(ctx, mru.driver, _spec); err != nil {
  554. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  555. err = &NotFoundError{messagerecords.Label}
  556. } else if sqlgraph.IsConstraintError(err) {
  557. err = &ConstraintError{msg: err.Error(), wrap: err}
  558. }
  559. return 0, err
  560. }
  561. mru.mutation.done = true
  562. return n, nil
  563. }
  564. // MessageRecordsUpdateOne is the builder for updating a single MessageRecords entity.
  565. type MessageRecordsUpdateOne struct {
  566. config
  567. fields []string
  568. hooks []Hook
  569. mutation *MessageRecordsMutation
  570. }
  571. // SetUpdatedAt sets the "updated_at" field.
  572. func (mruo *MessageRecordsUpdateOne) SetUpdatedAt(t time.Time) *MessageRecordsUpdateOne {
  573. mruo.mutation.SetUpdatedAt(t)
  574. return mruo
  575. }
  576. // SetStatus sets the "status" field.
  577. func (mruo *MessageRecordsUpdateOne) SetStatus(u uint8) *MessageRecordsUpdateOne {
  578. mruo.mutation.ResetStatus()
  579. mruo.mutation.SetStatus(u)
  580. return mruo
  581. }
  582. // SetNillableStatus sets the "status" field if the given value is not nil.
  583. func (mruo *MessageRecordsUpdateOne) SetNillableStatus(u *uint8) *MessageRecordsUpdateOne {
  584. if u != nil {
  585. mruo.SetStatus(*u)
  586. }
  587. return mruo
  588. }
  589. // AddStatus adds u to the "status" field.
  590. func (mruo *MessageRecordsUpdateOne) AddStatus(u int8) *MessageRecordsUpdateOne {
  591. mruo.mutation.AddStatus(u)
  592. return mruo
  593. }
  594. // ClearStatus clears the value of the "status" field.
  595. func (mruo *MessageRecordsUpdateOne) ClearStatus() *MessageRecordsUpdateOne {
  596. mruo.mutation.ClearStatus()
  597. return mruo
  598. }
  599. // SetDeletedAt sets the "deleted_at" field.
  600. func (mruo *MessageRecordsUpdateOne) SetDeletedAt(t time.Time) *MessageRecordsUpdateOne {
  601. mruo.mutation.SetDeletedAt(t)
  602. return mruo
  603. }
  604. // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
  605. func (mruo *MessageRecordsUpdateOne) SetNillableDeletedAt(t *time.Time) *MessageRecordsUpdateOne {
  606. if t != nil {
  607. mruo.SetDeletedAt(*t)
  608. }
  609. return mruo
  610. }
  611. // ClearDeletedAt clears the value of the "deleted_at" field.
  612. func (mruo *MessageRecordsUpdateOne) ClearDeletedAt() *MessageRecordsUpdateOne {
  613. mruo.mutation.ClearDeletedAt()
  614. return mruo
  615. }
  616. // SetBotWxid sets the "bot_wxid" field.
  617. func (mruo *MessageRecordsUpdateOne) SetBotWxid(s string) *MessageRecordsUpdateOne {
  618. mruo.mutation.SetBotWxid(s)
  619. return mruo
  620. }
  621. // SetNillableBotWxid sets the "bot_wxid" field if the given value is not nil.
  622. func (mruo *MessageRecordsUpdateOne) SetNillableBotWxid(s *string) *MessageRecordsUpdateOne {
  623. if s != nil {
  624. mruo.SetBotWxid(*s)
  625. }
  626. return mruo
  627. }
  628. // SetContactID sets the "contact_id" field.
  629. func (mruo *MessageRecordsUpdateOne) SetContactID(u uint64) *MessageRecordsUpdateOne {
  630. mruo.mutation.SetContactID(u)
  631. return mruo
  632. }
  633. // SetNillableContactID sets the "contact_id" field if the given value is not nil.
  634. func (mruo *MessageRecordsUpdateOne) SetNillableContactID(u *uint64) *MessageRecordsUpdateOne {
  635. if u != nil {
  636. mruo.SetContactID(*u)
  637. }
  638. return mruo
  639. }
  640. // ClearContactID clears the value of the "contact_id" field.
  641. func (mruo *MessageRecordsUpdateOne) ClearContactID() *MessageRecordsUpdateOne {
  642. mruo.mutation.ClearContactID()
  643. return mruo
  644. }
  645. // SetContactType sets the "contact_type" field.
  646. func (mruo *MessageRecordsUpdateOne) SetContactType(i int) *MessageRecordsUpdateOne {
  647. mruo.mutation.ResetContactType()
  648. mruo.mutation.SetContactType(i)
  649. return mruo
  650. }
  651. // SetNillableContactType sets the "contact_type" field if the given value is not nil.
  652. func (mruo *MessageRecordsUpdateOne) SetNillableContactType(i *int) *MessageRecordsUpdateOne {
  653. if i != nil {
  654. mruo.SetContactType(*i)
  655. }
  656. return mruo
  657. }
  658. // AddContactType adds i to the "contact_type" field.
  659. func (mruo *MessageRecordsUpdateOne) AddContactType(i int) *MessageRecordsUpdateOne {
  660. mruo.mutation.AddContactType(i)
  661. return mruo
  662. }
  663. // SetContactWxid sets the "contact_wxid" field.
  664. func (mruo *MessageRecordsUpdateOne) SetContactWxid(s string) *MessageRecordsUpdateOne {
  665. mruo.mutation.SetContactWxid(s)
  666. return mruo
  667. }
  668. // SetNillableContactWxid sets the "contact_wxid" field if the given value is not nil.
  669. func (mruo *MessageRecordsUpdateOne) SetNillableContactWxid(s *string) *MessageRecordsUpdateOne {
  670. if s != nil {
  671. mruo.SetContactWxid(*s)
  672. }
  673. return mruo
  674. }
  675. // SetContentType sets the "content_type" field.
  676. func (mruo *MessageRecordsUpdateOne) SetContentType(i int) *MessageRecordsUpdateOne {
  677. mruo.mutation.ResetContentType()
  678. mruo.mutation.SetContentType(i)
  679. return mruo
  680. }
  681. // SetNillableContentType sets the "content_type" field if the given value is not nil.
  682. func (mruo *MessageRecordsUpdateOne) SetNillableContentType(i *int) *MessageRecordsUpdateOne {
  683. if i != nil {
  684. mruo.SetContentType(*i)
  685. }
  686. return mruo
  687. }
  688. // AddContentType adds i to the "content_type" field.
  689. func (mruo *MessageRecordsUpdateOne) AddContentType(i int) *MessageRecordsUpdateOne {
  690. mruo.mutation.AddContentType(i)
  691. return mruo
  692. }
  693. // SetContent sets the "content" field.
  694. func (mruo *MessageRecordsUpdateOne) SetContent(s string) *MessageRecordsUpdateOne {
  695. mruo.mutation.SetContent(s)
  696. return mruo
  697. }
  698. // SetNillableContent sets the "content" field if the given value is not nil.
  699. func (mruo *MessageRecordsUpdateOne) SetNillableContent(s *string) *MessageRecordsUpdateOne {
  700. if s != nil {
  701. mruo.SetContent(*s)
  702. }
  703. return mruo
  704. }
  705. // SetMeta sets the "meta" field.
  706. func (mruo *MessageRecordsUpdateOne) SetMeta(ct custom_types.Meta) *MessageRecordsUpdateOne {
  707. mruo.mutation.SetMeta(ct)
  708. return mruo
  709. }
  710. // SetNillableMeta sets the "meta" field if the given value is not nil.
  711. func (mruo *MessageRecordsUpdateOne) SetNillableMeta(ct *custom_types.Meta) *MessageRecordsUpdateOne {
  712. if ct != nil {
  713. mruo.SetMeta(*ct)
  714. }
  715. return mruo
  716. }
  717. // ClearMeta clears the value of the "meta" field.
  718. func (mruo *MessageRecordsUpdateOne) ClearMeta() *MessageRecordsUpdateOne {
  719. mruo.mutation.ClearMeta()
  720. return mruo
  721. }
  722. // SetErrorDetail sets the "error_detail" field.
  723. func (mruo *MessageRecordsUpdateOne) SetErrorDetail(s string) *MessageRecordsUpdateOne {
  724. mruo.mutation.SetErrorDetail(s)
  725. return mruo
  726. }
  727. // SetNillableErrorDetail sets the "error_detail" field if the given value is not nil.
  728. func (mruo *MessageRecordsUpdateOne) SetNillableErrorDetail(s *string) *MessageRecordsUpdateOne {
  729. if s != nil {
  730. mruo.SetErrorDetail(*s)
  731. }
  732. return mruo
  733. }
  734. // SetSendTime sets the "send_time" field.
  735. func (mruo *MessageRecordsUpdateOne) SetSendTime(t time.Time) *MessageRecordsUpdateOne {
  736. mruo.mutation.SetSendTime(t)
  737. return mruo
  738. }
  739. // SetNillableSendTime sets the "send_time" field if the given value is not nil.
  740. func (mruo *MessageRecordsUpdateOne) SetNillableSendTime(t *time.Time) *MessageRecordsUpdateOne {
  741. if t != nil {
  742. mruo.SetSendTime(*t)
  743. }
  744. return mruo
  745. }
  746. // ClearSendTime clears the value of the "send_time" field.
  747. func (mruo *MessageRecordsUpdateOne) ClearSendTime() *MessageRecordsUpdateOne {
  748. mruo.mutation.ClearSendTime()
  749. return mruo
  750. }
  751. // SetSourceType sets the "source_type" field.
  752. func (mruo *MessageRecordsUpdateOne) SetSourceType(i int) *MessageRecordsUpdateOne {
  753. mruo.mutation.ResetSourceType()
  754. mruo.mutation.SetSourceType(i)
  755. return mruo
  756. }
  757. // SetNillableSourceType sets the "source_type" field if the given value is not nil.
  758. func (mruo *MessageRecordsUpdateOne) SetNillableSourceType(i *int) *MessageRecordsUpdateOne {
  759. if i != nil {
  760. mruo.SetSourceType(*i)
  761. }
  762. return mruo
  763. }
  764. // AddSourceType adds i to the "source_type" field.
  765. func (mruo *MessageRecordsUpdateOne) AddSourceType(i int) *MessageRecordsUpdateOne {
  766. mruo.mutation.AddSourceType(i)
  767. return mruo
  768. }
  769. // SetSourceID sets the "source_id" field.
  770. func (mruo *MessageRecordsUpdateOne) SetSourceID(u uint64) *MessageRecordsUpdateOne {
  771. mruo.mutation.SetSourceID(u)
  772. return mruo
  773. }
  774. // SetNillableSourceID sets the "source_id" field if the given value is not nil.
  775. func (mruo *MessageRecordsUpdateOne) SetNillableSourceID(u *uint64) *MessageRecordsUpdateOne {
  776. if u != nil {
  777. mruo.SetSourceID(*u)
  778. }
  779. return mruo
  780. }
  781. // ClearSourceID clears the value of the "source_id" field.
  782. func (mruo *MessageRecordsUpdateOne) ClearSourceID() *MessageRecordsUpdateOne {
  783. mruo.mutation.ClearSourceID()
  784. return mruo
  785. }
  786. // SetSubSourceID sets the "sub_source_id" field.
  787. func (mruo *MessageRecordsUpdateOne) SetSubSourceID(u uint64) *MessageRecordsUpdateOne {
  788. mruo.mutation.SetSubSourceID(u)
  789. return mruo
  790. }
  791. // SetNillableSubSourceID sets the "sub_source_id" field if the given value is not nil.
  792. func (mruo *MessageRecordsUpdateOne) SetNillableSubSourceID(u *uint64) *MessageRecordsUpdateOne {
  793. if u != nil {
  794. mruo.SetSubSourceID(*u)
  795. }
  796. return mruo
  797. }
  798. // ClearSubSourceID clears the value of the "sub_source_id" field.
  799. func (mruo *MessageRecordsUpdateOne) ClearSubSourceID() *MessageRecordsUpdateOne {
  800. mruo.mutation.ClearSubSourceID()
  801. return mruo
  802. }
  803. // SetOrganizationID sets the "organization_id" field.
  804. func (mruo *MessageRecordsUpdateOne) SetOrganizationID(u uint64) *MessageRecordsUpdateOne {
  805. mruo.mutation.ResetOrganizationID()
  806. mruo.mutation.SetOrganizationID(u)
  807. return mruo
  808. }
  809. // SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
  810. func (mruo *MessageRecordsUpdateOne) SetNillableOrganizationID(u *uint64) *MessageRecordsUpdateOne {
  811. if u != nil {
  812. mruo.SetOrganizationID(*u)
  813. }
  814. return mruo
  815. }
  816. // AddOrganizationID adds u to the "organization_id" field.
  817. func (mruo *MessageRecordsUpdateOne) AddOrganizationID(u int64) *MessageRecordsUpdateOne {
  818. mruo.mutation.AddOrganizationID(u)
  819. return mruo
  820. }
  821. // ClearOrganizationID clears the value of the "organization_id" field.
  822. func (mruo *MessageRecordsUpdateOne) ClearOrganizationID() *MessageRecordsUpdateOne {
  823. mruo.mutation.ClearOrganizationID()
  824. return mruo
  825. }
  826. // SetSopStageID sets the "sop_stage" edge to the SopStage entity by ID.
  827. func (mruo *MessageRecordsUpdateOne) SetSopStageID(id uint64) *MessageRecordsUpdateOne {
  828. mruo.mutation.SetSopStageID(id)
  829. return mruo
  830. }
  831. // SetNillableSopStageID sets the "sop_stage" edge to the SopStage entity by ID if the given value is not nil.
  832. func (mruo *MessageRecordsUpdateOne) SetNillableSopStageID(id *uint64) *MessageRecordsUpdateOne {
  833. if id != nil {
  834. mruo = mruo.SetSopStageID(*id)
  835. }
  836. return mruo
  837. }
  838. // SetSopStage sets the "sop_stage" edge to the SopStage entity.
  839. func (mruo *MessageRecordsUpdateOne) SetSopStage(s *SopStage) *MessageRecordsUpdateOne {
  840. return mruo.SetSopStageID(s.ID)
  841. }
  842. // SetSopNodeID sets the "sop_node" edge to the SopNode entity by ID.
  843. func (mruo *MessageRecordsUpdateOne) SetSopNodeID(id uint64) *MessageRecordsUpdateOne {
  844. mruo.mutation.SetSopNodeID(id)
  845. return mruo
  846. }
  847. // SetNillableSopNodeID sets the "sop_node" edge to the SopNode entity by ID if the given value is not nil.
  848. func (mruo *MessageRecordsUpdateOne) SetNillableSopNodeID(id *uint64) *MessageRecordsUpdateOne {
  849. if id != nil {
  850. mruo = mruo.SetSopNodeID(*id)
  851. }
  852. return mruo
  853. }
  854. // SetSopNode sets the "sop_node" edge to the SopNode entity.
  855. func (mruo *MessageRecordsUpdateOne) SetSopNode(s *SopNode) *MessageRecordsUpdateOne {
  856. return mruo.SetSopNodeID(s.ID)
  857. }
  858. // SetMessageContactID sets the "message_contact" edge to the Contact entity by ID.
  859. func (mruo *MessageRecordsUpdateOne) SetMessageContactID(id uint64) *MessageRecordsUpdateOne {
  860. mruo.mutation.SetMessageContactID(id)
  861. return mruo
  862. }
  863. // SetNillableMessageContactID sets the "message_contact" edge to the Contact entity by ID if the given value is not nil.
  864. func (mruo *MessageRecordsUpdateOne) SetNillableMessageContactID(id *uint64) *MessageRecordsUpdateOne {
  865. if id != nil {
  866. mruo = mruo.SetMessageContactID(*id)
  867. }
  868. return mruo
  869. }
  870. // SetMessageContact sets the "message_contact" edge to the Contact entity.
  871. func (mruo *MessageRecordsUpdateOne) SetMessageContact(c *Contact) *MessageRecordsUpdateOne {
  872. return mruo.SetMessageContactID(c.ID)
  873. }
  874. // Mutation returns the MessageRecordsMutation object of the builder.
  875. func (mruo *MessageRecordsUpdateOne) Mutation() *MessageRecordsMutation {
  876. return mruo.mutation
  877. }
  878. // ClearSopStage clears the "sop_stage" edge to the SopStage entity.
  879. func (mruo *MessageRecordsUpdateOne) ClearSopStage() *MessageRecordsUpdateOne {
  880. mruo.mutation.ClearSopStage()
  881. return mruo
  882. }
  883. // ClearSopNode clears the "sop_node" edge to the SopNode entity.
  884. func (mruo *MessageRecordsUpdateOne) ClearSopNode() *MessageRecordsUpdateOne {
  885. mruo.mutation.ClearSopNode()
  886. return mruo
  887. }
  888. // ClearMessageContact clears the "message_contact" edge to the Contact entity.
  889. func (mruo *MessageRecordsUpdateOne) ClearMessageContact() *MessageRecordsUpdateOne {
  890. mruo.mutation.ClearMessageContact()
  891. return mruo
  892. }
  893. // Where appends a list predicates to the MessageRecordsUpdate builder.
  894. func (mruo *MessageRecordsUpdateOne) Where(ps ...predicate.MessageRecords) *MessageRecordsUpdateOne {
  895. mruo.mutation.Where(ps...)
  896. return mruo
  897. }
  898. // Select allows selecting one or more fields (columns) of the returned entity.
  899. // The default is selecting all fields defined in the entity schema.
  900. func (mruo *MessageRecordsUpdateOne) Select(field string, fields ...string) *MessageRecordsUpdateOne {
  901. mruo.fields = append([]string{field}, fields...)
  902. return mruo
  903. }
  904. // Save executes the query and returns the updated MessageRecords entity.
  905. func (mruo *MessageRecordsUpdateOne) Save(ctx context.Context) (*MessageRecords, error) {
  906. if err := mruo.defaults(); err != nil {
  907. return nil, err
  908. }
  909. return withHooks(ctx, mruo.sqlSave, mruo.mutation, mruo.hooks)
  910. }
  911. // SaveX is like Save, but panics if an error occurs.
  912. func (mruo *MessageRecordsUpdateOne) SaveX(ctx context.Context) *MessageRecords {
  913. node, err := mruo.Save(ctx)
  914. if err != nil {
  915. panic(err)
  916. }
  917. return node
  918. }
  919. // Exec executes the query on the entity.
  920. func (mruo *MessageRecordsUpdateOne) Exec(ctx context.Context) error {
  921. _, err := mruo.Save(ctx)
  922. return err
  923. }
  924. // ExecX is like Exec, but panics if an error occurs.
  925. func (mruo *MessageRecordsUpdateOne) ExecX(ctx context.Context) {
  926. if err := mruo.Exec(ctx); err != nil {
  927. panic(err)
  928. }
  929. }
  930. // defaults sets the default values of the builder before save.
  931. func (mruo *MessageRecordsUpdateOne) defaults() error {
  932. if _, ok := mruo.mutation.UpdatedAt(); !ok {
  933. if messagerecords.UpdateDefaultUpdatedAt == nil {
  934. return fmt.Errorf("ent: uninitialized messagerecords.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
  935. }
  936. v := messagerecords.UpdateDefaultUpdatedAt()
  937. mruo.mutation.SetUpdatedAt(v)
  938. }
  939. return nil
  940. }
  941. func (mruo *MessageRecordsUpdateOne) sqlSave(ctx context.Context) (_node *MessageRecords, err error) {
  942. _spec := sqlgraph.NewUpdateSpec(messagerecords.Table, messagerecords.Columns, sqlgraph.NewFieldSpec(messagerecords.FieldID, field.TypeUint64))
  943. id, ok := mruo.mutation.ID()
  944. if !ok {
  945. return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "MessageRecords.id" for update`)}
  946. }
  947. _spec.Node.ID.Value = id
  948. if fields := mruo.fields; len(fields) > 0 {
  949. _spec.Node.Columns = make([]string, 0, len(fields))
  950. _spec.Node.Columns = append(_spec.Node.Columns, messagerecords.FieldID)
  951. for _, f := range fields {
  952. if !messagerecords.ValidColumn(f) {
  953. return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
  954. }
  955. if f != messagerecords.FieldID {
  956. _spec.Node.Columns = append(_spec.Node.Columns, f)
  957. }
  958. }
  959. }
  960. if ps := mruo.mutation.predicates; len(ps) > 0 {
  961. _spec.Predicate = func(selector *sql.Selector) {
  962. for i := range ps {
  963. ps[i](selector)
  964. }
  965. }
  966. }
  967. if value, ok := mruo.mutation.UpdatedAt(); ok {
  968. _spec.SetField(messagerecords.FieldUpdatedAt, field.TypeTime, value)
  969. }
  970. if value, ok := mruo.mutation.Status(); ok {
  971. _spec.SetField(messagerecords.FieldStatus, field.TypeUint8, value)
  972. }
  973. if value, ok := mruo.mutation.AddedStatus(); ok {
  974. _spec.AddField(messagerecords.FieldStatus, field.TypeUint8, value)
  975. }
  976. if mruo.mutation.StatusCleared() {
  977. _spec.ClearField(messagerecords.FieldStatus, field.TypeUint8)
  978. }
  979. if value, ok := mruo.mutation.DeletedAt(); ok {
  980. _spec.SetField(messagerecords.FieldDeletedAt, field.TypeTime, value)
  981. }
  982. if mruo.mutation.DeletedAtCleared() {
  983. _spec.ClearField(messagerecords.FieldDeletedAt, field.TypeTime)
  984. }
  985. if value, ok := mruo.mutation.BotWxid(); ok {
  986. _spec.SetField(messagerecords.FieldBotWxid, field.TypeString, value)
  987. }
  988. if value, ok := mruo.mutation.ContactType(); ok {
  989. _spec.SetField(messagerecords.FieldContactType, field.TypeInt, value)
  990. }
  991. if value, ok := mruo.mutation.AddedContactType(); ok {
  992. _spec.AddField(messagerecords.FieldContactType, field.TypeInt, value)
  993. }
  994. if value, ok := mruo.mutation.ContactWxid(); ok {
  995. _spec.SetField(messagerecords.FieldContactWxid, field.TypeString, value)
  996. }
  997. if value, ok := mruo.mutation.ContentType(); ok {
  998. _spec.SetField(messagerecords.FieldContentType, field.TypeInt, value)
  999. }
  1000. if value, ok := mruo.mutation.AddedContentType(); ok {
  1001. _spec.AddField(messagerecords.FieldContentType, field.TypeInt, value)
  1002. }
  1003. if value, ok := mruo.mutation.Content(); ok {
  1004. _spec.SetField(messagerecords.FieldContent, field.TypeString, value)
  1005. }
  1006. if value, ok := mruo.mutation.Meta(); ok {
  1007. _spec.SetField(messagerecords.FieldMeta, field.TypeJSON, value)
  1008. }
  1009. if mruo.mutation.MetaCleared() {
  1010. _spec.ClearField(messagerecords.FieldMeta, field.TypeJSON)
  1011. }
  1012. if value, ok := mruo.mutation.ErrorDetail(); ok {
  1013. _spec.SetField(messagerecords.FieldErrorDetail, field.TypeString, value)
  1014. }
  1015. if value, ok := mruo.mutation.SendTime(); ok {
  1016. _spec.SetField(messagerecords.FieldSendTime, field.TypeTime, value)
  1017. }
  1018. if mruo.mutation.SendTimeCleared() {
  1019. _spec.ClearField(messagerecords.FieldSendTime, field.TypeTime)
  1020. }
  1021. if value, ok := mruo.mutation.SourceType(); ok {
  1022. _spec.SetField(messagerecords.FieldSourceType, field.TypeInt, value)
  1023. }
  1024. if value, ok := mruo.mutation.AddedSourceType(); ok {
  1025. _spec.AddField(messagerecords.FieldSourceType, field.TypeInt, value)
  1026. }
  1027. if value, ok := mruo.mutation.OrganizationID(); ok {
  1028. _spec.SetField(messagerecords.FieldOrganizationID, field.TypeUint64, value)
  1029. }
  1030. if value, ok := mruo.mutation.AddedOrganizationID(); ok {
  1031. _spec.AddField(messagerecords.FieldOrganizationID, field.TypeUint64, value)
  1032. }
  1033. if mruo.mutation.OrganizationIDCleared() {
  1034. _spec.ClearField(messagerecords.FieldOrganizationID, field.TypeUint64)
  1035. }
  1036. if mruo.mutation.SopStageCleared() {
  1037. edge := &sqlgraph.EdgeSpec{
  1038. Rel: sqlgraph.M2O,
  1039. Inverse: true,
  1040. Table: messagerecords.SopStageTable,
  1041. Columns: []string{messagerecords.SopStageColumn},
  1042. Bidi: false,
  1043. Target: &sqlgraph.EdgeTarget{
  1044. IDSpec: sqlgraph.NewFieldSpec(sopstage.FieldID, field.TypeUint64),
  1045. },
  1046. }
  1047. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  1048. }
  1049. if nodes := mruo.mutation.SopStageIDs(); len(nodes) > 0 {
  1050. edge := &sqlgraph.EdgeSpec{
  1051. Rel: sqlgraph.M2O,
  1052. Inverse: true,
  1053. Table: messagerecords.SopStageTable,
  1054. Columns: []string{messagerecords.SopStageColumn},
  1055. Bidi: false,
  1056. Target: &sqlgraph.EdgeTarget{
  1057. IDSpec: sqlgraph.NewFieldSpec(sopstage.FieldID, field.TypeUint64),
  1058. },
  1059. }
  1060. for _, k := range nodes {
  1061. edge.Target.Nodes = append(edge.Target.Nodes, k)
  1062. }
  1063. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  1064. }
  1065. if mruo.mutation.SopNodeCleared() {
  1066. edge := &sqlgraph.EdgeSpec{
  1067. Rel: sqlgraph.M2O,
  1068. Inverse: true,
  1069. Table: messagerecords.SopNodeTable,
  1070. Columns: []string{messagerecords.SopNodeColumn},
  1071. Bidi: false,
  1072. Target: &sqlgraph.EdgeTarget{
  1073. IDSpec: sqlgraph.NewFieldSpec(sopnode.FieldID, field.TypeUint64),
  1074. },
  1075. }
  1076. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  1077. }
  1078. if nodes := mruo.mutation.SopNodeIDs(); len(nodes) > 0 {
  1079. edge := &sqlgraph.EdgeSpec{
  1080. Rel: sqlgraph.M2O,
  1081. Inverse: true,
  1082. Table: messagerecords.SopNodeTable,
  1083. Columns: []string{messagerecords.SopNodeColumn},
  1084. Bidi: false,
  1085. Target: &sqlgraph.EdgeTarget{
  1086. IDSpec: sqlgraph.NewFieldSpec(sopnode.FieldID, field.TypeUint64),
  1087. },
  1088. }
  1089. for _, k := range nodes {
  1090. edge.Target.Nodes = append(edge.Target.Nodes, k)
  1091. }
  1092. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  1093. }
  1094. if mruo.mutation.MessageContactCleared() {
  1095. edge := &sqlgraph.EdgeSpec{
  1096. Rel: sqlgraph.M2O,
  1097. Inverse: true,
  1098. Table: messagerecords.MessageContactTable,
  1099. Columns: []string{messagerecords.MessageContactColumn},
  1100. Bidi: false,
  1101. Target: &sqlgraph.EdgeTarget{
  1102. IDSpec: sqlgraph.NewFieldSpec(contact.FieldID, field.TypeUint64),
  1103. },
  1104. }
  1105. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  1106. }
  1107. if nodes := mruo.mutation.MessageContactIDs(); len(nodes) > 0 {
  1108. edge := &sqlgraph.EdgeSpec{
  1109. Rel: sqlgraph.M2O,
  1110. Inverse: true,
  1111. Table: messagerecords.MessageContactTable,
  1112. Columns: []string{messagerecords.MessageContactColumn},
  1113. Bidi: false,
  1114. Target: &sqlgraph.EdgeTarget{
  1115. IDSpec: sqlgraph.NewFieldSpec(contact.FieldID, field.TypeUint64),
  1116. },
  1117. }
  1118. for _, k := range nodes {
  1119. edge.Target.Nodes = append(edge.Target.Nodes, k)
  1120. }
  1121. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  1122. }
  1123. _node = &MessageRecords{config: mruo.config}
  1124. _spec.Assign = _node.assignValues
  1125. _spec.ScanValues = _node.scanValues
  1126. if err = sqlgraph.UpdateNode(ctx, mruo.driver, _spec); err != nil {
  1127. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  1128. err = &NotFoundError{messagerecords.Label}
  1129. } else if sqlgraph.IsConstraintError(err) {
  1130. err = &ConstraintError{msg: err.Error(), wrap: err}
  1131. }
  1132. return nil, err
  1133. }
  1134. mruo.mutation.done = true
  1135. return _node, nil
  1136. }