wx_create.go 44 KB

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