xunji_create.go 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303
  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/xunji"
  9. "entgo.io/ent/dialect/sql"
  10. "entgo.io/ent/dialect/sql/sqlgraph"
  11. "entgo.io/ent/schema/field"
  12. )
  13. // XunjiCreate is the builder for creating a Xunji entity.
  14. type XunjiCreate struct {
  15. config
  16. mutation *XunjiMutation
  17. hooks []Hook
  18. conflict []sql.ConflictOption
  19. }
  20. // SetCreatedAt sets the "created_at" field.
  21. func (xc *XunjiCreate) SetCreatedAt(t time.Time) *XunjiCreate {
  22. xc.mutation.SetCreatedAt(t)
  23. return xc
  24. }
  25. // SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
  26. func (xc *XunjiCreate) SetNillableCreatedAt(t *time.Time) *XunjiCreate {
  27. if t != nil {
  28. xc.SetCreatedAt(*t)
  29. }
  30. return xc
  31. }
  32. // SetUpdatedAt sets the "updated_at" field.
  33. func (xc *XunjiCreate) SetUpdatedAt(t time.Time) *XunjiCreate {
  34. xc.mutation.SetUpdatedAt(t)
  35. return xc
  36. }
  37. // SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
  38. func (xc *XunjiCreate) SetNillableUpdatedAt(t *time.Time) *XunjiCreate {
  39. if t != nil {
  40. xc.SetUpdatedAt(*t)
  41. }
  42. return xc
  43. }
  44. // SetStatus sets the "status" field.
  45. func (xc *XunjiCreate) SetStatus(u uint8) *XunjiCreate {
  46. xc.mutation.SetStatus(u)
  47. return xc
  48. }
  49. // SetNillableStatus sets the "status" field if the given value is not nil.
  50. func (xc *XunjiCreate) SetNillableStatus(u *uint8) *XunjiCreate {
  51. if u != nil {
  52. xc.SetStatus(*u)
  53. }
  54. return xc
  55. }
  56. // SetDeletedAt sets the "deleted_at" field.
  57. func (xc *XunjiCreate) SetDeletedAt(t time.Time) *XunjiCreate {
  58. xc.mutation.SetDeletedAt(t)
  59. return xc
  60. }
  61. // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
  62. func (xc *XunjiCreate) SetNillableDeletedAt(t *time.Time) *XunjiCreate {
  63. if t != nil {
  64. xc.SetDeletedAt(*t)
  65. }
  66. return xc
  67. }
  68. // SetAppKey sets the "app_key" field.
  69. func (xc *XunjiCreate) SetAppKey(s string) *XunjiCreate {
  70. xc.mutation.SetAppKey(s)
  71. return xc
  72. }
  73. // SetAppSecret sets the "app_secret" field.
  74. func (xc *XunjiCreate) SetAppSecret(s string) *XunjiCreate {
  75. xc.mutation.SetAppSecret(s)
  76. return xc
  77. }
  78. // SetToken sets the "token" field.
  79. func (xc *XunjiCreate) SetToken(s string) *XunjiCreate {
  80. xc.mutation.SetToken(s)
  81. return xc
  82. }
  83. // SetEncodingKey sets the "encoding_key" field.
  84. func (xc *XunjiCreate) SetEncodingKey(s string) *XunjiCreate {
  85. xc.mutation.SetEncodingKey(s)
  86. return xc
  87. }
  88. // SetAgentID sets the "agent_id" field.
  89. func (xc *XunjiCreate) SetAgentID(u uint64) *XunjiCreate {
  90. xc.mutation.SetAgentID(u)
  91. return xc
  92. }
  93. // SetOrganizationID sets the "organization_id" field.
  94. func (xc *XunjiCreate) SetOrganizationID(u uint64) *XunjiCreate {
  95. xc.mutation.SetOrganizationID(u)
  96. return xc
  97. }
  98. // SetWxid sets the "wxid" field.
  99. func (xc *XunjiCreate) SetWxid(s string) *XunjiCreate {
  100. xc.mutation.SetWxid(s)
  101. return xc
  102. }
  103. // SetAPIBase sets the "api_base" field.
  104. func (xc *XunjiCreate) SetAPIBase(s string) *XunjiCreate {
  105. xc.mutation.SetAPIBase(s)
  106. return xc
  107. }
  108. // SetNillableAPIBase sets the "api_base" field if the given value is not nil.
  109. func (xc *XunjiCreate) SetNillableAPIBase(s *string) *XunjiCreate {
  110. if s != nil {
  111. xc.SetAPIBase(*s)
  112. }
  113. return xc
  114. }
  115. // SetAPIKey sets the "api_key" field.
  116. func (xc *XunjiCreate) SetAPIKey(s string) *XunjiCreate {
  117. xc.mutation.SetAPIKey(s)
  118. return xc
  119. }
  120. // SetNillableAPIKey sets the "api_key" field if the given value is not nil.
  121. func (xc *XunjiCreate) SetNillableAPIKey(s *string) *XunjiCreate {
  122. if s != nil {
  123. xc.SetAPIKey(*s)
  124. }
  125. return xc
  126. }
  127. // SetID sets the "id" field.
  128. func (xc *XunjiCreate) SetID(u uint64) *XunjiCreate {
  129. xc.mutation.SetID(u)
  130. return xc
  131. }
  132. // Mutation returns the XunjiMutation object of the builder.
  133. func (xc *XunjiCreate) Mutation() *XunjiMutation {
  134. return xc.mutation
  135. }
  136. // Save creates the Xunji in the database.
  137. func (xc *XunjiCreate) Save(ctx context.Context) (*Xunji, error) {
  138. if err := xc.defaults(); err != nil {
  139. return nil, err
  140. }
  141. return withHooks(ctx, xc.sqlSave, xc.mutation, xc.hooks)
  142. }
  143. // SaveX calls Save and panics if Save returns an error.
  144. func (xc *XunjiCreate) SaveX(ctx context.Context) *Xunji {
  145. v, err := xc.Save(ctx)
  146. if err != nil {
  147. panic(err)
  148. }
  149. return v
  150. }
  151. // Exec executes the query.
  152. func (xc *XunjiCreate) Exec(ctx context.Context) error {
  153. _, err := xc.Save(ctx)
  154. return err
  155. }
  156. // ExecX is like Exec, but panics if an error occurs.
  157. func (xc *XunjiCreate) ExecX(ctx context.Context) {
  158. if err := xc.Exec(ctx); err != nil {
  159. panic(err)
  160. }
  161. }
  162. // defaults sets the default values of the builder before save.
  163. func (xc *XunjiCreate) defaults() error {
  164. if _, ok := xc.mutation.CreatedAt(); !ok {
  165. if xunji.DefaultCreatedAt == nil {
  166. return fmt.Errorf("ent: uninitialized xunji.DefaultCreatedAt (forgotten import ent/runtime?)")
  167. }
  168. v := xunji.DefaultCreatedAt()
  169. xc.mutation.SetCreatedAt(v)
  170. }
  171. if _, ok := xc.mutation.UpdatedAt(); !ok {
  172. if xunji.DefaultUpdatedAt == nil {
  173. return fmt.Errorf("ent: uninitialized xunji.DefaultUpdatedAt (forgotten import ent/runtime?)")
  174. }
  175. v := xunji.DefaultUpdatedAt()
  176. xc.mutation.SetUpdatedAt(v)
  177. }
  178. if _, ok := xc.mutation.Status(); !ok {
  179. v := xunji.DefaultStatus
  180. xc.mutation.SetStatus(v)
  181. }
  182. if _, ok := xc.mutation.APIBase(); !ok {
  183. v := xunji.DefaultAPIBase
  184. xc.mutation.SetAPIBase(v)
  185. }
  186. if _, ok := xc.mutation.APIKey(); !ok {
  187. v := xunji.DefaultAPIKey
  188. xc.mutation.SetAPIKey(v)
  189. }
  190. return nil
  191. }
  192. // check runs all checks and user-defined validators on the builder.
  193. func (xc *XunjiCreate) check() error {
  194. if _, ok := xc.mutation.CreatedAt(); !ok {
  195. return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "Xunji.created_at"`)}
  196. }
  197. if _, ok := xc.mutation.UpdatedAt(); !ok {
  198. return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "Xunji.updated_at"`)}
  199. }
  200. if _, ok := xc.mutation.AppKey(); !ok {
  201. return &ValidationError{Name: "app_key", err: errors.New(`ent: missing required field "Xunji.app_key"`)}
  202. }
  203. if _, ok := xc.mutation.AppSecret(); !ok {
  204. return &ValidationError{Name: "app_secret", err: errors.New(`ent: missing required field "Xunji.app_secret"`)}
  205. }
  206. if _, ok := xc.mutation.Token(); !ok {
  207. return &ValidationError{Name: "token", err: errors.New(`ent: missing required field "Xunji.token"`)}
  208. }
  209. if _, ok := xc.mutation.EncodingKey(); !ok {
  210. return &ValidationError{Name: "encoding_key", err: errors.New(`ent: missing required field "Xunji.encoding_key"`)}
  211. }
  212. if _, ok := xc.mutation.AgentID(); !ok {
  213. return &ValidationError{Name: "agent_id", err: errors.New(`ent: missing required field "Xunji.agent_id"`)}
  214. }
  215. if _, ok := xc.mutation.OrganizationID(); !ok {
  216. return &ValidationError{Name: "organization_id", err: errors.New(`ent: missing required field "Xunji.organization_id"`)}
  217. }
  218. if v, ok := xc.mutation.OrganizationID(); ok {
  219. if err := xunji.OrganizationIDValidator(v); err != nil {
  220. return &ValidationError{Name: "organization_id", err: fmt.Errorf(`ent: validator failed for field "Xunji.organization_id": %w`, err)}
  221. }
  222. }
  223. if _, ok := xc.mutation.Wxid(); !ok {
  224. return &ValidationError{Name: "wxid", err: errors.New(`ent: missing required field "Xunji.wxid"`)}
  225. }
  226. return nil
  227. }
  228. func (xc *XunjiCreate) sqlSave(ctx context.Context) (*Xunji, error) {
  229. if err := xc.check(); err != nil {
  230. return nil, err
  231. }
  232. _node, _spec := xc.createSpec()
  233. if err := sqlgraph.CreateNode(ctx, xc.driver, _spec); err != nil {
  234. if sqlgraph.IsConstraintError(err) {
  235. err = &ConstraintError{msg: err.Error(), wrap: err}
  236. }
  237. return nil, err
  238. }
  239. if _spec.ID.Value != _node.ID {
  240. id := _spec.ID.Value.(int64)
  241. _node.ID = uint64(id)
  242. }
  243. xc.mutation.id = &_node.ID
  244. xc.mutation.done = true
  245. return _node, nil
  246. }
  247. func (xc *XunjiCreate) createSpec() (*Xunji, *sqlgraph.CreateSpec) {
  248. var (
  249. _node = &Xunji{config: xc.config}
  250. _spec = sqlgraph.NewCreateSpec(xunji.Table, sqlgraph.NewFieldSpec(xunji.FieldID, field.TypeUint64))
  251. )
  252. _spec.OnConflict = xc.conflict
  253. if id, ok := xc.mutation.ID(); ok {
  254. _node.ID = id
  255. _spec.ID.Value = id
  256. }
  257. if value, ok := xc.mutation.CreatedAt(); ok {
  258. _spec.SetField(xunji.FieldCreatedAt, field.TypeTime, value)
  259. _node.CreatedAt = value
  260. }
  261. if value, ok := xc.mutation.UpdatedAt(); ok {
  262. _spec.SetField(xunji.FieldUpdatedAt, field.TypeTime, value)
  263. _node.UpdatedAt = value
  264. }
  265. if value, ok := xc.mutation.Status(); ok {
  266. _spec.SetField(xunji.FieldStatus, field.TypeUint8, value)
  267. _node.Status = value
  268. }
  269. if value, ok := xc.mutation.DeletedAt(); ok {
  270. _spec.SetField(xunji.FieldDeletedAt, field.TypeTime, value)
  271. _node.DeletedAt = value
  272. }
  273. if value, ok := xc.mutation.AppKey(); ok {
  274. _spec.SetField(xunji.FieldAppKey, field.TypeString, value)
  275. _node.AppKey = value
  276. }
  277. if value, ok := xc.mutation.AppSecret(); ok {
  278. _spec.SetField(xunji.FieldAppSecret, field.TypeString, value)
  279. _node.AppSecret = value
  280. }
  281. if value, ok := xc.mutation.Token(); ok {
  282. _spec.SetField(xunji.FieldToken, field.TypeString, value)
  283. _node.Token = value
  284. }
  285. if value, ok := xc.mutation.EncodingKey(); ok {
  286. _spec.SetField(xunji.FieldEncodingKey, field.TypeString, value)
  287. _node.EncodingKey = value
  288. }
  289. if value, ok := xc.mutation.AgentID(); ok {
  290. _spec.SetField(xunji.FieldAgentID, field.TypeUint64, value)
  291. _node.AgentID = value
  292. }
  293. if value, ok := xc.mutation.OrganizationID(); ok {
  294. _spec.SetField(xunji.FieldOrganizationID, field.TypeUint64, value)
  295. _node.OrganizationID = value
  296. }
  297. if value, ok := xc.mutation.Wxid(); ok {
  298. _spec.SetField(xunji.FieldWxid, field.TypeString, value)
  299. _node.Wxid = value
  300. }
  301. if value, ok := xc.mutation.APIBase(); ok {
  302. _spec.SetField(xunji.FieldAPIBase, field.TypeString, value)
  303. _node.APIBase = value
  304. }
  305. if value, ok := xc.mutation.APIKey(); ok {
  306. _spec.SetField(xunji.FieldAPIKey, field.TypeString, value)
  307. _node.APIKey = value
  308. }
  309. return _node, _spec
  310. }
  311. // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
  312. // of the `INSERT` statement. For example:
  313. //
  314. // client.Xunji.Create().
  315. // SetCreatedAt(v).
  316. // OnConflict(
  317. // // Update the row with the new values
  318. // // the was proposed for insertion.
  319. // sql.ResolveWithNewValues(),
  320. // ).
  321. // // Override some of the fields with custom
  322. // // update values.
  323. // Update(func(u *ent.XunjiUpsert) {
  324. // SetCreatedAt(v+v).
  325. // }).
  326. // Exec(ctx)
  327. func (xc *XunjiCreate) OnConflict(opts ...sql.ConflictOption) *XunjiUpsertOne {
  328. xc.conflict = opts
  329. return &XunjiUpsertOne{
  330. create: xc,
  331. }
  332. }
  333. // OnConflictColumns calls `OnConflict` and configures the columns
  334. // as conflict target. Using this option is equivalent to using:
  335. //
  336. // client.Xunji.Create().
  337. // OnConflict(sql.ConflictColumns(columns...)).
  338. // Exec(ctx)
  339. func (xc *XunjiCreate) OnConflictColumns(columns ...string) *XunjiUpsertOne {
  340. xc.conflict = append(xc.conflict, sql.ConflictColumns(columns...))
  341. return &XunjiUpsertOne{
  342. create: xc,
  343. }
  344. }
  345. type (
  346. // XunjiUpsertOne is the builder for "upsert"-ing
  347. // one Xunji node.
  348. XunjiUpsertOne struct {
  349. create *XunjiCreate
  350. }
  351. // XunjiUpsert is the "OnConflict" setter.
  352. XunjiUpsert struct {
  353. *sql.UpdateSet
  354. }
  355. )
  356. // SetUpdatedAt sets the "updated_at" field.
  357. func (u *XunjiUpsert) SetUpdatedAt(v time.Time) *XunjiUpsert {
  358. u.Set(xunji.FieldUpdatedAt, v)
  359. return u
  360. }
  361. // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
  362. func (u *XunjiUpsert) UpdateUpdatedAt() *XunjiUpsert {
  363. u.SetExcluded(xunji.FieldUpdatedAt)
  364. return u
  365. }
  366. // SetStatus sets the "status" field.
  367. func (u *XunjiUpsert) SetStatus(v uint8) *XunjiUpsert {
  368. u.Set(xunji.FieldStatus, v)
  369. return u
  370. }
  371. // UpdateStatus sets the "status" field to the value that was provided on create.
  372. func (u *XunjiUpsert) UpdateStatus() *XunjiUpsert {
  373. u.SetExcluded(xunji.FieldStatus)
  374. return u
  375. }
  376. // AddStatus adds v to the "status" field.
  377. func (u *XunjiUpsert) AddStatus(v uint8) *XunjiUpsert {
  378. u.Add(xunji.FieldStatus, v)
  379. return u
  380. }
  381. // ClearStatus clears the value of the "status" field.
  382. func (u *XunjiUpsert) ClearStatus() *XunjiUpsert {
  383. u.SetNull(xunji.FieldStatus)
  384. return u
  385. }
  386. // SetDeletedAt sets the "deleted_at" field.
  387. func (u *XunjiUpsert) SetDeletedAt(v time.Time) *XunjiUpsert {
  388. u.Set(xunji.FieldDeletedAt, v)
  389. return u
  390. }
  391. // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
  392. func (u *XunjiUpsert) UpdateDeletedAt() *XunjiUpsert {
  393. u.SetExcluded(xunji.FieldDeletedAt)
  394. return u
  395. }
  396. // ClearDeletedAt clears the value of the "deleted_at" field.
  397. func (u *XunjiUpsert) ClearDeletedAt() *XunjiUpsert {
  398. u.SetNull(xunji.FieldDeletedAt)
  399. return u
  400. }
  401. // SetAppKey sets the "app_key" field.
  402. func (u *XunjiUpsert) SetAppKey(v string) *XunjiUpsert {
  403. u.Set(xunji.FieldAppKey, v)
  404. return u
  405. }
  406. // UpdateAppKey sets the "app_key" field to the value that was provided on create.
  407. func (u *XunjiUpsert) UpdateAppKey() *XunjiUpsert {
  408. u.SetExcluded(xunji.FieldAppKey)
  409. return u
  410. }
  411. // SetAppSecret sets the "app_secret" field.
  412. func (u *XunjiUpsert) SetAppSecret(v string) *XunjiUpsert {
  413. u.Set(xunji.FieldAppSecret, v)
  414. return u
  415. }
  416. // UpdateAppSecret sets the "app_secret" field to the value that was provided on create.
  417. func (u *XunjiUpsert) UpdateAppSecret() *XunjiUpsert {
  418. u.SetExcluded(xunji.FieldAppSecret)
  419. return u
  420. }
  421. // SetToken sets the "token" field.
  422. func (u *XunjiUpsert) SetToken(v string) *XunjiUpsert {
  423. u.Set(xunji.FieldToken, v)
  424. return u
  425. }
  426. // UpdateToken sets the "token" field to the value that was provided on create.
  427. func (u *XunjiUpsert) UpdateToken() *XunjiUpsert {
  428. u.SetExcluded(xunji.FieldToken)
  429. return u
  430. }
  431. // SetEncodingKey sets the "encoding_key" field.
  432. func (u *XunjiUpsert) SetEncodingKey(v string) *XunjiUpsert {
  433. u.Set(xunji.FieldEncodingKey, v)
  434. return u
  435. }
  436. // UpdateEncodingKey sets the "encoding_key" field to the value that was provided on create.
  437. func (u *XunjiUpsert) UpdateEncodingKey() *XunjiUpsert {
  438. u.SetExcluded(xunji.FieldEncodingKey)
  439. return u
  440. }
  441. // SetAgentID sets the "agent_id" field.
  442. func (u *XunjiUpsert) SetAgentID(v uint64) *XunjiUpsert {
  443. u.Set(xunji.FieldAgentID, v)
  444. return u
  445. }
  446. // UpdateAgentID sets the "agent_id" field to the value that was provided on create.
  447. func (u *XunjiUpsert) UpdateAgentID() *XunjiUpsert {
  448. u.SetExcluded(xunji.FieldAgentID)
  449. return u
  450. }
  451. // AddAgentID adds v to the "agent_id" field.
  452. func (u *XunjiUpsert) AddAgentID(v uint64) *XunjiUpsert {
  453. u.Add(xunji.FieldAgentID, v)
  454. return u
  455. }
  456. // SetOrganizationID sets the "organization_id" field.
  457. func (u *XunjiUpsert) SetOrganizationID(v uint64) *XunjiUpsert {
  458. u.Set(xunji.FieldOrganizationID, v)
  459. return u
  460. }
  461. // UpdateOrganizationID sets the "organization_id" field to the value that was provided on create.
  462. func (u *XunjiUpsert) UpdateOrganizationID() *XunjiUpsert {
  463. u.SetExcluded(xunji.FieldOrganizationID)
  464. return u
  465. }
  466. // AddOrganizationID adds v to the "organization_id" field.
  467. func (u *XunjiUpsert) AddOrganizationID(v uint64) *XunjiUpsert {
  468. u.Add(xunji.FieldOrganizationID, v)
  469. return u
  470. }
  471. // SetWxid sets the "wxid" field.
  472. func (u *XunjiUpsert) SetWxid(v string) *XunjiUpsert {
  473. u.Set(xunji.FieldWxid, v)
  474. return u
  475. }
  476. // UpdateWxid sets the "wxid" field to the value that was provided on create.
  477. func (u *XunjiUpsert) UpdateWxid() *XunjiUpsert {
  478. u.SetExcluded(xunji.FieldWxid)
  479. return u
  480. }
  481. // SetAPIBase sets the "api_base" field.
  482. func (u *XunjiUpsert) SetAPIBase(v string) *XunjiUpsert {
  483. u.Set(xunji.FieldAPIBase, v)
  484. return u
  485. }
  486. // UpdateAPIBase sets the "api_base" field to the value that was provided on create.
  487. func (u *XunjiUpsert) UpdateAPIBase() *XunjiUpsert {
  488. u.SetExcluded(xunji.FieldAPIBase)
  489. return u
  490. }
  491. // ClearAPIBase clears the value of the "api_base" field.
  492. func (u *XunjiUpsert) ClearAPIBase() *XunjiUpsert {
  493. u.SetNull(xunji.FieldAPIBase)
  494. return u
  495. }
  496. // SetAPIKey sets the "api_key" field.
  497. func (u *XunjiUpsert) SetAPIKey(v string) *XunjiUpsert {
  498. u.Set(xunji.FieldAPIKey, v)
  499. return u
  500. }
  501. // UpdateAPIKey sets the "api_key" field to the value that was provided on create.
  502. func (u *XunjiUpsert) UpdateAPIKey() *XunjiUpsert {
  503. u.SetExcluded(xunji.FieldAPIKey)
  504. return u
  505. }
  506. // ClearAPIKey clears the value of the "api_key" field.
  507. func (u *XunjiUpsert) ClearAPIKey() *XunjiUpsert {
  508. u.SetNull(xunji.FieldAPIKey)
  509. return u
  510. }
  511. // UpdateNewValues updates the mutable fields using the new values that were set on create except the ID field.
  512. // Using this option is equivalent to using:
  513. //
  514. // client.Xunji.Create().
  515. // OnConflict(
  516. // sql.ResolveWithNewValues(),
  517. // sql.ResolveWith(func(u *sql.UpdateSet) {
  518. // u.SetIgnore(xunji.FieldID)
  519. // }),
  520. // ).
  521. // Exec(ctx)
  522. func (u *XunjiUpsertOne) UpdateNewValues() *XunjiUpsertOne {
  523. u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
  524. u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
  525. if _, exists := u.create.mutation.ID(); exists {
  526. s.SetIgnore(xunji.FieldID)
  527. }
  528. if _, exists := u.create.mutation.CreatedAt(); exists {
  529. s.SetIgnore(xunji.FieldCreatedAt)
  530. }
  531. }))
  532. return u
  533. }
  534. // Ignore sets each column to itself in case of conflict.
  535. // Using this option is equivalent to using:
  536. //
  537. // client.Xunji.Create().
  538. // OnConflict(sql.ResolveWithIgnore()).
  539. // Exec(ctx)
  540. func (u *XunjiUpsertOne) Ignore() *XunjiUpsertOne {
  541. u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
  542. return u
  543. }
  544. // DoNothing configures the conflict_action to `DO NOTHING`.
  545. // Supported only by SQLite and PostgreSQL.
  546. func (u *XunjiUpsertOne) DoNothing() *XunjiUpsertOne {
  547. u.create.conflict = append(u.create.conflict, sql.DoNothing())
  548. return u
  549. }
  550. // Update allows overriding fields `UPDATE` values. See the XunjiCreate.OnConflict
  551. // documentation for more info.
  552. func (u *XunjiUpsertOne) Update(set func(*XunjiUpsert)) *XunjiUpsertOne {
  553. u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
  554. set(&XunjiUpsert{UpdateSet: update})
  555. }))
  556. return u
  557. }
  558. // SetUpdatedAt sets the "updated_at" field.
  559. func (u *XunjiUpsertOne) SetUpdatedAt(v time.Time) *XunjiUpsertOne {
  560. return u.Update(func(s *XunjiUpsert) {
  561. s.SetUpdatedAt(v)
  562. })
  563. }
  564. // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
  565. func (u *XunjiUpsertOne) UpdateUpdatedAt() *XunjiUpsertOne {
  566. return u.Update(func(s *XunjiUpsert) {
  567. s.UpdateUpdatedAt()
  568. })
  569. }
  570. // SetStatus sets the "status" field.
  571. func (u *XunjiUpsertOne) SetStatus(v uint8) *XunjiUpsertOne {
  572. return u.Update(func(s *XunjiUpsert) {
  573. s.SetStatus(v)
  574. })
  575. }
  576. // AddStatus adds v to the "status" field.
  577. func (u *XunjiUpsertOne) AddStatus(v uint8) *XunjiUpsertOne {
  578. return u.Update(func(s *XunjiUpsert) {
  579. s.AddStatus(v)
  580. })
  581. }
  582. // UpdateStatus sets the "status" field to the value that was provided on create.
  583. func (u *XunjiUpsertOne) UpdateStatus() *XunjiUpsertOne {
  584. return u.Update(func(s *XunjiUpsert) {
  585. s.UpdateStatus()
  586. })
  587. }
  588. // ClearStatus clears the value of the "status" field.
  589. func (u *XunjiUpsertOne) ClearStatus() *XunjiUpsertOne {
  590. return u.Update(func(s *XunjiUpsert) {
  591. s.ClearStatus()
  592. })
  593. }
  594. // SetDeletedAt sets the "deleted_at" field.
  595. func (u *XunjiUpsertOne) SetDeletedAt(v time.Time) *XunjiUpsertOne {
  596. return u.Update(func(s *XunjiUpsert) {
  597. s.SetDeletedAt(v)
  598. })
  599. }
  600. // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
  601. func (u *XunjiUpsertOne) UpdateDeletedAt() *XunjiUpsertOne {
  602. return u.Update(func(s *XunjiUpsert) {
  603. s.UpdateDeletedAt()
  604. })
  605. }
  606. // ClearDeletedAt clears the value of the "deleted_at" field.
  607. func (u *XunjiUpsertOne) ClearDeletedAt() *XunjiUpsertOne {
  608. return u.Update(func(s *XunjiUpsert) {
  609. s.ClearDeletedAt()
  610. })
  611. }
  612. // SetAppKey sets the "app_key" field.
  613. func (u *XunjiUpsertOne) SetAppKey(v string) *XunjiUpsertOne {
  614. return u.Update(func(s *XunjiUpsert) {
  615. s.SetAppKey(v)
  616. })
  617. }
  618. // UpdateAppKey sets the "app_key" field to the value that was provided on create.
  619. func (u *XunjiUpsertOne) UpdateAppKey() *XunjiUpsertOne {
  620. return u.Update(func(s *XunjiUpsert) {
  621. s.UpdateAppKey()
  622. })
  623. }
  624. // SetAppSecret sets the "app_secret" field.
  625. func (u *XunjiUpsertOne) SetAppSecret(v string) *XunjiUpsertOne {
  626. return u.Update(func(s *XunjiUpsert) {
  627. s.SetAppSecret(v)
  628. })
  629. }
  630. // UpdateAppSecret sets the "app_secret" field to the value that was provided on create.
  631. func (u *XunjiUpsertOne) UpdateAppSecret() *XunjiUpsertOne {
  632. return u.Update(func(s *XunjiUpsert) {
  633. s.UpdateAppSecret()
  634. })
  635. }
  636. // SetToken sets the "token" field.
  637. func (u *XunjiUpsertOne) SetToken(v string) *XunjiUpsertOne {
  638. return u.Update(func(s *XunjiUpsert) {
  639. s.SetToken(v)
  640. })
  641. }
  642. // UpdateToken sets the "token" field to the value that was provided on create.
  643. func (u *XunjiUpsertOne) UpdateToken() *XunjiUpsertOne {
  644. return u.Update(func(s *XunjiUpsert) {
  645. s.UpdateToken()
  646. })
  647. }
  648. // SetEncodingKey sets the "encoding_key" field.
  649. func (u *XunjiUpsertOne) SetEncodingKey(v string) *XunjiUpsertOne {
  650. return u.Update(func(s *XunjiUpsert) {
  651. s.SetEncodingKey(v)
  652. })
  653. }
  654. // UpdateEncodingKey sets the "encoding_key" field to the value that was provided on create.
  655. func (u *XunjiUpsertOne) UpdateEncodingKey() *XunjiUpsertOne {
  656. return u.Update(func(s *XunjiUpsert) {
  657. s.UpdateEncodingKey()
  658. })
  659. }
  660. // SetAgentID sets the "agent_id" field.
  661. func (u *XunjiUpsertOne) SetAgentID(v uint64) *XunjiUpsertOne {
  662. return u.Update(func(s *XunjiUpsert) {
  663. s.SetAgentID(v)
  664. })
  665. }
  666. // AddAgentID adds v to the "agent_id" field.
  667. func (u *XunjiUpsertOne) AddAgentID(v uint64) *XunjiUpsertOne {
  668. return u.Update(func(s *XunjiUpsert) {
  669. s.AddAgentID(v)
  670. })
  671. }
  672. // UpdateAgentID sets the "agent_id" field to the value that was provided on create.
  673. func (u *XunjiUpsertOne) UpdateAgentID() *XunjiUpsertOne {
  674. return u.Update(func(s *XunjiUpsert) {
  675. s.UpdateAgentID()
  676. })
  677. }
  678. // SetOrganizationID sets the "organization_id" field.
  679. func (u *XunjiUpsertOne) SetOrganizationID(v uint64) *XunjiUpsertOne {
  680. return u.Update(func(s *XunjiUpsert) {
  681. s.SetOrganizationID(v)
  682. })
  683. }
  684. // AddOrganizationID adds v to the "organization_id" field.
  685. func (u *XunjiUpsertOne) AddOrganizationID(v uint64) *XunjiUpsertOne {
  686. return u.Update(func(s *XunjiUpsert) {
  687. s.AddOrganizationID(v)
  688. })
  689. }
  690. // UpdateOrganizationID sets the "organization_id" field to the value that was provided on create.
  691. func (u *XunjiUpsertOne) UpdateOrganizationID() *XunjiUpsertOne {
  692. return u.Update(func(s *XunjiUpsert) {
  693. s.UpdateOrganizationID()
  694. })
  695. }
  696. // SetWxid sets the "wxid" field.
  697. func (u *XunjiUpsertOne) SetWxid(v string) *XunjiUpsertOne {
  698. return u.Update(func(s *XunjiUpsert) {
  699. s.SetWxid(v)
  700. })
  701. }
  702. // UpdateWxid sets the "wxid" field to the value that was provided on create.
  703. func (u *XunjiUpsertOne) UpdateWxid() *XunjiUpsertOne {
  704. return u.Update(func(s *XunjiUpsert) {
  705. s.UpdateWxid()
  706. })
  707. }
  708. // SetAPIBase sets the "api_base" field.
  709. func (u *XunjiUpsertOne) SetAPIBase(v string) *XunjiUpsertOne {
  710. return u.Update(func(s *XunjiUpsert) {
  711. s.SetAPIBase(v)
  712. })
  713. }
  714. // UpdateAPIBase sets the "api_base" field to the value that was provided on create.
  715. func (u *XunjiUpsertOne) UpdateAPIBase() *XunjiUpsertOne {
  716. return u.Update(func(s *XunjiUpsert) {
  717. s.UpdateAPIBase()
  718. })
  719. }
  720. // ClearAPIBase clears the value of the "api_base" field.
  721. func (u *XunjiUpsertOne) ClearAPIBase() *XunjiUpsertOne {
  722. return u.Update(func(s *XunjiUpsert) {
  723. s.ClearAPIBase()
  724. })
  725. }
  726. // SetAPIKey sets the "api_key" field.
  727. func (u *XunjiUpsertOne) SetAPIKey(v string) *XunjiUpsertOne {
  728. return u.Update(func(s *XunjiUpsert) {
  729. s.SetAPIKey(v)
  730. })
  731. }
  732. // UpdateAPIKey sets the "api_key" field to the value that was provided on create.
  733. func (u *XunjiUpsertOne) UpdateAPIKey() *XunjiUpsertOne {
  734. return u.Update(func(s *XunjiUpsert) {
  735. s.UpdateAPIKey()
  736. })
  737. }
  738. // ClearAPIKey clears the value of the "api_key" field.
  739. func (u *XunjiUpsertOne) ClearAPIKey() *XunjiUpsertOne {
  740. return u.Update(func(s *XunjiUpsert) {
  741. s.ClearAPIKey()
  742. })
  743. }
  744. // Exec executes the query.
  745. func (u *XunjiUpsertOne) Exec(ctx context.Context) error {
  746. if len(u.create.conflict) == 0 {
  747. return errors.New("ent: missing options for XunjiCreate.OnConflict")
  748. }
  749. return u.create.Exec(ctx)
  750. }
  751. // ExecX is like Exec, but panics if an error occurs.
  752. func (u *XunjiUpsertOne) ExecX(ctx context.Context) {
  753. if err := u.create.Exec(ctx); err != nil {
  754. panic(err)
  755. }
  756. }
  757. // Exec executes the UPSERT query and returns the inserted/updated ID.
  758. func (u *XunjiUpsertOne) ID(ctx context.Context) (id uint64, err error) {
  759. node, err := u.create.Save(ctx)
  760. if err != nil {
  761. return id, err
  762. }
  763. return node.ID, nil
  764. }
  765. // IDX is like ID, but panics if an error occurs.
  766. func (u *XunjiUpsertOne) IDX(ctx context.Context) uint64 {
  767. id, err := u.ID(ctx)
  768. if err != nil {
  769. panic(err)
  770. }
  771. return id
  772. }
  773. // XunjiCreateBulk is the builder for creating many Xunji entities in bulk.
  774. type XunjiCreateBulk struct {
  775. config
  776. err error
  777. builders []*XunjiCreate
  778. conflict []sql.ConflictOption
  779. }
  780. // Save creates the Xunji entities in the database.
  781. func (xcb *XunjiCreateBulk) Save(ctx context.Context) ([]*Xunji, error) {
  782. if xcb.err != nil {
  783. return nil, xcb.err
  784. }
  785. specs := make([]*sqlgraph.CreateSpec, len(xcb.builders))
  786. nodes := make([]*Xunji, len(xcb.builders))
  787. mutators := make([]Mutator, len(xcb.builders))
  788. for i := range xcb.builders {
  789. func(i int, root context.Context) {
  790. builder := xcb.builders[i]
  791. builder.defaults()
  792. var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
  793. mutation, ok := m.(*XunjiMutation)
  794. if !ok {
  795. return nil, fmt.Errorf("unexpected mutation type %T", m)
  796. }
  797. if err := builder.check(); err != nil {
  798. return nil, err
  799. }
  800. builder.mutation = mutation
  801. var err error
  802. nodes[i], specs[i] = builder.createSpec()
  803. if i < len(mutators)-1 {
  804. _, err = mutators[i+1].Mutate(root, xcb.builders[i+1].mutation)
  805. } else {
  806. spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
  807. spec.OnConflict = xcb.conflict
  808. // Invoke the actual operation on the latest mutation in the chain.
  809. if err = sqlgraph.BatchCreate(ctx, xcb.driver, spec); err != nil {
  810. if sqlgraph.IsConstraintError(err) {
  811. err = &ConstraintError{msg: err.Error(), wrap: err}
  812. }
  813. }
  814. }
  815. if err != nil {
  816. return nil, err
  817. }
  818. mutation.id = &nodes[i].ID
  819. if specs[i].ID.Value != nil && nodes[i].ID == 0 {
  820. id := specs[i].ID.Value.(int64)
  821. nodes[i].ID = uint64(id)
  822. }
  823. mutation.done = true
  824. return nodes[i], nil
  825. })
  826. for i := len(builder.hooks) - 1; i >= 0; i-- {
  827. mut = builder.hooks[i](mut)
  828. }
  829. mutators[i] = mut
  830. }(i, ctx)
  831. }
  832. if len(mutators) > 0 {
  833. if _, err := mutators[0].Mutate(ctx, xcb.builders[0].mutation); err != nil {
  834. return nil, err
  835. }
  836. }
  837. return nodes, nil
  838. }
  839. // SaveX is like Save, but panics if an error occurs.
  840. func (xcb *XunjiCreateBulk) SaveX(ctx context.Context) []*Xunji {
  841. v, err := xcb.Save(ctx)
  842. if err != nil {
  843. panic(err)
  844. }
  845. return v
  846. }
  847. // Exec executes the query.
  848. func (xcb *XunjiCreateBulk) Exec(ctx context.Context) error {
  849. _, err := xcb.Save(ctx)
  850. return err
  851. }
  852. // ExecX is like Exec, but panics if an error occurs.
  853. func (xcb *XunjiCreateBulk) ExecX(ctx context.Context) {
  854. if err := xcb.Exec(ctx); err != nil {
  855. panic(err)
  856. }
  857. }
  858. // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
  859. // of the `INSERT` statement. For example:
  860. //
  861. // client.Xunji.CreateBulk(builders...).
  862. // OnConflict(
  863. // // Update the row with the new values
  864. // // the was proposed for insertion.
  865. // sql.ResolveWithNewValues(),
  866. // ).
  867. // // Override some of the fields with custom
  868. // // update values.
  869. // Update(func(u *ent.XunjiUpsert) {
  870. // SetCreatedAt(v+v).
  871. // }).
  872. // Exec(ctx)
  873. func (xcb *XunjiCreateBulk) OnConflict(opts ...sql.ConflictOption) *XunjiUpsertBulk {
  874. xcb.conflict = opts
  875. return &XunjiUpsertBulk{
  876. create: xcb,
  877. }
  878. }
  879. // OnConflictColumns calls `OnConflict` and configures the columns
  880. // as conflict target. Using this option is equivalent to using:
  881. //
  882. // client.Xunji.Create().
  883. // OnConflict(sql.ConflictColumns(columns...)).
  884. // Exec(ctx)
  885. func (xcb *XunjiCreateBulk) OnConflictColumns(columns ...string) *XunjiUpsertBulk {
  886. xcb.conflict = append(xcb.conflict, sql.ConflictColumns(columns...))
  887. return &XunjiUpsertBulk{
  888. create: xcb,
  889. }
  890. }
  891. // XunjiUpsertBulk is the builder for "upsert"-ing
  892. // a bulk of Xunji nodes.
  893. type XunjiUpsertBulk struct {
  894. create *XunjiCreateBulk
  895. }
  896. // UpdateNewValues updates the mutable fields using the new values that
  897. // were set on create. Using this option is equivalent to using:
  898. //
  899. // client.Xunji.Create().
  900. // OnConflict(
  901. // sql.ResolveWithNewValues(),
  902. // sql.ResolveWith(func(u *sql.UpdateSet) {
  903. // u.SetIgnore(xunji.FieldID)
  904. // }),
  905. // ).
  906. // Exec(ctx)
  907. func (u *XunjiUpsertBulk) UpdateNewValues() *XunjiUpsertBulk {
  908. u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
  909. u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
  910. for _, b := range u.create.builders {
  911. if _, exists := b.mutation.ID(); exists {
  912. s.SetIgnore(xunji.FieldID)
  913. }
  914. if _, exists := b.mutation.CreatedAt(); exists {
  915. s.SetIgnore(xunji.FieldCreatedAt)
  916. }
  917. }
  918. }))
  919. return u
  920. }
  921. // Ignore sets each column to itself in case of conflict.
  922. // Using this option is equivalent to using:
  923. //
  924. // client.Xunji.Create().
  925. // OnConflict(sql.ResolveWithIgnore()).
  926. // Exec(ctx)
  927. func (u *XunjiUpsertBulk) Ignore() *XunjiUpsertBulk {
  928. u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
  929. return u
  930. }
  931. // DoNothing configures the conflict_action to `DO NOTHING`.
  932. // Supported only by SQLite and PostgreSQL.
  933. func (u *XunjiUpsertBulk) DoNothing() *XunjiUpsertBulk {
  934. u.create.conflict = append(u.create.conflict, sql.DoNothing())
  935. return u
  936. }
  937. // Update allows overriding fields `UPDATE` values. See the XunjiCreateBulk.OnConflict
  938. // documentation for more info.
  939. func (u *XunjiUpsertBulk) Update(set func(*XunjiUpsert)) *XunjiUpsertBulk {
  940. u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
  941. set(&XunjiUpsert{UpdateSet: update})
  942. }))
  943. return u
  944. }
  945. // SetUpdatedAt sets the "updated_at" field.
  946. func (u *XunjiUpsertBulk) SetUpdatedAt(v time.Time) *XunjiUpsertBulk {
  947. return u.Update(func(s *XunjiUpsert) {
  948. s.SetUpdatedAt(v)
  949. })
  950. }
  951. // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
  952. func (u *XunjiUpsertBulk) UpdateUpdatedAt() *XunjiUpsertBulk {
  953. return u.Update(func(s *XunjiUpsert) {
  954. s.UpdateUpdatedAt()
  955. })
  956. }
  957. // SetStatus sets the "status" field.
  958. func (u *XunjiUpsertBulk) SetStatus(v uint8) *XunjiUpsertBulk {
  959. return u.Update(func(s *XunjiUpsert) {
  960. s.SetStatus(v)
  961. })
  962. }
  963. // AddStatus adds v to the "status" field.
  964. func (u *XunjiUpsertBulk) AddStatus(v uint8) *XunjiUpsertBulk {
  965. return u.Update(func(s *XunjiUpsert) {
  966. s.AddStatus(v)
  967. })
  968. }
  969. // UpdateStatus sets the "status" field to the value that was provided on create.
  970. func (u *XunjiUpsertBulk) UpdateStatus() *XunjiUpsertBulk {
  971. return u.Update(func(s *XunjiUpsert) {
  972. s.UpdateStatus()
  973. })
  974. }
  975. // ClearStatus clears the value of the "status" field.
  976. func (u *XunjiUpsertBulk) ClearStatus() *XunjiUpsertBulk {
  977. return u.Update(func(s *XunjiUpsert) {
  978. s.ClearStatus()
  979. })
  980. }
  981. // SetDeletedAt sets the "deleted_at" field.
  982. func (u *XunjiUpsertBulk) SetDeletedAt(v time.Time) *XunjiUpsertBulk {
  983. return u.Update(func(s *XunjiUpsert) {
  984. s.SetDeletedAt(v)
  985. })
  986. }
  987. // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
  988. func (u *XunjiUpsertBulk) UpdateDeletedAt() *XunjiUpsertBulk {
  989. return u.Update(func(s *XunjiUpsert) {
  990. s.UpdateDeletedAt()
  991. })
  992. }
  993. // ClearDeletedAt clears the value of the "deleted_at" field.
  994. func (u *XunjiUpsertBulk) ClearDeletedAt() *XunjiUpsertBulk {
  995. return u.Update(func(s *XunjiUpsert) {
  996. s.ClearDeletedAt()
  997. })
  998. }
  999. // SetAppKey sets the "app_key" field.
  1000. func (u *XunjiUpsertBulk) SetAppKey(v string) *XunjiUpsertBulk {
  1001. return u.Update(func(s *XunjiUpsert) {
  1002. s.SetAppKey(v)
  1003. })
  1004. }
  1005. // UpdateAppKey sets the "app_key" field to the value that was provided on create.
  1006. func (u *XunjiUpsertBulk) UpdateAppKey() *XunjiUpsertBulk {
  1007. return u.Update(func(s *XunjiUpsert) {
  1008. s.UpdateAppKey()
  1009. })
  1010. }
  1011. // SetAppSecret sets the "app_secret" field.
  1012. func (u *XunjiUpsertBulk) SetAppSecret(v string) *XunjiUpsertBulk {
  1013. return u.Update(func(s *XunjiUpsert) {
  1014. s.SetAppSecret(v)
  1015. })
  1016. }
  1017. // UpdateAppSecret sets the "app_secret" field to the value that was provided on create.
  1018. func (u *XunjiUpsertBulk) UpdateAppSecret() *XunjiUpsertBulk {
  1019. return u.Update(func(s *XunjiUpsert) {
  1020. s.UpdateAppSecret()
  1021. })
  1022. }
  1023. // SetToken sets the "token" field.
  1024. func (u *XunjiUpsertBulk) SetToken(v string) *XunjiUpsertBulk {
  1025. return u.Update(func(s *XunjiUpsert) {
  1026. s.SetToken(v)
  1027. })
  1028. }
  1029. // UpdateToken sets the "token" field to the value that was provided on create.
  1030. func (u *XunjiUpsertBulk) UpdateToken() *XunjiUpsertBulk {
  1031. return u.Update(func(s *XunjiUpsert) {
  1032. s.UpdateToken()
  1033. })
  1034. }
  1035. // SetEncodingKey sets the "encoding_key" field.
  1036. func (u *XunjiUpsertBulk) SetEncodingKey(v string) *XunjiUpsertBulk {
  1037. return u.Update(func(s *XunjiUpsert) {
  1038. s.SetEncodingKey(v)
  1039. })
  1040. }
  1041. // UpdateEncodingKey sets the "encoding_key" field to the value that was provided on create.
  1042. func (u *XunjiUpsertBulk) UpdateEncodingKey() *XunjiUpsertBulk {
  1043. return u.Update(func(s *XunjiUpsert) {
  1044. s.UpdateEncodingKey()
  1045. })
  1046. }
  1047. // SetAgentID sets the "agent_id" field.
  1048. func (u *XunjiUpsertBulk) SetAgentID(v uint64) *XunjiUpsertBulk {
  1049. return u.Update(func(s *XunjiUpsert) {
  1050. s.SetAgentID(v)
  1051. })
  1052. }
  1053. // AddAgentID adds v to the "agent_id" field.
  1054. func (u *XunjiUpsertBulk) AddAgentID(v uint64) *XunjiUpsertBulk {
  1055. return u.Update(func(s *XunjiUpsert) {
  1056. s.AddAgentID(v)
  1057. })
  1058. }
  1059. // UpdateAgentID sets the "agent_id" field to the value that was provided on create.
  1060. func (u *XunjiUpsertBulk) UpdateAgentID() *XunjiUpsertBulk {
  1061. return u.Update(func(s *XunjiUpsert) {
  1062. s.UpdateAgentID()
  1063. })
  1064. }
  1065. // SetOrganizationID sets the "organization_id" field.
  1066. func (u *XunjiUpsertBulk) SetOrganizationID(v uint64) *XunjiUpsertBulk {
  1067. return u.Update(func(s *XunjiUpsert) {
  1068. s.SetOrganizationID(v)
  1069. })
  1070. }
  1071. // AddOrganizationID adds v to the "organization_id" field.
  1072. func (u *XunjiUpsertBulk) AddOrganizationID(v uint64) *XunjiUpsertBulk {
  1073. return u.Update(func(s *XunjiUpsert) {
  1074. s.AddOrganizationID(v)
  1075. })
  1076. }
  1077. // UpdateOrganizationID sets the "organization_id" field to the value that was provided on create.
  1078. func (u *XunjiUpsertBulk) UpdateOrganizationID() *XunjiUpsertBulk {
  1079. return u.Update(func(s *XunjiUpsert) {
  1080. s.UpdateOrganizationID()
  1081. })
  1082. }
  1083. // SetWxid sets the "wxid" field.
  1084. func (u *XunjiUpsertBulk) SetWxid(v string) *XunjiUpsertBulk {
  1085. return u.Update(func(s *XunjiUpsert) {
  1086. s.SetWxid(v)
  1087. })
  1088. }
  1089. // UpdateWxid sets the "wxid" field to the value that was provided on create.
  1090. func (u *XunjiUpsertBulk) UpdateWxid() *XunjiUpsertBulk {
  1091. return u.Update(func(s *XunjiUpsert) {
  1092. s.UpdateWxid()
  1093. })
  1094. }
  1095. // SetAPIBase sets the "api_base" field.
  1096. func (u *XunjiUpsertBulk) SetAPIBase(v string) *XunjiUpsertBulk {
  1097. return u.Update(func(s *XunjiUpsert) {
  1098. s.SetAPIBase(v)
  1099. })
  1100. }
  1101. // UpdateAPIBase sets the "api_base" field to the value that was provided on create.
  1102. func (u *XunjiUpsertBulk) UpdateAPIBase() *XunjiUpsertBulk {
  1103. return u.Update(func(s *XunjiUpsert) {
  1104. s.UpdateAPIBase()
  1105. })
  1106. }
  1107. // ClearAPIBase clears the value of the "api_base" field.
  1108. func (u *XunjiUpsertBulk) ClearAPIBase() *XunjiUpsertBulk {
  1109. return u.Update(func(s *XunjiUpsert) {
  1110. s.ClearAPIBase()
  1111. })
  1112. }
  1113. // SetAPIKey sets the "api_key" field.
  1114. func (u *XunjiUpsertBulk) SetAPIKey(v string) *XunjiUpsertBulk {
  1115. return u.Update(func(s *XunjiUpsert) {
  1116. s.SetAPIKey(v)
  1117. })
  1118. }
  1119. // UpdateAPIKey sets the "api_key" field to the value that was provided on create.
  1120. func (u *XunjiUpsertBulk) UpdateAPIKey() *XunjiUpsertBulk {
  1121. return u.Update(func(s *XunjiUpsert) {
  1122. s.UpdateAPIKey()
  1123. })
  1124. }
  1125. // ClearAPIKey clears the value of the "api_key" field.
  1126. func (u *XunjiUpsertBulk) ClearAPIKey() *XunjiUpsertBulk {
  1127. return u.Update(func(s *XunjiUpsert) {
  1128. s.ClearAPIKey()
  1129. })
  1130. }
  1131. // Exec executes the query.
  1132. func (u *XunjiUpsertBulk) Exec(ctx context.Context) error {
  1133. if u.create.err != nil {
  1134. return u.create.err
  1135. }
  1136. for i, b := range u.create.builders {
  1137. if len(b.conflict) != 0 {
  1138. return fmt.Errorf("ent: OnConflict was set for builder %d. Set it on the XunjiCreateBulk instead", i)
  1139. }
  1140. }
  1141. if len(u.create.conflict) == 0 {
  1142. return errors.New("ent: missing options for XunjiCreateBulk.OnConflict")
  1143. }
  1144. return u.create.Exec(ctx)
  1145. }
  1146. // ExecX is like Exec, but panics if an error occurs.
  1147. func (u *XunjiUpsertBulk) ExecX(ctx context.Context) {
  1148. if err := u.create.Exec(ctx); err != nil {
  1149. panic(err)
  1150. }
  1151. }