| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388 |
- // Code generated by ent, DO NOT EDIT.
- package ent
- import (
- "context"
- "errors"
- "fmt"
- "time"
- "entgo.io/ent/dialect/sql"
- "entgo.io/ent/dialect/sql/sqlgraph"
- "entgo.io/ent/schema/field"
- "github.com/Wei-Shaw/sub2api/ent/apikey"
- "github.com/Wei-Shaw/sub2api/ent/group"
- "github.com/Wei-Shaw/sub2api/ent/usagelog"
- "github.com/Wei-Shaw/sub2api/ent/user"
- )
- // APIKeyCreate is the builder for creating a APIKey entity.
- type APIKeyCreate struct {
- config
- mutation *APIKeyMutation
- hooks []Hook
- conflict []sql.ConflictOption
- }
- // SetCreatedAt sets the "created_at" field.
- func (_c *APIKeyCreate) SetCreatedAt(v time.Time) *APIKeyCreate {
- _c.mutation.SetCreatedAt(v)
- return _c
- }
- // SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
- func (_c *APIKeyCreate) SetNillableCreatedAt(v *time.Time) *APIKeyCreate {
- if v != nil {
- _c.SetCreatedAt(*v)
- }
- return _c
- }
- // SetUpdatedAt sets the "updated_at" field.
- func (_c *APIKeyCreate) SetUpdatedAt(v time.Time) *APIKeyCreate {
- _c.mutation.SetUpdatedAt(v)
- return _c
- }
- // SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
- func (_c *APIKeyCreate) SetNillableUpdatedAt(v *time.Time) *APIKeyCreate {
- if v != nil {
- _c.SetUpdatedAt(*v)
- }
- return _c
- }
- // SetDeletedAt sets the "deleted_at" field.
- func (_c *APIKeyCreate) SetDeletedAt(v time.Time) *APIKeyCreate {
- _c.mutation.SetDeletedAt(v)
- return _c
- }
- // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
- func (_c *APIKeyCreate) SetNillableDeletedAt(v *time.Time) *APIKeyCreate {
- if v != nil {
- _c.SetDeletedAt(*v)
- }
- return _c
- }
- // SetUserID sets the "user_id" field.
- func (_c *APIKeyCreate) SetUserID(v int64) *APIKeyCreate {
- _c.mutation.SetUserID(v)
- return _c
- }
- // SetKey sets the "key" field.
- func (_c *APIKeyCreate) SetKey(v string) *APIKeyCreate {
- _c.mutation.SetKey(v)
- return _c
- }
- // SetNillableKey sets the "key" field if the given value is not nil.
- func (_c *APIKeyCreate) SetNillableKey(v *string) *APIKeyCreate {
- if v != nil {
- _c.SetKey(*v)
- }
- return _c
- }
- // SetKeyHash sets the "key_hash" field.
- func (_c *APIKeyCreate) SetKeyHash(v string) *APIKeyCreate {
- _c.mutation.SetKeyHash(v)
- return _c
- }
- // SetNillableKeyHash sets the "key_hash" field if the given value is not nil.
- func (_c *APIKeyCreate) SetNillableKeyHash(v *string) *APIKeyCreate {
- if v != nil {
- _c.SetKeyHash(*v)
- }
- return _c
- }
- // SetKeyPrefix sets the "key_prefix" field.
- func (_c *APIKeyCreate) SetKeyPrefix(v string) *APIKeyCreate {
- _c.mutation.SetKeyPrefix(v)
- return _c
- }
- // SetNillableKeyPrefix sets the "key_prefix" field if the given value is not nil.
- func (_c *APIKeyCreate) SetNillableKeyPrefix(v *string) *APIKeyCreate {
- if v != nil {
- _c.SetKeyPrefix(*v)
- }
- return _c
- }
- // SetName sets the "name" field.
- func (_c *APIKeyCreate) SetName(v string) *APIKeyCreate {
- _c.mutation.SetName(v)
- return _c
- }
- // SetGroupID sets the "group_id" field.
- func (_c *APIKeyCreate) SetGroupID(v int64) *APIKeyCreate {
- _c.mutation.SetGroupID(v)
- return _c
- }
- // SetNillableGroupID sets the "group_id" field if the given value is not nil.
- func (_c *APIKeyCreate) SetNillableGroupID(v *int64) *APIKeyCreate {
- if v != nil {
- _c.SetGroupID(*v)
- }
- return _c
- }
- // SetStatus sets the "status" field.
- func (_c *APIKeyCreate) SetStatus(v string) *APIKeyCreate {
- _c.mutation.SetStatus(v)
- return _c
- }
- // SetNillableStatus sets the "status" field if the given value is not nil.
- func (_c *APIKeyCreate) SetNillableStatus(v *string) *APIKeyCreate {
- if v != nil {
- _c.SetStatus(*v)
- }
- return _c
- }
- // SetLastUsedAt sets the "last_used_at" field.
- func (_c *APIKeyCreate) SetLastUsedAt(v time.Time) *APIKeyCreate {
- _c.mutation.SetLastUsedAt(v)
- return _c
- }
- // SetNillableLastUsedAt sets the "last_used_at" field if the given value is not nil.
- func (_c *APIKeyCreate) SetNillableLastUsedAt(v *time.Time) *APIKeyCreate {
- if v != nil {
- _c.SetLastUsedAt(*v)
- }
- return _c
- }
- // SetIPWhitelist sets the "ip_whitelist" field.
- func (_c *APIKeyCreate) SetIPWhitelist(v []string) *APIKeyCreate {
- _c.mutation.SetIPWhitelist(v)
- return _c
- }
- // SetIPBlacklist sets the "ip_blacklist" field.
- func (_c *APIKeyCreate) SetIPBlacklist(v []string) *APIKeyCreate {
- _c.mutation.SetIPBlacklist(v)
- return _c
- }
- // SetQuota sets the "quota" field.
- func (_c *APIKeyCreate) SetQuota(v float64) *APIKeyCreate {
- _c.mutation.SetQuota(v)
- return _c
- }
- // SetNillableQuota sets the "quota" field if the given value is not nil.
- func (_c *APIKeyCreate) SetNillableQuota(v *float64) *APIKeyCreate {
- if v != nil {
- _c.SetQuota(*v)
- }
- return _c
- }
- // SetQuotaUsed sets the "quota_used" field.
- func (_c *APIKeyCreate) SetQuotaUsed(v float64) *APIKeyCreate {
- _c.mutation.SetQuotaUsed(v)
- return _c
- }
- // SetNillableQuotaUsed sets the "quota_used" field if the given value is not nil.
- func (_c *APIKeyCreate) SetNillableQuotaUsed(v *float64) *APIKeyCreate {
- if v != nil {
- _c.SetQuotaUsed(*v)
- }
- return _c
- }
- // SetExpiresAt sets the "expires_at" field.
- func (_c *APIKeyCreate) SetExpiresAt(v time.Time) *APIKeyCreate {
- _c.mutation.SetExpiresAt(v)
- return _c
- }
- // SetNillableExpiresAt sets the "expires_at" field if the given value is not nil.
- func (_c *APIKeyCreate) SetNillableExpiresAt(v *time.Time) *APIKeyCreate {
- if v != nil {
- _c.SetExpiresAt(*v)
- }
- return _c
- }
- // SetRateLimit5h sets the "rate_limit_5h" field.
- func (_c *APIKeyCreate) SetRateLimit5h(v float64) *APIKeyCreate {
- _c.mutation.SetRateLimit5h(v)
- return _c
- }
- // SetNillableRateLimit5h sets the "rate_limit_5h" field if the given value is not nil.
- func (_c *APIKeyCreate) SetNillableRateLimit5h(v *float64) *APIKeyCreate {
- if v != nil {
- _c.SetRateLimit5h(*v)
- }
- return _c
- }
- // SetRateLimit1d sets the "rate_limit_1d" field.
- func (_c *APIKeyCreate) SetRateLimit1d(v float64) *APIKeyCreate {
- _c.mutation.SetRateLimit1d(v)
- return _c
- }
- // SetNillableRateLimit1d sets the "rate_limit_1d" field if the given value is not nil.
- func (_c *APIKeyCreate) SetNillableRateLimit1d(v *float64) *APIKeyCreate {
- if v != nil {
- _c.SetRateLimit1d(*v)
- }
- return _c
- }
- // SetRateLimit7d sets the "rate_limit_7d" field.
- func (_c *APIKeyCreate) SetRateLimit7d(v float64) *APIKeyCreate {
- _c.mutation.SetRateLimit7d(v)
- return _c
- }
- // SetNillableRateLimit7d sets the "rate_limit_7d" field if the given value is not nil.
- func (_c *APIKeyCreate) SetNillableRateLimit7d(v *float64) *APIKeyCreate {
- if v != nil {
- _c.SetRateLimit7d(*v)
- }
- return _c
- }
- // SetUsage5h sets the "usage_5h" field.
- func (_c *APIKeyCreate) SetUsage5h(v float64) *APIKeyCreate {
- _c.mutation.SetUsage5h(v)
- return _c
- }
- // SetNillableUsage5h sets the "usage_5h" field if the given value is not nil.
- func (_c *APIKeyCreate) SetNillableUsage5h(v *float64) *APIKeyCreate {
- if v != nil {
- _c.SetUsage5h(*v)
- }
- return _c
- }
- // SetUsage1d sets the "usage_1d" field.
- func (_c *APIKeyCreate) SetUsage1d(v float64) *APIKeyCreate {
- _c.mutation.SetUsage1d(v)
- return _c
- }
- // SetNillableUsage1d sets the "usage_1d" field if the given value is not nil.
- func (_c *APIKeyCreate) SetNillableUsage1d(v *float64) *APIKeyCreate {
- if v != nil {
- _c.SetUsage1d(*v)
- }
- return _c
- }
- // SetUsage7d sets the "usage_7d" field.
- func (_c *APIKeyCreate) SetUsage7d(v float64) *APIKeyCreate {
- _c.mutation.SetUsage7d(v)
- return _c
- }
- // SetNillableUsage7d sets the "usage_7d" field if the given value is not nil.
- func (_c *APIKeyCreate) SetNillableUsage7d(v *float64) *APIKeyCreate {
- if v != nil {
- _c.SetUsage7d(*v)
- }
- return _c
- }
- // SetWindow5hStart sets the "window_5h_start" field.
- func (_c *APIKeyCreate) SetWindow5hStart(v time.Time) *APIKeyCreate {
- _c.mutation.SetWindow5hStart(v)
- return _c
- }
- // SetNillableWindow5hStart sets the "window_5h_start" field if the given value is not nil.
- func (_c *APIKeyCreate) SetNillableWindow5hStart(v *time.Time) *APIKeyCreate {
- if v != nil {
- _c.SetWindow5hStart(*v)
- }
- return _c
- }
- // SetWindow1dStart sets the "window_1d_start" field.
- func (_c *APIKeyCreate) SetWindow1dStart(v time.Time) *APIKeyCreate {
- _c.mutation.SetWindow1dStart(v)
- return _c
- }
- // SetNillableWindow1dStart sets the "window_1d_start" field if the given value is not nil.
- func (_c *APIKeyCreate) SetNillableWindow1dStart(v *time.Time) *APIKeyCreate {
- if v != nil {
- _c.SetWindow1dStart(*v)
- }
- return _c
- }
- // SetWindow7dStart sets the "window_7d_start" field.
- func (_c *APIKeyCreate) SetWindow7dStart(v time.Time) *APIKeyCreate {
- _c.mutation.SetWindow7dStart(v)
- return _c
- }
- // SetNillableWindow7dStart sets the "window_7d_start" field if the given value is not nil.
- func (_c *APIKeyCreate) SetNillableWindow7dStart(v *time.Time) *APIKeyCreate {
- if v != nil {
- _c.SetWindow7dStart(*v)
- }
- return _c
- }
- // SetUser sets the "user" edge to the User entity.
- func (_c *APIKeyCreate) SetUser(v *User) *APIKeyCreate {
- return _c.SetUserID(v.ID)
- }
- // SetGroup sets the "group" edge to the Group entity.
- func (_c *APIKeyCreate) SetGroup(v *Group) *APIKeyCreate {
- return _c.SetGroupID(v.ID)
- }
- // AddUsageLogIDs adds the "usage_logs" edge to the UsageLog entity by IDs.
- func (_c *APIKeyCreate) AddUsageLogIDs(ids ...int64) *APIKeyCreate {
- _c.mutation.AddUsageLogIDs(ids...)
- return _c
- }
- // AddUsageLogs adds the "usage_logs" edges to the UsageLog entity.
- func (_c *APIKeyCreate) AddUsageLogs(v ...*UsageLog) *APIKeyCreate {
- ids := make([]int64, len(v))
- for i := range v {
- ids[i] = v[i].ID
- }
- return _c.AddUsageLogIDs(ids...)
- }
- // Mutation returns the APIKeyMutation object of the builder.
- func (_c *APIKeyCreate) Mutation() *APIKeyMutation {
- return _c.mutation
- }
- // Save creates the APIKey in the database.
- func (_c *APIKeyCreate) Save(ctx context.Context) (*APIKey, error) {
- if err := _c.defaults(); err != nil {
- return nil, err
- }
- return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
- }
- // SaveX calls Save and panics if Save returns an error.
- func (_c *APIKeyCreate) SaveX(ctx context.Context) *APIKey {
- v, err := _c.Save(ctx)
- if err != nil {
- panic(err)
- }
- return v
- }
- // Exec executes the query.
- func (_c *APIKeyCreate) Exec(ctx context.Context) error {
- _, err := _c.Save(ctx)
- return err
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (_c *APIKeyCreate) ExecX(ctx context.Context) {
- if err := _c.Exec(ctx); err != nil {
- panic(err)
- }
- }
- // defaults sets the default values of the builder before save.
- func (_c *APIKeyCreate) defaults() error {
- if _, ok := _c.mutation.CreatedAt(); !ok {
- if apikey.DefaultCreatedAt == nil {
- return fmt.Errorf("ent: uninitialized apikey.DefaultCreatedAt (forgotten import ent/runtime?)")
- }
- v := apikey.DefaultCreatedAt()
- _c.mutation.SetCreatedAt(v)
- }
- if _, ok := _c.mutation.UpdatedAt(); !ok {
- if apikey.DefaultUpdatedAt == nil {
- return fmt.Errorf("ent: uninitialized apikey.DefaultUpdatedAt (forgotten import ent/runtime?)")
- }
- v := apikey.DefaultUpdatedAt()
- _c.mutation.SetUpdatedAt(v)
- }
- if _, ok := _c.mutation.Status(); !ok {
- v := apikey.DefaultStatus
- _c.mutation.SetStatus(v)
- }
- if _, ok := _c.mutation.Quota(); !ok {
- v := apikey.DefaultQuota
- _c.mutation.SetQuota(v)
- }
- if _, ok := _c.mutation.QuotaUsed(); !ok {
- v := apikey.DefaultQuotaUsed
- _c.mutation.SetQuotaUsed(v)
- }
- if _, ok := _c.mutation.RateLimit5h(); !ok {
- v := apikey.DefaultRateLimit5h
- _c.mutation.SetRateLimit5h(v)
- }
- if _, ok := _c.mutation.RateLimit1d(); !ok {
- v := apikey.DefaultRateLimit1d
- _c.mutation.SetRateLimit1d(v)
- }
- if _, ok := _c.mutation.RateLimit7d(); !ok {
- v := apikey.DefaultRateLimit7d
- _c.mutation.SetRateLimit7d(v)
- }
- if _, ok := _c.mutation.Usage5h(); !ok {
- v := apikey.DefaultUsage5h
- _c.mutation.SetUsage5h(v)
- }
- if _, ok := _c.mutation.Usage1d(); !ok {
- v := apikey.DefaultUsage1d
- _c.mutation.SetUsage1d(v)
- }
- if _, ok := _c.mutation.Usage7d(); !ok {
- v := apikey.DefaultUsage7d
- _c.mutation.SetUsage7d(v)
- }
- return nil
- }
- // check runs all checks and user-defined validators on the builder.
- func (_c *APIKeyCreate) check() error {
- if _, ok := _c.mutation.CreatedAt(); !ok {
- return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "APIKey.created_at"`)}
- }
- if _, ok := _c.mutation.UpdatedAt(); !ok {
- return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "APIKey.updated_at"`)}
- }
- if _, ok := _c.mutation.UserID(); !ok {
- return &ValidationError{Name: "user_id", err: errors.New(`ent: missing required field "APIKey.user_id"`)}
- }
- if v, ok := _c.mutation.Key(); ok {
- if err := apikey.KeyValidator(v); err != nil {
- return &ValidationError{Name: "key", err: fmt.Errorf(`ent: validator failed for field "APIKey.key": %w`, err)}
- }
- }
- if v, ok := _c.mutation.KeyHash(); ok {
- if err := apikey.KeyHashValidator(v); err != nil {
- return &ValidationError{Name: "key_hash", err: fmt.Errorf(`ent: validator failed for field "APIKey.key_hash": %w`, err)}
- }
- }
- if v, ok := _c.mutation.KeyPrefix(); ok {
- if err := apikey.KeyPrefixValidator(v); err != nil {
- return &ValidationError{Name: "key_prefix", err: fmt.Errorf(`ent: validator failed for field "APIKey.key_prefix": %w`, err)}
- }
- }
- if _, ok := _c.mutation.Name(); !ok {
- return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "APIKey.name"`)}
- }
- if v, ok := _c.mutation.Name(); ok {
- if err := apikey.NameValidator(v); err != nil {
- return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "APIKey.name": %w`, err)}
- }
- }
- if _, ok := _c.mutation.Status(); !ok {
- return &ValidationError{Name: "status", err: errors.New(`ent: missing required field "APIKey.status"`)}
- }
- if v, ok := _c.mutation.Status(); ok {
- if err := apikey.StatusValidator(v); err != nil {
- return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "APIKey.status": %w`, err)}
- }
- }
- if _, ok := _c.mutation.Quota(); !ok {
- return &ValidationError{Name: "quota", err: errors.New(`ent: missing required field "APIKey.quota"`)}
- }
- if _, ok := _c.mutation.QuotaUsed(); !ok {
- return &ValidationError{Name: "quota_used", err: errors.New(`ent: missing required field "APIKey.quota_used"`)}
- }
- if _, ok := _c.mutation.RateLimit5h(); !ok {
- return &ValidationError{Name: "rate_limit_5h", err: errors.New(`ent: missing required field "APIKey.rate_limit_5h"`)}
- }
- if _, ok := _c.mutation.RateLimit1d(); !ok {
- return &ValidationError{Name: "rate_limit_1d", err: errors.New(`ent: missing required field "APIKey.rate_limit_1d"`)}
- }
- if _, ok := _c.mutation.RateLimit7d(); !ok {
- return &ValidationError{Name: "rate_limit_7d", err: errors.New(`ent: missing required field "APIKey.rate_limit_7d"`)}
- }
- if _, ok := _c.mutation.Usage5h(); !ok {
- return &ValidationError{Name: "usage_5h", err: errors.New(`ent: missing required field "APIKey.usage_5h"`)}
- }
- if _, ok := _c.mutation.Usage1d(); !ok {
- return &ValidationError{Name: "usage_1d", err: errors.New(`ent: missing required field "APIKey.usage_1d"`)}
- }
- if _, ok := _c.mutation.Usage7d(); !ok {
- return &ValidationError{Name: "usage_7d", err: errors.New(`ent: missing required field "APIKey.usage_7d"`)}
- }
- if len(_c.mutation.UserIDs()) == 0 {
- return &ValidationError{Name: "user", err: errors.New(`ent: missing required edge "APIKey.user"`)}
- }
- return nil
- }
- func (_c *APIKeyCreate) sqlSave(ctx context.Context) (*APIKey, error) {
- if err := _c.check(); err != nil {
- return nil, err
- }
- _node, _spec := _c.createSpec()
- if err := sqlgraph.CreateNode(ctx, _c.driver, _spec); err != nil {
- if sqlgraph.IsConstraintError(err) {
- err = &ConstraintError{msg: err.Error(), wrap: err}
- }
- return nil, err
- }
- id := _spec.ID.Value.(int64)
- _node.ID = int64(id)
- _c.mutation.id = &_node.ID
- _c.mutation.done = true
- return _node, nil
- }
- func (_c *APIKeyCreate) createSpec() (*APIKey, *sqlgraph.CreateSpec) {
- var (
- _node = &APIKey{config: _c.config}
- _spec = sqlgraph.NewCreateSpec(apikey.Table, sqlgraph.NewFieldSpec(apikey.FieldID, field.TypeInt64))
- )
- _spec.OnConflict = _c.conflict
- if value, ok := _c.mutation.CreatedAt(); ok {
- _spec.SetField(apikey.FieldCreatedAt, field.TypeTime, value)
- _node.CreatedAt = value
- }
- if value, ok := _c.mutation.UpdatedAt(); ok {
- _spec.SetField(apikey.FieldUpdatedAt, field.TypeTime, value)
- _node.UpdatedAt = value
- }
- if value, ok := _c.mutation.DeletedAt(); ok {
- _spec.SetField(apikey.FieldDeletedAt, field.TypeTime, value)
- _node.DeletedAt = &value
- }
- if value, ok := _c.mutation.Key(); ok {
- _spec.SetField(apikey.FieldKey, field.TypeString, value)
- _node.Key = value
- }
- if value, ok := _c.mutation.KeyHash(); ok {
- _spec.SetField(apikey.FieldKeyHash, field.TypeString, value)
- _node.KeyHash = value
- }
- if value, ok := _c.mutation.KeyPrefix(); ok {
- _spec.SetField(apikey.FieldKeyPrefix, field.TypeString, value)
- _node.KeyPrefix = value
- }
- if value, ok := _c.mutation.Name(); ok {
- _spec.SetField(apikey.FieldName, field.TypeString, value)
- _node.Name = value
- }
- if value, ok := _c.mutation.Status(); ok {
- _spec.SetField(apikey.FieldStatus, field.TypeString, value)
- _node.Status = value
- }
- if value, ok := _c.mutation.LastUsedAt(); ok {
- _spec.SetField(apikey.FieldLastUsedAt, field.TypeTime, value)
- _node.LastUsedAt = &value
- }
- if value, ok := _c.mutation.IPWhitelist(); ok {
- _spec.SetField(apikey.FieldIPWhitelist, field.TypeJSON, value)
- _node.IPWhitelist = value
- }
- if value, ok := _c.mutation.IPBlacklist(); ok {
- _spec.SetField(apikey.FieldIPBlacklist, field.TypeJSON, value)
- _node.IPBlacklist = value
- }
- if value, ok := _c.mutation.Quota(); ok {
- _spec.SetField(apikey.FieldQuota, field.TypeFloat64, value)
- _node.Quota = value
- }
- if value, ok := _c.mutation.QuotaUsed(); ok {
- _spec.SetField(apikey.FieldQuotaUsed, field.TypeFloat64, value)
- _node.QuotaUsed = value
- }
- if value, ok := _c.mutation.ExpiresAt(); ok {
- _spec.SetField(apikey.FieldExpiresAt, field.TypeTime, value)
- _node.ExpiresAt = &value
- }
- if value, ok := _c.mutation.RateLimit5h(); ok {
- _spec.SetField(apikey.FieldRateLimit5h, field.TypeFloat64, value)
- _node.RateLimit5h = value
- }
- if value, ok := _c.mutation.RateLimit1d(); ok {
- _spec.SetField(apikey.FieldRateLimit1d, field.TypeFloat64, value)
- _node.RateLimit1d = value
- }
- if value, ok := _c.mutation.RateLimit7d(); ok {
- _spec.SetField(apikey.FieldRateLimit7d, field.TypeFloat64, value)
- _node.RateLimit7d = value
- }
- if value, ok := _c.mutation.Usage5h(); ok {
- _spec.SetField(apikey.FieldUsage5h, field.TypeFloat64, value)
- _node.Usage5h = value
- }
- if value, ok := _c.mutation.Usage1d(); ok {
- _spec.SetField(apikey.FieldUsage1d, field.TypeFloat64, value)
- _node.Usage1d = value
- }
- if value, ok := _c.mutation.Usage7d(); ok {
- _spec.SetField(apikey.FieldUsage7d, field.TypeFloat64, value)
- _node.Usage7d = value
- }
- if value, ok := _c.mutation.Window5hStart(); ok {
- _spec.SetField(apikey.FieldWindow5hStart, field.TypeTime, value)
- _node.Window5hStart = &value
- }
- if value, ok := _c.mutation.Window1dStart(); ok {
- _spec.SetField(apikey.FieldWindow1dStart, field.TypeTime, value)
- _node.Window1dStart = &value
- }
- if value, ok := _c.mutation.Window7dStart(); ok {
- _spec.SetField(apikey.FieldWindow7dStart, field.TypeTime, value)
- _node.Window7dStart = &value
- }
- if nodes := _c.mutation.UserIDs(); len(nodes) > 0 {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.M2O,
- Inverse: true,
- Table: apikey.UserTable,
- Columns: []string{apikey.UserColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt64),
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _node.UserID = nodes[0]
- _spec.Edges = append(_spec.Edges, edge)
- }
- if nodes := _c.mutation.GroupIDs(); len(nodes) > 0 {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.M2O,
- Inverse: true,
- Table: apikey.GroupTable,
- Columns: []string{apikey.GroupColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt64),
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _node.GroupID = &nodes[0]
- _spec.Edges = append(_spec.Edges, edge)
- }
- if nodes := _c.mutation.UsageLogsIDs(); len(nodes) > 0 {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: false,
- Table: apikey.UsageLogsTable,
- Columns: []string{apikey.UsageLogsColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(usagelog.FieldID, field.TypeInt64),
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges = append(_spec.Edges, edge)
- }
- return _node, _spec
- }
- // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
- // of the `INSERT` statement. For example:
- //
- // client.APIKey.Create().
- // SetCreatedAt(v).
- // OnConflict(
- // // Update the row with the new values
- // // the was proposed for insertion.
- // sql.ResolveWithNewValues(),
- // ).
- // // Override some of the fields with custom
- // // update values.
- // Update(func(u *ent.APIKeyUpsert) {
- // SetCreatedAt(v+v).
- // }).
- // Exec(ctx)
- func (_c *APIKeyCreate) OnConflict(opts ...sql.ConflictOption) *APIKeyUpsertOne {
- _c.conflict = opts
- return &APIKeyUpsertOne{
- create: _c,
- }
- }
- // OnConflictColumns calls `OnConflict` and configures the columns
- // as conflict target. Using this option is equivalent to using:
- //
- // client.APIKey.Create().
- // OnConflict(sql.ConflictColumns(columns...)).
- // Exec(ctx)
- func (_c *APIKeyCreate) OnConflictColumns(columns ...string) *APIKeyUpsertOne {
- _c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
- return &APIKeyUpsertOne{
- create: _c,
- }
- }
- type (
- // APIKeyUpsertOne is the builder for "upsert"-ing
- // one APIKey node.
- APIKeyUpsertOne struct {
- create *APIKeyCreate
- }
- // APIKeyUpsert is the "OnConflict" setter.
- APIKeyUpsert struct {
- *sql.UpdateSet
- }
- )
- // SetUpdatedAt sets the "updated_at" field.
- func (u *APIKeyUpsert) SetUpdatedAt(v time.Time) *APIKeyUpsert {
- u.Set(apikey.FieldUpdatedAt, v)
- return u
- }
- // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
- func (u *APIKeyUpsert) UpdateUpdatedAt() *APIKeyUpsert {
- u.SetExcluded(apikey.FieldUpdatedAt)
- return u
- }
- // SetDeletedAt sets the "deleted_at" field.
- func (u *APIKeyUpsert) SetDeletedAt(v time.Time) *APIKeyUpsert {
- u.Set(apikey.FieldDeletedAt, v)
- return u
- }
- // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
- func (u *APIKeyUpsert) UpdateDeletedAt() *APIKeyUpsert {
- u.SetExcluded(apikey.FieldDeletedAt)
- return u
- }
- // ClearDeletedAt clears the value of the "deleted_at" field.
- func (u *APIKeyUpsert) ClearDeletedAt() *APIKeyUpsert {
- u.SetNull(apikey.FieldDeletedAt)
- return u
- }
- // SetUserID sets the "user_id" field.
- func (u *APIKeyUpsert) SetUserID(v int64) *APIKeyUpsert {
- u.Set(apikey.FieldUserID, v)
- return u
- }
- // UpdateUserID sets the "user_id" field to the value that was provided on create.
- func (u *APIKeyUpsert) UpdateUserID() *APIKeyUpsert {
- u.SetExcluded(apikey.FieldUserID)
- return u
- }
- // SetKey sets the "key" field.
- func (u *APIKeyUpsert) SetKey(v string) *APIKeyUpsert {
- u.Set(apikey.FieldKey, v)
- return u
- }
- // UpdateKey sets the "key" field to the value that was provided on create.
- func (u *APIKeyUpsert) UpdateKey() *APIKeyUpsert {
- u.SetExcluded(apikey.FieldKey)
- return u
- }
- // ClearKey clears the value of the "key" field.
- func (u *APIKeyUpsert) ClearKey() *APIKeyUpsert {
- u.SetNull(apikey.FieldKey)
- return u
- }
- // SetKeyHash sets the "key_hash" field.
- func (u *APIKeyUpsert) SetKeyHash(v string) *APIKeyUpsert {
- u.Set(apikey.FieldKeyHash, v)
- return u
- }
- // UpdateKeyHash sets the "key_hash" field to the value that was provided on create.
- func (u *APIKeyUpsert) UpdateKeyHash() *APIKeyUpsert {
- u.SetExcluded(apikey.FieldKeyHash)
- return u
- }
- // ClearKeyHash clears the value of the "key_hash" field.
- func (u *APIKeyUpsert) ClearKeyHash() *APIKeyUpsert {
- u.SetNull(apikey.FieldKeyHash)
- return u
- }
- // SetKeyPrefix sets the "key_prefix" field.
- func (u *APIKeyUpsert) SetKeyPrefix(v string) *APIKeyUpsert {
- u.Set(apikey.FieldKeyPrefix, v)
- return u
- }
- // UpdateKeyPrefix sets the "key_prefix" field to the value that was provided on create.
- func (u *APIKeyUpsert) UpdateKeyPrefix() *APIKeyUpsert {
- u.SetExcluded(apikey.FieldKeyPrefix)
- return u
- }
- // ClearKeyPrefix clears the value of the "key_prefix" field.
- func (u *APIKeyUpsert) ClearKeyPrefix() *APIKeyUpsert {
- u.SetNull(apikey.FieldKeyPrefix)
- return u
- }
- // SetName sets the "name" field.
- func (u *APIKeyUpsert) SetName(v string) *APIKeyUpsert {
- u.Set(apikey.FieldName, v)
- return u
- }
- // UpdateName sets the "name" field to the value that was provided on create.
- func (u *APIKeyUpsert) UpdateName() *APIKeyUpsert {
- u.SetExcluded(apikey.FieldName)
- return u
- }
- // SetGroupID sets the "group_id" field.
- func (u *APIKeyUpsert) SetGroupID(v int64) *APIKeyUpsert {
- u.Set(apikey.FieldGroupID, v)
- return u
- }
- // UpdateGroupID sets the "group_id" field to the value that was provided on create.
- func (u *APIKeyUpsert) UpdateGroupID() *APIKeyUpsert {
- u.SetExcluded(apikey.FieldGroupID)
- return u
- }
- // ClearGroupID clears the value of the "group_id" field.
- func (u *APIKeyUpsert) ClearGroupID() *APIKeyUpsert {
- u.SetNull(apikey.FieldGroupID)
- return u
- }
- // SetStatus sets the "status" field.
- func (u *APIKeyUpsert) SetStatus(v string) *APIKeyUpsert {
- u.Set(apikey.FieldStatus, v)
- return u
- }
- // UpdateStatus sets the "status" field to the value that was provided on create.
- func (u *APIKeyUpsert) UpdateStatus() *APIKeyUpsert {
- u.SetExcluded(apikey.FieldStatus)
- return u
- }
- // SetLastUsedAt sets the "last_used_at" field.
- func (u *APIKeyUpsert) SetLastUsedAt(v time.Time) *APIKeyUpsert {
- u.Set(apikey.FieldLastUsedAt, v)
- return u
- }
- // UpdateLastUsedAt sets the "last_used_at" field to the value that was provided on create.
- func (u *APIKeyUpsert) UpdateLastUsedAt() *APIKeyUpsert {
- u.SetExcluded(apikey.FieldLastUsedAt)
- return u
- }
- // ClearLastUsedAt clears the value of the "last_used_at" field.
- func (u *APIKeyUpsert) ClearLastUsedAt() *APIKeyUpsert {
- u.SetNull(apikey.FieldLastUsedAt)
- return u
- }
- // SetIPWhitelist sets the "ip_whitelist" field.
- func (u *APIKeyUpsert) SetIPWhitelist(v []string) *APIKeyUpsert {
- u.Set(apikey.FieldIPWhitelist, v)
- return u
- }
- // UpdateIPWhitelist sets the "ip_whitelist" field to the value that was provided on create.
- func (u *APIKeyUpsert) UpdateIPWhitelist() *APIKeyUpsert {
- u.SetExcluded(apikey.FieldIPWhitelist)
- return u
- }
- // ClearIPWhitelist clears the value of the "ip_whitelist" field.
- func (u *APIKeyUpsert) ClearIPWhitelist() *APIKeyUpsert {
- u.SetNull(apikey.FieldIPWhitelist)
- return u
- }
- // SetIPBlacklist sets the "ip_blacklist" field.
- func (u *APIKeyUpsert) SetIPBlacklist(v []string) *APIKeyUpsert {
- u.Set(apikey.FieldIPBlacklist, v)
- return u
- }
- // UpdateIPBlacklist sets the "ip_blacklist" field to the value that was provided on create.
- func (u *APIKeyUpsert) UpdateIPBlacklist() *APIKeyUpsert {
- u.SetExcluded(apikey.FieldIPBlacklist)
- return u
- }
- // ClearIPBlacklist clears the value of the "ip_blacklist" field.
- func (u *APIKeyUpsert) ClearIPBlacklist() *APIKeyUpsert {
- u.SetNull(apikey.FieldIPBlacklist)
- return u
- }
- // SetQuota sets the "quota" field.
- func (u *APIKeyUpsert) SetQuota(v float64) *APIKeyUpsert {
- u.Set(apikey.FieldQuota, v)
- return u
- }
- // UpdateQuota sets the "quota" field to the value that was provided on create.
- func (u *APIKeyUpsert) UpdateQuota() *APIKeyUpsert {
- u.SetExcluded(apikey.FieldQuota)
- return u
- }
- // AddQuota adds v to the "quota" field.
- func (u *APIKeyUpsert) AddQuota(v float64) *APIKeyUpsert {
- u.Add(apikey.FieldQuota, v)
- return u
- }
- // SetQuotaUsed sets the "quota_used" field.
- func (u *APIKeyUpsert) SetQuotaUsed(v float64) *APIKeyUpsert {
- u.Set(apikey.FieldQuotaUsed, v)
- return u
- }
- // UpdateQuotaUsed sets the "quota_used" field to the value that was provided on create.
- func (u *APIKeyUpsert) UpdateQuotaUsed() *APIKeyUpsert {
- u.SetExcluded(apikey.FieldQuotaUsed)
- return u
- }
- // AddQuotaUsed adds v to the "quota_used" field.
- func (u *APIKeyUpsert) AddQuotaUsed(v float64) *APIKeyUpsert {
- u.Add(apikey.FieldQuotaUsed, v)
- return u
- }
- // SetExpiresAt sets the "expires_at" field.
- func (u *APIKeyUpsert) SetExpiresAt(v time.Time) *APIKeyUpsert {
- u.Set(apikey.FieldExpiresAt, v)
- return u
- }
- // UpdateExpiresAt sets the "expires_at" field to the value that was provided on create.
- func (u *APIKeyUpsert) UpdateExpiresAt() *APIKeyUpsert {
- u.SetExcluded(apikey.FieldExpiresAt)
- return u
- }
- // ClearExpiresAt clears the value of the "expires_at" field.
- func (u *APIKeyUpsert) ClearExpiresAt() *APIKeyUpsert {
- u.SetNull(apikey.FieldExpiresAt)
- return u
- }
- // SetRateLimit5h sets the "rate_limit_5h" field.
- func (u *APIKeyUpsert) SetRateLimit5h(v float64) *APIKeyUpsert {
- u.Set(apikey.FieldRateLimit5h, v)
- return u
- }
- // UpdateRateLimit5h sets the "rate_limit_5h" field to the value that was provided on create.
- func (u *APIKeyUpsert) UpdateRateLimit5h() *APIKeyUpsert {
- u.SetExcluded(apikey.FieldRateLimit5h)
- return u
- }
- // AddRateLimit5h adds v to the "rate_limit_5h" field.
- func (u *APIKeyUpsert) AddRateLimit5h(v float64) *APIKeyUpsert {
- u.Add(apikey.FieldRateLimit5h, v)
- return u
- }
- // SetRateLimit1d sets the "rate_limit_1d" field.
- func (u *APIKeyUpsert) SetRateLimit1d(v float64) *APIKeyUpsert {
- u.Set(apikey.FieldRateLimit1d, v)
- return u
- }
- // UpdateRateLimit1d sets the "rate_limit_1d" field to the value that was provided on create.
- func (u *APIKeyUpsert) UpdateRateLimit1d() *APIKeyUpsert {
- u.SetExcluded(apikey.FieldRateLimit1d)
- return u
- }
- // AddRateLimit1d adds v to the "rate_limit_1d" field.
- func (u *APIKeyUpsert) AddRateLimit1d(v float64) *APIKeyUpsert {
- u.Add(apikey.FieldRateLimit1d, v)
- return u
- }
- // SetRateLimit7d sets the "rate_limit_7d" field.
- func (u *APIKeyUpsert) SetRateLimit7d(v float64) *APIKeyUpsert {
- u.Set(apikey.FieldRateLimit7d, v)
- return u
- }
- // UpdateRateLimit7d sets the "rate_limit_7d" field to the value that was provided on create.
- func (u *APIKeyUpsert) UpdateRateLimit7d() *APIKeyUpsert {
- u.SetExcluded(apikey.FieldRateLimit7d)
- return u
- }
- // AddRateLimit7d adds v to the "rate_limit_7d" field.
- func (u *APIKeyUpsert) AddRateLimit7d(v float64) *APIKeyUpsert {
- u.Add(apikey.FieldRateLimit7d, v)
- return u
- }
- // SetUsage5h sets the "usage_5h" field.
- func (u *APIKeyUpsert) SetUsage5h(v float64) *APIKeyUpsert {
- u.Set(apikey.FieldUsage5h, v)
- return u
- }
- // UpdateUsage5h sets the "usage_5h" field to the value that was provided on create.
- func (u *APIKeyUpsert) UpdateUsage5h() *APIKeyUpsert {
- u.SetExcluded(apikey.FieldUsage5h)
- return u
- }
- // AddUsage5h adds v to the "usage_5h" field.
- func (u *APIKeyUpsert) AddUsage5h(v float64) *APIKeyUpsert {
- u.Add(apikey.FieldUsage5h, v)
- return u
- }
- // SetUsage1d sets the "usage_1d" field.
- func (u *APIKeyUpsert) SetUsage1d(v float64) *APIKeyUpsert {
- u.Set(apikey.FieldUsage1d, v)
- return u
- }
- // UpdateUsage1d sets the "usage_1d" field to the value that was provided on create.
- func (u *APIKeyUpsert) UpdateUsage1d() *APIKeyUpsert {
- u.SetExcluded(apikey.FieldUsage1d)
- return u
- }
- // AddUsage1d adds v to the "usage_1d" field.
- func (u *APIKeyUpsert) AddUsage1d(v float64) *APIKeyUpsert {
- u.Add(apikey.FieldUsage1d, v)
- return u
- }
- // SetUsage7d sets the "usage_7d" field.
- func (u *APIKeyUpsert) SetUsage7d(v float64) *APIKeyUpsert {
- u.Set(apikey.FieldUsage7d, v)
- return u
- }
- // UpdateUsage7d sets the "usage_7d" field to the value that was provided on create.
- func (u *APIKeyUpsert) UpdateUsage7d() *APIKeyUpsert {
- u.SetExcluded(apikey.FieldUsage7d)
- return u
- }
- // AddUsage7d adds v to the "usage_7d" field.
- func (u *APIKeyUpsert) AddUsage7d(v float64) *APIKeyUpsert {
- u.Add(apikey.FieldUsage7d, v)
- return u
- }
- // SetWindow5hStart sets the "window_5h_start" field.
- func (u *APIKeyUpsert) SetWindow5hStart(v time.Time) *APIKeyUpsert {
- u.Set(apikey.FieldWindow5hStart, v)
- return u
- }
- // UpdateWindow5hStart sets the "window_5h_start" field to the value that was provided on create.
- func (u *APIKeyUpsert) UpdateWindow5hStart() *APIKeyUpsert {
- u.SetExcluded(apikey.FieldWindow5hStart)
- return u
- }
- // ClearWindow5hStart clears the value of the "window_5h_start" field.
- func (u *APIKeyUpsert) ClearWindow5hStart() *APIKeyUpsert {
- u.SetNull(apikey.FieldWindow5hStart)
- return u
- }
- // SetWindow1dStart sets the "window_1d_start" field.
- func (u *APIKeyUpsert) SetWindow1dStart(v time.Time) *APIKeyUpsert {
- u.Set(apikey.FieldWindow1dStart, v)
- return u
- }
- // UpdateWindow1dStart sets the "window_1d_start" field to the value that was provided on create.
- func (u *APIKeyUpsert) UpdateWindow1dStart() *APIKeyUpsert {
- u.SetExcluded(apikey.FieldWindow1dStart)
- return u
- }
- // ClearWindow1dStart clears the value of the "window_1d_start" field.
- func (u *APIKeyUpsert) ClearWindow1dStart() *APIKeyUpsert {
- u.SetNull(apikey.FieldWindow1dStart)
- return u
- }
- // SetWindow7dStart sets the "window_7d_start" field.
- func (u *APIKeyUpsert) SetWindow7dStart(v time.Time) *APIKeyUpsert {
- u.Set(apikey.FieldWindow7dStart, v)
- return u
- }
- // UpdateWindow7dStart sets the "window_7d_start" field to the value that was provided on create.
- func (u *APIKeyUpsert) UpdateWindow7dStart() *APIKeyUpsert {
- u.SetExcluded(apikey.FieldWindow7dStart)
- return u
- }
- // ClearWindow7dStart clears the value of the "window_7d_start" field.
- func (u *APIKeyUpsert) ClearWindow7dStart() *APIKeyUpsert {
- u.SetNull(apikey.FieldWindow7dStart)
- return u
- }
- // UpdateNewValues updates the mutable fields using the new values that were set on create.
- // Using this option is equivalent to using:
- //
- // client.APIKey.Create().
- // OnConflict(
- // sql.ResolveWithNewValues(),
- // ).
- // Exec(ctx)
- func (u *APIKeyUpsertOne) UpdateNewValues() *APIKeyUpsertOne {
- u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
- u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
- if _, exists := u.create.mutation.CreatedAt(); exists {
- s.SetIgnore(apikey.FieldCreatedAt)
- }
- }))
- return u
- }
- // Ignore sets each column to itself in case of conflict.
- // Using this option is equivalent to using:
- //
- // client.APIKey.Create().
- // OnConflict(sql.ResolveWithIgnore()).
- // Exec(ctx)
- func (u *APIKeyUpsertOne) Ignore() *APIKeyUpsertOne {
- u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
- return u
- }
- // DoNothing configures the conflict_action to `DO NOTHING`.
- // Supported only by SQLite and PostgreSQL.
- func (u *APIKeyUpsertOne) DoNothing() *APIKeyUpsertOne {
- u.create.conflict = append(u.create.conflict, sql.DoNothing())
- return u
- }
- // Update allows overriding fields `UPDATE` values. See the APIKeyCreate.OnConflict
- // documentation for more info.
- func (u *APIKeyUpsertOne) Update(set func(*APIKeyUpsert)) *APIKeyUpsertOne {
- u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
- set(&APIKeyUpsert{UpdateSet: update})
- }))
- return u
- }
- // SetUpdatedAt sets the "updated_at" field.
- func (u *APIKeyUpsertOne) SetUpdatedAt(v time.Time) *APIKeyUpsertOne {
- return u.Update(func(s *APIKeyUpsert) {
- s.SetUpdatedAt(v)
- })
- }
- // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
- func (u *APIKeyUpsertOne) UpdateUpdatedAt() *APIKeyUpsertOne {
- return u.Update(func(s *APIKeyUpsert) {
- s.UpdateUpdatedAt()
- })
- }
- // SetDeletedAt sets the "deleted_at" field.
- func (u *APIKeyUpsertOne) SetDeletedAt(v time.Time) *APIKeyUpsertOne {
- return u.Update(func(s *APIKeyUpsert) {
- s.SetDeletedAt(v)
- })
- }
- // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
- func (u *APIKeyUpsertOne) UpdateDeletedAt() *APIKeyUpsertOne {
- return u.Update(func(s *APIKeyUpsert) {
- s.UpdateDeletedAt()
- })
- }
- // ClearDeletedAt clears the value of the "deleted_at" field.
- func (u *APIKeyUpsertOne) ClearDeletedAt() *APIKeyUpsertOne {
- return u.Update(func(s *APIKeyUpsert) {
- s.ClearDeletedAt()
- })
- }
- // SetUserID sets the "user_id" field.
- func (u *APIKeyUpsertOne) SetUserID(v int64) *APIKeyUpsertOne {
- return u.Update(func(s *APIKeyUpsert) {
- s.SetUserID(v)
- })
- }
- // UpdateUserID sets the "user_id" field to the value that was provided on create.
- func (u *APIKeyUpsertOne) UpdateUserID() *APIKeyUpsertOne {
- return u.Update(func(s *APIKeyUpsert) {
- s.UpdateUserID()
- })
- }
- // SetKey sets the "key" field.
- func (u *APIKeyUpsertOne) SetKey(v string) *APIKeyUpsertOne {
- return u.Update(func(s *APIKeyUpsert) {
- s.SetKey(v)
- })
- }
- // UpdateKey sets the "key" field to the value that was provided on create.
- func (u *APIKeyUpsertOne) UpdateKey() *APIKeyUpsertOne {
- return u.Update(func(s *APIKeyUpsert) {
- s.UpdateKey()
- })
- }
- // ClearKey clears the value of the "key" field.
- func (u *APIKeyUpsertOne) ClearKey() *APIKeyUpsertOne {
- return u.Update(func(s *APIKeyUpsert) {
- s.ClearKey()
- })
- }
- // SetKeyHash sets the "key_hash" field.
- func (u *APIKeyUpsertOne) SetKeyHash(v string) *APIKeyUpsertOne {
- return u.Update(func(s *APIKeyUpsert) {
- s.SetKeyHash(v)
- })
- }
- // UpdateKeyHash sets the "key_hash" field to the value that was provided on create.
- func (u *APIKeyUpsertOne) UpdateKeyHash() *APIKeyUpsertOne {
- return u.Update(func(s *APIKeyUpsert) {
- s.UpdateKeyHash()
- })
- }
- // ClearKeyHash clears the value of the "key_hash" field.
- func (u *APIKeyUpsertOne) ClearKeyHash() *APIKeyUpsertOne {
- return u.Update(func(s *APIKeyUpsert) {
- s.ClearKeyHash()
- })
- }
- // SetKeyPrefix sets the "key_prefix" field.
- func (u *APIKeyUpsertOne) SetKeyPrefix(v string) *APIKeyUpsertOne {
- return u.Update(func(s *APIKeyUpsert) {
- s.SetKeyPrefix(v)
- })
- }
- // UpdateKeyPrefix sets the "key_prefix" field to the value that was provided on create.
- func (u *APIKeyUpsertOne) UpdateKeyPrefix() *APIKeyUpsertOne {
- return u.Update(func(s *APIKeyUpsert) {
- s.UpdateKeyPrefix()
- })
- }
- // ClearKeyPrefix clears the value of the "key_prefix" field.
- func (u *APIKeyUpsertOne) ClearKeyPrefix() *APIKeyUpsertOne {
- return u.Update(func(s *APIKeyUpsert) {
- s.ClearKeyPrefix()
- })
- }
- // SetName sets the "name" field.
- func (u *APIKeyUpsertOne) SetName(v string) *APIKeyUpsertOne {
- return u.Update(func(s *APIKeyUpsert) {
- s.SetName(v)
- })
- }
- // UpdateName sets the "name" field to the value that was provided on create.
- func (u *APIKeyUpsertOne) UpdateName() *APIKeyUpsertOne {
- return u.Update(func(s *APIKeyUpsert) {
- s.UpdateName()
- })
- }
- // SetGroupID sets the "group_id" field.
- func (u *APIKeyUpsertOne) SetGroupID(v int64) *APIKeyUpsertOne {
- return u.Update(func(s *APIKeyUpsert) {
- s.SetGroupID(v)
- })
- }
- // UpdateGroupID sets the "group_id" field to the value that was provided on create.
- func (u *APIKeyUpsertOne) UpdateGroupID() *APIKeyUpsertOne {
- return u.Update(func(s *APIKeyUpsert) {
- s.UpdateGroupID()
- })
- }
- // ClearGroupID clears the value of the "group_id" field.
- func (u *APIKeyUpsertOne) ClearGroupID() *APIKeyUpsertOne {
- return u.Update(func(s *APIKeyUpsert) {
- s.ClearGroupID()
- })
- }
- // SetStatus sets the "status" field.
- func (u *APIKeyUpsertOne) SetStatus(v string) *APIKeyUpsertOne {
- return u.Update(func(s *APIKeyUpsert) {
- s.SetStatus(v)
- })
- }
- // UpdateStatus sets the "status" field to the value that was provided on create.
- func (u *APIKeyUpsertOne) UpdateStatus() *APIKeyUpsertOne {
- return u.Update(func(s *APIKeyUpsert) {
- s.UpdateStatus()
- })
- }
- // SetLastUsedAt sets the "last_used_at" field.
- func (u *APIKeyUpsertOne) SetLastUsedAt(v time.Time) *APIKeyUpsertOne {
- return u.Update(func(s *APIKeyUpsert) {
- s.SetLastUsedAt(v)
- })
- }
- // UpdateLastUsedAt sets the "last_used_at" field to the value that was provided on create.
- func (u *APIKeyUpsertOne) UpdateLastUsedAt() *APIKeyUpsertOne {
- return u.Update(func(s *APIKeyUpsert) {
- s.UpdateLastUsedAt()
- })
- }
- // ClearLastUsedAt clears the value of the "last_used_at" field.
- func (u *APIKeyUpsertOne) ClearLastUsedAt() *APIKeyUpsertOne {
- return u.Update(func(s *APIKeyUpsert) {
- s.ClearLastUsedAt()
- })
- }
- // SetIPWhitelist sets the "ip_whitelist" field.
- func (u *APIKeyUpsertOne) SetIPWhitelist(v []string) *APIKeyUpsertOne {
- return u.Update(func(s *APIKeyUpsert) {
- s.SetIPWhitelist(v)
- })
- }
- // UpdateIPWhitelist sets the "ip_whitelist" field to the value that was provided on create.
- func (u *APIKeyUpsertOne) UpdateIPWhitelist() *APIKeyUpsertOne {
- return u.Update(func(s *APIKeyUpsert) {
- s.UpdateIPWhitelist()
- })
- }
- // ClearIPWhitelist clears the value of the "ip_whitelist" field.
- func (u *APIKeyUpsertOne) ClearIPWhitelist() *APIKeyUpsertOne {
- return u.Update(func(s *APIKeyUpsert) {
- s.ClearIPWhitelist()
- })
- }
- // SetIPBlacklist sets the "ip_blacklist" field.
- func (u *APIKeyUpsertOne) SetIPBlacklist(v []string) *APIKeyUpsertOne {
- return u.Update(func(s *APIKeyUpsert) {
- s.SetIPBlacklist(v)
- })
- }
- // UpdateIPBlacklist sets the "ip_blacklist" field to the value that was provided on create.
- func (u *APIKeyUpsertOne) UpdateIPBlacklist() *APIKeyUpsertOne {
- return u.Update(func(s *APIKeyUpsert) {
- s.UpdateIPBlacklist()
- })
- }
- // ClearIPBlacklist clears the value of the "ip_blacklist" field.
- func (u *APIKeyUpsertOne) ClearIPBlacklist() *APIKeyUpsertOne {
- return u.Update(func(s *APIKeyUpsert) {
- s.ClearIPBlacklist()
- })
- }
- // SetQuota sets the "quota" field.
- func (u *APIKeyUpsertOne) SetQuota(v float64) *APIKeyUpsertOne {
- return u.Update(func(s *APIKeyUpsert) {
- s.SetQuota(v)
- })
- }
- // AddQuota adds v to the "quota" field.
- func (u *APIKeyUpsertOne) AddQuota(v float64) *APIKeyUpsertOne {
- return u.Update(func(s *APIKeyUpsert) {
- s.AddQuota(v)
- })
- }
- // UpdateQuota sets the "quota" field to the value that was provided on create.
- func (u *APIKeyUpsertOne) UpdateQuota() *APIKeyUpsertOne {
- return u.Update(func(s *APIKeyUpsert) {
- s.UpdateQuota()
- })
- }
- // SetQuotaUsed sets the "quota_used" field.
- func (u *APIKeyUpsertOne) SetQuotaUsed(v float64) *APIKeyUpsertOne {
- return u.Update(func(s *APIKeyUpsert) {
- s.SetQuotaUsed(v)
- })
- }
- // AddQuotaUsed adds v to the "quota_used" field.
- func (u *APIKeyUpsertOne) AddQuotaUsed(v float64) *APIKeyUpsertOne {
- return u.Update(func(s *APIKeyUpsert) {
- s.AddQuotaUsed(v)
- })
- }
- // UpdateQuotaUsed sets the "quota_used" field to the value that was provided on create.
- func (u *APIKeyUpsertOne) UpdateQuotaUsed() *APIKeyUpsertOne {
- return u.Update(func(s *APIKeyUpsert) {
- s.UpdateQuotaUsed()
- })
- }
- // SetExpiresAt sets the "expires_at" field.
- func (u *APIKeyUpsertOne) SetExpiresAt(v time.Time) *APIKeyUpsertOne {
- return u.Update(func(s *APIKeyUpsert) {
- s.SetExpiresAt(v)
- })
- }
- // UpdateExpiresAt sets the "expires_at" field to the value that was provided on create.
- func (u *APIKeyUpsertOne) UpdateExpiresAt() *APIKeyUpsertOne {
- return u.Update(func(s *APIKeyUpsert) {
- s.UpdateExpiresAt()
- })
- }
- // ClearExpiresAt clears the value of the "expires_at" field.
- func (u *APIKeyUpsertOne) ClearExpiresAt() *APIKeyUpsertOne {
- return u.Update(func(s *APIKeyUpsert) {
- s.ClearExpiresAt()
- })
- }
- // SetRateLimit5h sets the "rate_limit_5h" field.
- func (u *APIKeyUpsertOne) SetRateLimit5h(v float64) *APIKeyUpsertOne {
- return u.Update(func(s *APIKeyUpsert) {
- s.SetRateLimit5h(v)
- })
- }
- // AddRateLimit5h adds v to the "rate_limit_5h" field.
- func (u *APIKeyUpsertOne) AddRateLimit5h(v float64) *APIKeyUpsertOne {
- return u.Update(func(s *APIKeyUpsert) {
- s.AddRateLimit5h(v)
- })
- }
- // UpdateRateLimit5h sets the "rate_limit_5h" field to the value that was provided on create.
- func (u *APIKeyUpsertOne) UpdateRateLimit5h() *APIKeyUpsertOne {
- return u.Update(func(s *APIKeyUpsert) {
- s.UpdateRateLimit5h()
- })
- }
- // SetRateLimit1d sets the "rate_limit_1d" field.
- func (u *APIKeyUpsertOne) SetRateLimit1d(v float64) *APIKeyUpsertOne {
- return u.Update(func(s *APIKeyUpsert) {
- s.SetRateLimit1d(v)
- })
- }
- // AddRateLimit1d adds v to the "rate_limit_1d" field.
- func (u *APIKeyUpsertOne) AddRateLimit1d(v float64) *APIKeyUpsertOne {
- return u.Update(func(s *APIKeyUpsert) {
- s.AddRateLimit1d(v)
- })
- }
- // UpdateRateLimit1d sets the "rate_limit_1d" field to the value that was provided on create.
- func (u *APIKeyUpsertOne) UpdateRateLimit1d() *APIKeyUpsertOne {
- return u.Update(func(s *APIKeyUpsert) {
- s.UpdateRateLimit1d()
- })
- }
- // SetRateLimit7d sets the "rate_limit_7d" field.
- func (u *APIKeyUpsertOne) SetRateLimit7d(v float64) *APIKeyUpsertOne {
- return u.Update(func(s *APIKeyUpsert) {
- s.SetRateLimit7d(v)
- })
- }
- // AddRateLimit7d adds v to the "rate_limit_7d" field.
- func (u *APIKeyUpsertOne) AddRateLimit7d(v float64) *APIKeyUpsertOne {
- return u.Update(func(s *APIKeyUpsert) {
- s.AddRateLimit7d(v)
- })
- }
- // UpdateRateLimit7d sets the "rate_limit_7d" field to the value that was provided on create.
- func (u *APIKeyUpsertOne) UpdateRateLimit7d() *APIKeyUpsertOne {
- return u.Update(func(s *APIKeyUpsert) {
- s.UpdateRateLimit7d()
- })
- }
- // SetUsage5h sets the "usage_5h" field.
- func (u *APIKeyUpsertOne) SetUsage5h(v float64) *APIKeyUpsertOne {
- return u.Update(func(s *APIKeyUpsert) {
- s.SetUsage5h(v)
- })
- }
- // AddUsage5h adds v to the "usage_5h" field.
- func (u *APIKeyUpsertOne) AddUsage5h(v float64) *APIKeyUpsertOne {
- return u.Update(func(s *APIKeyUpsert) {
- s.AddUsage5h(v)
- })
- }
- // UpdateUsage5h sets the "usage_5h" field to the value that was provided on create.
- func (u *APIKeyUpsertOne) UpdateUsage5h() *APIKeyUpsertOne {
- return u.Update(func(s *APIKeyUpsert) {
- s.UpdateUsage5h()
- })
- }
- // SetUsage1d sets the "usage_1d" field.
- func (u *APIKeyUpsertOne) SetUsage1d(v float64) *APIKeyUpsertOne {
- return u.Update(func(s *APIKeyUpsert) {
- s.SetUsage1d(v)
- })
- }
- // AddUsage1d adds v to the "usage_1d" field.
- func (u *APIKeyUpsertOne) AddUsage1d(v float64) *APIKeyUpsertOne {
- return u.Update(func(s *APIKeyUpsert) {
- s.AddUsage1d(v)
- })
- }
- // UpdateUsage1d sets the "usage_1d" field to the value that was provided on create.
- func (u *APIKeyUpsertOne) UpdateUsage1d() *APIKeyUpsertOne {
- return u.Update(func(s *APIKeyUpsert) {
- s.UpdateUsage1d()
- })
- }
- // SetUsage7d sets the "usage_7d" field.
- func (u *APIKeyUpsertOne) SetUsage7d(v float64) *APIKeyUpsertOne {
- return u.Update(func(s *APIKeyUpsert) {
- s.SetUsage7d(v)
- })
- }
- // AddUsage7d adds v to the "usage_7d" field.
- func (u *APIKeyUpsertOne) AddUsage7d(v float64) *APIKeyUpsertOne {
- return u.Update(func(s *APIKeyUpsert) {
- s.AddUsage7d(v)
- })
- }
- // UpdateUsage7d sets the "usage_7d" field to the value that was provided on create.
- func (u *APIKeyUpsertOne) UpdateUsage7d() *APIKeyUpsertOne {
- return u.Update(func(s *APIKeyUpsert) {
- s.UpdateUsage7d()
- })
- }
- // SetWindow5hStart sets the "window_5h_start" field.
- func (u *APIKeyUpsertOne) SetWindow5hStart(v time.Time) *APIKeyUpsertOne {
- return u.Update(func(s *APIKeyUpsert) {
- s.SetWindow5hStart(v)
- })
- }
- // UpdateWindow5hStart sets the "window_5h_start" field to the value that was provided on create.
- func (u *APIKeyUpsertOne) UpdateWindow5hStart() *APIKeyUpsertOne {
- return u.Update(func(s *APIKeyUpsert) {
- s.UpdateWindow5hStart()
- })
- }
- // ClearWindow5hStart clears the value of the "window_5h_start" field.
- func (u *APIKeyUpsertOne) ClearWindow5hStart() *APIKeyUpsertOne {
- return u.Update(func(s *APIKeyUpsert) {
- s.ClearWindow5hStart()
- })
- }
- // SetWindow1dStart sets the "window_1d_start" field.
- func (u *APIKeyUpsertOne) SetWindow1dStart(v time.Time) *APIKeyUpsertOne {
- return u.Update(func(s *APIKeyUpsert) {
- s.SetWindow1dStart(v)
- })
- }
- // UpdateWindow1dStart sets the "window_1d_start" field to the value that was provided on create.
- func (u *APIKeyUpsertOne) UpdateWindow1dStart() *APIKeyUpsertOne {
- return u.Update(func(s *APIKeyUpsert) {
- s.UpdateWindow1dStart()
- })
- }
- // ClearWindow1dStart clears the value of the "window_1d_start" field.
- func (u *APIKeyUpsertOne) ClearWindow1dStart() *APIKeyUpsertOne {
- return u.Update(func(s *APIKeyUpsert) {
- s.ClearWindow1dStart()
- })
- }
- // SetWindow7dStart sets the "window_7d_start" field.
- func (u *APIKeyUpsertOne) SetWindow7dStart(v time.Time) *APIKeyUpsertOne {
- return u.Update(func(s *APIKeyUpsert) {
- s.SetWindow7dStart(v)
- })
- }
- // UpdateWindow7dStart sets the "window_7d_start" field to the value that was provided on create.
- func (u *APIKeyUpsertOne) UpdateWindow7dStart() *APIKeyUpsertOne {
- return u.Update(func(s *APIKeyUpsert) {
- s.UpdateWindow7dStart()
- })
- }
- // ClearWindow7dStart clears the value of the "window_7d_start" field.
- func (u *APIKeyUpsertOne) ClearWindow7dStart() *APIKeyUpsertOne {
- return u.Update(func(s *APIKeyUpsert) {
- s.ClearWindow7dStart()
- })
- }
- // Exec executes the query.
- func (u *APIKeyUpsertOne) Exec(ctx context.Context) error {
- if len(u.create.conflict) == 0 {
- return errors.New("ent: missing options for APIKeyCreate.OnConflict")
- }
- return u.create.Exec(ctx)
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (u *APIKeyUpsertOne) ExecX(ctx context.Context) {
- if err := u.create.Exec(ctx); err != nil {
- panic(err)
- }
- }
- // Exec executes the UPSERT query and returns the inserted/updated ID.
- func (u *APIKeyUpsertOne) ID(ctx context.Context) (id int64, err error) {
- node, err := u.create.Save(ctx)
- if err != nil {
- return id, err
- }
- return node.ID, nil
- }
- // IDX is like ID, but panics if an error occurs.
- func (u *APIKeyUpsertOne) IDX(ctx context.Context) int64 {
- id, err := u.ID(ctx)
- if err != nil {
- panic(err)
- }
- return id
- }
- // APIKeyCreateBulk is the builder for creating many APIKey entities in bulk.
- type APIKeyCreateBulk struct {
- config
- err error
- builders []*APIKeyCreate
- conflict []sql.ConflictOption
- }
- // Save creates the APIKey entities in the database.
- func (_c *APIKeyCreateBulk) Save(ctx context.Context) ([]*APIKey, error) {
- if _c.err != nil {
- return nil, _c.err
- }
- specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
- nodes := make([]*APIKey, len(_c.builders))
- mutators := make([]Mutator, len(_c.builders))
- for i := range _c.builders {
- func(i int, root context.Context) {
- builder := _c.builders[i]
- builder.defaults()
- var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
- mutation, ok := m.(*APIKeyMutation)
- if !ok {
- return nil, fmt.Errorf("unexpected mutation type %T", m)
- }
- if err := builder.check(); err != nil {
- return nil, err
- }
- builder.mutation = mutation
- var err error
- nodes[i], specs[i] = builder.createSpec()
- if i < len(mutators)-1 {
- _, err = mutators[i+1].Mutate(root, _c.builders[i+1].mutation)
- } else {
- spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
- spec.OnConflict = _c.conflict
- // Invoke the actual operation on the latest mutation in the chain.
- if err = sqlgraph.BatchCreate(ctx, _c.driver, spec); err != nil {
- if sqlgraph.IsConstraintError(err) {
- err = &ConstraintError{msg: err.Error(), wrap: err}
- }
- }
- }
- if err != nil {
- return nil, err
- }
- mutation.id = &nodes[i].ID
- if specs[i].ID.Value != nil {
- id := specs[i].ID.Value.(int64)
- nodes[i].ID = int64(id)
- }
- mutation.done = true
- return nodes[i], nil
- })
- for i := len(builder.hooks) - 1; i >= 0; i-- {
- mut = builder.hooks[i](mut)
- }
- mutators[i] = mut
- }(i, ctx)
- }
- if len(mutators) > 0 {
- if _, err := mutators[0].Mutate(ctx, _c.builders[0].mutation); err != nil {
- return nil, err
- }
- }
- return nodes, nil
- }
- // SaveX is like Save, but panics if an error occurs.
- func (_c *APIKeyCreateBulk) SaveX(ctx context.Context) []*APIKey {
- v, err := _c.Save(ctx)
- if err != nil {
- panic(err)
- }
- return v
- }
- // Exec executes the query.
- func (_c *APIKeyCreateBulk) Exec(ctx context.Context) error {
- _, err := _c.Save(ctx)
- return err
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (_c *APIKeyCreateBulk) ExecX(ctx context.Context) {
- if err := _c.Exec(ctx); err != nil {
- panic(err)
- }
- }
- // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
- // of the `INSERT` statement. For example:
- //
- // client.APIKey.CreateBulk(builders...).
- // OnConflict(
- // // Update the row with the new values
- // // the was proposed for insertion.
- // sql.ResolveWithNewValues(),
- // ).
- // // Override some of the fields with custom
- // // update values.
- // Update(func(u *ent.APIKeyUpsert) {
- // SetCreatedAt(v+v).
- // }).
- // Exec(ctx)
- func (_c *APIKeyCreateBulk) OnConflict(opts ...sql.ConflictOption) *APIKeyUpsertBulk {
- _c.conflict = opts
- return &APIKeyUpsertBulk{
- create: _c,
- }
- }
- // OnConflictColumns calls `OnConflict` and configures the columns
- // as conflict target. Using this option is equivalent to using:
- //
- // client.APIKey.Create().
- // OnConflict(sql.ConflictColumns(columns...)).
- // Exec(ctx)
- func (_c *APIKeyCreateBulk) OnConflictColumns(columns ...string) *APIKeyUpsertBulk {
- _c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
- return &APIKeyUpsertBulk{
- create: _c,
- }
- }
- // APIKeyUpsertBulk is the builder for "upsert"-ing
- // a bulk of APIKey nodes.
- type APIKeyUpsertBulk struct {
- create *APIKeyCreateBulk
- }
- // UpdateNewValues updates the mutable fields using the new values that
- // were set on create. Using this option is equivalent to using:
- //
- // client.APIKey.Create().
- // OnConflict(
- // sql.ResolveWithNewValues(),
- // ).
- // Exec(ctx)
- func (u *APIKeyUpsertBulk) UpdateNewValues() *APIKeyUpsertBulk {
- u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
- u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
- for _, b := range u.create.builders {
- if _, exists := b.mutation.CreatedAt(); exists {
- s.SetIgnore(apikey.FieldCreatedAt)
- }
- }
- }))
- return u
- }
- // Ignore sets each column to itself in case of conflict.
- // Using this option is equivalent to using:
- //
- // client.APIKey.Create().
- // OnConflict(sql.ResolveWithIgnore()).
- // Exec(ctx)
- func (u *APIKeyUpsertBulk) Ignore() *APIKeyUpsertBulk {
- u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
- return u
- }
- // DoNothing configures the conflict_action to `DO NOTHING`.
- // Supported only by SQLite and PostgreSQL.
- func (u *APIKeyUpsertBulk) DoNothing() *APIKeyUpsertBulk {
- u.create.conflict = append(u.create.conflict, sql.DoNothing())
- return u
- }
- // Update allows overriding fields `UPDATE` values. See the APIKeyCreateBulk.OnConflict
- // documentation for more info.
- func (u *APIKeyUpsertBulk) Update(set func(*APIKeyUpsert)) *APIKeyUpsertBulk {
- u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
- set(&APIKeyUpsert{UpdateSet: update})
- }))
- return u
- }
- // SetUpdatedAt sets the "updated_at" field.
- func (u *APIKeyUpsertBulk) SetUpdatedAt(v time.Time) *APIKeyUpsertBulk {
- return u.Update(func(s *APIKeyUpsert) {
- s.SetUpdatedAt(v)
- })
- }
- // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
- func (u *APIKeyUpsertBulk) UpdateUpdatedAt() *APIKeyUpsertBulk {
- return u.Update(func(s *APIKeyUpsert) {
- s.UpdateUpdatedAt()
- })
- }
- // SetDeletedAt sets the "deleted_at" field.
- func (u *APIKeyUpsertBulk) SetDeletedAt(v time.Time) *APIKeyUpsertBulk {
- return u.Update(func(s *APIKeyUpsert) {
- s.SetDeletedAt(v)
- })
- }
- // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
- func (u *APIKeyUpsertBulk) UpdateDeletedAt() *APIKeyUpsertBulk {
- return u.Update(func(s *APIKeyUpsert) {
- s.UpdateDeletedAt()
- })
- }
- // ClearDeletedAt clears the value of the "deleted_at" field.
- func (u *APIKeyUpsertBulk) ClearDeletedAt() *APIKeyUpsertBulk {
- return u.Update(func(s *APIKeyUpsert) {
- s.ClearDeletedAt()
- })
- }
- // SetUserID sets the "user_id" field.
- func (u *APIKeyUpsertBulk) SetUserID(v int64) *APIKeyUpsertBulk {
- return u.Update(func(s *APIKeyUpsert) {
- s.SetUserID(v)
- })
- }
- // UpdateUserID sets the "user_id" field to the value that was provided on create.
- func (u *APIKeyUpsertBulk) UpdateUserID() *APIKeyUpsertBulk {
- return u.Update(func(s *APIKeyUpsert) {
- s.UpdateUserID()
- })
- }
- // SetKey sets the "key" field.
- func (u *APIKeyUpsertBulk) SetKey(v string) *APIKeyUpsertBulk {
- return u.Update(func(s *APIKeyUpsert) {
- s.SetKey(v)
- })
- }
- // UpdateKey sets the "key" field to the value that was provided on create.
- func (u *APIKeyUpsertBulk) UpdateKey() *APIKeyUpsertBulk {
- return u.Update(func(s *APIKeyUpsert) {
- s.UpdateKey()
- })
- }
- // ClearKey clears the value of the "key" field.
- func (u *APIKeyUpsertBulk) ClearKey() *APIKeyUpsertBulk {
- return u.Update(func(s *APIKeyUpsert) {
- s.ClearKey()
- })
- }
- // SetKeyHash sets the "key_hash" field.
- func (u *APIKeyUpsertBulk) SetKeyHash(v string) *APIKeyUpsertBulk {
- return u.Update(func(s *APIKeyUpsert) {
- s.SetKeyHash(v)
- })
- }
- // UpdateKeyHash sets the "key_hash" field to the value that was provided on create.
- func (u *APIKeyUpsertBulk) UpdateKeyHash() *APIKeyUpsertBulk {
- return u.Update(func(s *APIKeyUpsert) {
- s.UpdateKeyHash()
- })
- }
- // ClearKeyHash clears the value of the "key_hash" field.
- func (u *APIKeyUpsertBulk) ClearKeyHash() *APIKeyUpsertBulk {
- return u.Update(func(s *APIKeyUpsert) {
- s.ClearKeyHash()
- })
- }
- // SetKeyPrefix sets the "key_prefix" field.
- func (u *APIKeyUpsertBulk) SetKeyPrefix(v string) *APIKeyUpsertBulk {
- return u.Update(func(s *APIKeyUpsert) {
- s.SetKeyPrefix(v)
- })
- }
- // UpdateKeyPrefix sets the "key_prefix" field to the value that was provided on create.
- func (u *APIKeyUpsertBulk) UpdateKeyPrefix() *APIKeyUpsertBulk {
- return u.Update(func(s *APIKeyUpsert) {
- s.UpdateKeyPrefix()
- })
- }
- // ClearKeyPrefix clears the value of the "key_prefix" field.
- func (u *APIKeyUpsertBulk) ClearKeyPrefix() *APIKeyUpsertBulk {
- return u.Update(func(s *APIKeyUpsert) {
- s.ClearKeyPrefix()
- })
- }
- // SetName sets the "name" field.
- func (u *APIKeyUpsertBulk) SetName(v string) *APIKeyUpsertBulk {
- return u.Update(func(s *APIKeyUpsert) {
- s.SetName(v)
- })
- }
- // UpdateName sets the "name" field to the value that was provided on create.
- func (u *APIKeyUpsertBulk) UpdateName() *APIKeyUpsertBulk {
- return u.Update(func(s *APIKeyUpsert) {
- s.UpdateName()
- })
- }
- // SetGroupID sets the "group_id" field.
- func (u *APIKeyUpsertBulk) SetGroupID(v int64) *APIKeyUpsertBulk {
- return u.Update(func(s *APIKeyUpsert) {
- s.SetGroupID(v)
- })
- }
- // UpdateGroupID sets the "group_id" field to the value that was provided on create.
- func (u *APIKeyUpsertBulk) UpdateGroupID() *APIKeyUpsertBulk {
- return u.Update(func(s *APIKeyUpsert) {
- s.UpdateGroupID()
- })
- }
- // ClearGroupID clears the value of the "group_id" field.
- func (u *APIKeyUpsertBulk) ClearGroupID() *APIKeyUpsertBulk {
- return u.Update(func(s *APIKeyUpsert) {
- s.ClearGroupID()
- })
- }
- // SetStatus sets the "status" field.
- func (u *APIKeyUpsertBulk) SetStatus(v string) *APIKeyUpsertBulk {
- return u.Update(func(s *APIKeyUpsert) {
- s.SetStatus(v)
- })
- }
- // UpdateStatus sets the "status" field to the value that was provided on create.
- func (u *APIKeyUpsertBulk) UpdateStatus() *APIKeyUpsertBulk {
- return u.Update(func(s *APIKeyUpsert) {
- s.UpdateStatus()
- })
- }
- // SetLastUsedAt sets the "last_used_at" field.
- func (u *APIKeyUpsertBulk) SetLastUsedAt(v time.Time) *APIKeyUpsertBulk {
- return u.Update(func(s *APIKeyUpsert) {
- s.SetLastUsedAt(v)
- })
- }
- // UpdateLastUsedAt sets the "last_used_at" field to the value that was provided on create.
- func (u *APIKeyUpsertBulk) UpdateLastUsedAt() *APIKeyUpsertBulk {
- return u.Update(func(s *APIKeyUpsert) {
- s.UpdateLastUsedAt()
- })
- }
- // ClearLastUsedAt clears the value of the "last_used_at" field.
- func (u *APIKeyUpsertBulk) ClearLastUsedAt() *APIKeyUpsertBulk {
- return u.Update(func(s *APIKeyUpsert) {
- s.ClearLastUsedAt()
- })
- }
- // SetIPWhitelist sets the "ip_whitelist" field.
- func (u *APIKeyUpsertBulk) SetIPWhitelist(v []string) *APIKeyUpsertBulk {
- return u.Update(func(s *APIKeyUpsert) {
- s.SetIPWhitelist(v)
- })
- }
- // UpdateIPWhitelist sets the "ip_whitelist" field to the value that was provided on create.
- func (u *APIKeyUpsertBulk) UpdateIPWhitelist() *APIKeyUpsertBulk {
- return u.Update(func(s *APIKeyUpsert) {
- s.UpdateIPWhitelist()
- })
- }
- // ClearIPWhitelist clears the value of the "ip_whitelist" field.
- func (u *APIKeyUpsertBulk) ClearIPWhitelist() *APIKeyUpsertBulk {
- return u.Update(func(s *APIKeyUpsert) {
- s.ClearIPWhitelist()
- })
- }
- // SetIPBlacklist sets the "ip_blacklist" field.
- func (u *APIKeyUpsertBulk) SetIPBlacklist(v []string) *APIKeyUpsertBulk {
- return u.Update(func(s *APIKeyUpsert) {
- s.SetIPBlacklist(v)
- })
- }
- // UpdateIPBlacklist sets the "ip_blacklist" field to the value that was provided on create.
- func (u *APIKeyUpsertBulk) UpdateIPBlacklist() *APIKeyUpsertBulk {
- return u.Update(func(s *APIKeyUpsert) {
- s.UpdateIPBlacklist()
- })
- }
- // ClearIPBlacklist clears the value of the "ip_blacklist" field.
- func (u *APIKeyUpsertBulk) ClearIPBlacklist() *APIKeyUpsertBulk {
- return u.Update(func(s *APIKeyUpsert) {
- s.ClearIPBlacklist()
- })
- }
- // SetQuota sets the "quota" field.
- func (u *APIKeyUpsertBulk) SetQuota(v float64) *APIKeyUpsertBulk {
- return u.Update(func(s *APIKeyUpsert) {
- s.SetQuota(v)
- })
- }
- // AddQuota adds v to the "quota" field.
- func (u *APIKeyUpsertBulk) AddQuota(v float64) *APIKeyUpsertBulk {
- return u.Update(func(s *APIKeyUpsert) {
- s.AddQuota(v)
- })
- }
- // UpdateQuota sets the "quota" field to the value that was provided on create.
- func (u *APIKeyUpsertBulk) UpdateQuota() *APIKeyUpsertBulk {
- return u.Update(func(s *APIKeyUpsert) {
- s.UpdateQuota()
- })
- }
- // SetQuotaUsed sets the "quota_used" field.
- func (u *APIKeyUpsertBulk) SetQuotaUsed(v float64) *APIKeyUpsertBulk {
- return u.Update(func(s *APIKeyUpsert) {
- s.SetQuotaUsed(v)
- })
- }
- // AddQuotaUsed adds v to the "quota_used" field.
- func (u *APIKeyUpsertBulk) AddQuotaUsed(v float64) *APIKeyUpsertBulk {
- return u.Update(func(s *APIKeyUpsert) {
- s.AddQuotaUsed(v)
- })
- }
- // UpdateQuotaUsed sets the "quota_used" field to the value that was provided on create.
- func (u *APIKeyUpsertBulk) UpdateQuotaUsed() *APIKeyUpsertBulk {
- return u.Update(func(s *APIKeyUpsert) {
- s.UpdateQuotaUsed()
- })
- }
- // SetExpiresAt sets the "expires_at" field.
- func (u *APIKeyUpsertBulk) SetExpiresAt(v time.Time) *APIKeyUpsertBulk {
- return u.Update(func(s *APIKeyUpsert) {
- s.SetExpiresAt(v)
- })
- }
- // UpdateExpiresAt sets the "expires_at" field to the value that was provided on create.
- func (u *APIKeyUpsertBulk) UpdateExpiresAt() *APIKeyUpsertBulk {
- return u.Update(func(s *APIKeyUpsert) {
- s.UpdateExpiresAt()
- })
- }
- // ClearExpiresAt clears the value of the "expires_at" field.
- func (u *APIKeyUpsertBulk) ClearExpiresAt() *APIKeyUpsertBulk {
- return u.Update(func(s *APIKeyUpsert) {
- s.ClearExpiresAt()
- })
- }
- // SetRateLimit5h sets the "rate_limit_5h" field.
- func (u *APIKeyUpsertBulk) SetRateLimit5h(v float64) *APIKeyUpsertBulk {
- return u.Update(func(s *APIKeyUpsert) {
- s.SetRateLimit5h(v)
- })
- }
- // AddRateLimit5h adds v to the "rate_limit_5h" field.
- func (u *APIKeyUpsertBulk) AddRateLimit5h(v float64) *APIKeyUpsertBulk {
- return u.Update(func(s *APIKeyUpsert) {
- s.AddRateLimit5h(v)
- })
- }
- // UpdateRateLimit5h sets the "rate_limit_5h" field to the value that was provided on create.
- func (u *APIKeyUpsertBulk) UpdateRateLimit5h() *APIKeyUpsertBulk {
- return u.Update(func(s *APIKeyUpsert) {
- s.UpdateRateLimit5h()
- })
- }
- // SetRateLimit1d sets the "rate_limit_1d" field.
- func (u *APIKeyUpsertBulk) SetRateLimit1d(v float64) *APIKeyUpsertBulk {
- return u.Update(func(s *APIKeyUpsert) {
- s.SetRateLimit1d(v)
- })
- }
- // AddRateLimit1d adds v to the "rate_limit_1d" field.
- func (u *APIKeyUpsertBulk) AddRateLimit1d(v float64) *APIKeyUpsertBulk {
- return u.Update(func(s *APIKeyUpsert) {
- s.AddRateLimit1d(v)
- })
- }
- // UpdateRateLimit1d sets the "rate_limit_1d" field to the value that was provided on create.
- func (u *APIKeyUpsertBulk) UpdateRateLimit1d() *APIKeyUpsertBulk {
- return u.Update(func(s *APIKeyUpsert) {
- s.UpdateRateLimit1d()
- })
- }
- // SetRateLimit7d sets the "rate_limit_7d" field.
- func (u *APIKeyUpsertBulk) SetRateLimit7d(v float64) *APIKeyUpsertBulk {
- return u.Update(func(s *APIKeyUpsert) {
- s.SetRateLimit7d(v)
- })
- }
- // AddRateLimit7d adds v to the "rate_limit_7d" field.
- func (u *APIKeyUpsertBulk) AddRateLimit7d(v float64) *APIKeyUpsertBulk {
- return u.Update(func(s *APIKeyUpsert) {
- s.AddRateLimit7d(v)
- })
- }
- // UpdateRateLimit7d sets the "rate_limit_7d" field to the value that was provided on create.
- func (u *APIKeyUpsertBulk) UpdateRateLimit7d() *APIKeyUpsertBulk {
- return u.Update(func(s *APIKeyUpsert) {
- s.UpdateRateLimit7d()
- })
- }
- // SetUsage5h sets the "usage_5h" field.
- func (u *APIKeyUpsertBulk) SetUsage5h(v float64) *APIKeyUpsertBulk {
- return u.Update(func(s *APIKeyUpsert) {
- s.SetUsage5h(v)
- })
- }
- // AddUsage5h adds v to the "usage_5h" field.
- func (u *APIKeyUpsertBulk) AddUsage5h(v float64) *APIKeyUpsertBulk {
- return u.Update(func(s *APIKeyUpsert) {
- s.AddUsage5h(v)
- })
- }
- // UpdateUsage5h sets the "usage_5h" field to the value that was provided on create.
- func (u *APIKeyUpsertBulk) UpdateUsage5h() *APIKeyUpsertBulk {
- return u.Update(func(s *APIKeyUpsert) {
- s.UpdateUsage5h()
- })
- }
- // SetUsage1d sets the "usage_1d" field.
- func (u *APIKeyUpsertBulk) SetUsage1d(v float64) *APIKeyUpsertBulk {
- return u.Update(func(s *APIKeyUpsert) {
- s.SetUsage1d(v)
- })
- }
- // AddUsage1d adds v to the "usage_1d" field.
- func (u *APIKeyUpsertBulk) AddUsage1d(v float64) *APIKeyUpsertBulk {
- return u.Update(func(s *APIKeyUpsert) {
- s.AddUsage1d(v)
- })
- }
- // UpdateUsage1d sets the "usage_1d" field to the value that was provided on create.
- func (u *APIKeyUpsertBulk) UpdateUsage1d() *APIKeyUpsertBulk {
- return u.Update(func(s *APIKeyUpsert) {
- s.UpdateUsage1d()
- })
- }
- // SetUsage7d sets the "usage_7d" field.
- func (u *APIKeyUpsertBulk) SetUsage7d(v float64) *APIKeyUpsertBulk {
- return u.Update(func(s *APIKeyUpsert) {
- s.SetUsage7d(v)
- })
- }
- // AddUsage7d adds v to the "usage_7d" field.
- func (u *APIKeyUpsertBulk) AddUsage7d(v float64) *APIKeyUpsertBulk {
- return u.Update(func(s *APIKeyUpsert) {
- s.AddUsage7d(v)
- })
- }
- // UpdateUsage7d sets the "usage_7d" field to the value that was provided on create.
- func (u *APIKeyUpsertBulk) UpdateUsage7d() *APIKeyUpsertBulk {
- return u.Update(func(s *APIKeyUpsert) {
- s.UpdateUsage7d()
- })
- }
- // SetWindow5hStart sets the "window_5h_start" field.
- func (u *APIKeyUpsertBulk) SetWindow5hStart(v time.Time) *APIKeyUpsertBulk {
- return u.Update(func(s *APIKeyUpsert) {
- s.SetWindow5hStart(v)
- })
- }
- // UpdateWindow5hStart sets the "window_5h_start" field to the value that was provided on create.
- func (u *APIKeyUpsertBulk) UpdateWindow5hStart() *APIKeyUpsertBulk {
- return u.Update(func(s *APIKeyUpsert) {
- s.UpdateWindow5hStart()
- })
- }
- // ClearWindow5hStart clears the value of the "window_5h_start" field.
- func (u *APIKeyUpsertBulk) ClearWindow5hStart() *APIKeyUpsertBulk {
- return u.Update(func(s *APIKeyUpsert) {
- s.ClearWindow5hStart()
- })
- }
- // SetWindow1dStart sets the "window_1d_start" field.
- func (u *APIKeyUpsertBulk) SetWindow1dStart(v time.Time) *APIKeyUpsertBulk {
- return u.Update(func(s *APIKeyUpsert) {
- s.SetWindow1dStart(v)
- })
- }
- // UpdateWindow1dStart sets the "window_1d_start" field to the value that was provided on create.
- func (u *APIKeyUpsertBulk) UpdateWindow1dStart() *APIKeyUpsertBulk {
- return u.Update(func(s *APIKeyUpsert) {
- s.UpdateWindow1dStart()
- })
- }
- // ClearWindow1dStart clears the value of the "window_1d_start" field.
- func (u *APIKeyUpsertBulk) ClearWindow1dStart() *APIKeyUpsertBulk {
- return u.Update(func(s *APIKeyUpsert) {
- s.ClearWindow1dStart()
- })
- }
- // SetWindow7dStart sets the "window_7d_start" field.
- func (u *APIKeyUpsertBulk) SetWindow7dStart(v time.Time) *APIKeyUpsertBulk {
- return u.Update(func(s *APIKeyUpsert) {
- s.SetWindow7dStart(v)
- })
- }
- // UpdateWindow7dStart sets the "window_7d_start" field to the value that was provided on create.
- func (u *APIKeyUpsertBulk) UpdateWindow7dStart() *APIKeyUpsertBulk {
- return u.Update(func(s *APIKeyUpsert) {
- s.UpdateWindow7dStart()
- })
- }
- // ClearWindow7dStart clears the value of the "window_7d_start" field.
- func (u *APIKeyUpsertBulk) ClearWindow7dStart() *APIKeyUpsertBulk {
- return u.Update(func(s *APIKeyUpsert) {
- s.ClearWindow7dStart()
- })
- }
- // Exec executes the query.
- func (u *APIKeyUpsertBulk) Exec(ctx context.Context) error {
- if u.create.err != nil {
- return u.create.err
- }
- for i, b := range u.create.builders {
- if len(b.conflict) != 0 {
- return fmt.Errorf("ent: OnConflict was set for builder %d. Set it on the APIKeyCreateBulk instead", i)
- }
- }
- if len(u.create.conflict) == 0 {
- return errors.New("ent: missing options for APIKeyCreateBulk.OnConflict")
- }
- return u.create.Exec(ctx)
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (u *APIKeyUpsertBulk) ExecX(ctx context.Context) {
- if err := u.create.Exec(ctx); err != nil {
- panic(err)
- }
- }
|