messagerecords_update.go 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198
  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. // SetSopStageID sets the "sop_stage" edge to the SopStage entity by ID.
  262. func (mru *MessageRecordsUpdate) SetSopStageID(id uint64) *MessageRecordsUpdate {
  263. mru.mutation.SetSopStageID(id)
  264. return mru
  265. }
  266. // SetNillableSopStageID sets the "sop_stage" edge to the SopStage entity by ID if the given value is not nil.
  267. func (mru *MessageRecordsUpdate) SetNillableSopStageID(id *uint64) *MessageRecordsUpdate {
  268. if id != nil {
  269. mru = mru.SetSopStageID(*id)
  270. }
  271. return mru
  272. }
  273. // SetSopStage sets the "sop_stage" edge to the SopStage entity.
  274. func (mru *MessageRecordsUpdate) SetSopStage(s *SopStage) *MessageRecordsUpdate {
  275. return mru.SetSopStageID(s.ID)
  276. }
  277. // SetSopNodeID sets the "sop_node" edge to the SopNode entity by ID.
  278. func (mru *MessageRecordsUpdate) SetSopNodeID(id uint64) *MessageRecordsUpdate {
  279. mru.mutation.SetSopNodeID(id)
  280. return mru
  281. }
  282. // SetNillableSopNodeID sets the "sop_node" edge to the SopNode entity by ID if the given value is not nil.
  283. func (mru *MessageRecordsUpdate) SetNillableSopNodeID(id *uint64) *MessageRecordsUpdate {
  284. if id != nil {
  285. mru = mru.SetSopNodeID(*id)
  286. }
  287. return mru
  288. }
  289. // SetSopNode sets the "sop_node" edge to the SopNode entity.
  290. func (mru *MessageRecordsUpdate) SetSopNode(s *SopNode) *MessageRecordsUpdate {
  291. return mru.SetSopNodeID(s.ID)
  292. }
  293. // SetMessageContactID sets the "message_contact" edge to the Contact entity by ID.
  294. func (mru *MessageRecordsUpdate) SetMessageContactID(id uint64) *MessageRecordsUpdate {
  295. mru.mutation.SetMessageContactID(id)
  296. return mru
  297. }
  298. // SetNillableMessageContactID sets the "message_contact" edge to the Contact entity by ID if the given value is not nil.
  299. func (mru *MessageRecordsUpdate) SetNillableMessageContactID(id *uint64) *MessageRecordsUpdate {
  300. if id != nil {
  301. mru = mru.SetMessageContactID(*id)
  302. }
  303. return mru
  304. }
  305. // SetMessageContact sets the "message_contact" edge to the Contact entity.
  306. func (mru *MessageRecordsUpdate) SetMessageContact(c *Contact) *MessageRecordsUpdate {
  307. return mru.SetMessageContactID(c.ID)
  308. }
  309. // Mutation returns the MessageRecordsMutation object of the builder.
  310. func (mru *MessageRecordsUpdate) Mutation() *MessageRecordsMutation {
  311. return mru.mutation
  312. }
  313. // ClearSopStage clears the "sop_stage" edge to the SopStage entity.
  314. func (mru *MessageRecordsUpdate) ClearSopStage() *MessageRecordsUpdate {
  315. mru.mutation.ClearSopStage()
  316. return mru
  317. }
  318. // ClearSopNode clears the "sop_node" edge to the SopNode entity.
  319. func (mru *MessageRecordsUpdate) ClearSopNode() *MessageRecordsUpdate {
  320. mru.mutation.ClearSopNode()
  321. return mru
  322. }
  323. // ClearMessageContact clears the "message_contact" edge to the Contact entity.
  324. func (mru *MessageRecordsUpdate) ClearMessageContact() *MessageRecordsUpdate {
  325. mru.mutation.ClearMessageContact()
  326. return mru
  327. }
  328. // Save executes the query and returns the number of nodes affected by the update operation.
  329. func (mru *MessageRecordsUpdate) Save(ctx context.Context) (int, error) {
  330. if err := mru.defaults(); err != nil {
  331. return 0, err
  332. }
  333. return withHooks(ctx, mru.sqlSave, mru.mutation, mru.hooks)
  334. }
  335. // SaveX is like Save, but panics if an error occurs.
  336. func (mru *MessageRecordsUpdate) SaveX(ctx context.Context) int {
  337. affected, err := mru.Save(ctx)
  338. if err != nil {
  339. panic(err)
  340. }
  341. return affected
  342. }
  343. // Exec executes the query.
  344. func (mru *MessageRecordsUpdate) Exec(ctx context.Context) error {
  345. _, err := mru.Save(ctx)
  346. return err
  347. }
  348. // ExecX is like Exec, but panics if an error occurs.
  349. func (mru *MessageRecordsUpdate) ExecX(ctx context.Context) {
  350. if err := mru.Exec(ctx); err != nil {
  351. panic(err)
  352. }
  353. }
  354. // defaults sets the default values of the builder before save.
  355. func (mru *MessageRecordsUpdate) defaults() error {
  356. if _, ok := mru.mutation.UpdatedAt(); !ok {
  357. if messagerecords.UpdateDefaultUpdatedAt == nil {
  358. return fmt.Errorf("ent: uninitialized messagerecords.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
  359. }
  360. v := messagerecords.UpdateDefaultUpdatedAt()
  361. mru.mutation.SetUpdatedAt(v)
  362. }
  363. return nil
  364. }
  365. func (mru *MessageRecordsUpdate) sqlSave(ctx context.Context) (n int, err error) {
  366. _spec := sqlgraph.NewUpdateSpec(messagerecords.Table, messagerecords.Columns, sqlgraph.NewFieldSpec(messagerecords.FieldID, field.TypeUint64))
  367. if ps := mru.mutation.predicates; len(ps) > 0 {
  368. _spec.Predicate = func(selector *sql.Selector) {
  369. for i := range ps {
  370. ps[i](selector)
  371. }
  372. }
  373. }
  374. if value, ok := mru.mutation.UpdatedAt(); ok {
  375. _spec.SetField(messagerecords.FieldUpdatedAt, field.TypeTime, value)
  376. }
  377. if value, ok := mru.mutation.Status(); ok {
  378. _spec.SetField(messagerecords.FieldStatus, field.TypeUint8, value)
  379. }
  380. if value, ok := mru.mutation.AddedStatus(); ok {
  381. _spec.AddField(messagerecords.FieldStatus, field.TypeUint8, value)
  382. }
  383. if mru.mutation.StatusCleared() {
  384. _spec.ClearField(messagerecords.FieldStatus, field.TypeUint8)
  385. }
  386. if value, ok := mru.mutation.DeletedAt(); ok {
  387. _spec.SetField(messagerecords.FieldDeletedAt, field.TypeTime, value)
  388. }
  389. if mru.mutation.DeletedAtCleared() {
  390. _spec.ClearField(messagerecords.FieldDeletedAt, field.TypeTime)
  391. }
  392. if value, ok := mru.mutation.BotWxid(); ok {
  393. _spec.SetField(messagerecords.FieldBotWxid, field.TypeString, value)
  394. }
  395. if value, ok := mru.mutation.ContactType(); ok {
  396. _spec.SetField(messagerecords.FieldContactType, field.TypeInt, value)
  397. }
  398. if value, ok := mru.mutation.AddedContactType(); ok {
  399. _spec.AddField(messagerecords.FieldContactType, field.TypeInt, value)
  400. }
  401. if value, ok := mru.mutation.ContactWxid(); ok {
  402. _spec.SetField(messagerecords.FieldContactWxid, field.TypeString, value)
  403. }
  404. if value, ok := mru.mutation.ContentType(); ok {
  405. _spec.SetField(messagerecords.FieldContentType, field.TypeInt, value)
  406. }
  407. if value, ok := mru.mutation.AddedContentType(); ok {
  408. _spec.AddField(messagerecords.FieldContentType, field.TypeInt, value)
  409. }
  410. if value, ok := mru.mutation.Content(); ok {
  411. _spec.SetField(messagerecords.FieldContent, field.TypeString, value)
  412. }
  413. if value, ok := mru.mutation.Meta(); ok {
  414. _spec.SetField(messagerecords.FieldMeta, field.TypeJSON, value)
  415. }
  416. if mru.mutation.MetaCleared() {
  417. _spec.ClearField(messagerecords.FieldMeta, field.TypeJSON)
  418. }
  419. if value, ok := mru.mutation.ErrorDetail(); ok {
  420. _spec.SetField(messagerecords.FieldErrorDetail, field.TypeString, value)
  421. }
  422. if value, ok := mru.mutation.SendTime(); ok {
  423. _spec.SetField(messagerecords.FieldSendTime, field.TypeTime, value)
  424. }
  425. if mru.mutation.SendTimeCleared() {
  426. _spec.ClearField(messagerecords.FieldSendTime, field.TypeTime)
  427. }
  428. if value, ok := mru.mutation.SourceType(); ok {
  429. _spec.SetField(messagerecords.FieldSourceType, field.TypeInt, value)
  430. }
  431. if value, ok := mru.mutation.AddedSourceType(); ok {
  432. _spec.AddField(messagerecords.FieldSourceType, field.TypeInt, value)
  433. }
  434. if mru.mutation.SopStageCleared() {
  435. edge := &sqlgraph.EdgeSpec{
  436. Rel: sqlgraph.M2O,
  437. Inverse: true,
  438. Table: messagerecords.SopStageTable,
  439. Columns: []string{messagerecords.SopStageColumn},
  440. Bidi: false,
  441. Target: &sqlgraph.EdgeTarget{
  442. IDSpec: sqlgraph.NewFieldSpec(sopstage.FieldID, field.TypeUint64),
  443. },
  444. }
  445. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  446. }
  447. if nodes := mru.mutation.SopStageIDs(); len(nodes) > 0 {
  448. edge := &sqlgraph.EdgeSpec{
  449. Rel: sqlgraph.M2O,
  450. Inverse: true,
  451. Table: messagerecords.SopStageTable,
  452. Columns: []string{messagerecords.SopStageColumn},
  453. Bidi: false,
  454. Target: &sqlgraph.EdgeTarget{
  455. IDSpec: sqlgraph.NewFieldSpec(sopstage.FieldID, field.TypeUint64),
  456. },
  457. }
  458. for _, k := range nodes {
  459. edge.Target.Nodes = append(edge.Target.Nodes, k)
  460. }
  461. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  462. }
  463. if mru.mutation.SopNodeCleared() {
  464. edge := &sqlgraph.EdgeSpec{
  465. Rel: sqlgraph.M2O,
  466. Inverse: true,
  467. Table: messagerecords.SopNodeTable,
  468. Columns: []string{messagerecords.SopNodeColumn},
  469. Bidi: false,
  470. Target: &sqlgraph.EdgeTarget{
  471. IDSpec: sqlgraph.NewFieldSpec(sopnode.FieldID, field.TypeUint64),
  472. },
  473. }
  474. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  475. }
  476. if nodes := mru.mutation.SopNodeIDs(); len(nodes) > 0 {
  477. edge := &sqlgraph.EdgeSpec{
  478. Rel: sqlgraph.M2O,
  479. Inverse: true,
  480. Table: messagerecords.SopNodeTable,
  481. Columns: []string{messagerecords.SopNodeColumn},
  482. Bidi: false,
  483. Target: &sqlgraph.EdgeTarget{
  484. IDSpec: sqlgraph.NewFieldSpec(sopnode.FieldID, field.TypeUint64),
  485. },
  486. }
  487. for _, k := range nodes {
  488. edge.Target.Nodes = append(edge.Target.Nodes, k)
  489. }
  490. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  491. }
  492. if mru.mutation.MessageContactCleared() {
  493. edge := &sqlgraph.EdgeSpec{
  494. Rel: sqlgraph.M2O,
  495. Inverse: true,
  496. Table: messagerecords.MessageContactTable,
  497. Columns: []string{messagerecords.MessageContactColumn},
  498. Bidi: false,
  499. Target: &sqlgraph.EdgeTarget{
  500. IDSpec: sqlgraph.NewFieldSpec(contact.FieldID, field.TypeUint64),
  501. },
  502. }
  503. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  504. }
  505. if nodes := mru.mutation.MessageContactIDs(); len(nodes) > 0 {
  506. edge := &sqlgraph.EdgeSpec{
  507. Rel: sqlgraph.M2O,
  508. Inverse: true,
  509. Table: messagerecords.MessageContactTable,
  510. Columns: []string{messagerecords.MessageContactColumn},
  511. Bidi: false,
  512. Target: &sqlgraph.EdgeTarget{
  513. IDSpec: sqlgraph.NewFieldSpec(contact.FieldID, field.TypeUint64),
  514. },
  515. }
  516. for _, k := range nodes {
  517. edge.Target.Nodes = append(edge.Target.Nodes, k)
  518. }
  519. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  520. }
  521. if n, err = sqlgraph.UpdateNodes(ctx, mru.driver, _spec); err != nil {
  522. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  523. err = &NotFoundError{messagerecords.Label}
  524. } else if sqlgraph.IsConstraintError(err) {
  525. err = &ConstraintError{msg: err.Error(), wrap: err}
  526. }
  527. return 0, err
  528. }
  529. mru.mutation.done = true
  530. return n, nil
  531. }
  532. // MessageRecordsUpdateOne is the builder for updating a single MessageRecords entity.
  533. type MessageRecordsUpdateOne struct {
  534. config
  535. fields []string
  536. hooks []Hook
  537. mutation *MessageRecordsMutation
  538. }
  539. // SetUpdatedAt sets the "updated_at" field.
  540. func (mruo *MessageRecordsUpdateOne) SetUpdatedAt(t time.Time) *MessageRecordsUpdateOne {
  541. mruo.mutation.SetUpdatedAt(t)
  542. return mruo
  543. }
  544. // SetStatus sets the "status" field.
  545. func (mruo *MessageRecordsUpdateOne) SetStatus(u uint8) *MessageRecordsUpdateOne {
  546. mruo.mutation.ResetStatus()
  547. mruo.mutation.SetStatus(u)
  548. return mruo
  549. }
  550. // SetNillableStatus sets the "status" field if the given value is not nil.
  551. func (mruo *MessageRecordsUpdateOne) SetNillableStatus(u *uint8) *MessageRecordsUpdateOne {
  552. if u != nil {
  553. mruo.SetStatus(*u)
  554. }
  555. return mruo
  556. }
  557. // AddStatus adds u to the "status" field.
  558. func (mruo *MessageRecordsUpdateOne) AddStatus(u int8) *MessageRecordsUpdateOne {
  559. mruo.mutation.AddStatus(u)
  560. return mruo
  561. }
  562. // ClearStatus clears the value of the "status" field.
  563. func (mruo *MessageRecordsUpdateOne) ClearStatus() *MessageRecordsUpdateOne {
  564. mruo.mutation.ClearStatus()
  565. return mruo
  566. }
  567. // SetDeletedAt sets the "deleted_at" field.
  568. func (mruo *MessageRecordsUpdateOne) SetDeletedAt(t time.Time) *MessageRecordsUpdateOne {
  569. mruo.mutation.SetDeletedAt(t)
  570. return mruo
  571. }
  572. // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
  573. func (mruo *MessageRecordsUpdateOne) SetNillableDeletedAt(t *time.Time) *MessageRecordsUpdateOne {
  574. if t != nil {
  575. mruo.SetDeletedAt(*t)
  576. }
  577. return mruo
  578. }
  579. // ClearDeletedAt clears the value of the "deleted_at" field.
  580. func (mruo *MessageRecordsUpdateOne) ClearDeletedAt() *MessageRecordsUpdateOne {
  581. mruo.mutation.ClearDeletedAt()
  582. return mruo
  583. }
  584. // SetBotWxid sets the "bot_wxid" field.
  585. func (mruo *MessageRecordsUpdateOne) SetBotWxid(s string) *MessageRecordsUpdateOne {
  586. mruo.mutation.SetBotWxid(s)
  587. return mruo
  588. }
  589. // SetNillableBotWxid sets the "bot_wxid" field if the given value is not nil.
  590. func (mruo *MessageRecordsUpdateOne) SetNillableBotWxid(s *string) *MessageRecordsUpdateOne {
  591. if s != nil {
  592. mruo.SetBotWxid(*s)
  593. }
  594. return mruo
  595. }
  596. // SetContactID sets the "contact_id" field.
  597. func (mruo *MessageRecordsUpdateOne) SetContactID(u uint64) *MessageRecordsUpdateOne {
  598. mruo.mutation.SetContactID(u)
  599. return mruo
  600. }
  601. // SetNillableContactID sets the "contact_id" field if the given value is not nil.
  602. func (mruo *MessageRecordsUpdateOne) SetNillableContactID(u *uint64) *MessageRecordsUpdateOne {
  603. if u != nil {
  604. mruo.SetContactID(*u)
  605. }
  606. return mruo
  607. }
  608. // ClearContactID clears the value of the "contact_id" field.
  609. func (mruo *MessageRecordsUpdateOne) ClearContactID() *MessageRecordsUpdateOne {
  610. mruo.mutation.ClearContactID()
  611. return mruo
  612. }
  613. // SetContactType sets the "contact_type" field.
  614. func (mruo *MessageRecordsUpdateOne) SetContactType(i int) *MessageRecordsUpdateOne {
  615. mruo.mutation.ResetContactType()
  616. mruo.mutation.SetContactType(i)
  617. return mruo
  618. }
  619. // SetNillableContactType sets the "contact_type" field if the given value is not nil.
  620. func (mruo *MessageRecordsUpdateOne) SetNillableContactType(i *int) *MessageRecordsUpdateOne {
  621. if i != nil {
  622. mruo.SetContactType(*i)
  623. }
  624. return mruo
  625. }
  626. // AddContactType adds i to the "contact_type" field.
  627. func (mruo *MessageRecordsUpdateOne) AddContactType(i int) *MessageRecordsUpdateOne {
  628. mruo.mutation.AddContactType(i)
  629. return mruo
  630. }
  631. // SetContactWxid sets the "contact_wxid" field.
  632. func (mruo *MessageRecordsUpdateOne) SetContactWxid(s string) *MessageRecordsUpdateOne {
  633. mruo.mutation.SetContactWxid(s)
  634. return mruo
  635. }
  636. // SetNillableContactWxid sets the "contact_wxid" field if the given value is not nil.
  637. func (mruo *MessageRecordsUpdateOne) SetNillableContactWxid(s *string) *MessageRecordsUpdateOne {
  638. if s != nil {
  639. mruo.SetContactWxid(*s)
  640. }
  641. return mruo
  642. }
  643. // SetContentType sets the "content_type" field.
  644. func (mruo *MessageRecordsUpdateOne) SetContentType(i int) *MessageRecordsUpdateOne {
  645. mruo.mutation.ResetContentType()
  646. mruo.mutation.SetContentType(i)
  647. return mruo
  648. }
  649. // SetNillableContentType sets the "content_type" field if the given value is not nil.
  650. func (mruo *MessageRecordsUpdateOne) SetNillableContentType(i *int) *MessageRecordsUpdateOne {
  651. if i != nil {
  652. mruo.SetContentType(*i)
  653. }
  654. return mruo
  655. }
  656. // AddContentType adds i to the "content_type" field.
  657. func (mruo *MessageRecordsUpdateOne) AddContentType(i int) *MessageRecordsUpdateOne {
  658. mruo.mutation.AddContentType(i)
  659. return mruo
  660. }
  661. // SetContent sets the "content" field.
  662. func (mruo *MessageRecordsUpdateOne) SetContent(s string) *MessageRecordsUpdateOne {
  663. mruo.mutation.SetContent(s)
  664. return mruo
  665. }
  666. // SetNillableContent sets the "content" field if the given value is not nil.
  667. func (mruo *MessageRecordsUpdateOne) SetNillableContent(s *string) *MessageRecordsUpdateOne {
  668. if s != nil {
  669. mruo.SetContent(*s)
  670. }
  671. return mruo
  672. }
  673. // SetMeta sets the "meta" field.
  674. func (mruo *MessageRecordsUpdateOne) SetMeta(ct custom_types.Meta) *MessageRecordsUpdateOne {
  675. mruo.mutation.SetMeta(ct)
  676. return mruo
  677. }
  678. // SetNillableMeta sets the "meta" field if the given value is not nil.
  679. func (mruo *MessageRecordsUpdateOne) SetNillableMeta(ct *custom_types.Meta) *MessageRecordsUpdateOne {
  680. if ct != nil {
  681. mruo.SetMeta(*ct)
  682. }
  683. return mruo
  684. }
  685. // ClearMeta clears the value of the "meta" field.
  686. func (mruo *MessageRecordsUpdateOne) ClearMeta() *MessageRecordsUpdateOne {
  687. mruo.mutation.ClearMeta()
  688. return mruo
  689. }
  690. // SetErrorDetail sets the "error_detail" field.
  691. func (mruo *MessageRecordsUpdateOne) SetErrorDetail(s string) *MessageRecordsUpdateOne {
  692. mruo.mutation.SetErrorDetail(s)
  693. return mruo
  694. }
  695. // SetNillableErrorDetail sets the "error_detail" field if the given value is not nil.
  696. func (mruo *MessageRecordsUpdateOne) SetNillableErrorDetail(s *string) *MessageRecordsUpdateOne {
  697. if s != nil {
  698. mruo.SetErrorDetail(*s)
  699. }
  700. return mruo
  701. }
  702. // SetSendTime sets the "send_time" field.
  703. func (mruo *MessageRecordsUpdateOne) SetSendTime(t time.Time) *MessageRecordsUpdateOne {
  704. mruo.mutation.SetSendTime(t)
  705. return mruo
  706. }
  707. // SetNillableSendTime sets the "send_time" field if the given value is not nil.
  708. func (mruo *MessageRecordsUpdateOne) SetNillableSendTime(t *time.Time) *MessageRecordsUpdateOne {
  709. if t != nil {
  710. mruo.SetSendTime(*t)
  711. }
  712. return mruo
  713. }
  714. // ClearSendTime clears the value of the "send_time" field.
  715. func (mruo *MessageRecordsUpdateOne) ClearSendTime() *MessageRecordsUpdateOne {
  716. mruo.mutation.ClearSendTime()
  717. return mruo
  718. }
  719. // SetSourceType sets the "source_type" field.
  720. func (mruo *MessageRecordsUpdateOne) SetSourceType(i int) *MessageRecordsUpdateOne {
  721. mruo.mutation.ResetSourceType()
  722. mruo.mutation.SetSourceType(i)
  723. return mruo
  724. }
  725. // SetNillableSourceType sets the "source_type" field if the given value is not nil.
  726. func (mruo *MessageRecordsUpdateOne) SetNillableSourceType(i *int) *MessageRecordsUpdateOne {
  727. if i != nil {
  728. mruo.SetSourceType(*i)
  729. }
  730. return mruo
  731. }
  732. // AddSourceType adds i to the "source_type" field.
  733. func (mruo *MessageRecordsUpdateOne) AddSourceType(i int) *MessageRecordsUpdateOne {
  734. mruo.mutation.AddSourceType(i)
  735. return mruo
  736. }
  737. // SetSourceID sets the "source_id" field.
  738. func (mruo *MessageRecordsUpdateOne) SetSourceID(u uint64) *MessageRecordsUpdateOne {
  739. mruo.mutation.SetSourceID(u)
  740. return mruo
  741. }
  742. // SetNillableSourceID sets the "source_id" field if the given value is not nil.
  743. func (mruo *MessageRecordsUpdateOne) SetNillableSourceID(u *uint64) *MessageRecordsUpdateOne {
  744. if u != nil {
  745. mruo.SetSourceID(*u)
  746. }
  747. return mruo
  748. }
  749. // ClearSourceID clears the value of the "source_id" field.
  750. func (mruo *MessageRecordsUpdateOne) ClearSourceID() *MessageRecordsUpdateOne {
  751. mruo.mutation.ClearSourceID()
  752. return mruo
  753. }
  754. // SetSubSourceID sets the "sub_source_id" field.
  755. func (mruo *MessageRecordsUpdateOne) SetSubSourceID(u uint64) *MessageRecordsUpdateOne {
  756. mruo.mutation.SetSubSourceID(u)
  757. return mruo
  758. }
  759. // SetNillableSubSourceID sets the "sub_source_id" field if the given value is not nil.
  760. func (mruo *MessageRecordsUpdateOne) SetNillableSubSourceID(u *uint64) *MessageRecordsUpdateOne {
  761. if u != nil {
  762. mruo.SetSubSourceID(*u)
  763. }
  764. return mruo
  765. }
  766. // ClearSubSourceID clears the value of the "sub_source_id" field.
  767. func (mruo *MessageRecordsUpdateOne) ClearSubSourceID() *MessageRecordsUpdateOne {
  768. mruo.mutation.ClearSubSourceID()
  769. return mruo
  770. }
  771. // SetSopStageID sets the "sop_stage" edge to the SopStage entity by ID.
  772. func (mruo *MessageRecordsUpdateOne) SetSopStageID(id uint64) *MessageRecordsUpdateOne {
  773. mruo.mutation.SetSopStageID(id)
  774. return mruo
  775. }
  776. // SetNillableSopStageID sets the "sop_stage" edge to the SopStage entity by ID if the given value is not nil.
  777. func (mruo *MessageRecordsUpdateOne) SetNillableSopStageID(id *uint64) *MessageRecordsUpdateOne {
  778. if id != nil {
  779. mruo = mruo.SetSopStageID(*id)
  780. }
  781. return mruo
  782. }
  783. // SetSopStage sets the "sop_stage" edge to the SopStage entity.
  784. func (mruo *MessageRecordsUpdateOne) SetSopStage(s *SopStage) *MessageRecordsUpdateOne {
  785. return mruo.SetSopStageID(s.ID)
  786. }
  787. // SetSopNodeID sets the "sop_node" edge to the SopNode entity by ID.
  788. func (mruo *MessageRecordsUpdateOne) SetSopNodeID(id uint64) *MessageRecordsUpdateOne {
  789. mruo.mutation.SetSopNodeID(id)
  790. return mruo
  791. }
  792. // SetNillableSopNodeID sets the "sop_node" edge to the SopNode entity by ID if the given value is not nil.
  793. func (mruo *MessageRecordsUpdateOne) SetNillableSopNodeID(id *uint64) *MessageRecordsUpdateOne {
  794. if id != nil {
  795. mruo = mruo.SetSopNodeID(*id)
  796. }
  797. return mruo
  798. }
  799. // SetSopNode sets the "sop_node" edge to the SopNode entity.
  800. func (mruo *MessageRecordsUpdateOne) SetSopNode(s *SopNode) *MessageRecordsUpdateOne {
  801. return mruo.SetSopNodeID(s.ID)
  802. }
  803. // SetMessageContactID sets the "message_contact" edge to the Contact entity by ID.
  804. func (mruo *MessageRecordsUpdateOne) SetMessageContactID(id uint64) *MessageRecordsUpdateOne {
  805. mruo.mutation.SetMessageContactID(id)
  806. return mruo
  807. }
  808. // SetNillableMessageContactID sets the "message_contact" edge to the Contact entity by ID if the given value is not nil.
  809. func (mruo *MessageRecordsUpdateOne) SetNillableMessageContactID(id *uint64) *MessageRecordsUpdateOne {
  810. if id != nil {
  811. mruo = mruo.SetMessageContactID(*id)
  812. }
  813. return mruo
  814. }
  815. // SetMessageContact sets the "message_contact" edge to the Contact entity.
  816. func (mruo *MessageRecordsUpdateOne) SetMessageContact(c *Contact) *MessageRecordsUpdateOne {
  817. return mruo.SetMessageContactID(c.ID)
  818. }
  819. // Mutation returns the MessageRecordsMutation object of the builder.
  820. func (mruo *MessageRecordsUpdateOne) Mutation() *MessageRecordsMutation {
  821. return mruo.mutation
  822. }
  823. // ClearSopStage clears the "sop_stage" edge to the SopStage entity.
  824. func (mruo *MessageRecordsUpdateOne) ClearSopStage() *MessageRecordsUpdateOne {
  825. mruo.mutation.ClearSopStage()
  826. return mruo
  827. }
  828. // ClearSopNode clears the "sop_node" edge to the SopNode entity.
  829. func (mruo *MessageRecordsUpdateOne) ClearSopNode() *MessageRecordsUpdateOne {
  830. mruo.mutation.ClearSopNode()
  831. return mruo
  832. }
  833. // ClearMessageContact clears the "message_contact" edge to the Contact entity.
  834. func (mruo *MessageRecordsUpdateOne) ClearMessageContact() *MessageRecordsUpdateOne {
  835. mruo.mutation.ClearMessageContact()
  836. return mruo
  837. }
  838. // Where appends a list predicates to the MessageRecordsUpdate builder.
  839. func (mruo *MessageRecordsUpdateOne) Where(ps ...predicate.MessageRecords) *MessageRecordsUpdateOne {
  840. mruo.mutation.Where(ps...)
  841. return mruo
  842. }
  843. // Select allows selecting one or more fields (columns) of the returned entity.
  844. // The default is selecting all fields defined in the entity schema.
  845. func (mruo *MessageRecordsUpdateOne) Select(field string, fields ...string) *MessageRecordsUpdateOne {
  846. mruo.fields = append([]string{field}, fields...)
  847. return mruo
  848. }
  849. // Save executes the query and returns the updated MessageRecords entity.
  850. func (mruo *MessageRecordsUpdateOne) Save(ctx context.Context) (*MessageRecords, error) {
  851. if err := mruo.defaults(); err != nil {
  852. return nil, err
  853. }
  854. return withHooks(ctx, mruo.sqlSave, mruo.mutation, mruo.hooks)
  855. }
  856. // SaveX is like Save, but panics if an error occurs.
  857. func (mruo *MessageRecordsUpdateOne) SaveX(ctx context.Context) *MessageRecords {
  858. node, err := mruo.Save(ctx)
  859. if err != nil {
  860. panic(err)
  861. }
  862. return node
  863. }
  864. // Exec executes the query on the entity.
  865. func (mruo *MessageRecordsUpdateOne) Exec(ctx context.Context) error {
  866. _, err := mruo.Save(ctx)
  867. return err
  868. }
  869. // ExecX is like Exec, but panics if an error occurs.
  870. func (mruo *MessageRecordsUpdateOne) ExecX(ctx context.Context) {
  871. if err := mruo.Exec(ctx); err != nil {
  872. panic(err)
  873. }
  874. }
  875. // defaults sets the default values of the builder before save.
  876. func (mruo *MessageRecordsUpdateOne) defaults() error {
  877. if _, ok := mruo.mutation.UpdatedAt(); !ok {
  878. if messagerecords.UpdateDefaultUpdatedAt == nil {
  879. return fmt.Errorf("ent: uninitialized messagerecords.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
  880. }
  881. v := messagerecords.UpdateDefaultUpdatedAt()
  882. mruo.mutation.SetUpdatedAt(v)
  883. }
  884. return nil
  885. }
  886. func (mruo *MessageRecordsUpdateOne) sqlSave(ctx context.Context) (_node *MessageRecords, err error) {
  887. _spec := sqlgraph.NewUpdateSpec(messagerecords.Table, messagerecords.Columns, sqlgraph.NewFieldSpec(messagerecords.FieldID, field.TypeUint64))
  888. id, ok := mruo.mutation.ID()
  889. if !ok {
  890. return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "MessageRecords.id" for update`)}
  891. }
  892. _spec.Node.ID.Value = id
  893. if fields := mruo.fields; len(fields) > 0 {
  894. _spec.Node.Columns = make([]string, 0, len(fields))
  895. _spec.Node.Columns = append(_spec.Node.Columns, messagerecords.FieldID)
  896. for _, f := range fields {
  897. if !messagerecords.ValidColumn(f) {
  898. return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
  899. }
  900. if f != messagerecords.FieldID {
  901. _spec.Node.Columns = append(_spec.Node.Columns, f)
  902. }
  903. }
  904. }
  905. if ps := mruo.mutation.predicates; len(ps) > 0 {
  906. _spec.Predicate = func(selector *sql.Selector) {
  907. for i := range ps {
  908. ps[i](selector)
  909. }
  910. }
  911. }
  912. if value, ok := mruo.mutation.UpdatedAt(); ok {
  913. _spec.SetField(messagerecords.FieldUpdatedAt, field.TypeTime, value)
  914. }
  915. if value, ok := mruo.mutation.Status(); ok {
  916. _spec.SetField(messagerecords.FieldStatus, field.TypeUint8, value)
  917. }
  918. if value, ok := mruo.mutation.AddedStatus(); ok {
  919. _spec.AddField(messagerecords.FieldStatus, field.TypeUint8, value)
  920. }
  921. if mruo.mutation.StatusCleared() {
  922. _spec.ClearField(messagerecords.FieldStatus, field.TypeUint8)
  923. }
  924. if value, ok := mruo.mutation.DeletedAt(); ok {
  925. _spec.SetField(messagerecords.FieldDeletedAt, field.TypeTime, value)
  926. }
  927. if mruo.mutation.DeletedAtCleared() {
  928. _spec.ClearField(messagerecords.FieldDeletedAt, field.TypeTime)
  929. }
  930. if value, ok := mruo.mutation.BotWxid(); ok {
  931. _spec.SetField(messagerecords.FieldBotWxid, field.TypeString, value)
  932. }
  933. if value, ok := mruo.mutation.ContactType(); ok {
  934. _spec.SetField(messagerecords.FieldContactType, field.TypeInt, value)
  935. }
  936. if value, ok := mruo.mutation.AddedContactType(); ok {
  937. _spec.AddField(messagerecords.FieldContactType, field.TypeInt, value)
  938. }
  939. if value, ok := mruo.mutation.ContactWxid(); ok {
  940. _spec.SetField(messagerecords.FieldContactWxid, field.TypeString, value)
  941. }
  942. if value, ok := mruo.mutation.ContentType(); ok {
  943. _spec.SetField(messagerecords.FieldContentType, field.TypeInt, value)
  944. }
  945. if value, ok := mruo.mutation.AddedContentType(); ok {
  946. _spec.AddField(messagerecords.FieldContentType, field.TypeInt, value)
  947. }
  948. if value, ok := mruo.mutation.Content(); ok {
  949. _spec.SetField(messagerecords.FieldContent, field.TypeString, value)
  950. }
  951. if value, ok := mruo.mutation.Meta(); ok {
  952. _spec.SetField(messagerecords.FieldMeta, field.TypeJSON, value)
  953. }
  954. if mruo.mutation.MetaCleared() {
  955. _spec.ClearField(messagerecords.FieldMeta, field.TypeJSON)
  956. }
  957. if value, ok := mruo.mutation.ErrorDetail(); ok {
  958. _spec.SetField(messagerecords.FieldErrorDetail, field.TypeString, value)
  959. }
  960. if value, ok := mruo.mutation.SendTime(); ok {
  961. _spec.SetField(messagerecords.FieldSendTime, field.TypeTime, value)
  962. }
  963. if mruo.mutation.SendTimeCleared() {
  964. _spec.ClearField(messagerecords.FieldSendTime, field.TypeTime)
  965. }
  966. if value, ok := mruo.mutation.SourceType(); ok {
  967. _spec.SetField(messagerecords.FieldSourceType, field.TypeInt, value)
  968. }
  969. if value, ok := mruo.mutation.AddedSourceType(); ok {
  970. _spec.AddField(messagerecords.FieldSourceType, field.TypeInt, value)
  971. }
  972. if mruo.mutation.SopStageCleared() {
  973. edge := &sqlgraph.EdgeSpec{
  974. Rel: sqlgraph.M2O,
  975. Inverse: true,
  976. Table: messagerecords.SopStageTable,
  977. Columns: []string{messagerecords.SopStageColumn},
  978. Bidi: false,
  979. Target: &sqlgraph.EdgeTarget{
  980. IDSpec: sqlgraph.NewFieldSpec(sopstage.FieldID, field.TypeUint64),
  981. },
  982. }
  983. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  984. }
  985. if nodes := mruo.mutation.SopStageIDs(); len(nodes) > 0 {
  986. edge := &sqlgraph.EdgeSpec{
  987. Rel: sqlgraph.M2O,
  988. Inverse: true,
  989. Table: messagerecords.SopStageTable,
  990. Columns: []string{messagerecords.SopStageColumn},
  991. Bidi: false,
  992. Target: &sqlgraph.EdgeTarget{
  993. IDSpec: sqlgraph.NewFieldSpec(sopstage.FieldID, field.TypeUint64),
  994. },
  995. }
  996. for _, k := range nodes {
  997. edge.Target.Nodes = append(edge.Target.Nodes, k)
  998. }
  999. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  1000. }
  1001. if mruo.mutation.SopNodeCleared() {
  1002. edge := &sqlgraph.EdgeSpec{
  1003. Rel: sqlgraph.M2O,
  1004. Inverse: true,
  1005. Table: messagerecords.SopNodeTable,
  1006. Columns: []string{messagerecords.SopNodeColumn},
  1007. Bidi: false,
  1008. Target: &sqlgraph.EdgeTarget{
  1009. IDSpec: sqlgraph.NewFieldSpec(sopnode.FieldID, field.TypeUint64),
  1010. },
  1011. }
  1012. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  1013. }
  1014. if nodes := mruo.mutation.SopNodeIDs(); len(nodes) > 0 {
  1015. edge := &sqlgraph.EdgeSpec{
  1016. Rel: sqlgraph.M2O,
  1017. Inverse: true,
  1018. Table: messagerecords.SopNodeTable,
  1019. Columns: []string{messagerecords.SopNodeColumn},
  1020. Bidi: false,
  1021. Target: &sqlgraph.EdgeTarget{
  1022. IDSpec: sqlgraph.NewFieldSpec(sopnode.FieldID, field.TypeUint64),
  1023. },
  1024. }
  1025. for _, k := range nodes {
  1026. edge.Target.Nodes = append(edge.Target.Nodes, k)
  1027. }
  1028. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  1029. }
  1030. if mruo.mutation.MessageContactCleared() {
  1031. edge := &sqlgraph.EdgeSpec{
  1032. Rel: sqlgraph.M2O,
  1033. Inverse: true,
  1034. Table: messagerecords.MessageContactTable,
  1035. Columns: []string{messagerecords.MessageContactColumn},
  1036. Bidi: false,
  1037. Target: &sqlgraph.EdgeTarget{
  1038. IDSpec: sqlgraph.NewFieldSpec(contact.FieldID, field.TypeUint64),
  1039. },
  1040. }
  1041. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  1042. }
  1043. if nodes := mruo.mutation.MessageContactIDs(); len(nodes) > 0 {
  1044. edge := &sqlgraph.EdgeSpec{
  1045. Rel: sqlgraph.M2O,
  1046. Inverse: true,
  1047. Table: messagerecords.MessageContactTable,
  1048. Columns: []string{messagerecords.MessageContactColumn},
  1049. Bidi: false,
  1050. Target: &sqlgraph.EdgeTarget{
  1051. IDSpec: sqlgraph.NewFieldSpec(contact.FieldID, field.TypeUint64),
  1052. },
  1053. }
  1054. for _, k := range nodes {
  1055. edge.Target.Nodes = append(edge.Target.Nodes, k)
  1056. }
  1057. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  1058. }
  1059. _node = &MessageRecords{config: mruo.config}
  1060. _spec.Assign = _node.assignValues
  1061. _spec.ScanValues = _node.scanValues
  1062. if err = sqlgraph.UpdateNode(ctx, mruo.driver, _spec); err != nil {
  1063. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  1064. err = &NotFoundError{messagerecords.Label}
  1065. } else if sqlgraph.IsConstraintError(err) {
  1066. err = &ConstraintError{msg: err.Error(), wrap: err}
  1067. }
  1068. return nil, err
  1069. }
  1070. mruo.mutation.done = true
  1071. return _node, nil
  1072. }