wx_create.go 40 KB

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