messagerecords_update.go 38 KB

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