messagerecords_create.go 56 KB

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