apikey_create.go 67 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388
  1. // Code generated by ent, DO NOT EDIT.
  2. package ent
  3. import (
  4. "context"
  5. "errors"
  6. "fmt"
  7. "time"
  8. "entgo.io/ent/dialect/sql"
  9. "entgo.io/ent/dialect/sql/sqlgraph"
  10. "entgo.io/ent/schema/field"
  11. "github.com/Wei-Shaw/sub2api/ent/apikey"
  12. "github.com/Wei-Shaw/sub2api/ent/group"
  13. "github.com/Wei-Shaw/sub2api/ent/usagelog"
  14. "github.com/Wei-Shaw/sub2api/ent/user"
  15. )
  16. // APIKeyCreate is the builder for creating a APIKey entity.
  17. type APIKeyCreate struct {
  18. config
  19. mutation *APIKeyMutation
  20. hooks []Hook
  21. conflict []sql.ConflictOption
  22. }
  23. // SetCreatedAt sets the "created_at" field.
  24. func (_c *APIKeyCreate) SetCreatedAt(v time.Time) *APIKeyCreate {
  25. _c.mutation.SetCreatedAt(v)
  26. return _c
  27. }
  28. // SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
  29. func (_c *APIKeyCreate) SetNillableCreatedAt(v *time.Time) *APIKeyCreate {
  30. if v != nil {
  31. _c.SetCreatedAt(*v)
  32. }
  33. return _c
  34. }
  35. // SetUpdatedAt sets the "updated_at" field.
  36. func (_c *APIKeyCreate) SetUpdatedAt(v time.Time) *APIKeyCreate {
  37. _c.mutation.SetUpdatedAt(v)
  38. return _c
  39. }
  40. // SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
  41. func (_c *APIKeyCreate) SetNillableUpdatedAt(v *time.Time) *APIKeyCreate {
  42. if v != nil {
  43. _c.SetUpdatedAt(*v)
  44. }
  45. return _c
  46. }
  47. // SetDeletedAt sets the "deleted_at" field.
  48. func (_c *APIKeyCreate) SetDeletedAt(v time.Time) *APIKeyCreate {
  49. _c.mutation.SetDeletedAt(v)
  50. return _c
  51. }
  52. // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
  53. func (_c *APIKeyCreate) SetNillableDeletedAt(v *time.Time) *APIKeyCreate {
  54. if v != nil {
  55. _c.SetDeletedAt(*v)
  56. }
  57. return _c
  58. }
  59. // SetUserID sets the "user_id" field.
  60. func (_c *APIKeyCreate) SetUserID(v int64) *APIKeyCreate {
  61. _c.mutation.SetUserID(v)
  62. return _c
  63. }
  64. // SetKey sets the "key" field.
  65. func (_c *APIKeyCreate) SetKey(v string) *APIKeyCreate {
  66. _c.mutation.SetKey(v)
  67. return _c
  68. }
  69. // SetNillableKey sets the "key" field if the given value is not nil.
  70. func (_c *APIKeyCreate) SetNillableKey(v *string) *APIKeyCreate {
  71. if v != nil {
  72. _c.SetKey(*v)
  73. }
  74. return _c
  75. }
  76. // SetKeyHash sets the "key_hash" field.
  77. func (_c *APIKeyCreate) SetKeyHash(v string) *APIKeyCreate {
  78. _c.mutation.SetKeyHash(v)
  79. return _c
  80. }
  81. // SetNillableKeyHash sets the "key_hash" field if the given value is not nil.
  82. func (_c *APIKeyCreate) SetNillableKeyHash(v *string) *APIKeyCreate {
  83. if v != nil {
  84. _c.SetKeyHash(*v)
  85. }
  86. return _c
  87. }
  88. // SetKeyPrefix sets the "key_prefix" field.
  89. func (_c *APIKeyCreate) SetKeyPrefix(v string) *APIKeyCreate {
  90. _c.mutation.SetKeyPrefix(v)
  91. return _c
  92. }
  93. // SetNillableKeyPrefix sets the "key_prefix" field if the given value is not nil.
  94. func (_c *APIKeyCreate) SetNillableKeyPrefix(v *string) *APIKeyCreate {
  95. if v != nil {
  96. _c.SetKeyPrefix(*v)
  97. }
  98. return _c
  99. }
  100. // SetName sets the "name" field.
  101. func (_c *APIKeyCreate) SetName(v string) *APIKeyCreate {
  102. _c.mutation.SetName(v)
  103. return _c
  104. }
  105. // SetGroupID sets the "group_id" field.
  106. func (_c *APIKeyCreate) SetGroupID(v int64) *APIKeyCreate {
  107. _c.mutation.SetGroupID(v)
  108. return _c
  109. }
  110. // SetNillableGroupID sets the "group_id" field if the given value is not nil.
  111. func (_c *APIKeyCreate) SetNillableGroupID(v *int64) *APIKeyCreate {
  112. if v != nil {
  113. _c.SetGroupID(*v)
  114. }
  115. return _c
  116. }
  117. // SetStatus sets the "status" field.
  118. func (_c *APIKeyCreate) SetStatus(v string) *APIKeyCreate {
  119. _c.mutation.SetStatus(v)
  120. return _c
  121. }
  122. // SetNillableStatus sets the "status" field if the given value is not nil.
  123. func (_c *APIKeyCreate) SetNillableStatus(v *string) *APIKeyCreate {
  124. if v != nil {
  125. _c.SetStatus(*v)
  126. }
  127. return _c
  128. }
  129. // SetLastUsedAt sets the "last_used_at" field.
  130. func (_c *APIKeyCreate) SetLastUsedAt(v time.Time) *APIKeyCreate {
  131. _c.mutation.SetLastUsedAt(v)
  132. return _c
  133. }
  134. // SetNillableLastUsedAt sets the "last_used_at" field if the given value is not nil.
  135. func (_c *APIKeyCreate) SetNillableLastUsedAt(v *time.Time) *APIKeyCreate {
  136. if v != nil {
  137. _c.SetLastUsedAt(*v)
  138. }
  139. return _c
  140. }
  141. // SetIPWhitelist sets the "ip_whitelist" field.
  142. func (_c *APIKeyCreate) SetIPWhitelist(v []string) *APIKeyCreate {
  143. _c.mutation.SetIPWhitelist(v)
  144. return _c
  145. }
  146. // SetIPBlacklist sets the "ip_blacklist" field.
  147. func (_c *APIKeyCreate) SetIPBlacklist(v []string) *APIKeyCreate {
  148. _c.mutation.SetIPBlacklist(v)
  149. return _c
  150. }
  151. // SetQuota sets the "quota" field.
  152. func (_c *APIKeyCreate) SetQuota(v float64) *APIKeyCreate {
  153. _c.mutation.SetQuota(v)
  154. return _c
  155. }
  156. // SetNillableQuota sets the "quota" field if the given value is not nil.
  157. func (_c *APIKeyCreate) SetNillableQuota(v *float64) *APIKeyCreate {
  158. if v != nil {
  159. _c.SetQuota(*v)
  160. }
  161. return _c
  162. }
  163. // SetQuotaUsed sets the "quota_used" field.
  164. func (_c *APIKeyCreate) SetQuotaUsed(v float64) *APIKeyCreate {
  165. _c.mutation.SetQuotaUsed(v)
  166. return _c
  167. }
  168. // SetNillableQuotaUsed sets the "quota_used" field if the given value is not nil.
  169. func (_c *APIKeyCreate) SetNillableQuotaUsed(v *float64) *APIKeyCreate {
  170. if v != nil {
  171. _c.SetQuotaUsed(*v)
  172. }
  173. return _c
  174. }
  175. // SetExpiresAt sets the "expires_at" field.
  176. func (_c *APIKeyCreate) SetExpiresAt(v time.Time) *APIKeyCreate {
  177. _c.mutation.SetExpiresAt(v)
  178. return _c
  179. }
  180. // SetNillableExpiresAt sets the "expires_at" field if the given value is not nil.
  181. func (_c *APIKeyCreate) SetNillableExpiresAt(v *time.Time) *APIKeyCreate {
  182. if v != nil {
  183. _c.SetExpiresAt(*v)
  184. }
  185. return _c
  186. }
  187. // SetRateLimit5h sets the "rate_limit_5h" field.
  188. func (_c *APIKeyCreate) SetRateLimit5h(v float64) *APIKeyCreate {
  189. _c.mutation.SetRateLimit5h(v)
  190. return _c
  191. }
  192. // SetNillableRateLimit5h sets the "rate_limit_5h" field if the given value is not nil.
  193. func (_c *APIKeyCreate) SetNillableRateLimit5h(v *float64) *APIKeyCreate {
  194. if v != nil {
  195. _c.SetRateLimit5h(*v)
  196. }
  197. return _c
  198. }
  199. // SetRateLimit1d sets the "rate_limit_1d" field.
  200. func (_c *APIKeyCreate) SetRateLimit1d(v float64) *APIKeyCreate {
  201. _c.mutation.SetRateLimit1d(v)
  202. return _c
  203. }
  204. // SetNillableRateLimit1d sets the "rate_limit_1d" field if the given value is not nil.
  205. func (_c *APIKeyCreate) SetNillableRateLimit1d(v *float64) *APIKeyCreate {
  206. if v != nil {
  207. _c.SetRateLimit1d(*v)
  208. }
  209. return _c
  210. }
  211. // SetRateLimit7d sets the "rate_limit_7d" field.
  212. func (_c *APIKeyCreate) SetRateLimit7d(v float64) *APIKeyCreate {
  213. _c.mutation.SetRateLimit7d(v)
  214. return _c
  215. }
  216. // SetNillableRateLimit7d sets the "rate_limit_7d" field if the given value is not nil.
  217. func (_c *APIKeyCreate) SetNillableRateLimit7d(v *float64) *APIKeyCreate {
  218. if v != nil {
  219. _c.SetRateLimit7d(*v)
  220. }
  221. return _c
  222. }
  223. // SetUsage5h sets the "usage_5h" field.
  224. func (_c *APIKeyCreate) SetUsage5h(v float64) *APIKeyCreate {
  225. _c.mutation.SetUsage5h(v)
  226. return _c
  227. }
  228. // SetNillableUsage5h sets the "usage_5h" field if the given value is not nil.
  229. func (_c *APIKeyCreate) SetNillableUsage5h(v *float64) *APIKeyCreate {
  230. if v != nil {
  231. _c.SetUsage5h(*v)
  232. }
  233. return _c
  234. }
  235. // SetUsage1d sets the "usage_1d" field.
  236. func (_c *APIKeyCreate) SetUsage1d(v float64) *APIKeyCreate {
  237. _c.mutation.SetUsage1d(v)
  238. return _c
  239. }
  240. // SetNillableUsage1d sets the "usage_1d" field if the given value is not nil.
  241. func (_c *APIKeyCreate) SetNillableUsage1d(v *float64) *APIKeyCreate {
  242. if v != nil {
  243. _c.SetUsage1d(*v)
  244. }
  245. return _c
  246. }
  247. // SetUsage7d sets the "usage_7d" field.
  248. func (_c *APIKeyCreate) SetUsage7d(v float64) *APIKeyCreate {
  249. _c.mutation.SetUsage7d(v)
  250. return _c
  251. }
  252. // SetNillableUsage7d sets the "usage_7d" field if the given value is not nil.
  253. func (_c *APIKeyCreate) SetNillableUsage7d(v *float64) *APIKeyCreate {
  254. if v != nil {
  255. _c.SetUsage7d(*v)
  256. }
  257. return _c
  258. }
  259. // SetWindow5hStart sets the "window_5h_start" field.
  260. func (_c *APIKeyCreate) SetWindow5hStart(v time.Time) *APIKeyCreate {
  261. _c.mutation.SetWindow5hStart(v)
  262. return _c
  263. }
  264. // SetNillableWindow5hStart sets the "window_5h_start" field if the given value is not nil.
  265. func (_c *APIKeyCreate) SetNillableWindow5hStart(v *time.Time) *APIKeyCreate {
  266. if v != nil {
  267. _c.SetWindow5hStart(*v)
  268. }
  269. return _c
  270. }
  271. // SetWindow1dStart sets the "window_1d_start" field.
  272. func (_c *APIKeyCreate) SetWindow1dStart(v time.Time) *APIKeyCreate {
  273. _c.mutation.SetWindow1dStart(v)
  274. return _c
  275. }
  276. // SetNillableWindow1dStart sets the "window_1d_start" field if the given value is not nil.
  277. func (_c *APIKeyCreate) SetNillableWindow1dStart(v *time.Time) *APIKeyCreate {
  278. if v != nil {
  279. _c.SetWindow1dStart(*v)
  280. }
  281. return _c
  282. }
  283. // SetWindow7dStart sets the "window_7d_start" field.
  284. func (_c *APIKeyCreate) SetWindow7dStart(v time.Time) *APIKeyCreate {
  285. _c.mutation.SetWindow7dStart(v)
  286. return _c
  287. }
  288. // SetNillableWindow7dStart sets the "window_7d_start" field if the given value is not nil.
  289. func (_c *APIKeyCreate) SetNillableWindow7dStart(v *time.Time) *APIKeyCreate {
  290. if v != nil {
  291. _c.SetWindow7dStart(*v)
  292. }
  293. return _c
  294. }
  295. // SetUser sets the "user" edge to the User entity.
  296. func (_c *APIKeyCreate) SetUser(v *User) *APIKeyCreate {
  297. return _c.SetUserID(v.ID)
  298. }
  299. // SetGroup sets the "group" edge to the Group entity.
  300. func (_c *APIKeyCreate) SetGroup(v *Group) *APIKeyCreate {
  301. return _c.SetGroupID(v.ID)
  302. }
  303. // AddUsageLogIDs adds the "usage_logs" edge to the UsageLog entity by IDs.
  304. func (_c *APIKeyCreate) AddUsageLogIDs(ids ...int64) *APIKeyCreate {
  305. _c.mutation.AddUsageLogIDs(ids...)
  306. return _c
  307. }
  308. // AddUsageLogs adds the "usage_logs" edges to the UsageLog entity.
  309. func (_c *APIKeyCreate) AddUsageLogs(v ...*UsageLog) *APIKeyCreate {
  310. ids := make([]int64, len(v))
  311. for i := range v {
  312. ids[i] = v[i].ID
  313. }
  314. return _c.AddUsageLogIDs(ids...)
  315. }
  316. // Mutation returns the APIKeyMutation object of the builder.
  317. func (_c *APIKeyCreate) Mutation() *APIKeyMutation {
  318. return _c.mutation
  319. }
  320. // Save creates the APIKey in the database.
  321. func (_c *APIKeyCreate) Save(ctx context.Context) (*APIKey, error) {
  322. if err := _c.defaults(); err != nil {
  323. return nil, err
  324. }
  325. return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
  326. }
  327. // SaveX calls Save and panics if Save returns an error.
  328. func (_c *APIKeyCreate) SaveX(ctx context.Context) *APIKey {
  329. v, err := _c.Save(ctx)
  330. if err != nil {
  331. panic(err)
  332. }
  333. return v
  334. }
  335. // Exec executes the query.
  336. func (_c *APIKeyCreate) Exec(ctx context.Context) error {
  337. _, err := _c.Save(ctx)
  338. return err
  339. }
  340. // ExecX is like Exec, but panics if an error occurs.
  341. func (_c *APIKeyCreate) ExecX(ctx context.Context) {
  342. if err := _c.Exec(ctx); err != nil {
  343. panic(err)
  344. }
  345. }
  346. // defaults sets the default values of the builder before save.
  347. func (_c *APIKeyCreate) defaults() error {
  348. if _, ok := _c.mutation.CreatedAt(); !ok {
  349. if apikey.DefaultCreatedAt == nil {
  350. return fmt.Errorf("ent: uninitialized apikey.DefaultCreatedAt (forgotten import ent/runtime?)")
  351. }
  352. v := apikey.DefaultCreatedAt()
  353. _c.mutation.SetCreatedAt(v)
  354. }
  355. if _, ok := _c.mutation.UpdatedAt(); !ok {
  356. if apikey.DefaultUpdatedAt == nil {
  357. return fmt.Errorf("ent: uninitialized apikey.DefaultUpdatedAt (forgotten import ent/runtime?)")
  358. }
  359. v := apikey.DefaultUpdatedAt()
  360. _c.mutation.SetUpdatedAt(v)
  361. }
  362. if _, ok := _c.mutation.Status(); !ok {
  363. v := apikey.DefaultStatus
  364. _c.mutation.SetStatus(v)
  365. }
  366. if _, ok := _c.mutation.Quota(); !ok {
  367. v := apikey.DefaultQuota
  368. _c.mutation.SetQuota(v)
  369. }
  370. if _, ok := _c.mutation.QuotaUsed(); !ok {
  371. v := apikey.DefaultQuotaUsed
  372. _c.mutation.SetQuotaUsed(v)
  373. }
  374. if _, ok := _c.mutation.RateLimit5h(); !ok {
  375. v := apikey.DefaultRateLimit5h
  376. _c.mutation.SetRateLimit5h(v)
  377. }
  378. if _, ok := _c.mutation.RateLimit1d(); !ok {
  379. v := apikey.DefaultRateLimit1d
  380. _c.mutation.SetRateLimit1d(v)
  381. }
  382. if _, ok := _c.mutation.RateLimit7d(); !ok {
  383. v := apikey.DefaultRateLimit7d
  384. _c.mutation.SetRateLimit7d(v)
  385. }
  386. if _, ok := _c.mutation.Usage5h(); !ok {
  387. v := apikey.DefaultUsage5h
  388. _c.mutation.SetUsage5h(v)
  389. }
  390. if _, ok := _c.mutation.Usage1d(); !ok {
  391. v := apikey.DefaultUsage1d
  392. _c.mutation.SetUsage1d(v)
  393. }
  394. if _, ok := _c.mutation.Usage7d(); !ok {
  395. v := apikey.DefaultUsage7d
  396. _c.mutation.SetUsage7d(v)
  397. }
  398. return nil
  399. }
  400. // check runs all checks and user-defined validators on the builder.
  401. func (_c *APIKeyCreate) check() error {
  402. if _, ok := _c.mutation.CreatedAt(); !ok {
  403. return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "APIKey.created_at"`)}
  404. }
  405. if _, ok := _c.mutation.UpdatedAt(); !ok {
  406. return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "APIKey.updated_at"`)}
  407. }
  408. if _, ok := _c.mutation.UserID(); !ok {
  409. return &ValidationError{Name: "user_id", err: errors.New(`ent: missing required field "APIKey.user_id"`)}
  410. }
  411. if v, ok := _c.mutation.Key(); ok {
  412. if err := apikey.KeyValidator(v); err != nil {
  413. return &ValidationError{Name: "key", err: fmt.Errorf(`ent: validator failed for field "APIKey.key": %w`, err)}
  414. }
  415. }
  416. if v, ok := _c.mutation.KeyHash(); ok {
  417. if err := apikey.KeyHashValidator(v); err != nil {
  418. return &ValidationError{Name: "key_hash", err: fmt.Errorf(`ent: validator failed for field "APIKey.key_hash": %w`, err)}
  419. }
  420. }
  421. if v, ok := _c.mutation.KeyPrefix(); ok {
  422. if err := apikey.KeyPrefixValidator(v); err != nil {
  423. return &ValidationError{Name: "key_prefix", err: fmt.Errorf(`ent: validator failed for field "APIKey.key_prefix": %w`, err)}
  424. }
  425. }
  426. if _, ok := _c.mutation.Name(); !ok {
  427. return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "APIKey.name"`)}
  428. }
  429. if v, ok := _c.mutation.Name(); ok {
  430. if err := apikey.NameValidator(v); err != nil {
  431. return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "APIKey.name": %w`, err)}
  432. }
  433. }
  434. if _, ok := _c.mutation.Status(); !ok {
  435. return &ValidationError{Name: "status", err: errors.New(`ent: missing required field "APIKey.status"`)}
  436. }
  437. if v, ok := _c.mutation.Status(); ok {
  438. if err := apikey.StatusValidator(v); err != nil {
  439. return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "APIKey.status": %w`, err)}
  440. }
  441. }
  442. if _, ok := _c.mutation.Quota(); !ok {
  443. return &ValidationError{Name: "quota", err: errors.New(`ent: missing required field "APIKey.quota"`)}
  444. }
  445. if _, ok := _c.mutation.QuotaUsed(); !ok {
  446. return &ValidationError{Name: "quota_used", err: errors.New(`ent: missing required field "APIKey.quota_used"`)}
  447. }
  448. if _, ok := _c.mutation.RateLimit5h(); !ok {
  449. return &ValidationError{Name: "rate_limit_5h", err: errors.New(`ent: missing required field "APIKey.rate_limit_5h"`)}
  450. }
  451. if _, ok := _c.mutation.RateLimit1d(); !ok {
  452. return &ValidationError{Name: "rate_limit_1d", err: errors.New(`ent: missing required field "APIKey.rate_limit_1d"`)}
  453. }
  454. if _, ok := _c.mutation.RateLimit7d(); !ok {
  455. return &ValidationError{Name: "rate_limit_7d", err: errors.New(`ent: missing required field "APIKey.rate_limit_7d"`)}
  456. }
  457. if _, ok := _c.mutation.Usage5h(); !ok {
  458. return &ValidationError{Name: "usage_5h", err: errors.New(`ent: missing required field "APIKey.usage_5h"`)}
  459. }
  460. if _, ok := _c.mutation.Usage1d(); !ok {
  461. return &ValidationError{Name: "usage_1d", err: errors.New(`ent: missing required field "APIKey.usage_1d"`)}
  462. }
  463. if _, ok := _c.mutation.Usage7d(); !ok {
  464. return &ValidationError{Name: "usage_7d", err: errors.New(`ent: missing required field "APIKey.usage_7d"`)}
  465. }
  466. if len(_c.mutation.UserIDs()) == 0 {
  467. return &ValidationError{Name: "user", err: errors.New(`ent: missing required edge "APIKey.user"`)}
  468. }
  469. return nil
  470. }
  471. func (_c *APIKeyCreate) sqlSave(ctx context.Context) (*APIKey, error) {
  472. if err := _c.check(); err != nil {
  473. return nil, err
  474. }
  475. _node, _spec := _c.createSpec()
  476. if err := sqlgraph.CreateNode(ctx, _c.driver, _spec); err != nil {
  477. if sqlgraph.IsConstraintError(err) {
  478. err = &ConstraintError{msg: err.Error(), wrap: err}
  479. }
  480. return nil, err
  481. }
  482. id := _spec.ID.Value.(int64)
  483. _node.ID = int64(id)
  484. _c.mutation.id = &_node.ID
  485. _c.mutation.done = true
  486. return _node, nil
  487. }
  488. func (_c *APIKeyCreate) createSpec() (*APIKey, *sqlgraph.CreateSpec) {
  489. var (
  490. _node = &APIKey{config: _c.config}
  491. _spec = sqlgraph.NewCreateSpec(apikey.Table, sqlgraph.NewFieldSpec(apikey.FieldID, field.TypeInt64))
  492. )
  493. _spec.OnConflict = _c.conflict
  494. if value, ok := _c.mutation.CreatedAt(); ok {
  495. _spec.SetField(apikey.FieldCreatedAt, field.TypeTime, value)
  496. _node.CreatedAt = value
  497. }
  498. if value, ok := _c.mutation.UpdatedAt(); ok {
  499. _spec.SetField(apikey.FieldUpdatedAt, field.TypeTime, value)
  500. _node.UpdatedAt = value
  501. }
  502. if value, ok := _c.mutation.DeletedAt(); ok {
  503. _spec.SetField(apikey.FieldDeletedAt, field.TypeTime, value)
  504. _node.DeletedAt = &value
  505. }
  506. if value, ok := _c.mutation.Key(); ok {
  507. _spec.SetField(apikey.FieldKey, field.TypeString, value)
  508. _node.Key = value
  509. }
  510. if value, ok := _c.mutation.KeyHash(); ok {
  511. _spec.SetField(apikey.FieldKeyHash, field.TypeString, value)
  512. _node.KeyHash = value
  513. }
  514. if value, ok := _c.mutation.KeyPrefix(); ok {
  515. _spec.SetField(apikey.FieldKeyPrefix, field.TypeString, value)
  516. _node.KeyPrefix = value
  517. }
  518. if value, ok := _c.mutation.Name(); ok {
  519. _spec.SetField(apikey.FieldName, field.TypeString, value)
  520. _node.Name = value
  521. }
  522. if value, ok := _c.mutation.Status(); ok {
  523. _spec.SetField(apikey.FieldStatus, field.TypeString, value)
  524. _node.Status = value
  525. }
  526. if value, ok := _c.mutation.LastUsedAt(); ok {
  527. _spec.SetField(apikey.FieldLastUsedAt, field.TypeTime, value)
  528. _node.LastUsedAt = &value
  529. }
  530. if value, ok := _c.mutation.IPWhitelist(); ok {
  531. _spec.SetField(apikey.FieldIPWhitelist, field.TypeJSON, value)
  532. _node.IPWhitelist = value
  533. }
  534. if value, ok := _c.mutation.IPBlacklist(); ok {
  535. _spec.SetField(apikey.FieldIPBlacklist, field.TypeJSON, value)
  536. _node.IPBlacklist = value
  537. }
  538. if value, ok := _c.mutation.Quota(); ok {
  539. _spec.SetField(apikey.FieldQuota, field.TypeFloat64, value)
  540. _node.Quota = value
  541. }
  542. if value, ok := _c.mutation.QuotaUsed(); ok {
  543. _spec.SetField(apikey.FieldQuotaUsed, field.TypeFloat64, value)
  544. _node.QuotaUsed = value
  545. }
  546. if value, ok := _c.mutation.ExpiresAt(); ok {
  547. _spec.SetField(apikey.FieldExpiresAt, field.TypeTime, value)
  548. _node.ExpiresAt = &value
  549. }
  550. if value, ok := _c.mutation.RateLimit5h(); ok {
  551. _spec.SetField(apikey.FieldRateLimit5h, field.TypeFloat64, value)
  552. _node.RateLimit5h = value
  553. }
  554. if value, ok := _c.mutation.RateLimit1d(); ok {
  555. _spec.SetField(apikey.FieldRateLimit1d, field.TypeFloat64, value)
  556. _node.RateLimit1d = value
  557. }
  558. if value, ok := _c.mutation.RateLimit7d(); ok {
  559. _spec.SetField(apikey.FieldRateLimit7d, field.TypeFloat64, value)
  560. _node.RateLimit7d = value
  561. }
  562. if value, ok := _c.mutation.Usage5h(); ok {
  563. _spec.SetField(apikey.FieldUsage5h, field.TypeFloat64, value)
  564. _node.Usage5h = value
  565. }
  566. if value, ok := _c.mutation.Usage1d(); ok {
  567. _spec.SetField(apikey.FieldUsage1d, field.TypeFloat64, value)
  568. _node.Usage1d = value
  569. }
  570. if value, ok := _c.mutation.Usage7d(); ok {
  571. _spec.SetField(apikey.FieldUsage7d, field.TypeFloat64, value)
  572. _node.Usage7d = value
  573. }
  574. if value, ok := _c.mutation.Window5hStart(); ok {
  575. _spec.SetField(apikey.FieldWindow5hStart, field.TypeTime, value)
  576. _node.Window5hStart = &value
  577. }
  578. if value, ok := _c.mutation.Window1dStart(); ok {
  579. _spec.SetField(apikey.FieldWindow1dStart, field.TypeTime, value)
  580. _node.Window1dStart = &value
  581. }
  582. if value, ok := _c.mutation.Window7dStart(); ok {
  583. _spec.SetField(apikey.FieldWindow7dStart, field.TypeTime, value)
  584. _node.Window7dStart = &value
  585. }
  586. if nodes := _c.mutation.UserIDs(); len(nodes) > 0 {
  587. edge := &sqlgraph.EdgeSpec{
  588. Rel: sqlgraph.M2O,
  589. Inverse: true,
  590. Table: apikey.UserTable,
  591. Columns: []string{apikey.UserColumn},
  592. Bidi: false,
  593. Target: &sqlgraph.EdgeTarget{
  594. IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt64),
  595. },
  596. }
  597. for _, k := range nodes {
  598. edge.Target.Nodes = append(edge.Target.Nodes, k)
  599. }
  600. _node.UserID = nodes[0]
  601. _spec.Edges = append(_spec.Edges, edge)
  602. }
  603. if nodes := _c.mutation.GroupIDs(); len(nodes) > 0 {
  604. edge := &sqlgraph.EdgeSpec{
  605. Rel: sqlgraph.M2O,
  606. Inverse: true,
  607. Table: apikey.GroupTable,
  608. Columns: []string{apikey.GroupColumn},
  609. Bidi: false,
  610. Target: &sqlgraph.EdgeTarget{
  611. IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt64),
  612. },
  613. }
  614. for _, k := range nodes {
  615. edge.Target.Nodes = append(edge.Target.Nodes, k)
  616. }
  617. _node.GroupID = &nodes[0]
  618. _spec.Edges = append(_spec.Edges, edge)
  619. }
  620. if nodes := _c.mutation.UsageLogsIDs(); len(nodes) > 0 {
  621. edge := &sqlgraph.EdgeSpec{
  622. Rel: sqlgraph.O2M,
  623. Inverse: false,
  624. Table: apikey.UsageLogsTable,
  625. Columns: []string{apikey.UsageLogsColumn},
  626. Bidi: false,
  627. Target: &sqlgraph.EdgeTarget{
  628. IDSpec: sqlgraph.NewFieldSpec(usagelog.FieldID, field.TypeInt64),
  629. },
  630. }
  631. for _, k := range nodes {
  632. edge.Target.Nodes = append(edge.Target.Nodes, k)
  633. }
  634. _spec.Edges = append(_spec.Edges, edge)
  635. }
  636. return _node, _spec
  637. }
  638. // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
  639. // of the `INSERT` statement. For example:
  640. //
  641. // client.APIKey.Create().
  642. // SetCreatedAt(v).
  643. // OnConflict(
  644. // // Update the row with the new values
  645. // // the was proposed for insertion.
  646. // sql.ResolveWithNewValues(),
  647. // ).
  648. // // Override some of the fields with custom
  649. // // update values.
  650. // Update(func(u *ent.APIKeyUpsert) {
  651. // SetCreatedAt(v+v).
  652. // }).
  653. // Exec(ctx)
  654. func (_c *APIKeyCreate) OnConflict(opts ...sql.ConflictOption) *APIKeyUpsertOne {
  655. _c.conflict = opts
  656. return &APIKeyUpsertOne{
  657. create: _c,
  658. }
  659. }
  660. // OnConflictColumns calls `OnConflict` and configures the columns
  661. // as conflict target. Using this option is equivalent to using:
  662. //
  663. // client.APIKey.Create().
  664. // OnConflict(sql.ConflictColumns(columns...)).
  665. // Exec(ctx)
  666. func (_c *APIKeyCreate) OnConflictColumns(columns ...string) *APIKeyUpsertOne {
  667. _c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
  668. return &APIKeyUpsertOne{
  669. create: _c,
  670. }
  671. }
  672. type (
  673. // APIKeyUpsertOne is the builder for "upsert"-ing
  674. // one APIKey node.
  675. APIKeyUpsertOne struct {
  676. create *APIKeyCreate
  677. }
  678. // APIKeyUpsert is the "OnConflict" setter.
  679. APIKeyUpsert struct {
  680. *sql.UpdateSet
  681. }
  682. )
  683. // SetUpdatedAt sets the "updated_at" field.
  684. func (u *APIKeyUpsert) SetUpdatedAt(v time.Time) *APIKeyUpsert {
  685. u.Set(apikey.FieldUpdatedAt, v)
  686. return u
  687. }
  688. // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
  689. func (u *APIKeyUpsert) UpdateUpdatedAt() *APIKeyUpsert {
  690. u.SetExcluded(apikey.FieldUpdatedAt)
  691. return u
  692. }
  693. // SetDeletedAt sets the "deleted_at" field.
  694. func (u *APIKeyUpsert) SetDeletedAt(v time.Time) *APIKeyUpsert {
  695. u.Set(apikey.FieldDeletedAt, v)
  696. return u
  697. }
  698. // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
  699. func (u *APIKeyUpsert) UpdateDeletedAt() *APIKeyUpsert {
  700. u.SetExcluded(apikey.FieldDeletedAt)
  701. return u
  702. }
  703. // ClearDeletedAt clears the value of the "deleted_at" field.
  704. func (u *APIKeyUpsert) ClearDeletedAt() *APIKeyUpsert {
  705. u.SetNull(apikey.FieldDeletedAt)
  706. return u
  707. }
  708. // SetUserID sets the "user_id" field.
  709. func (u *APIKeyUpsert) SetUserID(v int64) *APIKeyUpsert {
  710. u.Set(apikey.FieldUserID, v)
  711. return u
  712. }
  713. // UpdateUserID sets the "user_id" field to the value that was provided on create.
  714. func (u *APIKeyUpsert) UpdateUserID() *APIKeyUpsert {
  715. u.SetExcluded(apikey.FieldUserID)
  716. return u
  717. }
  718. // SetKey sets the "key" field.
  719. func (u *APIKeyUpsert) SetKey(v string) *APIKeyUpsert {
  720. u.Set(apikey.FieldKey, v)
  721. return u
  722. }
  723. // UpdateKey sets the "key" field to the value that was provided on create.
  724. func (u *APIKeyUpsert) UpdateKey() *APIKeyUpsert {
  725. u.SetExcluded(apikey.FieldKey)
  726. return u
  727. }
  728. // ClearKey clears the value of the "key" field.
  729. func (u *APIKeyUpsert) ClearKey() *APIKeyUpsert {
  730. u.SetNull(apikey.FieldKey)
  731. return u
  732. }
  733. // SetKeyHash sets the "key_hash" field.
  734. func (u *APIKeyUpsert) SetKeyHash(v string) *APIKeyUpsert {
  735. u.Set(apikey.FieldKeyHash, v)
  736. return u
  737. }
  738. // UpdateKeyHash sets the "key_hash" field to the value that was provided on create.
  739. func (u *APIKeyUpsert) UpdateKeyHash() *APIKeyUpsert {
  740. u.SetExcluded(apikey.FieldKeyHash)
  741. return u
  742. }
  743. // ClearKeyHash clears the value of the "key_hash" field.
  744. func (u *APIKeyUpsert) ClearKeyHash() *APIKeyUpsert {
  745. u.SetNull(apikey.FieldKeyHash)
  746. return u
  747. }
  748. // SetKeyPrefix sets the "key_prefix" field.
  749. func (u *APIKeyUpsert) SetKeyPrefix(v string) *APIKeyUpsert {
  750. u.Set(apikey.FieldKeyPrefix, v)
  751. return u
  752. }
  753. // UpdateKeyPrefix sets the "key_prefix" field to the value that was provided on create.
  754. func (u *APIKeyUpsert) UpdateKeyPrefix() *APIKeyUpsert {
  755. u.SetExcluded(apikey.FieldKeyPrefix)
  756. return u
  757. }
  758. // ClearKeyPrefix clears the value of the "key_prefix" field.
  759. func (u *APIKeyUpsert) ClearKeyPrefix() *APIKeyUpsert {
  760. u.SetNull(apikey.FieldKeyPrefix)
  761. return u
  762. }
  763. // SetName sets the "name" field.
  764. func (u *APIKeyUpsert) SetName(v string) *APIKeyUpsert {
  765. u.Set(apikey.FieldName, v)
  766. return u
  767. }
  768. // UpdateName sets the "name" field to the value that was provided on create.
  769. func (u *APIKeyUpsert) UpdateName() *APIKeyUpsert {
  770. u.SetExcluded(apikey.FieldName)
  771. return u
  772. }
  773. // SetGroupID sets the "group_id" field.
  774. func (u *APIKeyUpsert) SetGroupID(v int64) *APIKeyUpsert {
  775. u.Set(apikey.FieldGroupID, v)
  776. return u
  777. }
  778. // UpdateGroupID sets the "group_id" field to the value that was provided on create.
  779. func (u *APIKeyUpsert) UpdateGroupID() *APIKeyUpsert {
  780. u.SetExcluded(apikey.FieldGroupID)
  781. return u
  782. }
  783. // ClearGroupID clears the value of the "group_id" field.
  784. func (u *APIKeyUpsert) ClearGroupID() *APIKeyUpsert {
  785. u.SetNull(apikey.FieldGroupID)
  786. return u
  787. }
  788. // SetStatus sets the "status" field.
  789. func (u *APIKeyUpsert) SetStatus(v string) *APIKeyUpsert {
  790. u.Set(apikey.FieldStatus, v)
  791. return u
  792. }
  793. // UpdateStatus sets the "status" field to the value that was provided on create.
  794. func (u *APIKeyUpsert) UpdateStatus() *APIKeyUpsert {
  795. u.SetExcluded(apikey.FieldStatus)
  796. return u
  797. }
  798. // SetLastUsedAt sets the "last_used_at" field.
  799. func (u *APIKeyUpsert) SetLastUsedAt(v time.Time) *APIKeyUpsert {
  800. u.Set(apikey.FieldLastUsedAt, v)
  801. return u
  802. }
  803. // UpdateLastUsedAt sets the "last_used_at" field to the value that was provided on create.
  804. func (u *APIKeyUpsert) UpdateLastUsedAt() *APIKeyUpsert {
  805. u.SetExcluded(apikey.FieldLastUsedAt)
  806. return u
  807. }
  808. // ClearLastUsedAt clears the value of the "last_used_at" field.
  809. func (u *APIKeyUpsert) ClearLastUsedAt() *APIKeyUpsert {
  810. u.SetNull(apikey.FieldLastUsedAt)
  811. return u
  812. }
  813. // SetIPWhitelist sets the "ip_whitelist" field.
  814. func (u *APIKeyUpsert) SetIPWhitelist(v []string) *APIKeyUpsert {
  815. u.Set(apikey.FieldIPWhitelist, v)
  816. return u
  817. }
  818. // UpdateIPWhitelist sets the "ip_whitelist" field to the value that was provided on create.
  819. func (u *APIKeyUpsert) UpdateIPWhitelist() *APIKeyUpsert {
  820. u.SetExcluded(apikey.FieldIPWhitelist)
  821. return u
  822. }
  823. // ClearIPWhitelist clears the value of the "ip_whitelist" field.
  824. func (u *APIKeyUpsert) ClearIPWhitelist() *APIKeyUpsert {
  825. u.SetNull(apikey.FieldIPWhitelist)
  826. return u
  827. }
  828. // SetIPBlacklist sets the "ip_blacklist" field.
  829. func (u *APIKeyUpsert) SetIPBlacklist(v []string) *APIKeyUpsert {
  830. u.Set(apikey.FieldIPBlacklist, v)
  831. return u
  832. }
  833. // UpdateIPBlacklist sets the "ip_blacklist" field to the value that was provided on create.
  834. func (u *APIKeyUpsert) UpdateIPBlacklist() *APIKeyUpsert {
  835. u.SetExcluded(apikey.FieldIPBlacklist)
  836. return u
  837. }
  838. // ClearIPBlacklist clears the value of the "ip_blacklist" field.
  839. func (u *APIKeyUpsert) ClearIPBlacklist() *APIKeyUpsert {
  840. u.SetNull(apikey.FieldIPBlacklist)
  841. return u
  842. }
  843. // SetQuota sets the "quota" field.
  844. func (u *APIKeyUpsert) SetQuota(v float64) *APIKeyUpsert {
  845. u.Set(apikey.FieldQuota, v)
  846. return u
  847. }
  848. // UpdateQuota sets the "quota" field to the value that was provided on create.
  849. func (u *APIKeyUpsert) UpdateQuota() *APIKeyUpsert {
  850. u.SetExcluded(apikey.FieldQuota)
  851. return u
  852. }
  853. // AddQuota adds v to the "quota" field.
  854. func (u *APIKeyUpsert) AddQuota(v float64) *APIKeyUpsert {
  855. u.Add(apikey.FieldQuota, v)
  856. return u
  857. }
  858. // SetQuotaUsed sets the "quota_used" field.
  859. func (u *APIKeyUpsert) SetQuotaUsed(v float64) *APIKeyUpsert {
  860. u.Set(apikey.FieldQuotaUsed, v)
  861. return u
  862. }
  863. // UpdateQuotaUsed sets the "quota_used" field to the value that was provided on create.
  864. func (u *APIKeyUpsert) UpdateQuotaUsed() *APIKeyUpsert {
  865. u.SetExcluded(apikey.FieldQuotaUsed)
  866. return u
  867. }
  868. // AddQuotaUsed adds v to the "quota_used" field.
  869. func (u *APIKeyUpsert) AddQuotaUsed(v float64) *APIKeyUpsert {
  870. u.Add(apikey.FieldQuotaUsed, v)
  871. return u
  872. }
  873. // SetExpiresAt sets the "expires_at" field.
  874. func (u *APIKeyUpsert) SetExpiresAt(v time.Time) *APIKeyUpsert {
  875. u.Set(apikey.FieldExpiresAt, v)
  876. return u
  877. }
  878. // UpdateExpiresAt sets the "expires_at" field to the value that was provided on create.
  879. func (u *APIKeyUpsert) UpdateExpiresAt() *APIKeyUpsert {
  880. u.SetExcluded(apikey.FieldExpiresAt)
  881. return u
  882. }
  883. // ClearExpiresAt clears the value of the "expires_at" field.
  884. func (u *APIKeyUpsert) ClearExpiresAt() *APIKeyUpsert {
  885. u.SetNull(apikey.FieldExpiresAt)
  886. return u
  887. }
  888. // SetRateLimit5h sets the "rate_limit_5h" field.
  889. func (u *APIKeyUpsert) SetRateLimit5h(v float64) *APIKeyUpsert {
  890. u.Set(apikey.FieldRateLimit5h, v)
  891. return u
  892. }
  893. // UpdateRateLimit5h sets the "rate_limit_5h" field to the value that was provided on create.
  894. func (u *APIKeyUpsert) UpdateRateLimit5h() *APIKeyUpsert {
  895. u.SetExcluded(apikey.FieldRateLimit5h)
  896. return u
  897. }
  898. // AddRateLimit5h adds v to the "rate_limit_5h" field.
  899. func (u *APIKeyUpsert) AddRateLimit5h(v float64) *APIKeyUpsert {
  900. u.Add(apikey.FieldRateLimit5h, v)
  901. return u
  902. }
  903. // SetRateLimit1d sets the "rate_limit_1d" field.
  904. func (u *APIKeyUpsert) SetRateLimit1d(v float64) *APIKeyUpsert {
  905. u.Set(apikey.FieldRateLimit1d, v)
  906. return u
  907. }
  908. // UpdateRateLimit1d sets the "rate_limit_1d" field to the value that was provided on create.
  909. func (u *APIKeyUpsert) UpdateRateLimit1d() *APIKeyUpsert {
  910. u.SetExcluded(apikey.FieldRateLimit1d)
  911. return u
  912. }
  913. // AddRateLimit1d adds v to the "rate_limit_1d" field.
  914. func (u *APIKeyUpsert) AddRateLimit1d(v float64) *APIKeyUpsert {
  915. u.Add(apikey.FieldRateLimit1d, v)
  916. return u
  917. }
  918. // SetRateLimit7d sets the "rate_limit_7d" field.
  919. func (u *APIKeyUpsert) SetRateLimit7d(v float64) *APIKeyUpsert {
  920. u.Set(apikey.FieldRateLimit7d, v)
  921. return u
  922. }
  923. // UpdateRateLimit7d sets the "rate_limit_7d" field to the value that was provided on create.
  924. func (u *APIKeyUpsert) UpdateRateLimit7d() *APIKeyUpsert {
  925. u.SetExcluded(apikey.FieldRateLimit7d)
  926. return u
  927. }
  928. // AddRateLimit7d adds v to the "rate_limit_7d" field.
  929. func (u *APIKeyUpsert) AddRateLimit7d(v float64) *APIKeyUpsert {
  930. u.Add(apikey.FieldRateLimit7d, v)
  931. return u
  932. }
  933. // SetUsage5h sets the "usage_5h" field.
  934. func (u *APIKeyUpsert) SetUsage5h(v float64) *APIKeyUpsert {
  935. u.Set(apikey.FieldUsage5h, v)
  936. return u
  937. }
  938. // UpdateUsage5h sets the "usage_5h" field to the value that was provided on create.
  939. func (u *APIKeyUpsert) UpdateUsage5h() *APIKeyUpsert {
  940. u.SetExcluded(apikey.FieldUsage5h)
  941. return u
  942. }
  943. // AddUsage5h adds v to the "usage_5h" field.
  944. func (u *APIKeyUpsert) AddUsage5h(v float64) *APIKeyUpsert {
  945. u.Add(apikey.FieldUsage5h, v)
  946. return u
  947. }
  948. // SetUsage1d sets the "usage_1d" field.
  949. func (u *APIKeyUpsert) SetUsage1d(v float64) *APIKeyUpsert {
  950. u.Set(apikey.FieldUsage1d, v)
  951. return u
  952. }
  953. // UpdateUsage1d sets the "usage_1d" field to the value that was provided on create.
  954. func (u *APIKeyUpsert) UpdateUsage1d() *APIKeyUpsert {
  955. u.SetExcluded(apikey.FieldUsage1d)
  956. return u
  957. }
  958. // AddUsage1d adds v to the "usage_1d" field.
  959. func (u *APIKeyUpsert) AddUsage1d(v float64) *APIKeyUpsert {
  960. u.Add(apikey.FieldUsage1d, v)
  961. return u
  962. }
  963. // SetUsage7d sets the "usage_7d" field.
  964. func (u *APIKeyUpsert) SetUsage7d(v float64) *APIKeyUpsert {
  965. u.Set(apikey.FieldUsage7d, v)
  966. return u
  967. }
  968. // UpdateUsage7d sets the "usage_7d" field to the value that was provided on create.
  969. func (u *APIKeyUpsert) UpdateUsage7d() *APIKeyUpsert {
  970. u.SetExcluded(apikey.FieldUsage7d)
  971. return u
  972. }
  973. // AddUsage7d adds v to the "usage_7d" field.
  974. func (u *APIKeyUpsert) AddUsage7d(v float64) *APIKeyUpsert {
  975. u.Add(apikey.FieldUsage7d, v)
  976. return u
  977. }
  978. // SetWindow5hStart sets the "window_5h_start" field.
  979. func (u *APIKeyUpsert) SetWindow5hStart(v time.Time) *APIKeyUpsert {
  980. u.Set(apikey.FieldWindow5hStart, v)
  981. return u
  982. }
  983. // UpdateWindow5hStart sets the "window_5h_start" field to the value that was provided on create.
  984. func (u *APIKeyUpsert) UpdateWindow5hStart() *APIKeyUpsert {
  985. u.SetExcluded(apikey.FieldWindow5hStart)
  986. return u
  987. }
  988. // ClearWindow5hStart clears the value of the "window_5h_start" field.
  989. func (u *APIKeyUpsert) ClearWindow5hStart() *APIKeyUpsert {
  990. u.SetNull(apikey.FieldWindow5hStart)
  991. return u
  992. }
  993. // SetWindow1dStart sets the "window_1d_start" field.
  994. func (u *APIKeyUpsert) SetWindow1dStart(v time.Time) *APIKeyUpsert {
  995. u.Set(apikey.FieldWindow1dStart, v)
  996. return u
  997. }
  998. // UpdateWindow1dStart sets the "window_1d_start" field to the value that was provided on create.
  999. func (u *APIKeyUpsert) UpdateWindow1dStart() *APIKeyUpsert {
  1000. u.SetExcluded(apikey.FieldWindow1dStart)
  1001. return u
  1002. }
  1003. // ClearWindow1dStart clears the value of the "window_1d_start" field.
  1004. func (u *APIKeyUpsert) ClearWindow1dStart() *APIKeyUpsert {
  1005. u.SetNull(apikey.FieldWindow1dStart)
  1006. return u
  1007. }
  1008. // SetWindow7dStart sets the "window_7d_start" field.
  1009. func (u *APIKeyUpsert) SetWindow7dStart(v time.Time) *APIKeyUpsert {
  1010. u.Set(apikey.FieldWindow7dStart, v)
  1011. return u
  1012. }
  1013. // UpdateWindow7dStart sets the "window_7d_start" field to the value that was provided on create.
  1014. func (u *APIKeyUpsert) UpdateWindow7dStart() *APIKeyUpsert {
  1015. u.SetExcluded(apikey.FieldWindow7dStart)
  1016. return u
  1017. }
  1018. // ClearWindow7dStart clears the value of the "window_7d_start" field.
  1019. func (u *APIKeyUpsert) ClearWindow7dStart() *APIKeyUpsert {
  1020. u.SetNull(apikey.FieldWindow7dStart)
  1021. return u
  1022. }
  1023. // UpdateNewValues updates the mutable fields using the new values that were set on create.
  1024. // Using this option is equivalent to using:
  1025. //
  1026. // client.APIKey.Create().
  1027. // OnConflict(
  1028. // sql.ResolveWithNewValues(),
  1029. // ).
  1030. // Exec(ctx)
  1031. func (u *APIKeyUpsertOne) UpdateNewValues() *APIKeyUpsertOne {
  1032. u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
  1033. u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
  1034. if _, exists := u.create.mutation.CreatedAt(); exists {
  1035. s.SetIgnore(apikey.FieldCreatedAt)
  1036. }
  1037. }))
  1038. return u
  1039. }
  1040. // Ignore sets each column to itself in case of conflict.
  1041. // Using this option is equivalent to using:
  1042. //
  1043. // client.APIKey.Create().
  1044. // OnConflict(sql.ResolveWithIgnore()).
  1045. // Exec(ctx)
  1046. func (u *APIKeyUpsertOne) Ignore() *APIKeyUpsertOne {
  1047. u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
  1048. return u
  1049. }
  1050. // DoNothing configures the conflict_action to `DO NOTHING`.
  1051. // Supported only by SQLite and PostgreSQL.
  1052. func (u *APIKeyUpsertOne) DoNothing() *APIKeyUpsertOne {
  1053. u.create.conflict = append(u.create.conflict, sql.DoNothing())
  1054. return u
  1055. }
  1056. // Update allows overriding fields `UPDATE` values. See the APIKeyCreate.OnConflict
  1057. // documentation for more info.
  1058. func (u *APIKeyUpsertOne) Update(set func(*APIKeyUpsert)) *APIKeyUpsertOne {
  1059. u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
  1060. set(&APIKeyUpsert{UpdateSet: update})
  1061. }))
  1062. return u
  1063. }
  1064. // SetUpdatedAt sets the "updated_at" field.
  1065. func (u *APIKeyUpsertOne) SetUpdatedAt(v time.Time) *APIKeyUpsertOne {
  1066. return u.Update(func(s *APIKeyUpsert) {
  1067. s.SetUpdatedAt(v)
  1068. })
  1069. }
  1070. // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
  1071. func (u *APIKeyUpsertOne) UpdateUpdatedAt() *APIKeyUpsertOne {
  1072. return u.Update(func(s *APIKeyUpsert) {
  1073. s.UpdateUpdatedAt()
  1074. })
  1075. }
  1076. // SetDeletedAt sets the "deleted_at" field.
  1077. func (u *APIKeyUpsertOne) SetDeletedAt(v time.Time) *APIKeyUpsertOne {
  1078. return u.Update(func(s *APIKeyUpsert) {
  1079. s.SetDeletedAt(v)
  1080. })
  1081. }
  1082. // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
  1083. func (u *APIKeyUpsertOne) UpdateDeletedAt() *APIKeyUpsertOne {
  1084. return u.Update(func(s *APIKeyUpsert) {
  1085. s.UpdateDeletedAt()
  1086. })
  1087. }
  1088. // ClearDeletedAt clears the value of the "deleted_at" field.
  1089. func (u *APIKeyUpsertOne) ClearDeletedAt() *APIKeyUpsertOne {
  1090. return u.Update(func(s *APIKeyUpsert) {
  1091. s.ClearDeletedAt()
  1092. })
  1093. }
  1094. // SetUserID sets the "user_id" field.
  1095. func (u *APIKeyUpsertOne) SetUserID(v int64) *APIKeyUpsertOne {
  1096. return u.Update(func(s *APIKeyUpsert) {
  1097. s.SetUserID(v)
  1098. })
  1099. }
  1100. // UpdateUserID sets the "user_id" field to the value that was provided on create.
  1101. func (u *APIKeyUpsertOne) UpdateUserID() *APIKeyUpsertOne {
  1102. return u.Update(func(s *APIKeyUpsert) {
  1103. s.UpdateUserID()
  1104. })
  1105. }
  1106. // SetKey sets the "key" field.
  1107. func (u *APIKeyUpsertOne) SetKey(v string) *APIKeyUpsertOne {
  1108. return u.Update(func(s *APIKeyUpsert) {
  1109. s.SetKey(v)
  1110. })
  1111. }
  1112. // UpdateKey sets the "key" field to the value that was provided on create.
  1113. func (u *APIKeyUpsertOne) UpdateKey() *APIKeyUpsertOne {
  1114. return u.Update(func(s *APIKeyUpsert) {
  1115. s.UpdateKey()
  1116. })
  1117. }
  1118. // ClearKey clears the value of the "key" field.
  1119. func (u *APIKeyUpsertOne) ClearKey() *APIKeyUpsertOne {
  1120. return u.Update(func(s *APIKeyUpsert) {
  1121. s.ClearKey()
  1122. })
  1123. }
  1124. // SetKeyHash sets the "key_hash" field.
  1125. func (u *APIKeyUpsertOne) SetKeyHash(v string) *APIKeyUpsertOne {
  1126. return u.Update(func(s *APIKeyUpsert) {
  1127. s.SetKeyHash(v)
  1128. })
  1129. }
  1130. // UpdateKeyHash sets the "key_hash" field to the value that was provided on create.
  1131. func (u *APIKeyUpsertOne) UpdateKeyHash() *APIKeyUpsertOne {
  1132. return u.Update(func(s *APIKeyUpsert) {
  1133. s.UpdateKeyHash()
  1134. })
  1135. }
  1136. // ClearKeyHash clears the value of the "key_hash" field.
  1137. func (u *APIKeyUpsertOne) ClearKeyHash() *APIKeyUpsertOne {
  1138. return u.Update(func(s *APIKeyUpsert) {
  1139. s.ClearKeyHash()
  1140. })
  1141. }
  1142. // SetKeyPrefix sets the "key_prefix" field.
  1143. func (u *APIKeyUpsertOne) SetKeyPrefix(v string) *APIKeyUpsertOne {
  1144. return u.Update(func(s *APIKeyUpsert) {
  1145. s.SetKeyPrefix(v)
  1146. })
  1147. }
  1148. // UpdateKeyPrefix sets the "key_prefix" field to the value that was provided on create.
  1149. func (u *APIKeyUpsertOne) UpdateKeyPrefix() *APIKeyUpsertOne {
  1150. return u.Update(func(s *APIKeyUpsert) {
  1151. s.UpdateKeyPrefix()
  1152. })
  1153. }
  1154. // ClearKeyPrefix clears the value of the "key_prefix" field.
  1155. func (u *APIKeyUpsertOne) ClearKeyPrefix() *APIKeyUpsertOne {
  1156. return u.Update(func(s *APIKeyUpsert) {
  1157. s.ClearKeyPrefix()
  1158. })
  1159. }
  1160. // SetName sets the "name" field.
  1161. func (u *APIKeyUpsertOne) SetName(v string) *APIKeyUpsertOne {
  1162. return u.Update(func(s *APIKeyUpsert) {
  1163. s.SetName(v)
  1164. })
  1165. }
  1166. // UpdateName sets the "name" field to the value that was provided on create.
  1167. func (u *APIKeyUpsertOne) UpdateName() *APIKeyUpsertOne {
  1168. return u.Update(func(s *APIKeyUpsert) {
  1169. s.UpdateName()
  1170. })
  1171. }
  1172. // SetGroupID sets the "group_id" field.
  1173. func (u *APIKeyUpsertOne) SetGroupID(v int64) *APIKeyUpsertOne {
  1174. return u.Update(func(s *APIKeyUpsert) {
  1175. s.SetGroupID(v)
  1176. })
  1177. }
  1178. // UpdateGroupID sets the "group_id" field to the value that was provided on create.
  1179. func (u *APIKeyUpsertOne) UpdateGroupID() *APIKeyUpsertOne {
  1180. return u.Update(func(s *APIKeyUpsert) {
  1181. s.UpdateGroupID()
  1182. })
  1183. }
  1184. // ClearGroupID clears the value of the "group_id" field.
  1185. func (u *APIKeyUpsertOne) ClearGroupID() *APIKeyUpsertOne {
  1186. return u.Update(func(s *APIKeyUpsert) {
  1187. s.ClearGroupID()
  1188. })
  1189. }
  1190. // SetStatus sets the "status" field.
  1191. func (u *APIKeyUpsertOne) SetStatus(v string) *APIKeyUpsertOne {
  1192. return u.Update(func(s *APIKeyUpsert) {
  1193. s.SetStatus(v)
  1194. })
  1195. }
  1196. // UpdateStatus sets the "status" field to the value that was provided on create.
  1197. func (u *APIKeyUpsertOne) UpdateStatus() *APIKeyUpsertOne {
  1198. return u.Update(func(s *APIKeyUpsert) {
  1199. s.UpdateStatus()
  1200. })
  1201. }
  1202. // SetLastUsedAt sets the "last_used_at" field.
  1203. func (u *APIKeyUpsertOne) SetLastUsedAt(v time.Time) *APIKeyUpsertOne {
  1204. return u.Update(func(s *APIKeyUpsert) {
  1205. s.SetLastUsedAt(v)
  1206. })
  1207. }
  1208. // UpdateLastUsedAt sets the "last_used_at" field to the value that was provided on create.
  1209. func (u *APIKeyUpsertOne) UpdateLastUsedAt() *APIKeyUpsertOne {
  1210. return u.Update(func(s *APIKeyUpsert) {
  1211. s.UpdateLastUsedAt()
  1212. })
  1213. }
  1214. // ClearLastUsedAt clears the value of the "last_used_at" field.
  1215. func (u *APIKeyUpsertOne) ClearLastUsedAt() *APIKeyUpsertOne {
  1216. return u.Update(func(s *APIKeyUpsert) {
  1217. s.ClearLastUsedAt()
  1218. })
  1219. }
  1220. // SetIPWhitelist sets the "ip_whitelist" field.
  1221. func (u *APIKeyUpsertOne) SetIPWhitelist(v []string) *APIKeyUpsertOne {
  1222. return u.Update(func(s *APIKeyUpsert) {
  1223. s.SetIPWhitelist(v)
  1224. })
  1225. }
  1226. // UpdateIPWhitelist sets the "ip_whitelist" field to the value that was provided on create.
  1227. func (u *APIKeyUpsertOne) UpdateIPWhitelist() *APIKeyUpsertOne {
  1228. return u.Update(func(s *APIKeyUpsert) {
  1229. s.UpdateIPWhitelist()
  1230. })
  1231. }
  1232. // ClearIPWhitelist clears the value of the "ip_whitelist" field.
  1233. func (u *APIKeyUpsertOne) ClearIPWhitelist() *APIKeyUpsertOne {
  1234. return u.Update(func(s *APIKeyUpsert) {
  1235. s.ClearIPWhitelist()
  1236. })
  1237. }
  1238. // SetIPBlacklist sets the "ip_blacklist" field.
  1239. func (u *APIKeyUpsertOne) SetIPBlacklist(v []string) *APIKeyUpsertOne {
  1240. return u.Update(func(s *APIKeyUpsert) {
  1241. s.SetIPBlacklist(v)
  1242. })
  1243. }
  1244. // UpdateIPBlacklist sets the "ip_blacklist" field to the value that was provided on create.
  1245. func (u *APIKeyUpsertOne) UpdateIPBlacklist() *APIKeyUpsertOne {
  1246. return u.Update(func(s *APIKeyUpsert) {
  1247. s.UpdateIPBlacklist()
  1248. })
  1249. }
  1250. // ClearIPBlacklist clears the value of the "ip_blacklist" field.
  1251. func (u *APIKeyUpsertOne) ClearIPBlacklist() *APIKeyUpsertOne {
  1252. return u.Update(func(s *APIKeyUpsert) {
  1253. s.ClearIPBlacklist()
  1254. })
  1255. }
  1256. // SetQuota sets the "quota" field.
  1257. func (u *APIKeyUpsertOne) SetQuota(v float64) *APIKeyUpsertOne {
  1258. return u.Update(func(s *APIKeyUpsert) {
  1259. s.SetQuota(v)
  1260. })
  1261. }
  1262. // AddQuota adds v to the "quota" field.
  1263. func (u *APIKeyUpsertOne) AddQuota(v float64) *APIKeyUpsertOne {
  1264. return u.Update(func(s *APIKeyUpsert) {
  1265. s.AddQuota(v)
  1266. })
  1267. }
  1268. // UpdateQuota sets the "quota" field to the value that was provided on create.
  1269. func (u *APIKeyUpsertOne) UpdateQuota() *APIKeyUpsertOne {
  1270. return u.Update(func(s *APIKeyUpsert) {
  1271. s.UpdateQuota()
  1272. })
  1273. }
  1274. // SetQuotaUsed sets the "quota_used" field.
  1275. func (u *APIKeyUpsertOne) SetQuotaUsed(v float64) *APIKeyUpsertOne {
  1276. return u.Update(func(s *APIKeyUpsert) {
  1277. s.SetQuotaUsed(v)
  1278. })
  1279. }
  1280. // AddQuotaUsed adds v to the "quota_used" field.
  1281. func (u *APIKeyUpsertOne) AddQuotaUsed(v float64) *APIKeyUpsertOne {
  1282. return u.Update(func(s *APIKeyUpsert) {
  1283. s.AddQuotaUsed(v)
  1284. })
  1285. }
  1286. // UpdateQuotaUsed sets the "quota_used" field to the value that was provided on create.
  1287. func (u *APIKeyUpsertOne) UpdateQuotaUsed() *APIKeyUpsertOne {
  1288. return u.Update(func(s *APIKeyUpsert) {
  1289. s.UpdateQuotaUsed()
  1290. })
  1291. }
  1292. // SetExpiresAt sets the "expires_at" field.
  1293. func (u *APIKeyUpsertOne) SetExpiresAt(v time.Time) *APIKeyUpsertOne {
  1294. return u.Update(func(s *APIKeyUpsert) {
  1295. s.SetExpiresAt(v)
  1296. })
  1297. }
  1298. // UpdateExpiresAt sets the "expires_at" field to the value that was provided on create.
  1299. func (u *APIKeyUpsertOne) UpdateExpiresAt() *APIKeyUpsertOne {
  1300. return u.Update(func(s *APIKeyUpsert) {
  1301. s.UpdateExpiresAt()
  1302. })
  1303. }
  1304. // ClearExpiresAt clears the value of the "expires_at" field.
  1305. func (u *APIKeyUpsertOne) ClearExpiresAt() *APIKeyUpsertOne {
  1306. return u.Update(func(s *APIKeyUpsert) {
  1307. s.ClearExpiresAt()
  1308. })
  1309. }
  1310. // SetRateLimit5h sets the "rate_limit_5h" field.
  1311. func (u *APIKeyUpsertOne) SetRateLimit5h(v float64) *APIKeyUpsertOne {
  1312. return u.Update(func(s *APIKeyUpsert) {
  1313. s.SetRateLimit5h(v)
  1314. })
  1315. }
  1316. // AddRateLimit5h adds v to the "rate_limit_5h" field.
  1317. func (u *APIKeyUpsertOne) AddRateLimit5h(v float64) *APIKeyUpsertOne {
  1318. return u.Update(func(s *APIKeyUpsert) {
  1319. s.AddRateLimit5h(v)
  1320. })
  1321. }
  1322. // UpdateRateLimit5h sets the "rate_limit_5h" field to the value that was provided on create.
  1323. func (u *APIKeyUpsertOne) UpdateRateLimit5h() *APIKeyUpsertOne {
  1324. return u.Update(func(s *APIKeyUpsert) {
  1325. s.UpdateRateLimit5h()
  1326. })
  1327. }
  1328. // SetRateLimit1d sets the "rate_limit_1d" field.
  1329. func (u *APIKeyUpsertOne) SetRateLimit1d(v float64) *APIKeyUpsertOne {
  1330. return u.Update(func(s *APIKeyUpsert) {
  1331. s.SetRateLimit1d(v)
  1332. })
  1333. }
  1334. // AddRateLimit1d adds v to the "rate_limit_1d" field.
  1335. func (u *APIKeyUpsertOne) AddRateLimit1d(v float64) *APIKeyUpsertOne {
  1336. return u.Update(func(s *APIKeyUpsert) {
  1337. s.AddRateLimit1d(v)
  1338. })
  1339. }
  1340. // UpdateRateLimit1d sets the "rate_limit_1d" field to the value that was provided on create.
  1341. func (u *APIKeyUpsertOne) UpdateRateLimit1d() *APIKeyUpsertOne {
  1342. return u.Update(func(s *APIKeyUpsert) {
  1343. s.UpdateRateLimit1d()
  1344. })
  1345. }
  1346. // SetRateLimit7d sets the "rate_limit_7d" field.
  1347. func (u *APIKeyUpsertOne) SetRateLimit7d(v float64) *APIKeyUpsertOne {
  1348. return u.Update(func(s *APIKeyUpsert) {
  1349. s.SetRateLimit7d(v)
  1350. })
  1351. }
  1352. // AddRateLimit7d adds v to the "rate_limit_7d" field.
  1353. func (u *APIKeyUpsertOne) AddRateLimit7d(v float64) *APIKeyUpsertOne {
  1354. return u.Update(func(s *APIKeyUpsert) {
  1355. s.AddRateLimit7d(v)
  1356. })
  1357. }
  1358. // UpdateRateLimit7d sets the "rate_limit_7d" field to the value that was provided on create.
  1359. func (u *APIKeyUpsertOne) UpdateRateLimit7d() *APIKeyUpsertOne {
  1360. return u.Update(func(s *APIKeyUpsert) {
  1361. s.UpdateRateLimit7d()
  1362. })
  1363. }
  1364. // SetUsage5h sets the "usage_5h" field.
  1365. func (u *APIKeyUpsertOne) SetUsage5h(v float64) *APIKeyUpsertOne {
  1366. return u.Update(func(s *APIKeyUpsert) {
  1367. s.SetUsage5h(v)
  1368. })
  1369. }
  1370. // AddUsage5h adds v to the "usage_5h" field.
  1371. func (u *APIKeyUpsertOne) AddUsage5h(v float64) *APIKeyUpsertOne {
  1372. return u.Update(func(s *APIKeyUpsert) {
  1373. s.AddUsage5h(v)
  1374. })
  1375. }
  1376. // UpdateUsage5h sets the "usage_5h" field to the value that was provided on create.
  1377. func (u *APIKeyUpsertOne) UpdateUsage5h() *APIKeyUpsertOne {
  1378. return u.Update(func(s *APIKeyUpsert) {
  1379. s.UpdateUsage5h()
  1380. })
  1381. }
  1382. // SetUsage1d sets the "usage_1d" field.
  1383. func (u *APIKeyUpsertOne) SetUsage1d(v float64) *APIKeyUpsertOne {
  1384. return u.Update(func(s *APIKeyUpsert) {
  1385. s.SetUsage1d(v)
  1386. })
  1387. }
  1388. // AddUsage1d adds v to the "usage_1d" field.
  1389. func (u *APIKeyUpsertOne) AddUsage1d(v float64) *APIKeyUpsertOne {
  1390. return u.Update(func(s *APIKeyUpsert) {
  1391. s.AddUsage1d(v)
  1392. })
  1393. }
  1394. // UpdateUsage1d sets the "usage_1d" field to the value that was provided on create.
  1395. func (u *APIKeyUpsertOne) UpdateUsage1d() *APIKeyUpsertOne {
  1396. return u.Update(func(s *APIKeyUpsert) {
  1397. s.UpdateUsage1d()
  1398. })
  1399. }
  1400. // SetUsage7d sets the "usage_7d" field.
  1401. func (u *APIKeyUpsertOne) SetUsage7d(v float64) *APIKeyUpsertOne {
  1402. return u.Update(func(s *APIKeyUpsert) {
  1403. s.SetUsage7d(v)
  1404. })
  1405. }
  1406. // AddUsage7d adds v to the "usage_7d" field.
  1407. func (u *APIKeyUpsertOne) AddUsage7d(v float64) *APIKeyUpsertOne {
  1408. return u.Update(func(s *APIKeyUpsert) {
  1409. s.AddUsage7d(v)
  1410. })
  1411. }
  1412. // UpdateUsage7d sets the "usage_7d" field to the value that was provided on create.
  1413. func (u *APIKeyUpsertOne) UpdateUsage7d() *APIKeyUpsertOne {
  1414. return u.Update(func(s *APIKeyUpsert) {
  1415. s.UpdateUsage7d()
  1416. })
  1417. }
  1418. // SetWindow5hStart sets the "window_5h_start" field.
  1419. func (u *APIKeyUpsertOne) SetWindow5hStart(v time.Time) *APIKeyUpsertOne {
  1420. return u.Update(func(s *APIKeyUpsert) {
  1421. s.SetWindow5hStart(v)
  1422. })
  1423. }
  1424. // UpdateWindow5hStart sets the "window_5h_start" field to the value that was provided on create.
  1425. func (u *APIKeyUpsertOne) UpdateWindow5hStart() *APIKeyUpsertOne {
  1426. return u.Update(func(s *APIKeyUpsert) {
  1427. s.UpdateWindow5hStart()
  1428. })
  1429. }
  1430. // ClearWindow5hStart clears the value of the "window_5h_start" field.
  1431. func (u *APIKeyUpsertOne) ClearWindow5hStart() *APIKeyUpsertOne {
  1432. return u.Update(func(s *APIKeyUpsert) {
  1433. s.ClearWindow5hStart()
  1434. })
  1435. }
  1436. // SetWindow1dStart sets the "window_1d_start" field.
  1437. func (u *APIKeyUpsertOne) SetWindow1dStart(v time.Time) *APIKeyUpsertOne {
  1438. return u.Update(func(s *APIKeyUpsert) {
  1439. s.SetWindow1dStart(v)
  1440. })
  1441. }
  1442. // UpdateWindow1dStart sets the "window_1d_start" field to the value that was provided on create.
  1443. func (u *APIKeyUpsertOne) UpdateWindow1dStart() *APIKeyUpsertOne {
  1444. return u.Update(func(s *APIKeyUpsert) {
  1445. s.UpdateWindow1dStart()
  1446. })
  1447. }
  1448. // ClearWindow1dStart clears the value of the "window_1d_start" field.
  1449. func (u *APIKeyUpsertOne) ClearWindow1dStart() *APIKeyUpsertOne {
  1450. return u.Update(func(s *APIKeyUpsert) {
  1451. s.ClearWindow1dStart()
  1452. })
  1453. }
  1454. // SetWindow7dStart sets the "window_7d_start" field.
  1455. func (u *APIKeyUpsertOne) SetWindow7dStart(v time.Time) *APIKeyUpsertOne {
  1456. return u.Update(func(s *APIKeyUpsert) {
  1457. s.SetWindow7dStart(v)
  1458. })
  1459. }
  1460. // UpdateWindow7dStart sets the "window_7d_start" field to the value that was provided on create.
  1461. func (u *APIKeyUpsertOne) UpdateWindow7dStart() *APIKeyUpsertOne {
  1462. return u.Update(func(s *APIKeyUpsert) {
  1463. s.UpdateWindow7dStart()
  1464. })
  1465. }
  1466. // ClearWindow7dStart clears the value of the "window_7d_start" field.
  1467. func (u *APIKeyUpsertOne) ClearWindow7dStart() *APIKeyUpsertOne {
  1468. return u.Update(func(s *APIKeyUpsert) {
  1469. s.ClearWindow7dStart()
  1470. })
  1471. }
  1472. // Exec executes the query.
  1473. func (u *APIKeyUpsertOne) Exec(ctx context.Context) error {
  1474. if len(u.create.conflict) == 0 {
  1475. return errors.New("ent: missing options for APIKeyCreate.OnConflict")
  1476. }
  1477. return u.create.Exec(ctx)
  1478. }
  1479. // ExecX is like Exec, but panics if an error occurs.
  1480. func (u *APIKeyUpsertOne) ExecX(ctx context.Context) {
  1481. if err := u.create.Exec(ctx); err != nil {
  1482. panic(err)
  1483. }
  1484. }
  1485. // Exec executes the UPSERT query and returns the inserted/updated ID.
  1486. func (u *APIKeyUpsertOne) ID(ctx context.Context) (id int64, err error) {
  1487. node, err := u.create.Save(ctx)
  1488. if err != nil {
  1489. return id, err
  1490. }
  1491. return node.ID, nil
  1492. }
  1493. // IDX is like ID, but panics if an error occurs.
  1494. func (u *APIKeyUpsertOne) IDX(ctx context.Context) int64 {
  1495. id, err := u.ID(ctx)
  1496. if err != nil {
  1497. panic(err)
  1498. }
  1499. return id
  1500. }
  1501. // APIKeyCreateBulk is the builder for creating many APIKey entities in bulk.
  1502. type APIKeyCreateBulk struct {
  1503. config
  1504. err error
  1505. builders []*APIKeyCreate
  1506. conflict []sql.ConflictOption
  1507. }
  1508. // Save creates the APIKey entities in the database.
  1509. func (_c *APIKeyCreateBulk) Save(ctx context.Context) ([]*APIKey, error) {
  1510. if _c.err != nil {
  1511. return nil, _c.err
  1512. }
  1513. specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
  1514. nodes := make([]*APIKey, len(_c.builders))
  1515. mutators := make([]Mutator, len(_c.builders))
  1516. for i := range _c.builders {
  1517. func(i int, root context.Context) {
  1518. builder := _c.builders[i]
  1519. builder.defaults()
  1520. var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
  1521. mutation, ok := m.(*APIKeyMutation)
  1522. if !ok {
  1523. return nil, fmt.Errorf("unexpected mutation type %T", m)
  1524. }
  1525. if err := builder.check(); err != nil {
  1526. return nil, err
  1527. }
  1528. builder.mutation = mutation
  1529. var err error
  1530. nodes[i], specs[i] = builder.createSpec()
  1531. if i < len(mutators)-1 {
  1532. _, err = mutators[i+1].Mutate(root, _c.builders[i+1].mutation)
  1533. } else {
  1534. spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
  1535. spec.OnConflict = _c.conflict
  1536. // Invoke the actual operation on the latest mutation in the chain.
  1537. if err = sqlgraph.BatchCreate(ctx, _c.driver, spec); err != nil {
  1538. if sqlgraph.IsConstraintError(err) {
  1539. err = &ConstraintError{msg: err.Error(), wrap: err}
  1540. }
  1541. }
  1542. }
  1543. if err != nil {
  1544. return nil, err
  1545. }
  1546. mutation.id = &nodes[i].ID
  1547. if specs[i].ID.Value != nil {
  1548. id := specs[i].ID.Value.(int64)
  1549. nodes[i].ID = int64(id)
  1550. }
  1551. mutation.done = true
  1552. return nodes[i], nil
  1553. })
  1554. for i := len(builder.hooks) - 1; i >= 0; i-- {
  1555. mut = builder.hooks[i](mut)
  1556. }
  1557. mutators[i] = mut
  1558. }(i, ctx)
  1559. }
  1560. if len(mutators) > 0 {
  1561. if _, err := mutators[0].Mutate(ctx, _c.builders[0].mutation); err != nil {
  1562. return nil, err
  1563. }
  1564. }
  1565. return nodes, nil
  1566. }
  1567. // SaveX is like Save, but panics if an error occurs.
  1568. func (_c *APIKeyCreateBulk) SaveX(ctx context.Context) []*APIKey {
  1569. v, err := _c.Save(ctx)
  1570. if err != nil {
  1571. panic(err)
  1572. }
  1573. return v
  1574. }
  1575. // Exec executes the query.
  1576. func (_c *APIKeyCreateBulk) Exec(ctx context.Context) error {
  1577. _, err := _c.Save(ctx)
  1578. return err
  1579. }
  1580. // ExecX is like Exec, but panics if an error occurs.
  1581. func (_c *APIKeyCreateBulk) ExecX(ctx context.Context) {
  1582. if err := _c.Exec(ctx); err != nil {
  1583. panic(err)
  1584. }
  1585. }
  1586. // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
  1587. // of the `INSERT` statement. For example:
  1588. //
  1589. // client.APIKey.CreateBulk(builders...).
  1590. // OnConflict(
  1591. // // Update the row with the new values
  1592. // // the was proposed for insertion.
  1593. // sql.ResolveWithNewValues(),
  1594. // ).
  1595. // // Override some of the fields with custom
  1596. // // update values.
  1597. // Update(func(u *ent.APIKeyUpsert) {
  1598. // SetCreatedAt(v+v).
  1599. // }).
  1600. // Exec(ctx)
  1601. func (_c *APIKeyCreateBulk) OnConflict(opts ...sql.ConflictOption) *APIKeyUpsertBulk {
  1602. _c.conflict = opts
  1603. return &APIKeyUpsertBulk{
  1604. create: _c,
  1605. }
  1606. }
  1607. // OnConflictColumns calls `OnConflict` and configures the columns
  1608. // as conflict target. Using this option is equivalent to using:
  1609. //
  1610. // client.APIKey.Create().
  1611. // OnConflict(sql.ConflictColumns(columns...)).
  1612. // Exec(ctx)
  1613. func (_c *APIKeyCreateBulk) OnConflictColumns(columns ...string) *APIKeyUpsertBulk {
  1614. _c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
  1615. return &APIKeyUpsertBulk{
  1616. create: _c,
  1617. }
  1618. }
  1619. // APIKeyUpsertBulk is the builder for "upsert"-ing
  1620. // a bulk of APIKey nodes.
  1621. type APIKeyUpsertBulk struct {
  1622. create *APIKeyCreateBulk
  1623. }
  1624. // UpdateNewValues updates the mutable fields using the new values that
  1625. // were set on create. Using this option is equivalent to using:
  1626. //
  1627. // client.APIKey.Create().
  1628. // OnConflict(
  1629. // sql.ResolveWithNewValues(),
  1630. // ).
  1631. // Exec(ctx)
  1632. func (u *APIKeyUpsertBulk) UpdateNewValues() *APIKeyUpsertBulk {
  1633. u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
  1634. u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
  1635. for _, b := range u.create.builders {
  1636. if _, exists := b.mutation.CreatedAt(); exists {
  1637. s.SetIgnore(apikey.FieldCreatedAt)
  1638. }
  1639. }
  1640. }))
  1641. return u
  1642. }
  1643. // Ignore sets each column to itself in case of conflict.
  1644. // Using this option is equivalent to using:
  1645. //
  1646. // client.APIKey.Create().
  1647. // OnConflict(sql.ResolveWithIgnore()).
  1648. // Exec(ctx)
  1649. func (u *APIKeyUpsertBulk) Ignore() *APIKeyUpsertBulk {
  1650. u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
  1651. return u
  1652. }
  1653. // DoNothing configures the conflict_action to `DO NOTHING`.
  1654. // Supported only by SQLite and PostgreSQL.
  1655. func (u *APIKeyUpsertBulk) DoNothing() *APIKeyUpsertBulk {
  1656. u.create.conflict = append(u.create.conflict, sql.DoNothing())
  1657. return u
  1658. }
  1659. // Update allows overriding fields `UPDATE` values. See the APIKeyCreateBulk.OnConflict
  1660. // documentation for more info.
  1661. func (u *APIKeyUpsertBulk) Update(set func(*APIKeyUpsert)) *APIKeyUpsertBulk {
  1662. u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
  1663. set(&APIKeyUpsert{UpdateSet: update})
  1664. }))
  1665. return u
  1666. }
  1667. // SetUpdatedAt sets the "updated_at" field.
  1668. func (u *APIKeyUpsertBulk) SetUpdatedAt(v time.Time) *APIKeyUpsertBulk {
  1669. return u.Update(func(s *APIKeyUpsert) {
  1670. s.SetUpdatedAt(v)
  1671. })
  1672. }
  1673. // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
  1674. func (u *APIKeyUpsertBulk) UpdateUpdatedAt() *APIKeyUpsertBulk {
  1675. return u.Update(func(s *APIKeyUpsert) {
  1676. s.UpdateUpdatedAt()
  1677. })
  1678. }
  1679. // SetDeletedAt sets the "deleted_at" field.
  1680. func (u *APIKeyUpsertBulk) SetDeletedAt(v time.Time) *APIKeyUpsertBulk {
  1681. return u.Update(func(s *APIKeyUpsert) {
  1682. s.SetDeletedAt(v)
  1683. })
  1684. }
  1685. // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
  1686. func (u *APIKeyUpsertBulk) UpdateDeletedAt() *APIKeyUpsertBulk {
  1687. return u.Update(func(s *APIKeyUpsert) {
  1688. s.UpdateDeletedAt()
  1689. })
  1690. }
  1691. // ClearDeletedAt clears the value of the "deleted_at" field.
  1692. func (u *APIKeyUpsertBulk) ClearDeletedAt() *APIKeyUpsertBulk {
  1693. return u.Update(func(s *APIKeyUpsert) {
  1694. s.ClearDeletedAt()
  1695. })
  1696. }
  1697. // SetUserID sets the "user_id" field.
  1698. func (u *APIKeyUpsertBulk) SetUserID(v int64) *APIKeyUpsertBulk {
  1699. return u.Update(func(s *APIKeyUpsert) {
  1700. s.SetUserID(v)
  1701. })
  1702. }
  1703. // UpdateUserID sets the "user_id" field to the value that was provided on create.
  1704. func (u *APIKeyUpsertBulk) UpdateUserID() *APIKeyUpsertBulk {
  1705. return u.Update(func(s *APIKeyUpsert) {
  1706. s.UpdateUserID()
  1707. })
  1708. }
  1709. // SetKey sets the "key" field.
  1710. func (u *APIKeyUpsertBulk) SetKey(v string) *APIKeyUpsertBulk {
  1711. return u.Update(func(s *APIKeyUpsert) {
  1712. s.SetKey(v)
  1713. })
  1714. }
  1715. // UpdateKey sets the "key" field to the value that was provided on create.
  1716. func (u *APIKeyUpsertBulk) UpdateKey() *APIKeyUpsertBulk {
  1717. return u.Update(func(s *APIKeyUpsert) {
  1718. s.UpdateKey()
  1719. })
  1720. }
  1721. // ClearKey clears the value of the "key" field.
  1722. func (u *APIKeyUpsertBulk) ClearKey() *APIKeyUpsertBulk {
  1723. return u.Update(func(s *APIKeyUpsert) {
  1724. s.ClearKey()
  1725. })
  1726. }
  1727. // SetKeyHash sets the "key_hash" field.
  1728. func (u *APIKeyUpsertBulk) SetKeyHash(v string) *APIKeyUpsertBulk {
  1729. return u.Update(func(s *APIKeyUpsert) {
  1730. s.SetKeyHash(v)
  1731. })
  1732. }
  1733. // UpdateKeyHash sets the "key_hash" field to the value that was provided on create.
  1734. func (u *APIKeyUpsertBulk) UpdateKeyHash() *APIKeyUpsertBulk {
  1735. return u.Update(func(s *APIKeyUpsert) {
  1736. s.UpdateKeyHash()
  1737. })
  1738. }
  1739. // ClearKeyHash clears the value of the "key_hash" field.
  1740. func (u *APIKeyUpsertBulk) ClearKeyHash() *APIKeyUpsertBulk {
  1741. return u.Update(func(s *APIKeyUpsert) {
  1742. s.ClearKeyHash()
  1743. })
  1744. }
  1745. // SetKeyPrefix sets the "key_prefix" field.
  1746. func (u *APIKeyUpsertBulk) SetKeyPrefix(v string) *APIKeyUpsertBulk {
  1747. return u.Update(func(s *APIKeyUpsert) {
  1748. s.SetKeyPrefix(v)
  1749. })
  1750. }
  1751. // UpdateKeyPrefix sets the "key_prefix" field to the value that was provided on create.
  1752. func (u *APIKeyUpsertBulk) UpdateKeyPrefix() *APIKeyUpsertBulk {
  1753. return u.Update(func(s *APIKeyUpsert) {
  1754. s.UpdateKeyPrefix()
  1755. })
  1756. }
  1757. // ClearKeyPrefix clears the value of the "key_prefix" field.
  1758. func (u *APIKeyUpsertBulk) ClearKeyPrefix() *APIKeyUpsertBulk {
  1759. return u.Update(func(s *APIKeyUpsert) {
  1760. s.ClearKeyPrefix()
  1761. })
  1762. }
  1763. // SetName sets the "name" field.
  1764. func (u *APIKeyUpsertBulk) SetName(v string) *APIKeyUpsertBulk {
  1765. return u.Update(func(s *APIKeyUpsert) {
  1766. s.SetName(v)
  1767. })
  1768. }
  1769. // UpdateName sets the "name" field to the value that was provided on create.
  1770. func (u *APIKeyUpsertBulk) UpdateName() *APIKeyUpsertBulk {
  1771. return u.Update(func(s *APIKeyUpsert) {
  1772. s.UpdateName()
  1773. })
  1774. }
  1775. // SetGroupID sets the "group_id" field.
  1776. func (u *APIKeyUpsertBulk) SetGroupID(v int64) *APIKeyUpsertBulk {
  1777. return u.Update(func(s *APIKeyUpsert) {
  1778. s.SetGroupID(v)
  1779. })
  1780. }
  1781. // UpdateGroupID sets the "group_id" field to the value that was provided on create.
  1782. func (u *APIKeyUpsertBulk) UpdateGroupID() *APIKeyUpsertBulk {
  1783. return u.Update(func(s *APIKeyUpsert) {
  1784. s.UpdateGroupID()
  1785. })
  1786. }
  1787. // ClearGroupID clears the value of the "group_id" field.
  1788. func (u *APIKeyUpsertBulk) ClearGroupID() *APIKeyUpsertBulk {
  1789. return u.Update(func(s *APIKeyUpsert) {
  1790. s.ClearGroupID()
  1791. })
  1792. }
  1793. // SetStatus sets the "status" field.
  1794. func (u *APIKeyUpsertBulk) SetStatus(v string) *APIKeyUpsertBulk {
  1795. return u.Update(func(s *APIKeyUpsert) {
  1796. s.SetStatus(v)
  1797. })
  1798. }
  1799. // UpdateStatus sets the "status" field to the value that was provided on create.
  1800. func (u *APIKeyUpsertBulk) UpdateStatus() *APIKeyUpsertBulk {
  1801. return u.Update(func(s *APIKeyUpsert) {
  1802. s.UpdateStatus()
  1803. })
  1804. }
  1805. // SetLastUsedAt sets the "last_used_at" field.
  1806. func (u *APIKeyUpsertBulk) SetLastUsedAt(v time.Time) *APIKeyUpsertBulk {
  1807. return u.Update(func(s *APIKeyUpsert) {
  1808. s.SetLastUsedAt(v)
  1809. })
  1810. }
  1811. // UpdateLastUsedAt sets the "last_used_at" field to the value that was provided on create.
  1812. func (u *APIKeyUpsertBulk) UpdateLastUsedAt() *APIKeyUpsertBulk {
  1813. return u.Update(func(s *APIKeyUpsert) {
  1814. s.UpdateLastUsedAt()
  1815. })
  1816. }
  1817. // ClearLastUsedAt clears the value of the "last_used_at" field.
  1818. func (u *APIKeyUpsertBulk) ClearLastUsedAt() *APIKeyUpsertBulk {
  1819. return u.Update(func(s *APIKeyUpsert) {
  1820. s.ClearLastUsedAt()
  1821. })
  1822. }
  1823. // SetIPWhitelist sets the "ip_whitelist" field.
  1824. func (u *APIKeyUpsertBulk) SetIPWhitelist(v []string) *APIKeyUpsertBulk {
  1825. return u.Update(func(s *APIKeyUpsert) {
  1826. s.SetIPWhitelist(v)
  1827. })
  1828. }
  1829. // UpdateIPWhitelist sets the "ip_whitelist" field to the value that was provided on create.
  1830. func (u *APIKeyUpsertBulk) UpdateIPWhitelist() *APIKeyUpsertBulk {
  1831. return u.Update(func(s *APIKeyUpsert) {
  1832. s.UpdateIPWhitelist()
  1833. })
  1834. }
  1835. // ClearIPWhitelist clears the value of the "ip_whitelist" field.
  1836. func (u *APIKeyUpsertBulk) ClearIPWhitelist() *APIKeyUpsertBulk {
  1837. return u.Update(func(s *APIKeyUpsert) {
  1838. s.ClearIPWhitelist()
  1839. })
  1840. }
  1841. // SetIPBlacklist sets the "ip_blacklist" field.
  1842. func (u *APIKeyUpsertBulk) SetIPBlacklist(v []string) *APIKeyUpsertBulk {
  1843. return u.Update(func(s *APIKeyUpsert) {
  1844. s.SetIPBlacklist(v)
  1845. })
  1846. }
  1847. // UpdateIPBlacklist sets the "ip_blacklist" field to the value that was provided on create.
  1848. func (u *APIKeyUpsertBulk) UpdateIPBlacklist() *APIKeyUpsertBulk {
  1849. return u.Update(func(s *APIKeyUpsert) {
  1850. s.UpdateIPBlacklist()
  1851. })
  1852. }
  1853. // ClearIPBlacklist clears the value of the "ip_blacklist" field.
  1854. func (u *APIKeyUpsertBulk) ClearIPBlacklist() *APIKeyUpsertBulk {
  1855. return u.Update(func(s *APIKeyUpsert) {
  1856. s.ClearIPBlacklist()
  1857. })
  1858. }
  1859. // SetQuota sets the "quota" field.
  1860. func (u *APIKeyUpsertBulk) SetQuota(v float64) *APIKeyUpsertBulk {
  1861. return u.Update(func(s *APIKeyUpsert) {
  1862. s.SetQuota(v)
  1863. })
  1864. }
  1865. // AddQuota adds v to the "quota" field.
  1866. func (u *APIKeyUpsertBulk) AddQuota(v float64) *APIKeyUpsertBulk {
  1867. return u.Update(func(s *APIKeyUpsert) {
  1868. s.AddQuota(v)
  1869. })
  1870. }
  1871. // UpdateQuota sets the "quota" field to the value that was provided on create.
  1872. func (u *APIKeyUpsertBulk) UpdateQuota() *APIKeyUpsertBulk {
  1873. return u.Update(func(s *APIKeyUpsert) {
  1874. s.UpdateQuota()
  1875. })
  1876. }
  1877. // SetQuotaUsed sets the "quota_used" field.
  1878. func (u *APIKeyUpsertBulk) SetQuotaUsed(v float64) *APIKeyUpsertBulk {
  1879. return u.Update(func(s *APIKeyUpsert) {
  1880. s.SetQuotaUsed(v)
  1881. })
  1882. }
  1883. // AddQuotaUsed adds v to the "quota_used" field.
  1884. func (u *APIKeyUpsertBulk) AddQuotaUsed(v float64) *APIKeyUpsertBulk {
  1885. return u.Update(func(s *APIKeyUpsert) {
  1886. s.AddQuotaUsed(v)
  1887. })
  1888. }
  1889. // UpdateQuotaUsed sets the "quota_used" field to the value that was provided on create.
  1890. func (u *APIKeyUpsertBulk) UpdateQuotaUsed() *APIKeyUpsertBulk {
  1891. return u.Update(func(s *APIKeyUpsert) {
  1892. s.UpdateQuotaUsed()
  1893. })
  1894. }
  1895. // SetExpiresAt sets the "expires_at" field.
  1896. func (u *APIKeyUpsertBulk) SetExpiresAt(v time.Time) *APIKeyUpsertBulk {
  1897. return u.Update(func(s *APIKeyUpsert) {
  1898. s.SetExpiresAt(v)
  1899. })
  1900. }
  1901. // UpdateExpiresAt sets the "expires_at" field to the value that was provided on create.
  1902. func (u *APIKeyUpsertBulk) UpdateExpiresAt() *APIKeyUpsertBulk {
  1903. return u.Update(func(s *APIKeyUpsert) {
  1904. s.UpdateExpiresAt()
  1905. })
  1906. }
  1907. // ClearExpiresAt clears the value of the "expires_at" field.
  1908. func (u *APIKeyUpsertBulk) ClearExpiresAt() *APIKeyUpsertBulk {
  1909. return u.Update(func(s *APIKeyUpsert) {
  1910. s.ClearExpiresAt()
  1911. })
  1912. }
  1913. // SetRateLimit5h sets the "rate_limit_5h" field.
  1914. func (u *APIKeyUpsertBulk) SetRateLimit5h(v float64) *APIKeyUpsertBulk {
  1915. return u.Update(func(s *APIKeyUpsert) {
  1916. s.SetRateLimit5h(v)
  1917. })
  1918. }
  1919. // AddRateLimit5h adds v to the "rate_limit_5h" field.
  1920. func (u *APIKeyUpsertBulk) AddRateLimit5h(v float64) *APIKeyUpsertBulk {
  1921. return u.Update(func(s *APIKeyUpsert) {
  1922. s.AddRateLimit5h(v)
  1923. })
  1924. }
  1925. // UpdateRateLimit5h sets the "rate_limit_5h" field to the value that was provided on create.
  1926. func (u *APIKeyUpsertBulk) UpdateRateLimit5h() *APIKeyUpsertBulk {
  1927. return u.Update(func(s *APIKeyUpsert) {
  1928. s.UpdateRateLimit5h()
  1929. })
  1930. }
  1931. // SetRateLimit1d sets the "rate_limit_1d" field.
  1932. func (u *APIKeyUpsertBulk) SetRateLimit1d(v float64) *APIKeyUpsertBulk {
  1933. return u.Update(func(s *APIKeyUpsert) {
  1934. s.SetRateLimit1d(v)
  1935. })
  1936. }
  1937. // AddRateLimit1d adds v to the "rate_limit_1d" field.
  1938. func (u *APIKeyUpsertBulk) AddRateLimit1d(v float64) *APIKeyUpsertBulk {
  1939. return u.Update(func(s *APIKeyUpsert) {
  1940. s.AddRateLimit1d(v)
  1941. })
  1942. }
  1943. // UpdateRateLimit1d sets the "rate_limit_1d" field to the value that was provided on create.
  1944. func (u *APIKeyUpsertBulk) UpdateRateLimit1d() *APIKeyUpsertBulk {
  1945. return u.Update(func(s *APIKeyUpsert) {
  1946. s.UpdateRateLimit1d()
  1947. })
  1948. }
  1949. // SetRateLimit7d sets the "rate_limit_7d" field.
  1950. func (u *APIKeyUpsertBulk) SetRateLimit7d(v float64) *APIKeyUpsertBulk {
  1951. return u.Update(func(s *APIKeyUpsert) {
  1952. s.SetRateLimit7d(v)
  1953. })
  1954. }
  1955. // AddRateLimit7d adds v to the "rate_limit_7d" field.
  1956. func (u *APIKeyUpsertBulk) AddRateLimit7d(v float64) *APIKeyUpsertBulk {
  1957. return u.Update(func(s *APIKeyUpsert) {
  1958. s.AddRateLimit7d(v)
  1959. })
  1960. }
  1961. // UpdateRateLimit7d sets the "rate_limit_7d" field to the value that was provided on create.
  1962. func (u *APIKeyUpsertBulk) UpdateRateLimit7d() *APIKeyUpsertBulk {
  1963. return u.Update(func(s *APIKeyUpsert) {
  1964. s.UpdateRateLimit7d()
  1965. })
  1966. }
  1967. // SetUsage5h sets the "usage_5h" field.
  1968. func (u *APIKeyUpsertBulk) SetUsage5h(v float64) *APIKeyUpsertBulk {
  1969. return u.Update(func(s *APIKeyUpsert) {
  1970. s.SetUsage5h(v)
  1971. })
  1972. }
  1973. // AddUsage5h adds v to the "usage_5h" field.
  1974. func (u *APIKeyUpsertBulk) AddUsage5h(v float64) *APIKeyUpsertBulk {
  1975. return u.Update(func(s *APIKeyUpsert) {
  1976. s.AddUsage5h(v)
  1977. })
  1978. }
  1979. // UpdateUsage5h sets the "usage_5h" field to the value that was provided on create.
  1980. func (u *APIKeyUpsertBulk) UpdateUsage5h() *APIKeyUpsertBulk {
  1981. return u.Update(func(s *APIKeyUpsert) {
  1982. s.UpdateUsage5h()
  1983. })
  1984. }
  1985. // SetUsage1d sets the "usage_1d" field.
  1986. func (u *APIKeyUpsertBulk) SetUsage1d(v float64) *APIKeyUpsertBulk {
  1987. return u.Update(func(s *APIKeyUpsert) {
  1988. s.SetUsage1d(v)
  1989. })
  1990. }
  1991. // AddUsage1d adds v to the "usage_1d" field.
  1992. func (u *APIKeyUpsertBulk) AddUsage1d(v float64) *APIKeyUpsertBulk {
  1993. return u.Update(func(s *APIKeyUpsert) {
  1994. s.AddUsage1d(v)
  1995. })
  1996. }
  1997. // UpdateUsage1d sets the "usage_1d" field to the value that was provided on create.
  1998. func (u *APIKeyUpsertBulk) UpdateUsage1d() *APIKeyUpsertBulk {
  1999. return u.Update(func(s *APIKeyUpsert) {
  2000. s.UpdateUsage1d()
  2001. })
  2002. }
  2003. // SetUsage7d sets the "usage_7d" field.
  2004. func (u *APIKeyUpsertBulk) SetUsage7d(v float64) *APIKeyUpsertBulk {
  2005. return u.Update(func(s *APIKeyUpsert) {
  2006. s.SetUsage7d(v)
  2007. })
  2008. }
  2009. // AddUsage7d adds v to the "usage_7d" field.
  2010. func (u *APIKeyUpsertBulk) AddUsage7d(v float64) *APIKeyUpsertBulk {
  2011. return u.Update(func(s *APIKeyUpsert) {
  2012. s.AddUsage7d(v)
  2013. })
  2014. }
  2015. // UpdateUsage7d sets the "usage_7d" field to the value that was provided on create.
  2016. func (u *APIKeyUpsertBulk) UpdateUsage7d() *APIKeyUpsertBulk {
  2017. return u.Update(func(s *APIKeyUpsert) {
  2018. s.UpdateUsage7d()
  2019. })
  2020. }
  2021. // SetWindow5hStart sets the "window_5h_start" field.
  2022. func (u *APIKeyUpsertBulk) SetWindow5hStart(v time.Time) *APIKeyUpsertBulk {
  2023. return u.Update(func(s *APIKeyUpsert) {
  2024. s.SetWindow5hStart(v)
  2025. })
  2026. }
  2027. // UpdateWindow5hStart sets the "window_5h_start" field to the value that was provided on create.
  2028. func (u *APIKeyUpsertBulk) UpdateWindow5hStart() *APIKeyUpsertBulk {
  2029. return u.Update(func(s *APIKeyUpsert) {
  2030. s.UpdateWindow5hStart()
  2031. })
  2032. }
  2033. // ClearWindow5hStart clears the value of the "window_5h_start" field.
  2034. func (u *APIKeyUpsertBulk) ClearWindow5hStart() *APIKeyUpsertBulk {
  2035. return u.Update(func(s *APIKeyUpsert) {
  2036. s.ClearWindow5hStart()
  2037. })
  2038. }
  2039. // SetWindow1dStart sets the "window_1d_start" field.
  2040. func (u *APIKeyUpsertBulk) SetWindow1dStart(v time.Time) *APIKeyUpsertBulk {
  2041. return u.Update(func(s *APIKeyUpsert) {
  2042. s.SetWindow1dStart(v)
  2043. })
  2044. }
  2045. // UpdateWindow1dStart sets the "window_1d_start" field to the value that was provided on create.
  2046. func (u *APIKeyUpsertBulk) UpdateWindow1dStart() *APIKeyUpsertBulk {
  2047. return u.Update(func(s *APIKeyUpsert) {
  2048. s.UpdateWindow1dStart()
  2049. })
  2050. }
  2051. // ClearWindow1dStart clears the value of the "window_1d_start" field.
  2052. func (u *APIKeyUpsertBulk) ClearWindow1dStart() *APIKeyUpsertBulk {
  2053. return u.Update(func(s *APIKeyUpsert) {
  2054. s.ClearWindow1dStart()
  2055. })
  2056. }
  2057. // SetWindow7dStart sets the "window_7d_start" field.
  2058. func (u *APIKeyUpsertBulk) SetWindow7dStart(v time.Time) *APIKeyUpsertBulk {
  2059. return u.Update(func(s *APIKeyUpsert) {
  2060. s.SetWindow7dStart(v)
  2061. })
  2062. }
  2063. // UpdateWindow7dStart sets the "window_7d_start" field to the value that was provided on create.
  2064. func (u *APIKeyUpsertBulk) UpdateWindow7dStart() *APIKeyUpsertBulk {
  2065. return u.Update(func(s *APIKeyUpsert) {
  2066. s.UpdateWindow7dStart()
  2067. })
  2068. }
  2069. // ClearWindow7dStart clears the value of the "window_7d_start" field.
  2070. func (u *APIKeyUpsertBulk) ClearWindow7dStart() *APIKeyUpsertBulk {
  2071. return u.Update(func(s *APIKeyUpsert) {
  2072. s.ClearWindow7dStart()
  2073. })
  2074. }
  2075. // Exec executes the query.
  2076. func (u *APIKeyUpsertBulk) Exec(ctx context.Context) error {
  2077. if u.create.err != nil {
  2078. return u.create.err
  2079. }
  2080. for i, b := range u.create.builders {
  2081. if len(b.conflict) != 0 {
  2082. return fmt.Errorf("ent: OnConflict was set for builder %d. Set it on the APIKeyCreateBulk instead", i)
  2083. }
  2084. }
  2085. if len(u.create.conflict) == 0 {
  2086. return errors.New("ent: missing options for APIKeyCreateBulk.OnConflict")
  2087. }
  2088. return u.create.Exec(ctx)
  2089. }
  2090. // ExecX is like Exec, but panics if an error occurs.
  2091. func (u *APIKeyUpsertBulk) ExecX(ctx context.Context) {
  2092. if err := u.create.Exec(ctx); err != nil {
  2093. panic(err)
  2094. }
  2095. }