token_create.go 38 KB

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