apikey_create.go 36 KB

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