messagerecords_create.go 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645
  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/messagerecords"
  10. "wechat-api/ent/sopnode"
  11. "wechat-api/ent/sopstage"
  12. "entgo.io/ent/dialect/sql"
  13. "entgo.io/ent/dialect/sql/sqlgraph"
  14. "entgo.io/ent/schema/field"
  15. )
  16. // MessageRecordsCreate is the builder for creating a MessageRecords entity.
  17. type MessageRecordsCreate struct {
  18. config
  19. mutation *MessageRecordsMutation
  20. hooks []Hook
  21. conflict []sql.ConflictOption
  22. }
  23. // SetCreatedAt sets the "created_at" field.
  24. func (mrc *MessageRecordsCreate) SetCreatedAt(t time.Time) *MessageRecordsCreate {
  25. mrc.mutation.SetCreatedAt(t)
  26. return mrc
  27. }
  28. // SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
  29. func (mrc *MessageRecordsCreate) SetNillableCreatedAt(t *time.Time) *MessageRecordsCreate {
  30. if t != nil {
  31. mrc.SetCreatedAt(*t)
  32. }
  33. return mrc
  34. }
  35. // SetUpdatedAt sets the "updated_at" field.
  36. func (mrc *MessageRecordsCreate) SetUpdatedAt(t time.Time) *MessageRecordsCreate {
  37. mrc.mutation.SetUpdatedAt(t)
  38. return mrc
  39. }
  40. // SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
  41. func (mrc *MessageRecordsCreate) SetNillableUpdatedAt(t *time.Time) *MessageRecordsCreate {
  42. if t != nil {
  43. mrc.SetUpdatedAt(*t)
  44. }
  45. return mrc
  46. }
  47. // SetStatus sets the "status" field.
  48. func (mrc *MessageRecordsCreate) SetStatus(u uint8) *MessageRecordsCreate {
  49. mrc.mutation.SetStatus(u)
  50. return mrc
  51. }
  52. // SetNillableStatus sets the "status" field if the given value is not nil.
  53. func (mrc *MessageRecordsCreate) SetNillableStatus(u *uint8) *MessageRecordsCreate {
  54. if u != nil {
  55. mrc.SetStatus(*u)
  56. }
  57. return mrc
  58. }
  59. // SetDeletedAt sets the "deleted_at" field.
  60. func (mrc *MessageRecordsCreate) SetDeletedAt(t time.Time) *MessageRecordsCreate {
  61. mrc.mutation.SetDeletedAt(t)
  62. return mrc
  63. }
  64. // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
  65. func (mrc *MessageRecordsCreate) SetNillableDeletedAt(t *time.Time) *MessageRecordsCreate {
  66. if t != nil {
  67. mrc.SetDeletedAt(*t)
  68. }
  69. return mrc
  70. }
  71. // SetBotWxid sets the "bot_wxid" field.
  72. func (mrc *MessageRecordsCreate) SetBotWxid(s string) *MessageRecordsCreate {
  73. mrc.mutation.SetBotWxid(s)
  74. return mrc
  75. }
  76. // SetContactID sets the "contact_id" field.
  77. func (mrc *MessageRecordsCreate) SetContactID(u uint64) *MessageRecordsCreate {
  78. mrc.mutation.SetContactID(u)
  79. return mrc
  80. }
  81. // SetNillableContactID sets the "contact_id" field if the given value is not nil.
  82. func (mrc *MessageRecordsCreate) SetNillableContactID(u *uint64) *MessageRecordsCreate {
  83. if u != nil {
  84. mrc.SetContactID(*u)
  85. }
  86. return mrc
  87. }
  88. // SetContactType sets the "contact_type" field.
  89. func (mrc *MessageRecordsCreate) SetContactType(i int) *MessageRecordsCreate {
  90. mrc.mutation.SetContactType(i)
  91. return mrc
  92. }
  93. // SetNillableContactType sets the "contact_type" field if the given value is not nil.
  94. func (mrc *MessageRecordsCreate) SetNillableContactType(i *int) *MessageRecordsCreate {
  95. if i != nil {
  96. mrc.SetContactType(*i)
  97. }
  98. return mrc
  99. }
  100. // SetContactWxid sets the "contact_wxid" field.
  101. func (mrc *MessageRecordsCreate) SetContactWxid(s string) *MessageRecordsCreate {
  102. mrc.mutation.SetContactWxid(s)
  103. return mrc
  104. }
  105. // SetNillableContactWxid sets the "contact_wxid" field if the given value is not nil.
  106. func (mrc *MessageRecordsCreate) SetNillableContactWxid(s *string) *MessageRecordsCreate {
  107. if s != nil {
  108. mrc.SetContactWxid(*s)
  109. }
  110. return mrc
  111. }
  112. // SetContentType sets the "content_type" field.
  113. func (mrc *MessageRecordsCreate) SetContentType(i int) *MessageRecordsCreate {
  114. mrc.mutation.SetContentType(i)
  115. return mrc
  116. }
  117. // SetNillableContentType sets the "content_type" field if the given value is not nil.
  118. func (mrc *MessageRecordsCreate) SetNillableContentType(i *int) *MessageRecordsCreate {
  119. if i != nil {
  120. mrc.SetContentType(*i)
  121. }
  122. return mrc
  123. }
  124. // SetContent sets the "content" field.
  125. func (mrc *MessageRecordsCreate) SetContent(s string) *MessageRecordsCreate {
  126. mrc.mutation.SetContent(s)
  127. return mrc
  128. }
  129. // SetNillableContent sets the "content" field if the given value is not nil.
  130. func (mrc *MessageRecordsCreate) SetNillableContent(s *string) *MessageRecordsCreate {
  131. if s != nil {
  132. mrc.SetContent(*s)
  133. }
  134. return mrc
  135. }
  136. // SetErrorDetail sets the "error_detail" field.
  137. func (mrc *MessageRecordsCreate) SetErrorDetail(s string) *MessageRecordsCreate {
  138. mrc.mutation.SetErrorDetail(s)
  139. return mrc
  140. }
  141. // SetNillableErrorDetail sets the "error_detail" field if the given value is not nil.
  142. func (mrc *MessageRecordsCreate) SetNillableErrorDetail(s *string) *MessageRecordsCreate {
  143. if s != nil {
  144. mrc.SetErrorDetail(*s)
  145. }
  146. return mrc
  147. }
  148. // SetSendTime sets the "send_time" field.
  149. func (mrc *MessageRecordsCreate) SetSendTime(t time.Time) *MessageRecordsCreate {
  150. mrc.mutation.SetSendTime(t)
  151. return mrc
  152. }
  153. // SetNillableSendTime sets the "send_time" field if the given value is not nil.
  154. func (mrc *MessageRecordsCreate) SetNillableSendTime(t *time.Time) *MessageRecordsCreate {
  155. if t != nil {
  156. mrc.SetSendTime(*t)
  157. }
  158. return mrc
  159. }
  160. // SetSourceType sets the "source_type" field.
  161. func (mrc *MessageRecordsCreate) SetSourceType(i int) *MessageRecordsCreate {
  162. mrc.mutation.SetSourceType(i)
  163. return mrc
  164. }
  165. // SetNillableSourceType sets the "source_type" field if the given value is not nil.
  166. func (mrc *MessageRecordsCreate) SetNillableSourceType(i *int) *MessageRecordsCreate {
  167. if i != nil {
  168. mrc.SetSourceType(*i)
  169. }
  170. return mrc
  171. }
  172. // SetSourceID sets the "source_id" field.
  173. func (mrc *MessageRecordsCreate) SetSourceID(u uint64) *MessageRecordsCreate {
  174. mrc.mutation.SetSourceID(u)
  175. return mrc
  176. }
  177. // SetNillableSourceID sets the "source_id" field if the given value is not nil.
  178. func (mrc *MessageRecordsCreate) SetNillableSourceID(u *uint64) *MessageRecordsCreate {
  179. if u != nil {
  180. mrc.SetSourceID(*u)
  181. }
  182. return mrc
  183. }
  184. // SetSubSourceID sets the "sub_source_id" field.
  185. func (mrc *MessageRecordsCreate) SetSubSourceID(u uint64) *MessageRecordsCreate {
  186. mrc.mutation.SetSubSourceID(u)
  187. return mrc
  188. }
  189. // SetNillableSubSourceID sets the "sub_source_id" field if the given value is not nil.
  190. func (mrc *MessageRecordsCreate) SetNillableSubSourceID(u *uint64) *MessageRecordsCreate {
  191. if u != nil {
  192. mrc.SetSubSourceID(*u)
  193. }
  194. return mrc
  195. }
  196. // SetID sets the "id" field.
  197. func (mrc *MessageRecordsCreate) SetID(u uint64) *MessageRecordsCreate {
  198. mrc.mutation.SetID(u)
  199. return mrc
  200. }
  201. // SetSopStageID sets the "sop_stage" edge to the SopStage entity by ID.
  202. func (mrc *MessageRecordsCreate) SetSopStageID(id uint64) *MessageRecordsCreate {
  203. mrc.mutation.SetSopStageID(id)
  204. return mrc
  205. }
  206. // SetNillableSopStageID sets the "sop_stage" edge to the SopStage entity by ID if the given value is not nil.
  207. func (mrc *MessageRecordsCreate) SetNillableSopStageID(id *uint64) *MessageRecordsCreate {
  208. if id != nil {
  209. mrc = mrc.SetSopStageID(*id)
  210. }
  211. return mrc
  212. }
  213. // SetSopStage sets the "sop_stage" edge to the SopStage entity.
  214. func (mrc *MessageRecordsCreate) SetSopStage(s *SopStage) *MessageRecordsCreate {
  215. return mrc.SetSopStageID(s.ID)
  216. }
  217. // SetSopNodeID sets the "sop_node" edge to the SopNode entity by ID.
  218. func (mrc *MessageRecordsCreate) SetSopNodeID(id uint64) *MessageRecordsCreate {
  219. mrc.mutation.SetSopNodeID(id)
  220. return mrc
  221. }
  222. // SetNillableSopNodeID sets the "sop_node" edge to the SopNode entity by ID if the given value is not nil.
  223. func (mrc *MessageRecordsCreate) SetNillableSopNodeID(id *uint64) *MessageRecordsCreate {
  224. if id != nil {
  225. mrc = mrc.SetSopNodeID(*id)
  226. }
  227. return mrc
  228. }
  229. // SetSopNode sets the "sop_node" edge to the SopNode entity.
  230. func (mrc *MessageRecordsCreate) SetSopNode(s *SopNode) *MessageRecordsCreate {
  231. return mrc.SetSopNodeID(s.ID)
  232. }
  233. // SetMessageContactID sets the "message_contact" edge to the Contact entity by ID.
  234. func (mrc *MessageRecordsCreate) SetMessageContactID(id uint64) *MessageRecordsCreate {
  235. mrc.mutation.SetMessageContactID(id)
  236. return mrc
  237. }
  238. // SetNillableMessageContactID sets the "message_contact" edge to the Contact entity by ID if the given value is not nil.
  239. func (mrc *MessageRecordsCreate) SetNillableMessageContactID(id *uint64) *MessageRecordsCreate {
  240. if id != nil {
  241. mrc = mrc.SetMessageContactID(*id)
  242. }
  243. return mrc
  244. }
  245. // SetMessageContact sets the "message_contact" edge to the Contact entity.
  246. func (mrc *MessageRecordsCreate) SetMessageContact(c *Contact) *MessageRecordsCreate {
  247. return mrc.SetMessageContactID(c.ID)
  248. }
  249. // Mutation returns the MessageRecordsMutation object of the builder.
  250. func (mrc *MessageRecordsCreate) Mutation() *MessageRecordsMutation {
  251. return mrc.mutation
  252. }
  253. // Save creates the MessageRecords in the database.
  254. func (mrc *MessageRecordsCreate) Save(ctx context.Context) (*MessageRecords, error) {
  255. if err := mrc.defaults(); err != nil {
  256. return nil, err
  257. }
  258. return withHooks(ctx, mrc.sqlSave, mrc.mutation, mrc.hooks)
  259. }
  260. // SaveX calls Save and panics if Save returns an error.
  261. func (mrc *MessageRecordsCreate) SaveX(ctx context.Context) *MessageRecords {
  262. v, err := mrc.Save(ctx)
  263. if err != nil {
  264. panic(err)
  265. }
  266. return v
  267. }
  268. // Exec executes the query.
  269. func (mrc *MessageRecordsCreate) Exec(ctx context.Context) error {
  270. _, err := mrc.Save(ctx)
  271. return err
  272. }
  273. // ExecX is like Exec, but panics if an error occurs.
  274. func (mrc *MessageRecordsCreate) ExecX(ctx context.Context) {
  275. if err := mrc.Exec(ctx); err != nil {
  276. panic(err)
  277. }
  278. }
  279. // defaults sets the default values of the builder before save.
  280. func (mrc *MessageRecordsCreate) defaults() error {
  281. if _, ok := mrc.mutation.CreatedAt(); !ok {
  282. if messagerecords.DefaultCreatedAt == nil {
  283. return fmt.Errorf("ent: uninitialized messagerecords.DefaultCreatedAt (forgotten import ent/runtime?)")
  284. }
  285. v := messagerecords.DefaultCreatedAt()
  286. mrc.mutation.SetCreatedAt(v)
  287. }
  288. if _, ok := mrc.mutation.UpdatedAt(); !ok {
  289. if messagerecords.DefaultUpdatedAt == nil {
  290. return fmt.Errorf("ent: uninitialized messagerecords.DefaultUpdatedAt (forgotten import ent/runtime?)")
  291. }
  292. v := messagerecords.DefaultUpdatedAt()
  293. mrc.mutation.SetUpdatedAt(v)
  294. }
  295. if _, ok := mrc.mutation.Status(); !ok {
  296. v := messagerecords.DefaultStatus
  297. mrc.mutation.SetStatus(v)
  298. }
  299. if _, ok := mrc.mutation.ContactType(); !ok {
  300. v := messagerecords.DefaultContactType
  301. mrc.mutation.SetContactType(v)
  302. }
  303. if _, ok := mrc.mutation.ContactWxid(); !ok {
  304. v := messagerecords.DefaultContactWxid
  305. mrc.mutation.SetContactWxid(v)
  306. }
  307. if _, ok := mrc.mutation.ContentType(); !ok {
  308. v := messagerecords.DefaultContentType
  309. mrc.mutation.SetContentType(v)
  310. }
  311. if _, ok := mrc.mutation.Content(); !ok {
  312. v := messagerecords.DefaultContent
  313. mrc.mutation.SetContent(v)
  314. }
  315. if _, ok := mrc.mutation.ErrorDetail(); !ok {
  316. v := messagerecords.DefaultErrorDetail
  317. mrc.mutation.SetErrorDetail(v)
  318. }
  319. if _, ok := mrc.mutation.SourceType(); !ok {
  320. v := messagerecords.DefaultSourceType
  321. mrc.mutation.SetSourceType(v)
  322. }
  323. if _, ok := mrc.mutation.SourceID(); !ok {
  324. v := messagerecords.DefaultSourceID
  325. mrc.mutation.SetSourceID(v)
  326. }
  327. if _, ok := mrc.mutation.SubSourceID(); !ok {
  328. v := messagerecords.DefaultSubSourceID
  329. mrc.mutation.SetSubSourceID(v)
  330. }
  331. return nil
  332. }
  333. // check runs all checks and user-defined validators on the builder.
  334. func (mrc *MessageRecordsCreate) check() error {
  335. if _, ok := mrc.mutation.CreatedAt(); !ok {
  336. return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "MessageRecords.created_at"`)}
  337. }
  338. if _, ok := mrc.mutation.UpdatedAt(); !ok {
  339. return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "MessageRecords.updated_at"`)}
  340. }
  341. if _, ok := mrc.mutation.BotWxid(); !ok {
  342. return &ValidationError{Name: "bot_wxid", err: errors.New(`ent: missing required field "MessageRecords.bot_wxid"`)}
  343. }
  344. if _, ok := mrc.mutation.ContactType(); !ok {
  345. return &ValidationError{Name: "contact_type", err: errors.New(`ent: missing required field "MessageRecords.contact_type"`)}
  346. }
  347. if _, ok := mrc.mutation.ContactWxid(); !ok {
  348. return &ValidationError{Name: "contact_wxid", err: errors.New(`ent: missing required field "MessageRecords.contact_wxid"`)}
  349. }
  350. if _, ok := mrc.mutation.ContentType(); !ok {
  351. return &ValidationError{Name: "content_type", err: errors.New(`ent: missing required field "MessageRecords.content_type"`)}
  352. }
  353. if _, ok := mrc.mutation.Content(); !ok {
  354. return &ValidationError{Name: "content", err: errors.New(`ent: missing required field "MessageRecords.content"`)}
  355. }
  356. if _, ok := mrc.mutation.ErrorDetail(); !ok {
  357. return &ValidationError{Name: "error_detail", err: errors.New(`ent: missing required field "MessageRecords.error_detail"`)}
  358. }
  359. if _, ok := mrc.mutation.SourceType(); !ok {
  360. return &ValidationError{Name: "source_type", err: errors.New(`ent: missing required field "MessageRecords.source_type"`)}
  361. }
  362. return nil
  363. }
  364. func (mrc *MessageRecordsCreate) sqlSave(ctx context.Context) (*MessageRecords, error) {
  365. if err := mrc.check(); err != nil {
  366. return nil, err
  367. }
  368. _node, _spec := mrc.createSpec()
  369. if err := sqlgraph.CreateNode(ctx, mrc.driver, _spec); err != nil {
  370. if sqlgraph.IsConstraintError(err) {
  371. err = &ConstraintError{msg: err.Error(), wrap: err}
  372. }
  373. return nil, err
  374. }
  375. if _spec.ID.Value != _node.ID {
  376. id := _spec.ID.Value.(int64)
  377. _node.ID = uint64(id)
  378. }
  379. mrc.mutation.id = &_node.ID
  380. mrc.mutation.done = true
  381. return _node, nil
  382. }
  383. func (mrc *MessageRecordsCreate) createSpec() (*MessageRecords, *sqlgraph.CreateSpec) {
  384. var (
  385. _node = &MessageRecords{config: mrc.config}
  386. _spec = sqlgraph.NewCreateSpec(messagerecords.Table, sqlgraph.NewFieldSpec(messagerecords.FieldID, field.TypeUint64))
  387. )
  388. _spec.OnConflict = mrc.conflict
  389. if id, ok := mrc.mutation.ID(); ok {
  390. _node.ID = id
  391. _spec.ID.Value = id
  392. }
  393. if value, ok := mrc.mutation.CreatedAt(); ok {
  394. _spec.SetField(messagerecords.FieldCreatedAt, field.TypeTime, value)
  395. _node.CreatedAt = value
  396. }
  397. if value, ok := mrc.mutation.UpdatedAt(); ok {
  398. _spec.SetField(messagerecords.FieldUpdatedAt, field.TypeTime, value)
  399. _node.UpdatedAt = value
  400. }
  401. if value, ok := mrc.mutation.Status(); ok {
  402. _spec.SetField(messagerecords.FieldStatus, field.TypeUint8, value)
  403. _node.Status = value
  404. }
  405. if value, ok := mrc.mutation.DeletedAt(); ok {
  406. _spec.SetField(messagerecords.FieldDeletedAt, field.TypeTime, value)
  407. _node.DeletedAt = value
  408. }
  409. if value, ok := mrc.mutation.BotWxid(); ok {
  410. _spec.SetField(messagerecords.FieldBotWxid, field.TypeString, value)
  411. _node.BotWxid = value
  412. }
  413. if value, ok := mrc.mutation.ContactType(); ok {
  414. _spec.SetField(messagerecords.FieldContactType, field.TypeInt, value)
  415. _node.ContactType = value
  416. }
  417. if value, ok := mrc.mutation.ContactWxid(); ok {
  418. _spec.SetField(messagerecords.FieldContactWxid, field.TypeString, value)
  419. _node.ContactWxid = value
  420. }
  421. if value, ok := mrc.mutation.ContentType(); ok {
  422. _spec.SetField(messagerecords.FieldContentType, field.TypeInt, value)
  423. _node.ContentType = value
  424. }
  425. if value, ok := mrc.mutation.Content(); ok {
  426. _spec.SetField(messagerecords.FieldContent, field.TypeString, value)
  427. _node.Content = value
  428. }
  429. if value, ok := mrc.mutation.ErrorDetail(); ok {
  430. _spec.SetField(messagerecords.FieldErrorDetail, field.TypeString, value)
  431. _node.ErrorDetail = value
  432. }
  433. if value, ok := mrc.mutation.SendTime(); ok {
  434. _spec.SetField(messagerecords.FieldSendTime, field.TypeTime, value)
  435. _node.SendTime = value
  436. }
  437. if value, ok := mrc.mutation.SourceType(); ok {
  438. _spec.SetField(messagerecords.FieldSourceType, field.TypeInt, value)
  439. _node.SourceType = value
  440. }
  441. if nodes := mrc.mutation.SopStageIDs(); len(nodes) > 0 {
  442. edge := &sqlgraph.EdgeSpec{
  443. Rel: sqlgraph.M2O,
  444. Inverse: true,
  445. Table: messagerecords.SopStageTable,
  446. Columns: []string{messagerecords.SopStageColumn},
  447. Bidi: false,
  448. Target: &sqlgraph.EdgeTarget{
  449. IDSpec: sqlgraph.NewFieldSpec(sopstage.FieldID, field.TypeUint64),
  450. },
  451. }
  452. for _, k := range nodes {
  453. edge.Target.Nodes = append(edge.Target.Nodes, k)
  454. }
  455. _node.SourceID = nodes[0]
  456. _spec.Edges = append(_spec.Edges, edge)
  457. }
  458. if nodes := mrc.mutation.SopNodeIDs(); len(nodes) > 0 {
  459. edge := &sqlgraph.EdgeSpec{
  460. Rel: sqlgraph.M2O,
  461. Inverse: true,
  462. Table: messagerecords.SopNodeTable,
  463. Columns: []string{messagerecords.SopNodeColumn},
  464. Bidi: false,
  465. Target: &sqlgraph.EdgeTarget{
  466. IDSpec: sqlgraph.NewFieldSpec(sopnode.FieldID, field.TypeUint64),
  467. },
  468. }
  469. for _, k := range nodes {
  470. edge.Target.Nodes = append(edge.Target.Nodes, k)
  471. }
  472. _node.SubSourceID = nodes[0]
  473. _spec.Edges = append(_spec.Edges, edge)
  474. }
  475. if nodes := mrc.mutation.MessageContactIDs(); len(nodes) > 0 {
  476. edge := &sqlgraph.EdgeSpec{
  477. Rel: sqlgraph.M2O,
  478. Inverse: true,
  479. Table: messagerecords.MessageContactTable,
  480. Columns: []string{messagerecords.MessageContactColumn},
  481. Bidi: false,
  482. Target: &sqlgraph.EdgeTarget{
  483. IDSpec: sqlgraph.NewFieldSpec(contact.FieldID, field.TypeUint64),
  484. },
  485. }
  486. for _, k := range nodes {
  487. edge.Target.Nodes = append(edge.Target.Nodes, k)
  488. }
  489. _node.ContactID = nodes[0]
  490. _spec.Edges = append(_spec.Edges, edge)
  491. }
  492. return _node, _spec
  493. }
  494. // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
  495. // of the `INSERT` statement. For example:
  496. //
  497. // client.MessageRecords.Create().
  498. // SetCreatedAt(v).
  499. // OnConflict(
  500. // // Update the row with the new values
  501. // // the was proposed for insertion.
  502. // sql.ResolveWithNewValues(),
  503. // ).
  504. // // Override some of the fields with custom
  505. // // update values.
  506. // Update(func(u *ent.MessageRecordsUpsert) {
  507. // SetCreatedAt(v+v).
  508. // }).
  509. // Exec(ctx)
  510. func (mrc *MessageRecordsCreate) OnConflict(opts ...sql.ConflictOption) *MessageRecordsUpsertOne {
  511. mrc.conflict = opts
  512. return &MessageRecordsUpsertOne{
  513. create: mrc,
  514. }
  515. }
  516. // OnConflictColumns calls `OnConflict` and configures the columns
  517. // as conflict target. Using this option is equivalent to using:
  518. //
  519. // client.MessageRecords.Create().
  520. // OnConflict(sql.ConflictColumns(columns...)).
  521. // Exec(ctx)
  522. func (mrc *MessageRecordsCreate) OnConflictColumns(columns ...string) *MessageRecordsUpsertOne {
  523. mrc.conflict = append(mrc.conflict, sql.ConflictColumns(columns...))
  524. return &MessageRecordsUpsertOne{
  525. create: mrc,
  526. }
  527. }
  528. type (
  529. // MessageRecordsUpsertOne is the builder for "upsert"-ing
  530. // one MessageRecords node.
  531. MessageRecordsUpsertOne struct {
  532. create *MessageRecordsCreate
  533. }
  534. // MessageRecordsUpsert is the "OnConflict" setter.
  535. MessageRecordsUpsert struct {
  536. *sql.UpdateSet
  537. }
  538. )
  539. // SetUpdatedAt sets the "updated_at" field.
  540. func (u *MessageRecordsUpsert) SetUpdatedAt(v time.Time) *MessageRecordsUpsert {
  541. u.Set(messagerecords.FieldUpdatedAt, v)
  542. return u
  543. }
  544. // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
  545. func (u *MessageRecordsUpsert) UpdateUpdatedAt() *MessageRecordsUpsert {
  546. u.SetExcluded(messagerecords.FieldUpdatedAt)
  547. return u
  548. }
  549. // SetStatus sets the "status" field.
  550. func (u *MessageRecordsUpsert) SetStatus(v uint8) *MessageRecordsUpsert {
  551. u.Set(messagerecords.FieldStatus, v)
  552. return u
  553. }
  554. // UpdateStatus sets the "status" field to the value that was provided on create.
  555. func (u *MessageRecordsUpsert) UpdateStatus() *MessageRecordsUpsert {
  556. u.SetExcluded(messagerecords.FieldStatus)
  557. return u
  558. }
  559. // AddStatus adds v to the "status" field.
  560. func (u *MessageRecordsUpsert) AddStatus(v uint8) *MessageRecordsUpsert {
  561. u.Add(messagerecords.FieldStatus, v)
  562. return u
  563. }
  564. // ClearStatus clears the value of the "status" field.
  565. func (u *MessageRecordsUpsert) ClearStatus() *MessageRecordsUpsert {
  566. u.SetNull(messagerecords.FieldStatus)
  567. return u
  568. }
  569. // SetDeletedAt sets the "deleted_at" field.
  570. func (u *MessageRecordsUpsert) SetDeletedAt(v time.Time) *MessageRecordsUpsert {
  571. u.Set(messagerecords.FieldDeletedAt, v)
  572. return u
  573. }
  574. // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
  575. func (u *MessageRecordsUpsert) UpdateDeletedAt() *MessageRecordsUpsert {
  576. u.SetExcluded(messagerecords.FieldDeletedAt)
  577. return u
  578. }
  579. // ClearDeletedAt clears the value of the "deleted_at" field.
  580. func (u *MessageRecordsUpsert) ClearDeletedAt() *MessageRecordsUpsert {
  581. u.SetNull(messagerecords.FieldDeletedAt)
  582. return u
  583. }
  584. // SetBotWxid sets the "bot_wxid" field.
  585. func (u *MessageRecordsUpsert) SetBotWxid(v string) *MessageRecordsUpsert {
  586. u.Set(messagerecords.FieldBotWxid, v)
  587. return u
  588. }
  589. // UpdateBotWxid sets the "bot_wxid" field to the value that was provided on create.
  590. func (u *MessageRecordsUpsert) UpdateBotWxid() *MessageRecordsUpsert {
  591. u.SetExcluded(messagerecords.FieldBotWxid)
  592. return u
  593. }
  594. // SetContactID sets the "contact_id" field.
  595. func (u *MessageRecordsUpsert) SetContactID(v uint64) *MessageRecordsUpsert {
  596. u.Set(messagerecords.FieldContactID, v)
  597. return u
  598. }
  599. // UpdateContactID sets the "contact_id" field to the value that was provided on create.
  600. func (u *MessageRecordsUpsert) UpdateContactID() *MessageRecordsUpsert {
  601. u.SetExcluded(messagerecords.FieldContactID)
  602. return u
  603. }
  604. // ClearContactID clears the value of the "contact_id" field.
  605. func (u *MessageRecordsUpsert) ClearContactID() *MessageRecordsUpsert {
  606. u.SetNull(messagerecords.FieldContactID)
  607. return u
  608. }
  609. // SetContactType sets the "contact_type" field.
  610. func (u *MessageRecordsUpsert) SetContactType(v int) *MessageRecordsUpsert {
  611. u.Set(messagerecords.FieldContactType, v)
  612. return u
  613. }
  614. // UpdateContactType sets the "contact_type" field to the value that was provided on create.
  615. func (u *MessageRecordsUpsert) UpdateContactType() *MessageRecordsUpsert {
  616. u.SetExcluded(messagerecords.FieldContactType)
  617. return u
  618. }
  619. // AddContactType adds v to the "contact_type" field.
  620. func (u *MessageRecordsUpsert) AddContactType(v int) *MessageRecordsUpsert {
  621. u.Add(messagerecords.FieldContactType, v)
  622. return u
  623. }
  624. // SetContactWxid sets the "contact_wxid" field.
  625. func (u *MessageRecordsUpsert) SetContactWxid(v string) *MessageRecordsUpsert {
  626. u.Set(messagerecords.FieldContactWxid, v)
  627. return u
  628. }
  629. // UpdateContactWxid sets the "contact_wxid" field to the value that was provided on create.
  630. func (u *MessageRecordsUpsert) UpdateContactWxid() *MessageRecordsUpsert {
  631. u.SetExcluded(messagerecords.FieldContactWxid)
  632. return u
  633. }
  634. // SetContentType sets the "content_type" field.
  635. func (u *MessageRecordsUpsert) SetContentType(v int) *MessageRecordsUpsert {
  636. u.Set(messagerecords.FieldContentType, v)
  637. return u
  638. }
  639. // UpdateContentType sets the "content_type" field to the value that was provided on create.
  640. func (u *MessageRecordsUpsert) UpdateContentType() *MessageRecordsUpsert {
  641. u.SetExcluded(messagerecords.FieldContentType)
  642. return u
  643. }
  644. // AddContentType adds v to the "content_type" field.
  645. func (u *MessageRecordsUpsert) AddContentType(v int) *MessageRecordsUpsert {
  646. u.Add(messagerecords.FieldContentType, v)
  647. return u
  648. }
  649. // SetContent sets the "content" field.
  650. func (u *MessageRecordsUpsert) SetContent(v string) *MessageRecordsUpsert {
  651. u.Set(messagerecords.FieldContent, v)
  652. return u
  653. }
  654. // UpdateContent sets the "content" field to the value that was provided on create.
  655. func (u *MessageRecordsUpsert) UpdateContent() *MessageRecordsUpsert {
  656. u.SetExcluded(messagerecords.FieldContent)
  657. return u
  658. }
  659. // SetErrorDetail sets the "error_detail" field.
  660. func (u *MessageRecordsUpsert) SetErrorDetail(v string) *MessageRecordsUpsert {
  661. u.Set(messagerecords.FieldErrorDetail, v)
  662. return u
  663. }
  664. // UpdateErrorDetail sets the "error_detail" field to the value that was provided on create.
  665. func (u *MessageRecordsUpsert) UpdateErrorDetail() *MessageRecordsUpsert {
  666. u.SetExcluded(messagerecords.FieldErrorDetail)
  667. return u
  668. }
  669. // SetSendTime sets the "send_time" field.
  670. func (u *MessageRecordsUpsert) SetSendTime(v time.Time) *MessageRecordsUpsert {
  671. u.Set(messagerecords.FieldSendTime, v)
  672. return u
  673. }
  674. // UpdateSendTime sets the "send_time" field to the value that was provided on create.
  675. func (u *MessageRecordsUpsert) UpdateSendTime() *MessageRecordsUpsert {
  676. u.SetExcluded(messagerecords.FieldSendTime)
  677. return u
  678. }
  679. // ClearSendTime clears the value of the "send_time" field.
  680. func (u *MessageRecordsUpsert) ClearSendTime() *MessageRecordsUpsert {
  681. u.SetNull(messagerecords.FieldSendTime)
  682. return u
  683. }
  684. // SetSourceType sets the "source_type" field.
  685. func (u *MessageRecordsUpsert) SetSourceType(v int) *MessageRecordsUpsert {
  686. u.Set(messagerecords.FieldSourceType, v)
  687. return u
  688. }
  689. // UpdateSourceType sets the "source_type" field to the value that was provided on create.
  690. func (u *MessageRecordsUpsert) UpdateSourceType() *MessageRecordsUpsert {
  691. u.SetExcluded(messagerecords.FieldSourceType)
  692. return u
  693. }
  694. // AddSourceType adds v to the "source_type" field.
  695. func (u *MessageRecordsUpsert) AddSourceType(v int) *MessageRecordsUpsert {
  696. u.Add(messagerecords.FieldSourceType, v)
  697. return u
  698. }
  699. // SetSourceID sets the "source_id" field.
  700. func (u *MessageRecordsUpsert) SetSourceID(v uint64) *MessageRecordsUpsert {
  701. u.Set(messagerecords.FieldSourceID, v)
  702. return u
  703. }
  704. // UpdateSourceID sets the "source_id" field to the value that was provided on create.
  705. func (u *MessageRecordsUpsert) UpdateSourceID() *MessageRecordsUpsert {
  706. u.SetExcluded(messagerecords.FieldSourceID)
  707. return u
  708. }
  709. // ClearSourceID clears the value of the "source_id" field.
  710. func (u *MessageRecordsUpsert) ClearSourceID() *MessageRecordsUpsert {
  711. u.SetNull(messagerecords.FieldSourceID)
  712. return u
  713. }
  714. // SetSubSourceID sets the "sub_source_id" field.
  715. func (u *MessageRecordsUpsert) SetSubSourceID(v uint64) *MessageRecordsUpsert {
  716. u.Set(messagerecords.FieldSubSourceID, v)
  717. return u
  718. }
  719. // UpdateSubSourceID sets the "sub_source_id" field to the value that was provided on create.
  720. func (u *MessageRecordsUpsert) UpdateSubSourceID() *MessageRecordsUpsert {
  721. u.SetExcluded(messagerecords.FieldSubSourceID)
  722. return u
  723. }
  724. // ClearSubSourceID clears the value of the "sub_source_id" field.
  725. func (u *MessageRecordsUpsert) ClearSubSourceID() *MessageRecordsUpsert {
  726. u.SetNull(messagerecords.FieldSubSourceID)
  727. return u
  728. }
  729. // UpdateNewValues updates the mutable fields using the new values that were set on create except the ID field.
  730. // Using this option is equivalent to using:
  731. //
  732. // client.MessageRecords.Create().
  733. // OnConflict(
  734. // sql.ResolveWithNewValues(),
  735. // sql.ResolveWith(func(u *sql.UpdateSet) {
  736. // u.SetIgnore(messagerecords.FieldID)
  737. // }),
  738. // ).
  739. // Exec(ctx)
  740. func (u *MessageRecordsUpsertOne) UpdateNewValues() *MessageRecordsUpsertOne {
  741. u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
  742. u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
  743. if _, exists := u.create.mutation.ID(); exists {
  744. s.SetIgnore(messagerecords.FieldID)
  745. }
  746. if _, exists := u.create.mutation.CreatedAt(); exists {
  747. s.SetIgnore(messagerecords.FieldCreatedAt)
  748. }
  749. }))
  750. return u
  751. }
  752. // Ignore sets each column to itself in case of conflict.
  753. // Using this option is equivalent to using:
  754. //
  755. // client.MessageRecords.Create().
  756. // OnConflict(sql.ResolveWithIgnore()).
  757. // Exec(ctx)
  758. func (u *MessageRecordsUpsertOne) Ignore() *MessageRecordsUpsertOne {
  759. u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
  760. return u
  761. }
  762. // DoNothing configures the conflict_action to `DO NOTHING`.
  763. // Supported only by SQLite and PostgreSQL.
  764. func (u *MessageRecordsUpsertOne) DoNothing() *MessageRecordsUpsertOne {
  765. u.create.conflict = append(u.create.conflict, sql.DoNothing())
  766. return u
  767. }
  768. // Update allows overriding fields `UPDATE` values. See the MessageRecordsCreate.OnConflict
  769. // documentation for more info.
  770. func (u *MessageRecordsUpsertOne) Update(set func(*MessageRecordsUpsert)) *MessageRecordsUpsertOne {
  771. u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
  772. set(&MessageRecordsUpsert{UpdateSet: update})
  773. }))
  774. return u
  775. }
  776. // SetUpdatedAt sets the "updated_at" field.
  777. func (u *MessageRecordsUpsertOne) SetUpdatedAt(v time.Time) *MessageRecordsUpsertOne {
  778. return u.Update(func(s *MessageRecordsUpsert) {
  779. s.SetUpdatedAt(v)
  780. })
  781. }
  782. // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
  783. func (u *MessageRecordsUpsertOne) UpdateUpdatedAt() *MessageRecordsUpsertOne {
  784. return u.Update(func(s *MessageRecordsUpsert) {
  785. s.UpdateUpdatedAt()
  786. })
  787. }
  788. // SetStatus sets the "status" field.
  789. func (u *MessageRecordsUpsertOne) SetStatus(v uint8) *MessageRecordsUpsertOne {
  790. return u.Update(func(s *MessageRecordsUpsert) {
  791. s.SetStatus(v)
  792. })
  793. }
  794. // AddStatus adds v to the "status" field.
  795. func (u *MessageRecordsUpsertOne) AddStatus(v uint8) *MessageRecordsUpsertOne {
  796. return u.Update(func(s *MessageRecordsUpsert) {
  797. s.AddStatus(v)
  798. })
  799. }
  800. // UpdateStatus sets the "status" field to the value that was provided on create.
  801. func (u *MessageRecordsUpsertOne) UpdateStatus() *MessageRecordsUpsertOne {
  802. return u.Update(func(s *MessageRecordsUpsert) {
  803. s.UpdateStatus()
  804. })
  805. }
  806. // ClearStatus clears the value of the "status" field.
  807. func (u *MessageRecordsUpsertOne) ClearStatus() *MessageRecordsUpsertOne {
  808. return u.Update(func(s *MessageRecordsUpsert) {
  809. s.ClearStatus()
  810. })
  811. }
  812. // SetDeletedAt sets the "deleted_at" field.
  813. func (u *MessageRecordsUpsertOne) SetDeletedAt(v time.Time) *MessageRecordsUpsertOne {
  814. return u.Update(func(s *MessageRecordsUpsert) {
  815. s.SetDeletedAt(v)
  816. })
  817. }
  818. // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
  819. func (u *MessageRecordsUpsertOne) UpdateDeletedAt() *MessageRecordsUpsertOne {
  820. return u.Update(func(s *MessageRecordsUpsert) {
  821. s.UpdateDeletedAt()
  822. })
  823. }
  824. // ClearDeletedAt clears the value of the "deleted_at" field.
  825. func (u *MessageRecordsUpsertOne) ClearDeletedAt() *MessageRecordsUpsertOne {
  826. return u.Update(func(s *MessageRecordsUpsert) {
  827. s.ClearDeletedAt()
  828. })
  829. }
  830. // SetBotWxid sets the "bot_wxid" field.
  831. func (u *MessageRecordsUpsertOne) SetBotWxid(v string) *MessageRecordsUpsertOne {
  832. return u.Update(func(s *MessageRecordsUpsert) {
  833. s.SetBotWxid(v)
  834. })
  835. }
  836. // UpdateBotWxid sets the "bot_wxid" field to the value that was provided on create.
  837. func (u *MessageRecordsUpsertOne) UpdateBotWxid() *MessageRecordsUpsertOne {
  838. return u.Update(func(s *MessageRecordsUpsert) {
  839. s.UpdateBotWxid()
  840. })
  841. }
  842. // SetContactID sets the "contact_id" field.
  843. func (u *MessageRecordsUpsertOne) SetContactID(v uint64) *MessageRecordsUpsertOne {
  844. return u.Update(func(s *MessageRecordsUpsert) {
  845. s.SetContactID(v)
  846. })
  847. }
  848. // UpdateContactID sets the "contact_id" field to the value that was provided on create.
  849. func (u *MessageRecordsUpsertOne) UpdateContactID() *MessageRecordsUpsertOne {
  850. return u.Update(func(s *MessageRecordsUpsert) {
  851. s.UpdateContactID()
  852. })
  853. }
  854. // ClearContactID clears the value of the "contact_id" field.
  855. func (u *MessageRecordsUpsertOne) ClearContactID() *MessageRecordsUpsertOne {
  856. return u.Update(func(s *MessageRecordsUpsert) {
  857. s.ClearContactID()
  858. })
  859. }
  860. // SetContactType sets the "contact_type" field.
  861. func (u *MessageRecordsUpsertOne) SetContactType(v int) *MessageRecordsUpsertOne {
  862. return u.Update(func(s *MessageRecordsUpsert) {
  863. s.SetContactType(v)
  864. })
  865. }
  866. // AddContactType adds v to the "contact_type" field.
  867. func (u *MessageRecordsUpsertOne) AddContactType(v int) *MessageRecordsUpsertOne {
  868. return u.Update(func(s *MessageRecordsUpsert) {
  869. s.AddContactType(v)
  870. })
  871. }
  872. // UpdateContactType sets the "contact_type" field to the value that was provided on create.
  873. func (u *MessageRecordsUpsertOne) UpdateContactType() *MessageRecordsUpsertOne {
  874. return u.Update(func(s *MessageRecordsUpsert) {
  875. s.UpdateContactType()
  876. })
  877. }
  878. // SetContactWxid sets the "contact_wxid" field.
  879. func (u *MessageRecordsUpsertOne) SetContactWxid(v string) *MessageRecordsUpsertOne {
  880. return u.Update(func(s *MessageRecordsUpsert) {
  881. s.SetContactWxid(v)
  882. })
  883. }
  884. // UpdateContactWxid sets the "contact_wxid" field to the value that was provided on create.
  885. func (u *MessageRecordsUpsertOne) UpdateContactWxid() *MessageRecordsUpsertOne {
  886. return u.Update(func(s *MessageRecordsUpsert) {
  887. s.UpdateContactWxid()
  888. })
  889. }
  890. // SetContentType sets the "content_type" field.
  891. func (u *MessageRecordsUpsertOne) SetContentType(v int) *MessageRecordsUpsertOne {
  892. return u.Update(func(s *MessageRecordsUpsert) {
  893. s.SetContentType(v)
  894. })
  895. }
  896. // AddContentType adds v to the "content_type" field.
  897. func (u *MessageRecordsUpsertOne) AddContentType(v int) *MessageRecordsUpsertOne {
  898. return u.Update(func(s *MessageRecordsUpsert) {
  899. s.AddContentType(v)
  900. })
  901. }
  902. // UpdateContentType sets the "content_type" field to the value that was provided on create.
  903. func (u *MessageRecordsUpsertOne) UpdateContentType() *MessageRecordsUpsertOne {
  904. return u.Update(func(s *MessageRecordsUpsert) {
  905. s.UpdateContentType()
  906. })
  907. }
  908. // SetContent sets the "content" field.
  909. func (u *MessageRecordsUpsertOne) SetContent(v string) *MessageRecordsUpsertOne {
  910. return u.Update(func(s *MessageRecordsUpsert) {
  911. s.SetContent(v)
  912. })
  913. }
  914. // UpdateContent sets the "content" field to the value that was provided on create.
  915. func (u *MessageRecordsUpsertOne) UpdateContent() *MessageRecordsUpsertOne {
  916. return u.Update(func(s *MessageRecordsUpsert) {
  917. s.UpdateContent()
  918. })
  919. }
  920. // SetErrorDetail sets the "error_detail" field.
  921. func (u *MessageRecordsUpsertOne) SetErrorDetail(v string) *MessageRecordsUpsertOne {
  922. return u.Update(func(s *MessageRecordsUpsert) {
  923. s.SetErrorDetail(v)
  924. })
  925. }
  926. // UpdateErrorDetail sets the "error_detail" field to the value that was provided on create.
  927. func (u *MessageRecordsUpsertOne) UpdateErrorDetail() *MessageRecordsUpsertOne {
  928. return u.Update(func(s *MessageRecordsUpsert) {
  929. s.UpdateErrorDetail()
  930. })
  931. }
  932. // SetSendTime sets the "send_time" field.
  933. func (u *MessageRecordsUpsertOne) SetSendTime(v time.Time) *MessageRecordsUpsertOne {
  934. return u.Update(func(s *MessageRecordsUpsert) {
  935. s.SetSendTime(v)
  936. })
  937. }
  938. // UpdateSendTime sets the "send_time" field to the value that was provided on create.
  939. func (u *MessageRecordsUpsertOne) UpdateSendTime() *MessageRecordsUpsertOne {
  940. return u.Update(func(s *MessageRecordsUpsert) {
  941. s.UpdateSendTime()
  942. })
  943. }
  944. // ClearSendTime clears the value of the "send_time" field.
  945. func (u *MessageRecordsUpsertOne) ClearSendTime() *MessageRecordsUpsertOne {
  946. return u.Update(func(s *MessageRecordsUpsert) {
  947. s.ClearSendTime()
  948. })
  949. }
  950. // SetSourceType sets the "source_type" field.
  951. func (u *MessageRecordsUpsertOne) SetSourceType(v int) *MessageRecordsUpsertOne {
  952. return u.Update(func(s *MessageRecordsUpsert) {
  953. s.SetSourceType(v)
  954. })
  955. }
  956. // AddSourceType adds v to the "source_type" field.
  957. func (u *MessageRecordsUpsertOne) AddSourceType(v int) *MessageRecordsUpsertOne {
  958. return u.Update(func(s *MessageRecordsUpsert) {
  959. s.AddSourceType(v)
  960. })
  961. }
  962. // UpdateSourceType sets the "source_type" field to the value that was provided on create.
  963. func (u *MessageRecordsUpsertOne) UpdateSourceType() *MessageRecordsUpsertOne {
  964. return u.Update(func(s *MessageRecordsUpsert) {
  965. s.UpdateSourceType()
  966. })
  967. }
  968. // SetSourceID sets the "source_id" field.
  969. func (u *MessageRecordsUpsertOne) SetSourceID(v uint64) *MessageRecordsUpsertOne {
  970. return u.Update(func(s *MessageRecordsUpsert) {
  971. s.SetSourceID(v)
  972. })
  973. }
  974. // UpdateSourceID sets the "source_id" field to the value that was provided on create.
  975. func (u *MessageRecordsUpsertOne) UpdateSourceID() *MessageRecordsUpsertOne {
  976. return u.Update(func(s *MessageRecordsUpsert) {
  977. s.UpdateSourceID()
  978. })
  979. }
  980. // ClearSourceID clears the value of the "source_id" field.
  981. func (u *MessageRecordsUpsertOne) ClearSourceID() *MessageRecordsUpsertOne {
  982. return u.Update(func(s *MessageRecordsUpsert) {
  983. s.ClearSourceID()
  984. })
  985. }
  986. // SetSubSourceID sets the "sub_source_id" field.
  987. func (u *MessageRecordsUpsertOne) SetSubSourceID(v uint64) *MessageRecordsUpsertOne {
  988. return u.Update(func(s *MessageRecordsUpsert) {
  989. s.SetSubSourceID(v)
  990. })
  991. }
  992. // UpdateSubSourceID sets the "sub_source_id" field to the value that was provided on create.
  993. func (u *MessageRecordsUpsertOne) UpdateSubSourceID() *MessageRecordsUpsertOne {
  994. return u.Update(func(s *MessageRecordsUpsert) {
  995. s.UpdateSubSourceID()
  996. })
  997. }
  998. // ClearSubSourceID clears the value of the "sub_source_id" field.
  999. func (u *MessageRecordsUpsertOne) ClearSubSourceID() *MessageRecordsUpsertOne {
  1000. return u.Update(func(s *MessageRecordsUpsert) {
  1001. s.ClearSubSourceID()
  1002. })
  1003. }
  1004. // Exec executes the query.
  1005. func (u *MessageRecordsUpsertOne) Exec(ctx context.Context) error {
  1006. if len(u.create.conflict) == 0 {
  1007. return errors.New("ent: missing options for MessageRecordsCreate.OnConflict")
  1008. }
  1009. return u.create.Exec(ctx)
  1010. }
  1011. // ExecX is like Exec, but panics if an error occurs.
  1012. func (u *MessageRecordsUpsertOne) ExecX(ctx context.Context) {
  1013. if err := u.create.Exec(ctx); err != nil {
  1014. panic(err)
  1015. }
  1016. }
  1017. // Exec executes the UPSERT query and returns the inserted/updated ID.
  1018. func (u *MessageRecordsUpsertOne) ID(ctx context.Context) (id uint64, err error) {
  1019. node, err := u.create.Save(ctx)
  1020. if err != nil {
  1021. return id, err
  1022. }
  1023. return node.ID, nil
  1024. }
  1025. // IDX is like ID, but panics if an error occurs.
  1026. func (u *MessageRecordsUpsertOne) IDX(ctx context.Context) uint64 {
  1027. id, err := u.ID(ctx)
  1028. if err != nil {
  1029. panic(err)
  1030. }
  1031. return id
  1032. }
  1033. // MessageRecordsCreateBulk is the builder for creating many MessageRecords entities in bulk.
  1034. type MessageRecordsCreateBulk struct {
  1035. config
  1036. err error
  1037. builders []*MessageRecordsCreate
  1038. conflict []sql.ConflictOption
  1039. }
  1040. // Save creates the MessageRecords entities in the database.
  1041. func (mrcb *MessageRecordsCreateBulk) Save(ctx context.Context) ([]*MessageRecords, error) {
  1042. if mrcb.err != nil {
  1043. return nil, mrcb.err
  1044. }
  1045. specs := make([]*sqlgraph.CreateSpec, len(mrcb.builders))
  1046. nodes := make([]*MessageRecords, len(mrcb.builders))
  1047. mutators := make([]Mutator, len(mrcb.builders))
  1048. for i := range mrcb.builders {
  1049. func(i int, root context.Context) {
  1050. builder := mrcb.builders[i]
  1051. builder.defaults()
  1052. var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
  1053. mutation, ok := m.(*MessageRecordsMutation)
  1054. if !ok {
  1055. return nil, fmt.Errorf("unexpected mutation type %T", m)
  1056. }
  1057. if err := builder.check(); err != nil {
  1058. return nil, err
  1059. }
  1060. builder.mutation = mutation
  1061. var err error
  1062. nodes[i], specs[i] = builder.createSpec()
  1063. if i < len(mutators)-1 {
  1064. _, err = mutators[i+1].Mutate(root, mrcb.builders[i+1].mutation)
  1065. } else {
  1066. spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
  1067. spec.OnConflict = mrcb.conflict
  1068. // Invoke the actual operation on the latest mutation in the chain.
  1069. if err = sqlgraph.BatchCreate(ctx, mrcb.driver, spec); err != nil {
  1070. if sqlgraph.IsConstraintError(err) {
  1071. err = &ConstraintError{msg: err.Error(), wrap: err}
  1072. }
  1073. }
  1074. }
  1075. if err != nil {
  1076. return nil, err
  1077. }
  1078. mutation.id = &nodes[i].ID
  1079. if specs[i].ID.Value != nil && nodes[i].ID == 0 {
  1080. id := specs[i].ID.Value.(int64)
  1081. nodes[i].ID = uint64(id)
  1082. }
  1083. mutation.done = true
  1084. return nodes[i], nil
  1085. })
  1086. for i := len(builder.hooks) - 1; i >= 0; i-- {
  1087. mut = builder.hooks[i](mut)
  1088. }
  1089. mutators[i] = mut
  1090. }(i, ctx)
  1091. }
  1092. if len(mutators) > 0 {
  1093. if _, err := mutators[0].Mutate(ctx, mrcb.builders[0].mutation); err != nil {
  1094. return nil, err
  1095. }
  1096. }
  1097. return nodes, nil
  1098. }
  1099. // SaveX is like Save, but panics if an error occurs.
  1100. func (mrcb *MessageRecordsCreateBulk) SaveX(ctx context.Context) []*MessageRecords {
  1101. v, err := mrcb.Save(ctx)
  1102. if err != nil {
  1103. panic(err)
  1104. }
  1105. return v
  1106. }
  1107. // Exec executes the query.
  1108. func (mrcb *MessageRecordsCreateBulk) Exec(ctx context.Context) error {
  1109. _, err := mrcb.Save(ctx)
  1110. return err
  1111. }
  1112. // ExecX is like Exec, but panics if an error occurs.
  1113. func (mrcb *MessageRecordsCreateBulk) ExecX(ctx context.Context) {
  1114. if err := mrcb.Exec(ctx); err != nil {
  1115. panic(err)
  1116. }
  1117. }
  1118. // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
  1119. // of the `INSERT` statement. For example:
  1120. //
  1121. // client.MessageRecords.CreateBulk(builders...).
  1122. // OnConflict(
  1123. // // Update the row with the new values
  1124. // // the was proposed for insertion.
  1125. // sql.ResolveWithNewValues(),
  1126. // ).
  1127. // // Override some of the fields with custom
  1128. // // update values.
  1129. // Update(func(u *ent.MessageRecordsUpsert) {
  1130. // SetCreatedAt(v+v).
  1131. // }).
  1132. // Exec(ctx)
  1133. func (mrcb *MessageRecordsCreateBulk) OnConflict(opts ...sql.ConflictOption) *MessageRecordsUpsertBulk {
  1134. mrcb.conflict = opts
  1135. return &MessageRecordsUpsertBulk{
  1136. create: mrcb,
  1137. }
  1138. }
  1139. // OnConflictColumns calls `OnConflict` and configures the columns
  1140. // as conflict target. Using this option is equivalent to using:
  1141. //
  1142. // client.MessageRecords.Create().
  1143. // OnConflict(sql.ConflictColumns(columns...)).
  1144. // Exec(ctx)
  1145. func (mrcb *MessageRecordsCreateBulk) OnConflictColumns(columns ...string) *MessageRecordsUpsertBulk {
  1146. mrcb.conflict = append(mrcb.conflict, sql.ConflictColumns(columns...))
  1147. return &MessageRecordsUpsertBulk{
  1148. create: mrcb,
  1149. }
  1150. }
  1151. // MessageRecordsUpsertBulk is the builder for "upsert"-ing
  1152. // a bulk of MessageRecords nodes.
  1153. type MessageRecordsUpsertBulk struct {
  1154. create *MessageRecordsCreateBulk
  1155. }
  1156. // UpdateNewValues updates the mutable fields using the new values that
  1157. // were set on create. Using this option is equivalent to using:
  1158. //
  1159. // client.MessageRecords.Create().
  1160. // OnConflict(
  1161. // sql.ResolveWithNewValues(),
  1162. // sql.ResolveWith(func(u *sql.UpdateSet) {
  1163. // u.SetIgnore(messagerecords.FieldID)
  1164. // }),
  1165. // ).
  1166. // Exec(ctx)
  1167. func (u *MessageRecordsUpsertBulk) UpdateNewValues() *MessageRecordsUpsertBulk {
  1168. u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
  1169. u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
  1170. for _, b := range u.create.builders {
  1171. if _, exists := b.mutation.ID(); exists {
  1172. s.SetIgnore(messagerecords.FieldID)
  1173. }
  1174. if _, exists := b.mutation.CreatedAt(); exists {
  1175. s.SetIgnore(messagerecords.FieldCreatedAt)
  1176. }
  1177. }
  1178. }))
  1179. return u
  1180. }
  1181. // Ignore sets each column to itself in case of conflict.
  1182. // Using this option is equivalent to using:
  1183. //
  1184. // client.MessageRecords.Create().
  1185. // OnConflict(sql.ResolveWithIgnore()).
  1186. // Exec(ctx)
  1187. func (u *MessageRecordsUpsertBulk) Ignore() *MessageRecordsUpsertBulk {
  1188. u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
  1189. return u
  1190. }
  1191. // DoNothing configures the conflict_action to `DO NOTHING`.
  1192. // Supported only by SQLite and PostgreSQL.
  1193. func (u *MessageRecordsUpsertBulk) DoNothing() *MessageRecordsUpsertBulk {
  1194. u.create.conflict = append(u.create.conflict, sql.DoNothing())
  1195. return u
  1196. }
  1197. // Update allows overriding fields `UPDATE` values. See the MessageRecordsCreateBulk.OnConflict
  1198. // documentation for more info.
  1199. func (u *MessageRecordsUpsertBulk) Update(set func(*MessageRecordsUpsert)) *MessageRecordsUpsertBulk {
  1200. u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
  1201. set(&MessageRecordsUpsert{UpdateSet: update})
  1202. }))
  1203. return u
  1204. }
  1205. // SetUpdatedAt sets the "updated_at" field.
  1206. func (u *MessageRecordsUpsertBulk) SetUpdatedAt(v time.Time) *MessageRecordsUpsertBulk {
  1207. return u.Update(func(s *MessageRecordsUpsert) {
  1208. s.SetUpdatedAt(v)
  1209. })
  1210. }
  1211. // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
  1212. func (u *MessageRecordsUpsertBulk) UpdateUpdatedAt() *MessageRecordsUpsertBulk {
  1213. return u.Update(func(s *MessageRecordsUpsert) {
  1214. s.UpdateUpdatedAt()
  1215. })
  1216. }
  1217. // SetStatus sets the "status" field.
  1218. func (u *MessageRecordsUpsertBulk) SetStatus(v uint8) *MessageRecordsUpsertBulk {
  1219. return u.Update(func(s *MessageRecordsUpsert) {
  1220. s.SetStatus(v)
  1221. })
  1222. }
  1223. // AddStatus adds v to the "status" field.
  1224. func (u *MessageRecordsUpsertBulk) AddStatus(v uint8) *MessageRecordsUpsertBulk {
  1225. return u.Update(func(s *MessageRecordsUpsert) {
  1226. s.AddStatus(v)
  1227. })
  1228. }
  1229. // UpdateStatus sets the "status" field to the value that was provided on create.
  1230. func (u *MessageRecordsUpsertBulk) UpdateStatus() *MessageRecordsUpsertBulk {
  1231. return u.Update(func(s *MessageRecordsUpsert) {
  1232. s.UpdateStatus()
  1233. })
  1234. }
  1235. // ClearStatus clears the value of the "status" field.
  1236. func (u *MessageRecordsUpsertBulk) ClearStatus() *MessageRecordsUpsertBulk {
  1237. return u.Update(func(s *MessageRecordsUpsert) {
  1238. s.ClearStatus()
  1239. })
  1240. }
  1241. // SetDeletedAt sets the "deleted_at" field.
  1242. func (u *MessageRecordsUpsertBulk) SetDeletedAt(v time.Time) *MessageRecordsUpsertBulk {
  1243. return u.Update(func(s *MessageRecordsUpsert) {
  1244. s.SetDeletedAt(v)
  1245. })
  1246. }
  1247. // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
  1248. func (u *MessageRecordsUpsertBulk) UpdateDeletedAt() *MessageRecordsUpsertBulk {
  1249. return u.Update(func(s *MessageRecordsUpsert) {
  1250. s.UpdateDeletedAt()
  1251. })
  1252. }
  1253. // ClearDeletedAt clears the value of the "deleted_at" field.
  1254. func (u *MessageRecordsUpsertBulk) ClearDeletedAt() *MessageRecordsUpsertBulk {
  1255. return u.Update(func(s *MessageRecordsUpsert) {
  1256. s.ClearDeletedAt()
  1257. })
  1258. }
  1259. // SetBotWxid sets the "bot_wxid" field.
  1260. func (u *MessageRecordsUpsertBulk) SetBotWxid(v string) *MessageRecordsUpsertBulk {
  1261. return u.Update(func(s *MessageRecordsUpsert) {
  1262. s.SetBotWxid(v)
  1263. })
  1264. }
  1265. // UpdateBotWxid sets the "bot_wxid" field to the value that was provided on create.
  1266. func (u *MessageRecordsUpsertBulk) UpdateBotWxid() *MessageRecordsUpsertBulk {
  1267. return u.Update(func(s *MessageRecordsUpsert) {
  1268. s.UpdateBotWxid()
  1269. })
  1270. }
  1271. // SetContactID sets the "contact_id" field.
  1272. func (u *MessageRecordsUpsertBulk) SetContactID(v uint64) *MessageRecordsUpsertBulk {
  1273. return u.Update(func(s *MessageRecordsUpsert) {
  1274. s.SetContactID(v)
  1275. })
  1276. }
  1277. // UpdateContactID sets the "contact_id" field to the value that was provided on create.
  1278. func (u *MessageRecordsUpsertBulk) UpdateContactID() *MessageRecordsUpsertBulk {
  1279. return u.Update(func(s *MessageRecordsUpsert) {
  1280. s.UpdateContactID()
  1281. })
  1282. }
  1283. // ClearContactID clears the value of the "contact_id" field.
  1284. func (u *MessageRecordsUpsertBulk) ClearContactID() *MessageRecordsUpsertBulk {
  1285. return u.Update(func(s *MessageRecordsUpsert) {
  1286. s.ClearContactID()
  1287. })
  1288. }
  1289. // SetContactType sets the "contact_type" field.
  1290. func (u *MessageRecordsUpsertBulk) SetContactType(v int) *MessageRecordsUpsertBulk {
  1291. return u.Update(func(s *MessageRecordsUpsert) {
  1292. s.SetContactType(v)
  1293. })
  1294. }
  1295. // AddContactType adds v to the "contact_type" field.
  1296. func (u *MessageRecordsUpsertBulk) AddContactType(v int) *MessageRecordsUpsertBulk {
  1297. return u.Update(func(s *MessageRecordsUpsert) {
  1298. s.AddContactType(v)
  1299. })
  1300. }
  1301. // UpdateContactType sets the "contact_type" field to the value that was provided on create.
  1302. func (u *MessageRecordsUpsertBulk) UpdateContactType() *MessageRecordsUpsertBulk {
  1303. return u.Update(func(s *MessageRecordsUpsert) {
  1304. s.UpdateContactType()
  1305. })
  1306. }
  1307. // SetContactWxid sets the "contact_wxid" field.
  1308. func (u *MessageRecordsUpsertBulk) SetContactWxid(v string) *MessageRecordsUpsertBulk {
  1309. return u.Update(func(s *MessageRecordsUpsert) {
  1310. s.SetContactWxid(v)
  1311. })
  1312. }
  1313. // UpdateContactWxid sets the "contact_wxid" field to the value that was provided on create.
  1314. func (u *MessageRecordsUpsertBulk) UpdateContactWxid() *MessageRecordsUpsertBulk {
  1315. return u.Update(func(s *MessageRecordsUpsert) {
  1316. s.UpdateContactWxid()
  1317. })
  1318. }
  1319. // SetContentType sets the "content_type" field.
  1320. func (u *MessageRecordsUpsertBulk) SetContentType(v int) *MessageRecordsUpsertBulk {
  1321. return u.Update(func(s *MessageRecordsUpsert) {
  1322. s.SetContentType(v)
  1323. })
  1324. }
  1325. // AddContentType adds v to the "content_type" field.
  1326. func (u *MessageRecordsUpsertBulk) AddContentType(v int) *MessageRecordsUpsertBulk {
  1327. return u.Update(func(s *MessageRecordsUpsert) {
  1328. s.AddContentType(v)
  1329. })
  1330. }
  1331. // UpdateContentType sets the "content_type" field to the value that was provided on create.
  1332. func (u *MessageRecordsUpsertBulk) UpdateContentType() *MessageRecordsUpsertBulk {
  1333. return u.Update(func(s *MessageRecordsUpsert) {
  1334. s.UpdateContentType()
  1335. })
  1336. }
  1337. // SetContent sets the "content" field.
  1338. func (u *MessageRecordsUpsertBulk) SetContent(v string) *MessageRecordsUpsertBulk {
  1339. return u.Update(func(s *MessageRecordsUpsert) {
  1340. s.SetContent(v)
  1341. })
  1342. }
  1343. // UpdateContent sets the "content" field to the value that was provided on create.
  1344. func (u *MessageRecordsUpsertBulk) UpdateContent() *MessageRecordsUpsertBulk {
  1345. return u.Update(func(s *MessageRecordsUpsert) {
  1346. s.UpdateContent()
  1347. })
  1348. }
  1349. // SetErrorDetail sets the "error_detail" field.
  1350. func (u *MessageRecordsUpsertBulk) SetErrorDetail(v string) *MessageRecordsUpsertBulk {
  1351. return u.Update(func(s *MessageRecordsUpsert) {
  1352. s.SetErrorDetail(v)
  1353. })
  1354. }
  1355. // UpdateErrorDetail sets the "error_detail" field to the value that was provided on create.
  1356. func (u *MessageRecordsUpsertBulk) UpdateErrorDetail() *MessageRecordsUpsertBulk {
  1357. return u.Update(func(s *MessageRecordsUpsert) {
  1358. s.UpdateErrorDetail()
  1359. })
  1360. }
  1361. // SetSendTime sets the "send_time" field.
  1362. func (u *MessageRecordsUpsertBulk) SetSendTime(v time.Time) *MessageRecordsUpsertBulk {
  1363. return u.Update(func(s *MessageRecordsUpsert) {
  1364. s.SetSendTime(v)
  1365. })
  1366. }
  1367. // UpdateSendTime sets the "send_time" field to the value that was provided on create.
  1368. func (u *MessageRecordsUpsertBulk) UpdateSendTime() *MessageRecordsUpsertBulk {
  1369. return u.Update(func(s *MessageRecordsUpsert) {
  1370. s.UpdateSendTime()
  1371. })
  1372. }
  1373. // ClearSendTime clears the value of the "send_time" field.
  1374. func (u *MessageRecordsUpsertBulk) ClearSendTime() *MessageRecordsUpsertBulk {
  1375. return u.Update(func(s *MessageRecordsUpsert) {
  1376. s.ClearSendTime()
  1377. })
  1378. }
  1379. // SetSourceType sets the "source_type" field.
  1380. func (u *MessageRecordsUpsertBulk) SetSourceType(v int) *MessageRecordsUpsertBulk {
  1381. return u.Update(func(s *MessageRecordsUpsert) {
  1382. s.SetSourceType(v)
  1383. })
  1384. }
  1385. // AddSourceType adds v to the "source_type" field.
  1386. func (u *MessageRecordsUpsertBulk) AddSourceType(v int) *MessageRecordsUpsertBulk {
  1387. return u.Update(func(s *MessageRecordsUpsert) {
  1388. s.AddSourceType(v)
  1389. })
  1390. }
  1391. // UpdateSourceType sets the "source_type" field to the value that was provided on create.
  1392. func (u *MessageRecordsUpsertBulk) UpdateSourceType() *MessageRecordsUpsertBulk {
  1393. return u.Update(func(s *MessageRecordsUpsert) {
  1394. s.UpdateSourceType()
  1395. })
  1396. }
  1397. // SetSourceID sets the "source_id" field.
  1398. func (u *MessageRecordsUpsertBulk) SetSourceID(v uint64) *MessageRecordsUpsertBulk {
  1399. return u.Update(func(s *MessageRecordsUpsert) {
  1400. s.SetSourceID(v)
  1401. })
  1402. }
  1403. // UpdateSourceID sets the "source_id" field to the value that was provided on create.
  1404. func (u *MessageRecordsUpsertBulk) UpdateSourceID() *MessageRecordsUpsertBulk {
  1405. return u.Update(func(s *MessageRecordsUpsert) {
  1406. s.UpdateSourceID()
  1407. })
  1408. }
  1409. // ClearSourceID clears the value of the "source_id" field.
  1410. func (u *MessageRecordsUpsertBulk) ClearSourceID() *MessageRecordsUpsertBulk {
  1411. return u.Update(func(s *MessageRecordsUpsert) {
  1412. s.ClearSourceID()
  1413. })
  1414. }
  1415. // SetSubSourceID sets the "sub_source_id" field.
  1416. func (u *MessageRecordsUpsertBulk) SetSubSourceID(v uint64) *MessageRecordsUpsertBulk {
  1417. return u.Update(func(s *MessageRecordsUpsert) {
  1418. s.SetSubSourceID(v)
  1419. })
  1420. }
  1421. // UpdateSubSourceID sets the "sub_source_id" field to the value that was provided on create.
  1422. func (u *MessageRecordsUpsertBulk) UpdateSubSourceID() *MessageRecordsUpsertBulk {
  1423. return u.Update(func(s *MessageRecordsUpsert) {
  1424. s.UpdateSubSourceID()
  1425. })
  1426. }
  1427. // ClearSubSourceID clears the value of the "sub_source_id" field.
  1428. func (u *MessageRecordsUpsertBulk) ClearSubSourceID() *MessageRecordsUpsertBulk {
  1429. return u.Update(func(s *MessageRecordsUpsert) {
  1430. s.ClearSubSourceID()
  1431. })
  1432. }
  1433. // Exec executes the query.
  1434. func (u *MessageRecordsUpsertBulk) Exec(ctx context.Context) error {
  1435. if u.create.err != nil {
  1436. return u.create.err
  1437. }
  1438. for i, b := range u.create.builders {
  1439. if len(b.conflict) != 0 {
  1440. return fmt.Errorf("ent: OnConflict was set for builder %d. Set it on the MessageRecordsCreateBulk instead", i)
  1441. }
  1442. }
  1443. if len(u.create.conflict) == 0 {
  1444. return errors.New("ent: missing options for MessageRecordsCreateBulk.OnConflict")
  1445. }
  1446. return u.create.Exec(ctx)
  1447. }
  1448. // ExecX is like Exec, but panics if an error occurs.
  1449. func (u *MessageRecordsUpsertBulk) ExecX(ctx context.Context) {
  1450. if err := u.create.Exec(ctx); err != nil {
  1451. panic(err)
  1452. }
  1453. }