From 20b03b3f6d5bfa5aaceab4b059348b4f5bcb4dd4 Mon Sep 17 00:00:00 2001 From: Mark Sagi-Kazar Date: Mon, 7 Mar 2022 10:15:01 +0100 Subject: [PATCH] feat: update generated storage files Signed-off-by: Mark Sagi-Kazar --- storage/ent/db/authcode_create.go | 47 +- storage/ent/db/authcode_query.go | 20 +- storage/ent/db/authcode_update.go | 31 +- storage/ent/db/authrequest_create.go | 39 +- storage/ent/db/authrequest_query.go | 20 +- storage/ent/db/authrequest_update.go | 3 +- storage/ent/db/client.go | 1 + storage/ent/db/connector_create.go | 21 +- storage/ent/db/connector_query.go | 20 +- storage/ent/db/connector_update.go | 11 +- storage/ent/db/devicerequest_create.go | 18 +- storage/ent/db/devicerequest_query.go | 20 +- storage/ent/db/devicerequest_update.go | 19 +- storage/ent/db/devicetoken_create.go | 14 +- storage/ent/db/devicetoken_query.go | 20 +- storage/ent/db/devicetoken_update.go | 11 +- storage/ent/db/ent.go | 2 +- storage/ent/db/keys_create.go | 17 +- storage/ent/db/keys_query.go | 20 +- storage/ent/db/keys_update.go | 3 +- storage/ent/db/migrate/migrate.go | 3 +- storage/ent/db/mutation.go | 563 ++++++++++++++++-------- storage/ent/db/oauth2client_create.go | 23 +- storage/ent/db/oauth2client_query.go | 20 +- storage/ent/db/oauth2client_update.go | 15 +- storage/ent/db/offlinesession_create.go | 19 +- storage/ent/db/offlinesession_query.go | 20 +- storage/ent/db/offlinesession_update.go | 11 +- storage/ent/db/password_create.go | 14 +- storage/ent/db/password_query.go | 20 +- storage/ent/db/password_update.go | 15 +- storage/ent/db/refreshtoken_create.go | 45 +- storage/ent/db/refreshtoken_query.go | 20 +- storage/ent/db/refreshtoken_update.go | 27 +- storage/ent/db/runtime/runtime.go | 4 +- storage/ent/db/tx.go | 8 +- 36 files changed, 747 insertions(+), 437 deletions(-) diff --git a/storage/ent/db/authcode_create.go b/storage/ent/db/authcode_create.go index eaf2f8ac..23b34300 100644 --- a/storage/ent/db/authcode_create.go +++ b/storage/ent/db/authcode_create.go @@ -228,79 +228,79 @@ func (acc *AuthCodeCreate) defaults() { // check runs all checks and user-defined validators on the builder. func (acc *AuthCodeCreate) check() error { if _, ok := acc.mutation.ClientID(); !ok { - return &ValidationError{Name: "client_id", err: errors.New(`db: missing required field "client_id"`)} + return &ValidationError{Name: "client_id", err: errors.New(`db: missing required field "AuthCode.client_id"`)} } if v, ok := acc.mutation.ClientID(); ok { if err := authcode.ClientIDValidator(v); err != nil { - return &ValidationError{Name: "client_id", err: fmt.Errorf(`db: validator failed for field "client_id": %w`, err)} + return &ValidationError{Name: "client_id", err: fmt.Errorf(`db: validator failed for field "AuthCode.client_id": %w`, err)} } } if _, ok := acc.mutation.Nonce(); !ok { - return &ValidationError{Name: "nonce", err: errors.New(`db: missing required field "nonce"`)} + return &ValidationError{Name: "nonce", err: errors.New(`db: missing required field "AuthCode.nonce"`)} } if v, ok := acc.mutation.Nonce(); ok { if err := authcode.NonceValidator(v); err != nil { - return &ValidationError{Name: "nonce", err: fmt.Errorf(`db: validator failed for field "nonce": %w`, err)} + return &ValidationError{Name: "nonce", err: fmt.Errorf(`db: validator failed for field "AuthCode.nonce": %w`, err)} } } if _, ok := acc.mutation.RedirectURI(); !ok { - return &ValidationError{Name: "redirect_uri", err: errors.New(`db: missing required field "redirect_uri"`)} + return &ValidationError{Name: "redirect_uri", err: errors.New(`db: missing required field "AuthCode.redirect_uri"`)} } if v, ok := acc.mutation.RedirectURI(); ok { if err := authcode.RedirectURIValidator(v); err != nil { - return &ValidationError{Name: "redirect_uri", err: fmt.Errorf(`db: validator failed for field "redirect_uri": %w`, err)} + return &ValidationError{Name: "redirect_uri", err: fmt.Errorf(`db: validator failed for field "AuthCode.redirect_uri": %w`, err)} } } if _, ok := acc.mutation.ClaimsUserID(); !ok { - return &ValidationError{Name: "claims_user_id", err: errors.New(`db: missing required field "claims_user_id"`)} + return &ValidationError{Name: "claims_user_id", err: errors.New(`db: missing required field "AuthCode.claims_user_id"`)} } if v, ok := acc.mutation.ClaimsUserID(); ok { if err := authcode.ClaimsUserIDValidator(v); err != nil { - return &ValidationError{Name: "claims_user_id", err: fmt.Errorf(`db: validator failed for field "claims_user_id": %w`, err)} + return &ValidationError{Name: "claims_user_id", err: fmt.Errorf(`db: validator failed for field "AuthCode.claims_user_id": %w`, err)} } } if _, ok := acc.mutation.ClaimsUsername(); !ok { - return &ValidationError{Name: "claims_username", err: errors.New(`db: missing required field "claims_username"`)} + return &ValidationError{Name: "claims_username", err: errors.New(`db: missing required field "AuthCode.claims_username"`)} } if v, ok := acc.mutation.ClaimsUsername(); ok { if err := authcode.ClaimsUsernameValidator(v); err != nil { - return &ValidationError{Name: "claims_username", err: fmt.Errorf(`db: validator failed for field "claims_username": %w`, err)} + return &ValidationError{Name: "claims_username", err: fmt.Errorf(`db: validator failed for field "AuthCode.claims_username": %w`, err)} } } if _, ok := acc.mutation.ClaimsEmail(); !ok { - return &ValidationError{Name: "claims_email", err: errors.New(`db: missing required field "claims_email"`)} + return &ValidationError{Name: "claims_email", err: errors.New(`db: missing required field "AuthCode.claims_email"`)} } if v, ok := acc.mutation.ClaimsEmail(); ok { if err := authcode.ClaimsEmailValidator(v); err != nil { - return &ValidationError{Name: "claims_email", err: fmt.Errorf(`db: validator failed for field "claims_email": %w`, err)} + return &ValidationError{Name: "claims_email", err: fmt.Errorf(`db: validator failed for field "AuthCode.claims_email": %w`, err)} } } if _, ok := acc.mutation.ClaimsEmailVerified(); !ok { - return &ValidationError{Name: "claims_email_verified", err: errors.New(`db: missing required field "claims_email_verified"`)} + return &ValidationError{Name: "claims_email_verified", err: errors.New(`db: missing required field "AuthCode.claims_email_verified"`)} } if _, ok := acc.mutation.ClaimsPreferredUsername(); !ok { - return &ValidationError{Name: "claims_preferred_username", err: errors.New(`db: missing required field "claims_preferred_username"`)} + return &ValidationError{Name: "claims_preferred_username", err: errors.New(`db: missing required field "AuthCode.claims_preferred_username"`)} } if _, ok := acc.mutation.ConnectorID(); !ok { - return &ValidationError{Name: "connector_id", err: errors.New(`db: missing required field "connector_id"`)} + return &ValidationError{Name: "connector_id", err: errors.New(`db: missing required field "AuthCode.connector_id"`)} } if v, ok := acc.mutation.ConnectorID(); ok { if err := authcode.ConnectorIDValidator(v); err != nil { - return &ValidationError{Name: "connector_id", err: fmt.Errorf(`db: validator failed for field "connector_id": %w`, err)} + return &ValidationError{Name: "connector_id", err: fmt.Errorf(`db: validator failed for field "AuthCode.connector_id": %w`, err)} } } if _, ok := acc.mutation.Expiry(); !ok { - return &ValidationError{Name: "expiry", err: errors.New(`db: missing required field "expiry"`)} + return &ValidationError{Name: "expiry", err: errors.New(`db: missing required field "AuthCode.expiry"`)} } if _, ok := acc.mutation.CodeChallenge(); !ok { - return &ValidationError{Name: "code_challenge", err: errors.New(`db: missing required field "code_challenge"`)} + return &ValidationError{Name: "code_challenge", err: errors.New(`db: missing required field "AuthCode.code_challenge"`)} } if _, ok := acc.mutation.CodeChallengeMethod(); !ok { - return &ValidationError{Name: "code_challenge_method", err: errors.New(`db: missing required field "code_challenge_method"`)} + return &ValidationError{Name: "code_challenge_method", err: errors.New(`db: missing required field "AuthCode.code_challenge_method"`)} } if v, ok := acc.mutation.ID(); ok { if err := authcode.IDValidator(v); err != nil { - return &ValidationError{Name: "id", err: fmt.Errorf(`db: validator failed for field "id": %w`, err)} + return &ValidationError{Name: "id", err: fmt.Errorf(`db: validator failed for field "AuthCode.id": %w`, err)} } } return nil @@ -314,6 +314,13 @@ func (acc *AuthCodeCreate) sqlSave(ctx context.Context) (*AuthCode, error) { } return nil, err } + if _spec.ID.Value != nil { + if id, ok := _spec.ID.Value.(string); ok { + _node.ID = id + } else { + return nil, fmt.Errorf("unexpected AuthCode.ID type: %T", _spec.ID.Value) + } + } return _node, nil } diff --git a/storage/ent/db/authcode_query.go b/storage/ent/db/authcode_query.go index 89116dd9..452b9847 100644 --- a/storage/ent/db/authcode_query.go +++ b/storage/ent/db/authcode_query.go @@ -106,7 +106,7 @@ func (acq *AuthCodeQuery) FirstIDX(ctx context.Context) string { } // Only returns a single AuthCode entity found by the query, ensuring it only returns one. -// Returns a *NotSingularError when exactly one AuthCode entity is not found. +// Returns a *NotSingularError when more than one AuthCode entity is found. // Returns a *NotFoundError when no AuthCode entities are found. func (acq *AuthCodeQuery) Only(ctx context.Context) (*AuthCode, error) { nodes, err := acq.Limit(2).All(ctx) @@ -133,7 +133,7 @@ func (acq *AuthCodeQuery) OnlyX(ctx context.Context) *AuthCode { } // OnlyID is like Only, but returns the only AuthCode ID in the query. -// Returns a *NotSingularError when exactly one AuthCode ID is not found. +// Returns a *NotSingularError when more than one AuthCode ID is found. // Returns a *NotFoundError when no entities are found. func (acq *AuthCodeQuery) OnlyID(ctx context.Context) (id string, err error) { var ids []string @@ -242,8 +242,9 @@ func (acq *AuthCodeQuery) Clone() *AuthCodeQuery { order: append([]OrderFunc{}, acq.order...), predicates: append([]predicate.AuthCode{}, acq.predicates...), // clone intermediate query. - sql: acq.sql.Clone(), - path: acq.path, + sql: acq.sql.Clone(), + path: acq.path, + unique: acq.unique, } } @@ -336,6 +337,10 @@ func (acq *AuthCodeQuery) sqlAll(ctx context.Context) ([]*AuthCode, error) { func (acq *AuthCodeQuery) sqlCount(ctx context.Context) (int, error) { _spec := acq.querySpec() + _spec.Node.Columns = acq.fields + if len(acq.fields) > 0 { + _spec.Unique = acq.unique != nil && *acq.unique + } return sqlgraph.CountNodes(ctx, acq.driver, _spec) } @@ -407,6 +412,9 @@ func (acq *AuthCodeQuery) sqlQuery(ctx context.Context) *sql.Selector { selector = acq.sql selector.Select(selector.Columns(columns...)...) } + if acq.unique != nil && *acq.unique { + selector.Distinct() + } for _, p := range acq.predicates { p(selector) } @@ -685,9 +693,7 @@ func (acgb *AuthCodeGroupBy) sqlQuery() *sql.Selector { for _, f := range acgb.fields { columns = append(columns, selector.C(f)) } - for _, c := range aggregation { - columns = append(columns, c) - } + columns = append(columns, aggregation...) selector.Select(columns...) } return selector.GroupBy(selector.Columns(acgb.fields...)...) diff --git a/storage/ent/db/authcode_update.go b/storage/ent/db/authcode_update.go index f86d04c6..ccd0eee8 100644 --- a/storage/ent/db/authcode_update.go +++ b/storage/ent/db/authcode_update.go @@ -4,6 +4,7 @@ package db import ( "context" + "errors" "fmt" "time" @@ -228,37 +229,37 @@ func (acu *AuthCodeUpdate) ExecX(ctx context.Context) { func (acu *AuthCodeUpdate) check() error { if v, ok := acu.mutation.ClientID(); ok { if err := authcode.ClientIDValidator(v); err != nil { - return &ValidationError{Name: "client_id", err: fmt.Errorf("db: validator failed for field \"client_id\": %w", err)} + return &ValidationError{Name: "client_id", err: fmt.Errorf(`db: validator failed for field "AuthCode.client_id": %w`, err)} } } if v, ok := acu.mutation.Nonce(); ok { if err := authcode.NonceValidator(v); err != nil { - return &ValidationError{Name: "nonce", err: fmt.Errorf("db: validator failed for field \"nonce\": %w", err)} + return &ValidationError{Name: "nonce", err: fmt.Errorf(`db: validator failed for field "AuthCode.nonce": %w`, err)} } } if v, ok := acu.mutation.RedirectURI(); ok { if err := authcode.RedirectURIValidator(v); err != nil { - return &ValidationError{Name: "redirect_uri", err: fmt.Errorf("db: validator failed for field \"redirect_uri\": %w", err)} + return &ValidationError{Name: "redirect_uri", err: fmt.Errorf(`db: validator failed for field "AuthCode.redirect_uri": %w`, err)} } } if v, ok := acu.mutation.ClaimsUserID(); ok { if err := authcode.ClaimsUserIDValidator(v); err != nil { - return &ValidationError{Name: "claims_user_id", err: fmt.Errorf("db: validator failed for field \"claims_user_id\": %w", err)} + return &ValidationError{Name: "claims_user_id", err: fmt.Errorf(`db: validator failed for field "AuthCode.claims_user_id": %w`, err)} } } if v, ok := acu.mutation.ClaimsUsername(); ok { if err := authcode.ClaimsUsernameValidator(v); err != nil { - return &ValidationError{Name: "claims_username", err: fmt.Errorf("db: validator failed for field \"claims_username\": %w", err)} + return &ValidationError{Name: "claims_username", err: fmt.Errorf(`db: validator failed for field "AuthCode.claims_username": %w`, err)} } } if v, ok := acu.mutation.ClaimsEmail(); ok { if err := authcode.ClaimsEmailValidator(v); err != nil { - return &ValidationError{Name: "claims_email", err: fmt.Errorf("db: validator failed for field \"claims_email\": %w", err)} + return &ValidationError{Name: "claims_email", err: fmt.Errorf(`db: validator failed for field "AuthCode.claims_email": %w`, err)} } } if v, ok := acu.mutation.ConnectorID(); ok { if err := authcode.ConnectorIDValidator(v); err != nil { - return &ValidationError{Name: "connector_id", err: fmt.Errorf("db: validator failed for field \"connector_id\": %w", err)} + return &ValidationError{Name: "connector_id", err: fmt.Errorf(`db: validator failed for field "AuthCode.connector_id": %w`, err)} } } return nil @@ -632,37 +633,37 @@ func (acuo *AuthCodeUpdateOne) ExecX(ctx context.Context) { func (acuo *AuthCodeUpdateOne) check() error { if v, ok := acuo.mutation.ClientID(); ok { if err := authcode.ClientIDValidator(v); err != nil { - return &ValidationError{Name: "client_id", err: fmt.Errorf("db: validator failed for field \"client_id\": %w", err)} + return &ValidationError{Name: "client_id", err: fmt.Errorf(`db: validator failed for field "AuthCode.client_id": %w`, err)} } } if v, ok := acuo.mutation.Nonce(); ok { if err := authcode.NonceValidator(v); err != nil { - return &ValidationError{Name: "nonce", err: fmt.Errorf("db: validator failed for field \"nonce\": %w", err)} + return &ValidationError{Name: "nonce", err: fmt.Errorf(`db: validator failed for field "AuthCode.nonce": %w`, err)} } } if v, ok := acuo.mutation.RedirectURI(); ok { if err := authcode.RedirectURIValidator(v); err != nil { - return &ValidationError{Name: "redirect_uri", err: fmt.Errorf("db: validator failed for field \"redirect_uri\": %w", err)} + return &ValidationError{Name: "redirect_uri", err: fmt.Errorf(`db: validator failed for field "AuthCode.redirect_uri": %w`, err)} } } if v, ok := acuo.mutation.ClaimsUserID(); ok { if err := authcode.ClaimsUserIDValidator(v); err != nil { - return &ValidationError{Name: "claims_user_id", err: fmt.Errorf("db: validator failed for field \"claims_user_id\": %w", err)} + return &ValidationError{Name: "claims_user_id", err: fmt.Errorf(`db: validator failed for field "AuthCode.claims_user_id": %w`, err)} } } if v, ok := acuo.mutation.ClaimsUsername(); ok { if err := authcode.ClaimsUsernameValidator(v); err != nil { - return &ValidationError{Name: "claims_username", err: fmt.Errorf("db: validator failed for field \"claims_username\": %w", err)} + return &ValidationError{Name: "claims_username", err: fmt.Errorf(`db: validator failed for field "AuthCode.claims_username": %w`, err)} } } if v, ok := acuo.mutation.ClaimsEmail(); ok { if err := authcode.ClaimsEmailValidator(v); err != nil { - return &ValidationError{Name: "claims_email", err: fmt.Errorf("db: validator failed for field \"claims_email\": %w", err)} + return &ValidationError{Name: "claims_email", err: fmt.Errorf(`db: validator failed for field "AuthCode.claims_email": %w`, err)} } } if v, ok := acuo.mutation.ConnectorID(); ok { if err := authcode.ConnectorIDValidator(v); err != nil { - return &ValidationError{Name: "connector_id", err: fmt.Errorf("db: validator failed for field \"connector_id\": %w", err)} + return &ValidationError{Name: "connector_id", err: fmt.Errorf(`db: validator failed for field "AuthCode.connector_id": %w`, err)} } } return nil @@ -681,7 +682,7 @@ func (acuo *AuthCodeUpdateOne) sqlSave(ctx context.Context) (_node *AuthCode, er } id, ok := acuo.mutation.ID() if !ok { - return nil, &ValidationError{Name: "ID", err: fmt.Errorf("missing AuthCode.ID for update")} + return nil, &ValidationError{Name: "id", err: errors.New(`db: missing "AuthCode.id" for update`)} } _spec.Node.ID.Value = id if fields := acuo.fields; len(fields) > 0 { diff --git a/storage/ent/db/authrequest_create.go b/storage/ent/db/authrequest_create.go index 3e96b284..f324c159 100644 --- a/storage/ent/db/authrequest_create.go +++ b/storage/ent/db/authrequest_create.go @@ -252,53 +252,53 @@ func (arc *AuthRequestCreate) defaults() { // check runs all checks and user-defined validators on the builder. func (arc *AuthRequestCreate) check() error { if _, ok := arc.mutation.ClientID(); !ok { - return &ValidationError{Name: "client_id", err: errors.New(`db: missing required field "client_id"`)} + return &ValidationError{Name: "client_id", err: errors.New(`db: missing required field "AuthRequest.client_id"`)} } if _, ok := arc.mutation.RedirectURI(); !ok { - return &ValidationError{Name: "redirect_uri", err: errors.New(`db: missing required field "redirect_uri"`)} + return &ValidationError{Name: "redirect_uri", err: errors.New(`db: missing required field "AuthRequest.redirect_uri"`)} } if _, ok := arc.mutation.Nonce(); !ok { - return &ValidationError{Name: "nonce", err: errors.New(`db: missing required field "nonce"`)} + return &ValidationError{Name: "nonce", err: errors.New(`db: missing required field "AuthRequest.nonce"`)} } if _, ok := arc.mutation.State(); !ok { - return &ValidationError{Name: "state", err: errors.New(`db: missing required field "state"`)} + return &ValidationError{Name: "state", err: errors.New(`db: missing required field "AuthRequest.state"`)} } if _, ok := arc.mutation.ForceApprovalPrompt(); !ok { - return &ValidationError{Name: "force_approval_prompt", err: errors.New(`db: missing required field "force_approval_prompt"`)} + return &ValidationError{Name: "force_approval_prompt", err: errors.New(`db: missing required field "AuthRequest.force_approval_prompt"`)} } if _, ok := arc.mutation.LoggedIn(); !ok { - return &ValidationError{Name: "logged_in", err: errors.New(`db: missing required field "logged_in"`)} + return &ValidationError{Name: "logged_in", err: errors.New(`db: missing required field "AuthRequest.logged_in"`)} } if _, ok := arc.mutation.ClaimsUserID(); !ok { - return &ValidationError{Name: "claims_user_id", err: errors.New(`db: missing required field "claims_user_id"`)} + return &ValidationError{Name: "claims_user_id", err: errors.New(`db: missing required field "AuthRequest.claims_user_id"`)} } if _, ok := arc.mutation.ClaimsUsername(); !ok { - return &ValidationError{Name: "claims_username", err: errors.New(`db: missing required field "claims_username"`)} + return &ValidationError{Name: "claims_username", err: errors.New(`db: missing required field "AuthRequest.claims_username"`)} } if _, ok := arc.mutation.ClaimsEmail(); !ok { - return &ValidationError{Name: "claims_email", err: errors.New(`db: missing required field "claims_email"`)} + return &ValidationError{Name: "claims_email", err: errors.New(`db: missing required field "AuthRequest.claims_email"`)} } if _, ok := arc.mutation.ClaimsEmailVerified(); !ok { - return &ValidationError{Name: "claims_email_verified", err: errors.New(`db: missing required field "claims_email_verified"`)} + return &ValidationError{Name: "claims_email_verified", err: errors.New(`db: missing required field "AuthRequest.claims_email_verified"`)} } if _, ok := arc.mutation.ClaimsPreferredUsername(); !ok { - return &ValidationError{Name: "claims_preferred_username", err: errors.New(`db: missing required field "claims_preferred_username"`)} + return &ValidationError{Name: "claims_preferred_username", err: errors.New(`db: missing required field "AuthRequest.claims_preferred_username"`)} } if _, ok := arc.mutation.ConnectorID(); !ok { - return &ValidationError{Name: "connector_id", err: errors.New(`db: missing required field "connector_id"`)} + return &ValidationError{Name: "connector_id", err: errors.New(`db: missing required field "AuthRequest.connector_id"`)} } if _, ok := arc.mutation.Expiry(); !ok { - return &ValidationError{Name: "expiry", err: errors.New(`db: missing required field "expiry"`)} + return &ValidationError{Name: "expiry", err: errors.New(`db: missing required field "AuthRequest.expiry"`)} } if _, ok := arc.mutation.CodeChallenge(); !ok { - return &ValidationError{Name: "code_challenge", err: errors.New(`db: missing required field "code_challenge"`)} + return &ValidationError{Name: "code_challenge", err: errors.New(`db: missing required field "AuthRequest.code_challenge"`)} } if _, ok := arc.mutation.CodeChallengeMethod(); !ok { - return &ValidationError{Name: "code_challenge_method", err: errors.New(`db: missing required field "code_challenge_method"`)} + return &ValidationError{Name: "code_challenge_method", err: errors.New(`db: missing required field "AuthRequest.code_challenge_method"`)} } if v, ok := arc.mutation.ID(); ok { if err := authrequest.IDValidator(v); err != nil { - return &ValidationError{Name: "id", err: fmt.Errorf(`db: validator failed for field "id": %w`, err)} + return &ValidationError{Name: "id", err: fmt.Errorf(`db: validator failed for field "AuthRequest.id": %w`, err)} } } return nil @@ -312,6 +312,13 @@ func (arc *AuthRequestCreate) sqlSave(ctx context.Context) (*AuthRequest, error) } return nil, err } + if _spec.ID.Value != nil { + if id, ok := _spec.ID.Value.(string); ok { + _node.ID = id + } else { + return nil, fmt.Errorf("unexpected AuthRequest.ID type: %T", _spec.ID.Value) + } + } return _node, nil } diff --git a/storage/ent/db/authrequest_query.go b/storage/ent/db/authrequest_query.go index e71f8546..236b684b 100644 --- a/storage/ent/db/authrequest_query.go +++ b/storage/ent/db/authrequest_query.go @@ -106,7 +106,7 @@ func (arq *AuthRequestQuery) FirstIDX(ctx context.Context) string { } // Only returns a single AuthRequest entity found by the query, ensuring it only returns one. -// Returns a *NotSingularError when exactly one AuthRequest entity is not found. +// Returns a *NotSingularError when more than one AuthRequest entity is found. // Returns a *NotFoundError when no AuthRequest entities are found. func (arq *AuthRequestQuery) Only(ctx context.Context) (*AuthRequest, error) { nodes, err := arq.Limit(2).All(ctx) @@ -133,7 +133,7 @@ func (arq *AuthRequestQuery) OnlyX(ctx context.Context) *AuthRequest { } // OnlyID is like Only, but returns the only AuthRequest ID in the query. -// Returns a *NotSingularError when exactly one AuthRequest ID is not found. +// Returns a *NotSingularError when more than one AuthRequest ID is found. // Returns a *NotFoundError when no entities are found. func (arq *AuthRequestQuery) OnlyID(ctx context.Context) (id string, err error) { var ids []string @@ -242,8 +242,9 @@ func (arq *AuthRequestQuery) Clone() *AuthRequestQuery { order: append([]OrderFunc{}, arq.order...), predicates: append([]predicate.AuthRequest{}, arq.predicates...), // clone intermediate query. - sql: arq.sql.Clone(), - path: arq.path, + sql: arq.sql.Clone(), + path: arq.path, + unique: arq.unique, } } @@ -336,6 +337,10 @@ func (arq *AuthRequestQuery) sqlAll(ctx context.Context) ([]*AuthRequest, error) func (arq *AuthRequestQuery) sqlCount(ctx context.Context) (int, error) { _spec := arq.querySpec() + _spec.Node.Columns = arq.fields + if len(arq.fields) > 0 { + _spec.Unique = arq.unique != nil && *arq.unique + } return sqlgraph.CountNodes(ctx, arq.driver, _spec) } @@ -407,6 +412,9 @@ func (arq *AuthRequestQuery) sqlQuery(ctx context.Context) *sql.Selector { selector = arq.sql selector.Select(selector.Columns(columns...)...) } + if arq.unique != nil && *arq.unique { + selector.Distinct() + } for _, p := range arq.predicates { p(selector) } @@ -685,9 +693,7 @@ func (argb *AuthRequestGroupBy) sqlQuery() *sql.Selector { for _, f := range argb.fields { columns = append(columns, selector.C(f)) } - for _, c := range aggregation { - columns = append(columns, c) - } + columns = append(columns, aggregation...) selector.Select(columns...) } return selector.GroupBy(selector.Columns(argb.fields...)...) diff --git a/storage/ent/db/authrequest_update.go b/storage/ent/db/authrequest_update.go index 2306d2e6..bc476c08 100644 --- a/storage/ent/db/authrequest_update.go +++ b/storage/ent/db/authrequest_update.go @@ -4,6 +4,7 @@ package db import ( "context" + "errors" "fmt" "time" @@ -683,7 +684,7 @@ func (aruo *AuthRequestUpdateOne) sqlSave(ctx context.Context) (_node *AuthReque } id, ok := aruo.mutation.ID() if !ok { - return nil, &ValidationError{Name: "ID", err: fmt.Errorf("missing AuthRequest.ID for update")} + return nil, &ValidationError{Name: "id", err: errors.New(`db: missing "AuthRequest.id" for update`)} } _spec.Node.ID.Value = id if fields := aruo.fields; len(fields) > 0 { diff --git a/storage/ent/db/client.go b/storage/ent/db/client.go index a27286a0..7a8e7ede 100644 --- a/storage/ent/db/client.go +++ b/storage/ent/db/client.go @@ -132,6 +132,7 @@ func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error) cfg := c.config cfg.driver = &txDriver{tx: tx, drv: c.driver} return &Tx{ + ctx: ctx, config: cfg, AuthCode: NewAuthCodeClient(cfg), AuthRequest: NewAuthRequestClient(cfg), diff --git a/storage/ent/db/connector_create.go b/storage/ent/db/connector_create.go index 387231b9..b3836019 100644 --- a/storage/ent/db/connector_create.go +++ b/storage/ent/db/connector_create.go @@ -120,30 +120,30 @@ func (cc *ConnectorCreate) ExecX(ctx context.Context) { // check runs all checks and user-defined validators on the builder. func (cc *ConnectorCreate) check() error { if _, ok := cc.mutation.GetType(); !ok { - return &ValidationError{Name: "type", err: errors.New(`db: missing required field "type"`)} + return &ValidationError{Name: "type", err: errors.New(`db: missing required field "Connector.type"`)} } if v, ok := cc.mutation.GetType(); ok { if err := connector.TypeValidator(v); err != nil { - return &ValidationError{Name: "type", err: fmt.Errorf(`db: validator failed for field "type": %w`, err)} + return &ValidationError{Name: "type", err: fmt.Errorf(`db: validator failed for field "Connector.type": %w`, err)} } } if _, ok := cc.mutation.Name(); !ok { - return &ValidationError{Name: "name", err: errors.New(`db: missing required field "name"`)} + return &ValidationError{Name: "name", err: errors.New(`db: missing required field "Connector.name"`)} } if v, ok := cc.mutation.Name(); ok { if err := connector.NameValidator(v); err != nil { - return &ValidationError{Name: "name", err: fmt.Errorf(`db: validator failed for field "name": %w`, err)} + return &ValidationError{Name: "name", err: fmt.Errorf(`db: validator failed for field "Connector.name": %w`, err)} } } if _, ok := cc.mutation.ResourceVersion(); !ok { - return &ValidationError{Name: "resource_version", err: errors.New(`db: missing required field "resource_version"`)} + return &ValidationError{Name: "resource_version", err: errors.New(`db: missing required field "Connector.resource_version"`)} } if _, ok := cc.mutation.Config(); !ok { - return &ValidationError{Name: "config", err: errors.New(`db: missing required field "config"`)} + return &ValidationError{Name: "config", err: errors.New(`db: missing required field "Connector.config"`)} } if v, ok := cc.mutation.ID(); ok { if err := connector.IDValidator(v); err != nil { - return &ValidationError{Name: "id", err: fmt.Errorf(`db: validator failed for field "id": %w`, err)} + return &ValidationError{Name: "id", err: fmt.Errorf(`db: validator failed for field "Connector.id": %w`, err)} } } return nil @@ -157,6 +157,13 @@ func (cc *ConnectorCreate) sqlSave(ctx context.Context) (*Connector, error) { } return nil, err } + if _spec.ID.Value != nil { + if id, ok := _spec.ID.Value.(string); ok { + _node.ID = id + } else { + return nil, fmt.Errorf("unexpected Connector.ID type: %T", _spec.ID.Value) + } + } return _node, nil } diff --git a/storage/ent/db/connector_query.go b/storage/ent/db/connector_query.go index 9bcf368a..f79b4047 100644 --- a/storage/ent/db/connector_query.go +++ b/storage/ent/db/connector_query.go @@ -106,7 +106,7 @@ func (cq *ConnectorQuery) FirstIDX(ctx context.Context) string { } // Only returns a single Connector entity found by the query, ensuring it only returns one. -// Returns a *NotSingularError when exactly one Connector entity is not found. +// Returns a *NotSingularError when more than one Connector entity is found. // Returns a *NotFoundError when no Connector entities are found. func (cq *ConnectorQuery) Only(ctx context.Context) (*Connector, error) { nodes, err := cq.Limit(2).All(ctx) @@ -133,7 +133,7 @@ func (cq *ConnectorQuery) OnlyX(ctx context.Context) *Connector { } // OnlyID is like Only, but returns the only Connector ID in the query. -// Returns a *NotSingularError when exactly one Connector ID is not found. +// Returns a *NotSingularError when more than one Connector ID is found. // Returns a *NotFoundError when no entities are found. func (cq *ConnectorQuery) OnlyID(ctx context.Context) (id string, err error) { var ids []string @@ -242,8 +242,9 @@ func (cq *ConnectorQuery) Clone() *ConnectorQuery { order: append([]OrderFunc{}, cq.order...), predicates: append([]predicate.Connector{}, cq.predicates...), // clone intermediate query. - sql: cq.sql.Clone(), - path: cq.path, + sql: cq.sql.Clone(), + path: cq.path, + unique: cq.unique, } } @@ -336,6 +337,10 @@ func (cq *ConnectorQuery) sqlAll(ctx context.Context) ([]*Connector, error) { func (cq *ConnectorQuery) sqlCount(ctx context.Context) (int, error) { _spec := cq.querySpec() + _spec.Node.Columns = cq.fields + if len(cq.fields) > 0 { + _spec.Unique = cq.unique != nil && *cq.unique + } return sqlgraph.CountNodes(ctx, cq.driver, _spec) } @@ -407,6 +412,9 @@ func (cq *ConnectorQuery) sqlQuery(ctx context.Context) *sql.Selector { selector = cq.sql selector.Select(selector.Columns(columns...)...) } + if cq.unique != nil && *cq.unique { + selector.Distinct() + } for _, p := range cq.predicates { p(selector) } @@ -685,9 +693,7 @@ func (cgb *ConnectorGroupBy) sqlQuery() *sql.Selector { for _, f := range cgb.fields { columns = append(columns, selector.C(f)) } - for _, c := range aggregation { - columns = append(columns, c) - } + columns = append(columns, aggregation...) selector.Select(columns...) } return selector.GroupBy(selector.Columns(cgb.fields...)...) diff --git a/storage/ent/db/connector_update.go b/storage/ent/db/connector_update.go index 1bc9ffb5..b11c1aa5 100644 --- a/storage/ent/db/connector_update.go +++ b/storage/ent/db/connector_update.go @@ -4,6 +4,7 @@ package db import ( "context" + "errors" "fmt" "entgo.io/ent/dialect/sql" @@ -119,12 +120,12 @@ func (cu *ConnectorUpdate) ExecX(ctx context.Context) { func (cu *ConnectorUpdate) check() error { if v, ok := cu.mutation.GetType(); ok { if err := connector.TypeValidator(v); err != nil { - return &ValidationError{Name: "type", err: fmt.Errorf("db: validator failed for field \"type\": %w", err)} + return &ValidationError{Name: "type", err: fmt.Errorf(`db: validator failed for field "Connector.type": %w`, err)} } } if v, ok := cu.mutation.Name(); ok { if err := connector.NameValidator(v); err != nil { - return &ValidationError{Name: "name", err: fmt.Errorf("db: validator failed for field \"name\": %w", err)} + return &ValidationError{Name: "name", err: fmt.Errorf(`db: validator failed for field "Connector.name": %w`, err)} } } return nil @@ -295,12 +296,12 @@ func (cuo *ConnectorUpdateOne) ExecX(ctx context.Context) { func (cuo *ConnectorUpdateOne) check() error { if v, ok := cuo.mutation.GetType(); ok { if err := connector.TypeValidator(v); err != nil { - return &ValidationError{Name: "type", err: fmt.Errorf("db: validator failed for field \"type\": %w", err)} + return &ValidationError{Name: "type", err: fmt.Errorf(`db: validator failed for field "Connector.type": %w`, err)} } } if v, ok := cuo.mutation.Name(); ok { if err := connector.NameValidator(v); err != nil { - return &ValidationError{Name: "name", err: fmt.Errorf("db: validator failed for field \"name\": %w", err)} + return &ValidationError{Name: "name", err: fmt.Errorf(`db: validator failed for field "Connector.name": %w`, err)} } } return nil @@ -319,7 +320,7 @@ func (cuo *ConnectorUpdateOne) sqlSave(ctx context.Context) (_node *Connector, e } id, ok := cuo.mutation.ID() if !ok { - return nil, &ValidationError{Name: "ID", err: fmt.Errorf("missing Connector.ID for update")} + return nil, &ValidationError{Name: "id", err: errors.New(`db: missing "Connector.id" for update`)} } _spec.Node.ID.Value = id if fields := cuo.fields; len(fields) > 0 { diff --git a/storage/ent/db/devicerequest_create.go b/storage/ent/db/devicerequest_create.go index 102d028e..7600b47b 100644 --- a/storage/ent/db/devicerequest_create.go +++ b/storage/ent/db/devicerequest_create.go @@ -127,39 +127,39 @@ func (drc *DeviceRequestCreate) ExecX(ctx context.Context) { // check runs all checks and user-defined validators on the builder. func (drc *DeviceRequestCreate) check() error { if _, ok := drc.mutation.UserCode(); !ok { - return &ValidationError{Name: "user_code", err: errors.New(`db: missing required field "user_code"`)} + return &ValidationError{Name: "user_code", err: errors.New(`db: missing required field "DeviceRequest.user_code"`)} } if v, ok := drc.mutation.UserCode(); ok { if err := devicerequest.UserCodeValidator(v); err != nil { - return &ValidationError{Name: "user_code", err: fmt.Errorf(`db: validator failed for field "user_code": %w`, err)} + return &ValidationError{Name: "user_code", err: fmt.Errorf(`db: validator failed for field "DeviceRequest.user_code": %w`, err)} } } if _, ok := drc.mutation.DeviceCode(); !ok { - return &ValidationError{Name: "device_code", err: errors.New(`db: missing required field "device_code"`)} + return &ValidationError{Name: "device_code", err: errors.New(`db: missing required field "DeviceRequest.device_code"`)} } if v, ok := drc.mutation.DeviceCode(); ok { if err := devicerequest.DeviceCodeValidator(v); err != nil { - return &ValidationError{Name: "device_code", err: fmt.Errorf(`db: validator failed for field "device_code": %w`, err)} + return &ValidationError{Name: "device_code", err: fmt.Errorf(`db: validator failed for field "DeviceRequest.device_code": %w`, err)} } } if _, ok := drc.mutation.ClientID(); !ok { - return &ValidationError{Name: "client_id", err: errors.New(`db: missing required field "client_id"`)} + return &ValidationError{Name: "client_id", err: errors.New(`db: missing required field "DeviceRequest.client_id"`)} } if v, ok := drc.mutation.ClientID(); ok { if err := devicerequest.ClientIDValidator(v); err != nil { - return &ValidationError{Name: "client_id", err: fmt.Errorf(`db: validator failed for field "client_id": %w`, err)} + return &ValidationError{Name: "client_id", err: fmt.Errorf(`db: validator failed for field "DeviceRequest.client_id": %w`, err)} } } if _, ok := drc.mutation.ClientSecret(); !ok { - return &ValidationError{Name: "client_secret", err: errors.New(`db: missing required field "client_secret"`)} + return &ValidationError{Name: "client_secret", err: errors.New(`db: missing required field "DeviceRequest.client_secret"`)} } if v, ok := drc.mutation.ClientSecret(); ok { if err := devicerequest.ClientSecretValidator(v); err != nil { - return &ValidationError{Name: "client_secret", err: fmt.Errorf(`db: validator failed for field "client_secret": %w`, err)} + return &ValidationError{Name: "client_secret", err: fmt.Errorf(`db: validator failed for field "DeviceRequest.client_secret": %w`, err)} } } if _, ok := drc.mutation.Expiry(); !ok { - return &ValidationError{Name: "expiry", err: errors.New(`db: missing required field "expiry"`)} + return &ValidationError{Name: "expiry", err: errors.New(`db: missing required field "DeviceRequest.expiry"`)} } return nil } diff --git a/storage/ent/db/devicerequest_query.go b/storage/ent/db/devicerequest_query.go index 350b7ae6..f6839821 100644 --- a/storage/ent/db/devicerequest_query.go +++ b/storage/ent/db/devicerequest_query.go @@ -106,7 +106,7 @@ func (drq *DeviceRequestQuery) FirstIDX(ctx context.Context) int { } // Only returns a single DeviceRequest entity found by the query, ensuring it only returns one. -// Returns a *NotSingularError when exactly one DeviceRequest entity is not found. +// Returns a *NotSingularError when more than one DeviceRequest entity is found. // Returns a *NotFoundError when no DeviceRequest entities are found. func (drq *DeviceRequestQuery) Only(ctx context.Context) (*DeviceRequest, error) { nodes, err := drq.Limit(2).All(ctx) @@ -133,7 +133,7 @@ func (drq *DeviceRequestQuery) OnlyX(ctx context.Context) *DeviceRequest { } // OnlyID is like Only, but returns the only DeviceRequest ID in the query. -// Returns a *NotSingularError when exactly one DeviceRequest ID is not found. +// Returns a *NotSingularError when more than one DeviceRequest ID is found. // Returns a *NotFoundError when no entities are found. func (drq *DeviceRequestQuery) OnlyID(ctx context.Context) (id int, err error) { var ids []int @@ -242,8 +242,9 @@ func (drq *DeviceRequestQuery) Clone() *DeviceRequestQuery { order: append([]OrderFunc{}, drq.order...), predicates: append([]predicate.DeviceRequest{}, drq.predicates...), // clone intermediate query. - sql: drq.sql.Clone(), - path: drq.path, + sql: drq.sql.Clone(), + path: drq.path, + unique: drq.unique, } } @@ -336,6 +337,10 @@ func (drq *DeviceRequestQuery) sqlAll(ctx context.Context) ([]*DeviceRequest, er func (drq *DeviceRequestQuery) sqlCount(ctx context.Context) (int, error) { _spec := drq.querySpec() + _spec.Node.Columns = drq.fields + if len(drq.fields) > 0 { + _spec.Unique = drq.unique != nil && *drq.unique + } return sqlgraph.CountNodes(ctx, drq.driver, _spec) } @@ -407,6 +412,9 @@ func (drq *DeviceRequestQuery) sqlQuery(ctx context.Context) *sql.Selector { selector = drq.sql selector.Select(selector.Columns(columns...)...) } + if drq.unique != nil && *drq.unique { + selector.Distinct() + } for _, p := range drq.predicates { p(selector) } @@ -685,9 +693,7 @@ func (drgb *DeviceRequestGroupBy) sqlQuery() *sql.Selector { for _, f := range drgb.fields { columns = append(columns, selector.C(f)) } - for _, c := range aggregation { - columns = append(columns, c) - } + columns = append(columns, aggregation...) selector.Select(columns...) } return selector.GroupBy(selector.Columns(drgb.fields...)...) diff --git a/storage/ent/db/devicerequest_update.go b/storage/ent/db/devicerequest_update.go index 21c2f300..e47e565a 100644 --- a/storage/ent/db/devicerequest_update.go +++ b/storage/ent/db/devicerequest_update.go @@ -4,6 +4,7 @@ package db import ( "context" + "errors" "fmt" "time" @@ -138,22 +139,22 @@ func (dru *DeviceRequestUpdate) ExecX(ctx context.Context) { func (dru *DeviceRequestUpdate) check() error { if v, ok := dru.mutation.UserCode(); ok { if err := devicerequest.UserCodeValidator(v); err != nil { - return &ValidationError{Name: "user_code", err: fmt.Errorf("db: validator failed for field \"user_code\": %w", err)} + return &ValidationError{Name: "user_code", err: fmt.Errorf(`db: validator failed for field "DeviceRequest.user_code": %w`, err)} } } if v, ok := dru.mutation.DeviceCode(); ok { if err := devicerequest.DeviceCodeValidator(v); err != nil { - return &ValidationError{Name: "device_code", err: fmt.Errorf("db: validator failed for field \"device_code\": %w", err)} + return &ValidationError{Name: "device_code", err: fmt.Errorf(`db: validator failed for field "DeviceRequest.device_code": %w`, err)} } } if v, ok := dru.mutation.ClientID(); ok { if err := devicerequest.ClientIDValidator(v); err != nil { - return &ValidationError{Name: "client_id", err: fmt.Errorf("db: validator failed for field \"client_id\": %w", err)} + return &ValidationError{Name: "client_id", err: fmt.Errorf(`db: validator failed for field "DeviceRequest.client_id": %w`, err)} } } if v, ok := dru.mutation.ClientSecret(); ok { if err := devicerequest.ClientSecretValidator(v); err != nil { - return &ValidationError{Name: "client_secret", err: fmt.Errorf("db: validator failed for field \"client_secret\": %w", err)} + return &ValidationError{Name: "client_secret", err: fmt.Errorf(`db: validator failed for field "DeviceRequest.client_secret": %w`, err)} } } return nil @@ -362,22 +363,22 @@ func (druo *DeviceRequestUpdateOne) ExecX(ctx context.Context) { func (druo *DeviceRequestUpdateOne) check() error { if v, ok := druo.mutation.UserCode(); ok { if err := devicerequest.UserCodeValidator(v); err != nil { - return &ValidationError{Name: "user_code", err: fmt.Errorf("db: validator failed for field \"user_code\": %w", err)} + return &ValidationError{Name: "user_code", err: fmt.Errorf(`db: validator failed for field "DeviceRequest.user_code": %w`, err)} } } if v, ok := druo.mutation.DeviceCode(); ok { if err := devicerequest.DeviceCodeValidator(v); err != nil { - return &ValidationError{Name: "device_code", err: fmt.Errorf("db: validator failed for field \"device_code\": %w", err)} + return &ValidationError{Name: "device_code", err: fmt.Errorf(`db: validator failed for field "DeviceRequest.device_code": %w`, err)} } } if v, ok := druo.mutation.ClientID(); ok { if err := devicerequest.ClientIDValidator(v); err != nil { - return &ValidationError{Name: "client_id", err: fmt.Errorf("db: validator failed for field \"client_id\": %w", err)} + return &ValidationError{Name: "client_id", err: fmt.Errorf(`db: validator failed for field "DeviceRequest.client_id": %w`, err)} } } if v, ok := druo.mutation.ClientSecret(); ok { if err := devicerequest.ClientSecretValidator(v); err != nil { - return &ValidationError{Name: "client_secret", err: fmt.Errorf("db: validator failed for field \"client_secret\": %w", err)} + return &ValidationError{Name: "client_secret", err: fmt.Errorf(`db: validator failed for field "DeviceRequest.client_secret": %w`, err)} } } return nil @@ -396,7 +397,7 @@ func (druo *DeviceRequestUpdateOne) sqlSave(ctx context.Context) (_node *DeviceR } id, ok := druo.mutation.ID() if !ok { - return nil, &ValidationError{Name: "ID", err: fmt.Errorf("missing DeviceRequest.ID for update")} + return nil, &ValidationError{Name: "id", err: errors.New(`db: missing "DeviceRequest.id" for update`)} } _spec.Node.ID.Value = id if fields := druo.fields; len(fields) > 0 { diff --git a/storage/ent/db/devicetoken_create.go b/storage/ent/db/devicetoken_create.go index db73ad4d..42c86755 100644 --- a/storage/ent/db/devicetoken_create.go +++ b/storage/ent/db/devicetoken_create.go @@ -127,29 +127,29 @@ func (dtc *DeviceTokenCreate) ExecX(ctx context.Context) { // check runs all checks and user-defined validators on the builder. func (dtc *DeviceTokenCreate) check() error { if _, ok := dtc.mutation.DeviceCode(); !ok { - return &ValidationError{Name: "device_code", err: errors.New(`db: missing required field "device_code"`)} + return &ValidationError{Name: "device_code", err: errors.New(`db: missing required field "DeviceToken.device_code"`)} } if v, ok := dtc.mutation.DeviceCode(); ok { if err := devicetoken.DeviceCodeValidator(v); err != nil { - return &ValidationError{Name: "device_code", err: fmt.Errorf(`db: validator failed for field "device_code": %w`, err)} + return &ValidationError{Name: "device_code", err: fmt.Errorf(`db: validator failed for field "DeviceToken.device_code": %w`, err)} } } if _, ok := dtc.mutation.Status(); !ok { - return &ValidationError{Name: "status", err: errors.New(`db: missing required field "status"`)} + return &ValidationError{Name: "status", err: errors.New(`db: missing required field "DeviceToken.status"`)} } if v, ok := dtc.mutation.Status(); ok { if err := devicetoken.StatusValidator(v); err != nil { - return &ValidationError{Name: "status", err: fmt.Errorf(`db: validator failed for field "status": %w`, err)} + return &ValidationError{Name: "status", err: fmt.Errorf(`db: validator failed for field "DeviceToken.status": %w`, err)} } } if _, ok := dtc.mutation.Expiry(); !ok { - return &ValidationError{Name: "expiry", err: errors.New(`db: missing required field "expiry"`)} + return &ValidationError{Name: "expiry", err: errors.New(`db: missing required field "DeviceToken.expiry"`)} } if _, ok := dtc.mutation.LastRequest(); !ok { - return &ValidationError{Name: "last_request", err: errors.New(`db: missing required field "last_request"`)} + return &ValidationError{Name: "last_request", err: errors.New(`db: missing required field "DeviceToken.last_request"`)} } if _, ok := dtc.mutation.PollInterval(); !ok { - return &ValidationError{Name: "poll_interval", err: errors.New(`db: missing required field "poll_interval"`)} + return &ValidationError{Name: "poll_interval", err: errors.New(`db: missing required field "DeviceToken.poll_interval"`)} } return nil } diff --git a/storage/ent/db/devicetoken_query.go b/storage/ent/db/devicetoken_query.go index 2fb2712f..07697c49 100644 --- a/storage/ent/db/devicetoken_query.go +++ b/storage/ent/db/devicetoken_query.go @@ -106,7 +106,7 @@ func (dtq *DeviceTokenQuery) FirstIDX(ctx context.Context) int { } // Only returns a single DeviceToken entity found by the query, ensuring it only returns one. -// Returns a *NotSingularError when exactly one DeviceToken entity is not found. +// Returns a *NotSingularError when more than one DeviceToken entity is found. // Returns a *NotFoundError when no DeviceToken entities are found. func (dtq *DeviceTokenQuery) Only(ctx context.Context) (*DeviceToken, error) { nodes, err := dtq.Limit(2).All(ctx) @@ -133,7 +133,7 @@ func (dtq *DeviceTokenQuery) OnlyX(ctx context.Context) *DeviceToken { } // OnlyID is like Only, but returns the only DeviceToken ID in the query. -// Returns a *NotSingularError when exactly one DeviceToken ID is not found. +// Returns a *NotSingularError when more than one DeviceToken ID is found. // Returns a *NotFoundError when no entities are found. func (dtq *DeviceTokenQuery) OnlyID(ctx context.Context) (id int, err error) { var ids []int @@ -242,8 +242,9 @@ func (dtq *DeviceTokenQuery) Clone() *DeviceTokenQuery { order: append([]OrderFunc{}, dtq.order...), predicates: append([]predicate.DeviceToken{}, dtq.predicates...), // clone intermediate query. - sql: dtq.sql.Clone(), - path: dtq.path, + sql: dtq.sql.Clone(), + path: dtq.path, + unique: dtq.unique, } } @@ -336,6 +337,10 @@ func (dtq *DeviceTokenQuery) sqlAll(ctx context.Context) ([]*DeviceToken, error) func (dtq *DeviceTokenQuery) sqlCount(ctx context.Context) (int, error) { _spec := dtq.querySpec() + _spec.Node.Columns = dtq.fields + if len(dtq.fields) > 0 { + _spec.Unique = dtq.unique != nil && *dtq.unique + } return sqlgraph.CountNodes(ctx, dtq.driver, _spec) } @@ -407,6 +412,9 @@ func (dtq *DeviceTokenQuery) sqlQuery(ctx context.Context) *sql.Selector { selector = dtq.sql selector.Select(selector.Columns(columns...)...) } + if dtq.unique != nil && *dtq.unique { + selector.Distinct() + } for _, p := range dtq.predicates { p(selector) } @@ -685,9 +693,7 @@ func (dtgb *DeviceTokenGroupBy) sqlQuery() *sql.Selector { for _, f := range dtgb.fields { columns = append(columns, selector.C(f)) } - for _, c := range aggregation { - columns = append(columns, c) - } + columns = append(columns, aggregation...) selector.Select(columns...) } return selector.GroupBy(selector.Columns(dtgb.fields...)...) diff --git a/storage/ent/db/devicetoken_update.go b/storage/ent/db/devicetoken_update.go index a61a8b0b..bf9d2993 100644 --- a/storage/ent/db/devicetoken_update.go +++ b/storage/ent/db/devicetoken_update.go @@ -4,6 +4,7 @@ package db import ( "context" + "errors" "fmt" "time" @@ -145,12 +146,12 @@ func (dtu *DeviceTokenUpdate) ExecX(ctx context.Context) { func (dtu *DeviceTokenUpdate) check() error { if v, ok := dtu.mutation.DeviceCode(); ok { if err := devicetoken.DeviceCodeValidator(v); err != nil { - return &ValidationError{Name: "device_code", err: fmt.Errorf("db: validator failed for field \"device_code\": %w", err)} + return &ValidationError{Name: "device_code", err: fmt.Errorf(`db: validator failed for field "DeviceToken.device_code": %w`, err)} } } if v, ok := dtu.mutation.Status(); ok { if err := devicetoken.StatusValidator(v); err != nil { - return &ValidationError{Name: "status", err: fmt.Errorf("db: validator failed for field \"status\": %w", err)} + return &ValidationError{Name: "status", err: fmt.Errorf(`db: validator failed for field "DeviceToken.status": %w`, err)} } } return nil @@ -373,12 +374,12 @@ func (dtuo *DeviceTokenUpdateOne) ExecX(ctx context.Context) { func (dtuo *DeviceTokenUpdateOne) check() error { if v, ok := dtuo.mutation.DeviceCode(); ok { if err := devicetoken.DeviceCodeValidator(v); err != nil { - return &ValidationError{Name: "device_code", err: fmt.Errorf("db: validator failed for field \"device_code\": %w", err)} + return &ValidationError{Name: "device_code", err: fmt.Errorf(`db: validator failed for field "DeviceToken.device_code": %w`, err)} } } if v, ok := dtuo.mutation.Status(); ok { if err := devicetoken.StatusValidator(v); err != nil { - return &ValidationError{Name: "status", err: fmt.Errorf("db: validator failed for field \"status\": %w", err)} + return &ValidationError{Name: "status", err: fmt.Errorf(`db: validator failed for field "DeviceToken.status": %w`, err)} } } return nil @@ -397,7 +398,7 @@ func (dtuo *DeviceTokenUpdateOne) sqlSave(ctx context.Context) (_node *DeviceTok } id, ok := dtuo.mutation.ID() if !ok { - return nil, &ValidationError{Name: "ID", err: fmt.Errorf("missing DeviceToken.ID for update")} + return nil, &ValidationError{Name: "id", err: errors.New(`db: missing "DeviceToken.id" for update`)} } _spec.Node.ID.Value = id if fields := dtuo.fields; len(fields) > 0 { diff --git a/storage/ent/db/ent.go b/storage/ent/db/ent.go index 42d7ad52..15a183a2 100644 --- a/storage/ent/db/ent.go +++ b/storage/ent/db/ent.go @@ -159,7 +159,7 @@ func Sum(field string) AggregateFunc { } } -// ValidationError returns when validating a field fails. +// ValidationError returns when validating a field or edge fails. type ValidationError struct { Name string // Field or edge name. err error diff --git a/storage/ent/db/keys_create.go b/storage/ent/db/keys_create.go index 18e58f8b..2b37b581 100644 --- a/storage/ent/db/keys_create.go +++ b/storage/ent/db/keys_create.go @@ -123,20 +123,20 @@ func (kc *KeysCreate) ExecX(ctx context.Context) { // check runs all checks and user-defined validators on the builder. func (kc *KeysCreate) check() error { if _, ok := kc.mutation.VerificationKeys(); !ok { - return &ValidationError{Name: "verification_keys", err: errors.New(`db: missing required field "verification_keys"`)} + return &ValidationError{Name: "verification_keys", err: errors.New(`db: missing required field "Keys.verification_keys"`)} } if _, ok := kc.mutation.SigningKey(); !ok { - return &ValidationError{Name: "signing_key", err: errors.New(`db: missing required field "signing_key"`)} + return &ValidationError{Name: "signing_key", err: errors.New(`db: missing required field "Keys.signing_key"`)} } if _, ok := kc.mutation.SigningKeyPub(); !ok { - return &ValidationError{Name: "signing_key_pub", err: errors.New(`db: missing required field "signing_key_pub"`)} + return &ValidationError{Name: "signing_key_pub", err: errors.New(`db: missing required field "Keys.signing_key_pub"`)} } if _, ok := kc.mutation.NextRotation(); !ok { - return &ValidationError{Name: "next_rotation", err: errors.New(`db: missing required field "next_rotation"`)} + return &ValidationError{Name: "next_rotation", err: errors.New(`db: missing required field "Keys.next_rotation"`)} } if v, ok := kc.mutation.ID(); ok { if err := keys.IDValidator(v); err != nil { - return &ValidationError{Name: "id", err: fmt.Errorf(`db: validator failed for field "id": %w`, err)} + return &ValidationError{Name: "id", err: fmt.Errorf(`db: validator failed for field "Keys.id": %w`, err)} } } return nil @@ -150,6 +150,13 @@ func (kc *KeysCreate) sqlSave(ctx context.Context) (*Keys, error) { } return nil, err } + if _spec.ID.Value != nil { + if id, ok := _spec.ID.Value.(string); ok { + _node.ID = id + } else { + return nil, fmt.Errorf("unexpected Keys.ID type: %T", _spec.ID.Value) + } + } return _node, nil } diff --git a/storage/ent/db/keys_query.go b/storage/ent/db/keys_query.go index ee102e27..c2dfc173 100644 --- a/storage/ent/db/keys_query.go +++ b/storage/ent/db/keys_query.go @@ -106,7 +106,7 @@ func (kq *KeysQuery) FirstIDX(ctx context.Context) string { } // Only returns a single Keys entity found by the query, ensuring it only returns one. -// Returns a *NotSingularError when exactly one Keys entity is not found. +// Returns a *NotSingularError when more than one Keys entity is found. // Returns a *NotFoundError when no Keys entities are found. func (kq *KeysQuery) Only(ctx context.Context) (*Keys, error) { nodes, err := kq.Limit(2).All(ctx) @@ -133,7 +133,7 @@ func (kq *KeysQuery) OnlyX(ctx context.Context) *Keys { } // OnlyID is like Only, but returns the only Keys ID in the query. -// Returns a *NotSingularError when exactly one Keys ID is not found. +// Returns a *NotSingularError when more than one Keys ID is found. // Returns a *NotFoundError when no entities are found. func (kq *KeysQuery) OnlyID(ctx context.Context) (id string, err error) { var ids []string @@ -242,8 +242,9 @@ func (kq *KeysQuery) Clone() *KeysQuery { order: append([]OrderFunc{}, kq.order...), predicates: append([]predicate.Keys{}, kq.predicates...), // clone intermediate query. - sql: kq.sql.Clone(), - path: kq.path, + sql: kq.sql.Clone(), + path: kq.path, + unique: kq.unique, } } @@ -336,6 +337,10 @@ func (kq *KeysQuery) sqlAll(ctx context.Context) ([]*Keys, error) { func (kq *KeysQuery) sqlCount(ctx context.Context) (int, error) { _spec := kq.querySpec() + _spec.Node.Columns = kq.fields + if len(kq.fields) > 0 { + _spec.Unique = kq.unique != nil && *kq.unique + } return sqlgraph.CountNodes(ctx, kq.driver, _spec) } @@ -407,6 +412,9 @@ func (kq *KeysQuery) sqlQuery(ctx context.Context) *sql.Selector { selector = kq.sql selector.Select(selector.Columns(columns...)...) } + if kq.unique != nil && *kq.unique { + selector.Distinct() + } for _, p := range kq.predicates { p(selector) } @@ -685,9 +693,7 @@ func (kgb *KeysGroupBy) sqlQuery() *sql.Selector { for _, f := range kgb.fields { columns = append(columns, selector.C(f)) } - for _, c := range aggregation { - columns = append(columns, c) - } + columns = append(columns, aggregation...) selector.Select(columns...) } return selector.GroupBy(selector.Columns(kgb.fields...)...) diff --git a/storage/ent/db/keys_update.go b/storage/ent/db/keys_update.go index 0e40565f..e5b5529a 100644 --- a/storage/ent/db/keys_update.go +++ b/storage/ent/db/keys_update.go @@ -4,6 +4,7 @@ package db import ( "context" + "errors" "fmt" "time" @@ -280,7 +281,7 @@ func (kuo *KeysUpdateOne) sqlSave(ctx context.Context) (_node *Keys, err error) } id, ok := kuo.mutation.ID() if !ok { - return nil, &ValidationError{Name: "ID", err: fmt.Errorf("missing Keys.ID for update")} + return nil, &ValidationError{Name: "id", err: errors.New(`db: missing "Keys.id" for update`)} } _spec.Node.ID.Value = id if fields := kuo.fields; len(fields) > 0 { diff --git a/storage/ent/db/migrate/migrate.go b/storage/ent/db/migrate/migrate.go index e4a9a221..9bdaf523 100644 --- a/storage/ent/db/migrate/migrate.go +++ b/storage/ent/db/migrate/migrate.go @@ -37,8 +37,7 @@ var ( // Schema is the API for creating, migrating and dropping a schema. type Schema struct { - drv dialect.Driver - universalID bool + drv dialect.Driver } // NewSchema creates a new schema client. diff --git a/storage/ent/db/mutation.go b/storage/ent/db/mutation.go index d6d1dbab..d7d4e423 100644 --- a/storage/ent/db/mutation.go +++ b/storage/ent/db/mutation.go @@ -4,6 +4,7 @@ package db import ( "context" + "errors" "fmt" "sync" "time" @@ -103,7 +104,7 @@ func withAuthCodeID(id string) authcodeOption { m.oldValue = func(ctx context.Context) (*AuthCode, error) { once.Do(func() { if m.done { - err = fmt.Errorf("querying old values post mutation is not allowed") + err = errors.New("querying old values post mutation is not allowed") } else { value, err = m.Client().AuthCode.Get(ctx, id) } @@ -136,7 +137,7 @@ func (m AuthCodeMutation) Client() *Client { // it returns an error otherwise. func (m AuthCodeMutation) Tx() (*Tx, error) { if _, ok := m.driver.(*txDriver); !ok { - return nil, fmt.Errorf("db: mutation is not running in a transaction") + return nil, errors.New("db: mutation is not running in a transaction") } tx := &Tx{config: m.config} tx.init() @@ -158,6 +159,25 @@ func (m *AuthCodeMutation) ID() (id string, exists bool) { return *m.id, true } +// IDs queries the database and returns the entity ids that match the mutation's predicate. +// That means, if the mutation is applied within a transaction with an isolation level such +// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated +// or updated by the mutation. +func (m *AuthCodeMutation) IDs(ctx context.Context) ([]string, error) { + switch { + case m.op.Is(OpUpdateOne | OpDeleteOne): + id, exists := m.ID() + if exists { + return []string{id}, nil + } + fallthrough + case m.op.Is(OpUpdate | OpDelete): + return m.Client().AuthCode.Query().Where(m.predicates...).IDs(ctx) + default: + return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) + } +} + // SetClientID sets the "client_id" field. func (m *AuthCodeMutation) SetClientID(s string) { m.client_id = &s @@ -177,10 +197,10 @@ func (m *AuthCodeMutation) ClientID() (r string, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *AuthCodeMutation) OldClientID(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldClientID is only allowed on UpdateOne operations") + return v, errors.New("OldClientID is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldClientID requires an ID field in the mutation") + return v, errors.New("OldClientID requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -213,10 +233,10 @@ func (m *AuthCodeMutation) Scopes() (r []string, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *AuthCodeMutation) OldScopes(ctx context.Context) (v []string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldScopes is only allowed on UpdateOne operations") + return v, errors.New("OldScopes is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldScopes requires an ID field in the mutation") + return v, errors.New("OldScopes requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -262,10 +282,10 @@ func (m *AuthCodeMutation) Nonce() (r string, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *AuthCodeMutation) OldNonce(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldNonce is only allowed on UpdateOne operations") + return v, errors.New("OldNonce is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldNonce requires an ID field in the mutation") + return v, errors.New("OldNonce requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -298,10 +318,10 @@ func (m *AuthCodeMutation) RedirectURI() (r string, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *AuthCodeMutation) OldRedirectURI(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldRedirectURI is only allowed on UpdateOne operations") + return v, errors.New("OldRedirectURI is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldRedirectURI requires an ID field in the mutation") + return v, errors.New("OldRedirectURI requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -334,10 +354,10 @@ func (m *AuthCodeMutation) ClaimsUserID() (r string, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *AuthCodeMutation) OldClaimsUserID(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldClaimsUserID is only allowed on UpdateOne operations") + return v, errors.New("OldClaimsUserID is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldClaimsUserID requires an ID field in the mutation") + return v, errors.New("OldClaimsUserID requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -370,10 +390,10 @@ func (m *AuthCodeMutation) ClaimsUsername() (r string, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *AuthCodeMutation) OldClaimsUsername(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldClaimsUsername is only allowed on UpdateOne operations") + return v, errors.New("OldClaimsUsername is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldClaimsUsername requires an ID field in the mutation") + return v, errors.New("OldClaimsUsername requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -406,10 +426,10 @@ func (m *AuthCodeMutation) ClaimsEmail() (r string, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *AuthCodeMutation) OldClaimsEmail(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldClaimsEmail is only allowed on UpdateOne operations") + return v, errors.New("OldClaimsEmail is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldClaimsEmail requires an ID field in the mutation") + return v, errors.New("OldClaimsEmail requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -442,10 +462,10 @@ func (m *AuthCodeMutation) ClaimsEmailVerified() (r bool, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *AuthCodeMutation) OldClaimsEmailVerified(ctx context.Context) (v bool, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldClaimsEmailVerified is only allowed on UpdateOne operations") + return v, errors.New("OldClaimsEmailVerified is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldClaimsEmailVerified requires an ID field in the mutation") + return v, errors.New("OldClaimsEmailVerified requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -478,10 +498,10 @@ func (m *AuthCodeMutation) ClaimsGroups() (r []string, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *AuthCodeMutation) OldClaimsGroups(ctx context.Context) (v []string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldClaimsGroups is only allowed on UpdateOne operations") + return v, errors.New("OldClaimsGroups is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldClaimsGroups requires an ID field in the mutation") + return v, errors.New("OldClaimsGroups requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -527,10 +547,10 @@ func (m *AuthCodeMutation) ClaimsPreferredUsername() (r string, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *AuthCodeMutation) OldClaimsPreferredUsername(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldClaimsPreferredUsername is only allowed on UpdateOne operations") + return v, errors.New("OldClaimsPreferredUsername is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldClaimsPreferredUsername requires an ID field in the mutation") + return v, errors.New("OldClaimsPreferredUsername requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -563,10 +583,10 @@ func (m *AuthCodeMutation) ConnectorID() (r string, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *AuthCodeMutation) OldConnectorID(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldConnectorID is only allowed on UpdateOne operations") + return v, errors.New("OldConnectorID is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldConnectorID requires an ID field in the mutation") + return v, errors.New("OldConnectorID requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -599,10 +619,10 @@ func (m *AuthCodeMutation) ConnectorData() (r []byte, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *AuthCodeMutation) OldConnectorData(ctx context.Context) (v *[]byte, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldConnectorData is only allowed on UpdateOne operations") + return v, errors.New("OldConnectorData is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldConnectorData requires an ID field in the mutation") + return v, errors.New("OldConnectorData requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -648,10 +668,10 @@ func (m *AuthCodeMutation) Expiry() (r time.Time, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *AuthCodeMutation) OldExpiry(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldExpiry is only allowed on UpdateOne operations") + return v, errors.New("OldExpiry is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldExpiry requires an ID field in the mutation") + return v, errors.New("OldExpiry requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -684,10 +704,10 @@ func (m *AuthCodeMutation) CodeChallenge() (r string, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *AuthCodeMutation) OldCodeChallenge(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldCodeChallenge is only allowed on UpdateOne operations") + return v, errors.New("OldCodeChallenge is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldCodeChallenge requires an ID field in the mutation") + return v, errors.New("OldCodeChallenge requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -720,10 +740,10 @@ func (m *AuthCodeMutation) CodeChallengeMethod() (r string, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *AuthCodeMutation) OldCodeChallengeMethod(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldCodeChallengeMethod is only allowed on UpdateOne operations") + return v, errors.New("OldCodeChallengeMethod is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldCodeChallengeMethod requires an ID field in the mutation") + return v, errors.New("OldCodeChallengeMethod requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -1221,7 +1241,7 @@ func withAuthRequestID(id string) authrequestOption { m.oldValue = func(ctx context.Context) (*AuthRequest, error) { once.Do(func() { if m.done { - err = fmt.Errorf("querying old values post mutation is not allowed") + err = errors.New("querying old values post mutation is not allowed") } else { value, err = m.Client().AuthRequest.Get(ctx, id) } @@ -1254,7 +1274,7 @@ func (m AuthRequestMutation) Client() *Client { // it returns an error otherwise. func (m AuthRequestMutation) Tx() (*Tx, error) { if _, ok := m.driver.(*txDriver); !ok { - return nil, fmt.Errorf("db: mutation is not running in a transaction") + return nil, errors.New("db: mutation is not running in a transaction") } tx := &Tx{config: m.config} tx.init() @@ -1276,6 +1296,25 @@ func (m *AuthRequestMutation) ID() (id string, exists bool) { return *m.id, true } +// IDs queries the database and returns the entity ids that match the mutation's predicate. +// That means, if the mutation is applied within a transaction with an isolation level such +// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated +// or updated by the mutation. +func (m *AuthRequestMutation) IDs(ctx context.Context) ([]string, error) { + switch { + case m.op.Is(OpUpdateOne | OpDeleteOne): + id, exists := m.ID() + if exists { + return []string{id}, nil + } + fallthrough + case m.op.Is(OpUpdate | OpDelete): + return m.Client().AuthRequest.Query().Where(m.predicates...).IDs(ctx) + default: + return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) + } +} + // SetClientID sets the "client_id" field. func (m *AuthRequestMutation) SetClientID(s string) { m.client_id = &s @@ -1295,10 +1334,10 @@ func (m *AuthRequestMutation) ClientID() (r string, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *AuthRequestMutation) OldClientID(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldClientID is only allowed on UpdateOne operations") + return v, errors.New("OldClientID is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldClientID requires an ID field in the mutation") + return v, errors.New("OldClientID requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -1331,10 +1370,10 @@ func (m *AuthRequestMutation) Scopes() (r []string, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *AuthRequestMutation) OldScopes(ctx context.Context) (v []string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldScopes is only allowed on UpdateOne operations") + return v, errors.New("OldScopes is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldScopes requires an ID field in the mutation") + return v, errors.New("OldScopes requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -1380,10 +1419,10 @@ func (m *AuthRequestMutation) ResponseTypes() (r []string, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *AuthRequestMutation) OldResponseTypes(ctx context.Context) (v []string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldResponseTypes is only allowed on UpdateOne operations") + return v, errors.New("OldResponseTypes is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldResponseTypes requires an ID field in the mutation") + return v, errors.New("OldResponseTypes requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -1429,10 +1468,10 @@ func (m *AuthRequestMutation) RedirectURI() (r string, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *AuthRequestMutation) OldRedirectURI(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldRedirectURI is only allowed on UpdateOne operations") + return v, errors.New("OldRedirectURI is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldRedirectURI requires an ID field in the mutation") + return v, errors.New("OldRedirectURI requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -1465,10 +1504,10 @@ func (m *AuthRequestMutation) Nonce() (r string, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *AuthRequestMutation) OldNonce(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldNonce is only allowed on UpdateOne operations") + return v, errors.New("OldNonce is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldNonce requires an ID field in the mutation") + return v, errors.New("OldNonce requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -1501,10 +1540,10 @@ func (m *AuthRequestMutation) State() (r string, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *AuthRequestMutation) OldState(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldState is only allowed on UpdateOne operations") + return v, errors.New("OldState is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldState requires an ID field in the mutation") + return v, errors.New("OldState requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -1537,10 +1576,10 @@ func (m *AuthRequestMutation) ForceApprovalPrompt() (r bool, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *AuthRequestMutation) OldForceApprovalPrompt(ctx context.Context) (v bool, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldForceApprovalPrompt is only allowed on UpdateOne operations") + return v, errors.New("OldForceApprovalPrompt is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldForceApprovalPrompt requires an ID field in the mutation") + return v, errors.New("OldForceApprovalPrompt requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -1573,10 +1612,10 @@ func (m *AuthRequestMutation) LoggedIn() (r bool, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *AuthRequestMutation) OldLoggedIn(ctx context.Context) (v bool, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldLoggedIn is only allowed on UpdateOne operations") + return v, errors.New("OldLoggedIn is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldLoggedIn requires an ID field in the mutation") + return v, errors.New("OldLoggedIn requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -1609,10 +1648,10 @@ func (m *AuthRequestMutation) ClaimsUserID() (r string, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *AuthRequestMutation) OldClaimsUserID(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldClaimsUserID is only allowed on UpdateOne operations") + return v, errors.New("OldClaimsUserID is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldClaimsUserID requires an ID field in the mutation") + return v, errors.New("OldClaimsUserID requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -1645,10 +1684,10 @@ func (m *AuthRequestMutation) ClaimsUsername() (r string, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *AuthRequestMutation) OldClaimsUsername(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldClaimsUsername is only allowed on UpdateOne operations") + return v, errors.New("OldClaimsUsername is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldClaimsUsername requires an ID field in the mutation") + return v, errors.New("OldClaimsUsername requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -1681,10 +1720,10 @@ func (m *AuthRequestMutation) ClaimsEmail() (r string, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *AuthRequestMutation) OldClaimsEmail(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldClaimsEmail is only allowed on UpdateOne operations") + return v, errors.New("OldClaimsEmail is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldClaimsEmail requires an ID field in the mutation") + return v, errors.New("OldClaimsEmail requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -1717,10 +1756,10 @@ func (m *AuthRequestMutation) ClaimsEmailVerified() (r bool, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *AuthRequestMutation) OldClaimsEmailVerified(ctx context.Context) (v bool, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldClaimsEmailVerified is only allowed on UpdateOne operations") + return v, errors.New("OldClaimsEmailVerified is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldClaimsEmailVerified requires an ID field in the mutation") + return v, errors.New("OldClaimsEmailVerified requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -1753,10 +1792,10 @@ func (m *AuthRequestMutation) ClaimsGroups() (r []string, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *AuthRequestMutation) OldClaimsGroups(ctx context.Context) (v []string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldClaimsGroups is only allowed on UpdateOne operations") + return v, errors.New("OldClaimsGroups is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldClaimsGroups requires an ID field in the mutation") + return v, errors.New("OldClaimsGroups requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -1802,10 +1841,10 @@ func (m *AuthRequestMutation) ClaimsPreferredUsername() (r string, exists bool) // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *AuthRequestMutation) OldClaimsPreferredUsername(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldClaimsPreferredUsername is only allowed on UpdateOne operations") + return v, errors.New("OldClaimsPreferredUsername is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldClaimsPreferredUsername requires an ID field in the mutation") + return v, errors.New("OldClaimsPreferredUsername requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -1838,10 +1877,10 @@ func (m *AuthRequestMutation) ConnectorID() (r string, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *AuthRequestMutation) OldConnectorID(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldConnectorID is only allowed on UpdateOne operations") + return v, errors.New("OldConnectorID is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldConnectorID requires an ID field in the mutation") + return v, errors.New("OldConnectorID requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -1874,10 +1913,10 @@ func (m *AuthRequestMutation) ConnectorData() (r []byte, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *AuthRequestMutation) OldConnectorData(ctx context.Context) (v *[]byte, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldConnectorData is only allowed on UpdateOne operations") + return v, errors.New("OldConnectorData is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldConnectorData requires an ID field in the mutation") + return v, errors.New("OldConnectorData requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -1923,10 +1962,10 @@ func (m *AuthRequestMutation) Expiry() (r time.Time, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *AuthRequestMutation) OldExpiry(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldExpiry is only allowed on UpdateOne operations") + return v, errors.New("OldExpiry is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldExpiry requires an ID field in the mutation") + return v, errors.New("OldExpiry requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -1959,10 +1998,10 @@ func (m *AuthRequestMutation) CodeChallenge() (r string, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *AuthRequestMutation) OldCodeChallenge(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldCodeChallenge is only allowed on UpdateOne operations") + return v, errors.New("OldCodeChallenge is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldCodeChallenge requires an ID field in the mutation") + return v, errors.New("OldCodeChallenge requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -1995,10 +2034,10 @@ func (m *AuthRequestMutation) CodeChallengeMethod() (r string, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *AuthRequestMutation) OldCodeChallengeMethod(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldCodeChallengeMethod is only allowed on UpdateOne operations") + return v, errors.New("OldCodeChallengeMethod is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldCodeChallengeMethod requires an ID field in the mutation") + return v, errors.New("OldCodeChallengeMethod requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -2555,7 +2594,7 @@ func withConnectorID(id string) connectorOption { m.oldValue = func(ctx context.Context) (*Connector, error) { once.Do(func() { if m.done { - err = fmt.Errorf("querying old values post mutation is not allowed") + err = errors.New("querying old values post mutation is not allowed") } else { value, err = m.Client().Connector.Get(ctx, id) } @@ -2588,7 +2627,7 @@ func (m ConnectorMutation) Client() *Client { // it returns an error otherwise. func (m ConnectorMutation) Tx() (*Tx, error) { if _, ok := m.driver.(*txDriver); !ok { - return nil, fmt.Errorf("db: mutation is not running in a transaction") + return nil, errors.New("db: mutation is not running in a transaction") } tx := &Tx{config: m.config} tx.init() @@ -2610,6 +2649,25 @@ func (m *ConnectorMutation) ID() (id string, exists bool) { return *m.id, true } +// IDs queries the database and returns the entity ids that match the mutation's predicate. +// That means, if the mutation is applied within a transaction with an isolation level such +// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated +// or updated by the mutation. +func (m *ConnectorMutation) IDs(ctx context.Context) ([]string, error) { + switch { + case m.op.Is(OpUpdateOne | OpDeleteOne): + id, exists := m.ID() + if exists { + return []string{id}, nil + } + fallthrough + case m.op.Is(OpUpdate | OpDelete): + return m.Client().Connector.Query().Where(m.predicates...).IDs(ctx) + default: + return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) + } +} + // SetType sets the "type" field. func (m *ConnectorMutation) SetType(s string) { m._type = &s @@ -2629,10 +2687,10 @@ func (m *ConnectorMutation) GetType() (r string, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *ConnectorMutation) OldType(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldType is only allowed on UpdateOne operations") + return v, errors.New("OldType is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldType requires an ID field in the mutation") + return v, errors.New("OldType requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -2665,10 +2723,10 @@ func (m *ConnectorMutation) Name() (r string, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *ConnectorMutation) OldName(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldName is only allowed on UpdateOne operations") + return v, errors.New("OldName is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldName requires an ID field in the mutation") + return v, errors.New("OldName requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -2701,10 +2759,10 @@ func (m *ConnectorMutation) ResourceVersion() (r string, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *ConnectorMutation) OldResourceVersion(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldResourceVersion is only allowed on UpdateOne operations") + return v, errors.New("OldResourceVersion is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldResourceVersion requires an ID field in the mutation") + return v, errors.New("OldResourceVersion requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -2737,10 +2795,10 @@ func (m *ConnectorMutation) Config() (r []byte, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *ConnectorMutation) OldConfig(ctx context.Context) (v []byte, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldConfig is only allowed on UpdateOne operations") + return v, errors.New("OldConfig is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldConfig requires an ID field in the mutation") + return v, errors.New("OldConfig requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -3017,7 +3075,7 @@ func withDeviceRequestID(id int) devicerequestOption { m.oldValue = func(ctx context.Context) (*DeviceRequest, error) { once.Do(func() { if m.done { - err = fmt.Errorf("querying old values post mutation is not allowed") + err = errors.New("querying old values post mutation is not allowed") } else { value, err = m.Client().DeviceRequest.Get(ctx, id) } @@ -3050,7 +3108,7 @@ func (m DeviceRequestMutation) Client() *Client { // it returns an error otherwise. func (m DeviceRequestMutation) Tx() (*Tx, error) { if _, ok := m.driver.(*txDriver); !ok { - return nil, fmt.Errorf("db: mutation is not running in a transaction") + return nil, errors.New("db: mutation is not running in a transaction") } tx := &Tx{config: m.config} tx.init() @@ -3066,6 +3124,25 @@ func (m *DeviceRequestMutation) ID() (id int, exists bool) { return *m.id, true } +// IDs queries the database and returns the entity ids that match the mutation's predicate. +// That means, if the mutation is applied within a transaction with an isolation level such +// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated +// or updated by the mutation. +func (m *DeviceRequestMutation) IDs(ctx context.Context) ([]int, error) { + switch { + case m.op.Is(OpUpdateOne | OpDeleteOne): + id, exists := m.ID() + if exists { + return []int{id}, nil + } + fallthrough + case m.op.Is(OpUpdate | OpDelete): + return m.Client().DeviceRequest.Query().Where(m.predicates...).IDs(ctx) + default: + return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) + } +} + // SetUserCode sets the "user_code" field. func (m *DeviceRequestMutation) SetUserCode(s string) { m.user_code = &s @@ -3085,10 +3162,10 @@ func (m *DeviceRequestMutation) UserCode() (r string, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *DeviceRequestMutation) OldUserCode(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldUserCode is only allowed on UpdateOne operations") + return v, errors.New("OldUserCode is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldUserCode requires an ID field in the mutation") + return v, errors.New("OldUserCode requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -3121,10 +3198,10 @@ func (m *DeviceRequestMutation) DeviceCode() (r string, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *DeviceRequestMutation) OldDeviceCode(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldDeviceCode is only allowed on UpdateOne operations") + return v, errors.New("OldDeviceCode is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldDeviceCode requires an ID field in the mutation") + return v, errors.New("OldDeviceCode requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -3157,10 +3234,10 @@ func (m *DeviceRequestMutation) ClientID() (r string, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *DeviceRequestMutation) OldClientID(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldClientID is only allowed on UpdateOne operations") + return v, errors.New("OldClientID is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldClientID requires an ID field in the mutation") + return v, errors.New("OldClientID requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -3193,10 +3270,10 @@ func (m *DeviceRequestMutation) ClientSecret() (r string, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *DeviceRequestMutation) OldClientSecret(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldClientSecret is only allowed on UpdateOne operations") + return v, errors.New("OldClientSecret is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldClientSecret requires an ID field in the mutation") + return v, errors.New("OldClientSecret requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -3229,10 +3306,10 @@ func (m *DeviceRequestMutation) Scopes() (r []string, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *DeviceRequestMutation) OldScopes(ctx context.Context) (v []string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldScopes is only allowed on UpdateOne operations") + return v, errors.New("OldScopes is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldScopes requires an ID field in the mutation") + return v, errors.New("OldScopes requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -3278,10 +3355,10 @@ func (m *DeviceRequestMutation) Expiry() (r time.Time, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *DeviceRequestMutation) OldExpiry(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldExpiry is only allowed on UpdateOne operations") + return v, errors.New("OldExpiry is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldExpiry requires an ID field in the mutation") + return v, errors.New("OldExpiry requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -3602,7 +3679,7 @@ func withDeviceTokenID(id int) devicetokenOption { m.oldValue = func(ctx context.Context) (*DeviceToken, error) { once.Do(func() { if m.done { - err = fmt.Errorf("querying old values post mutation is not allowed") + err = errors.New("querying old values post mutation is not allowed") } else { value, err = m.Client().DeviceToken.Get(ctx, id) } @@ -3635,7 +3712,7 @@ func (m DeviceTokenMutation) Client() *Client { // it returns an error otherwise. func (m DeviceTokenMutation) Tx() (*Tx, error) { if _, ok := m.driver.(*txDriver); !ok { - return nil, fmt.Errorf("db: mutation is not running in a transaction") + return nil, errors.New("db: mutation is not running in a transaction") } tx := &Tx{config: m.config} tx.init() @@ -3651,6 +3728,25 @@ func (m *DeviceTokenMutation) ID() (id int, exists bool) { return *m.id, true } +// IDs queries the database and returns the entity ids that match the mutation's predicate. +// That means, if the mutation is applied within a transaction with an isolation level such +// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated +// or updated by the mutation. +func (m *DeviceTokenMutation) IDs(ctx context.Context) ([]int, error) { + switch { + case m.op.Is(OpUpdateOne | OpDeleteOne): + id, exists := m.ID() + if exists { + return []int{id}, nil + } + fallthrough + case m.op.Is(OpUpdate | OpDelete): + return m.Client().DeviceToken.Query().Where(m.predicates...).IDs(ctx) + default: + return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) + } +} + // SetDeviceCode sets the "device_code" field. func (m *DeviceTokenMutation) SetDeviceCode(s string) { m.device_code = &s @@ -3670,10 +3766,10 @@ func (m *DeviceTokenMutation) DeviceCode() (r string, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *DeviceTokenMutation) OldDeviceCode(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldDeviceCode is only allowed on UpdateOne operations") + return v, errors.New("OldDeviceCode is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldDeviceCode requires an ID field in the mutation") + return v, errors.New("OldDeviceCode requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -3706,10 +3802,10 @@ func (m *DeviceTokenMutation) Status() (r string, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *DeviceTokenMutation) OldStatus(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldStatus is only allowed on UpdateOne operations") + return v, errors.New("OldStatus is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldStatus requires an ID field in the mutation") + return v, errors.New("OldStatus requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -3742,10 +3838,10 @@ func (m *DeviceTokenMutation) Token() (r []byte, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *DeviceTokenMutation) OldToken(ctx context.Context) (v *[]byte, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldToken is only allowed on UpdateOne operations") + return v, errors.New("OldToken is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldToken requires an ID field in the mutation") + return v, errors.New("OldToken requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -3791,10 +3887,10 @@ func (m *DeviceTokenMutation) Expiry() (r time.Time, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *DeviceTokenMutation) OldExpiry(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldExpiry is only allowed on UpdateOne operations") + return v, errors.New("OldExpiry is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldExpiry requires an ID field in the mutation") + return v, errors.New("OldExpiry requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -3827,10 +3923,10 @@ func (m *DeviceTokenMutation) LastRequest() (r time.Time, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *DeviceTokenMutation) OldLastRequest(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldLastRequest is only allowed on UpdateOne operations") + return v, errors.New("OldLastRequest is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldLastRequest requires an ID field in the mutation") + return v, errors.New("OldLastRequest requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -3864,10 +3960,10 @@ func (m *DeviceTokenMutation) PollInterval() (r int, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *DeviceTokenMutation) OldPollInterval(ctx context.Context) (v int, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldPollInterval is only allowed on UpdateOne operations") + return v, errors.New("OldPollInterval is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldPollInterval requires an ID field in the mutation") + return v, errors.New("OldPollInterval requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -4219,7 +4315,7 @@ func withKeysID(id string) keysOption { m.oldValue = func(ctx context.Context) (*Keys, error) { once.Do(func() { if m.done { - err = fmt.Errorf("querying old values post mutation is not allowed") + err = errors.New("querying old values post mutation is not allowed") } else { value, err = m.Client().Keys.Get(ctx, id) } @@ -4252,7 +4348,7 @@ func (m KeysMutation) Client() *Client { // it returns an error otherwise. func (m KeysMutation) Tx() (*Tx, error) { if _, ok := m.driver.(*txDriver); !ok { - return nil, fmt.Errorf("db: mutation is not running in a transaction") + return nil, errors.New("db: mutation is not running in a transaction") } tx := &Tx{config: m.config} tx.init() @@ -4274,6 +4370,25 @@ func (m *KeysMutation) ID() (id string, exists bool) { return *m.id, true } +// IDs queries the database and returns the entity ids that match the mutation's predicate. +// That means, if the mutation is applied within a transaction with an isolation level such +// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated +// or updated by the mutation. +func (m *KeysMutation) IDs(ctx context.Context) ([]string, error) { + switch { + case m.op.Is(OpUpdateOne | OpDeleteOne): + id, exists := m.ID() + if exists { + return []string{id}, nil + } + fallthrough + case m.op.Is(OpUpdate | OpDelete): + return m.Client().Keys.Query().Where(m.predicates...).IDs(ctx) + default: + return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) + } +} + // SetVerificationKeys sets the "verification_keys" field. func (m *KeysMutation) SetVerificationKeys(sk []storage.VerificationKey) { m.verification_keys = &sk @@ -4293,10 +4408,10 @@ func (m *KeysMutation) VerificationKeys() (r []storage.VerificationKey, exists b // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *KeysMutation) OldVerificationKeys(ctx context.Context) (v []storage.VerificationKey, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldVerificationKeys is only allowed on UpdateOne operations") + return v, errors.New("OldVerificationKeys is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldVerificationKeys requires an ID field in the mutation") + return v, errors.New("OldVerificationKeys requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -4329,10 +4444,10 @@ func (m *KeysMutation) SigningKey() (r jose.JSONWebKey, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *KeysMutation) OldSigningKey(ctx context.Context) (v jose.JSONWebKey, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldSigningKey is only allowed on UpdateOne operations") + return v, errors.New("OldSigningKey is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldSigningKey requires an ID field in the mutation") + return v, errors.New("OldSigningKey requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -4365,10 +4480,10 @@ func (m *KeysMutation) SigningKeyPub() (r jose.JSONWebKey, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *KeysMutation) OldSigningKeyPub(ctx context.Context) (v jose.JSONWebKey, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldSigningKeyPub is only allowed on UpdateOne operations") + return v, errors.New("OldSigningKeyPub is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldSigningKeyPub requires an ID field in the mutation") + return v, errors.New("OldSigningKeyPub requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -4401,10 +4516,10 @@ func (m *KeysMutation) NextRotation() (r time.Time, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *KeysMutation) OldNextRotation(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldNextRotation is only allowed on UpdateOne operations") + return v, errors.New("OldNextRotation is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldNextRotation requires an ID field in the mutation") + return v, errors.New("OldNextRotation requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -4681,7 +4796,7 @@ func withOAuth2ClientID(id string) oauth2clientOption { m.oldValue = func(ctx context.Context) (*OAuth2Client, error) { once.Do(func() { if m.done { - err = fmt.Errorf("querying old values post mutation is not allowed") + err = errors.New("querying old values post mutation is not allowed") } else { value, err = m.Client().OAuth2Client.Get(ctx, id) } @@ -4714,7 +4829,7 @@ func (m OAuth2ClientMutation) Client() *Client { // it returns an error otherwise. func (m OAuth2ClientMutation) Tx() (*Tx, error) { if _, ok := m.driver.(*txDriver); !ok { - return nil, fmt.Errorf("db: mutation is not running in a transaction") + return nil, errors.New("db: mutation is not running in a transaction") } tx := &Tx{config: m.config} tx.init() @@ -4736,6 +4851,25 @@ func (m *OAuth2ClientMutation) ID() (id string, exists bool) { return *m.id, true } +// IDs queries the database and returns the entity ids that match the mutation's predicate. +// That means, if the mutation is applied within a transaction with an isolation level such +// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated +// or updated by the mutation. +func (m *OAuth2ClientMutation) IDs(ctx context.Context) ([]string, error) { + switch { + case m.op.Is(OpUpdateOne | OpDeleteOne): + id, exists := m.ID() + if exists { + return []string{id}, nil + } + fallthrough + case m.op.Is(OpUpdate | OpDelete): + return m.Client().OAuth2Client.Query().Where(m.predicates...).IDs(ctx) + default: + return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) + } +} + // SetSecret sets the "secret" field. func (m *OAuth2ClientMutation) SetSecret(s string) { m.secret = &s @@ -4755,10 +4889,10 @@ func (m *OAuth2ClientMutation) Secret() (r string, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *OAuth2ClientMutation) OldSecret(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldSecret is only allowed on UpdateOne operations") + return v, errors.New("OldSecret is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldSecret requires an ID field in the mutation") + return v, errors.New("OldSecret requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -4791,10 +4925,10 @@ func (m *OAuth2ClientMutation) RedirectUris() (r []string, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *OAuth2ClientMutation) OldRedirectUris(ctx context.Context) (v []string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldRedirectUris is only allowed on UpdateOne operations") + return v, errors.New("OldRedirectUris is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldRedirectUris requires an ID field in the mutation") + return v, errors.New("OldRedirectUris requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -4840,10 +4974,10 @@ func (m *OAuth2ClientMutation) TrustedPeers() (r []string, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *OAuth2ClientMutation) OldTrustedPeers(ctx context.Context) (v []string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldTrustedPeers is only allowed on UpdateOne operations") + return v, errors.New("OldTrustedPeers is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldTrustedPeers requires an ID field in the mutation") + return v, errors.New("OldTrustedPeers requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -4889,10 +5023,10 @@ func (m *OAuth2ClientMutation) Public() (r bool, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *OAuth2ClientMutation) OldPublic(ctx context.Context) (v bool, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldPublic is only allowed on UpdateOne operations") + return v, errors.New("OldPublic is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldPublic requires an ID field in the mutation") + return v, errors.New("OldPublic requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -4925,10 +5059,10 @@ func (m *OAuth2ClientMutation) Name() (r string, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *OAuth2ClientMutation) OldName(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldName is only allowed on UpdateOne operations") + return v, errors.New("OldName is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldName requires an ID field in the mutation") + return v, errors.New("OldName requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -4961,10 +5095,10 @@ func (m *OAuth2ClientMutation) LogoURL() (r string, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *OAuth2ClientMutation) OldLogoURL(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldLogoURL is only allowed on UpdateOne operations") + return v, errors.New("OldLogoURL is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldLogoURL requires an ID field in the mutation") + return v, errors.New("OldLogoURL requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -5288,7 +5422,7 @@ func withOfflineSessionID(id string) offlinesessionOption { m.oldValue = func(ctx context.Context) (*OfflineSession, error) { once.Do(func() { if m.done { - err = fmt.Errorf("querying old values post mutation is not allowed") + err = errors.New("querying old values post mutation is not allowed") } else { value, err = m.Client().OfflineSession.Get(ctx, id) } @@ -5321,7 +5455,7 @@ func (m OfflineSessionMutation) Client() *Client { // it returns an error otherwise. func (m OfflineSessionMutation) Tx() (*Tx, error) { if _, ok := m.driver.(*txDriver); !ok { - return nil, fmt.Errorf("db: mutation is not running in a transaction") + return nil, errors.New("db: mutation is not running in a transaction") } tx := &Tx{config: m.config} tx.init() @@ -5343,6 +5477,25 @@ func (m *OfflineSessionMutation) ID() (id string, exists bool) { return *m.id, true } +// IDs queries the database and returns the entity ids that match the mutation's predicate. +// That means, if the mutation is applied within a transaction with an isolation level such +// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated +// or updated by the mutation. +func (m *OfflineSessionMutation) IDs(ctx context.Context) ([]string, error) { + switch { + case m.op.Is(OpUpdateOne | OpDeleteOne): + id, exists := m.ID() + if exists { + return []string{id}, nil + } + fallthrough + case m.op.Is(OpUpdate | OpDelete): + return m.Client().OfflineSession.Query().Where(m.predicates...).IDs(ctx) + default: + return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) + } +} + // SetUserID sets the "user_id" field. func (m *OfflineSessionMutation) SetUserID(s string) { m.user_id = &s @@ -5362,10 +5515,10 @@ func (m *OfflineSessionMutation) UserID() (r string, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *OfflineSessionMutation) OldUserID(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldUserID is only allowed on UpdateOne operations") + return v, errors.New("OldUserID is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldUserID requires an ID field in the mutation") + return v, errors.New("OldUserID requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -5398,10 +5551,10 @@ func (m *OfflineSessionMutation) ConnID() (r string, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *OfflineSessionMutation) OldConnID(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldConnID is only allowed on UpdateOne operations") + return v, errors.New("OldConnID is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldConnID requires an ID field in the mutation") + return v, errors.New("OldConnID requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -5434,10 +5587,10 @@ func (m *OfflineSessionMutation) Refresh() (r []byte, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *OfflineSessionMutation) OldRefresh(ctx context.Context) (v []byte, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldRefresh is only allowed on UpdateOne operations") + return v, errors.New("OldRefresh is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldRefresh requires an ID field in the mutation") + return v, errors.New("OldRefresh requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -5470,10 +5623,10 @@ func (m *OfflineSessionMutation) ConnectorData() (r []byte, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *OfflineSessionMutation) OldConnectorData(ctx context.Context) (v *[]byte, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldConnectorData is only allowed on UpdateOne operations") + return v, errors.New("OldConnectorData is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldConnectorData requires an ID field in the mutation") + return v, errors.New("OldConnectorData requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -5770,7 +5923,7 @@ func withPasswordID(id int) passwordOption { m.oldValue = func(ctx context.Context) (*Password, error) { once.Do(func() { if m.done { - err = fmt.Errorf("querying old values post mutation is not allowed") + err = errors.New("querying old values post mutation is not allowed") } else { value, err = m.Client().Password.Get(ctx, id) } @@ -5803,7 +5956,7 @@ func (m PasswordMutation) Client() *Client { // it returns an error otherwise. func (m PasswordMutation) Tx() (*Tx, error) { if _, ok := m.driver.(*txDriver); !ok { - return nil, fmt.Errorf("db: mutation is not running in a transaction") + return nil, errors.New("db: mutation is not running in a transaction") } tx := &Tx{config: m.config} tx.init() @@ -5819,6 +5972,25 @@ func (m *PasswordMutation) ID() (id int, exists bool) { return *m.id, true } +// IDs queries the database and returns the entity ids that match the mutation's predicate. +// That means, if the mutation is applied within a transaction with an isolation level such +// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated +// or updated by the mutation. +func (m *PasswordMutation) IDs(ctx context.Context) ([]int, error) { + switch { + case m.op.Is(OpUpdateOne | OpDeleteOne): + id, exists := m.ID() + if exists { + return []int{id}, nil + } + fallthrough + case m.op.Is(OpUpdate | OpDelete): + return m.Client().Password.Query().Where(m.predicates...).IDs(ctx) + default: + return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) + } +} + // SetEmail sets the "email" field. func (m *PasswordMutation) SetEmail(s string) { m.email = &s @@ -5838,10 +6010,10 @@ func (m *PasswordMutation) Email() (r string, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *PasswordMutation) OldEmail(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldEmail is only allowed on UpdateOne operations") + return v, errors.New("OldEmail is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldEmail requires an ID field in the mutation") + return v, errors.New("OldEmail requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -5874,10 +6046,10 @@ func (m *PasswordMutation) Hash() (r []byte, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *PasswordMutation) OldHash(ctx context.Context) (v []byte, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldHash is only allowed on UpdateOne operations") + return v, errors.New("OldHash is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldHash requires an ID field in the mutation") + return v, errors.New("OldHash requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -5910,10 +6082,10 @@ func (m *PasswordMutation) Username() (r string, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *PasswordMutation) OldUsername(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldUsername is only allowed on UpdateOne operations") + return v, errors.New("OldUsername is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldUsername requires an ID field in the mutation") + return v, errors.New("OldUsername requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -5946,10 +6118,10 @@ func (m *PasswordMutation) UserID() (r string, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *PasswordMutation) OldUserID(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldUserID is only allowed on UpdateOne operations") + return v, errors.New("OldUserID is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldUserID requires an ID field in the mutation") + return v, errors.New("OldUserID requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -6235,7 +6407,7 @@ func withRefreshTokenID(id string) refreshtokenOption { m.oldValue = func(ctx context.Context) (*RefreshToken, error) { once.Do(func() { if m.done { - err = fmt.Errorf("querying old values post mutation is not allowed") + err = errors.New("querying old values post mutation is not allowed") } else { value, err = m.Client().RefreshToken.Get(ctx, id) } @@ -6268,7 +6440,7 @@ func (m RefreshTokenMutation) Client() *Client { // it returns an error otherwise. func (m RefreshTokenMutation) Tx() (*Tx, error) { if _, ok := m.driver.(*txDriver); !ok { - return nil, fmt.Errorf("db: mutation is not running in a transaction") + return nil, errors.New("db: mutation is not running in a transaction") } tx := &Tx{config: m.config} tx.init() @@ -6290,6 +6462,25 @@ func (m *RefreshTokenMutation) ID() (id string, exists bool) { return *m.id, true } +// IDs queries the database and returns the entity ids that match the mutation's predicate. +// That means, if the mutation is applied within a transaction with an isolation level such +// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated +// or updated by the mutation. +func (m *RefreshTokenMutation) IDs(ctx context.Context) ([]string, error) { + switch { + case m.op.Is(OpUpdateOne | OpDeleteOne): + id, exists := m.ID() + if exists { + return []string{id}, nil + } + fallthrough + case m.op.Is(OpUpdate | OpDelete): + return m.Client().RefreshToken.Query().Where(m.predicates...).IDs(ctx) + default: + return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) + } +} + // SetClientID sets the "client_id" field. func (m *RefreshTokenMutation) SetClientID(s string) { m.client_id = &s @@ -6309,10 +6500,10 @@ func (m *RefreshTokenMutation) ClientID() (r string, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *RefreshTokenMutation) OldClientID(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldClientID is only allowed on UpdateOne operations") + return v, errors.New("OldClientID is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldClientID requires an ID field in the mutation") + return v, errors.New("OldClientID requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -6345,10 +6536,10 @@ func (m *RefreshTokenMutation) Scopes() (r []string, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *RefreshTokenMutation) OldScopes(ctx context.Context) (v []string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldScopes is only allowed on UpdateOne operations") + return v, errors.New("OldScopes is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldScopes requires an ID field in the mutation") + return v, errors.New("OldScopes requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -6394,10 +6585,10 @@ func (m *RefreshTokenMutation) Nonce() (r string, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *RefreshTokenMutation) OldNonce(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldNonce is only allowed on UpdateOne operations") + return v, errors.New("OldNonce is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldNonce requires an ID field in the mutation") + return v, errors.New("OldNonce requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -6430,10 +6621,10 @@ func (m *RefreshTokenMutation) ClaimsUserID() (r string, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *RefreshTokenMutation) OldClaimsUserID(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldClaimsUserID is only allowed on UpdateOne operations") + return v, errors.New("OldClaimsUserID is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldClaimsUserID requires an ID field in the mutation") + return v, errors.New("OldClaimsUserID requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -6466,10 +6657,10 @@ func (m *RefreshTokenMutation) ClaimsUsername() (r string, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *RefreshTokenMutation) OldClaimsUsername(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldClaimsUsername is only allowed on UpdateOne operations") + return v, errors.New("OldClaimsUsername is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldClaimsUsername requires an ID field in the mutation") + return v, errors.New("OldClaimsUsername requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -6502,10 +6693,10 @@ func (m *RefreshTokenMutation) ClaimsEmail() (r string, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *RefreshTokenMutation) OldClaimsEmail(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldClaimsEmail is only allowed on UpdateOne operations") + return v, errors.New("OldClaimsEmail is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldClaimsEmail requires an ID field in the mutation") + return v, errors.New("OldClaimsEmail requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -6538,10 +6729,10 @@ func (m *RefreshTokenMutation) ClaimsEmailVerified() (r bool, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *RefreshTokenMutation) OldClaimsEmailVerified(ctx context.Context) (v bool, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldClaimsEmailVerified is only allowed on UpdateOne operations") + return v, errors.New("OldClaimsEmailVerified is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldClaimsEmailVerified requires an ID field in the mutation") + return v, errors.New("OldClaimsEmailVerified requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -6574,10 +6765,10 @@ func (m *RefreshTokenMutation) ClaimsGroups() (r []string, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *RefreshTokenMutation) OldClaimsGroups(ctx context.Context) (v []string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldClaimsGroups is only allowed on UpdateOne operations") + return v, errors.New("OldClaimsGroups is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldClaimsGroups requires an ID field in the mutation") + return v, errors.New("OldClaimsGroups requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -6623,10 +6814,10 @@ func (m *RefreshTokenMutation) ClaimsPreferredUsername() (r string, exists bool) // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *RefreshTokenMutation) OldClaimsPreferredUsername(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldClaimsPreferredUsername is only allowed on UpdateOne operations") + return v, errors.New("OldClaimsPreferredUsername is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldClaimsPreferredUsername requires an ID field in the mutation") + return v, errors.New("OldClaimsPreferredUsername requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -6659,10 +6850,10 @@ func (m *RefreshTokenMutation) ConnectorID() (r string, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *RefreshTokenMutation) OldConnectorID(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldConnectorID is only allowed on UpdateOne operations") + return v, errors.New("OldConnectorID is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldConnectorID requires an ID field in the mutation") + return v, errors.New("OldConnectorID requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -6695,10 +6886,10 @@ func (m *RefreshTokenMutation) ConnectorData() (r []byte, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *RefreshTokenMutation) OldConnectorData(ctx context.Context) (v *[]byte, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldConnectorData is only allowed on UpdateOne operations") + return v, errors.New("OldConnectorData is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldConnectorData requires an ID field in the mutation") + return v, errors.New("OldConnectorData requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -6744,10 +6935,10 @@ func (m *RefreshTokenMutation) Token() (r string, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *RefreshTokenMutation) OldToken(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldToken is only allowed on UpdateOne operations") + return v, errors.New("OldToken is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldToken requires an ID field in the mutation") + return v, errors.New("OldToken requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -6780,10 +6971,10 @@ func (m *RefreshTokenMutation) ObsoleteToken() (r string, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *RefreshTokenMutation) OldObsoleteToken(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldObsoleteToken is only allowed on UpdateOne operations") + return v, errors.New("OldObsoleteToken is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldObsoleteToken requires an ID field in the mutation") + return v, errors.New("OldObsoleteToken requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -6816,10 +7007,10 @@ func (m *RefreshTokenMutation) CreatedAt() (r time.Time, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *RefreshTokenMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldCreatedAt is only allowed on UpdateOne operations") + return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldCreatedAt requires an ID field in the mutation") + return v, errors.New("OldCreatedAt requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { @@ -6852,10 +7043,10 @@ func (m *RefreshTokenMutation) LastUsed() (r time.Time, exists bool) { // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *RefreshTokenMutation) OldLastUsed(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldLastUsed is only allowed on UpdateOne operations") + return v, errors.New("OldLastUsed is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldLastUsed requires an ID field in the mutation") + return v, errors.New("OldLastUsed requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { diff --git a/storage/ent/db/oauth2client_create.go b/storage/ent/db/oauth2client_create.go index b141352b..4c64b11b 100644 --- a/storage/ent/db/oauth2client_create.go +++ b/storage/ent/db/oauth2client_create.go @@ -132,35 +132,35 @@ func (oc *OAuth2ClientCreate) ExecX(ctx context.Context) { // check runs all checks and user-defined validators on the builder. func (oc *OAuth2ClientCreate) check() error { if _, ok := oc.mutation.Secret(); !ok { - return &ValidationError{Name: "secret", err: errors.New(`db: missing required field "secret"`)} + return &ValidationError{Name: "secret", err: errors.New(`db: missing required field "OAuth2Client.secret"`)} } if v, ok := oc.mutation.Secret(); ok { if err := oauth2client.SecretValidator(v); err != nil { - return &ValidationError{Name: "secret", err: fmt.Errorf(`db: validator failed for field "secret": %w`, err)} + return &ValidationError{Name: "secret", err: fmt.Errorf(`db: validator failed for field "OAuth2Client.secret": %w`, err)} } } if _, ok := oc.mutation.Public(); !ok { - return &ValidationError{Name: "public", err: errors.New(`db: missing required field "public"`)} + return &ValidationError{Name: "public", err: errors.New(`db: missing required field "OAuth2Client.public"`)} } if _, ok := oc.mutation.Name(); !ok { - return &ValidationError{Name: "name", err: errors.New(`db: missing required field "name"`)} + return &ValidationError{Name: "name", err: errors.New(`db: missing required field "OAuth2Client.name"`)} } if v, ok := oc.mutation.Name(); ok { if err := oauth2client.NameValidator(v); err != nil { - return &ValidationError{Name: "name", err: fmt.Errorf(`db: validator failed for field "name": %w`, err)} + return &ValidationError{Name: "name", err: fmt.Errorf(`db: validator failed for field "OAuth2Client.name": %w`, err)} } } if _, ok := oc.mutation.LogoURL(); !ok { - return &ValidationError{Name: "logo_url", err: errors.New(`db: missing required field "logo_url"`)} + return &ValidationError{Name: "logo_url", err: errors.New(`db: missing required field "OAuth2Client.logo_url"`)} } if v, ok := oc.mutation.LogoURL(); ok { if err := oauth2client.LogoURLValidator(v); err != nil { - return &ValidationError{Name: "logo_url", err: fmt.Errorf(`db: validator failed for field "logo_url": %w`, err)} + return &ValidationError{Name: "logo_url", err: fmt.Errorf(`db: validator failed for field "OAuth2Client.logo_url": %w`, err)} } } if v, ok := oc.mutation.ID(); ok { if err := oauth2client.IDValidator(v); err != nil { - return &ValidationError{Name: "id", err: fmt.Errorf(`db: validator failed for field "id": %w`, err)} + return &ValidationError{Name: "id", err: fmt.Errorf(`db: validator failed for field "OAuth2Client.id": %w`, err)} } } return nil @@ -174,6 +174,13 @@ func (oc *OAuth2ClientCreate) sqlSave(ctx context.Context) (*OAuth2Client, error } return nil, err } + if _spec.ID.Value != nil { + if id, ok := _spec.ID.Value.(string); ok { + _node.ID = id + } else { + return nil, fmt.Errorf("unexpected OAuth2Client.ID type: %T", _spec.ID.Value) + } + } return _node, nil } diff --git a/storage/ent/db/oauth2client_query.go b/storage/ent/db/oauth2client_query.go index d2363288..d66607ab 100644 --- a/storage/ent/db/oauth2client_query.go +++ b/storage/ent/db/oauth2client_query.go @@ -106,7 +106,7 @@ func (oq *OAuth2ClientQuery) FirstIDX(ctx context.Context) string { } // Only returns a single OAuth2Client entity found by the query, ensuring it only returns one. -// Returns a *NotSingularError when exactly one OAuth2Client entity is not found. +// Returns a *NotSingularError when more than one OAuth2Client entity is found. // Returns a *NotFoundError when no OAuth2Client entities are found. func (oq *OAuth2ClientQuery) Only(ctx context.Context) (*OAuth2Client, error) { nodes, err := oq.Limit(2).All(ctx) @@ -133,7 +133,7 @@ func (oq *OAuth2ClientQuery) OnlyX(ctx context.Context) *OAuth2Client { } // OnlyID is like Only, but returns the only OAuth2Client ID in the query. -// Returns a *NotSingularError when exactly one OAuth2Client ID is not found. +// Returns a *NotSingularError when more than one OAuth2Client ID is found. // Returns a *NotFoundError when no entities are found. func (oq *OAuth2ClientQuery) OnlyID(ctx context.Context) (id string, err error) { var ids []string @@ -242,8 +242,9 @@ func (oq *OAuth2ClientQuery) Clone() *OAuth2ClientQuery { order: append([]OrderFunc{}, oq.order...), predicates: append([]predicate.OAuth2Client{}, oq.predicates...), // clone intermediate query. - sql: oq.sql.Clone(), - path: oq.path, + sql: oq.sql.Clone(), + path: oq.path, + unique: oq.unique, } } @@ -336,6 +337,10 @@ func (oq *OAuth2ClientQuery) sqlAll(ctx context.Context) ([]*OAuth2Client, error func (oq *OAuth2ClientQuery) sqlCount(ctx context.Context) (int, error) { _spec := oq.querySpec() + _spec.Node.Columns = oq.fields + if len(oq.fields) > 0 { + _spec.Unique = oq.unique != nil && *oq.unique + } return sqlgraph.CountNodes(ctx, oq.driver, _spec) } @@ -407,6 +412,9 @@ func (oq *OAuth2ClientQuery) sqlQuery(ctx context.Context) *sql.Selector { selector = oq.sql selector.Select(selector.Columns(columns...)...) } + if oq.unique != nil && *oq.unique { + selector.Distinct() + } for _, p := range oq.predicates { p(selector) } @@ -685,9 +693,7 @@ func (ogb *OAuth2ClientGroupBy) sqlQuery() *sql.Selector { for _, f := range ogb.fields { columns = append(columns, selector.C(f)) } - for _, c := range aggregation { - columns = append(columns, c) - } + columns = append(columns, aggregation...) selector.Select(columns...) } return selector.GroupBy(selector.Columns(ogb.fields...)...) diff --git a/storage/ent/db/oauth2client_update.go b/storage/ent/db/oauth2client_update.go index 29b7f090..b86c5491 100644 --- a/storage/ent/db/oauth2client_update.go +++ b/storage/ent/db/oauth2client_update.go @@ -4,6 +4,7 @@ package db import ( "context" + "errors" "fmt" "entgo.io/ent/dialect/sql" @@ -143,17 +144,17 @@ func (ou *OAuth2ClientUpdate) ExecX(ctx context.Context) { func (ou *OAuth2ClientUpdate) check() error { if v, ok := ou.mutation.Secret(); ok { if err := oauth2client.SecretValidator(v); err != nil { - return &ValidationError{Name: "secret", err: fmt.Errorf("db: validator failed for field \"secret\": %w", err)} + return &ValidationError{Name: "secret", err: fmt.Errorf(`db: validator failed for field "OAuth2Client.secret": %w`, err)} } } if v, ok := ou.mutation.Name(); ok { if err := oauth2client.NameValidator(v); err != nil { - return &ValidationError{Name: "name", err: fmt.Errorf("db: validator failed for field \"name\": %w", err)} + return &ValidationError{Name: "name", err: fmt.Errorf(`db: validator failed for field "OAuth2Client.name": %w`, err)} } } if v, ok := ou.mutation.LogoURL(); ok { if err := oauth2client.LogoURLValidator(v); err != nil { - return &ValidationError{Name: "logo_url", err: fmt.Errorf("db: validator failed for field \"logo_url\": %w", err)} + return &ValidationError{Name: "logo_url", err: fmt.Errorf(`db: validator failed for field "OAuth2Client.logo_url": %w`, err)} } } return nil @@ -374,17 +375,17 @@ func (ouo *OAuth2ClientUpdateOne) ExecX(ctx context.Context) { func (ouo *OAuth2ClientUpdateOne) check() error { if v, ok := ouo.mutation.Secret(); ok { if err := oauth2client.SecretValidator(v); err != nil { - return &ValidationError{Name: "secret", err: fmt.Errorf("db: validator failed for field \"secret\": %w", err)} + return &ValidationError{Name: "secret", err: fmt.Errorf(`db: validator failed for field "OAuth2Client.secret": %w`, err)} } } if v, ok := ouo.mutation.Name(); ok { if err := oauth2client.NameValidator(v); err != nil { - return &ValidationError{Name: "name", err: fmt.Errorf("db: validator failed for field \"name\": %w", err)} + return &ValidationError{Name: "name", err: fmt.Errorf(`db: validator failed for field "OAuth2Client.name": %w`, err)} } } if v, ok := ouo.mutation.LogoURL(); ok { if err := oauth2client.LogoURLValidator(v); err != nil { - return &ValidationError{Name: "logo_url", err: fmt.Errorf("db: validator failed for field \"logo_url\": %w", err)} + return &ValidationError{Name: "logo_url", err: fmt.Errorf(`db: validator failed for field "OAuth2Client.logo_url": %w`, err)} } } return nil @@ -403,7 +404,7 @@ func (ouo *OAuth2ClientUpdateOne) sqlSave(ctx context.Context) (_node *OAuth2Cli } id, ok := ouo.mutation.ID() if !ok { - return nil, &ValidationError{Name: "ID", err: fmt.Errorf("missing OAuth2Client.ID for update")} + return nil, &ValidationError{Name: "id", err: errors.New(`db: missing "OAuth2Client.id" for update`)} } _spec.Node.ID.Value = id if fields := ouo.fields; len(fields) > 0 { diff --git a/storage/ent/db/offlinesession_create.go b/storage/ent/db/offlinesession_create.go index add3912a..74bb3213 100644 --- a/storage/ent/db/offlinesession_create.go +++ b/storage/ent/db/offlinesession_create.go @@ -120,27 +120,27 @@ func (osc *OfflineSessionCreate) ExecX(ctx context.Context) { // check runs all checks and user-defined validators on the builder. func (osc *OfflineSessionCreate) check() error { if _, ok := osc.mutation.UserID(); !ok { - return &ValidationError{Name: "user_id", err: errors.New(`db: missing required field "user_id"`)} + return &ValidationError{Name: "user_id", err: errors.New(`db: missing required field "OfflineSession.user_id"`)} } if v, ok := osc.mutation.UserID(); ok { if err := offlinesession.UserIDValidator(v); err != nil { - return &ValidationError{Name: "user_id", err: fmt.Errorf(`db: validator failed for field "user_id": %w`, err)} + return &ValidationError{Name: "user_id", err: fmt.Errorf(`db: validator failed for field "OfflineSession.user_id": %w`, err)} } } if _, ok := osc.mutation.ConnID(); !ok { - return &ValidationError{Name: "conn_id", err: errors.New(`db: missing required field "conn_id"`)} + return &ValidationError{Name: "conn_id", err: errors.New(`db: missing required field "OfflineSession.conn_id"`)} } if v, ok := osc.mutation.ConnID(); ok { if err := offlinesession.ConnIDValidator(v); err != nil { - return &ValidationError{Name: "conn_id", err: fmt.Errorf(`db: validator failed for field "conn_id": %w`, err)} + return &ValidationError{Name: "conn_id", err: fmt.Errorf(`db: validator failed for field "OfflineSession.conn_id": %w`, err)} } } if _, ok := osc.mutation.Refresh(); !ok { - return &ValidationError{Name: "refresh", err: errors.New(`db: missing required field "refresh"`)} + return &ValidationError{Name: "refresh", err: errors.New(`db: missing required field "OfflineSession.refresh"`)} } if v, ok := osc.mutation.ID(); ok { if err := offlinesession.IDValidator(v); err != nil { - return &ValidationError{Name: "id", err: fmt.Errorf(`db: validator failed for field "id": %w`, err)} + return &ValidationError{Name: "id", err: fmt.Errorf(`db: validator failed for field "OfflineSession.id": %w`, err)} } } return nil @@ -154,6 +154,13 @@ func (osc *OfflineSessionCreate) sqlSave(ctx context.Context) (*OfflineSession, } return nil, err } + if _spec.ID.Value != nil { + if id, ok := _spec.ID.Value.(string); ok { + _node.ID = id + } else { + return nil, fmt.Errorf("unexpected OfflineSession.ID type: %T", _spec.ID.Value) + } + } return _node, nil } diff --git a/storage/ent/db/offlinesession_query.go b/storage/ent/db/offlinesession_query.go index 4306deaa..f40e2255 100644 --- a/storage/ent/db/offlinesession_query.go +++ b/storage/ent/db/offlinesession_query.go @@ -106,7 +106,7 @@ func (osq *OfflineSessionQuery) FirstIDX(ctx context.Context) string { } // Only returns a single OfflineSession entity found by the query, ensuring it only returns one. -// Returns a *NotSingularError when exactly one OfflineSession entity is not found. +// Returns a *NotSingularError when more than one OfflineSession entity is found. // Returns a *NotFoundError when no OfflineSession entities are found. func (osq *OfflineSessionQuery) Only(ctx context.Context) (*OfflineSession, error) { nodes, err := osq.Limit(2).All(ctx) @@ -133,7 +133,7 @@ func (osq *OfflineSessionQuery) OnlyX(ctx context.Context) *OfflineSession { } // OnlyID is like Only, but returns the only OfflineSession ID in the query. -// Returns a *NotSingularError when exactly one OfflineSession ID is not found. +// Returns a *NotSingularError when more than one OfflineSession ID is found. // Returns a *NotFoundError when no entities are found. func (osq *OfflineSessionQuery) OnlyID(ctx context.Context) (id string, err error) { var ids []string @@ -242,8 +242,9 @@ func (osq *OfflineSessionQuery) Clone() *OfflineSessionQuery { order: append([]OrderFunc{}, osq.order...), predicates: append([]predicate.OfflineSession{}, osq.predicates...), // clone intermediate query. - sql: osq.sql.Clone(), - path: osq.path, + sql: osq.sql.Clone(), + path: osq.path, + unique: osq.unique, } } @@ -336,6 +337,10 @@ func (osq *OfflineSessionQuery) sqlAll(ctx context.Context) ([]*OfflineSession, func (osq *OfflineSessionQuery) sqlCount(ctx context.Context) (int, error) { _spec := osq.querySpec() + _spec.Node.Columns = osq.fields + if len(osq.fields) > 0 { + _spec.Unique = osq.unique != nil && *osq.unique + } return sqlgraph.CountNodes(ctx, osq.driver, _spec) } @@ -407,6 +412,9 @@ func (osq *OfflineSessionQuery) sqlQuery(ctx context.Context) *sql.Selector { selector = osq.sql selector.Select(selector.Columns(columns...)...) } + if osq.unique != nil && *osq.unique { + selector.Distinct() + } for _, p := range osq.predicates { p(selector) } @@ -685,9 +693,7 @@ func (osgb *OfflineSessionGroupBy) sqlQuery() *sql.Selector { for _, f := range osgb.fields { columns = append(columns, selector.C(f)) } - for _, c := range aggregation { - columns = append(columns, c) - } + columns = append(columns, aggregation...) selector.Select(columns...) } return selector.GroupBy(selector.Columns(osgb.fields...)...) diff --git a/storage/ent/db/offlinesession_update.go b/storage/ent/db/offlinesession_update.go index 20c9faf3..e19f5a05 100644 --- a/storage/ent/db/offlinesession_update.go +++ b/storage/ent/db/offlinesession_update.go @@ -4,6 +4,7 @@ package db import ( "context" + "errors" "fmt" "entgo.io/ent/dialect/sql" @@ -125,12 +126,12 @@ func (osu *OfflineSessionUpdate) ExecX(ctx context.Context) { func (osu *OfflineSessionUpdate) check() error { if v, ok := osu.mutation.UserID(); ok { if err := offlinesession.UserIDValidator(v); err != nil { - return &ValidationError{Name: "user_id", err: fmt.Errorf("db: validator failed for field \"user_id\": %w", err)} + return &ValidationError{Name: "user_id", err: fmt.Errorf(`db: validator failed for field "OfflineSession.user_id": %w`, err)} } } if v, ok := osu.mutation.ConnID(); ok { if err := offlinesession.ConnIDValidator(v); err != nil { - return &ValidationError{Name: "conn_id", err: fmt.Errorf("db: validator failed for field \"conn_id\": %w", err)} + return &ValidationError{Name: "conn_id", err: fmt.Errorf(`db: validator failed for field "OfflineSession.conn_id": %w`, err)} } } return nil @@ -313,12 +314,12 @@ func (osuo *OfflineSessionUpdateOne) ExecX(ctx context.Context) { func (osuo *OfflineSessionUpdateOne) check() error { if v, ok := osuo.mutation.UserID(); ok { if err := offlinesession.UserIDValidator(v); err != nil { - return &ValidationError{Name: "user_id", err: fmt.Errorf("db: validator failed for field \"user_id\": %w", err)} + return &ValidationError{Name: "user_id", err: fmt.Errorf(`db: validator failed for field "OfflineSession.user_id": %w`, err)} } } if v, ok := osuo.mutation.ConnID(); ok { if err := offlinesession.ConnIDValidator(v); err != nil { - return &ValidationError{Name: "conn_id", err: fmt.Errorf("db: validator failed for field \"conn_id\": %w", err)} + return &ValidationError{Name: "conn_id", err: fmt.Errorf(`db: validator failed for field "OfflineSession.conn_id": %w`, err)} } } return nil @@ -337,7 +338,7 @@ func (osuo *OfflineSessionUpdateOne) sqlSave(ctx context.Context) (_node *Offlin } id, ok := osuo.mutation.ID() if !ok { - return nil, &ValidationError{Name: "ID", err: fmt.Errorf("missing OfflineSession.ID for update")} + return nil, &ValidationError{Name: "id", err: errors.New(`db: missing "OfflineSession.id" for update`)} } _spec.Node.ID.Value = id if fields := osuo.fields; len(fields) > 0 { diff --git a/storage/ent/db/password_create.go b/storage/ent/db/password_create.go index af902ea3..fa356dca 100644 --- a/storage/ent/db/password_create.go +++ b/storage/ent/db/password_create.go @@ -114,30 +114,30 @@ func (pc *PasswordCreate) ExecX(ctx context.Context) { // check runs all checks and user-defined validators on the builder. func (pc *PasswordCreate) check() error { if _, ok := pc.mutation.Email(); !ok { - return &ValidationError{Name: "email", err: errors.New(`db: missing required field "email"`)} + return &ValidationError{Name: "email", err: errors.New(`db: missing required field "Password.email"`)} } if v, ok := pc.mutation.Email(); ok { if err := password.EmailValidator(v); err != nil { - return &ValidationError{Name: "email", err: fmt.Errorf(`db: validator failed for field "email": %w`, err)} + return &ValidationError{Name: "email", err: fmt.Errorf(`db: validator failed for field "Password.email": %w`, err)} } } if _, ok := pc.mutation.Hash(); !ok { - return &ValidationError{Name: "hash", err: errors.New(`db: missing required field "hash"`)} + return &ValidationError{Name: "hash", err: errors.New(`db: missing required field "Password.hash"`)} } if _, ok := pc.mutation.Username(); !ok { - return &ValidationError{Name: "username", err: errors.New(`db: missing required field "username"`)} + return &ValidationError{Name: "username", err: errors.New(`db: missing required field "Password.username"`)} } if v, ok := pc.mutation.Username(); ok { if err := password.UsernameValidator(v); err != nil { - return &ValidationError{Name: "username", err: fmt.Errorf(`db: validator failed for field "username": %w`, err)} + return &ValidationError{Name: "username", err: fmt.Errorf(`db: validator failed for field "Password.username": %w`, err)} } } if _, ok := pc.mutation.UserID(); !ok { - return &ValidationError{Name: "user_id", err: errors.New(`db: missing required field "user_id"`)} + return &ValidationError{Name: "user_id", err: errors.New(`db: missing required field "Password.user_id"`)} } if v, ok := pc.mutation.UserID(); ok { if err := password.UserIDValidator(v); err != nil { - return &ValidationError{Name: "user_id", err: fmt.Errorf(`db: validator failed for field "user_id": %w`, err)} + return &ValidationError{Name: "user_id", err: fmt.Errorf(`db: validator failed for field "Password.user_id": %w`, err)} } } return nil diff --git a/storage/ent/db/password_query.go b/storage/ent/db/password_query.go index 50e493fd..99b1af76 100644 --- a/storage/ent/db/password_query.go +++ b/storage/ent/db/password_query.go @@ -106,7 +106,7 @@ func (pq *PasswordQuery) FirstIDX(ctx context.Context) int { } // Only returns a single Password entity found by the query, ensuring it only returns one. -// Returns a *NotSingularError when exactly one Password entity is not found. +// Returns a *NotSingularError when more than one Password entity is found. // Returns a *NotFoundError when no Password entities are found. func (pq *PasswordQuery) Only(ctx context.Context) (*Password, error) { nodes, err := pq.Limit(2).All(ctx) @@ -133,7 +133,7 @@ func (pq *PasswordQuery) OnlyX(ctx context.Context) *Password { } // OnlyID is like Only, but returns the only Password ID in the query. -// Returns a *NotSingularError when exactly one Password ID is not found. +// Returns a *NotSingularError when more than one Password ID is found. // Returns a *NotFoundError when no entities are found. func (pq *PasswordQuery) OnlyID(ctx context.Context) (id int, err error) { var ids []int @@ -242,8 +242,9 @@ func (pq *PasswordQuery) Clone() *PasswordQuery { order: append([]OrderFunc{}, pq.order...), predicates: append([]predicate.Password{}, pq.predicates...), // clone intermediate query. - sql: pq.sql.Clone(), - path: pq.path, + sql: pq.sql.Clone(), + path: pq.path, + unique: pq.unique, } } @@ -336,6 +337,10 @@ func (pq *PasswordQuery) sqlAll(ctx context.Context) ([]*Password, error) { func (pq *PasswordQuery) sqlCount(ctx context.Context) (int, error) { _spec := pq.querySpec() + _spec.Node.Columns = pq.fields + if len(pq.fields) > 0 { + _spec.Unique = pq.unique != nil && *pq.unique + } return sqlgraph.CountNodes(ctx, pq.driver, _spec) } @@ -407,6 +412,9 @@ func (pq *PasswordQuery) sqlQuery(ctx context.Context) *sql.Selector { selector = pq.sql selector.Select(selector.Columns(columns...)...) } + if pq.unique != nil && *pq.unique { + selector.Distinct() + } for _, p := range pq.predicates { p(selector) } @@ -685,9 +693,7 @@ func (pgb *PasswordGroupBy) sqlQuery() *sql.Selector { for _, f := range pgb.fields { columns = append(columns, selector.C(f)) } - for _, c := range aggregation { - columns = append(columns, c) - } + columns = append(columns, aggregation...) selector.Select(columns...) } return selector.GroupBy(selector.Columns(pgb.fields...)...) diff --git a/storage/ent/db/password_update.go b/storage/ent/db/password_update.go index f15fb017..f1c376af 100644 --- a/storage/ent/db/password_update.go +++ b/storage/ent/db/password_update.go @@ -4,6 +4,7 @@ package db import ( "context" + "errors" "fmt" "entgo.io/ent/dialect/sql" @@ -119,17 +120,17 @@ func (pu *PasswordUpdate) ExecX(ctx context.Context) { func (pu *PasswordUpdate) check() error { if v, ok := pu.mutation.Email(); ok { if err := password.EmailValidator(v); err != nil { - return &ValidationError{Name: "email", err: fmt.Errorf("db: validator failed for field \"email\": %w", err)} + return &ValidationError{Name: "email", err: fmt.Errorf(`db: validator failed for field "Password.email": %w`, err)} } } if v, ok := pu.mutation.Username(); ok { if err := password.UsernameValidator(v); err != nil { - return &ValidationError{Name: "username", err: fmt.Errorf("db: validator failed for field \"username\": %w", err)} + return &ValidationError{Name: "username", err: fmt.Errorf(`db: validator failed for field "Password.username": %w`, err)} } } if v, ok := pu.mutation.UserID(); ok { if err := password.UserIDValidator(v); err != nil { - return &ValidationError{Name: "user_id", err: fmt.Errorf("db: validator failed for field \"user_id\": %w", err)} + return &ValidationError{Name: "user_id", err: fmt.Errorf(`db: validator failed for field "Password.user_id": %w`, err)} } } return nil @@ -300,17 +301,17 @@ func (puo *PasswordUpdateOne) ExecX(ctx context.Context) { func (puo *PasswordUpdateOne) check() error { if v, ok := puo.mutation.Email(); ok { if err := password.EmailValidator(v); err != nil { - return &ValidationError{Name: "email", err: fmt.Errorf("db: validator failed for field \"email\": %w", err)} + return &ValidationError{Name: "email", err: fmt.Errorf(`db: validator failed for field "Password.email": %w`, err)} } } if v, ok := puo.mutation.Username(); ok { if err := password.UsernameValidator(v); err != nil { - return &ValidationError{Name: "username", err: fmt.Errorf("db: validator failed for field \"username\": %w", err)} + return &ValidationError{Name: "username", err: fmt.Errorf(`db: validator failed for field "Password.username": %w`, err)} } } if v, ok := puo.mutation.UserID(); ok { if err := password.UserIDValidator(v); err != nil { - return &ValidationError{Name: "user_id", err: fmt.Errorf("db: validator failed for field \"user_id\": %w", err)} + return &ValidationError{Name: "user_id", err: fmt.Errorf(`db: validator failed for field "Password.user_id": %w`, err)} } } return nil @@ -329,7 +330,7 @@ func (puo *PasswordUpdateOne) sqlSave(ctx context.Context) (_node *Password, err } id, ok := puo.mutation.ID() if !ok { - return nil, &ValidationError{Name: "ID", err: fmt.Errorf("missing Password.ID for update")} + return nil, &ValidationError{Name: "id", err: errors.New(`db: missing "Password.id" for update`)} } _spec.Node.ID.Value = id if fields := puo.fields; len(fields) > 0 { diff --git a/storage/ent/db/refreshtoken_create.go b/storage/ent/db/refreshtoken_create.go index 00d29775..7e925f37 100644 --- a/storage/ent/db/refreshtoken_create.go +++ b/storage/ent/db/refreshtoken_create.go @@ -252,74 +252,74 @@ func (rtc *RefreshTokenCreate) defaults() { // check runs all checks and user-defined validators on the builder. func (rtc *RefreshTokenCreate) check() error { if _, ok := rtc.mutation.ClientID(); !ok { - return &ValidationError{Name: "client_id", err: errors.New(`db: missing required field "client_id"`)} + return &ValidationError{Name: "client_id", err: errors.New(`db: missing required field "RefreshToken.client_id"`)} } if v, ok := rtc.mutation.ClientID(); ok { if err := refreshtoken.ClientIDValidator(v); err != nil { - return &ValidationError{Name: "client_id", err: fmt.Errorf(`db: validator failed for field "client_id": %w`, err)} + return &ValidationError{Name: "client_id", err: fmt.Errorf(`db: validator failed for field "RefreshToken.client_id": %w`, err)} } } if _, ok := rtc.mutation.Nonce(); !ok { - return &ValidationError{Name: "nonce", err: errors.New(`db: missing required field "nonce"`)} + return &ValidationError{Name: "nonce", err: errors.New(`db: missing required field "RefreshToken.nonce"`)} } if v, ok := rtc.mutation.Nonce(); ok { if err := refreshtoken.NonceValidator(v); err != nil { - return &ValidationError{Name: "nonce", err: fmt.Errorf(`db: validator failed for field "nonce": %w`, err)} + return &ValidationError{Name: "nonce", err: fmt.Errorf(`db: validator failed for field "RefreshToken.nonce": %w`, err)} } } if _, ok := rtc.mutation.ClaimsUserID(); !ok { - return &ValidationError{Name: "claims_user_id", err: errors.New(`db: missing required field "claims_user_id"`)} + return &ValidationError{Name: "claims_user_id", err: errors.New(`db: missing required field "RefreshToken.claims_user_id"`)} } if v, ok := rtc.mutation.ClaimsUserID(); ok { if err := refreshtoken.ClaimsUserIDValidator(v); err != nil { - return &ValidationError{Name: "claims_user_id", err: fmt.Errorf(`db: validator failed for field "claims_user_id": %w`, err)} + return &ValidationError{Name: "claims_user_id", err: fmt.Errorf(`db: validator failed for field "RefreshToken.claims_user_id": %w`, err)} } } if _, ok := rtc.mutation.ClaimsUsername(); !ok { - return &ValidationError{Name: "claims_username", err: errors.New(`db: missing required field "claims_username"`)} + return &ValidationError{Name: "claims_username", err: errors.New(`db: missing required field "RefreshToken.claims_username"`)} } if v, ok := rtc.mutation.ClaimsUsername(); ok { if err := refreshtoken.ClaimsUsernameValidator(v); err != nil { - return &ValidationError{Name: "claims_username", err: fmt.Errorf(`db: validator failed for field "claims_username": %w`, err)} + return &ValidationError{Name: "claims_username", err: fmt.Errorf(`db: validator failed for field "RefreshToken.claims_username": %w`, err)} } } if _, ok := rtc.mutation.ClaimsEmail(); !ok { - return &ValidationError{Name: "claims_email", err: errors.New(`db: missing required field "claims_email"`)} + return &ValidationError{Name: "claims_email", err: errors.New(`db: missing required field "RefreshToken.claims_email"`)} } if v, ok := rtc.mutation.ClaimsEmail(); ok { if err := refreshtoken.ClaimsEmailValidator(v); err != nil { - return &ValidationError{Name: "claims_email", err: fmt.Errorf(`db: validator failed for field "claims_email": %w`, err)} + return &ValidationError{Name: "claims_email", err: fmt.Errorf(`db: validator failed for field "RefreshToken.claims_email": %w`, err)} } } if _, ok := rtc.mutation.ClaimsEmailVerified(); !ok { - return &ValidationError{Name: "claims_email_verified", err: errors.New(`db: missing required field "claims_email_verified"`)} + return &ValidationError{Name: "claims_email_verified", err: errors.New(`db: missing required field "RefreshToken.claims_email_verified"`)} } if _, ok := rtc.mutation.ClaimsPreferredUsername(); !ok { - return &ValidationError{Name: "claims_preferred_username", err: errors.New(`db: missing required field "claims_preferred_username"`)} + return &ValidationError{Name: "claims_preferred_username", err: errors.New(`db: missing required field "RefreshToken.claims_preferred_username"`)} } if _, ok := rtc.mutation.ConnectorID(); !ok { - return &ValidationError{Name: "connector_id", err: errors.New(`db: missing required field "connector_id"`)} + return &ValidationError{Name: "connector_id", err: errors.New(`db: missing required field "RefreshToken.connector_id"`)} } if v, ok := rtc.mutation.ConnectorID(); ok { if err := refreshtoken.ConnectorIDValidator(v); err != nil { - return &ValidationError{Name: "connector_id", err: fmt.Errorf(`db: validator failed for field "connector_id": %w`, err)} + return &ValidationError{Name: "connector_id", err: fmt.Errorf(`db: validator failed for field "RefreshToken.connector_id": %w`, err)} } } if _, ok := rtc.mutation.Token(); !ok { - return &ValidationError{Name: "token", err: errors.New(`db: missing required field "token"`)} + return &ValidationError{Name: "token", err: errors.New(`db: missing required field "RefreshToken.token"`)} } if _, ok := rtc.mutation.ObsoleteToken(); !ok { - return &ValidationError{Name: "obsolete_token", err: errors.New(`db: missing required field "obsolete_token"`)} + return &ValidationError{Name: "obsolete_token", err: errors.New(`db: missing required field "RefreshToken.obsolete_token"`)} } if _, ok := rtc.mutation.CreatedAt(); !ok { - return &ValidationError{Name: "created_at", err: errors.New(`db: missing required field "created_at"`)} + return &ValidationError{Name: "created_at", err: errors.New(`db: missing required field "RefreshToken.created_at"`)} } if _, ok := rtc.mutation.LastUsed(); !ok { - return &ValidationError{Name: "last_used", err: errors.New(`db: missing required field "last_used"`)} + return &ValidationError{Name: "last_used", err: errors.New(`db: missing required field "RefreshToken.last_used"`)} } if v, ok := rtc.mutation.ID(); ok { if err := refreshtoken.IDValidator(v); err != nil { - return &ValidationError{Name: "id", err: fmt.Errorf(`db: validator failed for field "id": %w`, err)} + return &ValidationError{Name: "id", err: fmt.Errorf(`db: validator failed for field "RefreshToken.id": %w`, err)} } } return nil @@ -333,6 +333,13 @@ func (rtc *RefreshTokenCreate) sqlSave(ctx context.Context) (*RefreshToken, erro } return nil, err } + if _spec.ID.Value != nil { + if id, ok := _spec.ID.Value.(string); ok { + _node.ID = id + } else { + return nil, fmt.Errorf("unexpected RefreshToken.ID type: %T", _spec.ID.Value) + } + } return _node, nil } diff --git a/storage/ent/db/refreshtoken_query.go b/storage/ent/db/refreshtoken_query.go index 2ee4d4f9..d585fdc1 100644 --- a/storage/ent/db/refreshtoken_query.go +++ b/storage/ent/db/refreshtoken_query.go @@ -106,7 +106,7 @@ func (rtq *RefreshTokenQuery) FirstIDX(ctx context.Context) string { } // Only returns a single RefreshToken entity found by the query, ensuring it only returns one. -// Returns a *NotSingularError when exactly one RefreshToken entity is not found. +// Returns a *NotSingularError when more than one RefreshToken entity is found. // Returns a *NotFoundError when no RefreshToken entities are found. func (rtq *RefreshTokenQuery) Only(ctx context.Context) (*RefreshToken, error) { nodes, err := rtq.Limit(2).All(ctx) @@ -133,7 +133,7 @@ func (rtq *RefreshTokenQuery) OnlyX(ctx context.Context) *RefreshToken { } // OnlyID is like Only, but returns the only RefreshToken ID in the query. -// Returns a *NotSingularError when exactly one RefreshToken ID is not found. +// Returns a *NotSingularError when more than one RefreshToken ID is found. // Returns a *NotFoundError when no entities are found. func (rtq *RefreshTokenQuery) OnlyID(ctx context.Context) (id string, err error) { var ids []string @@ -242,8 +242,9 @@ func (rtq *RefreshTokenQuery) Clone() *RefreshTokenQuery { order: append([]OrderFunc{}, rtq.order...), predicates: append([]predicate.RefreshToken{}, rtq.predicates...), // clone intermediate query. - sql: rtq.sql.Clone(), - path: rtq.path, + sql: rtq.sql.Clone(), + path: rtq.path, + unique: rtq.unique, } } @@ -336,6 +337,10 @@ func (rtq *RefreshTokenQuery) sqlAll(ctx context.Context) ([]*RefreshToken, erro func (rtq *RefreshTokenQuery) sqlCount(ctx context.Context) (int, error) { _spec := rtq.querySpec() + _spec.Node.Columns = rtq.fields + if len(rtq.fields) > 0 { + _spec.Unique = rtq.unique != nil && *rtq.unique + } return sqlgraph.CountNodes(ctx, rtq.driver, _spec) } @@ -407,6 +412,9 @@ func (rtq *RefreshTokenQuery) sqlQuery(ctx context.Context) *sql.Selector { selector = rtq.sql selector.Select(selector.Columns(columns...)...) } + if rtq.unique != nil && *rtq.unique { + selector.Distinct() + } for _, p := range rtq.predicates { p(selector) } @@ -685,9 +693,7 @@ func (rtgb *RefreshTokenGroupBy) sqlQuery() *sql.Selector { for _, f := range rtgb.fields { columns = append(columns, selector.C(f)) } - for _, c := range aggregation { - columns = append(columns, c) - } + columns = append(columns, aggregation...) selector.Select(columns...) } return selector.GroupBy(selector.Columns(rtgb.fields...)...) diff --git a/storage/ent/db/refreshtoken_update.go b/storage/ent/db/refreshtoken_update.go index 913666bb..f6e6e61b 100644 --- a/storage/ent/db/refreshtoken_update.go +++ b/storage/ent/db/refreshtoken_update.go @@ -4,6 +4,7 @@ package db import ( "context" + "errors" "fmt" "time" @@ -244,32 +245,32 @@ func (rtu *RefreshTokenUpdate) ExecX(ctx context.Context) { func (rtu *RefreshTokenUpdate) check() error { if v, ok := rtu.mutation.ClientID(); ok { if err := refreshtoken.ClientIDValidator(v); err != nil { - return &ValidationError{Name: "client_id", err: fmt.Errorf("db: validator failed for field \"client_id\": %w", err)} + return &ValidationError{Name: "client_id", err: fmt.Errorf(`db: validator failed for field "RefreshToken.client_id": %w`, err)} } } if v, ok := rtu.mutation.Nonce(); ok { if err := refreshtoken.NonceValidator(v); err != nil { - return &ValidationError{Name: "nonce", err: fmt.Errorf("db: validator failed for field \"nonce\": %w", err)} + return &ValidationError{Name: "nonce", err: fmt.Errorf(`db: validator failed for field "RefreshToken.nonce": %w`, err)} } } if v, ok := rtu.mutation.ClaimsUserID(); ok { if err := refreshtoken.ClaimsUserIDValidator(v); err != nil { - return &ValidationError{Name: "claims_user_id", err: fmt.Errorf("db: validator failed for field \"claims_user_id\": %w", err)} + return &ValidationError{Name: "claims_user_id", err: fmt.Errorf(`db: validator failed for field "RefreshToken.claims_user_id": %w`, err)} } } if v, ok := rtu.mutation.ClaimsUsername(); ok { if err := refreshtoken.ClaimsUsernameValidator(v); err != nil { - return &ValidationError{Name: "claims_username", err: fmt.Errorf("db: validator failed for field \"claims_username\": %w", err)} + return &ValidationError{Name: "claims_username", err: fmt.Errorf(`db: validator failed for field "RefreshToken.claims_username": %w`, err)} } } if v, ok := rtu.mutation.ClaimsEmail(); ok { if err := refreshtoken.ClaimsEmailValidator(v); err != nil { - return &ValidationError{Name: "claims_email", err: fmt.Errorf("db: validator failed for field \"claims_email\": %w", err)} + return &ValidationError{Name: "claims_email", err: fmt.Errorf(`db: validator failed for field "RefreshToken.claims_email": %w`, err)} } } if v, ok := rtu.mutation.ConnectorID(); ok { if err := refreshtoken.ConnectorIDValidator(v); err != nil { - return &ValidationError{Name: "connector_id", err: fmt.Errorf("db: validator failed for field \"connector_id\": %w", err)} + return &ValidationError{Name: "connector_id", err: fmt.Errorf(`db: validator failed for field "RefreshToken.connector_id": %w`, err)} } } return nil @@ -659,32 +660,32 @@ func (rtuo *RefreshTokenUpdateOne) ExecX(ctx context.Context) { func (rtuo *RefreshTokenUpdateOne) check() error { if v, ok := rtuo.mutation.ClientID(); ok { if err := refreshtoken.ClientIDValidator(v); err != nil { - return &ValidationError{Name: "client_id", err: fmt.Errorf("db: validator failed for field \"client_id\": %w", err)} + return &ValidationError{Name: "client_id", err: fmt.Errorf(`db: validator failed for field "RefreshToken.client_id": %w`, err)} } } if v, ok := rtuo.mutation.Nonce(); ok { if err := refreshtoken.NonceValidator(v); err != nil { - return &ValidationError{Name: "nonce", err: fmt.Errorf("db: validator failed for field \"nonce\": %w", err)} + return &ValidationError{Name: "nonce", err: fmt.Errorf(`db: validator failed for field "RefreshToken.nonce": %w`, err)} } } if v, ok := rtuo.mutation.ClaimsUserID(); ok { if err := refreshtoken.ClaimsUserIDValidator(v); err != nil { - return &ValidationError{Name: "claims_user_id", err: fmt.Errorf("db: validator failed for field \"claims_user_id\": %w", err)} + return &ValidationError{Name: "claims_user_id", err: fmt.Errorf(`db: validator failed for field "RefreshToken.claims_user_id": %w`, err)} } } if v, ok := rtuo.mutation.ClaimsUsername(); ok { if err := refreshtoken.ClaimsUsernameValidator(v); err != nil { - return &ValidationError{Name: "claims_username", err: fmt.Errorf("db: validator failed for field \"claims_username\": %w", err)} + return &ValidationError{Name: "claims_username", err: fmt.Errorf(`db: validator failed for field "RefreshToken.claims_username": %w`, err)} } } if v, ok := rtuo.mutation.ClaimsEmail(); ok { if err := refreshtoken.ClaimsEmailValidator(v); err != nil { - return &ValidationError{Name: "claims_email", err: fmt.Errorf("db: validator failed for field \"claims_email\": %w", err)} + return &ValidationError{Name: "claims_email", err: fmt.Errorf(`db: validator failed for field "RefreshToken.claims_email": %w`, err)} } } if v, ok := rtuo.mutation.ConnectorID(); ok { if err := refreshtoken.ConnectorIDValidator(v); err != nil { - return &ValidationError{Name: "connector_id", err: fmt.Errorf("db: validator failed for field \"connector_id\": %w", err)} + return &ValidationError{Name: "connector_id", err: fmt.Errorf(`db: validator failed for field "RefreshToken.connector_id": %w`, err)} } } return nil @@ -703,7 +704,7 @@ func (rtuo *RefreshTokenUpdateOne) sqlSave(ctx context.Context) (_node *RefreshT } id, ok := rtuo.mutation.ID() if !ok { - return nil, &ValidationError{Name: "ID", err: fmt.Errorf("missing RefreshToken.ID for update")} + return nil, &ValidationError{Name: "id", err: errors.New(`db: missing "RefreshToken.id" for update`)} } _spec.Node.ID.Value = id if fields := rtuo.fields; len(fields) > 0 { diff --git a/storage/ent/db/runtime/runtime.go b/storage/ent/db/runtime/runtime.go index b52d54b6..8c201fe1 100644 --- a/storage/ent/db/runtime/runtime.go +++ b/storage/ent/db/runtime/runtime.go @@ -5,6 +5,6 @@ package runtime // The schema-stitching logic is generated in github.com/dexidp/dex/storage/ent/db/runtime.go const ( - Version = "v0.9.0" // Version of ent codegen. - Sum = "h1:2S1zfpMMW6p+wctj6kcYUprNPNjLWFW06T5MdyAfmWc=" // Sum of ent codegen. + Version = "v0.10.1" // Version of ent codegen. + Sum = "h1:dM5h4Zk6yHGIgw4dCqVzGw3nWgpGYJiV4/kyHEF6PFo=" // Sum of ent codegen. ) diff --git a/storage/ent/db/tx.go b/storage/ent/db/tx.go index 5b1f7f16..0107193b 100644 --- a/storage/ent/db/tx.go +++ b/storage/ent/db/tx.go @@ -48,7 +48,7 @@ type Tx struct { } type ( - // Committer is the interface that wraps the Committer method. + // Committer is the interface that wraps the Commit method. Committer interface { Commit(context.Context, *Tx) error } @@ -62,7 +62,7 @@ type ( // and returns a Committer. For example: // // hook := func(next ent.Committer) ent.Committer { - // return ent.CommitFunc(func(context.Context, tx *ent.Tx) error { + // return ent.CommitFunc(func(ctx context.Context, tx *ent.Tx) error { // // Do some stuff before. // if err := next.Commit(ctx, tx); err != nil { // return err @@ -103,7 +103,7 @@ func (tx *Tx) OnCommit(f CommitHook) { } type ( - // Rollbacker is the interface that wraps the Rollbacker method. + // Rollbacker is the interface that wraps the Rollback method. Rollbacker interface { Rollback(context.Context, *Tx) error } @@ -117,7 +117,7 @@ type ( // and returns a Rollbacker. For example: // // hook := func(next ent.Rollbacker) ent.Rollbacker { - // return ent.RollbackFunc(func(context.Context, tx *ent.Tx) error { + // return ent.RollbackFunc(func(ctx context.Context, tx *ent.Tx) error { // // Do some stuff before. // if err := next.Rollback(ctx, tx); err != nil { // return err