diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index aba41663..9b136d1a 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -124,6 +124,6 @@ jobs: - name: Lint run: make lint - # Ensure proto generation doesn't depend on external packages. - - name: Verify proto - run: make verify-proto + # Ensure that generated files were committed. + - name: Verify + run: make verify diff --git a/Makefile b/Makefile index 0f1453bf..89dbf8c6 100644 --- a/Makefile +++ b/Makefile @@ -25,16 +25,22 @@ LD_FLAGS="-w -X main.version=$(VERSION)" KIND_NODE_IMAGE = "kindest/node:v1.19.11@sha256:07db187ae84b4b7de440a73886f008cf903fcf5764ba8106a9fd5243d6f32729" KIND_TMP_DIR = "$(PWD)/bin/test/dex-kind-kubeconfig" -.PHONY: generate -generate: - @go generate $(REPO_PATH)/storage/ent/ +build: bin/dex -build: generate bin/dex +verify: verify-proto verify-ent bin/dex: @mkdir -p bin/ @go install -v -ldflags $(LD_FLAGS) $(REPO_PATH)/cmd/dex +.PHONY: ent-generate +ent-generate: + @go generate $(REPO_PATH)/storage/ent/ + +.PHONY: verify-ent +verify-ent: ent-generate + @./scripts/git-diff + examples: bin/grpc-client bin/example-app bin/grpc-client: @@ -47,7 +53,7 @@ bin/example-app: .PHONY: release-binary release-binary: LD_FLAGS = "-w -X main.version=$(VERSION) -extldflags \"-static\"" -release-binary: generate +release-binary: @go build -o /go/bin/dex -v -ldflags $(LD_FLAGS) $(REPO_PATH)/cmd/dex @go build -o /go/bin/docker-entrypoint -v -ldflags $(LD_FLAGS) $(REPO_PATH)/cmd/docker-entrypoint diff --git a/go.sum b/go.sum index 00704768..696983f6 100644 --- a/go.sum +++ b/go.sum @@ -243,6 +243,7 @@ github.com/lib/pq v1.10.7 h1:p7ZhMD+KsSRozJr34udlUrhboJwWAgCg34+/ZZNvZZw= github.com/lib/pq v1.10.7/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= github.com/mattermost/xml-roundtrip-validator v0.1.0 h1:RXbVD2UAl7A7nOTR4u7E3ILa4IbtvKBHw64LDsmu9hU= github.com/mattermost/xml-roundtrip-validator v0.1.0/go.mod h1:qccnGMcpgwcNaBnxqpJpWWUiPNr5H3O8eDgGV9gT5To= +github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0= github.com/mattn/go-sqlite3 v1.14.16 h1:yOQRA0RpS5PFz/oikGwBEqvAWhWg5ufRz4ETLjwpU1Y= github.com/mattn/go-sqlite3 v1.14.16/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg= github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU= @@ -262,6 +263,7 @@ github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRW github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/oklog/run v1.1.0 h1:GEenZ1cK0+q0+wsJew9qUg/DyD8k3JzYsZAi5gYi2mA= github.com/oklog/run v1.1.0/go.mod h1:sVPdnTZT1zYwAJeCMu2Th4T21pA3FPOQRfWjQlk7DVU= +github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec= github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= @@ -579,6 +581,7 @@ golang.org/x/tools v0.0.0-20200804011535-6c149bb5ef0d/go.mod h1:njjCfa9FT2d7l9Bc golang.org/x/tools v0.0.0-20200825202427-b303f430e36d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= +golang.org/x/tools v0.3.1-0.20221202221704-aa9f4b2f3d57 h1:/X0t/E4VxbZE7MLS7auvE7YICHeVvbIa9vkOVvYW/24= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/scripts/git-version b/scripts/git-version index 936641cb..a60cdc40 100755 --- a/scripts/git-version +++ b/scripts/git-version @@ -1,5 +1,4 @@ #!/bin/sh -e -# Since this script will be run in a rkt container, use "/bin/sh" instead of "/bin/bash" # parse the current git commit hash COMMIT=`git rev-parse HEAD` diff --git a/storage/ent/db/authcode.go b/storage/ent/db/authcode.go index 6ddbeb57..b08516d6 100644 --- a/storage/ent/db/authcode.go +++ b/storage/ent/db/authcode.go @@ -50,8 +50,8 @@ type AuthCode struct { } // scanValues returns the types for scanning values from sql.Rows. -func (*AuthCode) scanValues(columns []string) ([]interface{}, error) { - values := make([]interface{}, len(columns)) +func (*AuthCode) scanValues(columns []string) ([]any, error) { + values := make([]any, len(columns)) for i := range columns { switch columns[i] { case authcode.FieldScopes, authcode.FieldClaimsGroups, authcode.FieldConnectorData: @@ -71,7 +71,7 @@ func (*AuthCode) scanValues(columns []string) ([]interface{}, error) { // assignValues assigns the values that were returned from sql.Rows (after scanning) // to the AuthCode fields. -func (ac *AuthCode) assignValues(columns []string, values []interface{}) error { +func (ac *AuthCode) assignValues(columns []string, values []any) error { if m, n := len(values), len(columns); m < n { return fmt.Errorf("mismatch number of scan values: %d != %d", m, n) } @@ -186,7 +186,7 @@ func (ac *AuthCode) assignValues(columns []string, values []interface{}) error { // Note that you need to call AuthCode.Unwrap() before calling this method if this AuthCode // was returned from a transaction, and the transaction was committed or rolled back. func (ac *AuthCode) Update() *AuthCodeUpdateOne { - return (&AuthCodeClient{config: ac.config}).UpdateOne(ac) + return NewAuthCodeClient(ac.config).UpdateOne(ac) } // Unwrap unwraps the AuthCode entity that was returned from a transaction after it was closed, @@ -257,9 +257,3 @@ func (ac *AuthCode) String() string { // AuthCodes is a parsable slice of AuthCode. type AuthCodes []*AuthCode - -func (ac AuthCodes) config(cfg config) { - for _i := range ac { - ac[_i].config = cfg - } -} diff --git a/storage/ent/db/authcode/where.go b/storage/ent/db/authcode/where.go index be1954d7..b1708d02 100644 --- a/storage/ent/db/authcode/where.go +++ b/storage/ent/db/authcode/where.go @@ -11,1338 +11,882 @@ import ( // ID filters vertices based on their ID field. func ID(id string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldID), id)) - }) + return predicate.AuthCode(sql.FieldEQ(FieldID, id)) } // IDEQ applies the EQ predicate on the ID field. func IDEQ(id string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldID), id)) - }) + return predicate.AuthCode(sql.FieldEQ(FieldID, id)) } // IDNEQ applies the NEQ predicate on the ID field. func IDNEQ(id string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldID), id)) - }) + return predicate.AuthCode(sql.FieldNEQ(FieldID, id)) } // IDIn applies the In predicate on the ID field. func IDIn(ids ...string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - v := make([]interface{}, len(ids)) - for i := range v { - v[i] = ids[i] - } - s.Where(sql.In(s.C(FieldID), v...)) - }) + return predicate.AuthCode(sql.FieldIn(FieldID, ids...)) } // IDNotIn applies the NotIn predicate on the ID field. func IDNotIn(ids ...string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - v := make([]interface{}, len(ids)) - for i := range v { - v[i] = ids[i] - } - s.Where(sql.NotIn(s.C(FieldID), v...)) - }) + return predicate.AuthCode(sql.FieldNotIn(FieldID, ids...)) } // IDGT applies the GT predicate on the ID field. func IDGT(id string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldID), id)) - }) + return predicate.AuthCode(sql.FieldGT(FieldID, id)) } // IDGTE applies the GTE predicate on the ID field. func IDGTE(id string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldID), id)) - }) + return predicate.AuthCode(sql.FieldGTE(FieldID, id)) } // IDLT applies the LT predicate on the ID field. func IDLT(id string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldID), id)) - }) + return predicate.AuthCode(sql.FieldLT(FieldID, id)) } // IDLTE applies the LTE predicate on the ID field. func IDLTE(id string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldID), id)) - }) + return predicate.AuthCode(sql.FieldLTE(FieldID, id)) } // ClientID applies equality check predicate on the "client_id" field. It's identical to ClientIDEQ. func ClientID(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldClientID), v)) - }) + return predicate.AuthCode(sql.FieldEQ(FieldClientID, v)) } // Nonce applies equality check predicate on the "nonce" field. It's identical to NonceEQ. func Nonce(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldNonce), v)) - }) + return predicate.AuthCode(sql.FieldEQ(FieldNonce, v)) } // RedirectURI applies equality check predicate on the "redirect_uri" field. It's identical to RedirectURIEQ. func RedirectURI(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldRedirectURI), v)) - }) + return predicate.AuthCode(sql.FieldEQ(FieldRedirectURI, v)) } // ClaimsUserID applies equality check predicate on the "claims_user_id" field. It's identical to ClaimsUserIDEQ. func ClaimsUserID(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldClaimsUserID), v)) - }) + return predicate.AuthCode(sql.FieldEQ(FieldClaimsUserID, v)) } // ClaimsUsername applies equality check predicate on the "claims_username" field. It's identical to ClaimsUsernameEQ. func ClaimsUsername(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldClaimsUsername), v)) - }) + return predicate.AuthCode(sql.FieldEQ(FieldClaimsUsername, v)) } // ClaimsEmail applies equality check predicate on the "claims_email" field. It's identical to ClaimsEmailEQ. func ClaimsEmail(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldClaimsEmail), v)) - }) + return predicate.AuthCode(sql.FieldEQ(FieldClaimsEmail, v)) } // ClaimsEmailVerified applies equality check predicate on the "claims_email_verified" field. It's identical to ClaimsEmailVerifiedEQ. func ClaimsEmailVerified(v bool) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldClaimsEmailVerified), v)) - }) + return predicate.AuthCode(sql.FieldEQ(FieldClaimsEmailVerified, v)) } // ClaimsPreferredUsername applies equality check predicate on the "claims_preferred_username" field. It's identical to ClaimsPreferredUsernameEQ. func ClaimsPreferredUsername(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldClaimsPreferredUsername), v)) - }) + return predicate.AuthCode(sql.FieldEQ(FieldClaimsPreferredUsername, v)) } // ConnectorID applies equality check predicate on the "connector_id" field. It's identical to ConnectorIDEQ. func ConnectorID(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldConnectorID), v)) - }) + return predicate.AuthCode(sql.FieldEQ(FieldConnectorID, v)) } // ConnectorData applies equality check predicate on the "connector_data" field. It's identical to ConnectorDataEQ. func ConnectorData(v []byte) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldConnectorData), v)) - }) + return predicate.AuthCode(sql.FieldEQ(FieldConnectorData, v)) } // Expiry applies equality check predicate on the "expiry" field. It's identical to ExpiryEQ. func Expiry(v time.Time) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldExpiry), v)) - }) + return predicate.AuthCode(sql.FieldEQ(FieldExpiry, v)) } // CodeChallenge applies equality check predicate on the "code_challenge" field. It's identical to CodeChallengeEQ. func CodeChallenge(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldCodeChallenge), v)) - }) + return predicate.AuthCode(sql.FieldEQ(FieldCodeChallenge, v)) } // CodeChallengeMethod applies equality check predicate on the "code_challenge_method" field. It's identical to CodeChallengeMethodEQ. func CodeChallengeMethod(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldCodeChallengeMethod), v)) - }) + return predicate.AuthCode(sql.FieldEQ(FieldCodeChallengeMethod, v)) } // ClientIDEQ applies the EQ predicate on the "client_id" field. func ClientIDEQ(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldClientID), v)) - }) + return predicate.AuthCode(sql.FieldEQ(FieldClientID, v)) } // ClientIDNEQ applies the NEQ predicate on the "client_id" field. func ClientIDNEQ(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldClientID), v)) - }) + return predicate.AuthCode(sql.FieldNEQ(FieldClientID, v)) } // ClientIDIn applies the In predicate on the "client_id" field. func ClientIDIn(vs ...string) predicate.AuthCode { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldClientID), v...)) - }) + return predicate.AuthCode(sql.FieldIn(FieldClientID, vs...)) } // ClientIDNotIn applies the NotIn predicate on the "client_id" field. func ClientIDNotIn(vs ...string) predicate.AuthCode { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldClientID), v...)) - }) + return predicate.AuthCode(sql.FieldNotIn(FieldClientID, vs...)) } // ClientIDGT applies the GT predicate on the "client_id" field. func ClientIDGT(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldClientID), v)) - }) + return predicate.AuthCode(sql.FieldGT(FieldClientID, v)) } // ClientIDGTE applies the GTE predicate on the "client_id" field. func ClientIDGTE(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldClientID), v)) - }) + return predicate.AuthCode(sql.FieldGTE(FieldClientID, v)) } // ClientIDLT applies the LT predicate on the "client_id" field. func ClientIDLT(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldClientID), v)) - }) + return predicate.AuthCode(sql.FieldLT(FieldClientID, v)) } // ClientIDLTE applies the LTE predicate on the "client_id" field. func ClientIDLTE(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldClientID), v)) - }) + return predicate.AuthCode(sql.FieldLTE(FieldClientID, v)) } // ClientIDContains applies the Contains predicate on the "client_id" field. func ClientIDContains(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldClientID), v)) - }) + return predicate.AuthCode(sql.FieldContains(FieldClientID, v)) } // ClientIDHasPrefix applies the HasPrefix predicate on the "client_id" field. func ClientIDHasPrefix(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldClientID), v)) - }) + return predicate.AuthCode(sql.FieldHasPrefix(FieldClientID, v)) } // ClientIDHasSuffix applies the HasSuffix predicate on the "client_id" field. func ClientIDHasSuffix(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldClientID), v)) - }) + return predicate.AuthCode(sql.FieldHasSuffix(FieldClientID, v)) } // ClientIDEqualFold applies the EqualFold predicate on the "client_id" field. func ClientIDEqualFold(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldClientID), v)) - }) + return predicate.AuthCode(sql.FieldEqualFold(FieldClientID, v)) } // ClientIDContainsFold applies the ContainsFold predicate on the "client_id" field. func ClientIDContainsFold(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldClientID), v)) - }) + return predicate.AuthCode(sql.FieldContainsFold(FieldClientID, v)) } // ScopesIsNil applies the IsNil predicate on the "scopes" field. func ScopesIsNil() predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.IsNull(s.C(FieldScopes))) - }) + return predicate.AuthCode(sql.FieldIsNull(FieldScopes)) } // ScopesNotNil applies the NotNil predicate on the "scopes" field. func ScopesNotNil() predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.NotNull(s.C(FieldScopes))) - }) + return predicate.AuthCode(sql.FieldNotNull(FieldScopes)) } // NonceEQ applies the EQ predicate on the "nonce" field. func NonceEQ(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldNonce), v)) - }) + return predicate.AuthCode(sql.FieldEQ(FieldNonce, v)) } // NonceNEQ applies the NEQ predicate on the "nonce" field. func NonceNEQ(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldNonce), v)) - }) + return predicate.AuthCode(sql.FieldNEQ(FieldNonce, v)) } // NonceIn applies the In predicate on the "nonce" field. func NonceIn(vs ...string) predicate.AuthCode { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldNonce), v...)) - }) + return predicate.AuthCode(sql.FieldIn(FieldNonce, vs...)) } // NonceNotIn applies the NotIn predicate on the "nonce" field. func NonceNotIn(vs ...string) predicate.AuthCode { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldNonce), v...)) - }) + return predicate.AuthCode(sql.FieldNotIn(FieldNonce, vs...)) } // NonceGT applies the GT predicate on the "nonce" field. func NonceGT(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldNonce), v)) - }) + return predicate.AuthCode(sql.FieldGT(FieldNonce, v)) } // NonceGTE applies the GTE predicate on the "nonce" field. func NonceGTE(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldNonce), v)) - }) + return predicate.AuthCode(sql.FieldGTE(FieldNonce, v)) } // NonceLT applies the LT predicate on the "nonce" field. func NonceLT(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldNonce), v)) - }) + return predicate.AuthCode(sql.FieldLT(FieldNonce, v)) } // NonceLTE applies the LTE predicate on the "nonce" field. func NonceLTE(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldNonce), v)) - }) + return predicate.AuthCode(sql.FieldLTE(FieldNonce, v)) } // NonceContains applies the Contains predicate on the "nonce" field. func NonceContains(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldNonce), v)) - }) + return predicate.AuthCode(sql.FieldContains(FieldNonce, v)) } // NonceHasPrefix applies the HasPrefix predicate on the "nonce" field. func NonceHasPrefix(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldNonce), v)) - }) + return predicate.AuthCode(sql.FieldHasPrefix(FieldNonce, v)) } // NonceHasSuffix applies the HasSuffix predicate on the "nonce" field. func NonceHasSuffix(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldNonce), v)) - }) + return predicate.AuthCode(sql.FieldHasSuffix(FieldNonce, v)) } // NonceEqualFold applies the EqualFold predicate on the "nonce" field. func NonceEqualFold(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldNonce), v)) - }) + return predicate.AuthCode(sql.FieldEqualFold(FieldNonce, v)) } // NonceContainsFold applies the ContainsFold predicate on the "nonce" field. func NonceContainsFold(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldNonce), v)) - }) + return predicate.AuthCode(sql.FieldContainsFold(FieldNonce, v)) } // RedirectURIEQ applies the EQ predicate on the "redirect_uri" field. func RedirectURIEQ(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldRedirectURI), v)) - }) + return predicate.AuthCode(sql.FieldEQ(FieldRedirectURI, v)) } // RedirectURINEQ applies the NEQ predicate on the "redirect_uri" field. func RedirectURINEQ(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldRedirectURI), v)) - }) + return predicate.AuthCode(sql.FieldNEQ(FieldRedirectURI, v)) } // RedirectURIIn applies the In predicate on the "redirect_uri" field. func RedirectURIIn(vs ...string) predicate.AuthCode { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldRedirectURI), v...)) - }) + return predicate.AuthCode(sql.FieldIn(FieldRedirectURI, vs...)) } // RedirectURINotIn applies the NotIn predicate on the "redirect_uri" field. func RedirectURINotIn(vs ...string) predicate.AuthCode { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldRedirectURI), v...)) - }) + return predicate.AuthCode(sql.FieldNotIn(FieldRedirectURI, vs...)) } // RedirectURIGT applies the GT predicate on the "redirect_uri" field. func RedirectURIGT(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldRedirectURI), v)) - }) + return predicate.AuthCode(sql.FieldGT(FieldRedirectURI, v)) } // RedirectURIGTE applies the GTE predicate on the "redirect_uri" field. func RedirectURIGTE(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldRedirectURI), v)) - }) + return predicate.AuthCode(sql.FieldGTE(FieldRedirectURI, v)) } // RedirectURILT applies the LT predicate on the "redirect_uri" field. func RedirectURILT(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldRedirectURI), v)) - }) + return predicate.AuthCode(sql.FieldLT(FieldRedirectURI, v)) } // RedirectURILTE applies the LTE predicate on the "redirect_uri" field. func RedirectURILTE(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldRedirectURI), v)) - }) + return predicate.AuthCode(sql.FieldLTE(FieldRedirectURI, v)) } // RedirectURIContains applies the Contains predicate on the "redirect_uri" field. func RedirectURIContains(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldRedirectURI), v)) - }) + return predicate.AuthCode(sql.FieldContains(FieldRedirectURI, v)) } // RedirectURIHasPrefix applies the HasPrefix predicate on the "redirect_uri" field. func RedirectURIHasPrefix(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldRedirectURI), v)) - }) + return predicate.AuthCode(sql.FieldHasPrefix(FieldRedirectURI, v)) } // RedirectURIHasSuffix applies the HasSuffix predicate on the "redirect_uri" field. func RedirectURIHasSuffix(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldRedirectURI), v)) - }) + return predicate.AuthCode(sql.FieldHasSuffix(FieldRedirectURI, v)) } // RedirectURIEqualFold applies the EqualFold predicate on the "redirect_uri" field. func RedirectURIEqualFold(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldRedirectURI), v)) - }) + return predicate.AuthCode(sql.FieldEqualFold(FieldRedirectURI, v)) } // RedirectURIContainsFold applies the ContainsFold predicate on the "redirect_uri" field. func RedirectURIContainsFold(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldRedirectURI), v)) - }) + return predicate.AuthCode(sql.FieldContainsFold(FieldRedirectURI, v)) } // ClaimsUserIDEQ applies the EQ predicate on the "claims_user_id" field. func ClaimsUserIDEQ(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldClaimsUserID), v)) - }) + return predicate.AuthCode(sql.FieldEQ(FieldClaimsUserID, v)) } // ClaimsUserIDNEQ applies the NEQ predicate on the "claims_user_id" field. func ClaimsUserIDNEQ(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldClaimsUserID), v)) - }) + return predicate.AuthCode(sql.FieldNEQ(FieldClaimsUserID, v)) } // ClaimsUserIDIn applies the In predicate on the "claims_user_id" field. func ClaimsUserIDIn(vs ...string) predicate.AuthCode { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldClaimsUserID), v...)) - }) + return predicate.AuthCode(sql.FieldIn(FieldClaimsUserID, vs...)) } // ClaimsUserIDNotIn applies the NotIn predicate on the "claims_user_id" field. func ClaimsUserIDNotIn(vs ...string) predicate.AuthCode { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldClaimsUserID), v...)) - }) + return predicate.AuthCode(sql.FieldNotIn(FieldClaimsUserID, vs...)) } // ClaimsUserIDGT applies the GT predicate on the "claims_user_id" field. func ClaimsUserIDGT(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldClaimsUserID), v)) - }) + return predicate.AuthCode(sql.FieldGT(FieldClaimsUserID, v)) } // ClaimsUserIDGTE applies the GTE predicate on the "claims_user_id" field. func ClaimsUserIDGTE(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldClaimsUserID), v)) - }) + return predicate.AuthCode(sql.FieldGTE(FieldClaimsUserID, v)) } // ClaimsUserIDLT applies the LT predicate on the "claims_user_id" field. func ClaimsUserIDLT(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldClaimsUserID), v)) - }) + return predicate.AuthCode(sql.FieldLT(FieldClaimsUserID, v)) } // ClaimsUserIDLTE applies the LTE predicate on the "claims_user_id" field. func ClaimsUserIDLTE(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldClaimsUserID), v)) - }) + return predicate.AuthCode(sql.FieldLTE(FieldClaimsUserID, v)) } // ClaimsUserIDContains applies the Contains predicate on the "claims_user_id" field. func ClaimsUserIDContains(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldClaimsUserID), v)) - }) + return predicate.AuthCode(sql.FieldContains(FieldClaimsUserID, v)) } // ClaimsUserIDHasPrefix applies the HasPrefix predicate on the "claims_user_id" field. func ClaimsUserIDHasPrefix(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldClaimsUserID), v)) - }) + return predicate.AuthCode(sql.FieldHasPrefix(FieldClaimsUserID, v)) } // ClaimsUserIDHasSuffix applies the HasSuffix predicate on the "claims_user_id" field. func ClaimsUserIDHasSuffix(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldClaimsUserID), v)) - }) + return predicate.AuthCode(sql.FieldHasSuffix(FieldClaimsUserID, v)) } // ClaimsUserIDEqualFold applies the EqualFold predicate on the "claims_user_id" field. func ClaimsUserIDEqualFold(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldClaimsUserID), v)) - }) + return predicate.AuthCode(sql.FieldEqualFold(FieldClaimsUserID, v)) } // ClaimsUserIDContainsFold applies the ContainsFold predicate on the "claims_user_id" field. func ClaimsUserIDContainsFold(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldClaimsUserID), v)) - }) + return predicate.AuthCode(sql.FieldContainsFold(FieldClaimsUserID, v)) } // ClaimsUsernameEQ applies the EQ predicate on the "claims_username" field. func ClaimsUsernameEQ(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldClaimsUsername), v)) - }) + return predicate.AuthCode(sql.FieldEQ(FieldClaimsUsername, v)) } // ClaimsUsernameNEQ applies the NEQ predicate on the "claims_username" field. func ClaimsUsernameNEQ(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldClaimsUsername), v)) - }) + return predicate.AuthCode(sql.FieldNEQ(FieldClaimsUsername, v)) } // ClaimsUsernameIn applies the In predicate on the "claims_username" field. func ClaimsUsernameIn(vs ...string) predicate.AuthCode { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldClaimsUsername), v...)) - }) + return predicate.AuthCode(sql.FieldIn(FieldClaimsUsername, vs...)) } // ClaimsUsernameNotIn applies the NotIn predicate on the "claims_username" field. func ClaimsUsernameNotIn(vs ...string) predicate.AuthCode { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldClaimsUsername), v...)) - }) + return predicate.AuthCode(sql.FieldNotIn(FieldClaimsUsername, vs...)) } // ClaimsUsernameGT applies the GT predicate on the "claims_username" field. func ClaimsUsernameGT(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldClaimsUsername), v)) - }) + return predicate.AuthCode(sql.FieldGT(FieldClaimsUsername, v)) } // ClaimsUsernameGTE applies the GTE predicate on the "claims_username" field. func ClaimsUsernameGTE(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldClaimsUsername), v)) - }) + return predicate.AuthCode(sql.FieldGTE(FieldClaimsUsername, v)) } // ClaimsUsernameLT applies the LT predicate on the "claims_username" field. func ClaimsUsernameLT(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldClaimsUsername), v)) - }) + return predicate.AuthCode(sql.FieldLT(FieldClaimsUsername, v)) } // ClaimsUsernameLTE applies the LTE predicate on the "claims_username" field. func ClaimsUsernameLTE(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldClaimsUsername), v)) - }) + return predicate.AuthCode(sql.FieldLTE(FieldClaimsUsername, v)) } // ClaimsUsernameContains applies the Contains predicate on the "claims_username" field. func ClaimsUsernameContains(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldClaimsUsername), v)) - }) + return predicate.AuthCode(sql.FieldContains(FieldClaimsUsername, v)) } // ClaimsUsernameHasPrefix applies the HasPrefix predicate on the "claims_username" field. func ClaimsUsernameHasPrefix(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldClaimsUsername), v)) - }) + return predicate.AuthCode(sql.FieldHasPrefix(FieldClaimsUsername, v)) } // ClaimsUsernameHasSuffix applies the HasSuffix predicate on the "claims_username" field. func ClaimsUsernameHasSuffix(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldClaimsUsername), v)) - }) + return predicate.AuthCode(sql.FieldHasSuffix(FieldClaimsUsername, v)) } // ClaimsUsernameEqualFold applies the EqualFold predicate on the "claims_username" field. func ClaimsUsernameEqualFold(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldClaimsUsername), v)) - }) + return predicate.AuthCode(sql.FieldEqualFold(FieldClaimsUsername, v)) } // ClaimsUsernameContainsFold applies the ContainsFold predicate on the "claims_username" field. func ClaimsUsernameContainsFold(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldClaimsUsername), v)) - }) + return predicate.AuthCode(sql.FieldContainsFold(FieldClaimsUsername, v)) } // ClaimsEmailEQ applies the EQ predicate on the "claims_email" field. func ClaimsEmailEQ(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldClaimsEmail), v)) - }) + return predicate.AuthCode(sql.FieldEQ(FieldClaimsEmail, v)) } // ClaimsEmailNEQ applies the NEQ predicate on the "claims_email" field. func ClaimsEmailNEQ(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldClaimsEmail), v)) - }) + return predicate.AuthCode(sql.FieldNEQ(FieldClaimsEmail, v)) } // ClaimsEmailIn applies the In predicate on the "claims_email" field. func ClaimsEmailIn(vs ...string) predicate.AuthCode { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldClaimsEmail), v...)) - }) + return predicate.AuthCode(sql.FieldIn(FieldClaimsEmail, vs...)) } // ClaimsEmailNotIn applies the NotIn predicate on the "claims_email" field. func ClaimsEmailNotIn(vs ...string) predicate.AuthCode { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldClaimsEmail), v...)) - }) + return predicate.AuthCode(sql.FieldNotIn(FieldClaimsEmail, vs...)) } // ClaimsEmailGT applies the GT predicate on the "claims_email" field. func ClaimsEmailGT(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldClaimsEmail), v)) - }) + return predicate.AuthCode(sql.FieldGT(FieldClaimsEmail, v)) } // ClaimsEmailGTE applies the GTE predicate on the "claims_email" field. func ClaimsEmailGTE(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldClaimsEmail), v)) - }) + return predicate.AuthCode(sql.FieldGTE(FieldClaimsEmail, v)) } // ClaimsEmailLT applies the LT predicate on the "claims_email" field. func ClaimsEmailLT(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldClaimsEmail), v)) - }) + return predicate.AuthCode(sql.FieldLT(FieldClaimsEmail, v)) } // ClaimsEmailLTE applies the LTE predicate on the "claims_email" field. func ClaimsEmailLTE(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldClaimsEmail), v)) - }) + return predicate.AuthCode(sql.FieldLTE(FieldClaimsEmail, v)) } // ClaimsEmailContains applies the Contains predicate on the "claims_email" field. func ClaimsEmailContains(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldClaimsEmail), v)) - }) + return predicate.AuthCode(sql.FieldContains(FieldClaimsEmail, v)) } // ClaimsEmailHasPrefix applies the HasPrefix predicate on the "claims_email" field. func ClaimsEmailHasPrefix(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldClaimsEmail), v)) - }) + return predicate.AuthCode(sql.FieldHasPrefix(FieldClaimsEmail, v)) } // ClaimsEmailHasSuffix applies the HasSuffix predicate on the "claims_email" field. func ClaimsEmailHasSuffix(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldClaimsEmail), v)) - }) + return predicate.AuthCode(sql.FieldHasSuffix(FieldClaimsEmail, v)) } // ClaimsEmailEqualFold applies the EqualFold predicate on the "claims_email" field. func ClaimsEmailEqualFold(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldClaimsEmail), v)) - }) + return predicate.AuthCode(sql.FieldEqualFold(FieldClaimsEmail, v)) } // ClaimsEmailContainsFold applies the ContainsFold predicate on the "claims_email" field. func ClaimsEmailContainsFold(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldClaimsEmail), v)) - }) + return predicate.AuthCode(sql.FieldContainsFold(FieldClaimsEmail, v)) } // ClaimsEmailVerifiedEQ applies the EQ predicate on the "claims_email_verified" field. func ClaimsEmailVerifiedEQ(v bool) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldClaimsEmailVerified), v)) - }) + return predicate.AuthCode(sql.FieldEQ(FieldClaimsEmailVerified, v)) } // ClaimsEmailVerifiedNEQ applies the NEQ predicate on the "claims_email_verified" field. func ClaimsEmailVerifiedNEQ(v bool) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldClaimsEmailVerified), v)) - }) + return predicate.AuthCode(sql.FieldNEQ(FieldClaimsEmailVerified, v)) } // ClaimsGroupsIsNil applies the IsNil predicate on the "claims_groups" field. func ClaimsGroupsIsNil() predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.IsNull(s.C(FieldClaimsGroups))) - }) + return predicate.AuthCode(sql.FieldIsNull(FieldClaimsGroups)) } // ClaimsGroupsNotNil applies the NotNil predicate on the "claims_groups" field. func ClaimsGroupsNotNil() predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.NotNull(s.C(FieldClaimsGroups))) - }) + return predicate.AuthCode(sql.FieldNotNull(FieldClaimsGroups)) } // ClaimsPreferredUsernameEQ applies the EQ predicate on the "claims_preferred_username" field. func ClaimsPreferredUsernameEQ(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldClaimsPreferredUsername), v)) - }) + return predicate.AuthCode(sql.FieldEQ(FieldClaimsPreferredUsername, v)) } // ClaimsPreferredUsernameNEQ applies the NEQ predicate on the "claims_preferred_username" field. func ClaimsPreferredUsernameNEQ(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldClaimsPreferredUsername), v)) - }) + return predicate.AuthCode(sql.FieldNEQ(FieldClaimsPreferredUsername, v)) } // ClaimsPreferredUsernameIn applies the In predicate on the "claims_preferred_username" field. func ClaimsPreferredUsernameIn(vs ...string) predicate.AuthCode { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldClaimsPreferredUsername), v...)) - }) + return predicate.AuthCode(sql.FieldIn(FieldClaimsPreferredUsername, vs...)) } // ClaimsPreferredUsernameNotIn applies the NotIn predicate on the "claims_preferred_username" field. func ClaimsPreferredUsernameNotIn(vs ...string) predicate.AuthCode { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldClaimsPreferredUsername), v...)) - }) + return predicate.AuthCode(sql.FieldNotIn(FieldClaimsPreferredUsername, vs...)) } // ClaimsPreferredUsernameGT applies the GT predicate on the "claims_preferred_username" field. func ClaimsPreferredUsernameGT(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldClaimsPreferredUsername), v)) - }) + return predicate.AuthCode(sql.FieldGT(FieldClaimsPreferredUsername, v)) } // ClaimsPreferredUsernameGTE applies the GTE predicate on the "claims_preferred_username" field. func ClaimsPreferredUsernameGTE(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldClaimsPreferredUsername), v)) - }) + return predicate.AuthCode(sql.FieldGTE(FieldClaimsPreferredUsername, v)) } // ClaimsPreferredUsernameLT applies the LT predicate on the "claims_preferred_username" field. func ClaimsPreferredUsernameLT(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldClaimsPreferredUsername), v)) - }) + return predicate.AuthCode(sql.FieldLT(FieldClaimsPreferredUsername, v)) } // ClaimsPreferredUsernameLTE applies the LTE predicate on the "claims_preferred_username" field. func ClaimsPreferredUsernameLTE(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldClaimsPreferredUsername), v)) - }) + return predicate.AuthCode(sql.FieldLTE(FieldClaimsPreferredUsername, v)) } // ClaimsPreferredUsernameContains applies the Contains predicate on the "claims_preferred_username" field. func ClaimsPreferredUsernameContains(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldClaimsPreferredUsername), v)) - }) + return predicate.AuthCode(sql.FieldContains(FieldClaimsPreferredUsername, v)) } // ClaimsPreferredUsernameHasPrefix applies the HasPrefix predicate on the "claims_preferred_username" field. func ClaimsPreferredUsernameHasPrefix(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldClaimsPreferredUsername), v)) - }) + return predicate.AuthCode(sql.FieldHasPrefix(FieldClaimsPreferredUsername, v)) } // ClaimsPreferredUsernameHasSuffix applies the HasSuffix predicate on the "claims_preferred_username" field. func ClaimsPreferredUsernameHasSuffix(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldClaimsPreferredUsername), v)) - }) + return predicate.AuthCode(sql.FieldHasSuffix(FieldClaimsPreferredUsername, v)) } // ClaimsPreferredUsernameEqualFold applies the EqualFold predicate on the "claims_preferred_username" field. func ClaimsPreferredUsernameEqualFold(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldClaimsPreferredUsername), v)) - }) + return predicate.AuthCode(sql.FieldEqualFold(FieldClaimsPreferredUsername, v)) } // ClaimsPreferredUsernameContainsFold applies the ContainsFold predicate on the "claims_preferred_username" field. func ClaimsPreferredUsernameContainsFold(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldClaimsPreferredUsername), v)) - }) + return predicate.AuthCode(sql.FieldContainsFold(FieldClaimsPreferredUsername, v)) } // ConnectorIDEQ applies the EQ predicate on the "connector_id" field. func ConnectorIDEQ(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldConnectorID), v)) - }) + return predicate.AuthCode(sql.FieldEQ(FieldConnectorID, v)) } // ConnectorIDNEQ applies the NEQ predicate on the "connector_id" field. func ConnectorIDNEQ(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldConnectorID), v)) - }) + return predicate.AuthCode(sql.FieldNEQ(FieldConnectorID, v)) } // ConnectorIDIn applies the In predicate on the "connector_id" field. func ConnectorIDIn(vs ...string) predicate.AuthCode { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldConnectorID), v...)) - }) + return predicate.AuthCode(sql.FieldIn(FieldConnectorID, vs...)) } // ConnectorIDNotIn applies the NotIn predicate on the "connector_id" field. func ConnectorIDNotIn(vs ...string) predicate.AuthCode { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldConnectorID), v...)) - }) + return predicate.AuthCode(sql.FieldNotIn(FieldConnectorID, vs...)) } // ConnectorIDGT applies the GT predicate on the "connector_id" field. func ConnectorIDGT(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldConnectorID), v)) - }) + return predicate.AuthCode(sql.FieldGT(FieldConnectorID, v)) } // ConnectorIDGTE applies the GTE predicate on the "connector_id" field. func ConnectorIDGTE(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldConnectorID), v)) - }) + return predicate.AuthCode(sql.FieldGTE(FieldConnectorID, v)) } // ConnectorIDLT applies the LT predicate on the "connector_id" field. func ConnectorIDLT(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldConnectorID), v)) - }) + return predicate.AuthCode(sql.FieldLT(FieldConnectorID, v)) } // ConnectorIDLTE applies the LTE predicate on the "connector_id" field. func ConnectorIDLTE(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldConnectorID), v)) - }) + return predicate.AuthCode(sql.FieldLTE(FieldConnectorID, v)) } // ConnectorIDContains applies the Contains predicate on the "connector_id" field. func ConnectorIDContains(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldConnectorID), v)) - }) + return predicate.AuthCode(sql.FieldContains(FieldConnectorID, v)) } // ConnectorIDHasPrefix applies the HasPrefix predicate on the "connector_id" field. func ConnectorIDHasPrefix(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldConnectorID), v)) - }) + return predicate.AuthCode(sql.FieldHasPrefix(FieldConnectorID, v)) } // ConnectorIDHasSuffix applies the HasSuffix predicate on the "connector_id" field. func ConnectorIDHasSuffix(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldConnectorID), v)) - }) + return predicate.AuthCode(sql.FieldHasSuffix(FieldConnectorID, v)) } // ConnectorIDEqualFold applies the EqualFold predicate on the "connector_id" field. func ConnectorIDEqualFold(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldConnectorID), v)) - }) + return predicate.AuthCode(sql.FieldEqualFold(FieldConnectorID, v)) } // ConnectorIDContainsFold applies the ContainsFold predicate on the "connector_id" field. func ConnectorIDContainsFold(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldConnectorID), v)) - }) + return predicate.AuthCode(sql.FieldContainsFold(FieldConnectorID, v)) } // ConnectorDataEQ applies the EQ predicate on the "connector_data" field. func ConnectorDataEQ(v []byte) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldConnectorData), v)) - }) + return predicate.AuthCode(sql.FieldEQ(FieldConnectorData, v)) } // ConnectorDataNEQ applies the NEQ predicate on the "connector_data" field. func ConnectorDataNEQ(v []byte) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldConnectorData), v)) - }) + return predicate.AuthCode(sql.FieldNEQ(FieldConnectorData, v)) } // ConnectorDataIn applies the In predicate on the "connector_data" field. func ConnectorDataIn(vs ...[]byte) predicate.AuthCode { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldConnectorData), v...)) - }) + return predicate.AuthCode(sql.FieldIn(FieldConnectorData, vs...)) } // ConnectorDataNotIn applies the NotIn predicate on the "connector_data" field. func ConnectorDataNotIn(vs ...[]byte) predicate.AuthCode { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldConnectorData), v...)) - }) + return predicate.AuthCode(sql.FieldNotIn(FieldConnectorData, vs...)) } // ConnectorDataGT applies the GT predicate on the "connector_data" field. func ConnectorDataGT(v []byte) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldConnectorData), v)) - }) + return predicate.AuthCode(sql.FieldGT(FieldConnectorData, v)) } // ConnectorDataGTE applies the GTE predicate on the "connector_data" field. func ConnectorDataGTE(v []byte) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldConnectorData), v)) - }) + return predicate.AuthCode(sql.FieldGTE(FieldConnectorData, v)) } // ConnectorDataLT applies the LT predicate on the "connector_data" field. func ConnectorDataLT(v []byte) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldConnectorData), v)) - }) + return predicate.AuthCode(sql.FieldLT(FieldConnectorData, v)) } // ConnectorDataLTE applies the LTE predicate on the "connector_data" field. func ConnectorDataLTE(v []byte) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldConnectorData), v)) - }) + return predicate.AuthCode(sql.FieldLTE(FieldConnectorData, v)) } // ConnectorDataIsNil applies the IsNil predicate on the "connector_data" field. func ConnectorDataIsNil() predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.IsNull(s.C(FieldConnectorData))) - }) + return predicate.AuthCode(sql.FieldIsNull(FieldConnectorData)) } // ConnectorDataNotNil applies the NotNil predicate on the "connector_data" field. func ConnectorDataNotNil() predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.NotNull(s.C(FieldConnectorData))) - }) + return predicate.AuthCode(sql.FieldNotNull(FieldConnectorData)) } // ExpiryEQ applies the EQ predicate on the "expiry" field. func ExpiryEQ(v time.Time) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldExpiry), v)) - }) + return predicate.AuthCode(sql.FieldEQ(FieldExpiry, v)) } // ExpiryNEQ applies the NEQ predicate on the "expiry" field. func ExpiryNEQ(v time.Time) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldExpiry), v)) - }) + return predicate.AuthCode(sql.FieldNEQ(FieldExpiry, v)) } // ExpiryIn applies the In predicate on the "expiry" field. func ExpiryIn(vs ...time.Time) predicate.AuthCode { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldExpiry), v...)) - }) + return predicate.AuthCode(sql.FieldIn(FieldExpiry, vs...)) } // ExpiryNotIn applies the NotIn predicate on the "expiry" field. func ExpiryNotIn(vs ...time.Time) predicate.AuthCode { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldExpiry), v...)) - }) + return predicate.AuthCode(sql.FieldNotIn(FieldExpiry, vs...)) } // ExpiryGT applies the GT predicate on the "expiry" field. func ExpiryGT(v time.Time) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldExpiry), v)) - }) + return predicate.AuthCode(sql.FieldGT(FieldExpiry, v)) } // ExpiryGTE applies the GTE predicate on the "expiry" field. func ExpiryGTE(v time.Time) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldExpiry), v)) - }) + return predicate.AuthCode(sql.FieldGTE(FieldExpiry, v)) } // ExpiryLT applies the LT predicate on the "expiry" field. func ExpiryLT(v time.Time) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldExpiry), v)) - }) + return predicate.AuthCode(sql.FieldLT(FieldExpiry, v)) } // ExpiryLTE applies the LTE predicate on the "expiry" field. func ExpiryLTE(v time.Time) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldExpiry), v)) - }) + return predicate.AuthCode(sql.FieldLTE(FieldExpiry, v)) } // CodeChallengeEQ applies the EQ predicate on the "code_challenge" field. func CodeChallengeEQ(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldCodeChallenge), v)) - }) + return predicate.AuthCode(sql.FieldEQ(FieldCodeChallenge, v)) } // CodeChallengeNEQ applies the NEQ predicate on the "code_challenge" field. func CodeChallengeNEQ(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldCodeChallenge), v)) - }) + return predicate.AuthCode(sql.FieldNEQ(FieldCodeChallenge, v)) } // CodeChallengeIn applies the In predicate on the "code_challenge" field. func CodeChallengeIn(vs ...string) predicate.AuthCode { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldCodeChallenge), v...)) - }) + return predicate.AuthCode(sql.FieldIn(FieldCodeChallenge, vs...)) } // CodeChallengeNotIn applies the NotIn predicate on the "code_challenge" field. func CodeChallengeNotIn(vs ...string) predicate.AuthCode { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldCodeChallenge), v...)) - }) + return predicate.AuthCode(sql.FieldNotIn(FieldCodeChallenge, vs...)) } // CodeChallengeGT applies the GT predicate on the "code_challenge" field. func CodeChallengeGT(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldCodeChallenge), v)) - }) + return predicate.AuthCode(sql.FieldGT(FieldCodeChallenge, v)) } // CodeChallengeGTE applies the GTE predicate on the "code_challenge" field. func CodeChallengeGTE(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldCodeChallenge), v)) - }) + return predicate.AuthCode(sql.FieldGTE(FieldCodeChallenge, v)) } // CodeChallengeLT applies the LT predicate on the "code_challenge" field. func CodeChallengeLT(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldCodeChallenge), v)) - }) + return predicate.AuthCode(sql.FieldLT(FieldCodeChallenge, v)) } // CodeChallengeLTE applies the LTE predicate on the "code_challenge" field. func CodeChallengeLTE(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldCodeChallenge), v)) - }) + return predicate.AuthCode(sql.FieldLTE(FieldCodeChallenge, v)) } // CodeChallengeContains applies the Contains predicate on the "code_challenge" field. func CodeChallengeContains(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldCodeChallenge), v)) - }) + return predicate.AuthCode(sql.FieldContains(FieldCodeChallenge, v)) } // CodeChallengeHasPrefix applies the HasPrefix predicate on the "code_challenge" field. func CodeChallengeHasPrefix(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldCodeChallenge), v)) - }) + return predicate.AuthCode(sql.FieldHasPrefix(FieldCodeChallenge, v)) } // CodeChallengeHasSuffix applies the HasSuffix predicate on the "code_challenge" field. func CodeChallengeHasSuffix(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldCodeChallenge), v)) - }) + return predicate.AuthCode(sql.FieldHasSuffix(FieldCodeChallenge, v)) } // CodeChallengeEqualFold applies the EqualFold predicate on the "code_challenge" field. func CodeChallengeEqualFold(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldCodeChallenge), v)) - }) + return predicate.AuthCode(sql.FieldEqualFold(FieldCodeChallenge, v)) } // CodeChallengeContainsFold applies the ContainsFold predicate on the "code_challenge" field. func CodeChallengeContainsFold(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldCodeChallenge), v)) - }) + return predicate.AuthCode(sql.FieldContainsFold(FieldCodeChallenge, v)) } // CodeChallengeMethodEQ applies the EQ predicate on the "code_challenge_method" field. func CodeChallengeMethodEQ(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldCodeChallengeMethod), v)) - }) + return predicate.AuthCode(sql.FieldEQ(FieldCodeChallengeMethod, v)) } // CodeChallengeMethodNEQ applies the NEQ predicate on the "code_challenge_method" field. func CodeChallengeMethodNEQ(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldCodeChallengeMethod), v)) - }) + return predicate.AuthCode(sql.FieldNEQ(FieldCodeChallengeMethod, v)) } // CodeChallengeMethodIn applies the In predicate on the "code_challenge_method" field. func CodeChallengeMethodIn(vs ...string) predicate.AuthCode { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldCodeChallengeMethod), v...)) - }) + return predicate.AuthCode(sql.FieldIn(FieldCodeChallengeMethod, vs...)) } // CodeChallengeMethodNotIn applies the NotIn predicate on the "code_challenge_method" field. func CodeChallengeMethodNotIn(vs ...string) predicate.AuthCode { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldCodeChallengeMethod), v...)) - }) + return predicate.AuthCode(sql.FieldNotIn(FieldCodeChallengeMethod, vs...)) } // CodeChallengeMethodGT applies the GT predicate on the "code_challenge_method" field. func CodeChallengeMethodGT(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldCodeChallengeMethod), v)) - }) + return predicate.AuthCode(sql.FieldGT(FieldCodeChallengeMethod, v)) } // CodeChallengeMethodGTE applies the GTE predicate on the "code_challenge_method" field. func CodeChallengeMethodGTE(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldCodeChallengeMethod), v)) - }) + return predicate.AuthCode(sql.FieldGTE(FieldCodeChallengeMethod, v)) } // CodeChallengeMethodLT applies the LT predicate on the "code_challenge_method" field. func CodeChallengeMethodLT(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldCodeChallengeMethod), v)) - }) + return predicate.AuthCode(sql.FieldLT(FieldCodeChallengeMethod, v)) } // CodeChallengeMethodLTE applies the LTE predicate on the "code_challenge_method" field. func CodeChallengeMethodLTE(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldCodeChallengeMethod), v)) - }) + return predicate.AuthCode(sql.FieldLTE(FieldCodeChallengeMethod, v)) } // CodeChallengeMethodContains applies the Contains predicate on the "code_challenge_method" field. func CodeChallengeMethodContains(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldCodeChallengeMethod), v)) - }) + return predicate.AuthCode(sql.FieldContains(FieldCodeChallengeMethod, v)) } // CodeChallengeMethodHasPrefix applies the HasPrefix predicate on the "code_challenge_method" field. func CodeChallengeMethodHasPrefix(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldCodeChallengeMethod), v)) - }) + return predicate.AuthCode(sql.FieldHasPrefix(FieldCodeChallengeMethod, v)) } // CodeChallengeMethodHasSuffix applies the HasSuffix predicate on the "code_challenge_method" field. func CodeChallengeMethodHasSuffix(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldCodeChallengeMethod), v)) - }) + return predicate.AuthCode(sql.FieldHasSuffix(FieldCodeChallengeMethod, v)) } // CodeChallengeMethodEqualFold applies the EqualFold predicate on the "code_challenge_method" field. func CodeChallengeMethodEqualFold(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldCodeChallengeMethod), v)) - }) + return predicate.AuthCode(sql.FieldEqualFold(FieldCodeChallengeMethod, v)) } // CodeChallengeMethodContainsFold applies the ContainsFold predicate on the "code_challenge_method" field. func CodeChallengeMethodContainsFold(v string) predicate.AuthCode { - return predicate.AuthCode(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldCodeChallengeMethod), v)) - }) + return predicate.AuthCode(sql.FieldContainsFold(FieldCodeChallengeMethod, v)) } // And groups predicates with the AND operator between them. diff --git a/storage/ent/db/authcode_create.go b/storage/ent/db/authcode_create.go index c075c3d3..323a4704 100644 --- a/storage/ent/db/authcode_create.go +++ b/storage/ent/db/authcode_create.go @@ -147,50 +147,8 @@ func (acc *AuthCodeCreate) Mutation() *AuthCodeMutation { // Save creates the AuthCode in the database. func (acc *AuthCodeCreate) Save(ctx context.Context) (*AuthCode, error) { - var ( - err error - node *AuthCode - ) acc.defaults() - if len(acc.hooks) == 0 { - if err = acc.check(); err != nil { - return nil, err - } - node, err = acc.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*AuthCodeMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err = acc.check(); err != nil { - return nil, err - } - acc.mutation = mutation - if node, err = acc.sqlSave(ctx); err != nil { - return nil, err - } - mutation.id = &node.ID - mutation.done = true - return node, err - }) - for i := len(acc.hooks) - 1; i >= 0; i-- { - if acc.hooks[i] == nil { - return nil, fmt.Errorf("db: uninitialized hook (forgotten import db/runtime?)") - } - mut = acc.hooks[i](mut) - } - v, err := mut.Mutate(ctx, acc.mutation) - if err != nil { - return nil, err - } - nv, ok := v.(*AuthCode) - if !ok { - return nil, fmt.Errorf("unexpected node type %T returned from AuthCodeMutation", v) - } - node = nv - } - return node, err + return withHooks[*AuthCode, AuthCodeMutation](ctx, acc.sqlSave, acc.mutation, acc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -313,6 +271,9 @@ func (acc *AuthCodeCreate) check() error { } func (acc *AuthCodeCreate) sqlSave(ctx context.Context) (*AuthCode, error) { + if err := acc.check(); err != nil { + return nil, err + } _node, _spec := acc.createSpec() if err := sqlgraph.CreateNode(ctx, acc.driver, _spec); err != nil { if sqlgraph.IsConstraintError(err) { @@ -327,142 +288,78 @@ func (acc *AuthCodeCreate) sqlSave(ctx context.Context) (*AuthCode, error) { return nil, fmt.Errorf("unexpected AuthCode.ID type: %T", _spec.ID.Value) } } + acc.mutation.id = &_node.ID + acc.mutation.done = true return _node, nil } func (acc *AuthCodeCreate) createSpec() (*AuthCode, *sqlgraph.CreateSpec) { var ( _node = &AuthCode{config: acc.config} - _spec = &sqlgraph.CreateSpec{ - Table: authcode.Table, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeString, - Column: authcode.FieldID, - }, - } + _spec = sqlgraph.NewCreateSpec(authcode.Table, sqlgraph.NewFieldSpec(authcode.FieldID, field.TypeString)) ) if id, ok := acc.mutation.ID(); ok { _node.ID = id _spec.ID.Value = id } if value, ok := acc.mutation.ClientID(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: authcode.FieldClientID, - }) + _spec.SetField(authcode.FieldClientID, field.TypeString, value) _node.ClientID = value } if value, ok := acc.mutation.Scopes(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeJSON, - Value: value, - Column: authcode.FieldScopes, - }) + _spec.SetField(authcode.FieldScopes, field.TypeJSON, value) _node.Scopes = value } if value, ok := acc.mutation.Nonce(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: authcode.FieldNonce, - }) + _spec.SetField(authcode.FieldNonce, field.TypeString, value) _node.Nonce = value } if value, ok := acc.mutation.RedirectURI(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: authcode.FieldRedirectURI, - }) + _spec.SetField(authcode.FieldRedirectURI, field.TypeString, value) _node.RedirectURI = value } if value, ok := acc.mutation.ClaimsUserID(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: authcode.FieldClaimsUserID, - }) + _spec.SetField(authcode.FieldClaimsUserID, field.TypeString, value) _node.ClaimsUserID = value } if value, ok := acc.mutation.ClaimsUsername(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: authcode.FieldClaimsUsername, - }) + _spec.SetField(authcode.FieldClaimsUsername, field.TypeString, value) _node.ClaimsUsername = value } if value, ok := acc.mutation.ClaimsEmail(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: authcode.FieldClaimsEmail, - }) + _spec.SetField(authcode.FieldClaimsEmail, field.TypeString, value) _node.ClaimsEmail = value } if value, ok := acc.mutation.ClaimsEmailVerified(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeBool, - Value: value, - Column: authcode.FieldClaimsEmailVerified, - }) + _spec.SetField(authcode.FieldClaimsEmailVerified, field.TypeBool, value) _node.ClaimsEmailVerified = value } if value, ok := acc.mutation.ClaimsGroups(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeJSON, - Value: value, - Column: authcode.FieldClaimsGroups, - }) + _spec.SetField(authcode.FieldClaimsGroups, field.TypeJSON, value) _node.ClaimsGroups = value } if value, ok := acc.mutation.ClaimsPreferredUsername(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: authcode.FieldClaimsPreferredUsername, - }) + _spec.SetField(authcode.FieldClaimsPreferredUsername, field.TypeString, value) _node.ClaimsPreferredUsername = value } if value, ok := acc.mutation.ConnectorID(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: authcode.FieldConnectorID, - }) + _spec.SetField(authcode.FieldConnectorID, field.TypeString, value) _node.ConnectorID = value } if value, ok := acc.mutation.ConnectorData(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeBytes, - Value: value, - Column: authcode.FieldConnectorData, - }) + _spec.SetField(authcode.FieldConnectorData, field.TypeBytes, value) _node.ConnectorData = &value } if value, ok := acc.mutation.Expiry(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeTime, - Value: value, - Column: authcode.FieldExpiry, - }) + _spec.SetField(authcode.FieldExpiry, field.TypeTime, value) _node.Expiry = value } if value, ok := acc.mutation.CodeChallenge(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: authcode.FieldCodeChallenge, - }) + _spec.SetField(authcode.FieldCodeChallenge, field.TypeString, value) _node.CodeChallenge = value } if value, ok := acc.mutation.CodeChallengeMethod(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: authcode.FieldCodeChallengeMethod, - }) + _spec.SetField(authcode.FieldCodeChallengeMethod, field.TypeString, value) _node.CodeChallengeMethod = value } return _node, _spec diff --git a/storage/ent/db/authcode_delete.go b/storage/ent/db/authcode_delete.go index 3471394a..18040794 100644 --- a/storage/ent/db/authcode_delete.go +++ b/storage/ent/db/authcode_delete.go @@ -4,7 +4,6 @@ package db import ( "context" - "fmt" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" @@ -28,34 +27,7 @@ func (acd *AuthCodeDelete) Where(ps ...predicate.AuthCode) *AuthCodeDelete { // Exec executes the deletion query and returns how many vertices were deleted. func (acd *AuthCodeDelete) Exec(ctx context.Context) (int, error) { - var ( - err error - affected int - ) - if len(acd.hooks) == 0 { - affected, err = acd.sqlExec(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*AuthCodeMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - acd.mutation = mutation - affected, err = acd.sqlExec(ctx) - mutation.done = true - return affected, err - }) - for i := len(acd.hooks) - 1; i >= 0; i-- { - if acd.hooks[i] == nil { - return 0, fmt.Errorf("db: uninitialized hook (forgotten import db/runtime?)") - } - mut = acd.hooks[i](mut) - } - if _, err := mut.Mutate(ctx, acd.mutation); err != nil { - return 0, err - } - } - return affected, err + return withHooks[int, AuthCodeMutation](ctx, acd.sqlExec, acd.mutation, acd.hooks) } // ExecX is like Exec, but panics if an error occurs. @@ -68,15 +40,7 @@ func (acd *AuthCodeDelete) ExecX(ctx context.Context) int { } func (acd *AuthCodeDelete) sqlExec(ctx context.Context) (int, error) { - _spec := &sqlgraph.DeleteSpec{ - Node: &sqlgraph.NodeSpec{ - Table: authcode.Table, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeString, - Column: authcode.FieldID, - }, - }, - } + _spec := sqlgraph.NewDeleteSpec(authcode.Table, sqlgraph.NewFieldSpec(authcode.FieldID, field.TypeString)) if ps := acd.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { @@ -88,6 +52,7 @@ func (acd *AuthCodeDelete) sqlExec(ctx context.Context) (int, error) { if err != nil && sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } + acd.mutation.done = true return affected, err } @@ -96,6 +61,12 @@ type AuthCodeDeleteOne struct { acd *AuthCodeDelete } +// Where appends a list predicates to the AuthCodeDelete builder. +func (acdo *AuthCodeDeleteOne) Where(ps ...predicate.AuthCode) *AuthCodeDeleteOne { + acdo.acd.mutation.Where(ps...) + return acdo +} + // Exec executes the deletion query. func (acdo *AuthCodeDeleteOne) Exec(ctx context.Context) error { n, err := acdo.acd.Exec(ctx) @@ -111,5 +82,7 @@ func (acdo *AuthCodeDeleteOne) Exec(ctx context.Context) error { // ExecX is like Exec, but panics if an error occurs. func (acdo *AuthCodeDeleteOne) ExecX(ctx context.Context) { - acdo.acd.ExecX(ctx) + if err := acdo.Exec(ctx); err != nil { + panic(err) + } } diff --git a/storage/ent/db/authcode_query.go b/storage/ent/db/authcode_query.go index a82a4506..49da12fa 100644 --- a/storage/ent/db/authcode_query.go +++ b/storage/ent/db/authcode_query.go @@ -17,11 +17,9 @@ import ( // AuthCodeQuery is the builder for querying AuthCode entities. type AuthCodeQuery struct { config - limit *int - offset *int - unique *bool + ctx *QueryContext order []OrderFunc - fields []string + inters []Interceptor predicates []predicate.AuthCode // intermediate query (i.e. traversal path). sql *sql.Selector @@ -34,26 +32,26 @@ func (acq *AuthCodeQuery) Where(ps ...predicate.AuthCode) *AuthCodeQuery { return acq } -// Limit adds a limit step to the query. +// Limit the number of records to be returned by this query. func (acq *AuthCodeQuery) Limit(limit int) *AuthCodeQuery { - acq.limit = &limit + acq.ctx.Limit = &limit return acq } -// Offset adds an offset step to the query. +// Offset to start from. func (acq *AuthCodeQuery) Offset(offset int) *AuthCodeQuery { - acq.offset = &offset + acq.ctx.Offset = &offset return acq } // Unique configures the query builder to filter duplicate records on query. // By default, unique is set to true, and can be disabled using this method. func (acq *AuthCodeQuery) Unique(unique bool) *AuthCodeQuery { - acq.unique = &unique + acq.ctx.Unique = &unique return acq } -// Order adds an order step to the query. +// Order specifies how the records should be ordered. func (acq *AuthCodeQuery) Order(o ...OrderFunc) *AuthCodeQuery { acq.order = append(acq.order, o...) return acq @@ -62,7 +60,7 @@ func (acq *AuthCodeQuery) Order(o ...OrderFunc) *AuthCodeQuery { // First returns the first AuthCode entity from the query. // Returns a *NotFoundError when no AuthCode was found. func (acq *AuthCodeQuery) First(ctx context.Context) (*AuthCode, error) { - nodes, err := acq.Limit(1).All(ctx) + nodes, err := acq.Limit(1).All(setContextOp(ctx, acq.ctx, "First")) if err != nil { return nil, err } @@ -85,7 +83,7 @@ func (acq *AuthCodeQuery) FirstX(ctx context.Context) *AuthCode { // Returns a *NotFoundError when no AuthCode ID was found. func (acq *AuthCodeQuery) FirstID(ctx context.Context) (id string, err error) { var ids []string - if ids, err = acq.Limit(1).IDs(ctx); err != nil { + if ids, err = acq.Limit(1).IDs(setContextOp(ctx, acq.ctx, "FirstID")); err != nil { return } if len(ids) == 0 { @@ -108,7 +106,7 @@ func (acq *AuthCodeQuery) FirstIDX(ctx context.Context) string { // 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) + nodes, err := acq.Limit(2).All(setContextOp(ctx, acq.ctx, "Only")) if err != nil { return nil, err } @@ -136,7 +134,7 @@ func (acq *AuthCodeQuery) OnlyX(ctx context.Context) *AuthCode { // Returns a *NotFoundError when no entities are found. func (acq *AuthCodeQuery) OnlyID(ctx context.Context) (id string, err error) { var ids []string - if ids, err = acq.Limit(2).IDs(ctx); err != nil { + if ids, err = acq.Limit(2).IDs(setContextOp(ctx, acq.ctx, "OnlyID")); err != nil { return } switch len(ids) { @@ -161,10 +159,12 @@ func (acq *AuthCodeQuery) OnlyIDX(ctx context.Context) string { // All executes the query and returns a list of AuthCodes. func (acq *AuthCodeQuery) All(ctx context.Context) ([]*AuthCode, error) { + ctx = setContextOp(ctx, acq.ctx, "All") if err := acq.prepareQuery(ctx); err != nil { return nil, err } - return acq.sqlAll(ctx) + qr := querierAll[[]*AuthCode, *AuthCodeQuery]() + return withInterceptors[[]*AuthCode](ctx, acq, qr, acq.inters) } // AllX is like All, but panics if an error occurs. @@ -177,9 +177,12 @@ func (acq *AuthCodeQuery) AllX(ctx context.Context) []*AuthCode { } // IDs executes the query and returns a list of AuthCode IDs. -func (acq *AuthCodeQuery) IDs(ctx context.Context) ([]string, error) { - var ids []string - if err := acq.Select(authcode.FieldID).Scan(ctx, &ids); err != nil { +func (acq *AuthCodeQuery) IDs(ctx context.Context) (ids []string, err error) { + if acq.ctx.Unique == nil && acq.path != nil { + acq.Unique(true) + } + ctx = setContextOp(ctx, acq.ctx, "IDs") + if err = acq.Select(authcode.FieldID).Scan(ctx, &ids); err != nil { return nil, err } return ids, nil @@ -196,10 +199,11 @@ func (acq *AuthCodeQuery) IDsX(ctx context.Context) []string { // Count returns the count of the given query. func (acq *AuthCodeQuery) Count(ctx context.Context) (int, error) { + ctx = setContextOp(ctx, acq.ctx, "Count") if err := acq.prepareQuery(ctx); err != nil { return 0, err } - return acq.sqlCount(ctx) + return withInterceptors[int](ctx, acq, querierCount[*AuthCodeQuery](), acq.inters) } // CountX is like Count, but panics if an error occurs. @@ -213,10 +217,15 @@ func (acq *AuthCodeQuery) CountX(ctx context.Context) int { // Exist returns true if the query has elements in the graph. func (acq *AuthCodeQuery) Exist(ctx context.Context) (bool, error) { - if err := acq.prepareQuery(ctx); err != nil { - return false, err + ctx = setContextOp(ctx, acq.ctx, "Exist") + switch _, err := acq.FirstID(ctx); { + case IsNotFound(err): + return false, nil + case err != nil: + return false, fmt.Errorf("db: check existence: %w", err) + default: + return true, nil } - return acq.sqlExist(ctx) } // ExistX is like Exist, but panics if an error occurs. @@ -236,14 +245,13 @@ func (acq *AuthCodeQuery) Clone() *AuthCodeQuery { } return &AuthCodeQuery{ config: acq.config, - limit: acq.limit, - offset: acq.offset, + ctx: acq.ctx.Clone(), order: append([]OrderFunc{}, acq.order...), + inters: append([]Interceptor{}, acq.inters...), predicates: append([]predicate.AuthCode{}, acq.predicates...), // clone intermediate query. - sql: acq.sql.Clone(), - path: acq.path, - unique: acq.unique, + sql: acq.sql.Clone(), + path: acq.path, } } @@ -261,18 +269,12 @@ func (acq *AuthCodeQuery) Clone() *AuthCodeQuery { // GroupBy(authcode.FieldClientID). // Aggregate(db.Count()). // Scan(ctx, &v) -// func (acq *AuthCodeQuery) GroupBy(field string, fields ...string) *AuthCodeGroupBy { - grbuild := &AuthCodeGroupBy{config: acq.config} - grbuild.fields = append([]string{field}, fields...) - grbuild.path = func(ctx context.Context) (prev *sql.Selector, err error) { - if err := acq.prepareQuery(ctx); err != nil { - return nil, err - } - return acq.sqlQuery(ctx), nil - } + acq.ctx.Fields = append([]string{field}, fields...) + grbuild := &AuthCodeGroupBy{build: acq} + grbuild.flds = &acq.ctx.Fields grbuild.label = authcode.Label - grbuild.flds, grbuild.scan = &grbuild.fields, grbuild.Scan + grbuild.scan = grbuild.Scan return grbuild } @@ -288,17 +290,31 @@ func (acq *AuthCodeQuery) GroupBy(field string, fields ...string) *AuthCodeGroup // client.AuthCode.Query(). // Select(authcode.FieldClientID). // Scan(ctx, &v) -// func (acq *AuthCodeQuery) Select(fields ...string) *AuthCodeSelect { - acq.fields = append(acq.fields, fields...) - selbuild := &AuthCodeSelect{AuthCodeQuery: acq} - selbuild.label = authcode.Label - selbuild.flds, selbuild.scan = &acq.fields, selbuild.Scan - return selbuild + acq.ctx.Fields = append(acq.ctx.Fields, fields...) + sbuild := &AuthCodeSelect{AuthCodeQuery: acq} + sbuild.label = authcode.Label + sbuild.flds, sbuild.scan = &acq.ctx.Fields, sbuild.Scan + return sbuild +} + +// Aggregate returns a AuthCodeSelect configured with the given aggregations. +func (acq *AuthCodeQuery) Aggregate(fns ...AggregateFunc) *AuthCodeSelect { + return acq.Select().Aggregate(fns...) } func (acq *AuthCodeQuery) prepareQuery(ctx context.Context) error { - for _, f := range acq.fields { + for _, inter := range acq.inters { + if inter == nil { + return fmt.Errorf("db: uninitialized interceptor (forgotten import db/runtime?)") + } + if trv, ok := inter.(Traverser); ok { + if err := trv.Traverse(ctx, acq); err != nil { + return err + } + } + } + for _, f := range acq.ctx.Fields { if !authcode.ValidColumn(f) { return &ValidationError{Name: f, err: fmt.Errorf("db: invalid field %q for query", f)} } @@ -318,10 +334,10 @@ func (acq *AuthCodeQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Au nodes = []*AuthCode{} _spec = acq.querySpec() ) - _spec.ScanValues = func(columns []string) ([]interface{}, error) { + _spec.ScanValues = func(columns []string) ([]any, error) { return (*AuthCode).scanValues(nil, columns) } - _spec.Assign = func(columns []string, values []interface{}) error { + _spec.Assign = func(columns []string, values []any) error { node := &AuthCode{config: acq.config} nodes = append(nodes, node) return node.assignValues(columns, values) @@ -340,38 +356,22 @@ func (acq *AuthCodeQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Au 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 + _spec.Node.Columns = acq.ctx.Fields + if len(acq.ctx.Fields) > 0 { + _spec.Unique = acq.ctx.Unique != nil && *acq.ctx.Unique } return sqlgraph.CountNodes(ctx, acq.driver, _spec) } -func (acq *AuthCodeQuery) sqlExist(ctx context.Context) (bool, error) { - n, err := acq.sqlCount(ctx) - if err != nil { - return false, fmt.Errorf("db: check existence: %w", err) - } - return n > 0, nil -} - func (acq *AuthCodeQuery) querySpec() *sqlgraph.QuerySpec { - _spec := &sqlgraph.QuerySpec{ - Node: &sqlgraph.NodeSpec{ - Table: authcode.Table, - Columns: authcode.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeString, - Column: authcode.FieldID, - }, - }, - From: acq.sql, - Unique: true, - } - if unique := acq.unique; unique != nil { + _spec := sqlgraph.NewQuerySpec(authcode.Table, authcode.Columns, sqlgraph.NewFieldSpec(authcode.FieldID, field.TypeString)) + _spec.From = acq.sql + if unique := acq.ctx.Unique; unique != nil { _spec.Unique = *unique + } else if acq.path != nil { + _spec.Unique = true } - if fields := acq.fields; len(fields) > 0 { + if fields := acq.ctx.Fields; len(fields) > 0 { _spec.Node.Columns = make([]string, 0, len(fields)) _spec.Node.Columns = append(_spec.Node.Columns, authcode.FieldID) for i := range fields { @@ -387,10 +387,10 @@ func (acq *AuthCodeQuery) querySpec() *sqlgraph.QuerySpec { } } } - if limit := acq.limit; limit != nil { + if limit := acq.ctx.Limit; limit != nil { _spec.Limit = *limit } - if offset := acq.offset; offset != nil { + if offset := acq.ctx.Offset; offset != nil { _spec.Offset = *offset } if ps := acq.order; len(ps) > 0 { @@ -406,7 +406,7 @@ func (acq *AuthCodeQuery) querySpec() *sqlgraph.QuerySpec { func (acq *AuthCodeQuery) sqlQuery(ctx context.Context) *sql.Selector { builder := sql.Dialect(acq.driver.Dialect()) t1 := builder.Table(authcode.Table) - columns := acq.fields + columns := acq.ctx.Fields if len(columns) == 0 { columns = authcode.Columns } @@ -415,7 +415,7 @@ func (acq *AuthCodeQuery) sqlQuery(ctx context.Context) *sql.Selector { selector = acq.sql selector.Select(selector.Columns(columns...)...) } - if acq.unique != nil && *acq.unique { + if acq.ctx.Unique != nil && *acq.ctx.Unique { selector.Distinct() } for _, p := range acq.predicates { @@ -424,12 +424,12 @@ func (acq *AuthCodeQuery) sqlQuery(ctx context.Context) *sql.Selector { for _, p := range acq.order { p(selector) } - if offset := acq.offset; offset != nil { + if offset := acq.ctx.Offset; offset != nil { // limit is mandatory for offset clause. We start // with default value, and override it below if needed. selector.Offset(*offset).Limit(math.MaxInt32) } - if limit := acq.limit; limit != nil { + if limit := acq.ctx.Limit; limit != nil { selector.Limit(*limit) } return selector @@ -437,13 +437,8 @@ func (acq *AuthCodeQuery) sqlQuery(ctx context.Context) *sql.Selector { // AuthCodeGroupBy is the group-by builder for AuthCode entities. type AuthCodeGroupBy struct { - config selector - fields []string - fns []AggregateFunc - // intermediate query (i.e. traversal path). - sql *sql.Selector - path func(context.Context) (*sql.Selector, error) + build *AuthCodeQuery } // Aggregate adds the given aggregation functions to the group-by query. @@ -452,74 +447,77 @@ func (acgb *AuthCodeGroupBy) Aggregate(fns ...AggregateFunc) *AuthCodeGroupBy { return acgb } -// Scan applies the group-by query and scans the result into the given value. -func (acgb *AuthCodeGroupBy) Scan(ctx context.Context, v interface{}) error { - query, err := acgb.path(ctx) - if err != nil { +// Scan applies the selector query and scans the result into the given value. +func (acgb *AuthCodeGroupBy) Scan(ctx context.Context, v any) error { + ctx = setContextOp(ctx, acgb.build.ctx, "GroupBy") + if err := acgb.build.prepareQuery(ctx); err != nil { return err } - acgb.sql = query - return acgb.sqlScan(ctx, v) + return scanWithInterceptors[*AuthCodeQuery, *AuthCodeGroupBy](ctx, acgb.build, acgb, acgb.build.inters, v) } -func (acgb *AuthCodeGroupBy) sqlScan(ctx context.Context, v interface{}) error { - for _, f := range acgb.fields { - if !authcode.ValidColumn(f) { - return &ValidationError{Name: f, err: fmt.Errorf("invalid field %q for group-by", f)} - } - } - selector := acgb.sqlQuery() - if err := selector.Err(); err != nil { - return err - } - rows := &sql.Rows{} - query, args := selector.Query() - if err := acgb.driver.Query(ctx, query, args, rows); err != nil { - return err - } - defer rows.Close() - return sql.ScanSlice(rows, v) -} - -func (acgb *AuthCodeGroupBy) sqlQuery() *sql.Selector { - selector := acgb.sql.Select() +func (acgb *AuthCodeGroupBy) sqlScan(ctx context.Context, root *AuthCodeQuery, v any) error { + selector := root.sqlQuery(ctx).Select() aggregation := make([]string, 0, len(acgb.fns)) for _, fn := range acgb.fns { aggregation = append(aggregation, fn(selector)) } - // If no columns were selected in a custom aggregation function, the default - // selection is the fields used for "group-by", and the aggregation functions. if len(selector.SelectedColumns()) == 0 { - columns := make([]string, 0, len(acgb.fields)+len(acgb.fns)) - for _, f := range acgb.fields { + columns := make([]string, 0, len(*acgb.flds)+len(acgb.fns)) + for _, f := range *acgb.flds { columns = append(columns, selector.C(f)) } columns = append(columns, aggregation...) selector.Select(columns...) } - return selector.GroupBy(selector.Columns(acgb.fields...)...) + selector.GroupBy(selector.Columns(*acgb.flds...)...) + if err := selector.Err(); err != nil { + return err + } + rows := &sql.Rows{} + query, args := selector.Query() + if err := acgb.build.driver.Query(ctx, query, args, rows); err != nil { + return err + } + defer rows.Close() + return sql.ScanSlice(rows, v) } // AuthCodeSelect is the builder for selecting fields of AuthCode entities. type AuthCodeSelect struct { *AuthCodeQuery selector - // intermediate query (i.e. traversal path). - sql *sql.Selector +} + +// Aggregate adds the given aggregation functions to the selector query. +func (acs *AuthCodeSelect) Aggregate(fns ...AggregateFunc) *AuthCodeSelect { + acs.fns = append(acs.fns, fns...) + return acs } // Scan applies the selector query and scans the result into the given value. -func (acs *AuthCodeSelect) Scan(ctx context.Context, v interface{}) error { +func (acs *AuthCodeSelect) Scan(ctx context.Context, v any) error { + ctx = setContextOp(ctx, acs.ctx, "Select") if err := acs.prepareQuery(ctx); err != nil { return err } - acs.sql = acs.AuthCodeQuery.sqlQuery(ctx) - return acs.sqlScan(ctx, v) + return scanWithInterceptors[*AuthCodeQuery, *AuthCodeSelect](ctx, acs.AuthCodeQuery, acs, acs.inters, v) } -func (acs *AuthCodeSelect) sqlScan(ctx context.Context, v interface{}) error { +func (acs *AuthCodeSelect) sqlScan(ctx context.Context, root *AuthCodeQuery, v any) error { + selector := root.sqlQuery(ctx) + aggregation := make([]string, 0, len(acs.fns)) + for _, fn := range acs.fns { + aggregation = append(aggregation, fn(selector)) + } + switch n := len(*acs.selector.flds); { + case n == 0 && len(aggregation) > 0: + selector.Select(aggregation...) + case n != 0 && len(aggregation) > 0: + selector.AppendSelect(aggregation...) + } rows := &sql.Rows{} - query, args := acs.sql.Query() + query, args := selector.Query() if err := acs.driver.Query(ctx, query, args, rows); err != nil { return err } diff --git a/storage/ent/db/authcode_update.go b/storage/ent/db/authcode_update.go index 5d9764bc..85d25672 100644 --- a/storage/ent/db/authcode_update.go +++ b/storage/ent/db/authcode_update.go @@ -10,6 +10,7 @@ import ( "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/dialect/sql/sqljson" "entgo.io/ent/schema/field" "github.com/dexidp/dex/storage/ent/db/authcode" "github.com/dexidp/dex/storage/ent/db/predicate" @@ -40,6 +41,12 @@ func (acu *AuthCodeUpdate) SetScopes(s []string) *AuthCodeUpdate { return acu } +// AppendScopes appends s to the "scopes" field. +func (acu *AuthCodeUpdate) AppendScopes(s []string) *AuthCodeUpdate { + acu.mutation.AppendScopes(s) + return acu +} + // ClearScopes clears the value of the "scopes" field. func (acu *AuthCodeUpdate) ClearScopes() *AuthCodeUpdate { acu.mutation.ClearScopes() @@ -88,6 +95,12 @@ func (acu *AuthCodeUpdate) SetClaimsGroups(s []string) *AuthCodeUpdate { return acu } +// AppendClaimsGroups appends s to the "claims_groups" field. +func (acu *AuthCodeUpdate) AppendClaimsGroups(s []string) *AuthCodeUpdate { + acu.mutation.AppendClaimsGroups(s) + return acu +} + // ClearClaimsGroups clears the value of the "claims_groups" field. func (acu *AuthCodeUpdate) ClearClaimsGroups() *AuthCodeUpdate { acu.mutation.ClearClaimsGroups() @@ -167,40 +180,7 @@ func (acu *AuthCodeUpdate) Mutation() *AuthCodeMutation { // Save executes the query and returns the number of nodes affected by the update operation. func (acu *AuthCodeUpdate) Save(ctx context.Context) (int, error) { - var ( - err error - affected int - ) - if len(acu.hooks) == 0 { - if err = acu.check(); err != nil { - return 0, err - } - affected, err = acu.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*AuthCodeMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err = acu.check(); err != nil { - return 0, err - } - acu.mutation = mutation - affected, err = acu.sqlSave(ctx) - mutation.done = true - return affected, err - }) - for i := len(acu.hooks) - 1; i >= 0; i-- { - if acu.hooks[i] == nil { - return 0, fmt.Errorf("db: uninitialized hook (forgotten import db/runtime?)") - } - mut = acu.hooks[i](mut) - } - if _, err := mut.Mutate(ctx, acu.mutation); err != nil { - return 0, err - } - } - return affected, err + return withHooks[int, AuthCodeMutation](ctx, acu.sqlSave, acu.mutation, acu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -266,16 +246,10 @@ func (acu *AuthCodeUpdate) check() error { } func (acu *AuthCodeUpdate) sqlSave(ctx context.Context) (n int, err error) { - _spec := &sqlgraph.UpdateSpec{ - Node: &sqlgraph.NodeSpec{ - Table: authcode.Table, - Columns: authcode.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeString, - Column: authcode.FieldID, - }, - }, + if err := acu.check(); err != nil { + return n, err } + _spec := sqlgraph.NewUpdateSpec(authcode.Table, authcode.Columns, sqlgraph.NewFieldSpec(authcode.FieldID, field.TypeString)) if ps := acu.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { @@ -284,127 +258,68 @@ func (acu *AuthCodeUpdate) sqlSave(ctx context.Context) (n int, err error) { } } if value, ok := acu.mutation.ClientID(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: authcode.FieldClientID, - }) + _spec.SetField(authcode.FieldClientID, field.TypeString, value) } if value, ok := acu.mutation.Scopes(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeJSON, - Value: value, - Column: authcode.FieldScopes, + _spec.SetField(authcode.FieldScopes, field.TypeJSON, value) + } + if value, ok := acu.mutation.AppendedScopes(); ok { + _spec.AddModifier(func(u *sql.UpdateBuilder) { + sqljson.Append(u, authcode.FieldScopes, value) }) } if acu.mutation.ScopesCleared() { - _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ - Type: field.TypeJSON, - Column: authcode.FieldScopes, - }) + _spec.ClearField(authcode.FieldScopes, field.TypeJSON) } if value, ok := acu.mutation.Nonce(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: authcode.FieldNonce, - }) + _spec.SetField(authcode.FieldNonce, field.TypeString, value) } if value, ok := acu.mutation.RedirectURI(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: authcode.FieldRedirectURI, - }) + _spec.SetField(authcode.FieldRedirectURI, field.TypeString, value) } if value, ok := acu.mutation.ClaimsUserID(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: authcode.FieldClaimsUserID, - }) + _spec.SetField(authcode.FieldClaimsUserID, field.TypeString, value) } if value, ok := acu.mutation.ClaimsUsername(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: authcode.FieldClaimsUsername, - }) + _spec.SetField(authcode.FieldClaimsUsername, field.TypeString, value) } if value, ok := acu.mutation.ClaimsEmail(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: authcode.FieldClaimsEmail, - }) + _spec.SetField(authcode.FieldClaimsEmail, field.TypeString, value) } if value, ok := acu.mutation.ClaimsEmailVerified(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeBool, - Value: value, - Column: authcode.FieldClaimsEmailVerified, - }) + _spec.SetField(authcode.FieldClaimsEmailVerified, field.TypeBool, value) } if value, ok := acu.mutation.ClaimsGroups(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeJSON, - Value: value, - Column: authcode.FieldClaimsGroups, + _spec.SetField(authcode.FieldClaimsGroups, field.TypeJSON, value) + } + if value, ok := acu.mutation.AppendedClaimsGroups(); ok { + _spec.AddModifier(func(u *sql.UpdateBuilder) { + sqljson.Append(u, authcode.FieldClaimsGroups, value) }) } if acu.mutation.ClaimsGroupsCleared() { - _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ - Type: field.TypeJSON, - Column: authcode.FieldClaimsGroups, - }) + _spec.ClearField(authcode.FieldClaimsGroups, field.TypeJSON) } if value, ok := acu.mutation.ClaimsPreferredUsername(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: authcode.FieldClaimsPreferredUsername, - }) + _spec.SetField(authcode.FieldClaimsPreferredUsername, field.TypeString, value) } if value, ok := acu.mutation.ConnectorID(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: authcode.FieldConnectorID, - }) + _spec.SetField(authcode.FieldConnectorID, field.TypeString, value) } if value, ok := acu.mutation.ConnectorData(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeBytes, - Value: value, - Column: authcode.FieldConnectorData, - }) + _spec.SetField(authcode.FieldConnectorData, field.TypeBytes, value) } if acu.mutation.ConnectorDataCleared() { - _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ - Type: field.TypeBytes, - Column: authcode.FieldConnectorData, - }) + _spec.ClearField(authcode.FieldConnectorData, field.TypeBytes) } if value, ok := acu.mutation.Expiry(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeTime, - Value: value, - Column: authcode.FieldExpiry, - }) + _spec.SetField(authcode.FieldExpiry, field.TypeTime, value) } if value, ok := acu.mutation.CodeChallenge(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: authcode.FieldCodeChallenge, - }) + _spec.SetField(authcode.FieldCodeChallenge, field.TypeString, value) } if value, ok := acu.mutation.CodeChallengeMethod(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: authcode.FieldCodeChallengeMethod, - }) + _spec.SetField(authcode.FieldCodeChallengeMethod, field.TypeString, value) } if n, err = sqlgraph.UpdateNodes(ctx, acu.driver, _spec); err != nil { if _, ok := err.(*sqlgraph.NotFoundError); ok { @@ -414,6 +329,7 @@ func (acu *AuthCodeUpdate) sqlSave(ctx context.Context) (n int, err error) { } return 0, err } + acu.mutation.done = true return n, nil } @@ -437,6 +353,12 @@ func (acuo *AuthCodeUpdateOne) SetScopes(s []string) *AuthCodeUpdateOne { return acuo } +// AppendScopes appends s to the "scopes" field. +func (acuo *AuthCodeUpdateOne) AppendScopes(s []string) *AuthCodeUpdateOne { + acuo.mutation.AppendScopes(s) + return acuo +} + // ClearScopes clears the value of the "scopes" field. func (acuo *AuthCodeUpdateOne) ClearScopes() *AuthCodeUpdateOne { acuo.mutation.ClearScopes() @@ -485,6 +407,12 @@ func (acuo *AuthCodeUpdateOne) SetClaimsGroups(s []string) *AuthCodeUpdateOne { return acuo } +// AppendClaimsGroups appends s to the "claims_groups" field. +func (acuo *AuthCodeUpdateOne) AppendClaimsGroups(s []string) *AuthCodeUpdateOne { + acuo.mutation.AppendClaimsGroups(s) + return acuo +} + // ClearClaimsGroups clears the value of the "claims_groups" field. func (acuo *AuthCodeUpdateOne) ClearClaimsGroups() *AuthCodeUpdateOne { acuo.mutation.ClearClaimsGroups() @@ -562,6 +490,12 @@ func (acuo *AuthCodeUpdateOne) Mutation() *AuthCodeMutation { return acuo.mutation } +// Where appends a list predicates to the AuthCodeUpdate builder. +func (acuo *AuthCodeUpdateOne) Where(ps ...predicate.AuthCode) *AuthCodeUpdateOne { + acuo.mutation.Where(ps...) + return acuo +} + // Select allows selecting one or more fields (columns) of the returned entity. // The default is selecting all fields defined in the entity schema. func (acuo *AuthCodeUpdateOne) Select(field string, fields ...string) *AuthCodeUpdateOne { @@ -571,46 +505,7 @@ func (acuo *AuthCodeUpdateOne) Select(field string, fields ...string) *AuthCodeU // Save executes the query and returns the updated AuthCode entity. func (acuo *AuthCodeUpdateOne) Save(ctx context.Context) (*AuthCode, error) { - var ( - err error - node *AuthCode - ) - if len(acuo.hooks) == 0 { - if err = acuo.check(); err != nil { - return nil, err - } - node, err = acuo.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*AuthCodeMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err = acuo.check(); err != nil { - return nil, err - } - acuo.mutation = mutation - node, err = acuo.sqlSave(ctx) - mutation.done = true - return node, err - }) - for i := len(acuo.hooks) - 1; i >= 0; i-- { - if acuo.hooks[i] == nil { - return nil, fmt.Errorf("db: uninitialized hook (forgotten import db/runtime?)") - } - mut = acuo.hooks[i](mut) - } - v, err := mut.Mutate(ctx, acuo.mutation) - if err != nil { - return nil, err - } - nv, ok := v.(*AuthCode) - if !ok { - return nil, fmt.Errorf("unexpected node type %T returned from AuthCodeMutation", v) - } - node = nv - } - return node, err + return withHooks[*AuthCode, AuthCodeMutation](ctx, acuo.sqlSave, acuo.mutation, acuo.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -676,16 +571,10 @@ func (acuo *AuthCodeUpdateOne) check() error { } func (acuo *AuthCodeUpdateOne) sqlSave(ctx context.Context) (_node *AuthCode, err error) { - _spec := &sqlgraph.UpdateSpec{ - Node: &sqlgraph.NodeSpec{ - Table: authcode.Table, - Columns: authcode.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeString, - Column: authcode.FieldID, - }, - }, + if err := acuo.check(); err != nil { + return _node, err } + _spec := sqlgraph.NewUpdateSpec(authcode.Table, authcode.Columns, sqlgraph.NewFieldSpec(authcode.FieldID, field.TypeString)) id, ok := acuo.mutation.ID() if !ok { return nil, &ValidationError{Name: "id", err: errors.New(`db: missing "AuthCode.id" for update`)} @@ -711,127 +600,68 @@ func (acuo *AuthCodeUpdateOne) sqlSave(ctx context.Context) (_node *AuthCode, er } } if value, ok := acuo.mutation.ClientID(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: authcode.FieldClientID, - }) + _spec.SetField(authcode.FieldClientID, field.TypeString, value) } if value, ok := acuo.mutation.Scopes(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeJSON, - Value: value, - Column: authcode.FieldScopes, + _spec.SetField(authcode.FieldScopes, field.TypeJSON, value) + } + if value, ok := acuo.mutation.AppendedScopes(); ok { + _spec.AddModifier(func(u *sql.UpdateBuilder) { + sqljson.Append(u, authcode.FieldScopes, value) }) } if acuo.mutation.ScopesCleared() { - _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ - Type: field.TypeJSON, - Column: authcode.FieldScopes, - }) + _spec.ClearField(authcode.FieldScopes, field.TypeJSON) } if value, ok := acuo.mutation.Nonce(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: authcode.FieldNonce, - }) + _spec.SetField(authcode.FieldNonce, field.TypeString, value) } if value, ok := acuo.mutation.RedirectURI(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: authcode.FieldRedirectURI, - }) + _spec.SetField(authcode.FieldRedirectURI, field.TypeString, value) } if value, ok := acuo.mutation.ClaimsUserID(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: authcode.FieldClaimsUserID, - }) + _spec.SetField(authcode.FieldClaimsUserID, field.TypeString, value) } if value, ok := acuo.mutation.ClaimsUsername(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: authcode.FieldClaimsUsername, - }) + _spec.SetField(authcode.FieldClaimsUsername, field.TypeString, value) } if value, ok := acuo.mutation.ClaimsEmail(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: authcode.FieldClaimsEmail, - }) + _spec.SetField(authcode.FieldClaimsEmail, field.TypeString, value) } if value, ok := acuo.mutation.ClaimsEmailVerified(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeBool, - Value: value, - Column: authcode.FieldClaimsEmailVerified, - }) + _spec.SetField(authcode.FieldClaimsEmailVerified, field.TypeBool, value) } if value, ok := acuo.mutation.ClaimsGroups(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeJSON, - Value: value, - Column: authcode.FieldClaimsGroups, + _spec.SetField(authcode.FieldClaimsGroups, field.TypeJSON, value) + } + if value, ok := acuo.mutation.AppendedClaimsGroups(); ok { + _spec.AddModifier(func(u *sql.UpdateBuilder) { + sqljson.Append(u, authcode.FieldClaimsGroups, value) }) } if acuo.mutation.ClaimsGroupsCleared() { - _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ - Type: field.TypeJSON, - Column: authcode.FieldClaimsGroups, - }) + _spec.ClearField(authcode.FieldClaimsGroups, field.TypeJSON) } if value, ok := acuo.mutation.ClaimsPreferredUsername(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: authcode.FieldClaimsPreferredUsername, - }) + _spec.SetField(authcode.FieldClaimsPreferredUsername, field.TypeString, value) } if value, ok := acuo.mutation.ConnectorID(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: authcode.FieldConnectorID, - }) + _spec.SetField(authcode.FieldConnectorID, field.TypeString, value) } if value, ok := acuo.mutation.ConnectorData(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeBytes, - Value: value, - Column: authcode.FieldConnectorData, - }) + _spec.SetField(authcode.FieldConnectorData, field.TypeBytes, value) } if acuo.mutation.ConnectorDataCleared() { - _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ - Type: field.TypeBytes, - Column: authcode.FieldConnectorData, - }) + _spec.ClearField(authcode.FieldConnectorData, field.TypeBytes) } if value, ok := acuo.mutation.Expiry(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeTime, - Value: value, - Column: authcode.FieldExpiry, - }) + _spec.SetField(authcode.FieldExpiry, field.TypeTime, value) } if value, ok := acuo.mutation.CodeChallenge(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: authcode.FieldCodeChallenge, - }) + _spec.SetField(authcode.FieldCodeChallenge, field.TypeString, value) } if value, ok := acuo.mutation.CodeChallengeMethod(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: authcode.FieldCodeChallengeMethod, - }) + _spec.SetField(authcode.FieldCodeChallengeMethod, field.TypeString, value) } _node = &AuthCode{config: acuo.config} _spec.Assign = _node.assignValues @@ -844,5 +674,6 @@ func (acuo *AuthCodeUpdateOne) sqlSave(ctx context.Context) (_node *AuthCode, er } return nil, err } + acuo.mutation.done = true return _node, nil } diff --git a/storage/ent/db/authrequest.go b/storage/ent/db/authrequest.go index 095427ae..5cd6c445 100644 --- a/storage/ent/db/authrequest.go +++ b/storage/ent/db/authrequest.go @@ -60,8 +60,8 @@ type AuthRequest struct { } // scanValues returns the types for scanning values from sql.Rows. -func (*AuthRequest) scanValues(columns []string) ([]interface{}, error) { - values := make([]interface{}, len(columns)) +func (*AuthRequest) scanValues(columns []string) ([]any, error) { + values := make([]any, len(columns)) for i := range columns { switch columns[i] { case authrequest.FieldScopes, authrequest.FieldResponseTypes, authrequest.FieldClaimsGroups, authrequest.FieldConnectorData, authrequest.FieldHmacKey: @@ -81,7 +81,7 @@ func (*AuthRequest) scanValues(columns []string) ([]interface{}, error) { // assignValues assigns the values that were returned from sql.Rows (after scanning) // to the AuthRequest fields. -func (ar *AuthRequest) assignValues(columns []string, values []interface{}) error { +func (ar *AuthRequest) assignValues(columns []string, values []any) error { if m, n := len(values), len(columns); m < n { return fmt.Errorf("mismatch number of scan values: %d != %d", m, n) } @@ -228,7 +228,7 @@ func (ar *AuthRequest) assignValues(columns []string, values []interface{}) erro // Note that you need to call AuthRequest.Unwrap() before calling this method if this AuthRequest // was returned from a transaction, and the transaction was committed or rolled back. func (ar *AuthRequest) Update() *AuthRequestUpdateOne { - return (&AuthRequestClient{config: ar.config}).UpdateOne(ar) + return NewAuthRequestClient(ar.config).UpdateOne(ar) } // Unwrap unwraps the AuthRequest entity that was returned from a transaction after it was closed, @@ -305,7 +305,8 @@ func (ar *AuthRequest) String() string { builder.WriteString(", ") builder.WriteString("code_challenge_method=") builder.WriteString(ar.CodeChallengeMethod) - builder.WriteString(", hmac_key=") + builder.WriteString(", ") + builder.WriteString("hmac_key=") builder.WriteString(fmt.Sprintf("%v", ar.HmacKey)) builder.WriteByte(')') return builder.String() @@ -313,9 +314,3 @@ func (ar *AuthRequest) String() string { // AuthRequests is a parsable slice of AuthRequest. type AuthRequests []*AuthRequest - -func (ar AuthRequests) config(cfg config) { - for _i := range ar { - ar[_i].config = cfg - } -} diff --git a/storage/ent/db/authrequest/where.go b/storage/ent/db/authrequest/where.go index 1fd1d4e4..daa6b891 100644 --- a/storage/ent/db/authrequest/where.go +++ b/storage/ent/db/authrequest/where.go @@ -11,1583 +11,1037 @@ import ( // ID filters vertices based on their ID field. func ID(id string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldID), id)) - }) + return predicate.AuthRequest(sql.FieldEQ(FieldID, id)) } // IDEQ applies the EQ predicate on the ID field. func IDEQ(id string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldID), id)) - }) + return predicate.AuthRequest(sql.FieldEQ(FieldID, id)) } // IDNEQ applies the NEQ predicate on the ID field. func IDNEQ(id string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldID), id)) - }) + return predicate.AuthRequest(sql.FieldNEQ(FieldID, id)) } // IDIn applies the In predicate on the ID field. func IDIn(ids ...string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - v := make([]interface{}, len(ids)) - for i := range v { - v[i] = ids[i] - } - s.Where(sql.In(s.C(FieldID), v...)) - }) + return predicate.AuthRequest(sql.FieldIn(FieldID, ids...)) } // IDNotIn applies the NotIn predicate on the ID field. func IDNotIn(ids ...string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - v := make([]interface{}, len(ids)) - for i := range v { - v[i] = ids[i] - } - s.Where(sql.NotIn(s.C(FieldID), v...)) - }) + return predicate.AuthRequest(sql.FieldNotIn(FieldID, ids...)) } // IDGT applies the GT predicate on the ID field. func IDGT(id string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldID), id)) - }) + return predicate.AuthRequest(sql.FieldGT(FieldID, id)) } // IDGTE applies the GTE predicate on the ID field. func IDGTE(id string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldID), id)) - }) + return predicate.AuthRequest(sql.FieldGTE(FieldID, id)) } // IDLT applies the LT predicate on the ID field. func IDLT(id string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldID), id)) - }) + return predicate.AuthRequest(sql.FieldLT(FieldID, id)) } // IDLTE applies the LTE predicate on the ID field. func IDLTE(id string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldID), id)) - }) + return predicate.AuthRequest(sql.FieldLTE(FieldID, id)) } // ClientID applies equality check predicate on the "client_id" field. It's identical to ClientIDEQ. func ClientID(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldClientID), v)) - }) + return predicate.AuthRequest(sql.FieldEQ(FieldClientID, v)) } // RedirectURI applies equality check predicate on the "redirect_uri" field. It's identical to RedirectURIEQ. func RedirectURI(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldRedirectURI), v)) - }) + return predicate.AuthRequest(sql.FieldEQ(FieldRedirectURI, v)) } // Nonce applies equality check predicate on the "nonce" field. It's identical to NonceEQ. func Nonce(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldNonce), v)) - }) + return predicate.AuthRequest(sql.FieldEQ(FieldNonce, v)) } // State applies equality check predicate on the "state" field. It's identical to StateEQ. func State(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldState), v)) - }) + return predicate.AuthRequest(sql.FieldEQ(FieldState, v)) } // ForceApprovalPrompt applies equality check predicate on the "force_approval_prompt" field. It's identical to ForceApprovalPromptEQ. func ForceApprovalPrompt(v bool) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldForceApprovalPrompt), v)) - }) + return predicate.AuthRequest(sql.FieldEQ(FieldForceApprovalPrompt, v)) } // LoggedIn applies equality check predicate on the "logged_in" field. It's identical to LoggedInEQ. func LoggedIn(v bool) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldLoggedIn), v)) - }) + return predicate.AuthRequest(sql.FieldEQ(FieldLoggedIn, v)) } // ClaimsUserID applies equality check predicate on the "claims_user_id" field. It's identical to ClaimsUserIDEQ. func ClaimsUserID(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldClaimsUserID), v)) - }) + return predicate.AuthRequest(sql.FieldEQ(FieldClaimsUserID, v)) } // ClaimsUsername applies equality check predicate on the "claims_username" field. It's identical to ClaimsUsernameEQ. func ClaimsUsername(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldClaimsUsername), v)) - }) + return predicate.AuthRequest(sql.FieldEQ(FieldClaimsUsername, v)) } // ClaimsEmail applies equality check predicate on the "claims_email" field. It's identical to ClaimsEmailEQ. func ClaimsEmail(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldClaimsEmail), v)) - }) + return predicate.AuthRequest(sql.FieldEQ(FieldClaimsEmail, v)) } // ClaimsEmailVerified applies equality check predicate on the "claims_email_verified" field. It's identical to ClaimsEmailVerifiedEQ. func ClaimsEmailVerified(v bool) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldClaimsEmailVerified), v)) - }) + return predicate.AuthRequest(sql.FieldEQ(FieldClaimsEmailVerified, v)) } // ClaimsPreferredUsername applies equality check predicate on the "claims_preferred_username" field. It's identical to ClaimsPreferredUsernameEQ. func ClaimsPreferredUsername(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldClaimsPreferredUsername), v)) - }) + return predicate.AuthRequest(sql.FieldEQ(FieldClaimsPreferredUsername, v)) } // ConnectorID applies equality check predicate on the "connector_id" field. It's identical to ConnectorIDEQ. func ConnectorID(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldConnectorID), v)) - }) + return predicate.AuthRequest(sql.FieldEQ(FieldConnectorID, v)) } // ConnectorData applies equality check predicate on the "connector_data" field. It's identical to ConnectorDataEQ. func ConnectorData(v []byte) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldConnectorData), v)) - }) + return predicate.AuthRequest(sql.FieldEQ(FieldConnectorData, v)) } // Expiry applies equality check predicate on the "expiry" field. It's identical to ExpiryEQ. func Expiry(v time.Time) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldExpiry), v)) - }) + return predicate.AuthRequest(sql.FieldEQ(FieldExpiry, v)) } // CodeChallenge applies equality check predicate on the "code_challenge" field. It's identical to CodeChallengeEQ. func CodeChallenge(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldCodeChallenge), v)) - }) + return predicate.AuthRequest(sql.FieldEQ(FieldCodeChallenge, v)) } // CodeChallengeMethod applies equality check predicate on the "code_challenge_method" field. It's identical to CodeChallengeMethodEQ. func CodeChallengeMethod(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldCodeChallengeMethod), v)) - }) + return predicate.AuthRequest(sql.FieldEQ(FieldCodeChallengeMethod, v)) } // HmacKey applies equality check predicate on the "hmac_key" field. It's identical to HmacKeyEQ. func HmacKey(v []byte) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldHmacKey), v)) - }) + return predicate.AuthRequest(sql.FieldEQ(FieldHmacKey, v)) } // ClientIDEQ applies the EQ predicate on the "client_id" field. func ClientIDEQ(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldClientID), v)) - }) + return predicate.AuthRequest(sql.FieldEQ(FieldClientID, v)) } // ClientIDNEQ applies the NEQ predicate on the "client_id" field. func ClientIDNEQ(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldClientID), v)) - }) + return predicate.AuthRequest(sql.FieldNEQ(FieldClientID, v)) } // ClientIDIn applies the In predicate on the "client_id" field. func ClientIDIn(vs ...string) predicate.AuthRequest { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldClientID), v...)) - }) + return predicate.AuthRequest(sql.FieldIn(FieldClientID, vs...)) } // ClientIDNotIn applies the NotIn predicate on the "client_id" field. func ClientIDNotIn(vs ...string) predicate.AuthRequest { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldClientID), v...)) - }) + return predicate.AuthRequest(sql.FieldNotIn(FieldClientID, vs...)) } // ClientIDGT applies the GT predicate on the "client_id" field. func ClientIDGT(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldClientID), v)) - }) + return predicate.AuthRequest(sql.FieldGT(FieldClientID, v)) } // ClientIDGTE applies the GTE predicate on the "client_id" field. func ClientIDGTE(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldClientID), v)) - }) + return predicate.AuthRequest(sql.FieldGTE(FieldClientID, v)) } // ClientIDLT applies the LT predicate on the "client_id" field. func ClientIDLT(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldClientID), v)) - }) + return predicate.AuthRequest(sql.FieldLT(FieldClientID, v)) } // ClientIDLTE applies the LTE predicate on the "client_id" field. func ClientIDLTE(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldClientID), v)) - }) + return predicate.AuthRequest(sql.FieldLTE(FieldClientID, v)) } // ClientIDContains applies the Contains predicate on the "client_id" field. func ClientIDContains(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldClientID), v)) - }) + return predicate.AuthRequest(sql.FieldContains(FieldClientID, v)) } // ClientIDHasPrefix applies the HasPrefix predicate on the "client_id" field. func ClientIDHasPrefix(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldClientID), v)) - }) + return predicate.AuthRequest(sql.FieldHasPrefix(FieldClientID, v)) } // ClientIDHasSuffix applies the HasSuffix predicate on the "client_id" field. func ClientIDHasSuffix(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldClientID), v)) - }) + return predicate.AuthRequest(sql.FieldHasSuffix(FieldClientID, v)) } // ClientIDEqualFold applies the EqualFold predicate on the "client_id" field. func ClientIDEqualFold(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldClientID), v)) - }) + return predicate.AuthRequest(sql.FieldEqualFold(FieldClientID, v)) } // ClientIDContainsFold applies the ContainsFold predicate on the "client_id" field. func ClientIDContainsFold(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldClientID), v)) - }) + return predicate.AuthRequest(sql.FieldContainsFold(FieldClientID, v)) } // ScopesIsNil applies the IsNil predicate on the "scopes" field. func ScopesIsNil() predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.IsNull(s.C(FieldScopes))) - }) + return predicate.AuthRequest(sql.FieldIsNull(FieldScopes)) } // ScopesNotNil applies the NotNil predicate on the "scopes" field. func ScopesNotNil() predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.NotNull(s.C(FieldScopes))) - }) + return predicate.AuthRequest(sql.FieldNotNull(FieldScopes)) } // ResponseTypesIsNil applies the IsNil predicate on the "response_types" field. func ResponseTypesIsNil() predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.IsNull(s.C(FieldResponseTypes))) - }) + return predicate.AuthRequest(sql.FieldIsNull(FieldResponseTypes)) } // ResponseTypesNotNil applies the NotNil predicate on the "response_types" field. func ResponseTypesNotNil() predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.NotNull(s.C(FieldResponseTypes))) - }) + return predicate.AuthRequest(sql.FieldNotNull(FieldResponseTypes)) } // RedirectURIEQ applies the EQ predicate on the "redirect_uri" field. func RedirectURIEQ(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldRedirectURI), v)) - }) + return predicate.AuthRequest(sql.FieldEQ(FieldRedirectURI, v)) } // RedirectURINEQ applies the NEQ predicate on the "redirect_uri" field. func RedirectURINEQ(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldRedirectURI), v)) - }) + return predicate.AuthRequest(sql.FieldNEQ(FieldRedirectURI, v)) } // RedirectURIIn applies the In predicate on the "redirect_uri" field. func RedirectURIIn(vs ...string) predicate.AuthRequest { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldRedirectURI), v...)) - }) + return predicate.AuthRequest(sql.FieldIn(FieldRedirectURI, vs...)) } // RedirectURINotIn applies the NotIn predicate on the "redirect_uri" field. func RedirectURINotIn(vs ...string) predicate.AuthRequest { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldRedirectURI), v...)) - }) + return predicate.AuthRequest(sql.FieldNotIn(FieldRedirectURI, vs...)) } // RedirectURIGT applies the GT predicate on the "redirect_uri" field. func RedirectURIGT(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldRedirectURI), v)) - }) + return predicate.AuthRequest(sql.FieldGT(FieldRedirectURI, v)) } // RedirectURIGTE applies the GTE predicate on the "redirect_uri" field. func RedirectURIGTE(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldRedirectURI), v)) - }) + return predicate.AuthRequest(sql.FieldGTE(FieldRedirectURI, v)) } // RedirectURILT applies the LT predicate on the "redirect_uri" field. func RedirectURILT(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldRedirectURI), v)) - }) + return predicate.AuthRequest(sql.FieldLT(FieldRedirectURI, v)) } // RedirectURILTE applies the LTE predicate on the "redirect_uri" field. func RedirectURILTE(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldRedirectURI), v)) - }) + return predicate.AuthRequest(sql.FieldLTE(FieldRedirectURI, v)) } // RedirectURIContains applies the Contains predicate on the "redirect_uri" field. func RedirectURIContains(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldRedirectURI), v)) - }) + return predicate.AuthRequest(sql.FieldContains(FieldRedirectURI, v)) } // RedirectURIHasPrefix applies the HasPrefix predicate on the "redirect_uri" field. func RedirectURIHasPrefix(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldRedirectURI), v)) - }) + return predicate.AuthRequest(sql.FieldHasPrefix(FieldRedirectURI, v)) } // RedirectURIHasSuffix applies the HasSuffix predicate on the "redirect_uri" field. func RedirectURIHasSuffix(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldRedirectURI), v)) - }) + return predicate.AuthRequest(sql.FieldHasSuffix(FieldRedirectURI, v)) } // RedirectURIEqualFold applies the EqualFold predicate on the "redirect_uri" field. func RedirectURIEqualFold(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldRedirectURI), v)) - }) + return predicate.AuthRequest(sql.FieldEqualFold(FieldRedirectURI, v)) } // RedirectURIContainsFold applies the ContainsFold predicate on the "redirect_uri" field. func RedirectURIContainsFold(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldRedirectURI), v)) - }) + return predicate.AuthRequest(sql.FieldContainsFold(FieldRedirectURI, v)) } // NonceEQ applies the EQ predicate on the "nonce" field. func NonceEQ(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldNonce), v)) - }) + return predicate.AuthRequest(sql.FieldEQ(FieldNonce, v)) } // NonceNEQ applies the NEQ predicate on the "nonce" field. func NonceNEQ(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldNonce), v)) - }) + return predicate.AuthRequest(sql.FieldNEQ(FieldNonce, v)) } // NonceIn applies the In predicate on the "nonce" field. func NonceIn(vs ...string) predicate.AuthRequest { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldNonce), v...)) - }) + return predicate.AuthRequest(sql.FieldIn(FieldNonce, vs...)) } // NonceNotIn applies the NotIn predicate on the "nonce" field. func NonceNotIn(vs ...string) predicate.AuthRequest { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldNonce), v...)) - }) + return predicate.AuthRequest(sql.FieldNotIn(FieldNonce, vs...)) } // NonceGT applies the GT predicate on the "nonce" field. func NonceGT(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldNonce), v)) - }) + return predicate.AuthRequest(sql.FieldGT(FieldNonce, v)) } // NonceGTE applies the GTE predicate on the "nonce" field. func NonceGTE(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldNonce), v)) - }) + return predicate.AuthRequest(sql.FieldGTE(FieldNonce, v)) } // NonceLT applies the LT predicate on the "nonce" field. func NonceLT(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldNonce), v)) - }) + return predicate.AuthRequest(sql.FieldLT(FieldNonce, v)) } // NonceLTE applies the LTE predicate on the "nonce" field. func NonceLTE(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldNonce), v)) - }) + return predicate.AuthRequest(sql.FieldLTE(FieldNonce, v)) } // NonceContains applies the Contains predicate on the "nonce" field. func NonceContains(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldNonce), v)) - }) + return predicate.AuthRequest(sql.FieldContains(FieldNonce, v)) } // NonceHasPrefix applies the HasPrefix predicate on the "nonce" field. func NonceHasPrefix(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldNonce), v)) - }) + return predicate.AuthRequest(sql.FieldHasPrefix(FieldNonce, v)) } // NonceHasSuffix applies the HasSuffix predicate on the "nonce" field. func NonceHasSuffix(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldNonce), v)) - }) + return predicate.AuthRequest(sql.FieldHasSuffix(FieldNonce, v)) } // NonceEqualFold applies the EqualFold predicate on the "nonce" field. func NonceEqualFold(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldNonce), v)) - }) + return predicate.AuthRequest(sql.FieldEqualFold(FieldNonce, v)) } // NonceContainsFold applies the ContainsFold predicate on the "nonce" field. func NonceContainsFold(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldNonce), v)) - }) + return predicate.AuthRequest(sql.FieldContainsFold(FieldNonce, v)) } // StateEQ applies the EQ predicate on the "state" field. func StateEQ(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldState), v)) - }) + return predicate.AuthRequest(sql.FieldEQ(FieldState, v)) } // StateNEQ applies the NEQ predicate on the "state" field. func StateNEQ(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldState), v)) - }) + return predicate.AuthRequest(sql.FieldNEQ(FieldState, v)) } // StateIn applies the In predicate on the "state" field. func StateIn(vs ...string) predicate.AuthRequest { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldState), v...)) - }) + return predicate.AuthRequest(sql.FieldIn(FieldState, vs...)) } // StateNotIn applies the NotIn predicate on the "state" field. func StateNotIn(vs ...string) predicate.AuthRequest { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldState), v...)) - }) + return predicate.AuthRequest(sql.FieldNotIn(FieldState, vs...)) } // StateGT applies the GT predicate on the "state" field. func StateGT(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldState), v)) - }) + return predicate.AuthRequest(sql.FieldGT(FieldState, v)) } // StateGTE applies the GTE predicate on the "state" field. func StateGTE(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldState), v)) - }) + return predicate.AuthRequest(sql.FieldGTE(FieldState, v)) } // StateLT applies the LT predicate on the "state" field. func StateLT(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldState), v)) - }) + return predicate.AuthRequest(sql.FieldLT(FieldState, v)) } // StateLTE applies the LTE predicate on the "state" field. func StateLTE(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldState), v)) - }) + return predicate.AuthRequest(sql.FieldLTE(FieldState, v)) } // StateContains applies the Contains predicate on the "state" field. func StateContains(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldState), v)) - }) + return predicate.AuthRequest(sql.FieldContains(FieldState, v)) } // StateHasPrefix applies the HasPrefix predicate on the "state" field. func StateHasPrefix(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldState), v)) - }) + return predicate.AuthRequest(sql.FieldHasPrefix(FieldState, v)) } // StateHasSuffix applies the HasSuffix predicate on the "state" field. func StateHasSuffix(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldState), v)) - }) + return predicate.AuthRequest(sql.FieldHasSuffix(FieldState, v)) } // StateEqualFold applies the EqualFold predicate on the "state" field. func StateEqualFold(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldState), v)) - }) + return predicate.AuthRequest(sql.FieldEqualFold(FieldState, v)) } // StateContainsFold applies the ContainsFold predicate on the "state" field. func StateContainsFold(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldState), v)) - }) + return predicate.AuthRequest(sql.FieldContainsFold(FieldState, v)) } // ForceApprovalPromptEQ applies the EQ predicate on the "force_approval_prompt" field. func ForceApprovalPromptEQ(v bool) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldForceApprovalPrompt), v)) - }) + return predicate.AuthRequest(sql.FieldEQ(FieldForceApprovalPrompt, v)) } // ForceApprovalPromptNEQ applies the NEQ predicate on the "force_approval_prompt" field. func ForceApprovalPromptNEQ(v bool) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldForceApprovalPrompt), v)) - }) + return predicate.AuthRequest(sql.FieldNEQ(FieldForceApprovalPrompt, v)) } // LoggedInEQ applies the EQ predicate on the "logged_in" field. func LoggedInEQ(v bool) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldLoggedIn), v)) - }) + return predicate.AuthRequest(sql.FieldEQ(FieldLoggedIn, v)) } // LoggedInNEQ applies the NEQ predicate on the "logged_in" field. func LoggedInNEQ(v bool) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldLoggedIn), v)) - }) + return predicate.AuthRequest(sql.FieldNEQ(FieldLoggedIn, v)) } // ClaimsUserIDEQ applies the EQ predicate on the "claims_user_id" field. func ClaimsUserIDEQ(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldClaimsUserID), v)) - }) + return predicate.AuthRequest(sql.FieldEQ(FieldClaimsUserID, v)) } // ClaimsUserIDNEQ applies the NEQ predicate on the "claims_user_id" field. func ClaimsUserIDNEQ(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldClaimsUserID), v)) - }) + return predicate.AuthRequest(sql.FieldNEQ(FieldClaimsUserID, v)) } // ClaimsUserIDIn applies the In predicate on the "claims_user_id" field. func ClaimsUserIDIn(vs ...string) predicate.AuthRequest { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldClaimsUserID), v...)) - }) + return predicate.AuthRequest(sql.FieldIn(FieldClaimsUserID, vs...)) } // ClaimsUserIDNotIn applies the NotIn predicate on the "claims_user_id" field. func ClaimsUserIDNotIn(vs ...string) predicate.AuthRequest { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldClaimsUserID), v...)) - }) + return predicate.AuthRequest(sql.FieldNotIn(FieldClaimsUserID, vs...)) } // ClaimsUserIDGT applies the GT predicate on the "claims_user_id" field. func ClaimsUserIDGT(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldClaimsUserID), v)) - }) + return predicate.AuthRequest(sql.FieldGT(FieldClaimsUserID, v)) } // ClaimsUserIDGTE applies the GTE predicate on the "claims_user_id" field. func ClaimsUserIDGTE(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldClaimsUserID), v)) - }) + return predicate.AuthRequest(sql.FieldGTE(FieldClaimsUserID, v)) } // ClaimsUserIDLT applies the LT predicate on the "claims_user_id" field. func ClaimsUserIDLT(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldClaimsUserID), v)) - }) + return predicate.AuthRequest(sql.FieldLT(FieldClaimsUserID, v)) } // ClaimsUserIDLTE applies the LTE predicate on the "claims_user_id" field. func ClaimsUserIDLTE(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldClaimsUserID), v)) - }) + return predicate.AuthRequest(sql.FieldLTE(FieldClaimsUserID, v)) } // ClaimsUserIDContains applies the Contains predicate on the "claims_user_id" field. func ClaimsUserIDContains(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldClaimsUserID), v)) - }) + return predicate.AuthRequest(sql.FieldContains(FieldClaimsUserID, v)) } // ClaimsUserIDHasPrefix applies the HasPrefix predicate on the "claims_user_id" field. func ClaimsUserIDHasPrefix(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldClaimsUserID), v)) - }) + return predicate.AuthRequest(sql.FieldHasPrefix(FieldClaimsUserID, v)) } // ClaimsUserIDHasSuffix applies the HasSuffix predicate on the "claims_user_id" field. func ClaimsUserIDHasSuffix(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldClaimsUserID), v)) - }) + return predicate.AuthRequest(sql.FieldHasSuffix(FieldClaimsUserID, v)) } // ClaimsUserIDEqualFold applies the EqualFold predicate on the "claims_user_id" field. func ClaimsUserIDEqualFold(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldClaimsUserID), v)) - }) + return predicate.AuthRequest(sql.FieldEqualFold(FieldClaimsUserID, v)) } // ClaimsUserIDContainsFold applies the ContainsFold predicate on the "claims_user_id" field. func ClaimsUserIDContainsFold(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldClaimsUserID), v)) - }) + return predicate.AuthRequest(sql.FieldContainsFold(FieldClaimsUserID, v)) } // ClaimsUsernameEQ applies the EQ predicate on the "claims_username" field. func ClaimsUsernameEQ(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldClaimsUsername), v)) - }) + return predicate.AuthRequest(sql.FieldEQ(FieldClaimsUsername, v)) } // ClaimsUsernameNEQ applies the NEQ predicate on the "claims_username" field. func ClaimsUsernameNEQ(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldClaimsUsername), v)) - }) + return predicate.AuthRequest(sql.FieldNEQ(FieldClaimsUsername, v)) } // ClaimsUsernameIn applies the In predicate on the "claims_username" field. func ClaimsUsernameIn(vs ...string) predicate.AuthRequest { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldClaimsUsername), v...)) - }) + return predicate.AuthRequest(sql.FieldIn(FieldClaimsUsername, vs...)) } // ClaimsUsernameNotIn applies the NotIn predicate on the "claims_username" field. func ClaimsUsernameNotIn(vs ...string) predicate.AuthRequest { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldClaimsUsername), v...)) - }) + return predicate.AuthRequest(sql.FieldNotIn(FieldClaimsUsername, vs...)) } // ClaimsUsernameGT applies the GT predicate on the "claims_username" field. func ClaimsUsernameGT(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldClaimsUsername), v)) - }) + return predicate.AuthRequest(sql.FieldGT(FieldClaimsUsername, v)) } // ClaimsUsernameGTE applies the GTE predicate on the "claims_username" field. func ClaimsUsernameGTE(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldClaimsUsername), v)) - }) + return predicate.AuthRequest(sql.FieldGTE(FieldClaimsUsername, v)) } // ClaimsUsernameLT applies the LT predicate on the "claims_username" field. func ClaimsUsernameLT(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldClaimsUsername), v)) - }) + return predicate.AuthRequest(sql.FieldLT(FieldClaimsUsername, v)) } // ClaimsUsernameLTE applies the LTE predicate on the "claims_username" field. func ClaimsUsernameLTE(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldClaimsUsername), v)) - }) + return predicate.AuthRequest(sql.FieldLTE(FieldClaimsUsername, v)) } // ClaimsUsernameContains applies the Contains predicate on the "claims_username" field. func ClaimsUsernameContains(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldClaimsUsername), v)) - }) + return predicate.AuthRequest(sql.FieldContains(FieldClaimsUsername, v)) } // ClaimsUsernameHasPrefix applies the HasPrefix predicate on the "claims_username" field. func ClaimsUsernameHasPrefix(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldClaimsUsername), v)) - }) + return predicate.AuthRequest(sql.FieldHasPrefix(FieldClaimsUsername, v)) } // ClaimsUsernameHasSuffix applies the HasSuffix predicate on the "claims_username" field. func ClaimsUsernameHasSuffix(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldClaimsUsername), v)) - }) + return predicate.AuthRequest(sql.FieldHasSuffix(FieldClaimsUsername, v)) } // ClaimsUsernameEqualFold applies the EqualFold predicate on the "claims_username" field. func ClaimsUsernameEqualFold(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldClaimsUsername), v)) - }) + return predicate.AuthRequest(sql.FieldEqualFold(FieldClaimsUsername, v)) } // ClaimsUsernameContainsFold applies the ContainsFold predicate on the "claims_username" field. func ClaimsUsernameContainsFold(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldClaimsUsername), v)) - }) + return predicate.AuthRequest(sql.FieldContainsFold(FieldClaimsUsername, v)) } // ClaimsEmailEQ applies the EQ predicate on the "claims_email" field. func ClaimsEmailEQ(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldClaimsEmail), v)) - }) + return predicate.AuthRequest(sql.FieldEQ(FieldClaimsEmail, v)) } // ClaimsEmailNEQ applies the NEQ predicate on the "claims_email" field. func ClaimsEmailNEQ(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldClaimsEmail), v)) - }) + return predicate.AuthRequest(sql.FieldNEQ(FieldClaimsEmail, v)) } // ClaimsEmailIn applies the In predicate on the "claims_email" field. func ClaimsEmailIn(vs ...string) predicate.AuthRequest { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldClaimsEmail), v...)) - }) + return predicate.AuthRequest(sql.FieldIn(FieldClaimsEmail, vs...)) } // ClaimsEmailNotIn applies the NotIn predicate on the "claims_email" field. func ClaimsEmailNotIn(vs ...string) predicate.AuthRequest { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldClaimsEmail), v...)) - }) + return predicate.AuthRequest(sql.FieldNotIn(FieldClaimsEmail, vs...)) } // ClaimsEmailGT applies the GT predicate on the "claims_email" field. func ClaimsEmailGT(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldClaimsEmail), v)) - }) + return predicate.AuthRequest(sql.FieldGT(FieldClaimsEmail, v)) } // ClaimsEmailGTE applies the GTE predicate on the "claims_email" field. func ClaimsEmailGTE(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldClaimsEmail), v)) - }) + return predicate.AuthRequest(sql.FieldGTE(FieldClaimsEmail, v)) } // ClaimsEmailLT applies the LT predicate on the "claims_email" field. func ClaimsEmailLT(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldClaimsEmail), v)) - }) + return predicate.AuthRequest(sql.FieldLT(FieldClaimsEmail, v)) } // ClaimsEmailLTE applies the LTE predicate on the "claims_email" field. func ClaimsEmailLTE(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldClaimsEmail), v)) - }) + return predicate.AuthRequest(sql.FieldLTE(FieldClaimsEmail, v)) } // ClaimsEmailContains applies the Contains predicate on the "claims_email" field. func ClaimsEmailContains(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldClaimsEmail), v)) - }) + return predicate.AuthRequest(sql.FieldContains(FieldClaimsEmail, v)) } // ClaimsEmailHasPrefix applies the HasPrefix predicate on the "claims_email" field. func ClaimsEmailHasPrefix(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldClaimsEmail), v)) - }) + return predicate.AuthRequest(sql.FieldHasPrefix(FieldClaimsEmail, v)) } // ClaimsEmailHasSuffix applies the HasSuffix predicate on the "claims_email" field. func ClaimsEmailHasSuffix(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldClaimsEmail), v)) - }) + return predicate.AuthRequest(sql.FieldHasSuffix(FieldClaimsEmail, v)) } // ClaimsEmailEqualFold applies the EqualFold predicate on the "claims_email" field. func ClaimsEmailEqualFold(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldClaimsEmail), v)) - }) + return predicate.AuthRequest(sql.FieldEqualFold(FieldClaimsEmail, v)) } // ClaimsEmailContainsFold applies the ContainsFold predicate on the "claims_email" field. func ClaimsEmailContainsFold(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldClaimsEmail), v)) - }) + return predicate.AuthRequest(sql.FieldContainsFold(FieldClaimsEmail, v)) } // ClaimsEmailVerifiedEQ applies the EQ predicate on the "claims_email_verified" field. func ClaimsEmailVerifiedEQ(v bool) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldClaimsEmailVerified), v)) - }) + return predicate.AuthRequest(sql.FieldEQ(FieldClaimsEmailVerified, v)) } // ClaimsEmailVerifiedNEQ applies the NEQ predicate on the "claims_email_verified" field. func ClaimsEmailVerifiedNEQ(v bool) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldClaimsEmailVerified), v)) - }) + return predicate.AuthRequest(sql.FieldNEQ(FieldClaimsEmailVerified, v)) } // ClaimsGroupsIsNil applies the IsNil predicate on the "claims_groups" field. func ClaimsGroupsIsNil() predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.IsNull(s.C(FieldClaimsGroups))) - }) + return predicate.AuthRequest(sql.FieldIsNull(FieldClaimsGroups)) } // ClaimsGroupsNotNil applies the NotNil predicate on the "claims_groups" field. func ClaimsGroupsNotNil() predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.NotNull(s.C(FieldClaimsGroups))) - }) + return predicate.AuthRequest(sql.FieldNotNull(FieldClaimsGroups)) } // ClaimsPreferredUsernameEQ applies the EQ predicate on the "claims_preferred_username" field. func ClaimsPreferredUsernameEQ(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldClaimsPreferredUsername), v)) - }) + return predicate.AuthRequest(sql.FieldEQ(FieldClaimsPreferredUsername, v)) } // ClaimsPreferredUsernameNEQ applies the NEQ predicate on the "claims_preferred_username" field. func ClaimsPreferredUsernameNEQ(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldClaimsPreferredUsername), v)) - }) + return predicate.AuthRequest(sql.FieldNEQ(FieldClaimsPreferredUsername, v)) } // ClaimsPreferredUsernameIn applies the In predicate on the "claims_preferred_username" field. func ClaimsPreferredUsernameIn(vs ...string) predicate.AuthRequest { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldClaimsPreferredUsername), v...)) - }) + return predicate.AuthRequest(sql.FieldIn(FieldClaimsPreferredUsername, vs...)) } // ClaimsPreferredUsernameNotIn applies the NotIn predicate on the "claims_preferred_username" field. func ClaimsPreferredUsernameNotIn(vs ...string) predicate.AuthRequest { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldClaimsPreferredUsername), v...)) - }) + return predicate.AuthRequest(sql.FieldNotIn(FieldClaimsPreferredUsername, vs...)) } // ClaimsPreferredUsernameGT applies the GT predicate on the "claims_preferred_username" field. func ClaimsPreferredUsernameGT(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldClaimsPreferredUsername), v)) - }) + return predicate.AuthRequest(sql.FieldGT(FieldClaimsPreferredUsername, v)) } // ClaimsPreferredUsernameGTE applies the GTE predicate on the "claims_preferred_username" field. func ClaimsPreferredUsernameGTE(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldClaimsPreferredUsername), v)) - }) + return predicate.AuthRequest(sql.FieldGTE(FieldClaimsPreferredUsername, v)) } // ClaimsPreferredUsernameLT applies the LT predicate on the "claims_preferred_username" field. func ClaimsPreferredUsernameLT(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldClaimsPreferredUsername), v)) - }) + return predicate.AuthRequest(sql.FieldLT(FieldClaimsPreferredUsername, v)) } // ClaimsPreferredUsernameLTE applies the LTE predicate on the "claims_preferred_username" field. func ClaimsPreferredUsernameLTE(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldClaimsPreferredUsername), v)) - }) + return predicate.AuthRequest(sql.FieldLTE(FieldClaimsPreferredUsername, v)) } // ClaimsPreferredUsernameContains applies the Contains predicate on the "claims_preferred_username" field. func ClaimsPreferredUsernameContains(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldClaimsPreferredUsername), v)) - }) + return predicate.AuthRequest(sql.FieldContains(FieldClaimsPreferredUsername, v)) } // ClaimsPreferredUsernameHasPrefix applies the HasPrefix predicate on the "claims_preferred_username" field. func ClaimsPreferredUsernameHasPrefix(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldClaimsPreferredUsername), v)) - }) + return predicate.AuthRequest(sql.FieldHasPrefix(FieldClaimsPreferredUsername, v)) } // ClaimsPreferredUsernameHasSuffix applies the HasSuffix predicate on the "claims_preferred_username" field. func ClaimsPreferredUsernameHasSuffix(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldClaimsPreferredUsername), v)) - }) + return predicate.AuthRequest(sql.FieldHasSuffix(FieldClaimsPreferredUsername, v)) } // ClaimsPreferredUsernameEqualFold applies the EqualFold predicate on the "claims_preferred_username" field. func ClaimsPreferredUsernameEqualFold(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldClaimsPreferredUsername), v)) - }) + return predicate.AuthRequest(sql.FieldEqualFold(FieldClaimsPreferredUsername, v)) } // ClaimsPreferredUsernameContainsFold applies the ContainsFold predicate on the "claims_preferred_username" field. func ClaimsPreferredUsernameContainsFold(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldClaimsPreferredUsername), v)) - }) + return predicate.AuthRequest(sql.FieldContainsFold(FieldClaimsPreferredUsername, v)) } // ConnectorIDEQ applies the EQ predicate on the "connector_id" field. func ConnectorIDEQ(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldConnectorID), v)) - }) + return predicate.AuthRequest(sql.FieldEQ(FieldConnectorID, v)) } // ConnectorIDNEQ applies the NEQ predicate on the "connector_id" field. func ConnectorIDNEQ(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldConnectorID), v)) - }) + return predicate.AuthRequest(sql.FieldNEQ(FieldConnectorID, v)) } // ConnectorIDIn applies the In predicate on the "connector_id" field. func ConnectorIDIn(vs ...string) predicate.AuthRequest { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldConnectorID), v...)) - }) + return predicate.AuthRequest(sql.FieldIn(FieldConnectorID, vs...)) } // ConnectorIDNotIn applies the NotIn predicate on the "connector_id" field. func ConnectorIDNotIn(vs ...string) predicate.AuthRequest { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldConnectorID), v...)) - }) + return predicate.AuthRequest(sql.FieldNotIn(FieldConnectorID, vs...)) } // ConnectorIDGT applies the GT predicate on the "connector_id" field. func ConnectorIDGT(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldConnectorID), v)) - }) + return predicate.AuthRequest(sql.FieldGT(FieldConnectorID, v)) } // ConnectorIDGTE applies the GTE predicate on the "connector_id" field. func ConnectorIDGTE(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldConnectorID), v)) - }) + return predicate.AuthRequest(sql.FieldGTE(FieldConnectorID, v)) } // ConnectorIDLT applies the LT predicate on the "connector_id" field. func ConnectorIDLT(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldConnectorID), v)) - }) + return predicate.AuthRequest(sql.FieldLT(FieldConnectorID, v)) } // ConnectorIDLTE applies the LTE predicate on the "connector_id" field. func ConnectorIDLTE(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldConnectorID), v)) - }) + return predicate.AuthRequest(sql.FieldLTE(FieldConnectorID, v)) } // ConnectorIDContains applies the Contains predicate on the "connector_id" field. func ConnectorIDContains(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldConnectorID), v)) - }) + return predicate.AuthRequest(sql.FieldContains(FieldConnectorID, v)) } // ConnectorIDHasPrefix applies the HasPrefix predicate on the "connector_id" field. func ConnectorIDHasPrefix(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldConnectorID), v)) - }) + return predicate.AuthRequest(sql.FieldHasPrefix(FieldConnectorID, v)) } // ConnectorIDHasSuffix applies the HasSuffix predicate on the "connector_id" field. func ConnectorIDHasSuffix(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldConnectorID), v)) - }) + return predicate.AuthRequest(sql.FieldHasSuffix(FieldConnectorID, v)) } // ConnectorIDEqualFold applies the EqualFold predicate on the "connector_id" field. func ConnectorIDEqualFold(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldConnectorID), v)) - }) + return predicate.AuthRequest(sql.FieldEqualFold(FieldConnectorID, v)) } // ConnectorIDContainsFold applies the ContainsFold predicate on the "connector_id" field. func ConnectorIDContainsFold(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldConnectorID), v)) - }) + return predicate.AuthRequest(sql.FieldContainsFold(FieldConnectorID, v)) } // ConnectorDataEQ applies the EQ predicate on the "connector_data" field. func ConnectorDataEQ(v []byte) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldConnectorData), v)) - }) + return predicate.AuthRequest(sql.FieldEQ(FieldConnectorData, v)) } // ConnectorDataNEQ applies the NEQ predicate on the "connector_data" field. func ConnectorDataNEQ(v []byte) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldConnectorData), v)) - }) + return predicate.AuthRequest(sql.FieldNEQ(FieldConnectorData, v)) } // ConnectorDataIn applies the In predicate on the "connector_data" field. func ConnectorDataIn(vs ...[]byte) predicate.AuthRequest { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldConnectorData), v...)) - }) + return predicate.AuthRequest(sql.FieldIn(FieldConnectorData, vs...)) } // ConnectorDataNotIn applies the NotIn predicate on the "connector_data" field. func ConnectorDataNotIn(vs ...[]byte) predicate.AuthRequest { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldConnectorData), v...)) - }) + return predicate.AuthRequest(sql.FieldNotIn(FieldConnectorData, vs...)) } // ConnectorDataGT applies the GT predicate on the "connector_data" field. func ConnectorDataGT(v []byte) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldConnectorData), v)) - }) + return predicate.AuthRequest(sql.FieldGT(FieldConnectorData, v)) } // ConnectorDataGTE applies the GTE predicate on the "connector_data" field. func ConnectorDataGTE(v []byte) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldConnectorData), v)) - }) + return predicate.AuthRequest(sql.FieldGTE(FieldConnectorData, v)) } // ConnectorDataLT applies the LT predicate on the "connector_data" field. func ConnectorDataLT(v []byte) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldConnectorData), v)) - }) + return predicate.AuthRequest(sql.FieldLT(FieldConnectorData, v)) } // ConnectorDataLTE applies the LTE predicate on the "connector_data" field. func ConnectorDataLTE(v []byte) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldConnectorData), v)) - }) + return predicate.AuthRequest(sql.FieldLTE(FieldConnectorData, v)) } // ConnectorDataIsNil applies the IsNil predicate on the "connector_data" field. func ConnectorDataIsNil() predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.IsNull(s.C(FieldConnectorData))) - }) + return predicate.AuthRequest(sql.FieldIsNull(FieldConnectorData)) } // ConnectorDataNotNil applies the NotNil predicate on the "connector_data" field. func ConnectorDataNotNil() predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.NotNull(s.C(FieldConnectorData))) - }) + return predicate.AuthRequest(sql.FieldNotNull(FieldConnectorData)) } // ExpiryEQ applies the EQ predicate on the "expiry" field. func ExpiryEQ(v time.Time) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldExpiry), v)) - }) + return predicate.AuthRequest(sql.FieldEQ(FieldExpiry, v)) } // ExpiryNEQ applies the NEQ predicate on the "expiry" field. func ExpiryNEQ(v time.Time) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldExpiry), v)) - }) + return predicate.AuthRequest(sql.FieldNEQ(FieldExpiry, v)) } // ExpiryIn applies the In predicate on the "expiry" field. func ExpiryIn(vs ...time.Time) predicate.AuthRequest { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldExpiry), v...)) - }) + return predicate.AuthRequest(sql.FieldIn(FieldExpiry, vs...)) } // ExpiryNotIn applies the NotIn predicate on the "expiry" field. func ExpiryNotIn(vs ...time.Time) predicate.AuthRequest { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldExpiry), v...)) - }) + return predicate.AuthRequest(sql.FieldNotIn(FieldExpiry, vs...)) } // ExpiryGT applies the GT predicate on the "expiry" field. func ExpiryGT(v time.Time) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldExpiry), v)) - }) + return predicate.AuthRequest(sql.FieldGT(FieldExpiry, v)) } // ExpiryGTE applies the GTE predicate on the "expiry" field. func ExpiryGTE(v time.Time) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldExpiry), v)) - }) + return predicate.AuthRequest(sql.FieldGTE(FieldExpiry, v)) } // ExpiryLT applies the LT predicate on the "expiry" field. func ExpiryLT(v time.Time) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldExpiry), v)) - }) + return predicate.AuthRequest(sql.FieldLT(FieldExpiry, v)) } // ExpiryLTE applies the LTE predicate on the "expiry" field. func ExpiryLTE(v time.Time) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldExpiry), v)) - }) + return predicate.AuthRequest(sql.FieldLTE(FieldExpiry, v)) } // CodeChallengeEQ applies the EQ predicate on the "code_challenge" field. func CodeChallengeEQ(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldCodeChallenge), v)) - }) + return predicate.AuthRequest(sql.FieldEQ(FieldCodeChallenge, v)) } // CodeChallengeNEQ applies the NEQ predicate on the "code_challenge" field. func CodeChallengeNEQ(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldCodeChallenge), v)) - }) + return predicate.AuthRequest(sql.FieldNEQ(FieldCodeChallenge, v)) } // CodeChallengeIn applies the In predicate on the "code_challenge" field. func CodeChallengeIn(vs ...string) predicate.AuthRequest { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldCodeChallenge), v...)) - }) + return predicate.AuthRequest(sql.FieldIn(FieldCodeChallenge, vs...)) } // CodeChallengeNotIn applies the NotIn predicate on the "code_challenge" field. func CodeChallengeNotIn(vs ...string) predicate.AuthRequest { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldCodeChallenge), v...)) - }) + return predicate.AuthRequest(sql.FieldNotIn(FieldCodeChallenge, vs...)) } // CodeChallengeGT applies the GT predicate on the "code_challenge" field. func CodeChallengeGT(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldCodeChallenge), v)) - }) + return predicate.AuthRequest(sql.FieldGT(FieldCodeChallenge, v)) } // CodeChallengeGTE applies the GTE predicate on the "code_challenge" field. func CodeChallengeGTE(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldCodeChallenge), v)) - }) + return predicate.AuthRequest(sql.FieldGTE(FieldCodeChallenge, v)) } // CodeChallengeLT applies the LT predicate on the "code_challenge" field. func CodeChallengeLT(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldCodeChallenge), v)) - }) + return predicate.AuthRequest(sql.FieldLT(FieldCodeChallenge, v)) } // CodeChallengeLTE applies the LTE predicate on the "code_challenge" field. func CodeChallengeLTE(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldCodeChallenge), v)) - }) + return predicate.AuthRequest(sql.FieldLTE(FieldCodeChallenge, v)) } // CodeChallengeContains applies the Contains predicate on the "code_challenge" field. func CodeChallengeContains(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldCodeChallenge), v)) - }) + return predicate.AuthRequest(sql.FieldContains(FieldCodeChallenge, v)) } // CodeChallengeHasPrefix applies the HasPrefix predicate on the "code_challenge" field. func CodeChallengeHasPrefix(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldCodeChallenge), v)) - }) + return predicate.AuthRequest(sql.FieldHasPrefix(FieldCodeChallenge, v)) } // CodeChallengeHasSuffix applies the HasSuffix predicate on the "code_challenge" field. func CodeChallengeHasSuffix(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldCodeChallenge), v)) - }) + return predicate.AuthRequest(sql.FieldHasSuffix(FieldCodeChallenge, v)) } // CodeChallengeEqualFold applies the EqualFold predicate on the "code_challenge" field. func CodeChallengeEqualFold(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldCodeChallenge), v)) - }) + return predicate.AuthRequest(sql.FieldEqualFold(FieldCodeChallenge, v)) } // CodeChallengeContainsFold applies the ContainsFold predicate on the "code_challenge" field. func CodeChallengeContainsFold(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldCodeChallenge), v)) - }) + return predicate.AuthRequest(sql.FieldContainsFold(FieldCodeChallenge, v)) } // CodeChallengeMethodEQ applies the EQ predicate on the "code_challenge_method" field. func CodeChallengeMethodEQ(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldCodeChallengeMethod), v)) - }) + return predicate.AuthRequest(sql.FieldEQ(FieldCodeChallengeMethod, v)) } // CodeChallengeMethodNEQ applies the NEQ predicate on the "code_challenge_method" field. func CodeChallengeMethodNEQ(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldCodeChallengeMethod), v)) - }) + return predicate.AuthRequest(sql.FieldNEQ(FieldCodeChallengeMethod, v)) } // CodeChallengeMethodIn applies the In predicate on the "code_challenge_method" field. func CodeChallengeMethodIn(vs ...string) predicate.AuthRequest { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldCodeChallengeMethod), v...)) - }) + return predicate.AuthRequest(sql.FieldIn(FieldCodeChallengeMethod, vs...)) } // CodeChallengeMethodNotIn applies the NotIn predicate on the "code_challenge_method" field. func CodeChallengeMethodNotIn(vs ...string) predicate.AuthRequest { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldCodeChallengeMethod), v...)) - }) + return predicate.AuthRequest(sql.FieldNotIn(FieldCodeChallengeMethod, vs...)) } // CodeChallengeMethodGT applies the GT predicate on the "code_challenge_method" field. func CodeChallengeMethodGT(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldCodeChallengeMethod), v)) - }) + return predicate.AuthRequest(sql.FieldGT(FieldCodeChallengeMethod, v)) } // CodeChallengeMethodGTE applies the GTE predicate on the "code_challenge_method" field. func CodeChallengeMethodGTE(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldCodeChallengeMethod), v)) - }) + return predicate.AuthRequest(sql.FieldGTE(FieldCodeChallengeMethod, v)) } // CodeChallengeMethodLT applies the LT predicate on the "code_challenge_method" field. func CodeChallengeMethodLT(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldCodeChallengeMethod), v)) - }) + return predicate.AuthRequest(sql.FieldLT(FieldCodeChallengeMethod, v)) } // CodeChallengeMethodLTE applies the LTE predicate on the "code_challenge_method" field. func CodeChallengeMethodLTE(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldCodeChallengeMethod), v)) - }) + return predicate.AuthRequest(sql.FieldLTE(FieldCodeChallengeMethod, v)) } // CodeChallengeMethodContains applies the Contains predicate on the "code_challenge_method" field. func CodeChallengeMethodContains(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldCodeChallengeMethod), v)) - }) + return predicate.AuthRequest(sql.FieldContains(FieldCodeChallengeMethod, v)) } // CodeChallengeMethodHasPrefix applies the HasPrefix predicate on the "code_challenge_method" field. func CodeChallengeMethodHasPrefix(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldCodeChallengeMethod), v)) - }) + return predicate.AuthRequest(sql.FieldHasPrefix(FieldCodeChallengeMethod, v)) } // CodeChallengeMethodHasSuffix applies the HasSuffix predicate on the "code_challenge_method" field. func CodeChallengeMethodHasSuffix(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldCodeChallengeMethod), v)) - }) + return predicate.AuthRequest(sql.FieldHasSuffix(FieldCodeChallengeMethod, v)) } // CodeChallengeMethodEqualFold applies the EqualFold predicate on the "code_challenge_method" field. func CodeChallengeMethodEqualFold(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldCodeChallengeMethod), v)) - }) + return predicate.AuthRequest(sql.FieldEqualFold(FieldCodeChallengeMethod, v)) } // CodeChallengeMethodContainsFold applies the ContainsFold predicate on the "code_challenge_method" field. func CodeChallengeMethodContainsFold(v string) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldCodeChallengeMethod), v)) - }) + return predicate.AuthRequest(sql.FieldContainsFold(FieldCodeChallengeMethod, v)) } // HmacKeyEQ applies the EQ predicate on the "hmac_key" field. func HmacKeyEQ(v []byte) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldHmacKey), v)) - }) + return predicate.AuthRequest(sql.FieldEQ(FieldHmacKey, v)) } // HmacKeyNEQ applies the NEQ predicate on the "hmac_key" field. func HmacKeyNEQ(v []byte) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldHmacKey), v)) - }) + return predicate.AuthRequest(sql.FieldNEQ(FieldHmacKey, v)) } // HmacKeyIn applies the In predicate on the "hmac_key" field. func HmacKeyIn(vs ...[]byte) predicate.AuthRequest { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.AuthRequest(func(s *sql.Selector) { - // if not arguments were provided, append the FALSE constants, - // since we can't apply "IN ()". This will make this predicate falsy. - if len(v) == 0 { - s.Where(sql.False()) - return - } - s.Where(sql.In(s.C(FieldHmacKey), v...)) - }) + return predicate.AuthRequest(sql.FieldIn(FieldHmacKey, vs...)) } // HmacKeyNotIn applies the NotIn predicate on the "hmac_key" field. func HmacKeyNotIn(vs ...[]byte) predicate.AuthRequest { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.AuthRequest(func(s *sql.Selector) { - // if not arguments were provided, append the FALSE constants, - // since we can't apply "IN ()". This will make this predicate falsy. - if len(v) == 0 { - s.Where(sql.False()) - return - } - s.Where(sql.NotIn(s.C(FieldHmacKey), v...)) - }) + return predicate.AuthRequest(sql.FieldNotIn(FieldHmacKey, vs...)) } // HmacKeyGT applies the GT predicate on the "hmac_key" field. func HmacKeyGT(v []byte) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldHmacKey), v)) - }) + return predicate.AuthRequest(sql.FieldGT(FieldHmacKey, v)) } // HmacKeyGTE applies the GTE predicate on the "hmac_key" field. func HmacKeyGTE(v []byte) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldHmacKey), v)) - }) + return predicate.AuthRequest(sql.FieldGTE(FieldHmacKey, v)) } // HmacKeyLT applies the LT predicate on the "hmac_key" field. func HmacKeyLT(v []byte) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldHmacKey), v)) - }) + return predicate.AuthRequest(sql.FieldLT(FieldHmacKey, v)) } // HmacKeyLTE applies the LTE predicate on the "hmac_key" field. func HmacKeyLTE(v []byte) predicate.AuthRequest { - return predicate.AuthRequest(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldHmacKey), v)) - }) + return predicate.AuthRequest(sql.FieldLTE(FieldHmacKey, v)) } // And groups predicates with the AND operator between them. diff --git a/storage/ent/db/authrequest_create.go b/storage/ent/db/authrequest_create.go index c353c182..cf9c9e17 100644 --- a/storage/ent/db/authrequest_create.go +++ b/storage/ent/db/authrequest_create.go @@ -177,50 +177,8 @@ func (arc *AuthRequestCreate) Mutation() *AuthRequestMutation { // Save creates the AuthRequest in the database. func (arc *AuthRequestCreate) Save(ctx context.Context) (*AuthRequest, error) { - var ( - err error - node *AuthRequest - ) arc.defaults() - if len(arc.hooks) == 0 { - if err = arc.check(); err != nil { - return nil, err - } - node, err = arc.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*AuthRequestMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err = arc.check(); err != nil { - return nil, err - } - arc.mutation = mutation - if node, err = arc.sqlSave(ctx); err != nil { - return nil, err - } - mutation.id = &node.ID - mutation.done = true - return node, err - }) - for i := len(arc.hooks) - 1; i >= 0; i-- { - if arc.hooks[i] == nil { - return nil, fmt.Errorf("db: uninitialized hook (forgotten import db/runtime?)") - } - mut = arc.hooks[i](mut) - } - v, err := mut.Mutate(ctx, arc.mutation) - if err != nil { - return nil, err - } - nv, ok := v.(*AuthRequest) - if !ok { - return nil, fmt.Errorf("unexpected node type %T returned from AuthRequestMutation", v) - } - node = nv - } - return node, err + return withHooks[*AuthRequest, AuthRequestMutation](ctx, arc.sqlSave, arc.mutation, arc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -320,6 +278,9 @@ func (arc *AuthRequestCreate) check() error { } func (arc *AuthRequestCreate) sqlSave(ctx context.Context) (*AuthRequest, error) { + if err := arc.check(); err != nil { + return nil, err + } _node, _spec := arc.createSpec() if err := sqlgraph.CreateNode(ctx, arc.driver, _spec); err != nil { if sqlgraph.IsConstraintError(err) { @@ -334,182 +295,98 @@ func (arc *AuthRequestCreate) sqlSave(ctx context.Context) (*AuthRequest, error) return nil, fmt.Errorf("unexpected AuthRequest.ID type: %T", _spec.ID.Value) } } + arc.mutation.id = &_node.ID + arc.mutation.done = true return _node, nil } func (arc *AuthRequestCreate) createSpec() (*AuthRequest, *sqlgraph.CreateSpec) { var ( _node = &AuthRequest{config: arc.config} - _spec = &sqlgraph.CreateSpec{ - Table: authrequest.Table, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeString, - Column: authrequest.FieldID, - }, - } + _spec = sqlgraph.NewCreateSpec(authrequest.Table, sqlgraph.NewFieldSpec(authrequest.FieldID, field.TypeString)) ) if id, ok := arc.mutation.ID(); ok { _node.ID = id _spec.ID.Value = id } if value, ok := arc.mutation.ClientID(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: authrequest.FieldClientID, - }) + _spec.SetField(authrequest.FieldClientID, field.TypeString, value) _node.ClientID = value } if value, ok := arc.mutation.Scopes(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeJSON, - Value: value, - Column: authrequest.FieldScopes, - }) + _spec.SetField(authrequest.FieldScopes, field.TypeJSON, value) _node.Scopes = value } if value, ok := arc.mutation.ResponseTypes(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeJSON, - Value: value, - Column: authrequest.FieldResponseTypes, - }) + _spec.SetField(authrequest.FieldResponseTypes, field.TypeJSON, value) _node.ResponseTypes = value } if value, ok := arc.mutation.RedirectURI(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: authrequest.FieldRedirectURI, - }) + _spec.SetField(authrequest.FieldRedirectURI, field.TypeString, value) _node.RedirectURI = value } if value, ok := arc.mutation.Nonce(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: authrequest.FieldNonce, - }) + _spec.SetField(authrequest.FieldNonce, field.TypeString, value) _node.Nonce = value } if value, ok := arc.mutation.State(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: authrequest.FieldState, - }) + _spec.SetField(authrequest.FieldState, field.TypeString, value) _node.State = value } if value, ok := arc.mutation.ForceApprovalPrompt(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeBool, - Value: value, - Column: authrequest.FieldForceApprovalPrompt, - }) + _spec.SetField(authrequest.FieldForceApprovalPrompt, field.TypeBool, value) _node.ForceApprovalPrompt = value } if value, ok := arc.mutation.LoggedIn(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeBool, - Value: value, - Column: authrequest.FieldLoggedIn, - }) + _spec.SetField(authrequest.FieldLoggedIn, field.TypeBool, value) _node.LoggedIn = value } if value, ok := arc.mutation.ClaimsUserID(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: authrequest.FieldClaimsUserID, - }) + _spec.SetField(authrequest.FieldClaimsUserID, field.TypeString, value) _node.ClaimsUserID = value } if value, ok := arc.mutation.ClaimsUsername(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: authrequest.FieldClaimsUsername, - }) + _spec.SetField(authrequest.FieldClaimsUsername, field.TypeString, value) _node.ClaimsUsername = value } if value, ok := arc.mutation.ClaimsEmail(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: authrequest.FieldClaimsEmail, - }) + _spec.SetField(authrequest.FieldClaimsEmail, field.TypeString, value) _node.ClaimsEmail = value } if value, ok := arc.mutation.ClaimsEmailVerified(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeBool, - Value: value, - Column: authrequest.FieldClaimsEmailVerified, - }) + _spec.SetField(authrequest.FieldClaimsEmailVerified, field.TypeBool, value) _node.ClaimsEmailVerified = value } if value, ok := arc.mutation.ClaimsGroups(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeJSON, - Value: value, - Column: authrequest.FieldClaimsGroups, - }) + _spec.SetField(authrequest.FieldClaimsGroups, field.TypeJSON, value) _node.ClaimsGroups = value } if value, ok := arc.mutation.ClaimsPreferredUsername(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: authrequest.FieldClaimsPreferredUsername, - }) + _spec.SetField(authrequest.FieldClaimsPreferredUsername, field.TypeString, value) _node.ClaimsPreferredUsername = value } if value, ok := arc.mutation.ConnectorID(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: authrequest.FieldConnectorID, - }) + _spec.SetField(authrequest.FieldConnectorID, field.TypeString, value) _node.ConnectorID = value } if value, ok := arc.mutation.ConnectorData(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeBytes, - Value: value, - Column: authrequest.FieldConnectorData, - }) + _spec.SetField(authrequest.FieldConnectorData, field.TypeBytes, value) _node.ConnectorData = &value } if value, ok := arc.mutation.Expiry(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeTime, - Value: value, - Column: authrequest.FieldExpiry, - }) + _spec.SetField(authrequest.FieldExpiry, field.TypeTime, value) _node.Expiry = value } if value, ok := arc.mutation.CodeChallenge(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: authrequest.FieldCodeChallenge, - }) + _spec.SetField(authrequest.FieldCodeChallenge, field.TypeString, value) _node.CodeChallenge = value } if value, ok := arc.mutation.CodeChallengeMethod(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: authrequest.FieldCodeChallengeMethod, - }) + _spec.SetField(authrequest.FieldCodeChallengeMethod, field.TypeString, value) _node.CodeChallengeMethod = value } if value, ok := arc.mutation.HmacKey(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeBytes, - Value: value, - Column: authrequest.FieldHmacKey, - }) + _spec.SetField(authrequest.FieldHmacKey, field.TypeBytes, value) _node.HmacKey = value } return _node, _spec diff --git a/storage/ent/db/authrequest_delete.go b/storage/ent/db/authrequest_delete.go index 495f4676..a1ddc589 100644 --- a/storage/ent/db/authrequest_delete.go +++ b/storage/ent/db/authrequest_delete.go @@ -4,7 +4,6 @@ package db import ( "context" - "fmt" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" @@ -28,34 +27,7 @@ func (ard *AuthRequestDelete) Where(ps ...predicate.AuthRequest) *AuthRequestDel // Exec executes the deletion query and returns how many vertices were deleted. func (ard *AuthRequestDelete) Exec(ctx context.Context) (int, error) { - var ( - err error - affected int - ) - if len(ard.hooks) == 0 { - affected, err = ard.sqlExec(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*AuthRequestMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - ard.mutation = mutation - affected, err = ard.sqlExec(ctx) - mutation.done = true - return affected, err - }) - for i := len(ard.hooks) - 1; i >= 0; i-- { - if ard.hooks[i] == nil { - return 0, fmt.Errorf("db: uninitialized hook (forgotten import db/runtime?)") - } - mut = ard.hooks[i](mut) - } - if _, err := mut.Mutate(ctx, ard.mutation); err != nil { - return 0, err - } - } - return affected, err + return withHooks[int, AuthRequestMutation](ctx, ard.sqlExec, ard.mutation, ard.hooks) } // ExecX is like Exec, but panics if an error occurs. @@ -68,15 +40,7 @@ func (ard *AuthRequestDelete) ExecX(ctx context.Context) int { } func (ard *AuthRequestDelete) sqlExec(ctx context.Context) (int, error) { - _spec := &sqlgraph.DeleteSpec{ - Node: &sqlgraph.NodeSpec{ - Table: authrequest.Table, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeString, - Column: authrequest.FieldID, - }, - }, - } + _spec := sqlgraph.NewDeleteSpec(authrequest.Table, sqlgraph.NewFieldSpec(authrequest.FieldID, field.TypeString)) if ps := ard.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { @@ -88,6 +52,7 @@ func (ard *AuthRequestDelete) sqlExec(ctx context.Context) (int, error) { if err != nil && sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } + ard.mutation.done = true return affected, err } @@ -96,6 +61,12 @@ type AuthRequestDeleteOne struct { ard *AuthRequestDelete } +// Where appends a list predicates to the AuthRequestDelete builder. +func (ardo *AuthRequestDeleteOne) Where(ps ...predicate.AuthRequest) *AuthRequestDeleteOne { + ardo.ard.mutation.Where(ps...) + return ardo +} + // Exec executes the deletion query. func (ardo *AuthRequestDeleteOne) Exec(ctx context.Context) error { n, err := ardo.ard.Exec(ctx) @@ -111,5 +82,7 @@ func (ardo *AuthRequestDeleteOne) Exec(ctx context.Context) error { // ExecX is like Exec, but panics if an error occurs. func (ardo *AuthRequestDeleteOne) ExecX(ctx context.Context) { - ardo.ard.ExecX(ctx) + if err := ardo.Exec(ctx); err != nil { + panic(err) + } } diff --git a/storage/ent/db/authrequest_query.go b/storage/ent/db/authrequest_query.go index 577da17b..0bab5d4d 100644 --- a/storage/ent/db/authrequest_query.go +++ b/storage/ent/db/authrequest_query.go @@ -17,11 +17,9 @@ import ( // AuthRequestQuery is the builder for querying AuthRequest entities. type AuthRequestQuery struct { config - limit *int - offset *int - unique *bool + ctx *QueryContext order []OrderFunc - fields []string + inters []Interceptor predicates []predicate.AuthRequest // intermediate query (i.e. traversal path). sql *sql.Selector @@ -34,26 +32,26 @@ func (arq *AuthRequestQuery) Where(ps ...predicate.AuthRequest) *AuthRequestQuer return arq } -// Limit adds a limit step to the query. +// Limit the number of records to be returned by this query. func (arq *AuthRequestQuery) Limit(limit int) *AuthRequestQuery { - arq.limit = &limit + arq.ctx.Limit = &limit return arq } -// Offset adds an offset step to the query. +// Offset to start from. func (arq *AuthRequestQuery) Offset(offset int) *AuthRequestQuery { - arq.offset = &offset + arq.ctx.Offset = &offset return arq } // Unique configures the query builder to filter duplicate records on query. // By default, unique is set to true, and can be disabled using this method. func (arq *AuthRequestQuery) Unique(unique bool) *AuthRequestQuery { - arq.unique = &unique + arq.ctx.Unique = &unique return arq } -// Order adds an order step to the query. +// Order specifies how the records should be ordered. func (arq *AuthRequestQuery) Order(o ...OrderFunc) *AuthRequestQuery { arq.order = append(arq.order, o...) return arq @@ -62,7 +60,7 @@ func (arq *AuthRequestQuery) Order(o ...OrderFunc) *AuthRequestQuery { // First returns the first AuthRequest entity from the query. // Returns a *NotFoundError when no AuthRequest was found. func (arq *AuthRequestQuery) First(ctx context.Context) (*AuthRequest, error) { - nodes, err := arq.Limit(1).All(ctx) + nodes, err := arq.Limit(1).All(setContextOp(ctx, arq.ctx, "First")) if err != nil { return nil, err } @@ -85,7 +83,7 @@ func (arq *AuthRequestQuery) FirstX(ctx context.Context) *AuthRequest { // Returns a *NotFoundError when no AuthRequest ID was found. func (arq *AuthRequestQuery) FirstID(ctx context.Context) (id string, err error) { var ids []string - if ids, err = arq.Limit(1).IDs(ctx); err != nil { + if ids, err = arq.Limit(1).IDs(setContextOp(ctx, arq.ctx, "FirstID")); err != nil { return } if len(ids) == 0 { @@ -108,7 +106,7 @@ func (arq *AuthRequestQuery) FirstIDX(ctx context.Context) string { // 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) + nodes, err := arq.Limit(2).All(setContextOp(ctx, arq.ctx, "Only")) if err != nil { return nil, err } @@ -136,7 +134,7 @@ func (arq *AuthRequestQuery) OnlyX(ctx context.Context) *AuthRequest { // Returns a *NotFoundError when no entities are found. func (arq *AuthRequestQuery) OnlyID(ctx context.Context) (id string, err error) { var ids []string - if ids, err = arq.Limit(2).IDs(ctx); err != nil { + if ids, err = arq.Limit(2).IDs(setContextOp(ctx, arq.ctx, "OnlyID")); err != nil { return } switch len(ids) { @@ -161,10 +159,12 @@ func (arq *AuthRequestQuery) OnlyIDX(ctx context.Context) string { // All executes the query and returns a list of AuthRequests. func (arq *AuthRequestQuery) All(ctx context.Context) ([]*AuthRequest, error) { + ctx = setContextOp(ctx, arq.ctx, "All") if err := arq.prepareQuery(ctx); err != nil { return nil, err } - return arq.sqlAll(ctx) + qr := querierAll[[]*AuthRequest, *AuthRequestQuery]() + return withInterceptors[[]*AuthRequest](ctx, arq, qr, arq.inters) } // AllX is like All, but panics if an error occurs. @@ -177,9 +177,12 @@ func (arq *AuthRequestQuery) AllX(ctx context.Context) []*AuthRequest { } // IDs executes the query and returns a list of AuthRequest IDs. -func (arq *AuthRequestQuery) IDs(ctx context.Context) ([]string, error) { - var ids []string - if err := arq.Select(authrequest.FieldID).Scan(ctx, &ids); err != nil { +func (arq *AuthRequestQuery) IDs(ctx context.Context) (ids []string, err error) { + if arq.ctx.Unique == nil && arq.path != nil { + arq.Unique(true) + } + ctx = setContextOp(ctx, arq.ctx, "IDs") + if err = arq.Select(authrequest.FieldID).Scan(ctx, &ids); err != nil { return nil, err } return ids, nil @@ -196,10 +199,11 @@ func (arq *AuthRequestQuery) IDsX(ctx context.Context) []string { // Count returns the count of the given query. func (arq *AuthRequestQuery) Count(ctx context.Context) (int, error) { + ctx = setContextOp(ctx, arq.ctx, "Count") if err := arq.prepareQuery(ctx); err != nil { return 0, err } - return arq.sqlCount(ctx) + return withInterceptors[int](ctx, arq, querierCount[*AuthRequestQuery](), arq.inters) } // CountX is like Count, but panics if an error occurs. @@ -213,10 +217,15 @@ func (arq *AuthRequestQuery) CountX(ctx context.Context) int { // Exist returns true if the query has elements in the graph. func (arq *AuthRequestQuery) Exist(ctx context.Context) (bool, error) { - if err := arq.prepareQuery(ctx); err != nil { - return false, err + ctx = setContextOp(ctx, arq.ctx, "Exist") + switch _, err := arq.FirstID(ctx); { + case IsNotFound(err): + return false, nil + case err != nil: + return false, fmt.Errorf("db: check existence: %w", err) + default: + return true, nil } - return arq.sqlExist(ctx) } // ExistX is like Exist, but panics if an error occurs. @@ -236,14 +245,13 @@ func (arq *AuthRequestQuery) Clone() *AuthRequestQuery { } return &AuthRequestQuery{ config: arq.config, - limit: arq.limit, - offset: arq.offset, + ctx: arq.ctx.Clone(), order: append([]OrderFunc{}, arq.order...), + inters: append([]Interceptor{}, arq.inters...), predicates: append([]predicate.AuthRequest{}, arq.predicates...), // clone intermediate query. - sql: arq.sql.Clone(), - path: arq.path, - unique: arq.unique, + sql: arq.sql.Clone(), + path: arq.path, } } @@ -261,18 +269,12 @@ func (arq *AuthRequestQuery) Clone() *AuthRequestQuery { // GroupBy(authrequest.FieldClientID). // Aggregate(db.Count()). // Scan(ctx, &v) -// func (arq *AuthRequestQuery) GroupBy(field string, fields ...string) *AuthRequestGroupBy { - grbuild := &AuthRequestGroupBy{config: arq.config} - grbuild.fields = append([]string{field}, fields...) - grbuild.path = func(ctx context.Context) (prev *sql.Selector, err error) { - if err := arq.prepareQuery(ctx); err != nil { - return nil, err - } - return arq.sqlQuery(ctx), nil - } + arq.ctx.Fields = append([]string{field}, fields...) + grbuild := &AuthRequestGroupBy{build: arq} + grbuild.flds = &arq.ctx.Fields grbuild.label = authrequest.Label - grbuild.flds, grbuild.scan = &grbuild.fields, grbuild.Scan + grbuild.scan = grbuild.Scan return grbuild } @@ -288,17 +290,31 @@ func (arq *AuthRequestQuery) GroupBy(field string, fields ...string) *AuthReques // client.AuthRequest.Query(). // Select(authrequest.FieldClientID). // Scan(ctx, &v) -// func (arq *AuthRequestQuery) Select(fields ...string) *AuthRequestSelect { - arq.fields = append(arq.fields, fields...) - selbuild := &AuthRequestSelect{AuthRequestQuery: arq} - selbuild.label = authrequest.Label - selbuild.flds, selbuild.scan = &arq.fields, selbuild.Scan - return selbuild + arq.ctx.Fields = append(arq.ctx.Fields, fields...) + sbuild := &AuthRequestSelect{AuthRequestQuery: arq} + sbuild.label = authrequest.Label + sbuild.flds, sbuild.scan = &arq.ctx.Fields, sbuild.Scan + return sbuild +} + +// Aggregate returns a AuthRequestSelect configured with the given aggregations. +func (arq *AuthRequestQuery) Aggregate(fns ...AggregateFunc) *AuthRequestSelect { + return arq.Select().Aggregate(fns...) } func (arq *AuthRequestQuery) prepareQuery(ctx context.Context) error { - for _, f := range arq.fields { + for _, inter := range arq.inters { + if inter == nil { + return fmt.Errorf("db: uninitialized interceptor (forgotten import db/runtime?)") + } + if trv, ok := inter.(Traverser); ok { + if err := trv.Traverse(ctx, arq); err != nil { + return err + } + } + } + for _, f := range arq.ctx.Fields { if !authrequest.ValidColumn(f) { return &ValidationError{Name: f, err: fmt.Errorf("db: invalid field %q for query", f)} } @@ -318,10 +334,10 @@ func (arq *AuthRequestQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([] nodes = []*AuthRequest{} _spec = arq.querySpec() ) - _spec.ScanValues = func(columns []string) ([]interface{}, error) { + _spec.ScanValues = func(columns []string) ([]any, error) { return (*AuthRequest).scanValues(nil, columns) } - _spec.Assign = func(columns []string, values []interface{}) error { + _spec.Assign = func(columns []string, values []any) error { node := &AuthRequest{config: arq.config} nodes = append(nodes, node) return node.assignValues(columns, values) @@ -340,38 +356,22 @@ func (arq *AuthRequestQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([] 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 + _spec.Node.Columns = arq.ctx.Fields + if len(arq.ctx.Fields) > 0 { + _spec.Unique = arq.ctx.Unique != nil && *arq.ctx.Unique } return sqlgraph.CountNodes(ctx, arq.driver, _spec) } -func (arq *AuthRequestQuery) sqlExist(ctx context.Context) (bool, error) { - n, err := arq.sqlCount(ctx) - if err != nil { - return false, fmt.Errorf("db: check existence: %w", err) - } - return n > 0, nil -} - func (arq *AuthRequestQuery) querySpec() *sqlgraph.QuerySpec { - _spec := &sqlgraph.QuerySpec{ - Node: &sqlgraph.NodeSpec{ - Table: authrequest.Table, - Columns: authrequest.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeString, - Column: authrequest.FieldID, - }, - }, - From: arq.sql, - Unique: true, - } - if unique := arq.unique; unique != nil { + _spec := sqlgraph.NewQuerySpec(authrequest.Table, authrequest.Columns, sqlgraph.NewFieldSpec(authrequest.FieldID, field.TypeString)) + _spec.From = arq.sql + if unique := arq.ctx.Unique; unique != nil { _spec.Unique = *unique + } else if arq.path != nil { + _spec.Unique = true } - if fields := arq.fields; len(fields) > 0 { + if fields := arq.ctx.Fields; len(fields) > 0 { _spec.Node.Columns = make([]string, 0, len(fields)) _spec.Node.Columns = append(_spec.Node.Columns, authrequest.FieldID) for i := range fields { @@ -387,10 +387,10 @@ func (arq *AuthRequestQuery) querySpec() *sqlgraph.QuerySpec { } } } - if limit := arq.limit; limit != nil { + if limit := arq.ctx.Limit; limit != nil { _spec.Limit = *limit } - if offset := arq.offset; offset != nil { + if offset := arq.ctx.Offset; offset != nil { _spec.Offset = *offset } if ps := arq.order; len(ps) > 0 { @@ -406,7 +406,7 @@ func (arq *AuthRequestQuery) querySpec() *sqlgraph.QuerySpec { func (arq *AuthRequestQuery) sqlQuery(ctx context.Context) *sql.Selector { builder := sql.Dialect(arq.driver.Dialect()) t1 := builder.Table(authrequest.Table) - columns := arq.fields + columns := arq.ctx.Fields if len(columns) == 0 { columns = authrequest.Columns } @@ -415,7 +415,7 @@ func (arq *AuthRequestQuery) sqlQuery(ctx context.Context) *sql.Selector { selector = arq.sql selector.Select(selector.Columns(columns...)...) } - if arq.unique != nil && *arq.unique { + if arq.ctx.Unique != nil && *arq.ctx.Unique { selector.Distinct() } for _, p := range arq.predicates { @@ -424,12 +424,12 @@ func (arq *AuthRequestQuery) sqlQuery(ctx context.Context) *sql.Selector { for _, p := range arq.order { p(selector) } - if offset := arq.offset; offset != nil { + if offset := arq.ctx.Offset; offset != nil { // limit is mandatory for offset clause. We start // with default value, and override it below if needed. selector.Offset(*offset).Limit(math.MaxInt32) } - if limit := arq.limit; limit != nil { + if limit := arq.ctx.Limit; limit != nil { selector.Limit(*limit) } return selector @@ -437,13 +437,8 @@ func (arq *AuthRequestQuery) sqlQuery(ctx context.Context) *sql.Selector { // AuthRequestGroupBy is the group-by builder for AuthRequest entities. type AuthRequestGroupBy struct { - config selector - fields []string - fns []AggregateFunc - // intermediate query (i.e. traversal path). - sql *sql.Selector - path func(context.Context) (*sql.Selector, error) + build *AuthRequestQuery } // Aggregate adds the given aggregation functions to the group-by query. @@ -452,74 +447,77 @@ func (argb *AuthRequestGroupBy) Aggregate(fns ...AggregateFunc) *AuthRequestGrou return argb } -// Scan applies the group-by query and scans the result into the given value. -func (argb *AuthRequestGroupBy) Scan(ctx context.Context, v interface{}) error { - query, err := argb.path(ctx) - if err != nil { +// Scan applies the selector query and scans the result into the given value. +func (argb *AuthRequestGroupBy) Scan(ctx context.Context, v any) error { + ctx = setContextOp(ctx, argb.build.ctx, "GroupBy") + if err := argb.build.prepareQuery(ctx); err != nil { return err } - argb.sql = query - return argb.sqlScan(ctx, v) + return scanWithInterceptors[*AuthRequestQuery, *AuthRequestGroupBy](ctx, argb.build, argb, argb.build.inters, v) } -func (argb *AuthRequestGroupBy) sqlScan(ctx context.Context, v interface{}) error { - for _, f := range argb.fields { - if !authrequest.ValidColumn(f) { - return &ValidationError{Name: f, err: fmt.Errorf("invalid field %q for group-by", f)} - } - } - selector := argb.sqlQuery() - if err := selector.Err(); err != nil { - return err - } - rows := &sql.Rows{} - query, args := selector.Query() - if err := argb.driver.Query(ctx, query, args, rows); err != nil { - return err - } - defer rows.Close() - return sql.ScanSlice(rows, v) -} - -func (argb *AuthRequestGroupBy) sqlQuery() *sql.Selector { - selector := argb.sql.Select() +func (argb *AuthRequestGroupBy) sqlScan(ctx context.Context, root *AuthRequestQuery, v any) error { + selector := root.sqlQuery(ctx).Select() aggregation := make([]string, 0, len(argb.fns)) for _, fn := range argb.fns { aggregation = append(aggregation, fn(selector)) } - // If no columns were selected in a custom aggregation function, the default - // selection is the fields used for "group-by", and the aggregation functions. if len(selector.SelectedColumns()) == 0 { - columns := make([]string, 0, len(argb.fields)+len(argb.fns)) - for _, f := range argb.fields { + columns := make([]string, 0, len(*argb.flds)+len(argb.fns)) + for _, f := range *argb.flds { columns = append(columns, selector.C(f)) } columns = append(columns, aggregation...) selector.Select(columns...) } - return selector.GroupBy(selector.Columns(argb.fields...)...) + selector.GroupBy(selector.Columns(*argb.flds...)...) + if err := selector.Err(); err != nil { + return err + } + rows := &sql.Rows{} + query, args := selector.Query() + if err := argb.build.driver.Query(ctx, query, args, rows); err != nil { + return err + } + defer rows.Close() + return sql.ScanSlice(rows, v) } // AuthRequestSelect is the builder for selecting fields of AuthRequest entities. type AuthRequestSelect struct { *AuthRequestQuery selector - // intermediate query (i.e. traversal path). - sql *sql.Selector +} + +// Aggregate adds the given aggregation functions to the selector query. +func (ars *AuthRequestSelect) Aggregate(fns ...AggregateFunc) *AuthRequestSelect { + ars.fns = append(ars.fns, fns...) + return ars } // Scan applies the selector query and scans the result into the given value. -func (ars *AuthRequestSelect) Scan(ctx context.Context, v interface{}) error { +func (ars *AuthRequestSelect) Scan(ctx context.Context, v any) error { + ctx = setContextOp(ctx, ars.ctx, "Select") if err := ars.prepareQuery(ctx); err != nil { return err } - ars.sql = ars.AuthRequestQuery.sqlQuery(ctx) - return ars.sqlScan(ctx, v) + return scanWithInterceptors[*AuthRequestQuery, *AuthRequestSelect](ctx, ars.AuthRequestQuery, ars, ars.inters, v) } -func (ars *AuthRequestSelect) sqlScan(ctx context.Context, v interface{}) error { +func (ars *AuthRequestSelect) sqlScan(ctx context.Context, root *AuthRequestQuery, v any) error { + selector := root.sqlQuery(ctx) + aggregation := make([]string, 0, len(ars.fns)) + for _, fn := range ars.fns { + aggregation = append(aggregation, fn(selector)) + } + switch n := len(*ars.selector.flds); { + case n == 0 && len(aggregation) > 0: + selector.Select(aggregation...) + case n != 0 && len(aggregation) > 0: + selector.AppendSelect(aggregation...) + } rows := &sql.Rows{} - query, args := ars.sql.Query() + query, args := selector.Query() if err := ars.driver.Query(ctx, query, args, rows); err != nil { return err } diff --git a/storage/ent/db/authrequest_update.go b/storage/ent/db/authrequest_update.go index f0bf9b34..1a72d765 100644 --- a/storage/ent/db/authrequest_update.go +++ b/storage/ent/db/authrequest_update.go @@ -10,6 +10,7 @@ import ( "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/dialect/sql/sqljson" "entgo.io/ent/schema/field" "github.com/dexidp/dex/storage/ent/db/authrequest" "github.com/dexidp/dex/storage/ent/db/predicate" @@ -40,6 +41,12 @@ func (aru *AuthRequestUpdate) SetScopes(s []string) *AuthRequestUpdate { return aru } +// AppendScopes appends s to the "scopes" field. +func (aru *AuthRequestUpdate) AppendScopes(s []string) *AuthRequestUpdate { + aru.mutation.AppendScopes(s) + return aru +} + // ClearScopes clears the value of the "scopes" field. func (aru *AuthRequestUpdate) ClearScopes() *AuthRequestUpdate { aru.mutation.ClearScopes() @@ -52,6 +59,12 @@ func (aru *AuthRequestUpdate) SetResponseTypes(s []string) *AuthRequestUpdate { return aru } +// AppendResponseTypes appends s to the "response_types" field. +func (aru *AuthRequestUpdate) AppendResponseTypes(s []string) *AuthRequestUpdate { + aru.mutation.AppendResponseTypes(s) + return aru +} + // ClearResponseTypes clears the value of the "response_types" field. func (aru *AuthRequestUpdate) ClearResponseTypes() *AuthRequestUpdate { aru.mutation.ClearResponseTypes() @@ -118,6 +131,12 @@ func (aru *AuthRequestUpdate) SetClaimsGroups(s []string) *AuthRequestUpdate { return aru } +// AppendClaimsGroups appends s to the "claims_groups" field. +func (aru *AuthRequestUpdate) AppendClaimsGroups(s []string) *AuthRequestUpdate { + aru.mutation.AppendClaimsGroups(s) + return aru +} + // ClearClaimsGroups clears the value of the "claims_groups" field. func (aru *AuthRequestUpdate) ClearClaimsGroups() *AuthRequestUpdate { aru.mutation.ClearClaimsGroups() @@ -203,34 +222,7 @@ func (aru *AuthRequestUpdate) Mutation() *AuthRequestMutation { // Save executes the query and returns the number of nodes affected by the update operation. func (aru *AuthRequestUpdate) Save(ctx context.Context) (int, error) { - var ( - err error - affected int - ) - if len(aru.hooks) == 0 { - affected, err = aru.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*AuthRequestMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - aru.mutation = mutation - affected, err = aru.sqlSave(ctx) - mutation.done = true - return affected, err - }) - for i := len(aru.hooks) - 1; i >= 0; i-- { - if aru.hooks[i] == nil { - return 0, fmt.Errorf("db: uninitialized hook (forgotten import db/runtime?)") - } - mut = aru.hooks[i](mut) - } - if _, err := mut.Mutate(ctx, aru.mutation); err != nil { - return 0, err - } - } - return affected, err + return withHooks[int, AuthRequestMutation](ctx, aru.sqlSave, aru.mutation, aru.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -256,16 +248,7 @@ func (aru *AuthRequestUpdate) ExecX(ctx context.Context) { } func (aru *AuthRequestUpdate) sqlSave(ctx context.Context) (n int, err error) { - _spec := &sqlgraph.UpdateSpec{ - Node: &sqlgraph.NodeSpec{ - Table: authrequest.Table, - Columns: authrequest.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeString, - Column: authrequest.FieldID, - }, - }, - } + _spec := sqlgraph.NewUpdateSpec(authrequest.Table, authrequest.Columns, sqlgraph.NewFieldSpec(authrequest.FieldID, field.TypeString)) if ps := aru.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { @@ -274,168 +257,91 @@ func (aru *AuthRequestUpdate) sqlSave(ctx context.Context) (n int, err error) { } } if value, ok := aru.mutation.ClientID(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: authrequest.FieldClientID, - }) + _spec.SetField(authrequest.FieldClientID, field.TypeString, value) } if value, ok := aru.mutation.Scopes(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeJSON, - Value: value, - Column: authrequest.FieldScopes, + _spec.SetField(authrequest.FieldScopes, field.TypeJSON, value) + } + if value, ok := aru.mutation.AppendedScopes(); ok { + _spec.AddModifier(func(u *sql.UpdateBuilder) { + sqljson.Append(u, authrequest.FieldScopes, value) }) } if aru.mutation.ScopesCleared() { - _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ - Type: field.TypeJSON, - Column: authrequest.FieldScopes, - }) + _spec.ClearField(authrequest.FieldScopes, field.TypeJSON) } if value, ok := aru.mutation.ResponseTypes(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeJSON, - Value: value, - Column: authrequest.FieldResponseTypes, + _spec.SetField(authrequest.FieldResponseTypes, field.TypeJSON, value) + } + if value, ok := aru.mutation.AppendedResponseTypes(); ok { + _spec.AddModifier(func(u *sql.UpdateBuilder) { + sqljson.Append(u, authrequest.FieldResponseTypes, value) }) } if aru.mutation.ResponseTypesCleared() { - _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ - Type: field.TypeJSON, - Column: authrequest.FieldResponseTypes, - }) + _spec.ClearField(authrequest.FieldResponseTypes, field.TypeJSON) } if value, ok := aru.mutation.RedirectURI(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: authrequest.FieldRedirectURI, - }) + _spec.SetField(authrequest.FieldRedirectURI, field.TypeString, value) } if value, ok := aru.mutation.Nonce(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: authrequest.FieldNonce, - }) + _spec.SetField(authrequest.FieldNonce, field.TypeString, value) } if value, ok := aru.mutation.State(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: authrequest.FieldState, - }) + _spec.SetField(authrequest.FieldState, field.TypeString, value) } if value, ok := aru.mutation.ForceApprovalPrompt(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeBool, - Value: value, - Column: authrequest.FieldForceApprovalPrompt, - }) + _spec.SetField(authrequest.FieldForceApprovalPrompt, field.TypeBool, value) } if value, ok := aru.mutation.LoggedIn(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeBool, - Value: value, - Column: authrequest.FieldLoggedIn, - }) + _spec.SetField(authrequest.FieldLoggedIn, field.TypeBool, value) } if value, ok := aru.mutation.ClaimsUserID(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: authrequest.FieldClaimsUserID, - }) + _spec.SetField(authrequest.FieldClaimsUserID, field.TypeString, value) } if value, ok := aru.mutation.ClaimsUsername(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: authrequest.FieldClaimsUsername, - }) + _spec.SetField(authrequest.FieldClaimsUsername, field.TypeString, value) } if value, ok := aru.mutation.ClaimsEmail(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: authrequest.FieldClaimsEmail, - }) + _spec.SetField(authrequest.FieldClaimsEmail, field.TypeString, value) } if value, ok := aru.mutation.ClaimsEmailVerified(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeBool, - Value: value, - Column: authrequest.FieldClaimsEmailVerified, - }) + _spec.SetField(authrequest.FieldClaimsEmailVerified, field.TypeBool, value) } if value, ok := aru.mutation.ClaimsGroups(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeJSON, - Value: value, - Column: authrequest.FieldClaimsGroups, + _spec.SetField(authrequest.FieldClaimsGroups, field.TypeJSON, value) + } + if value, ok := aru.mutation.AppendedClaimsGroups(); ok { + _spec.AddModifier(func(u *sql.UpdateBuilder) { + sqljson.Append(u, authrequest.FieldClaimsGroups, value) }) } if aru.mutation.ClaimsGroupsCleared() { - _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ - Type: field.TypeJSON, - Column: authrequest.FieldClaimsGroups, - }) + _spec.ClearField(authrequest.FieldClaimsGroups, field.TypeJSON) } if value, ok := aru.mutation.ClaimsPreferredUsername(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: authrequest.FieldClaimsPreferredUsername, - }) + _spec.SetField(authrequest.FieldClaimsPreferredUsername, field.TypeString, value) } if value, ok := aru.mutation.ConnectorID(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: authrequest.FieldConnectorID, - }) + _spec.SetField(authrequest.FieldConnectorID, field.TypeString, value) } if value, ok := aru.mutation.ConnectorData(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeBytes, - Value: value, - Column: authrequest.FieldConnectorData, - }) + _spec.SetField(authrequest.FieldConnectorData, field.TypeBytes, value) } if aru.mutation.ConnectorDataCleared() { - _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ - Type: field.TypeBytes, - Column: authrequest.FieldConnectorData, - }) + _spec.ClearField(authrequest.FieldConnectorData, field.TypeBytes) } if value, ok := aru.mutation.Expiry(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeTime, - Value: value, - Column: authrequest.FieldExpiry, - }) + _spec.SetField(authrequest.FieldExpiry, field.TypeTime, value) } if value, ok := aru.mutation.CodeChallenge(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: authrequest.FieldCodeChallenge, - }) + _spec.SetField(authrequest.FieldCodeChallenge, field.TypeString, value) } if value, ok := aru.mutation.CodeChallengeMethod(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: authrequest.FieldCodeChallengeMethod, - }) + _spec.SetField(authrequest.FieldCodeChallengeMethod, field.TypeString, value) } if value, ok := aru.mutation.HmacKey(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeBytes, - Value: value, - Column: authrequest.FieldHmacKey, - }) + _spec.SetField(authrequest.FieldHmacKey, field.TypeBytes, value) } if n, err = sqlgraph.UpdateNodes(ctx, aru.driver, _spec); err != nil { if _, ok := err.(*sqlgraph.NotFoundError); ok { @@ -445,6 +351,7 @@ func (aru *AuthRequestUpdate) sqlSave(ctx context.Context) (n int, err error) { } return 0, err } + aru.mutation.done = true return n, nil } @@ -468,6 +375,12 @@ func (aruo *AuthRequestUpdateOne) SetScopes(s []string) *AuthRequestUpdateOne { return aruo } +// AppendScopes appends s to the "scopes" field. +func (aruo *AuthRequestUpdateOne) AppendScopes(s []string) *AuthRequestUpdateOne { + aruo.mutation.AppendScopes(s) + return aruo +} + // ClearScopes clears the value of the "scopes" field. func (aruo *AuthRequestUpdateOne) ClearScopes() *AuthRequestUpdateOne { aruo.mutation.ClearScopes() @@ -480,6 +393,12 @@ func (aruo *AuthRequestUpdateOne) SetResponseTypes(s []string) *AuthRequestUpdat return aruo } +// AppendResponseTypes appends s to the "response_types" field. +func (aruo *AuthRequestUpdateOne) AppendResponseTypes(s []string) *AuthRequestUpdateOne { + aruo.mutation.AppendResponseTypes(s) + return aruo +} + // ClearResponseTypes clears the value of the "response_types" field. func (aruo *AuthRequestUpdateOne) ClearResponseTypes() *AuthRequestUpdateOne { aruo.mutation.ClearResponseTypes() @@ -546,6 +465,12 @@ func (aruo *AuthRequestUpdateOne) SetClaimsGroups(s []string) *AuthRequestUpdate return aruo } +// AppendClaimsGroups appends s to the "claims_groups" field. +func (aruo *AuthRequestUpdateOne) AppendClaimsGroups(s []string) *AuthRequestUpdateOne { + aruo.mutation.AppendClaimsGroups(s) + return aruo +} + // ClearClaimsGroups clears the value of the "claims_groups" field. func (aruo *AuthRequestUpdateOne) ClearClaimsGroups() *AuthRequestUpdateOne { aruo.mutation.ClearClaimsGroups() @@ -629,6 +554,12 @@ func (aruo *AuthRequestUpdateOne) Mutation() *AuthRequestMutation { return aruo.mutation } +// Where appends a list predicates to the AuthRequestUpdate builder. +func (aruo *AuthRequestUpdateOne) Where(ps ...predicate.AuthRequest) *AuthRequestUpdateOne { + aruo.mutation.Where(ps...) + return aruo +} + // Select allows selecting one or more fields (columns) of the returned entity. // The default is selecting all fields defined in the entity schema. func (aruo *AuthRequestUpdateOne) Select(field string, fields ...string) *AuthRequestUpdateOne { @@ -638,40 +569,7 @@ func (aruo *AuthRequestUpdateOne) Select(field string, fields ...string) *AuthRe // Save executes the query and returns the updated AuthRequest entity. func (aruo *AuthRequestUpdateOne) Save(ctx context.Context) (*AuthRequest, error) { - var ( - err error - node *AuthRequest - ) - if len(aruo.hooks) == 0 { - node, err = aruo.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*AuthRequestMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - aruo.mutation = mutation - node, err = aruo.sqlSave(ctx) - mutation.done = true - return node, err - }) - for i := len(aruo.hooks) - 1; i >= 0; i-- { - if aruo.hooks[i] == nil { - return nil, fmt.Errorf("db: uninitialized hook (forgotten import db/runtime?)") - } - mut = aruo.hooks[i](mut) - } - v, err := mut.Mutate(ctx, aruo.mutation) - if err != nil { - return nil, err - } - nv, ok := v.(*AuthRequest) - if !ok { - return nil, fmt.Errorf("unexpected node type %T returned from AuthRequestMutation", v) - } - node = nv - } - return node, err + return withHooks[*AuthRequest, AuthRequestMutation](ctx, aruo.sqlSave, aruo.mutation, aruo.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -697,16 +595,7 @@ func (aruo *AuthRequestUpdateOne) ExecX(ctx context.Context) { } func (aruo *AuthRequestUpdateOne) sqlSave(ctx context.Context) (_node *AuthRequest, err error) { - _spec := &sqlgraph.UpdateSpec{ - Node: &sqlgraph.NodeSpec{ - Table: authrequest.Table, - Columns: authrequest.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeString, - Column: authrequest.FieldID, - }, - }, - } + _spec := sqlgraph.NewUpdateSpec(authrequest.Table, authrequest.Columns, sqlgraph.NewFieldSpec(authrequest.FieldID, field.TypeString)) id, ok := aruo.mutation.ID() if !ok { return nil, &ValidationError{Name: "id", err: errors.New(`db: missing "AuthRequest.id" for update`)} @@ -732,168 +621,91 @@ func (aruo *AuthRequestUpdateOne) sqlSave(ctx context.Context) (_node *AuthReque } } if value, ok := aruo.mutation.ClientID(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: authrequest.FieldClientID, - }) + _spec.SetField(authrequest.FieldClientID, field.TypeString, value) } if value, ok := aruo.mutation.Scopes(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeJSON, - Value: value, - Column: authrequest.FieldScopes, + _spec.SetField(authrequest.FieldScopes, field.TypeJSON, value) + } + if value, ok := aruo.mutation.AppendedScopes(); ok { + _spec.AddModifier(func(u *sql.UpdateBuilder) { + sqljson.Append(u, authrequest.FieldScopes, value) }) } if aruo.mutation.ScopesCleared() { - _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ - Type: field.TypeJSON, - Column: authrequest.FieldScopes, - }) + _spec.ClearField(authrequest.FieldScopes, field.TypeJSON) } if value, ok := aruo.mutation.ResponseTypes(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeJSON, - Value: value, - Column: authrequest.FieldResponseTypes, + _spec.SetField(authrequest.FieldResponseTypes, field.TypeJSON, value) + } + if value, ok := aruo.mutation.AppendedResponseTypes(); ok { + _spec.AddModifier(func(u *sql.UpdateBuilder) { + sqljson.Append(u, authrequest.FieldResponseTypes, value) }) } if aruo.mutation.ResponseTypesCleared() { - _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ - Type: field.TypeJSON, - Column: authrequest.FieldResponseTypes, - }) + _spec.ClearField(authrequest.FieldResponseTypes, field.TypeJSON) } if value, ok := aruo.mutation.RedirectURI(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: authrequest.FieldRedirectURI, - }) + _spec.SetField(authrequest.FieldRedirectURI, field.TypeString, value) } if value, ok := aruo.mutation.Nonce(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: authrequest.FieldNonce, - }) + _spec.SetField(authrequest.FieldNonce, field.TypeString, value) } if value, ok := aruo.mutation.State(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: authrequest.FieldState, - }) + _spec.SetField(authrequest.FieldState, field.TypeString, value) } if value, ok := aruo.mutation.ForceApprovalPrompt(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeBool, - Value: value, - Column: authrequest.FieldForceApprovalPrompt, - }) + _spec.SetField(authrequest.FieldForceApprovalPrompt, field.TypeBool, value) } if value, ok := aruo.mutation.LoggedIn(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeBool, - Value: value, - Column: authrequest.FieldLoggedIn, - }) + _spec.SetField(authrequest.FieldLoggedIn, field.TypeBool, value) } if value, ok := aruo.mutation.ClaimsUserID(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: authrequest.FieldClaimsUserID, - }) + _spec.SetField(authrequest.FieldClaimsUserID, field.TypeString, value) } if value, ok := aruo.mutation.ClaimsUsername(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: authrequest.FieldClaimsUsername, - }) + _spec.SetField(authrequest.FieldClaimsUsername, field.TypeString, value) } if value, ok := aruo.mutation.ClaimsEmail(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: authrequest.FieldClaimsEmail, - }) + _spec.SetField(authrequest.FieldClaimsEmail, field.TypeString, value) } if value, ok := aruo.mutation.ClaimsEmailVerified(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeBool, - Value: value, - Column: authrequest.FieldClaimsEmailVerified, - }) + _spec.SetField(authrequest.FieldClaimsEmailVerified, field.TypeBool, value) } if value, ok := aruo.mutation.ClaimsGroups(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeJSON, - Value: value, - Column: authrequest.FieldClaimsGroups, + _spec.SetField(authrequest.FieldClaimsGroups, field.TypeJSON, value) + } + if value, ok := aruo.mutation.AppendedClaimsGroups(); ok { + _spec.AddModifier(func(u *sql.UpdateBuilder) { + sqljson.Append(u, authrequest.FieldClaimsGroups, value) }) } if aruo.mutation.ClaimsGroupsCleared() { - _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ - Type: field.TypeJSON, - Column: authrequest.FieldClaimsGroups, - }) + _spec.ClearField(authrequest.FieldClaimsGroups, field.TypeJSON) } if value, ok := aruo.mutation.ClaimsPreferredUsername(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: authrequest.FieldClaimsPreferredUsername, - }) + _spec.SetField(authrequest.FieldClaimsPreferredUsername, field.TypeString, value) } if value, ok := aruo.mutation.ConnectorID(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: authrequest.FieldConnectorID, - }) + _spec.SetField(authrequest.FieldConnectorID, field.TypeString, value) } if value, ok := aruo.mutation.ConnectorData(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeBytes, - Value: value, - Column: authrequest.FieldConnectorData, - }) + _spec.SetField(authrequest.FieldConnectorData, field.TypeBytes, value) } if aruo.mutation.ConnectorDataCleared() { - _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ - Type: field.TypeBytes, - Column: authrequest.FieldConnectorData, - }) + _spec.ClearField(authrequest.FieldConnectorData, field.TypeBytes) } if value, ok := aruo.mutation.Expiry(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeTime, - Value: value, - Column: authrequest.FieldExpiry, - }) + _spec.SetField(authrequest.FieldExpiry, field.TypeTime, value) } if value, ok := aruo.mutation.CodeChallenge(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: authrequest.FieldCodeChallenge, - }) + _spec.SetField(authrequest.FieldCodeChallenge, field.TypeString, value) } if value, ok := aruo.mutation.CodeChallengeMethod(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: authrequest.FieldCodeChallengeMethod, - }) + _spec.SetField(authrequest.FieldCodeChallengeMethod, field.TypeString, value) } if value, ok := aruo.mutation.HmacKey(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeBytes, - Value: value, - Column: authrequest.FieldHmacKey, - }) + _spec.SetField(authrequest.FieldHmacKey, field.TypeBytes, value) } _node = &AuthRequest{config: aruo.config} _spec.Assign = _node.assignValues @@ -906,5 +718,6 @@ func (aruo *AuthRequestUpdateOne) sqlSave(ctx context.Context) (_node *AuthReque } return nil, err } + aruo.mutation.done = true return _node, nil } diff --git a/storage/ent/db/client.go b/storage/ent/db/client.go index 4bf55865..b3a2bd30 100644 --- a/storage/ent/db/client.go +++ b/storage/ent/db/client.go @@ -54,7 +54,7 @@ type Client struct { // NewClient creates a new client configured with the given options. func NewClient(opts ...Option) *Client { - cfg := config{log: log.Println, hooks: &hooks{}} + cfg := config{log: log.Println, hooks: &hooks{}, inters: &inters{}} cfg.options(opts...) client := &Client{config: cfg} client.init() @@ -154,7 +154,6 @@ func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error) // AuthCode. // Query(). // Count(ctx) -// func (c *Client) Debug() *Client { if c.debug { return c @@ -186,6 +185,49 @@ func (c *Client) Use(hooks ...Hook) { c.RefreshToken.Use(hooks...) } +// Intercept adds the query interceptors to all the entity clients. +// In order to add interceptors to a specific client, call: `client.Node.Intercept(...)`. +func (c *Client) Intercept(interceptors ...Interceptor) { + c.AuthCode.Intercept(interceptors...) + c.AuthRequest.Intercept(interceptors...) + c.Connector.Intercept(interceptors...) + c.DeviceRequest.Intercept(interceptors...) + c.DeviceToken.Intercept(interceptors...) + c.Keys.Intercept(interceptors...) + c.OAuth2Client.Intercept(interceptors...) + c.OfflineSession.Intercept(interceptors...) + c.Password.Intercept(interceptors...) + c.RefreshToken.Intercept(interceptors...) +} + +// Mutate implements the ent.Mutator interface. +func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) { + switch m := m.(type) { + case *AuthCodeMutation: + return c.AuthCode.mutate(ctx, m) + case *AuthRequestMutation: + return c.AuthRequest.mutate(ctx, m) + case *ConnectorMutation: + return c.Connector.mutate(ctx, m) + case *DeviceRequestMutation: + return c.DeviceRequest.mutate(ctx, m) + case *DeviceTokenMutation: + return c.DeviceToken.mutate(ctx, m) + case *KeysMutation: + return c.Keys.mutate(ctx, m) + case *OAuth2ClientMutation: + return c.OAuth2Client.mutate(ctx, m) + case *OfflineSessionMutation: + return c.OfflineSession.mutate(ctx, m) + case *PasswordMutation: + return c.Password.mutate(ctx, m) + case *RefreshTokenMutation: + return c.RefreshToken.mutate(ctx, m) + default: + return nil, fmt.Errorf("db: unknown mutation type %T", m) + } +} + // AuthCodeClient is a client for the AuthCode schema. type AuthCodeClient struct { config @@ -202,6 +244,12 @@ func (c *AuthCodeClient) Use(hooks ...Hook) { c.hooks.AuthCode = append(c.hooks.AuthCode, hooks...) } +// Intercept adds a list of query interceptors to the interceptors stack. +// A call to `Intercept(f, g, h)` equals to `authcode.Intercept(f(g(h())))`. +func (c *AuthCodeClient) Intercept(interceptors ...Interceptor) { + c.inters.AuthCode = append(c.inters.AuthCode, interceptors...) +} + // Create returns a builder for creating a AuthCode entity. func (c *AuthCodeClient) Create() *AuthCodeCreate { mutation := newAuthCodeMutation(c.config, OpCreate) @@ -242,7 +290,7 @@ func (c *AuthCodeClient) DeleteOne(ac *AuthCode) *AuthCodeDeleteOne { return c.DeleteOneID(ac.ID) } -// DeleteOne returns a builder for deleting the given entity by its id. +// DeleteOneID returns a builder for deleting the given entity by its id. func (c *AuthCodeClient) DeleteOneID(id string) *AuthCodeDeleteOne { builder := c.Delete().Where(authcode.ID(id)) builder.mutation.id = &id @@ -254,6 +302,8 @@ func (c *AuthCodeClient) DeleteOneID(id string) *AuthCodeDeleteOne { func (c *AuthCodeClient) Query() *AuthCodeQuery { return &AuthCodeQuery{ config: c.config, + ctx: &QueryContext{Type: TypeAuthCode}, + inters: c.Interceptors(), } } @@ -276,6 +326,26 @@ func (c *AuthCodeClient) Hooks() []Hook { return c.hooks.AuthCode } +// Interceptors returns the client interceptors. +func (c *AuthCodeClient) Interceptors() []Interceptor { + return c.inters.AuthCode +} + +func (c *AuthCodeClient) mutate(ctx context.Context, m *AuthCodeMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&AuthCodeCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&AuthCodeUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&AuthCodeUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&AuthCodeDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("db: unknown AuthCode mutation op: %q", m.Op()) + } +} + // AuthRequestClient is a client for the AuthRequest schema. type AuthRequestClient struct { config @@ -292,6 +362,12 @@ func (c *AuthRequestClient) Use(hooks ...Hook) { c.hooks.AuthRequest = append(c.hooks.AuthRequest, hooks...) } +// Intercept adds a list of query interceptors to the interceptors stack. +// A call to `Intercept(f, g, h)` equals to `authrequest.Intercept(f(g(h())))`. +func (c *AuthRequestClient) Intercept(interceptors ...Interceptor) { + c.inters.AuthRequest = append(c.inters.AuthRequest, interceptors...) +} + // Create returns a builder for creating a AuthRequest entity. func (c *AuthRequestClient) Create() *AuthRequestCreate { mutation := newAuthRequestMutation(c.config, OpCreate) @@ -332,7 +408,7 @@ func (c *AuthRequestClient) DeleteOne(ar *AuthRequest) *AuthRequestDeleteOne { return c.DeleteOneID(ar.ID) } -// DeleteOne returns a builder for deleting the given entity by its id. +// DeleteOneID returns a builder for deleting the given entity by its id. func (c *AuthRequestClient) DeleteOneID(id string) *AuthRequestDeleteOne { builder := c.Delete().Where(authrequest.ID(id)) builder.mutation.id = &id @@ -344,6 +420,8 @@ func (c *AuthRequestClient) DeleteOneID(id string) *AuthRequestDeleteOne { func (c *AuthRequestClient) Query() *AuthRequestQuery { return &AuthRequestQuery{ config: c.config, + ctx: &QueryContext{Type: TypeAuthRequest}, + inters: c.Interceptors(), } } @@ -366,6 +444,26 @@ func (c *AuthRequestClient) Hooks() []Hook { return c.hooks.AuthRequest } +// Interceptors returns the client interceptors. +func (c *AuthRequestClient) Interceptors() []Interceptor { + return c.inters.AuthRequest +} + +func (c *AuthRequestClient) mutate(ctx context.Context, m *AuthRequestMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&AuthRequestCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&AuthRequestUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&AuthRequestUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&AuthRequestDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("db: unknown AuthRequest mutation op: %q", m.Op()) + } +} + // ConnectorClient is a client for the Connector schema. type ConnectorClient struct { config @@ -382,6 +480,12 @@ func (c *ConnectorClient) Use(hooks ...Hook) { c.hooks.Connector = append(c.hooks.Connector, hooks...) } +// Intercept adds a list of query interceptors to the interceptors stack. +// A call to `Intercept(f, g, h)` equals to `connector.Intercept(f(g(h())))`. +func (c *ConnectorClient) Intercept(interceptors ...Interceptor) { + c.inters.Connector = append(c.inters.Connector, interceptors...) +} + // Create returns a builder for creating a Connector entity. func (c *ConnectorClient) Create() *ConnectorCreate { mutation := newConnectorMutation(c.config, OpCreate) @@ -422,7 +526,7 @@ func (c *ConnectorClient) DeleteOne(co *Connector) *ConnectorDeleteOne { return c.DeleteOneID(co.ID) } -// DeleteOne returns a builder for deleting the given entity by its id. +// DeleteOneID returns a builder for deleting the given entity by its id. func (c *ConnectorClient) DeleteOneID(id string) *ConnectorDeleteOne { builder := c.Delete().Where(connector.ID(id)) builder.mutation.id = &id @@ -434,6 +538,8 @@ func (c *ConnectorClient) DeleteOneID(id string) *ConnectorDeleteOne { func (c *ConnectorClient) Query() *ConnectorQuery { return &ConnectorQuery{ config: c.config, + ctx: &QueryContext{Type: TypeConnector}, + inters: c.Interceptors(), } } @@ -456,6 +562,26 @@ func (c *ConnectorClient) Hooks() []Hook { return c.hooks.Connector } +// Interceptors returns the client interceptors. +func (c *ConnectorClient) Interceptors() []Interceptor { + return c.inters.Connector +} + +func (c *ConnectorClient) mutate(ctx context.Context, m *ConnectorMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&ConnectorCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&ConnectorUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&ConnectorUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&ConnectorDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("db: unknown Connector mutation op: %q", m.Op()) + } +} + // DeviceRequestClient is a client for the DeviceRequest schema. type DeviceRequestClient struct { config @@ -472,6 +598,12 @@ func (c *DeviceRequestClient) Use(hooks ...Hook) { c.hooks.DeviceRequest = append(c.hooks.DeviceRequest, hooks...) } +// Intercept adds a list of query interceptors to the interceptors stack. +// A call to `Intercept(f, g, h)` equals to `devicerequest.Intercept(f(g(h())))`. +func (c *DeviceRequestClient) Intercept(interceptors ...Interceptor) { + c.inters.DeviceRequest = append(c.inters.DeviceRequest, interceptors...) +} + // Create returns a builder for creating a DeviceRequest entity. func (c *DeviceRequestClient) Create() *DeviceRequestCreate { mutation := newDeviceRequestMutation(c.config, OpCreate) @@ -512,7 +644,7 @@ func (c *DeviceRequestClient) DeleteOne(dr *DeviceRequest) *DeviceRequestDeleteO return c.DeleteOneID(dr.ID) } -// DeleteOne returns a builder for deleting the given entity by its id. +// DeleteOneID returns a builder for deleting the given entity by its id. func (c *DeviceRequestClient) DeleteOneID(id int) *DeviceRequestDeleteOne { builder := c.Delete().Where(devicerequest.ID(id)) builder.mutation.id = &id @@ -524,6 +656,8 @@ func (c *DeviceRequestClient) DeleteOneID(id int) *DeviceRequestDeleteOne { func (c *DeviceRequestClient) Query() *DeviceRequestQuery { return &DeviceRequestQuery{ config: c.config, + ctx: &QueryContext{Type: TypeDeviceRequest}, + inters: c.Interceptors(), } } @@ -546,6 +680,26 @@ func (c *DeviceRequestClient) Hooks() []Hook { return c.hooks.DeviceRequest } +// Interceptors returns the client interceptors. +func (c *DeviceRequestClient) Interceptors() []Interceptor { + return c.inters.DeviceRequest +} + +func (c *DeviceRequestClient) mutate(ctx context.Context, m *DeviceRequestMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&DeviceRequestCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&DeviceRequestUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&DeviceRequestUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&DeviceRequestDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("db: unknown DeviceRequest mutation op: %q", m.Op()) + } +} + // DeviceTokenClient is a client for the DeviceToken schema. type DeviceTokenClient struct { config @@ -562,6 +716,12 @@ func (c *DeviceTokenClient) Use(hooks ...Hook) { c.hooks.DeviceToken = append(c.hooks.DeviceToken, hooks...) } +// Intercept adds a list of query interceptors to the interceptors stack. +// A call to `Intercept(f, g, h)` equals to `devicetoken.Intercept(f(g(h())))`. +func (c *DeviceTokenClient) Intercept(interceptors ...Interceptor) { + c.inters.DeviceToken = append(c.inters.DeviceToken, interceptors...) +} + // Create returns a builder for creating a DeviceToken entity. func (c *DeviceTokenClient) Create() *DeviceTokenCreate { mutation := newDeviceTokenMutation(c.config, OpCreate) @@ -602,7 +762,7 @@ func (c *DeviceTokenClient) DeleteOne(dt *DeviceToken) *DeviceTokenDeleteOne { return c.DeleteOneID(dt.ID) } -// DeleteOne returns a builder for deleting the given entity by its id. +// DeleteOneID returns a builder for deleting the given entity by its id. func (c *DeviceTokenClient) DeleteOneID(id int) *DeviceTokenDeleteOne { builder := c.Delete().Where(devicetoken.ID(id)) builder.mutation.id = &id @@ -614,6 +774,8 @@ func (c *DeviceTokenClient) DeleteOneID(id int) *DeviceTokenDeleteOne { func (c *DeviceTokenClient) Query() *DeviceTokenQuery { return &DeviceTokenQuery{ config: c.config, + ctx: &QueryContext{Type: TypeDeviceToken}, + inters: c.Interceptors(), } } @@ -636,6 +798,26 @@ func (c *DeviceTokenClient) Hooks() []Hook { return c.hooks.DeviceToken } +// Interceptors returns the client interceptors. +func (c *DeviceTokenClient) Interceptors() []Interceptor { + return c.inters.DeviceToken +} + +func (c *DeviceTokenClient) mutate(ctx context.Context, m *DeviceTokenMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&DeviceTokenCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&DeviceTokenUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&DeviceTokenUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&DeviceTokenDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("db: unknown DeviceToken mutation op: %q", m.Op()) + } +} + // KeysClient is a client for the Keys schema. type KeysClient struct { config @@ -652,6 +834,12 @@ func (c *KeysClient) Use(hooks ...Hook) { c.hooks.Keys = append(c.hooks.Keys, hooks...) } +// Intercept adds a list of query interceptors to the interceptors stack. +// A call to `Intercept(f, g, h)` equals to `keys.Intercept(f(g(h())))`. +func (c *KeysClient) Intercept(interceptors ...Interceptor) { + c.inters.Keys = append(c.inters.Keys, interceptors...) +} + // Create returns a builder for creating a Keys entity. func (c *KeysClient) Create() *KeysCreate { mutation := newKeysMutation(c.config, OpCreate) @@ -692,7 +880,7 @@ func (c *KeysClient) DeleteOne(k *Keys) *KeysDeleteOne { return c.DeleteOneID(k.ID) } -// DeleteOne returns a builder for deleting the given entity by its id. +// DeleteOneID returns a builder for deleting the given entity by its id. func (c *KeysClient) DeleteOneID(id string) *KeysDeleteOne { builder := c.Delete().Where(keys.ID(id)) builder.mutation.id = &id @@ -704,6 +892,8 @@ func (c *KeysClient) DeleteOneID(id string) *KeysDeleteOne { func (c *KeysClient) Query() *KeysQuery { return &KeysQuery{ config: c.config, + ctx: &QueryContext{Type: TypeKeys}, + inters: c.Interceptors(), } } @@ -726,6 +916,26 @@ func (c *KeysClient) Hooks() []Hook { return c.hooks.Keys } +// Interceptors returns the client interceptors. +func (c *KeysClient) Interceptors() []Interceptor { + return c.inters.Keys +} + +func (c *KeysClient) mutate(ctx context.Context, m *KeysMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&KeysCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&KeysUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&KeysUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&KeysDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("db: unknown Keys mutation op: %q", m.Op()) + } +} + // OAuth2ClientClient is a client for the OAuth2Client schema. type OAuth2ClientClient struct { config @@ -742,6 +952,12 @@ func (c *OAuth2ClientClient) Use(hooks ...Hook) { c.hooks.OAuth2Client = append(c.hooks.OAuth2Client, hooks...) } +// Intercept adds a list of query interceptors to the interceptors stack. +// A call to `Intercept(f, g, h)` equals to `oauth2client.Intercept(f(g(h())))`. +func (c *OAuth2ClientClient) Intercept(interceptors ...Interceptor) { + c.inters.OAuth2Client = append(c.inters.OAuth2Client, interceptors...) +} + // Create returns a builder for creating a OAuth2Client entity. func (c *OAuth2ClientClient) Create() *OAuth2ClientCreate { mutation := newOAuth2ClientMutation(c.config, OpCreate) @@ -782,7 +998,7 @@ func (c *OAuth2ClientClient) DeleteOne(o *OAuth2Client) *OAuth2ClientDeleteOne { return c.DeleteOneID(o.ID) } -// DeleteOne returns a builder for deleting the given entity by its id. +// DeleteOneID returns a builder for deleting the given entity by its id. func (c *OAuth2ClientClient) DeleteOneID(id string) *OAuth2ClientDeleteOne { builder := c.Delete().Where(oauth2client.ID(id)) builder.mutation.id = &id @@ -794,6 +1010,8 @@ func (c *OAuth2ClientClient) DeleteOneID(id string) *OAuth2ClientDeleteOne { func (c *OAuth2ClientClient) Query() *OAuth2ClientQuery { return &OAuth2ClientQuery{ config: c.config, + ctx: &QueryContext{Type: TypeOAuth2Client}, + inters: c.Interceptors(), } } @@ -816,6 +1034,26 @@ func (c *OAuth2ClientClient) Hooks() []Hook { return c.hooks.OAuth2Client } +// Interceptors returns the client interceptors. +func (c *OAuth2ClientClient) Interceptors() []Interceptor { + return c.inters.OAuth2Client +} + +func (c *OAuth2ClientClient) mutate(ctx context.Context, m *OAuth2ClientMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&OAuth2ClientCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&OAuth2ClientUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&OAuth2ClientUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&OAuth2ClientDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("db: unknown OAuth2Client mutation op: %q", m.Op()) + } +} + // OfflineSessionClient is a client for the OfflineSession schema. type OfflineSessionClient struct { config @@ -832,6 +1070,12 @@ func (c *OfflineSessionClient) Use(hooks ...Hook) { c.hooks.OfflineSession = append(c.hooks.OfflineSession, hooks...) } +// Intercept adds a list of query interceptors to the interceptors stack. +// A call to `Intercept(f, g, h)` equals to `offlinesession.Intercept(f(g(h())))`. +func (c *OfflineSessionClient) Intercept(interceptors ...Interceptor) { + c.inters.OfflineSession = append(c.inters.OfflineSession, interceptors...) +} + // Create returns a builder for creating a OfflineSession entity. func (c *OfflineSessionClient) Create() *OfflineSessionCreate { mutation := newOfflineSessionMutation(c.config, OpCreate) @@ -872,7 +1116,7 @@ func (c *OfflineSessionClient) DeleteOne(os *OfflineSession) *OfflineSessionDele return c.DeleteOneID(os.ID) } -// DeleteOne returns a builder for deleting the given entity by its id. +// DeleteOneID returns a builder for deleting the given entity by its id. func (c *OfflineSessionClient) DeleteOneID(id string) *OfflineSessionDeleteOne { builder := c.Delete().Where(offlinesession.ID(id)) builder.mutation.id = &id @@ -884,6 +1128,8 @@ func (c *OfflineSessionClient) DeleteOneID(id string) *OfflineSessionDeleteOne { func (c *OfflineSessionClient) Query() *OfflineSessionQuery { return &OfflineSessionQuery{ config: c.config, + ctx: &QueryContext{Type: TypeOfflineSession}, + inters: c.Interceptors(), } } @@ -906,6 +1152,26 @@ func (c *OfflineSessionClient) Hooks() []Hook { return c.hooks.OfflineSession } +// Interceptors returns the client interceptors. +func (c *OfflineSessionClient) Interceptors() []Interceptor { + return c.inters.OfflineSession +} + +func (c *OfflineSessionClient) mutate(ctx context.Context, m *OfflineSessionMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&OfflineSessionCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&OfflineSessionUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&OfflineSessionUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&OfflineSessionDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("db: unknown OfflineSession mutation op: %q", m.Op()) + } +} + // PasswordClient is a client for the Password schema. type PasswordClient struct { config @@ -922,6 +1188,12 @@ func (c *PasswordClient) Use(hooks ...Hook) { c.hooks.Password = append(c.hooks.Password, hooks...) } +// Intercept adds a list of query interceptors to the interceptors stack. +// A call to `Intercept(f, g, h)` equals to `password.Intercept(f(g(h())))`. +func (c *PasswordClient) Intercept(interceptors ...Interceptor) { + c.inters.Password = append(c.inters.Password, interceptors...) +} + // Create returns a builder for creating a Password entity. func (c *PasswordClient) Create() *PasswordCreate { mutation := newPasswordMutation(c.config, OpCreate) @@ -962,7 +1234,7 @@ func (c *PasswordClient) DeleteOne(pa *Password) *PasswordDeleteOne { return c.DeleteOneID(pa.ID) } -// DeleteOne returns a builder for deleting the given entity by its id. +// DeleteOneID returns a builder for deleting the given entity by its id. func (c *PasswordClient) DeleteOneID(id int) *PasswordDeleteOne { builder := c.Delete().Where(password.ID(id)) builder.mutation.id = &id @@ -974,6 +1246,8 @@ func (c *PasswordClient) DeleteOneID(id int) *PasswordDeleteOne { func (c *PasswordClient) Query() *PasswordQuery { return &PasswordQuery{ config: c.config, + ctx: &QueryContext{Type: TypePassword}, + inters: c.Interceptors(), } } @@ -996,6 +1270,26 @@ func (c *PasswordClient) Hooks() []Hook { return c.hooks.Password } +// Interceptors returns the client interceptors. +func (c *PasswordClient) Interceptors() []Interceptor { + return c.inters.Password +} + +func (c *PasswordClient) mutate(ctx context.Context, m *PasswordMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&PasswordCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&PasswordUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&PasswordUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&PasswordDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("db: unknown Password mutation op: %q", m.Op()) + } +} + // RefreshTokenClient is a client for the RefreshToken schema. type RefreshTokenClient struct { config @@ -1012,6 +1306,12 @@ func (c *RefreshTokenClient) Use(hooks ...Hook) { c.hooks.RefreshToken = append(c.hooks.RefreshToken, hooks...) } +// Intercept adds a list of query interceptors to the interceptors stack. +// A call to `Intercept(f, g, h)` equals to `refreshtoken.Intercept(f(g(h())))`. +func (c *RefreshTokenClient) Intercept(interceptors ...Interceptor) { + c.inters.RefreshToken = append(c.inters.RefreshToken, interceptors...) +} + // Create returns a builder for creating a RefreshToken entity. func (c *RefreshTokenClient) Create() *RefreshTokenCreate { mutation := newRefreshTokenMutation(c.config, OpCreate) @@ -1052,7 +1352,7 @@ func (c *RefreshTokenClient) DeleteOne(rt *RefreshToken) *RefreshTokenDeleteOne return c.DeleteOneID(rt.ID) } -// DeleteOne returns a builder for deleting the given entity by its id. +// DeleteOneID returns a builder for deleting the given entity by its id. func (c *RefreshTokenClient) DeleteOneID(id string) *RefreshTokenDeleteOne { builder := c.Delete().Where(refreshtoken.ID(id)) builder.mutation.id = &id @@ -1064,6 +1364,8 @@ func (c *RefreshTokenClient) DeleteOneID(id string) *RefreshTokenDeleteOne { func (c *RefreshTokenClient) Query() *RefreshTokenQuery { return &RefreshTokenQuery{ config: c.config, + ctx: &QueryContext{Type: TypeRefreshToken}, + inters: c.Interceptors(), } } @@ -1085,3 +1387,23 @@ func (c *RefreshTokenClient) GetX(ctx context.Context, id string) *RefreshToken func (c *RefreshTokenClient) Hooks() []Hook { return c.hooks.RefreshToken } + +// Interceptors returns the client interceptors. +func (c *RefreshTokenClient) Interceptors() []Interceptor { + return c.inters.RefreshToken +} + +func (c *RefreshTokenClient) mutate(ctx context.Context, m *RefreshTokenMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&RefreshTokenCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&RefreshTokenUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&RefreshTokenUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&RefreshTokenDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("db: unknown RefreshToken mutation op: %q", m.Op()) + } +} diff --git a/storage/ent/db/config.go b/storage/ent/db/config.go index b26f166d..fc7832c5 100644 --- a/storage/ent/db/config.go +++ b/storage/ent/db/config.go @@ -17,24 +17,40 @@ type config struct { // debug enable a debug logging. debug bool // log used for logging on debug mode. - log func(...interface{}) + log func(...any) // hooks to execute on mutations. hooks *hooks + // interceptors to execute on queries. + inters *inters } -// hooks per client, for fast access. -type hooks struct { - AuthCode []ent.Hook - AuthRequest []ent.Hook - Connector []ent.Hook - DeviceRequest []ent.Hook - DeviceToken []ent.Hook - Keys []ent.Hook - OAuth2Client []ent.Hook - OfflineSession []ent.Hook - Password []ent.Hook - RefreshToken []ent.Hook -} +// hooks and interceptors per client, for fast access. +type ( + hooks struct { + AuthCode []ent.Hook + AuthRequest []ent.Hook + Connector []ent.Hook + DeviceRequest []ent.Hook + DeviceToken []ent.Hook + Keys []ent.Hook + OAuth2Client []ent.Hook + OfflineSession []ent.Hook + Password []ent.Hook + RefreshToken []ent.Hook + } + inters struct { + AuthCode []ent.Interceptor + AuthRequest []ent.Interceptor + Connector []ent.Interceptor + DeviceRequest []ent.Interceptor + DeviceToken []ent.Interceptor + Keys []ent.Interceptor + OAuth2Client []ent.Interceptor + OfflineSession []ent.Interceptor + Password []ent.Interceptor + RefreshToken []ent.Interceptor + } +) // Options applies the options on the config object. func (c *config) options(opts ...Option) { @@ -54,7 +70,7 @@ func Debug() Option { } // Log sets the logging function for debug mode. -func Log(fn func(...interface{})) Option { +func Log(fn func(...any)) Option { return func(c *config) { c.log = fn } diff --git a/storage/ent/db/connector.go b/storage/ent/db/connector.go index 65cd4d25..2c954d1b 100644 --- a/storage/ent/db/connector.go +++ b/storage/ent/db/connector.go @@ -26,8 +26,8 @@ type Connector struct { } // scanValues returns the types for scanning values from sql.Rows. -func (*Connector) scanValues(columns []string) ([]interface{}, error) { - values := make([]interface{}, len(columns)) +func (*Connector) scanValues(columns []string) ([]any, error) { + values := make([]any, len(columns)) for i := range columns { switch columns[i] { case connector.FieldConfig: @@ -43,7 +43,7 @@ func (*Connector) scanValues(columns []string) ([]interface{}, error) { // assignValues assigns the values that were returned from sql.Rows (after scanning) // to the Connector fields. -func (c *Connector) assignValues(columns []string, values []interface{}) error { +func (c *Connector) assignValues(columns []string, values []any) error { if m, n := len(values), len(columns); m < n { return fmt.Errorf("mismatch number of scan values: %d != %d", m, n) } @@ -88,7 +88,7 @@ func (c *Connector) assignValues(columns []string, values []interface{}) error { // Note that you need to call Connector.Unwrap() before calling this method if this Connector // was returned from a transaction, and the transaction was committed or rolled back. func (c *Connector) Update() *ConnectorUpdateOne { - return (&ConnectorClient{config: c.config}).UpdateOne(c) + return NewConnectorClient(c.config).UpdateOne(c) } // Unwrap unwraps the Connector entity that was returned from a transaction after it was closed, @@ -124,9 +124,3 @@ func (c *Connector) String() string { // Connectors is a parsable slice of Connector. type Connectors []*Connector - -func (c Connectors) config(cfg config) { - for _i := range c { - c[_i].config = cfg - } -} diff --git a/storage/ent/db/connector/where.go b/storage/ent/db/connector/where.go index e48576de..5e02bc85 100644 --- a/storage/ent/db/connector/where.go +++ b/storage/ent/db/connector/where.go @@ -9,462 +9,302 @@ import ( // ID filters vertices based on their ID field. func ID(id string) predicate.Connector { - return predicate.Connector(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldID), id)) - }) + return predicate.Connector(sql.FieldEQ(FieldID, id)) } // IDEQ applies the EQ predicate on the ID field. func IDEQ(id string) predicate.Connector { - return predicate.Connector(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldID), id)) - }) + return predicate.Connector(sql.FieldEQ(FieldID, id)) } // IDNEQ applies the NEQ predicate on the ID field. func IDNEQ(id string) predicate.Connector { - return predicate.Connector(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldID), id)) - }) + return predicate.Connector(sql.FieldNEQ(FieldID, id)) } // IDIn applies the In predicate on the ID field. func IDIn(ids ...string) predicate.Connector { - return predicate.Connector(func(s *sql.Selector) { - v := make([]interface{}, len(ids)) - for i := range v { - v[i] = ids[i] - } - s.Where(sql.In(s.C(FieldID), v...)) - }) + return predicate.Connector(sql.FieldIn(FieldID, ids...)) } // IDNotIn applies the NotIn predicate on the ID field. func IDNotIn(ids ...string) predicate.Connector { - return predicate.Connector(func(s *sql.Selector) { - v := make([]interface{}, len(ids)) - for i := range v { - v[i] = ids[i] - } - s.Where(sql.NotIn(s.C(FieldID), v...)) - }) + return predicate.Connector(sql.FieldNotIn(FieldID, ids...)) } // IDGT applies the GT predicate on the ID field. func IDGT(id string) predicate.Connector { - return predicate.Connector(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldID), id)) - }) + return predicate.Connector(sql.FieldGT(FieldID, id)) } // IDGTE applies the GTE predicate on the ID field. func IDGTE(id string) predicate.Connector { - return predicate.Connector(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldID), id)) - }) + return predicate.Connector(sql.FieldGTE(FieldID, id)) } // IDLT applies the LT predicate on the ID field. func IDLT(id string) predicate.Connector { - return predicate.Connector(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldID), id)) - }) + return predicate.Connector(sql.FieldLT(FieldID, id)) } // IDLTE applies the LTE predicate on the ID field. func IDLTE(id string) predicate.Connector { - return predicate.Connector(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldID), id)) - }) + return predicate.Connector(sql.FieldLTE(FieldID, id)) } // Type applies equality check predicate on the "type" field. It's identical to TypeEQ. func Type(v string) predicate.Connector { - return predicate.Connector(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldType), v)) - }) + return predicate.Connector(sql.FieldEQ(FieldType, v)) } // Name applies equality check predicate on the "name" field. It's identical to NameEQ. func Name(v string) predicate.Connector { - return predicate.Connector(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldName), v)) - }) + return predicate.Connector(sql.FieldEQ(FieldName, v)) } // ResourceVersion applies equality check predicate on the "resource_version" field. It's identical to ResourceVersionEQ. func ResourceVersion(v string) predicate.Connector { - return predicate.Connector(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldResourceVersion), v)) - }) + return predicate.Connector(sql.FieldEQ(FieldResourceVersion, v)) } // Config applies equality check predicate on the "config" field. It's identical to ConfigEQ. func Config(v []byte) predicate.Connector { - return predicate.Connector(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldConfig), v)) - }) + return predicate.Connector(sql.FieldEQ(FieldConfig, v)) } // TypeEQ applies the EQ predicate on the "type" field. func TypeEQ(v string) predicate.Connector { - return predicate.Connector(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldType), v)) - }) + return predicate.Connector(sql.FieldEQ(FieldType, v)) } // TypeNEQ applies the NEQ predicate on the "type" field. func TypeNEQ(v string) predicate.Connector { - return predicate.Connector(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldType), v)) - }) + return predicate.Connector(sql.FieldNEQ(FieldType, v)) } // TypeIn applies the In predicate on the "type" field. func TypeIn(vs ...string) predicate.Connector { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Connector(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldType), v...)) - }) + return predicate.Connector(sql.FieldIn(FieldType, vs...)) } // TypeNotIn applies the NotIn predicate on the "type" field. func TypeNotIn(vs ...string) predicate.Connector { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Connector(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldType), v...)) - }) + return predicate.Connector(sql.FieldNotIn(FieldType, vs...)) } // TypeGT applies the GT predicate on the "type" field. func TypeGT(v string) predicate.Connector { - return predicate.Connector(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldType), v)) - }) + return predicate.Connector(sql.FieldGT(FieldType, v)) } // TypeGTE applies the GTE predicate on the "type" field. func TypeGTE(v string) predicate.Connector { - return predicate.Connector(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldType), v)) - }) + return predicate.Connector(sql.FieldGTE(FieldType, v)) } // TypeLT applies the LT predicate on the "type" field. func TypeLT(v string) predicate.Connector { - return predicate.Connector(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldType), v)) - }) + return predicate.Connector(sql.FieldLT(FieldType, v)) } // TypeLTE applies the LTE predicate on the "type" field. func TypeLTE(v string) predicate.Connector { - return predicate.Connector(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldType), v)) - }) + return predicate.Connector(sql.FieldLTE(FieldType, v)) } // TypeContains applies the Contains predicate on the "type" field. func TypeContains(v string) predicate.Connector { - return predicate.Connector(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldType), v)) - }) + return predicate.Connector(sql.FieldContains(FieldType, v)) } // TypeHasPrefix applies the HasPrefix predicate on the "type" field. func TypeHasPrefix(v string) predicate.Connector { - return predicate.Connector(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldType), v)) - }) + return predicate.Connector(sql.FieldHasPrefix(FieldType, v)) } // TypeHasSuffix applies the HasSuffix predicate on the "type" field. func TypeHasSuffix(v string) predicate.Connector { - return predicate.Connector(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldType), v)) - }) + return predicate.Connector(sql.FieldHasSuffix(FieldType, v)) } // TypeEqualFold applies the EqualFold predicate on the "type" field. func TypeEqualFold(v string) predicate.Connector { - return predicate.Connector(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldType), v)) - }) + return predicate.Connector(sql.FieldEqualFold(FieldType, v)) } // TypeContainsFold applies the ContainsFold predicate on the "type" field. func TypeContainsFold(v string) predicate.Connector { - return predicate.Connector(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldType), v)) - }) + return predicate.Connector(sql.FieldContainsFold(FieldType, v)) } // NameEQ applies the EQ predicate on the "name" field. func NameEQ(v string) predicate.Connector { - return predicate.Connector(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldName), v)) - }) + return predicate.Connector(sql.FieldEQ(FieldName, v)) } // NameNEQ applies the NEQ predicate on the "name" field. func NameNEQ(v string) predicate.Connector { - return predicate.Connector(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldName), v)) - }) + return predicate.Connector(sql.FieldNEQ(FieldName, v)) } // NameIn applies the In predicate on the "name" field. func NameIn(vs ...string) predicate.Connector { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Connector(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldName), v...)) - }) + return predicate.Connector(sql.FieldIn(FieldName, vs...)) } // NameNotIn applies the NotIn predicate on the "name" field. func NameNotIn(vs ...string) predicate.Connector { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Connector(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldName), v...)) - }) + return predicate.Connector(sql.FieldNotIn(FieldName, vs...)) } // NameGT applies the GT predicate on the "name" field. func NameGT(v string) predicate.Connector { - return predicate.Connector(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldName), v)) - }) + return predicate.Connector(sql.FieldGT(FieldName, v)) } // NameGTE applies the GTE predicate on the "name" field. func NameGTE(v string) predicate.Connector { - return predicate.Connector(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldName), v)) - }) + return predicate.Connector(sql.FieldGTE(FieldName, v)) } // NameLT applies the LT predicate on the "name" field. func NameLT(v string) predicate.Connector { - return predicate.Connector(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldName), v)) - }) + return predicate.Connector(sql.FieldLT(FieldName, v)) } // NameLTE applies the LTE predicate on the "name" field. func NameLTE(v string) predicate.Connector { - return predicate.Connector(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldName), v)) - }) + return predicate.Connector(sql.FieldLTE(FieldName, v)) } // NameContains applies the Contains predicate on the "name" field. func NameContains(v string) predicate.Connector { - return predicate.Connector(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldName), v)) - }) + return predicate.Connector(sql.FieldContains(FieldName, v)) } // NameHasPrefix applies the HasPrefix predicate on the "name" field. func NameHasPrefix(v string) predicate.Connector { - return predicate.Connector(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldName), v)) - }) + return predicate.Connector(sql.FieldHasPrefix(FieldName, v)) } // NameHasSuffix applies the HasSuffix predicate on the "name" field. func NameHasSuffix(v string) predicate.Connector { - return predicate.Connector(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldName), v)) - }) + return predicate.Connector(sql.FieldHasSuffix(FieldName, v)) } // NameEqualFold applies the EqualFold predicate on the "name" field. func NameEqualFold(v string) predicate.Connector { - return predicate.Connector(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldName), v)) - }) + return predicate.Connector(sql.FieldEqualFold(FieldName, v)) } // NameContainsFold applies the ContainsFold predicate on the "name" field. func NameContainsFold(v string) predicate.Connector { - return predicate.Connector(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldName), v)) - }) + return predicate.Connector(sql.FieldContainsFold(FieldName, v)) } // ResourceVersionEQ applies the EQ predicate on the "resource_version" field. func ResourceVersionEQ(v string) predicate.Connector { - return predicate.Connector(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldResourceVersion), v)) - }) + return predicate.Connector(sql.FieldEQ(FieldResourceVersion, v)) } // ResourceVersionNEQ applies the NEQ predicate on the "resource_version" field. func ResourceVersionNEQ(v string) predicate.Connector { - return predicate.Connector(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldResourceVersion), v)) - }) + return predicate.Connector(sql.FieldNEQ(FieldResourceVersion, v)) } // ResourceVersionIn applies the In predicate on the "resource_version" field. func ResourceVersionIn(vs ...string) predicate.Connector { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Connector(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldResourceVersion), v...)) - }) + return predicate.Connector(sql.FieldIn(FieldResourceVersion, vs...)) } // ResourceVersionNotIn applies the NotIn predicate on the "resource_version" field. func ResourceVersionNotIn(vs ...string) predicate.Connector { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Connector(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldResourceVersion), v...)) - }) + return predicate.Connector(sql.FieldNotIn(FieldResourceVersion, vs...)) } // ResourceVersionGT applies the GT predicate on the "resource_version" field. func ResourceVersionGT(v string) predicate.Connector { - return predicate.Connector(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldResourceVersion), v)) - }) + return predicate.Connector(sql.FieldGT(FieldResourceVersion, v)) } // ResourceVersionGTE applies the GTE predicate on the "resource_version" field. func ResourceVersionGTE(v string) predicate.Connector { - return predicate.Connector(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldResourceVersion), v)) - }) + return predicate.Connector(sql.FieldGTE(FieldResourceVersion, v)) } // ResourceVersionLT applies the LT predicate on the "resource_version" field. func ResourceVersionLT(v string) predicate.Connector { - return predicate.Connector(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldResourceVersion), v)) - }) + return predicate.Connector(sql.FieldLT(FieldResourceVersion, v)) } // ResourceVersionLTE applies the LTE predicate on the "resource_version" field. func ResourceVersionLTE(v string) predicate.Connector { - return predicate.Connector(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldResourceVersion), v)) - }) + return predicate.Connector(sql.FieldLTE(FieldResourceVersion, v)) } // ResourceVersionContains applies the Contains predicate on the "resource_version" field. func ResourceVersionContains(v string) predicate.Connector { - return predicate.Connector(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldResourceVersion), v)) - }) + return predicate.Connector(sql.FieldContains(FieldResourceVersion, v)) } // ResourceVersionHasPrefix applies the HasPrefix predicate on the "resource_version" field. func ResourceVersionHasPrefix(v string) predicate.Connector { - return predicate.Connector(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldResourceVersion), v)) - }) + return predicate.Connector(sql.FieldHasPrefix(FieldResourceVersion, v)) } // ResourceVersionHasSuffix applies the HasSuffix predicate on the "resource_version" field. func ResourceVersionHasSuffix(v string) predicate.Connector { - return predicate.Connector(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldResourceVersion), v)) - }) + return predicate.Connector(sql.FieldHasSuffix(FieldResourceVersion, v)) } // ResourceVersionEqualFold applies the EqualFold predicate on the "resource_version" field. func ResourceVersionEqualFold(v string) predicate.Connector { - return predicate.Connector(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldResourceVersion), v)) - }) + return predicate.Connector(sql.FieldEqualFold(FieldResourceVersion, v)) } // ResourceVersionContainsFold applies the ContainsFold predicate on the "resource_version" field. func ResourceVersionContainsFold(v string) predicate.Connector { - return predicate.Connector(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldResourceVersion), v)) - }) + return predicate.Connector(sql.FieldContainsFold(FieldResourceVersion, v)) } // ConfigEQ applies the EQ predicate on the "config" field. func ConfigEQ(v []byte) predicate.Connector { - return predicate.Connector(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldConfig), v)) - }) + return predicate.Connector(sql.FieldEQ(FieldConfig, v)) } // ConfigNEQ applies the NEQ predicate on the "config" field. func ConfigNEQ(v []byte) predicate.Connector { - return predicate.Connector(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldConfig), v)) - }) + return predicate.Connector(sql.FieldNEQ(FieldConfig, v)) } // ConfigIn applies the In predicate on the "config" field. func ConfigIn(vs ...[]byte) predicate.Connector { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Connector(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldConfig), v...)) - }) + return predicate.Connector(sql.FieldIn(FieldConfig, vs...)) } // ConfigNotIn applies the NotIn predicate on the "config" field. func ConfigNotIn(vs ...[]byte) predicate.Connector { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Connector(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldConfig), v...)) - }) + return predicate.Connector(sql.FieldNotIn(FieldConfig, vs...)) } // ConfigGT applies the GT predicate on the "config" field. func ConfigGT(v []byte) predicate.Connector { - return predicate.Connector(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldConfig), v)) - }) + return predicate.Connector(sql.FieldGT(FieldConfig, v)) } // ConfigGTE applies the GTE predicate on the "config" field. func ConfigGTE(v []byte) predicate.Connector { - return predicate.Connector(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldConfig), v)) - }) + return predicate.Connector(sql.FieldGTE(FieldConfig, v)) } // ConfigLT applies the LT predicate on the "config" field. func ConfigLT(v []byte) predicate.Connector { - return predicate.Connector(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldConfig), v)) - }) + return predicate.Connector(sql.FieldLT(FieldConfig, v)) } // ConfigLTE applies the LTE predicate on the "config" field. func ConfigLTE(v []byte) predicate.Connector { - return predicate.Connector(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldConfig), v)) - }) + return predicate.Connector(sql.FieldLTE(FieldConfig, v)) } // And groups predicates with the AND operator between them. diff --git a/storage/ent/db/connector_create.go b/storage/ent/db/connector_create.go index ecff1c2f..9362684a 100644 --- a/storage/ent/db/connector_create.go +++ b/storage/ent/db/connector_create.go @@ -56,49 +56,7 @@ func (cc *ConnectorCreate) Mutation() *ConnectorMutation { // Save creates the Connector in the database. func (cc *ConnectorCreate) Save(ctx context.Context) (*Connector, error) { - var ( - err error - node *Connector - ) - if len(cc.hooks) == 0 { - if err = cc.check(); err != nil { - return nil, err - } - node, err = cc.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*ConnectorMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err = cc.check(); err != nil { - return nil, err - } - cc.mutation = mutation - if node, err = cc.sqlSave(ctx); err != nil { - return nil, err - } - mutation.id = &node.ID - mutation.done = true - return node, err - }) - for i := len(cc.hooks) - 1; i >= 0; i-- { - if cc.hooks[i] == nil { - return nil, fmt.Errorf("db: uninitialized hook (forgotten import db/runtime?)") - } - mut = cc.hooks[i](mut) - } - v, err := mut.Mutate(ctx, cc.mutation) - if err != nil { - return nil, err - } - nv, ok := v.(*Connector) - if !ok { - return nil, fmt.Errorf("unexpected node type %T returned from ConnectorMutation", v) - } - node = nv - } - return node, err + return withHooks[*Connector, ConnectorMutation](ctx, cc.sqlSave, cc.mutation, cc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -156,6 +114,9 @@ func (cc *ConnectorCreate) check() error { } func (cc *ConnectorCreate) sqlSave(ctx context.Context) (*Connector, error) { + if err := cc.check(); err != nil { + return nil, err + } _node, _spec := cc.createSpec() if err := sqlgraph.CreateNode(ctx, cc.driver, _spec); err != nil { if sqlgraph.IsConstraintError(err) { @@ -170,54 +131,34 @@ func (cc *ConnectorCreate) sqlSave(ctx context.Context) (*Connector, error) { return nil, fmt.Errorf("unexpected Connector.ID type: %T", _spec.ID.Value) } } + cc.mutation.id = &_node.ID + cc.mutation.done = true return _node, nil } func (cc *ConnectorCreate) createSpec() (*Connector, *sqlgraph.CreateSpec) { var ( _node = &Connector{config: cc.config} - _spec = &sqlgraph.CreateSpec{ - Table: connector.Table, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeString, - Column: connector.FieldID, - }, - } + _spec = sqlgraph.NewCreateSpec(connector.Table, sqlgraph.NewFieldSpec(connector.FieldID, field.TypeString)) ) if id, ok := cc.mutation.ID(); ok { _node.ID = id _spec.ID.Value = id } if value, ok := cc.mutation.GetType(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: connector.FieldType, - }) + _spec.SetField(connector.FieldType, field.TypeString, value) _node.Type = value } if value, ok := cc.mutation.Name(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: connector.FieldName, - }) + _spec.SetField(connector.FieldName, field.TypeString, value) _node.Name = value } if value, ok := cc.mutation.ResourceVersion(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: connector.FieldResourceVersion, - }) + _spec.SetField(connector.FieldResourceVersion, field.TypeString, value) _node.ResourceVersion = value } if value, ok := cc.mutation.Config(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeBytes, - Value: value, - Column: connector.FieldConfig, - }) + _spec.SetField(connector.FieldConfig, field.TypeBytes, value) _node.Config = value } return _node, _spec diff --git a/storage/ent/db/connector_delete.go b/storage/ent/db/connector_delete.go index 0c5381ee..f60df9b7 100644 --- a/storage/ent/db/connector_delete.go +++ b/storage/ent/db/connector_delete.go @@ -4,7 +4,6 @@ package db import ( "context" - "fmt" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" @@ -28,34 +27,7 @@ func (cd *ConnectorDelete) Where(ps ...predicate.Connector) *ConnectorDelete { // Exec executes the deletion query and returns how many vertices were deleted. func (cd *ConnectorDelete) Exec(ctx context.Context) (int, error) { - var ( - err error - affected int - ) - if len(cd.hooks) == 0 { - affected, err = cd.sqlExec(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*ConnectorMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - cd.mutation = mutation - affected, err = cd.sqlExec(ctx) - mutation.done = true - return affected, err - }) - for i := len(cd.hooks) - 1; i >= 0; i-- { - if cd.hooks[i] == nil { - return 0, fmt.Errorf("db: uninitialized hook (forgotten import db/runtime?)") - } - mut = cd.hooks[i](mut) - } - if _, err := mut.Mutate(ctx, cd.mutation); err != nil { - return 0, err - } - } - return affected, err + return withHooks[int, ConnectorMutation](ctx, cd.sqlExec, cd.mutation, cd.hooks) } // ExecX is like Exec, but panics if an error occurs. @@ -68,15 +40,7 @@ func (cd *ConnectorDelete) ExecX(ctx context.Context) int { } func (cd *ConnectorDelete) sqlExec(ctx context.Context) (int, error) { - _spec := &sqlgraph.DeleteSpec{ - Node: &sqlgraph.NodeSpec{ - Table: connector.Table, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeString, - Column: connector.FieldID, - }, - }, - } + _spec := sqlgraph.NewDeleteSpec(connector.Table, sqlgraph.NewFieldSpec(connector.FieldID, field.TypeString)) if ps := cd.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { @@ -88,6 +52,7 @@ func (cd *ConnectorDelete) sqlExec(ctx context.Context) (int, error) { if err != nil && sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } + cd.mutation.done = true return affected, err } @@ -96,6 +61,12 @@ type ConnectorDeleteOne struct { cd *ConnectorDelete } +// Where appends a list predicates to the ConnectorDelete builder. +func (cdo *ConnectorDeleteOne) Where(ps ...predicate.Connector) *ConnectorDeleteOne { + cdo.cd.mutation.Where(ps...) + return cdo +} + // Exec executes the deletion query. func (cdo *ConnectorDeleteOne) Exec(ctx context.Context) error { n, err := cdo.cd.Exec(ctx) @@ -111,5 +82,7 @@ func (cdo *ConnectorDeleteOne) Exec(ctx context.Context) error { // ExecX is like Exec, but panics if an error occurs. func (cdo *ConnectorDeleteOne) ExecX(ctx context.Context) { - cdo.cd.ExecX(ctx) + if err := cdo.Exec(ctx); err != nil { + panic(err) + } } diff --git a/storage/ent/db/connector_query.go b/storage/ent/db/connector_query.go index 32d60204..89b10ec2 100644 --- a/storage/ent/db/connector_query.go +++ b/storage/ent/db/connector_query.go @@ -17,11 +17,9 @@ import ( // ConnectorQuery is the builder for querying Connector entities. type ConnectorQuery struct { config - limit *int - offset *int - unique *bool + ctx *QueryContext order []OrderFunc - fields []string + inters []Interceptor predicates []predicate.Connector // intermediate query (i.e. traversal path). sql *sql.Selector @@ -34,26 +32,26 @@ func (cq *ConnectorQuery) Where(ps ...predicate.Connector) *ConnectorQuery { return cq } -// Limit adds a limit step to the query. +// Limit the number of records to be returned by this query. func (cq *ConnectorQuery) Limit(limit int) *ConnectorQuery { - cq.limit = &limit + cq.ctx.Limit = &limit return cq } -// Offset adds an offset step to the query. +// Offset to start from. func (cq *ConnectorQuery) Offset(offset int) *ConnectorQuery { - cq.offset = &offset + cq.ctx.Offset = &offset return cq } // Unique configures the query builder to filter duplicate records on query. // By default, unique is set to true, and can be disabled using this method. func (cq *ConnectorQuery) Unique(unique bool) *ConnectorQuery { - cq.unique = &unique + cq.ctx.Unique = &unique return cq } -// Order adds an order step to the query. +// Order specifies how the records should be ordered. func (cq *ConnectorQuery) Order(o ...OrderFunc) *ConnectorQuery { cq.order = append(cq.order, o...) return cq @@ -62,7 +60,7 @@ func (cq *ConnectorQuery) Order(o ...OrderFunc) *ConnectorQuery { // First returns the first Connector entity from the query. // Returns a *NotFoundError when no Connector was found. func (cq *ConnectorQuery) First(ctx context.Context) (*Connector, error) { - nodes, err := cq.Limit(1).All(ctx) + nodes, err := cq.Limit(1).All(setContextOp(ctx, cq.ctx, "First")) if err != nil { return nil, err } @@ -85,7 +83,7 @@ func (cq *ConnectorQuery) FirstX(ctx context.Context) *Connector { // Returns a *NotFoundError when no Connector ID was found. func (cq *ConnectorQuery) FirstID(ctx context.Context) (id string, err error) { var ids []string - if ids, err = cq.Limit(1).IDs(ctx); err != nil { + if ids, err = cq.Limit(1).IDs(setContextOp(ctx, cq.ctx, "FirstID")); err != nil { return } if len(ids) == 0 { @@ -108,7 +106,7 @@ func (cq *ConnectorQuery) FirstIDX(ctx context.Context) string { // 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) + nodes, err := cq.Limit(2).All(setContextOp(ctx, cq.ctx, "Only")) if err != nil { return nil, err } @@ -136,7 +134,7 @@ func (cq *ConnectorQuery) OnlyX(ctx context.Context) *Connector { // Returns a *NotFoundError when no entities are found. func (cq *ConnectorQuery) OnlyID(ctx context.Context) (id string, err error) { var ids []string - if ids, err = cq.Limit(2).IDs(ctx); err != nil { + if ids, err = cq.Limit(2).IDs(setContextOp(ctx, cq.ctx, "OnlyID")); err != nil { return } switch len(ids) { @@ -161,10 +159,12 @@ func (cq *ConnectorQuery) OnlyIDX(ctx context.Context) string { // All executes the query and returns a list of Connectors. func (cq *ConnectorQuery) All(ctx context.Context) ([]*Connector, error) { + ctx = setContextOp(ctx, cq.ctx, "All") if err := cq.prepareQuery(ctx); err != nil { return nil, err } - return cq.sqlAll(ctx) + qr := querierAll[[]*Connector, *ConnectorQuery]() + return withInterceptors[[]*Connector](ctx, cq, qr, cq.inters) } // AllX is like All, but panics if an error occurs. @@ -177,9 +177,12 @@ func (cq *ConnectorQuery) AllX(ctx context.Context) []*Connector { } // IDs executes the query and returns a list of Connector IDs. -func (cq *ConnectorQuery) IDs(ctx context.Context) ([]string, error) { - var ids []string - if err := cq.Select(connector.FieldID).Scan(ctx, &ids); err != nil { +func (cq *ConnectorQuery) IDs(ctx context.Context) (ids []string, err error) { + if cq.ctx.Unique == nil && cq.path != nil { + cq.Unique(true) + } + ctx = setContextOp(ctx, cq.ctx, "IDs") + if err = cq.Select(connector.FieldID).Scan(ctx, &ids); err != nil { return nil, err } return ids, nil @@ -196,10 +199,11 @@ func (cq *ConnectorQuery) IDsX(ctx context.Context) []string { // Count returns the count of the given query. func (cq *ConnectorQuery) Count(ctx context.Context) (int, error) { + ctx = setContextOp(ctx, cq.ctx, "Count") if err := cq.prepareQuery(ctx); err != nil { return 0, err } - return cq.sqlCount(ctx) + return withInterceptors[int](ctx, cq, querierCount[*ConnectorQuery](), cq.inters) } // CountX is like Count, but panics if an error occurs. @@ -213,10 +217,15 @@ func (cq *ConnectorQuery) CountX(ctx context.Context) int { // Exist returns true if the query has elements in the graph. func (cq *ConnectorQuery) Exist(ctx context.Context) (bool, error) { - if err := cq.prepareQuery(ctx); err != nil { - return false, err + ctx = setContextOp(ctx, cq.ctx, "Exist") + switch _, err := cq.FirstID(ctx); { + case IsNotFound(err): + return false, nil + case err != nil: + return false, fmt.Errorf("db: check existence: %w", err) + default: + return true, nil } - return cq.sqlExist(ctx) } // ExistX is like Exist, but panics if an error occurs. @@ -236,14 +245,13 @@ func (cq *ConnectorQuery) Clone() *ConnectorQuery { } return &ConnectorQuery{ config: cq.config, - limit: cq.limit, - offset: cq.offset, + ctx: cq.ctx.Clone(), order: append([]OrderFunc{}, cq.order...), + inters: append([]Interceptor{}, cq.inters...), predicates: append([]predicate.Connector{}, cq.predicates...), // clone intermediate query. - sql: cq.sql.Clone(), - path: cq.path, - unique: cq.unique, + sql: cq.sql.Clone(), + path: cq.path, } } @@ -261,18 +269,12 @@ func (cq *ConnectorQuery) Clone() *ConnectorQuery { // GroupBy(connector.FieldType). // Aggregate(db.Count()). // Scan(ctx, &v) -// func (cq *ConnectorQuery) GroupBy(field string, fields ...string) *ConnectorGroupBy { - grbuild := &ConnectorGroupBy{config: cq.config} - grbuild.fields = append([]string{field}, fields...) - grbuild.path = func(ctx context.Context) (prev *sql.Selector, err error) { - if err := cq.prepareQuery(ctx); err != nil { - return nil, err - } - return cq.sqlQuery(ctx), nil - } + cq.ctx.Fields = append([]string{field}, fields...) + grbuild := &ConnectorGroupBy{build: cq} + grbuild.flds = &cq.ctx.Fields grbuild.label = connector.Label - grbuild.flds, grbuild.scan = &grbuild.fields, grbuild.Scan + grbuild.scan = grbuild.Scan return grbuild } @@ -288,17 +290,31 @@ func (cq *ConnectorQuery) GroupBy(field string, fields ...string) *ConnectorGrou // client.Connector.Query(). // Select(connector.FieldType). // Scan(ctx, &v) -// func (cq *ConnectorQuery) Select(fields ...string) *ConnectorSelect { - cq.fields = append(cq.fields, fields...) - selbuild := &ConnectorSelect{ConnectorQuery: cq} - selbuild.label = connector.Label - selbuild.flds, selbuild.scan = &cq.fields, selbuild.Scan - return selbuild + cq.ctx.Fields = append(cq.ctx.Fields, fields...) + sbuild := &ConnectorSelect{ConnectorQuery: cq} + sbuild.label = connector.Label + sbuild.flds, sbuild.scan = &cq.ctx.Fields, sbuild.Scan + return sbuild +} + +// Aggregate returns a ConnectorSelect configured with the given aggregations. +func (cq *ConnectorQuery) Aggregate(fns ...AggregateFunc) *ConnectorSelect { + return cq.Select().Aggregate(fns...) } func (cq *ConnectorQuery) prepareQuery(ctx context.Context) error { - for _, f := range cq.fields { + for _, inter := range cq.inters { + if inter == nil { + return fmt.Errorf("db: uninitialized interceptor (forgotten import db/runtime?)") + } + if trv, ok := inter.(Traverser); ok { + if err := trv.Traverse(ctx, cq); err != nil { + return err + } + } + } + for _, f := range cq.ctx.Fields { if !connector.ValidColumn(f) { return &ValidationError{Name: f, err: fmt.Errorf("db: invalid field %q for query", f)} } @@ -318,10 +334,10 @@ func (cq *ConnectorQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Co nodes = []*Connector{} _spec = cq.querySpec() ) - _spec.ScanValues = func(columns []string) ([]interface{}, error) { + _spec.ScanValues = func(columns []string) ([]any, error) { return (*Connector).scanValues(nil, columns) } - _spec.Assign = func(columns []string, values []interface{}) error { + _spec.Assign = func(columns []string, values []any) error { node := &Connector{config: cq.config} nodes = append(nodes, node) return node.assignValues(columns, values) @@ -340,38 +356,22 @@ func (cq *ConnectorQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Co 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 + _spec.Node.Columns = cq.ctx.Fields + if len(cq.ctx.Fields) > 0 { + _spec.Unique = cq.ctx.Unique != nil && *cq.ctx.Unique } return sqlgraph.CountNodes(ctx, cq.driver, _spec) } -func (cq *ConnectorQuery) sqlExist(ctx context.Context) (bool, error) { - n, err := cq.sqlCount(ctx) - if err != nil { - return false, fmt.Errorf("db: check existence: %w", err) - } - return n > 0, nil -} - func (cq *ConnectorQuery) querySpec() *sqlgraph.QuerySpec { - _spec := &sqlgraph.QuerySpec{ - Node: &sqlgraph.NodeSpec{ - Table: connector.Table, - Columns: connector.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeString, - Column: connector.FieldID, - }, - }, - From: cq.sql, - Unique: true, - } - if unique := cq.unique; unique != nil { + _spec := sqlgraph.NewQuerySpec(connector.Table, connector.Columns, sqlgraph.NewFieldSpec(connector.FieldID, field.TypeString)) + _spec.From = cq.sql + if unique := cq.ctx.Unique; unique != nil { _spec.Unique = *unique + } else if cq.path != nil { + _spec.Unique = true } - if fields := cq.fields; len(fields) > 0 { + if fields := cq.ctx.Fields; len(fields) > 0 { _spec.Node.Columns = make([]string, 0, len(fields)) _spec.Node.Columns = append(_spec.Node.Columns, connector.FieldID) for i := range fields { @@ -387,10 +387,10 @@ func (cq *ConnectorQuery) querySpec() *sqlgraph.QuerySpec { } } } - if limit := cq.limit; limit != nil { + if limit := cq.ctx.Limit; limit != nil { _spec.Limit = *limit } - if offset := cq.offset; offset != nil { + if offset := cq.ctx.Offset; offset != nil { _spec.Offset = *offset } if ps := cq.order; len(ps) > 0 { @@ -406,7 +406,7 @@ func (cq *ConnectorQuery) querySpec() *sqlgraph.QuerySpec { func (cq *ConnectorQuery) sqlQuery(ctx context.Context) *sql.Selector { builder := sql.Dialect(cq.driver.Dialect()) t1 := builder.Table(connector.Table) - columns := cq.fields + columns := cq.ctx.Fields if len(columns) == 0 { columns = connector.Columns } @@ -415,7 +415,7 @@ func (cq *ConnectorQuery) sqlQuery(ctx context.Context) *sql.Selector { selector = cq.sql selector.Select(selector.Columns(columns...)...) } - if cq.unique != nil && *cq.unique { + if cq.ctx.Unique != nil && *cq.ctx.Unique { selector.Distinct() } for _, p := range cq.predicates { @@ -424,12 +424,12 @@ func (cq *ConnectorQuery) sqlQuery(ctx context.Context) *sql.Selector { for _, p := range cq.order { p(selector) } - if offset := cq.offset; offset != nil { + if offset := cq.ctx.Offset; offset != nil { // limit is mandatory for offset clause. We start // with default value, and override it below if needed. selector.Offset(*offset).Limit(math.MaxInt32) } - if limit := cq.limit; limit != nil { + if limit := cq.ctx.Limit; limit != nil { selector.Limit(*limit) } return selector @@ -437,13 +437,8 @@ func (cq *ConnectorQuery) sqlQuery(ctx context.Context) *sql.Selector { // ConnectorGroupBy is the group-by builder for Connector entities. type ConnectorGroupBy struct { - config selector - fields []string - fns []AggregateFunc - // intermediate query (i.e. traversal path). - sql *sql.Selector - path func(context.Context) (*sql.Selector, error) + build *ConnectorQuery } // Aggregate adds the given aggregation functions to the group-by query. @@ -452,74 +447,77 @@ func (cgb *ConnectorGroupBy) Aggregate(fns ...AggregateFunc) *ConnectorGroupBy { return cgb } -// Scan applies the group-by query and scans the result into the given value. -func (cgb *ConnectorGroupBy) Scan(ctx context.Context, v interface{}) error { - query, err := cgb.path(ctx) - if err != nil { +// Scan applies the selector query and scans the result into the given value. +func (cgb *ConnectorGroupBy) Scan(ctx context.Context, v any) error { + ctx = setContextOp(ctx, cgb.build.ctx, "GroupBy") + if err := cgb.build.prepareQuery(ctx); err != nil { return err } - cgb.sql = query - return cgb.sqlScan(ctx, v) + return scanWithInterceptors[*ConnectorQuery, *ConnectorGroupBy](ctx, cgb.build, cgb, cgb.build.inters, v) } -func (cgb *ConnectorGroupBy) sqlScan(ctx context.Context, v interface{}) error { - for _, f := range cgb.fields { - if !connector.ValidColumn(f) { - return &ValidationError{Name: f, err: fmt.Errorf("invalid field %q for group-by", f)} - } - } - selector := cgb.sqlQuery() - if err := selector.Err(); err != nil { - return err - } - rows := &sql.Rows{} - query, args := selector.Query() - if err := cgb.driver.Query(ctx, query, args, rows); err != nil { - return err - } - defer rows.Close() - return sql.ScanSlice(rows, v) -} - -func (cgb *ConnectorGroupBy) sqlQuery() *sql.Selector { - selector := cgb.sql.Select() +func (cgb *ConnectorGroupBy) sqlScan(ctx context.Context, root *ConnectorQuery, v any) error { + selector := root.sqlQuery(ctx).Select() aggregation := make([]string, 0, len(cgb.fns)) for _, fn := range cgb.fns { aggregation = append(aggregation, fn(selector)) } - // If no columns were selected in a custom aggregation function, the default - // selection is the fields used for "group-by", and the aggregation functions. if len(selector.SelectedColumns()) == 0 { - columns := make([]string, 0, len(cgb.fields)+len(cgb.fns)) - for _, f := range cgb.fields { + columns := make([]string, 0, len(*cgb.flds)+len(cgb.fns)) + for _, f := range *cgb.flds { columns = append(columns, selector.C(f)) } columns = append(columns, aggregation...) selector.Select(columns...) } - return selector.GroupBy(selector.Columns(cgb.fields...)...) + selector.GroupBy(selector.Columns(*cgb.flds...)...) + if err := selector.Err(); err != nil { + return err + } + rows := &sql.Rows{} + query, args := selector.Query() + if err := cgb.build.driver.Query(ctx, query, args, rows); err != nil { + return err + } + defer rows.Close() + return sql.ScanSlice(rows, v) } // ConnectorSelect is the builder for selecting fields of Connector entities. type ConnectorSelect struct { *ConnectorQuery selector - // intermediate query (i.e. traversal path). - sql *sql.Selector +} + +// Aggregate adds the given aggregation functions to the selector query. +func (cs *ConnectorSelect) Aggregate(fns ...AggregateFunc) *ConnectorSelect { + cs.fns = append(cs.fns, fns...) + return cs } // Scan applies the selector query and scans the result into the given value. -func (cs *ConnectorSelect) Scan(ctx context.Context, v interface{}) error { +func (cs *ConnectorSelect) Scan(ctx context.Context, v any) error { + ctx = setContextOp(ctx, cs.ctx, "Select") if err := cs.prepareQuery(ctx); err != nil { return err } - cs.sql = cs.ConnectorQuery.sqlQuery(ctx) - return cs.sqlScan(ctx, v) + return scanWithInterceptors[*ConnectorQuery, *ConnectorSelect](ctx, cs.ConnectorQuery, cs, cs.inters, v) } -func (cs *ConnectorSelect) sqlScan(ctx context.Context, v interface{}) error { +func (cs *ConnectorSelect) sqlScan(ctx context.Context, root *ConnectorQuery, v any) error { + selector := root.sqlQuery(ctx) + aggregation := make([]string, 0, len(cs.fns)) + for _, fn := range cs.fns { + aggregation = append(aggregation, fn(selector)) + } + switch n := len(*cs.selector.flds); { + case n == 0 && len(aggregation) > 0: + selector.Select(aggregation...) + case n != 0 && len(aggregation) > 0: + selector.AppendSelect(aggregation...) + } rows := &sql.Rows{} - query, args := cs.sql.Query() + query, args := selector.Query() if err := cs.driver.Query(ctx, query, args, rows); err != nil { return err } diff --git a/storage/ent/db/connector_update.go b/storage/ent/db/connector_update.go index 736d0a62..1e6db2b1 100644 --- a/storage/ent/db/connector_update.go +++ b/storage/ent/db/connector_update.go @@ -58,40 +58,7 @@ func (cu *ConnectorUpdate) Mutation() *ConnectorMutation { // Save executes the query and returns the number of nodes affected by the update operation. func (cu *ConnectorUpdate) Save(ctx context.Context) (int, error) { - var ( - err error - affected int - ) - if len(cu.hooks) == 0 { - if err = cu.check(); err != nil { - return 0, err - } - affected, err = cu.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*ConnectorMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err = cu.check(); err != nil { - return 0, err - } - cu.mutation = mutation - affected, err = cu.sqlSave(ctx) - mutation.done = true - return affected, err - }) - for i := len(cu.hooks) - 1; i >= 0; i-- { - if cu.hooks[i] == nil { - return 0, fmt.Errorf("db: uninitialized hook (forgotten import db/runtime?)") - } - mut = cu.hooks[i](mut) - } - if _, err := mut.Mutate(ctx, cu.mutation); err != nil { - return 0, err - } - } - return affected, err + return withHooks[int, ConnectorMutation](ctx, cu.sqlSave, cu.mutation, cu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -132,16 +99,10 @@ func (cu *ConnectorUpdate) check() error { } func (cu *ConnectorUpdate) sqlSave(ctx context.Context) (n int, err error) { - _spec := &sqlgraph.UpdateSpec{ - Node: &sqlgraph.NodeSpec{ - Table: connector.Table, - Columns: connector.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeString, - Column: connector.FieldID, - }, - }, + if err := cu.check(); err != nil { + return n, err } + _spec := sqlgraph.NewUpdateSpec(connector.Table, connector.Columns, sqlgraph.NewFieldSpec(connector.FieldID, field.TypeString)) if ps := cu.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { @@ -150,32 +111,16 @@ func (cu *ConnectorUpdate) sqlSave(ctx context.Context) (n int, err error) { } } if value, ok := cu.mutation.GetType(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: connector.FieldType, - }) + _spec.SetField(connector.FieldType, field.TypeString, value) } if value, ok := cu.mutation.Name(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: connector.FieldName, - }) + _spec.SetField(connector.FieldName, field.TypeString, value) } if value, ok := cu.mutation.ResourceVersion(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: connector.FieldResourceVersion, - }) + _spec.SetField(connector.FieldResourceVersion, field.TypeString, value) } if value, ok := cu.mutation.Config(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeBytes, - Value: value, - Column: connector.FieldConfig, - }) + _spec.SetField(connector.FieldConfig, field.TypeBytes, value) } if n, err = sqlgraph.UpdateNodes(ctx, cu.driver, _spec); err != nil { if _, ok := err.(*sqlgraph.NotFoundError); ok { @@ -185,6 +130,7 @@ func (cu *ConnectorUpdate) sqlSave(ctx context.Context) (n int, err error) { } return 0, err } + cu.mutation.done = true return n, nil } @@ -225,6 +171,12 @@ func (cuo *ConnectorUpdateOne) Mutation() *ConnectorMutation { return cuo.mutation } +// Where appends a list predicates to the ConnectorUpdate builder. +func (cuo *ConnectorUpdateOne) Where(ps ...predicate.Connector) *ConnectorUpdateOne { + cuo.mutation.Where(ps...) + return cuo +} + // Select allows selecting one or more fields (columns) of the returned entity. // The default is selecting all fields defined in the entity schema. func (cuo *ConnectorUpdateOne) Select(field string, fields ...string) *ConnectorUpdateOne { @@ -234,46 +186,7 @@ func (cuo *ConnectorUpdateOne) Select(field string, fields ...string) *Connector // Save executes the query and returns the updated Connector entity. func (cuo *ConnectorUpdateOne) Save(ctx context.Context) (*Connector, error) { - var ( - err error - node *Connector - ) - if len(cuo.hooks) == 0 { - if err = cuo.check(); err != nil { - return nil, err - } - node, err = cuo.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*ConnectorMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err = cuo.check(); err != nil { - return nil, err - } - cuo.mutation = mutation - node, err = cuo.sqlSave(ctx) - mutation.done = true - return node, err - }) - for i := len(cuo.hooks) - 1; i >= 0; i-- { - if cuo.hooks[i] == nil { - return nil, fmt.Errorf("db: uninitialized hook (forgotten import db/runtime?)") - } - mut = cuo.hooks[i](mut) - } - v, err := mut.Mutate(ctx, cuo.mutation) - if err != nil { - return nil, err - } - nv, ok := v.(*Connector) - if !ok { - return nil, fmt.Errorf("unexpected node type %T returned from ConnectorMutation", v) - } - node = nv - } - return node, err + return withHooks[*Connector, ConnectorMutation](ctx, cuo.sqlSave, cuo.mutation, cuo.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -314,16 +227,10 @@ func (cuo *ConnectorUpdateOne) check() error { } func (cuo *ConnectorUpdateOne) sqlSave(ctx context.Context) (_node *Connector, err error) { - _spec := &sqlgraph.UpdateSpec{ - Node: &sqlgraph.NodeSpec{ - Table: connector.Table, - Columns: connector.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeString, - Column: connector.FieldID, - }, - }, + if err := cuo.check(); err != nil { + return _node, err } + _spec := sqlgraph.NewUpdateSpec(connector.Table, connector.Columns, sqlgraph.NewFieldSpec(connector.FieldID, field.TypeString)) id, ok := cuo.mutation.ID() if !ok { return nil, &ValidationError{Name: "id", err: errors.New(`db: missing "Connector.id" for update`)} @@ -349,32 +256,16 @@ func (cuo *ConnectorUpdateOne) sqlSave(ctx context.Context) (_node *Connector, e } } if value, ok := cuo.mutation.GetType(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: connector.FieldType, - }) + _spec.SetField(connector.FieldType, field.TypeString, value) } if value, ok := cuo.mutation.Name(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: connector.FieldName, - }) + _spec.SetField(connector.FieldName, field.TypeString, value) } if value, ok := cuo.mutation.ResourceVersion(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: connector.FieldResourceVersion, - }) + _spec.SetField(connector.FieldResourceVersion, field.TypeString, value) } if value, ok := cuo.mutation.Config(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeBytes, - Value: value, - Column: connector.FieldConfig, - }) + _spec.SetField(connector.FieldConfig, field.TypeBytes, value) } _node = &Connector{config: cuo.config} _spec.Assign = _node.assignValues @@ -387,5 +278,6 @@ func (cuo *ConnectorUpdateOne) sqlSave(ctx context.Context) (_node *Connector, e } return nil, err } + cuo.mutation.done = true return _node, nil } diff --git a/storage/ent/db/devicerequest.go b/storage/ent/db/devicerequest.go index d358f174..ff82eb13 100644 --- a/storage/ent/db/devicerequest.go +++ b/storage/ent/db/devicerequest.go @@ -32,8 +32,8 @@ type DeviceRequest struct { } // scanValues returns the types for scanning values from sql.Rows. -func (*DeviceRequest) scanValues(columns []string) ([]interface{}, error) { - values := make([]interface{}, len(columns)) +func (*DeviceRequest) scanValues(columns []string) ([]any, error) { + values := make([]any, len(columns)) for i := range columns { switch columns[i] { case devicerequest.FieldScopes: @@ -53,7 +53,7 @@ func (*DeviceRequest) scanValues(columns []string) ([]interface{}, error) { // assignValues assigns the values that were returned from sql.Rows (after scanning) // to the DeviceRequest fields. -func (dr *DeviceRequest) assignValues(columns []string, values []interface{}) error { +func (dr *DeviceRequest) assignValues(columns []string, values []any) error { if m, n := len(values), len(columns); m < n { return fmt.Errorf("mismatch number of scan values: %d != %d", m, n) } @@ -112,7 +112,7 @@ func (dr *DeviceRequest) assignValues(columns []string, values []interface{}) er // Note that you need to call DeviceRequest.Unwrap() before calling this method if this DeviceRequest // was returned from a transaction, and the transaction was committed or rolled back. func (dr *DeviceRequest) Update() *DeviceRequestUpdateOne { - return (&DeviceRequestClient{config: dr.config}).UpdateOne(dr) + return NewDeviceRequestClient(dr.config).UpdateOne(dr) } // Unwrap unwraps the DeviceRequest entity that was returned from a transaction after it was closed, @@ -154,9 +154,3 @@ func (dr *DeviceRequest) String() string { // DeviceRequests is a parsable slice of DeviceRequest. type DeviceRequests []*DeviceRequest - -func (dr DeviceRequests) config(cfg config) { - for _i := range dr { - dr[_i].config = cfg - } -} diff --git a/storage/ent/db/devicerequest/where.go b/storage/ent/db/devicerequest/where.go index 5cb5ce44..63400e24 100644 --- a/storage/ent/db/devicerequest/where.go +++ b/storage/ent/db/devicerequest/where.go @@ -11,582 +11,382 @@ import ( // ID filters vertices based on their ID field. func ID(id int) predicate.DeviceRequest { - return predicate.DeviceRequest(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldID), id)) - }) + return predicate.DeviceRequest(sql.FieldEQ(FieldID, id)) } // IDEQ applies the EQ predicate on the ID field. func IDEQ(id int) predicate.DeviceRequest { - return predicate.DeviceRequest(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldID), id)) - }) + return predicate.DeviceRequest(sql.FieldEQ(FieldID, id)) } // IDNEQ applies the NEQ predicate on the ID field. func IDNEQ(id int) predicate.DeviceRequest { - return predicate.DeviceRequest(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldID), id)) - }) + return predicate.DeviceRequest(sql.FieldNEQ(FieldID, id)) } // IDIn applies the In predicate on the ID field. func IDIn(ids ...int) predicate.DeviceRequest { - return predicate.DeviceRequest(func(s *sql.Selector) { - v := make([]interface{}, len(ids)) - for i := range v { - v[i] = ids[i] - } - s.Where(sql.In(s.C(FieldID), v...)) - }) + return predicate.DeviceRequest(sql.FieldIn(FieldID, ids...)) } // IDNotIn applies the NotIn predicate on the ID field. func IDNotIn(ids ...int) predicate.DeviceRequest { - return predicate.DeviceRequest(func(s *sql.Selector) { - v := make([]interface{}, len(ids)) - for i := range v { - v[i] = ids[i] - } - s.Where(sql.NotIn(s.C(FieldID), v...)) - }) + return predicate.DeviceRequest(sql.FieldNotIn(FieldID, ids...)) } // IDGT applies the GT predicate on the ID field. func IDGT(id int) predicate.DeviceRequest { - return predicate.DeviceRequest(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldID), id)) - }) + return predicate.DeviceRequest(sql.FieldGT(FieldID, id)) } // IDGTE applies the GTE predicate on the ID field. func IDGTE(id int) predicate.DeviceRequest { - return predicate.DeviceRequest(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldID), id)) - }) + return predicate.DeviceRequest(sql.FieldGTE(FieldID, id)) } // IDLT applies the LT predicate on the ID field. func IDLT(id int) predicate.DeviceRequest { - return predicate.DeviceRequest(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldID), id)) - }) + return predicate.DeviceRequest(sql.FieldLT(FieldID, id)) } // IDLTE applies the LTE predicate on the ID field. func IDLTE(id int) predicate.DeviceRequest { - return predicate.DeviceRequest(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldID), id)) - }) + return predicate.DeviceRequest(sql.FieldLTE(FieldID, id)) } // UserCode applies equality check predicate on the "user_code" field. It's identical to UserCodeEQ. func UserCode(v string) predicate.DeviceRequest { - return predicate.DeviceRequest(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldUserCode), v)) - }) + return predicate.DeviceRequest(sql.FieldEQ(FieldUserCode, v)) } // DeviceCode applies equality check predicate on the "device_code" field. It's identical to DeviceCodeEQ. func DeviceCode(v string) predicate.DeviceRequest { - return predicate.DeviceRequest(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldDeviceCode), v)) - }) + return predicate.DeviceRequest(sql.FieldEQ(FieldDeviceCode, v)) } // ClientID applies equality check predicate on the "client_id" field. It's identical to ClientIDEQ. func ClientID(v string) predicate.DeviceRequest { - return predicate.DeviceRequest(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldClientID), v)) - }) + return predicate.DeviceRequest(sql.FieldEQ(FieldClientID, v)) } // ClientSecret applies equality check predicate on the "client_secret" field. It's identical to ClientSecretEQ. func ClientSecret(v string) predicate.DeviceRequest { - return predicate.DeviceRequest(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldClientSecret), v)) - }) + return predicate.DeviceRequest(sql.FieldEQ(FieldClientSecret, v)) } // Expiry applies equality check predicate on the "expiry" field. It's identical to ExpiryEQ. func Expiry(v time.Time) predicate.DeviceRequest { - return predicate.DeviceRequest(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldExpiry), v)) - }) + return predicate.DeviceRequest(sql.FieldEQ(FieldExpiry, v)) } // UserCodeEQ applies the EQ predicate on the "user_code" field. func UserCodeEQ(v string) predicate.DeviceRequest { - return predicate.DeviceRequest(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldUserCode), v)) - }) + return predicate.DeviceRequest(sql.FieldEQ(FieldUserCode, v)) } // UserCodeNEQ applies the NEQ predicate on the "user_code" field. func UserCodeNEQ(v string) predicate.DeviceRequest { - return predicate.DeviceRequest(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldUserCode), v)) - }) + return predicate.DeviceRequest(sql.FieldNEQ(FieldUserCode, v)) } // UserCodeIn applies the In predicate on the "user_code" field. func UserCodeIn(vs ...string) predicate.DeviceRequest { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.DeviceRequest(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldUserCode), v...)) - }) + return predicate.DeviceRequest(sql.FieldIn(FieldUserCode, vs...)) } // UserCodeNotIn applies the NotIn predicate on the "user_code" field. func UserCodeNotIn(vs ...string) predicate.DeviceRequest { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.DeviceRequest(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldUserCode), v...)) - }) + return predicate.DeviceRequest(sql.FieldNotIn(FieldUserCode, vs...)) } // UserCodeGT applies the GT predicate on the "user_code" field. func UserCodeGT(v string) predicate.DeviceRequest { - return predicate.DeviceRequest(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldUserCode), v)) - }) + return predicate.DeviceRequest(sql.FieldGT(FieldUserCode, v)) } // UserCodeGTE applies the GTE predicate on the "user_code" field. func UserCodeGTE(v string) predicate.DeviceRequest { - return predicate.DeviceRequest(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldUserCode), v)) - }) + return predicate.DeviceRequest(sql.FieldGTE(FieldUserCode, v)) } // UserCodeLT applies the LT predicate on the "user_code" field. func UserCodeLT(v string) predicate.DeviceRequest { - return predicate.DeviceRequest(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldUserCode), v)) - }) + return predicate.DeviceRequest(sql.FieldLT(FieldUserCode, v)) } // UserCodeLTE applies the LTE predicate on the "user_code" field. func UserCodeLTE(v string) predicate.DeviceRequest { - return predicate.DeviceRequest(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldUserCode), v)) - }) + return predicate.DeviceRequest(sql.FieldLTE(FieldUserCode, v)) } // UserCodeContains applies the Contains predicate on the "user_code" field. func UserCodeContains(v string) predicate.DeviceRequest { - return predicate.DeviceRequest(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldUserCode), v)) - }) + return predicate.DeviceRequest(sql.FieldContains(FieldUserCode, v)) } // UserCodeHasPrefix applies the HasPrefix predicate on the "user_code" field. func UserCodeHasPrefix(v string) predicate.DeviceRequest { - return predicate.DeviceRequest(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldUserCode), v)) - }) + return predicate.DeviceRequest(sql.FieldHasPrefix(FieldUserCode, v)) } // UserCodeHasSuffix applies the HasSuffix predicate on the "user_code" field. func UserCodeHasSuffix(v string) predicate.DeviceRequest { - return predicate.DeviceRequest(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldUserCode), v)) - }) + return predicate.DeviceRequest(sql.FieldHasSuffix(FieldUserCode, v)) } // UserCodeEqualFold applies the EqualFold predicate on the "user_code" field. func UserCodeEqualFold(v string) predicate.DeviceRequest { - return predicate.DeviceRequest(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldUserCode), v)) - }) + return predicate.DeviceRequest(sql.FieldEqualFold(FieldUserCode, v)) } // UserCodeContainsFold applies the ContainsFold predicate on the "user_code" field. func UserCodeContainsFold(v string) predicate.DeviceRequest { - return predicate.DeviceRequest(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldUserCode), v)) - }) + return predicate.DeviceRequest(sql.FieldContainsFold(FieldUserCode, v)) } // DeviceCodeEQ applies the EQ predicate on the "device_code" field. func DeviceCodeEQ(v string) predicate.DeviceRequest { - return predicate.DeviceRequest(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldDeviceCode), v)) - }) + return predicate.DeviceRequest(sql.FieldEQ(FieldDeviceCode, v)) } // DeviceCodeNEQ applies the NEQ predicate on the "device_code" field. func DeviceCodeNEQ(v string) predicate.DeviceRequest { - return predicate.DeviceRequest(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldDeviceCode), v)) - }) + return predicate.DeviceRequest(sql.FieldNEQ(FieldDeviceCode, v)) } // DeviceCodeIn applies the In predicate on the "device_code" field. func DeviceCodeIn(vs ...string) predicate.DeviceRequest { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.DeviceRequest(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldDeviceCode), v...)) - }) + return predicate.DeviceRequest(sql.FieldIn(FieldDeviceCode, vs...)) } // DeviceCodeNotIn applies the NotIn predicate on the "device_code" field. func DeviceCodeNotIn(vs ...string) predicate.DeviceRequest { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.DeviceRequest(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldDeviceCode), v...)) - }) + return predicate.DeviceRequest(sql.FieldNotIn(FieldDeviceCode, vs...)) } // DeviceCodeGT applies the GT predicate on the "device_code" field. func DeviceCodeGT(v string) predicate.DeviceRequest { - return predicate.DeviceRequest(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldDeviceCode), v)) - }) + return predicate.DeviceRequest(sql.FieldGT(FieldDeviceCode, v)) } // DeviceCodeGTE applies the GTE predicate on the "device_code" field. func DeviceCodeGTE(v string) predicate.DeviceRequest { - return predicate.DeviceRequest(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldDeviceCode), v)) - }) + return predicate.DeviceRequest(sql.FieldGTE(FieldDeviceCode, v)) } // DeviceCodeLT applies the LT predicate on the "device_code" field. func DeviceCodeLT(v string) predicate.DeviceRequest { - return predicate.DeviceRequest(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldDeviceCode), v)) - }) + return predicate.DeviceRequest(sql.FieldLT(FieldDeviceCode, v)) } // DeviceCodeLTE applies the LTE predicate on the "device_code" field. func DeviceCodeLTE(v string) predicate.DeviceRequest { - return predicate.DeviceRequest(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldDeviceCode), v)) - }) + return predicate.DeviceRequest(sql.FieldLTE(FieldDeviceCode, v)) } // DeviceCodeContains applies the Contains predicate on the "device_code" field. func DeviceCodeContains(v string) predicate.DeviceRequest { - return predicate.DeviceRequest(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldDeviceCode), v)) - }) + return predicate.DeviceRequest(sql.FieldContains(FieldDeviceCode, v)) } // DeviceCodeHasPrefix applies the HasPrefix predicate on the "device_code" field. func DeviceCodeHasPrefix(v string) predicate.DeviceRequest { - return predicate.DeviceRequest(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldDeviceCode), v)) - }) + return predicate.DeviceRequest(sql.FieldHasPrefix(FieldDeviceCode, v)) } // DeviceCodeHasSuffix applies the HasSuffix predicate on the "device_code" field. func DeviceCodeHasSuffix(v string) predicate.DeviceRequest { - return predicate.DeviceRequest(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldDeviceCode), v)) - }) + return predicate.DeviceRequest(sql.FieldHasSuffix(FieldDeviceCode, v)) } // DeviceCodeEqualFold applies the EqualFold predicate on the "device_code" field. func DeviceCodeEqualFold(v string) predicate.DeviceRequest { - return predicate.DeviceRequest(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldDeviceCode), v)) - }) + return predicate.DeviceRequest(sql.FieldEqualFold(FieldDeviceCode, v)) } // DeviceCodeContainsFold applies the ContainsFold predicate on the "device_code" field. func DeviceCodeContainsFold(v string) predicate.DeviceRequest { - return predicate.DeviceRequest(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldDeviceCode), v)) - }) + return predicate.DeviceRequest(sql.FieldContainsFold(FieldDeviceCode, v)) } // ClientIDEQ applies the EQ predicate on the "client_id" field. func ClientIDEQ(v string) predicate.DeviceRequest { - return predicate.DeviceRequest(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldClientID), v)) - }) + return predicate.DeviceRequest(sql.FieldEQ(FieldClientID, v)) } // ClientIDNEQ applies the NEQ predicate on the "client_id" field. func ClientIDNEQ(v string) predicate.DeviceRequest { - return predicate.DeviceRequest(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldClientID), v)) - }) + return predicate.DeviceRequest(sql.FieldNEQ(FieldClientID, v)) } // ClientIDIn applies the In predicate on the "client_id" field. func ClientIDIn(vs ...string) predicate.DeviceRequest { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.DeviceRequest(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldClientID), v...)) - }) + return predicate.DeviceRequest(sql.FieldIn(FieldClientID, vs...)) } // ClientIDNotIn applies the NotIn predicate on the "client_id" field. func ClientIDNotIn(vs ...string) predicate.DeviceRequest { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.DeviceRequest(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldClientID), v...)) - }) + return predicate.DeviceRequest(sql.FieldNotIn(FieldClientID, vs...)) } // ClientIDGT applies the GT predicate on the "client_id" field. func ClientIDGT(v string) predicate.DeviceRequest { - return predicate.DeviceRequest(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldClientID), v)) - }) + return predicate.DeviceRequest(sql.FieldGT(FieldClientID, v)) } // ClientIDGTE applies the GTE predicate on the "client_id" field. func ClientIDGTE(v string) predicate.DeviceRequest { - return predicate.DeviceRequest(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldClientID), v)) - }) + return predicate.DeviceRequest(sql.FieldGTE(FieldClientID, v)) } // ClientIDLT applies the LT predicate on the "client_id" field. func ClientIDLT(v string) predicate.DeviceRequest { - return predicate.DeviceRequest(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldClientID), v)) - }) + return predicate.DeviceRequest(sql.FieldLT(FieldClientID, v)) } // ClientIDLTE applies the LTE predicate on the "client_id" field. func ClientIDLTE(v string) predicate.DeviceRequest { - return predicate.DeviceRequest(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldClientID), v)) - }) + return predicate.DeviceRequest(sql.FieldLTE(FieldClientID, v)) } // ClientIDContains applies the Contains predicate on the "client_id" field. func ClientIDContains(v string) predicate.DeviceRequest { - return predicate.DeviceRequest(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldClientID), v)) - }) + return predicate.DeviceRequest(sql.FieldContains(FieldClientID, v)) } // ClientIDHasPrefix applies the HasPrefix predicate on the "client_id" field. func ClientIDHasPrefix(v string) predicate.DeviceRequest { - return predicate.DeviceRequest(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldClientID), v)) - }) + return predicate.DeviceRequest(sql.FieldHasPrefix(FieldClientID, v)) } // ClientIDHasSuffix applies the HasSuffix predicate on the "client_id" field. func ClientIDHasSuffix(v string) predicate.DeviceRequest { - return predicate.DeviceRequest(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldClientID), v)) - }) + return predicate.DeviceRequest(sql.FieldHasSuffix(FieldClientID, v)) } // ClientIDEqualFold applies the EqualFold predicate on the "client_id" field. func ClientIDEqualFold(v string) predicate.DeviceRequest { - return predicate.DeviceRequest(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldClientID), v)) - }) + return predicate.DeviceRequest(sql.FieldEqualFold(FieldClientID, v)) } // ClientIDContainsFold applies the ContainsFold predicate on the "client_id" field. func ClientIDContainsFold(v string) predicate.DeviceRequest { - return predicate.DeviceRequest(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldClientID), v)) - }) + return predicate.DeviceRequest(sql.FieldContainsFold(FieldClientID, v)) } // ClientSecretEQ applies the EQ predicate on the "client_secret" field. func ClientSecretEQ(v string) predicate.DeviceRequest { - return predicate.DeviceRequest(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldClientSecret), v)) - }) + return predicate.DeviceRequest(sql.FieldEQ(FieldClientSecret, v)) } // ClientSecretNEQ applies the NEQ predicate on the "client_secret" field. func ClientSecretNEQ(v string) predicate.DeviceRequest { - return predicate.DeviceRequest(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldClientSecret), v)) - }) + return predicate.DeviceRequest(sql.FieldNEQ(FieldClientSecret, v)) } // ClientSecretIn applies the In predicate on the "client_secret" field. func ClientSecretIn(vs ...string) predicate.DeviceRequest { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.DeviceRequest(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldClientSecret), v...)) - }) + return predicate.DeviceRequest(sql.FieldIn(FieldClientSecret, vs...)) } // ClientSecretNotIn applies the NotIn predicate on the "client_secret" field. func ClientSecretNotIn(vs ...string) predicate.DeviceRequest { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.DeviceRequest(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldClientSecret), v...)) - }) + return predicate.DeviceRequest(sql.FieldNotIn(FieldClientSecret, vs...)) } // ClientSecretGT applies the GT predicate on the "client_secret" field. func ClientSecretGT(v string) predicate.DeviceRequest { - return predicate.DeviceRequest(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldClientSecret), v)) - }) + return predicate.DeviceRequest(sql.FieldGT(FieldClientSecret, v)) } // ClientSecretGTE applies the GTE predicate on the "client_secret" field. func ClientSecretGTE(v string) predicate.DeviceRequest { - return predicate.DeviceRequest(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldClientSecret), v)) - }) + return predicate.DeviceRequest(sql.FieldGTE(FieldClientSecret, v)) } // ClientSecretLT applies the LT predicate on the "client_secret" field. func ClientSecretLT(v string) predicate.DeviceRequest { - return predicate.DeviceRequest(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldClientSecret), v)) - }) + return predicate.DeviceRequest(sql.FieldLT(FieldClientSecret, v)) } // ClientSecretLTE applies the LTE predicate on the "client_secret" field. func ClientSecretLTE(v string) predicate.DeviceRequest { - return predicate.DeviceRequest(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldClientSecret), v)) - }) + return predicate.DeviceRequest(sql.FieldLTE(FieldClientSecret, v)) } // ClientSecretContains applies the Contains predicate on the "client_secret" field. func ClientSecretContains(v string) predicate.DeviceRequest { - return predicate.DeviceRequest(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldClientSecret), v)) - }) + return predicate.DeviceRequest(sql.FieldContains(FieldClientSecret, v)) } // ClientSecretHasPrefix applies the HasPrefix predicate on the "client_secret" field. func ClientSecretHasPrefix(v string) predicate.DeviceRequest { - return predicate.DeviceRequest(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldClientSecret), v)) - }) + return predicate.DeviceRequest(sql.FieldHasPrefix(FieldClientSecret, v)) } // ClientSecretHasSuffix applies the HasSuffix predicate on the "client_secret" field. func ClientSecretHasSuffix(v string) predicate.DeviceRequest { - return predicate.DeviceRequest(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldClientSecret), v)) - }) + return predicate.DeviceRequest(sql.FieldHasSuffix(FieldClientSecret, v)) } // ClientSecretEqualFold applies the EqualFold predicate on the "client_secret" field. func ClientSecretEqualFold(v string) predicate.DeviceRequest { - return predicate.DeviceRequest(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldClientSecret), v)) - }) + return predicate.DeviceRequest(sql.FieldEqualFold(FieldClientSecret, v)) } // ClientSecretContainsFold applies the ContainsFold predicate on the "client_secret" field. func ClientSecretContainsFold(v string) predicate.DeviceRequest { - return predicate.DeviceRequest(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldClientSecret), v)) - }) + return predicate.DeviceRequest(sql.FieldContainsFold(FieldClientSecret, v)) } // ScopesIsNil applies the IsNil predicate on the "scopes" field. func ScopesIsNil() predicate.DeviceRequest { - return predicate.DeviceRequest(func(s *sql.Selector) { - s.Where(sql.IsNull(s.C(FieldScopes))) - }) + return predicate.DeviceRequest(sql.FieldIsNull(FieldScopes)) } // ScopesNotNil applies the NotNil predicate on the "scopes" field. func ScopesNotNil() predicate.DeviceRequest { - return predicate.DeviceRequest(func(s *sql.Selector) { - s.Where(sql.NotNull(s.C(FieldScopes))) - }) + return predicate.DeviceRequest(sql.FieldNotNull(FieldScopes)) } // ExpiryEQ applies the EQ predicate on the "expiry" field. func ExpiryEQ(v time.Time) predicate.DeviceRequest { - return predicate.DeviceRequest(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldExpiry), v)) - }) + return predicate.DeviceRequest(sql.FieldEQ(FieldExpiry, v)) } // ExpiryNEQ applies the NEQ predicate on the "expiry" field. func ExpiryNEQ(v time.Time) predicate.DeviceRequest { - return predicate.DeviceRequest(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldExpiry), v)) - }) + return predicate.DeviceRequest(sql.FieldNEQ(FieldExpiry, v)) } // ExpiryIn applies the In predicate on the "expiry" field. func ExpiryIn(vs ...time.Time) predicate.DeviceRequest { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.DeviceRequest(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldExpiry), v...)) - }) + return predicate.DeviceRequest(sql.FieldIn(FieldExpiry, vs...)) } // ExpiryNotIn applies the NotIn predicate on the "expiry" field. func ExpiryNotIn(vs ...time.Time) predicate.DeviceRequest { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.DeviceRequest(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldExpiry), v...)) - }) + return predicate.DeviceRequest(sql.FieldNotIn(FieldExpiry, vs...)) } // ExpiryGT applies the GT predicate on the "expiry" field. func ExpiryGT(v time.Time) predicate.DeviceRequest { - return predicate.DeviceRequest(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldExpiry), v)) - }) + return predicate.DeviceRequest(sql.FieldGT(FieldExpiry, v)) } // ExpiryGTE applies the GTE predicate on the "expiry" field. func ExpiryGTE(v time.Time) predicate.DeviceRequest { - return predicate.DeviceRequest(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldExpiry), v)) - }) + return predicate.DeviceRequest(sql.FieldGTE(FieldExpiry, v)) } // ExpiryLT applies the LT predicate on the "expiry" field. func ExpiryLT(v time.Time) predicate.DeviceRequest { - return predicate.DeviceRequest(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldExpiry), v)) - }) + return predicate.DeviceRequest(sql.FieldLT(FieldExpiry, v)) } // ExpiryLTE applies the LTE predicate on the "expiry" field. func ExpiryLTE(v time.Time) predicate.DeviceRequest { - return predicate.DeviceRequest(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldExpiry), v)) - }) + return predicate.DeviceRequest(sql.FieldLTE(FieldExpiry, v)) } // And groups predicates with the AND operator between them. diff --git a/storage/ent/db/devicerequest_create.go b/storage/ent/db/devicerequest_create.go index ae7644ca..3aec60ac 100644 --- a/storage/ent/db/devicerequest_create.go +++ b/storage/ent/db/devicerequest_create.go @@ -63,49 +63,7 @@ func (drc *DeviceRequestCreate) Mutation() *DeviceRequestMutation { // Save creates the DeviceRequest in the database. func (drc *DeviceRequestCreate) Save(ctx context.Context) (*DeviceRequest, error) { - var ( - err error - node *DeviceRequest - ) - if len(drc.hooks) == 0 { - if err = drc.check(); err != nil { - return nil, err - } - node, err = drc.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*DeviceRequestMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err = drc.check(); err != nil { - return nil, err - } - drc.mutation = mutation - if node, err = drc.sqlSave(ctx); err != nil { - return nil, err - } - mutation.id = &node.ID - mutation.done = true - return node, err - }) - for i := len(drc.hooks) - 1; i >= 0; i-- { - if drc.hooks[i] == nil { - return nil, fmt.Errorf("db: uninitialized hook (forgotten import db/runtime?)") - } - mut = drc.hooks[i](mut) - } - v, err := mut.Mutate(ctx, drc.mutation) - if err != nil { - return nil, err - } - nv, ok := v.(*DeviceRequest) - if !ok { - return nil, fmt.Errorf("unexpected node type %T returned from DeviceRequestMutation", v) - } - node = nv - } - return node, err + return withHooks[*DeviceRequest, DeviceRequestMutation](ctx, drc.sqlSave, drc.mutation, drc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -171,6 +129,9 @@ func (drc *DeviceRequestCreate) check() error { } func (drc *DeviceRequestCreate) sqlSave(ctx context.Context) (*DeviceRequest, error) { + if err := drc.check(); err != nil { + return nil, err + } _node, _spec := drc.createSpec() if err := sqlgraph.CreateNode(ctx, drc.driver, _spec); err != nil { if sqlgraph.IsConstraintError(err) { @@ -180,66 +141,38 @@ func (drc *DeviceRequestCreate) sqlSave(ctx context.Context) (*DeviceRequest, er } id := _spec.ID.Value.(int64) _node.ID = int(id) + drc.mutation.id = &_node.ID + drc.mutation.done = true return _node, nil } func (drc *DeviceRequestCreate) createSpec() (*DeviceRequest, *sqlgraph.CreateSpec) { var ( _node = &DeviceRequest{config: drc.config} - _spec = &sqlgraph.CreateSpec{ - Table: devicerequest.Table, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeInt, - Column: devicerequest.FieldID, - }, - } + _spec = sqlgraph.NewCreateSpec(devicerequest.Table, sqlgraph.NewFieldSpec(devicerequest.FieldID, field.TypeInt)) ) if value, ok := drc.mutation.UserCode(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: devicerequest.FieldUserCode, - }) + _spec.SetField(devicerequest.FieldUserCode, field.TypeString, value) _node.UserCode = value } if value, ok := drc.mutation.DeviceCode(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: devicerequest.FieldDeviceCode, - }) + _spec.SetField(devicerequest.FieldDeviceCode, field.TypeString, value) _node.DeviceCode = value } if value, ok := drc.mutation.ClientID(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: devicerequest.FieldClientID, - }) + _spec.SetField(devicerequest.FieldClientID, field.TypeString, value) _node.ClientID = value } if value, ok := drc.mutation.ClientSecret(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: devicerequest.FieldClientSecret, - }) + _spec.SetField(devicerequest.FieldClientSecret, field.TypeString, value) _node.ClientSecret = value } if value, ok := drc.mutation.Scopes(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeJSON, - Value: value, - Column: devicerequest.FieldScopes, - }) + _spec.SetField(devicerequest.FieldScopes, field.TypeJSON, value) _node.Scopes = value } if value, ok := drc.mutation.Expiry(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeTime, - Value: value, - Column: devicerequest.FieldExpiry, - }) + _spec.SetField(devicerequest.FieldExpiry, field.TypeTime, value) _node.Expiry = value } return _node, _spec diff --git a/storage/ent/db/devicerequest_delete.go b/storage/ent/db/devicerequest_delete.go index 635a8a49..ab3e494d 100644 --- a/storage/ent/db/devicerequest_delete.go +++ b/storage/ent/db/devicerequest_delete.go @@ -4,7 +4,6 @@ package db import ( "context" - "fmt" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" @@ -28,34 +27,7 @@ func (drd *DeviceRequestDelete) Where(ps ...predicate.DeviceRequest) *DeviceRequ // Exec executes the deletion query and returns how many vertices were deleted. func (drd *DeviceRequestDelete) Exec(ctx context.Context) (int, error) { - var ( - err error - affected int - ) - if len(drd.hooks) == 0 { - affected, err = drd.sqlExec(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*DeviceRequestMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - drd.mutation = mutation - affected, err = drd.sqlExec(ctx) - mutation.done = true - return affected, err - }) - for i := len(drd.hooks) - 1; i >= 0; i-- { - if drd.hooks[i] == nil { - return 0, fmt.Errorf("db: uninitialized hook (forgotten import db/runtime?)") - } - mut = drd.hooks[i](mut) - } - if _, err := mut.Mutate(ctx, drd.mutation); err != nil { - return 0, err - } - } - return affected, err + return withHooks[int, DeviceRequestMutation](ctx, drd.sqlExec, drd.mutation, drd.hooks) } // ExecX is like Exec, but panics if an error occurs. @@ -68,15 +40,7 @@ func (drd *DeviceRequestDelete) ExecX(ctx context.Context) int { } func (drd *DeviceRequestDelete) sqlExec(ctx context.Context) (int, error) { - _spec := &sqlgraph.DeleteSpec{ - Node: &sqlgraph.NodeSpec{ - Table: devicerequest.Table, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeInt, - Column: devicerequest.FieldID, - }, - }, - } + _spec := sqlgraph.NewDeleteSpec(devicerequest.Table, sqlgraph.NewFieldSpec(devicerequest.FieldID, field.TypeInt)) if ps := drd.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { @@ -88,6 +52,7 @@ func (drd *DeviceRequestDelete) sqlExec(ctx context.Context) (int, error) { if err != nil && sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } + drd.mutation.done = true return affected, err } @@ -96,6 +61,12 @@ type DeviceRequestDeleteOne struct { drd *DeviceRequestDelete } +// Where appends a list predicates to the DeviceRequestDelete builder. +func (drdo *DeviceRequestDeleteOne) Where(ps ...predicate.DeviceRequest) *DeviceRequestDeleteOne { + drdo.drd.mutation.Where(ps...) + return drdo +} + // Exec executes the deletion query. func (drdo *DeviceRequestDeleteOne) Exec(ctx context.Context) error { n, err := drdo.drd.Exec(ctx) @@ -111,5 +82,7 @@ func (drdo *DeviceRequestDeleteOne) Exec(ctx context.Context) error { // ExecX is like Exec, but panics if an error occurs. func (drdo *DeviceRequestDeleteOne) ExecX(ctx context.Context) { - drdo.drd.ExecX(ctx) + if err := drdo.Exec(ctx); err != nil { + panic(err) + } } diff --git a/storage/ent/db/devicerequest_query.go b/storage/ent/db/devicerequest_query.go index 3fd43dd8..4ee9fdd9 100644 --- a/storage/ent/db/devicerequest_query.go +++ b/storage/ent/db/devicerequest_query.go @@ -17,11 +17,9 @@ import ( // DeviceRequestQuery is the builder for querying DeviceRequest entities. type DeviceRequestQuery struct { config - limit *int - offset *int - unique *bool + ctx *QueryContext order []OrderFunc - fields []string + inters []Interceptor predicates []predicate.DeviceRequest // intermediate query (i.e. traversal path). sql *sql.Selector @@ -34,26 +32,26 @@ func (drq *DeviceRequestQuery) Where(ps ...predicate.DeviceRequest) *DeviceReque return drq } -// Limit adds a limit step to the query. +// Limit the number of records to be returned by this query. func (drq *DeviceRequestQuery) Limit(limit int) *DeviceRequestQuery { - drq.limit = &limit + drq.ctx.Limit = &limit return drq } -// Offset adds an offset step to the query. +// Offset to start from. func (drq *DeviceRequestQuery) Offset(offset int) *DeviceRequestQuery { - drq.offset = &offset + drq.ctx.Offset = &offset return drq } // Unique configures the query builder to filter duplicate records on query. // By default, unique is set to true, and can be disabled using this method. func (drq *DeviceRequestQuery) Unique(unique bool) *DeviceRequestQuery { - drq.unique = &unique + drq.ctx.Unique = &unique return drq } -// Order adds an order step to the query. +// Order specifies how the records should be ordered. func (drq *DeviceRequestQuery) Order(o ...OrderFunc) *DeviceRequestQuery { drq.order = append(drq.order, o...) return drq @@ -62,7 +60,7 @@ func (drq *DeviceRequestQuery) Order(o ...OrderFunc) *DeviceRequestQuery { // First returns the first DeviceRequest entity from the query. // Returns a *NotFoundError when no DeviceRequest was found. func (drq *DeviceRequestQuery) First(ctx context.Context) (*DeviceRequest, error) { - nodes, err := drq.Limit(1).All(ctx) + nodes, err := drq.Limit(1).All(setContextOp(ctx, drq.ctx, "First")) if err != nil { return nil, err } @@ -85,7 +83,7 @@ func (drq *DeviceRequestQuery) FirstX(ctx context.Context) *DeviceRequest { // Returns a *NotFoundError when no DeviceRequest ID was found. func (drq *DeviceRequestQuery) FirstID(ctx context.Context) (id int, err error) { var ids []int - if ids, err = drq.Limit(1).IDs(ctx); err != nil { + if ids, err = drq.Limit(1).IDs(setContextOp(ctx, drq.ctx, "FirstID")); err != nil { return } if len(ids) == 0 { @@ -108,7 +106,7 @@ func (drq *DeviceRequestQuery) FirstIDX(ctx context.Context) int { // 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) + nodes, err := drq.Limit(2).All(setContextOp(ctx, drq.ctx, "Only")) if err != nil { return nil, err } @@ -136,7 +134,7 @@ func (drq *DeviceRequestQuery) OnlyX(ctx context.Context) *DeviceRequest { // Returns a *NotFoundError when no entities are found. func (drq *DeviceRequestQuery) OnlyID(ctx context.Context) (id int, err error) { var ids []int - if ids, err = drq.Limit(2).IDs(ctx); err != nil { + if ids, err = drq.Limit(2).IDs(setContextOp(ctx, drq.ctx, "OnlyID")); err != nil { return } switch len(ids) { @@ -161,10 +159,12 @@ func (drq *DeviceRequestQuery) OnlyIDX(ctx context.Context) int { // All executes the query and returns a list of DeviceRequests. func (drq *DeviceRequestQuery) All(ctx context.Context) ([]*DeviceRequest, error) { + ctx = setContextOp(ctx, drq.ctx, "All") if err := drq.prepareQuery(ctx); err != nil { return nil, err } - return drq.sqlAll(ctx) + qr := querierAll[[]*DeviceRequest, *DeviceRequestQuery]() + return withInterceptors[[]*DeviceRequest](ctx, drq, qr, drq.inters) } // AllX is like All, but panics if an error occurs. @@ -177,9 +177,12 @@ func (drq *DeviceRequestQuery) AllX(ctx context.Context) []*DeviceRequest { } // IDs executes the query and returns a list of DeviceRequest IDs. -func (drq *DeviceRequestQuery) IDs(ctx context.Context) ([]int, error) { - var ids []int - if err := drq.Select(devicerequest.FieldID).Scan(ctx, &ids); err != nil { +func (drq *DeviceRequestQuery) IDs(ctx context.Context) (ids []int, err error) { + if drq.ctx.Unique == nil && drq.path != nil { + drq.Unique(true) + } + ctx = setContextOp(ctx, drq.ctx, "IDs") + if err = drq.Select(devicerequest.FieldID).Scan(ctx, &ids); err != nil { return nil, err } return ids, nil @@ -196,10 +199,11 @@ func (drq *DeviceRequestQuery) IDsX(ctx context.Context) []int { // Count returns the count of the given query. func (drq *DeviceRequestQuery) Count(ctx context.Context) (int, error) { + ctx = setContextOp(ctx, drq.ctx, "Count") if err := drq.prepareQuery(ctx); err != nil { return 0, err } - return drq.sqlCount(ctx) + return withInterceptors[int](ctx, drq, querierCount[*DeviceRequestQuery](), drq.inters) } // CountX is like Count, but panics if an error occurs. @@ -213,10 +217,15 @@ func (drq *DeviceRequestQuery) CountX(ctx context.Context) int { // Exist returns true if the query has elements in the graph. func (drq *DeviceRequestQuery) Exist(ctx context.Context) (bool, error) { - if err := drq.prepareQuery(ctx); err != nil { - return false, err + ctx = setContextOp(ctx, drq.ctx, "Exist") + switch _, err := drq.FirstID(ctx); { + case IsNotFound(err): + return false, nil + case err != nil: + return false, fmt.Errorf("db: check existence: %w", err) + default: + return true, nil } - return drq.sqlExist(ctx) } // ExistX is like Exist, but panics if an error occurs. @@ -236,14 +245,13 @@ func (drq *DeviceRequestQuery) Clone() *DeviceRequestQuery { } return &DeviceRequestQuery{ config: drq.config, - limit: drq.limit, - offset: drq.offset, + ctx: drq.ctx.Clone(), order: append([]OrderFunc{}, drq.order...), + inters: append([]Interceptor{}, drq.inters...), predicates: append([]predicate.DeviceRequest{}, drq.predicates...), // clone intermediate query. - sql: drq.sql.Clone(), - path: drq.path, - unique: drq.unique, + sql: drq.sql.Clone(), + path: drq.path, } } @@ -261,18 +269,12 @@ func (drq *DeviceRequestQuery) Clone() *DeviceRequestQuery { // GroupBy(devicerequest.FieldUserCode). // Aggregate(db.Count()). // Scan(ctx, &v) -// func (drq *DeviceRequestQuery) GroupBy(field string, fields ...string) *DeviceRequestGroupBy { - grbuild := &DeviceRequestGroupBy{config: drq.config} - grbuild.fields = append([]string{field}, fields...) - grbuild.path = func(ctx context.Context) (prev *sql.Selector, err error) { - if err := drq.prepareQuery(ctx); err != nil { - return nil, err - } - return drq.sqlQuery(ctx), nil - } + drq.ctx.Fields = append([]string{field}, fields...) + grbuild := &DeviceRequestGroupBy{build: drq} + grbuild.flds = &drq.ctx.Fields grbuild.label = devicerequest.Label - grbuild.flds, grbuild.scan = &grbuild.fields, grbuild.Scan + grbuild.scan = grbuild.Scan return grbuild } @@ -288,17 +290,31 @@ func (drq *DeviceRequestQuery) GroupBy(field string, fields ...string) *DeviceRe // client.DeviceRequest.Query(). // Select(devicerequest.FieldUserCode). // Scan(ctx, &v) -// func (drq *DeviceRequestQuery) Select(fields ...string) *DeviceRequestSelect { - drq.fields = append(drq.fields, fields...) - selbuild := &DeviceRequestSelect{DeviceRequestQuery: drq} - selbuild.label = devicerequest.Label - selbuild.flds, selbuild.scan = &drq.fields, selbuild.Scan - return selbuild + drq.ctx.Fields = append(drq.ctx.Fields, fields...) + sbuild := &DeviceRequestSelect{DeviceRequestQuery: drq} + sbuild.label = devicerequest.Label + sbuild.flds, sbuild.scan = &drq.ctx.Fields, sbuild.Scan + return sbuild +} + +// Aggregate returns a DeviceRequestSelect configured with the given aggregations. +func (drq *DeviceRequestQuery) Aggregate(fns ...AggregateFunc) *DeviceRequestSelect { + return drq.Select().Aggregate(fns...) } func (drq *DeviceRequestQuery) prepareQuery(ctx context.Context) error { - for _, f := range drq.fields { + for _, inter := range drq.inters { + if inter == nil { + return fmt.Errorf("db: uninitialized interceptor (forgotten import db/runtime?)") + } + if trv, ok := inter.(Traverser); ok { + if err := trv.Traverse(ctx, drq); err != nil { + return err + } + } + } + for _, f := range drq.ctx.Fields { if !devicerequest.ValidColumn(f) { return &ValidationError{Name: f, err: fmt.Errorf("db: invalid field %q for query", f)} } @@ -318,10 +334,10 @@ func (drq *DeviceRequestQuery) sqlAll(ctx context.Context, hooks ...queryHook) ( nodes = []*DeviceRequest{} _spec = drq.querySpec() ) - _spec.ScanValues = func(columns []string) ([]interface{}, error) { + _spec.ScanValues = func(columns []string) ([]any, error) { return (*DeviceRequest).scanValues(nil, columns) } - _spec.Assign = func(columns []string, values []interface{}) error { + _spec.Assign = func(columns []string, values []any) error { node := &DeviceRequest{config: drq.config} nodes = append(nodes, node) return node.assignValues(columns, values) @@ -340,38 +356,22 @@ func (drq *DeviceRequestQuery) sqlAll(ctx context.Context, hooks ...queryHook) ( 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 + _spec.Node.Columns = drq.ctx.Fields + if len(drq.ctx.Fields) > 0 { + _spec.Unique = drq.ctx.Unique != nil && *drq.ctx.Unique } return sqlgraph.CountNodes(ctx, drq.driver, _spec) } -func (drq *DeviceRequestQuery) sqlExist(ctx context.Context) (bool, error) { - n, err := drq.sqlCount(ctx) - if err != nil { - return false, fmt.Errorf("db: check existence: %w", err) - } - return n > 0, nil -} - func (drq *DeviceRequestQuery) querySpec() *sqlgraph.QuerySpec { - _spec := &sqlgraph.QuerySpec{ - Node: &sqlgraph.NodeSpec{ - Table: devicerequest.Table, - Columns: devicerequest.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeInt, - Column: devicerequest.FieldID, - }, - }, - From: drq.sql, - Unique: true, - } - if unique := drq.unique; unique != nil { + _spec := sqlgraph.NewQuerySpec(devicerequest.Table, devicerequest.Columns, sqlgraph.NewFieldSpec(devicerequest.FieldID, field.TypeInt)) + _spec.From = drq.sql + if unique := drq.ctx.Unique; unique != nil { _spec.Unique = *unique + } else if drq.path != nil { + _spec.Unique = true } - if fields := drq.fields; len(fields) > 0 { + if fields := drq.ctx.Fields; len(fields) > 0 { _spec.Node.Columns = make([]string, 0, len(fields)) _spec.Node.Columns = append(_spec.Node.Columns, devicerequest.FieldID) for i := range fields { @@ -387,10 +387,10 @@ func (drq *DeviceRequestQuery) querySpec() *sqlgraph.QuerySpec { } } } - if limit := drq.limit; limit != nil { + if limit := drq.ctx.Limit; limit != nil { _spec.Limit = *limit } - if offset := drq.offset; offset != nil { + if offset := drq.ctx.Offset; offset != nil { _spec.Offset = *offset } if ps := drq.order; len(ps) > 0 { @@ -406,7 +406,7 @@ func (drq *DeviceRequestQuery) querySpec() *sqlgraph.QuerySpec { func (drq *DeviceRequestQuery) sqlQuery(ctx context.Context) *sql.Selector { builder := sql.Dialect(drq.driver.Dialect()) t1 := builder.Table(devicerequest.Table) - columns := drq.fields + columns := drq.ctx.Fields if len(columns) == 0 { columns = devicerequest.Columns } @@ -415,7 +415,7 @@ func (drq *DeviceRequestQuery) sqlQuery(ctx context.Context) *sql.Selector { selector = drq.sql selector.Select(selector.Columns(columns...)...) } - if drq.unique != nil && *drq.unique { + if drq.ctx.Unique != nil && *drq.ctx.Unique { selector.Distinct() } for _, p := range drq.predicates { @@ -424,12 +424,12 @@ func (drq *DeviceRequestQuery) sqlQuery(ctx context.Context) *sql.Selector { for _, p := range drq.order { p(selector) } - if offset := drq.offset; offset != nil { + if offset := drq.ctx.Offset; offset != nil { // limit is mandatory for offset clause. We start // with default value, and override it below if needed. selector.Offset(*offset).Limit(math.MaxInt32) } - if limit := drq.limit; limit != nil { + if limit := drq.ctx.Limit; limit != nil { selector.Limit(*limit) } return selector @@ -437,13 +437,8 @@ func (drq *DeviceRequestQuery) sqlQuery(ctx context.Context) *sql.Selector { // DeviceRequestGroupBy is the group-by builder for DeviceRequest entities. type DeviceRequestGroupBy struct { - config selector - fields []string - fns []AggregateFunc - // intermediate query (i.e. traversal path). - sql *sql.Selector - path func(context.Context) (*sql.Selector, error) + build *DeviceRequestQuery } // Aggregate adds the given aggregation functions to the group-by query. @@ -452,74 +447,77 @@ func (drgb *DeviceRequestGroupBy) Aggregate(fns ...AggregateFunc) *DeviceRequest return drgb } -// Scan applies the group-by query and scans the result into the given value. -func (drgb *DeviceRequestGroupBy) Scan(ctx context.Context, v interface{}) error { - query, err := drgb.path(ctx) - if err != nil { +// Scan applies the selector query and scans the result into the given value. +func (drgb *DeviceRequestGroupBy) Scan(ctx context.Context, v any) error { + ctx = setContextOp(ctx, drgb.build.ctx, "GroupBy") + if err := drgb.build.prepareQuery(ctx); err != nil { return err } - drgb.sql = query - return drgb.sqlScan(ctx, v) + return scanWithInterceptors[*DeviceRequestQuery, *DeviceRequestGroupBy](ctx, drgb.build, drgb, drgb.build.inters, v) } -func (drgb *DeviceRequestGroupBy) sqlScan(ctx context.Context, v interface{}) error { - for _, f := range drgb.fields { - if !devicerequest.ValidColumn(f) { - return &ValidationError{Name: f, err: fmt.Errorf("invalid field %q for group-by", f)} - } - } - selector := drgb.sqlQuery() - if err := selector.Err(); err != nil { - return err - } - rows := &sql.Rows{} - query, args := selector.Query() - if err := drgb.driver.Query(ctx, query, args, rows); err != nil { - return err - } - defer rows.Close() - return sql.ScanSlice(rows, v) -} - -func (drgb *DeviceRequestGroupBy) sqlQuery() *sql.Selector { - selector := drgb.sql.Select() +func (drgb *DeviceRequestGroupBy) sqlScan(ctx context.Context, root *DeviceRequestQuery, v any) error { + selector := root.sqlQuery(ctx).Select() aggregation := make([]string, 0, len(drgb.fns)) for _, fn := range drgb.fns { aggregation = append(aggregation, fn(selector)) } - // If no columns were selected in a custom aggregation function, the default - // selection is the fields used for "group-by", and the aggregation functions. if len(selector.SelectedColumns()) == 0 { - columns := make([]string, 0, len(drgb.fields)+len(drgb.fns)) - for _, f := range drgb.fields { + columns := make([]string, 0, len(*drgb.flds)+len(drgb.fns)) + for _, f := range *drgb.flds { columns = append(columns, selector.C(f)) } columns = append(columns, aggregation...) selector.Select(columns...) } - return selector.GroupBy(selector.Columns(drgb.fields...)...) + selector.GroupBy(selector.Columns(*drgb.flds...)...) + if err := selector.Err(); err != nil { + return err + } + rows := &sql.Rows{} + query, args := selector.Query() + if err := drgb.build.driver.Query(ctx, query, args, rows); err != nil { + return err + } + defer rows.Close() + return sql.ScanSlice(rows, v) } // DeviceRequestSelect is the builder for selecting fields of DeviceRequest entities. type DeviceRequestSelect struct { *DeviceRequestQuery selector - // intermediate query (i.e. traversal path). - sql *sql.Selector +} + +// Aggregate adds the given aggregation functions to the selector query. +func (drs *DeviceRequestSelect) Aggregate(fns ...AggregateFunc) *DeviceRequestSelect { + drs.fns = append(drs.fns, fns...) + return drs } // Scan applies the selector query and scans the result into the given value. -func (drs *DeviceRequestSelect) Scan(ctx context.Context, v interface{}) error { +func (drs *DeviceRequestSelect) Scan(ctx context.Context, v any) error { + ctx = setContextOp(ctx, drs.ctx, "Select") if err := drs.prepareQuery(ctx); err != nil { return err } - drs.sql = drs.DeviceRequestQuery.sqlQuery(ctx) - return drs.sqlScan(ctx, v) + return scanWithInterceptors[*DeviceRequestQuery, *DeviceRequestSelect](ctx, drs.DeviceRequestQuery, drs, drs.inters, v) } -func (drs *DeviceRequestSelect) sqlScan(ctx context.Context, v interface{}) error { +func (drs *DeviceRequestSelect) sqlScan(ctx context.Context, root *DeviceRequestQuery, v any) error { + selector := root.sqlQuery(ctx) + aggregation := make([]string, 0, len(drs.fns)) + for _, fn := range drs.fns { + aggregation = append(aggregation, fn(selector)) + } + switch n := len(*drs.selector.flds); { + case n == 0 && len(aggregation) > 0: + selector.Select(aggregation...) + case n != 0 && len(aggregation) > 0: + selector.AppendSelect(aggregation...) + } rows := &sql.Rows{} - query, args := drs.sql.Query() + query, args := selector.Query() if err := drs.driver.Query(ctx, query, args, rows); err != nil { return err } diff --git a/storage/ent/db/devicerequest_update.go b/storage/ent/db/devicerequest_update.go index 2bf38af6..ccd42a85 100644 --- a/storage/ent/db/devicerequest_update.go +++ b/storage/ent/db/devicerequest_update.go @@ -10,6 +10,7 @@ import ( "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/dialect/sql/sqljson" "entgo.io/ent/schema/field" "github.com/dexidp/dex/storage/ent/db/devicerequest" "github.com/dexidp/dex/storage/ent/db/predicate" @@ -58,6 +59,12 @@ func (dru *DeviceRequestUpdate) SetScopes(s []string) *DeviceRequestUpdate { return dru } +// AppendScopes appends s to the "scopes" field. +func (dru *DeviceRequestUpdate) AppendScopes(s []string) *DeviceRequestUpdate { + dru.mutation.AppendScopes(s) + return dru +} + // ClearScopes clears the value of the "scopes" field. func (dru *DeviceRequestUpdate) ClearScopes() *DeviceRequestUpdate { dru.mutation.ClearScopes() @@ -77,40 +84,7 @@ func (dru *DeviceRequestUpdate) Mutation() *DeviceRequestMutation { // Save executes the query and returns the number of nodes affected by the update operation. func (dru *DeviceRequestUpdate) Save(ctx context.Context) (int, error) { - var ( - err error - affected int - ) - if len(dru.hooks) == 0 { - if err = dru.check(); err != nil { - return 0, err - } - affected, err = dru.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*DeviceRequestMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err = dru.check(); err != nil { - return 0, err - } - dru.mutation = mutation - affected, err = dru.sqlSave(ctx) - mutation.done = true - return affected, err - }) - for i := len(dru.hooks) - 1; i >= 0; i-- { - if dru.hooks[i] == nil { - return 0, fmt.Errorf("db: uninitialized hook (forgotten import db/runtime?)") - } - mut = dru.hooks[i](mut) - } - if _, err := mut.Mutate(ctx, dru.mutation); err != nil { - return 0, err - } - } - return affected, err + return withHooks[int, DeviceRequestMutation](ctx, dru.sqlSave, dru.mutation, dru.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -161,16 +135,10 @@ func (dru *DeviceRequestUpdate) check() error { } func (dru *DeviceRequestUpdate) sqlSave(ctx context.Context) (n int, err error) { - _spec := &sqlgraph.UpdateSpec{ - Node: &sqlgraph.NodeSpec{ - Table: devicerequest.Table, - Columns: devicerequest.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeInt, - Column: devicerequest.FieldID, - }, - }, + if err := dru.check(); err != nil { + return n, err } + _spec := sqlgraph.NewUpdateSpec(devicerequest.Table, devicerequest.Columns, sqlgraph.NewFieldSpec(devicerequest.FieldID, field.TypeInt)) if ps := dru.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { @@ -179,52 +147,30 @@ func (dru *DeviceRequestUpdate) sqlSave(ctx context.Context) (n int, err error) } } if value, ok := dru.mutation.UserCode(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: devicerequest.FieldUserCode, - }) + _spec.SetField(devicerequest.FieldUserCode, field.TypeString, value) } if value, ok := dru.mutation.DeviceCode(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: devicerequest.FieldDeviceCode, - }) + _spec.SetField(devicerequest.FieldDeviceCode, field.TypeString, value) } if value, ok := dru.mutation.ClientID(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: devicerequest.FieldClientID, - }) + _spec.SetField(devicerequest.FieldClientID, field.TypeString, value) } if value, ok := dru.mutation.ClientSecret(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: devicerequest.FieldClientSecret, - }) + _spec.SetField(devicerequest.FieldClientSecret, field.TypeString, value) } if value, ok := dru.mutation.Scopes(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeJSON, - Value: value, - Column: devicerequest.FieldScopes, + _spec.SetField(devicerequest.FieldScopes, field.TypeJSON, value) + } + if value, ok := dru.mutation.AppendedScopes(); ok { + _spec.AddModifier(func(u *sql.UpdateBuilder) { + sqljson.Append(u, devicerequest.FieldScopes, value) }) } if dru.mutation.ScopesCleared() { - _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ - Type: field.TypeJSON, - Column: devicerequest.FieldScopes, - }) + _spec.ClearField(devicerequest.FieldScopes, field.TypeJSON) } if value, ok := dru.mutation.Expiry(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeTime, - Value: value, - Column: devicerequest.FieldExpiry, - }) + _spec.SetField(devicerequest.FieldExpiry, field.TypeTime, value) } if n, err = sqlgraph.UpdateNodes(ctx, dru.driver, _spec); err != nil { if _, ok := err.(*sqlgraph.NotFoundError); ok { @@ -234,6 +180,7 @@ func (dru *DeviceRequestUpdate) sqlSave(ctx context.Context) (n int, err error) } return 0, err } + dru.mutation.done = true return n, nil } @@ -275,6 +222,12 @@ func (druo *DeviceRequestUpdateOne) SetScopes(s []string) *DeviceRequestUpdateOn return druo } +// AppendScopes appends s to the "scopes" field. +func (druo *DeviceRequestUpdateOne) AppendScopes(s []string) *DeviceRequestUpdateOne { + druo.mutation.AppendScopes(s) + return druo +} + // ClearScopes clears the value of the "scopes" field. func (druo *DeviceRequestUpdateOne) ClearScopes() *DeviceRequestUpdateOne { druo.mutation.ClearScopes() @@ -292,6 +245,12 @@ func (druo *DeviceRequestUpdateOne) Mutation() *DeviceRequestMutation { return druo.mutation } +// Where appends a list predicates to the DeviceRequestUpdate builder. +func (druo *DeviceRequestUpdateOne) Where(ps ...predicate.DeviceRequest) *DeviceRequestUpdateOne { + druo.mutation.Where(ps...) + return druo +} + // Select allows selecting one or more fields (columns) of the returned entity. // The default is selecting all fields defined in the entity schema. func (druo *DeviceRequestUpdateOne) Select(field string, fields ...string) *DeviceRequestUpdateOne { @@ -301,46 +260,7 @@ func (druo *DeviceRequestUpdateOne) Select(field string, fields ...string) *Devi // Save executes the query and returns the updated DeviceRequest entity. func (druo *DeviceRequestUpdateOne) Save(ctx context.Context) (*DeviceRequest, error) { - var ( - err error - node *DeviceRequest - ) - if len(druo.hooks) == 0 { - if err = druo.check(); err != nil { - return nil, err - } - node, err = druo.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*DeviceRequestMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err = druo.check(); err != nil { - return nil, err - } - druo.mutation = mutation - node, err = druo.sqlSave(ctx) - mutation.done = true - return node, err - }) - for i := len(druo.hooks) - 1; i >= 0; i-- { - if druo.hooks[i] == nil { - return nil, fmt.Errorf("db: uninitialized hook (forgotten import db/runtime?)") - } - mut = druo.hooks[i](mut) - } - v, err := mut.Mutate(ctx, druo.mutation) - if err != nil { - return nil, err - } - nv, ok := v.(*DeviceRequest) - if !ok { - return nil, fmt.Errorf("unexpected node type %T returned from DeviceRequestMutation", v) - } - node = nv - } - return node, err + return withHooks[*DeviceRequest, DeviceRequestMutation](ctx, druo.sqlSave, druo.mutation, druo.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -391,16 +311,10 @@ func (druo *DeviceRequestUpdateOne) check() error { } func (druo *DeviceRequestUpdateOne) sqlSave(ctx context.Context) (_node *DeviceRequest, err error) { - _spec := &sqlgraph.UpdateSpec{ - Node: &sqlgraph.NodeSpec{ - Table: devicerequest.Table, - Columns: devicerequest.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeInt, - Column: devicerequest.FieldID, - }, - }, + if err := druo.check(); err != nil { + return _node, err } + _spec := sqlgraph.NewUpdateSpec(devicerequest.Table, devicerequest.Columns, sqlgraph.NewFieldSpec(devicerequest.FieldID, field.TypeInt)) id, ok := druo.mutation.ID() if !ok { return nil, &ValidationError{Name: "id", err: errors.New(`db: missing "DeviceRequest.id" for update`)} @@ -426,52 +340,30 @@ func (druo *DeviceRequestUpdateOne) sqlSave(ctx context.Context) (_node *DeviceR } } if value, ok := druo.mutation.UserCode(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: devicerequest.FieldUserCode, - }) + _spec.SetField(devicerequest.FieldUserCode, field.TypeString, value) } if value, ok := druo.mutation.DeviceCode(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: devicerequest.FieldDeviceCode, - }) + _spec.SetField(devicerequest.FieldDeviceCode, field.TypeString, value) } if value, ok := druo.mutation.ClientID(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: devicerequest.FieldClientID, - }) + _spec.SetField(devicerequest.FieldClientID, field.TypeString, value) } if value, ok := druo.mutation.ClientSecret(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: devicerequest.FieldClientSecret, - }) + _spec.SetField(devicerequest.FieldClientSecret, field.TypeString, value) } if value, ok := druo.mutation.Scopes(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeJSON, - Value: value, - Column: devicerequest.FieldScopes, + _spec.SetField(devicerequest.FieldScopes, field.TypeJSON, value) + } + if value, ok := druo.mutation.AppendedScopes(); ok { + _spec.AddModifier(func(u *sql.UpdateBuilder) { + sqljson.Append(u, devicerequest.FieldScopes, value) }) } if druo.mutation.ScopesCleared() { - _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ - Type: field.TypeJSON, - Column: devicerequest.FieldScopes, - }) + _spec.ClearField(devicerequest.FieldScopes, field.TypeJSON) } if value, ok := druo.mutation.Expiry(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeTime, - Value: value, - Column: devicerequest.FieldExpiry, - }) + _spec.SetField(devicerequest.FieldExpiry, field.TypeTime, value) } _node = &DeviceRequest{config: druo.config} _spec.Assign = _node.assignValues @@ -484,5 +376,6 @@ func (druo *DeviceRequestUpdateOne) sqlSave(ctx context.Context) (_node *DeviceR } return nil, err } + druo.mutation.done = true return _node, nil } diff --git a/storage/ent/db/devicetoken.go b/storage/ent/db/devicetoken.go index 0daa1280..64261824 100644 --- a/storage/ent/db/devicetoken.go +++ b/storage/ent/db/devicetoken.go @@ -35,8 +35,8 @@ type DeviceToken struct { } // scanValues returns the types for scanning values from sql.Rows. -func (*DeviceToken) scanValues(columns []string) ([]interface{}, error) { - values := make([]interface{}, len(columns)) +func (*DeviceToken) scanValues(columns []string) ([]any, error) { + values := make([]any, len(columns)) for i := range columns { switch columns[i] { case devicetoken.FieldToken: @@ -56,7 +56,7 @@ func (*DeviceToken) scanValues(columns []string) ([]interface{}, error) { // assignValues assigns the values that were returned from sql.Rows (after scanning) // to the DeviceToken fields. -func (dt *DeviceToken) assignValues(columns []string, values []interface{}) error { +func (dt *DeviceToken) assignValues(columns []string, values []any) error { if m, n := len(values), len(columns); m < n { return fmt.Errorf("mismatch number of scan values: %d != %d", m, n) } @@ -125,7 +125,7 @@ func (dt *DeviceToken) assignValues(columns []string, values []interface{}) erro // Note that you need to call DeviceToken.Unwrap() before calling this method if this DeviceToken // was returned from a transaction, and the transaction was committed or rolled back. func (dt *DeviceToken) Update() *DeviceTokenUpdateOne { - return (&DeviceTokenClient{config: dt.config}).UpdateOne(dt) + return NewDeviceTokenClient(dt.config).UpdateOne(dt) } // Unwrap unwraps the DeviceToken entity that was returned from a transaction after it was closed, @@ -175,9 +175,3 @@ func (dt *DeviceToken) String() string { // DeviceTokens is a parsable slice of DeviceToken. type DeviceTokens []*DeviceToken - -func (dt DeviceTokens) config(cfg config) { - for _i := range dt { - dt[_i].config = cfg - } -} diff --git a/storage/ent/db/devicetoken/where.go b/storage/ent/db/devicetoken/where.go index a8e33f1e..f1eddd80 100644 --- a/storage/ent/db/devicetoken/where.go +++ b/storage/ent/db/devicetoken/where.go @@ -11,795 +11,517 @@ import ( // ID filters vertices based on their ID field. func ID(id int) predicate.DeviceToken { - return predicate.DeviceToken(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldID), id)) - }) + return predicate.DeviceToken(sql.FieldEQ(FieldID, id)) } // IDEQ applies the EQ predicate on the ID field. func IDEQ(id int) predicate.DeviceToken { - return predicate.DeviceToken(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldID), id)) - }) + return predicate.DeviceToken(sql.FieldEQ(FieldID, id)) } // IDNEQ applies the NEQ predicate on the ID field. func IDNEQ(id int) predicate.DeviceToken { - return predicate.DeviceToken(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldID), id)) - }) + return predicate.DeviceToken(sql.FieldNEQ(FieldID, id)) } // IDIn applies the In predicate on the ID field. func IDIn(ids ...int) predicate.DeviceToken { - return predicate.DeviceToken(func(s *sql.Selector) { - v := make([]interface{}, len(ids)) - for i := range v { - v[i] = ids[i] - } - s.Where(sql.In(s.C(FieldID), v...)) - }) + return predicate.DeviceToken(sql.FieldIn(FieldID, ids...)) } // IDNotIn applies the NotIn predicate on the ID field. func IDNotIn(ids ...int) predicate.DeviceToken { - return predicate.DeviceToken(func(s *sql.Selector) { - v := make([]interface{}, len(ids)) - for i := range v { - v[i] = ids[i] - } - s.Where(sql.NotIn(s.C(FieldID), v...)) - }) + return predicate.DeviceToken(sql.FieldNotIn(FieldID, ids...)) } // IDGT applies the GT predicate on the ID field. func IDGT(id int) predicate.DeviceToken { - return predicate.DeviceToken(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldID), id)) - }) + return predicate.DeviceToken(sql.FieldGT(FieldID, id)) } // IDGTE applies the GTE predicate on the ID field. func IDGTE(id int) predicate.DeviceToken { - return predicate.DeviceToken(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldID), id)) - }) + return predicate.DeviceToken(sql.FieldGTE(FieldID, id)) } // IDLT applies the LT predicate on the ID field. func IDLT(id int) predicate.DeviceToken { - return predicate.DeviceToken(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldID), id)) - }) + return predicate.DeviceToken(sql.FieldLT(FieldID, id)) } // IDLTE applies the LTE predicate on the ID field. func IDLTE(id int) predicate.DeviceToken { - return predicate.DeviceToken(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldID), id)) - }) + return predicate.DeviceToken(sql.FieldLTE(FieldID, id)) } // DeviceCode applies equality check predicate on the "device_code" field. It's identical to DeviceCodeEQ. func DeviceCode(v string) predicate.DeviceToken { - return predicate.DeviceToken(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldDeviceCode), v)) - }) + return predicate.DeviceToken(sql.FieldEQ(FieldDeviceCode, v)) } // Status applies equality check predicate on the "status" field. It's identical to StatusEQ. func Status(v string) predicate.DeviceToken { - return predicate.DeviceToken(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldStatus), v)) - }) + return predicate.DeviceToken(sql.FieldEQ(FieldStatus, v)) } // Token applies equality check predicate on the "token" field. It's identical to TokenEQ. func Token(v []byte) predicate.DeviceToken { - return predicate.DeviceToken(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldToken), v)) - }) + return predicate.DeviceToken(sql.FieldEQ(FieldToken, v)) } // Expiry applies equality check predicate on the "expiry" field. It's identical to ExpiryEQ. func Expiry(v time.Time) predicate.DeviceToken { - return predicate.DeviceToken(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldExpiry), v)) - }) + return predicate.DeviceToken(sql.FieldEQ(FieldExpiry, v)) } // LastRequest applies equality check predicate on the "last_request" field. It's identical to LastRequestEQ. func LastRequest(v time.Time) predicate.DeviceToken { - return predicate.DeviceToken(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldLastRequest), v)) - }) + return predicate.DeviceToken(sql.FieldEQ(FieldLastRequest, v)) } // PollInterval applies equality check predicate on the "poll_interval" field. It's identical to PollIntervalEQ. func PollInterval(v int) predicate.DeviceToken { - return predicate.DeviceToken(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldPollInterval), v)) - }) + return predicate.DeviceToken(sql.FieldEQ(FieldPollInterval, v)) } // CodeChallenge applies equality check predicate on the "code_challenge" field. It's identical to CodeChallengeEQ. func CodeChallenge(v string) predicate.DeviceToken { - return predicate.DeviceToken(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldCodeChallenge), v)) - }) + return predicate.DeviceToken(sql.FieldEQ(FieldCodeChallenge, v)) } // CodeChallengeMethod applies equality check predicate on the "code_challenge_method" field. It's identical to CodeChallengeMethodEQ. func CodeChallengeMethod(v string) predicate.DeviceToken { - return predicate.DeviceToken(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldCodeChallengeMethod), v)) - }) + return predicate.DeviceToken(sql.FieldEQ(FieldCodeChallengeMethod, v)) } // DeviceCodeEQ applies the EQ predicate on the "device_code" field. func DeviceCodeEQ(v string) predicate.DeviceToken { - return predicate.DeviceToken(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldDeviceCode), v)) - }) + return predicate.DeviceToken(sql.FieldEQ(FieldDeviceCode, v)) } // DeviceCodeNEQ applies the NEQ predicate on the "device_code" field. func DeviceCodeNEQ(v string) predicate.DeviceToken { - return predicate.DeviceToken(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldDeviceCode), v)) - }) + return predicate.DeviceToken(sql.FieldNEQ(FieldDeviceCode, v)) } // DeviceCodeIn applies the In predicate on the "device_code" field. func DeviceCodeIn(vs ...string) predicate.DeviceToken { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.DeviceToken(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldDeviceCode), v...)) - }) + return predicate.DeviceToken(sql.FieldIn(FieldDeviceCode, vs...)) } // DeviceCodeNotIn applies the NotIn predicate on the "device_code" field. func DeviceCodeNotIn(vs ...string) predicate.DeviceToken { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.DeviceToken(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldDeviceCode), v...)) - }) + return predicate.DeviceToken(sql.FieldNotIn(FieldDeviceCode, vs...)) } // DeviceCodeGT applies the GT predicate on the "device_code" field. func DeviceCodeGT(v string) predicate.DeviceToken { - return predicate.DeviceToken(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldDeviceCode), v)) - }) + return predicate.DeviceToken(sql.FieldGT(FieldDeviceCode, v)) } // DeviceCodeGTE applies the GTE predicate on the "device_code" field. func DeviceCodeGTE(v string) predicate.DeviceToken { - return predicate.DeviceToken(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldDeviceCode), v)) - }) + return predicate.DeviceToken(sql.FieldGTE(FieldDeviceCode, v)) } // DeviceCodeLT applies the LT predicate on the "device_code" field. func DeviceCodeLT(v string) predicate.DeviceToken { - return predicate.DeviceToken(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldDeviceCode), v)) - }) + return predicate.DeviceToken(sql.FieldLT(FieldDeviceCode, v)) } // DeviceCodeLTE applies the LTE predicate on the "device_code" field. func DeviceCodeLTE(v string) predicate.DeviceToken { - return predicate.DeviceToken(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldDeviceCode), v)) - }) + return predicate.DeviceToken(sql.FieldLTE(FieldDeviceCode, v)) } // DeviceCodeContains applies the Contains predicate on the "device_code" field. func DeviceCodeContains(v string) predicate.DeviceToken { - return predicate.DeviceToken(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldDeviceCode), v)) - }) + return predicate.DeviceToken(sql.FieldContains(FieldDeviceCode, v)) } // DeviceCodeHasPrefix applies the HasPrefix predicate on the "device_code" field. func DeviceCodeHasPrefix(v string) predicate.DeviceToken { - return predicate.DeviceToken(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldDeviceCode), v)) - }) + return predicate.DeviceToken(sql.FieldHasPrefix(FieldDeviceCode, v)) } // DeviceCodeHasSuffix applies the HasSuffix predicate on the "device_code" field. func DeviceCodeHasSuffix(v string) predicate.DeviceToken { - return predicate.DeviceToken(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldDeviceCode), v)) - }) + return predicate.DeviceToken(sql.FieldHasSuffix(FieldDeviceCode, v)) } // DeviceCodeEqualFold applies the EqualFold predicate on the "device_code" field. func DeviceCodeEqualFold(v string) predicate.DeviceToken { - return predicate.DeviceToken(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldDeviceCode), v)) - }) + return predicate.DeviceToken(sql.FieldEqualFold(FieldDeviceCode, v)) } // DeviceCodeContainsFold applies the ContainsFold predicate on the "device_code" field. func DeviceCodeContainsFold(v string) predicate.DeviceToken { - return predicate.DeviceToken(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldDeviceCode), v)) - }) + return predicate.DeviceToken(sql.FieldContainsFold(FieldDeviceCode, v)) } // StatusEQ applies the EQ predicate on the "status" field. func StatusEQ(v string) predicate.DeviceToken { - return predicate.DeviceToken(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldStatus), v)) - }) + return predicate.DeviceToken(sql.FieldEQ(FieldStatus, v)) } // StatusNEQ applies the NEQ predicate on the "status" field. func StatusNEQ(v string) predicate.DeviceToken { - return predicate.DeviceToken(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldStatus), v)) - }) + return predicate.DeviceToken(sql.FieldNEQ(FieldStatus, v)) } // StatusIn applies the In predicate on the "status" field. func StatusIn(vs ...string) predicate.DeviceToken { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.DeviceToken(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldStatus), v...)) - }) + return predicate.DeviceToken(sql.FieldIn(FieldStatus, vs...)) } // StatusNotIn applies the NotIn predicate on the "status" field. func StatusNotIn(vs ...string) predicate.DeviceToken { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.DeviceToken(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldStatus), v...)) - }) + return predicate.DeviceToken(sql.FieldNotIn(FieldStatus, vs...)) } // StatusGT applies the GT predicate on the "status" field. func StatusGT(v string) predicate.DeviceToken { - return predicate.DeviceToken(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldStatus), v)) - }) + return predicate.DeviceToken(sql.FieldGT(FieldStatus, v)) } // StatusGTE applies the GTE predicate on the "status" field. func StatusGTE(v string) predicate.DeviceToken { - return predicate.DeviceToken(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldStatus), v)) - }) + return predicate.DeviceToken(sql.FieldGTE(FieldStatus, v)) } // StatusLT applies the LT predicate on the "status" field. func StatusLT(v string) predicate.DeviceToken { - return predicate.DeviceToken(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldStatus), v)) - }) + return predicate.DeviceToken(sql.FieldLT(FieldStatus, v)) } // StatusLTE applies the LTE predicate on the "status" field. func StatusLTE(v string) predicate.DeviceToken { - return predicate.DeviceToken(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldStatus), v)) - }) + return predicate.DeviceToken(sql.FieldLTE(FieldStatus, v)) } // StatusContains applies the Contains predicate on the "status" field. func StatusContains(v string) predicate.DeviceToken { - return predicate.DeviceToken(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldStatus), v)) - }) + return predicate.DeviceToken(sql.FieldContains(FieldStatus, v)) } // StatusHasPrefix applies the HasPrefix predicate on the "status" field. func StatusHasPrefix(v string) predicate.DeviceToken { - return predicate.DeviceToken(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldStatus), v)) - }) + return predicate.DeviceToken(sql.FieldHasPrefix(FieldStatus, v)) } // StatusHasSuffix applies the HasSuffix predicate on the "status" field. func StatusHasSuffix(v string) predicate.DeviceToken { - return predicate.DeviceToken(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldStatus), v)) - }) + return predicate.DeviceToken(sql.FieldHasSuffix(FieldStatus, v)) } // StatusEqualFold applies the EqualFold predicate on the "status" field. func StatusEqualFold(v string) predicate.DeviceToken { - return predicate.DeviceToken(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldStatus), v)) - }) + return predicate.DeviceToken(sql.FieldEqualFold(FieldStatus, v)) } // StatusContainsFold applies the ContainsFold predicate on the "status" field. func StatusContainsFold(v string) predicate.DeviceToken { - return predicate.DeviceToken(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldStatus), v)) - }) + return predicate.DeviceToken(sql.FieldContainsFold(FieldStatus, v)) } // TokenEQ applies the EQ predicate on the "token" field. func TokenEQ(v []byte) predicate.DeviceToken { - return predicate.DeviceToken(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldToken), v)) - }) + return predicate.DeviceToken(sql.FieldEQ(FieldToken, v)) } // TokenNEQ applies the NEQ predicate on the "token" field. func TokenNEQ(v []byte) predicate.DeviceToken { - return predicate.DeviceToken(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldToken), v)) - }) + return predicate.DeviceToken(sql.FieldNEQ(FieldToken, v)) } // TokenIn applies the In predicate on the "token" field. func TokenIn(vs ...[]byte) predicate.DeviceToken { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.DeviceToken(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldToken), v...)) - }) + return predicate.DeviceToken(sql.FieldIn(FieldToken, vs...)) } // TokenNotIn applies the NotIn predicate on the "token" field. func TokenNotIn(vs ...[]byte) predicate.DeviceToken { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.DeviceToken(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldToken), v...)) - }) + return predicate.DeviceToken(sql.FieldNotIn(FieldToken, vs...)) } // TokenGT applies the GT predicate on the "token" field. func TokenGT(v []byte) predicate.DeviceToken { - return predicate.DeviceToken(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldToken), v)) - }) + return predicate.DeviceToken(sql.FieldGT(FieldToken, v)) } // TokenGTE applies the GTE predicate on the "token" field. func TokenGTE(v []byte) predicate.DeviceToken { - return predicate.DeviceToken(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldToken), v)) - }) + return predicate.DeviceToken(sql.FieldGTE(FieldToken, v)) } // TokenLT applies the LT predicate on the "token" field. func TokenLT(v []byte) predicate.DeviceToken { - return predicate.DeviceToken(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldToken), v)) - }) + return predicate.DeviceToken(sql.FieldLT(FieldToken, v)) } // TokenLTE applies the LTE predicate on the "token" field. func TokenLTE(v []byte) predicate.DeviceToken { - return predicate.DeviceToken(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldToken), v)) - }) + return predicate.DeviceToken(sql.FieldLTE(FieldToken, v)) } // TokenIsNil applies the IsNil predicate on the "token" field. func TokenIsNil() predicate.DeviceToken { - return predicate.DeviceToken(func(s *sql.Selector) { - s.Where(sql.IsNull(s.C(FieldToken))) - }) + return predicate.DeviceToken(sql.FieldIsNull(FieldToken)) } // TokenNotNil applies the NotNil predicate on the "token" field. func TokenNotNil() predicate.DeviceToken { - return predicate.DeviceToken(func(s *sql.Selector) { - s.Where(sql.NotNull(s.C(FieldToken))) - }) + return predicate.DeviceToken(sql.FieldNotNull(FieldToken)) } // ExpiryEQ applies the EQ predicate on the "expiry" field. func ExpiryEQ(v time.Time) predicate.DeviceToken { - return predicate.DeviceToken(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldExpiry), v)) - }) + return predicate.DeviceToken(sql.FieldEQ(FieldExpiry, v)) } // ExpiryNEQ applies the NEQ predicate on the "expiry" field. func ExpiryNEQ(v time.Time) predicate.DeviceToken { - return predicate.DeviceToken(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldExpiry), v)) - }) + return predicate.DeviceToken(sql.FieldNEQ(FieldExpiry, v)) } // ExpiryIn applies the In predicate on the "expiry" field. func ExpiryIn(vs ...time.Time) predicate.DeviceToken { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.DeviceToken(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldExpiry), v...)) - }) + return predicate.DeviceToken(sql.FieldIn(FieldExpiry, vs...)) } // ExpiryNotIn applies the NotIn predicate on the "expiry" field. func ExpiryNotIn(vs ...time.Time) predicate.DeviceToken { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.DeviceToken(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldExpiry), v...)) - }) + return predicate.DeviceToken(sql.FieldNotIn(FieldExpiry, vs...)) } // ExpiryGT applies the GT predicate on the "expiry" field. func ExpiryGT(v time.Time) predicate.DeviceToken { - return predicate.DeviceToken(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldExpiry), v)) - }) + return predicate.DeviceToken(sql.FieldGT(FieldExpiry, v)) } // ExpiryGTE applies the GTE predicate on the "expiry" field. func ExpiryGTE(v time.Time) predicate.DeviceToken { - return predicate.DeviceToken(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldExpiry), v)) - }) + return predicate.DeviceToken(sql.FieldGTE(FieldExpiry, v)) } // ExpiryLT applies the LT predicate on the "expiry" field. func ExpiryLT(v time.Time) predicate.DeviceToken { - return predicate.DeviceToken(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldExpiry), v)) - }) + return predicate.DeviceToken(sql.FieldLT(FieldExpiry, v)) } // ExpiryLTE applies the LTE predicate on the "expiry" field. func ExpiryLTE(v time.Time) predicate.DeviceToken { - return predicate.DeviceToken(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldExpiry), v)) - }) + return predicate.DeviceToken(sql.FieldLTE(FieldExpiry, v)) } // LastRequestEQ applies the EQ predicate on the "last_request" field. func LastRequestEQ(v time.Time) predicate.DeviceToken { - return predicate.DeviceToken(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldLastRequest), v)) - }) + return predicate.DeviceToken(sql.FieldEQ(FieldLastRequest, v)) } // LastRequestNEQ applies the NEQ predicate on the "last_request" field. func LastRequestNEQ(v time.Time) predicate.DeviceToken { - return predicate.DeviceToken(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldLastRequest), v)) - }) + return predicate.DeviceToken(sql.FieldNEQ(FieldLastRequest, v)) } // LastRequestIn applies the In predicate on the "last_request" field. func LastRequestIn(vs ...time.Time) predicate.DeviceToken { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.DeviceToken(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldLastRequest), v...)) - }) + return predicate.DeviceToken(sql.FieldIn(FieldLastRequest, vs...)) } // LastRequestNotIn applies the NotIn predicate on the "last_request" field. func LastRequestNotIn(vs ...time.Time) predicate.DeviceToken { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.DeviceToken(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldLastRequest), v...)) - }) + return predicate.DeviceToken(sql.FieldNotIn(FieldLastRequest, vs...)) } // LastRequestGT applies the GT predicate on the "last_request" field. func LastRequestGT(v time.Time) predicate.DeviceToken { - return predicate.DeviceToken(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldLastRequest), v)) - }) + return predicate.DeviceToken(sql.FieldGT(FieldLastRequest, v)) } // LastRequestGTE applies the GTE predicate on the "last_request" field. func LastRequestGTE(v time.Time) predicate.DeviceToken { - return predicate.DeviceToken(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldLastRequest), v)) - }) + return predicate.DeviceToken(sql.FieldGTE(FieldLastRequest, v)) } // LastRequestLT applies the LT predicate on the "last_request" field. func LastRequestLT(v time.Time) predicate.DeviceToken { - return predicate.DeviceToken(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldLastRequest), v)) - }) + return predicate.DeviceToken(sql.FieldLT(FieldLastRequest, v)) } // LastRequestLTE applies the LTE predicate on the "last_request" field. func LastRequestLTE(v time.Time) predicate.DeviceToken { - return predicate.DeviceToken(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldLastRequest), v)) - }) + return predicate.DeviceToken(sql.FieldLTE(FieldLastRequest, v)) } // PollIntervalEQ applies the EQ predicate on the "poll_interval" field. func PollIntervalEQ(v int) predicate.DeviceToken { - return predicate.DeviceToken(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldPollInterval), v)) - }) + return predicate.DeviceToken(sql.FieldEQ(FieldPollInterval, v)) } // PollIntervalNEQ applies the NEQ predicate on the "poll_interval" field. func PollIntervalNEQ(v int) predicate.DeviceToken { - return predicate.DeviceToken(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldPollInterval), v)) - }) + return predicate.DeviceToken(sql.FieldNEQ(FieldPollInterval, v)) } // PollIntervalIn applies the In predicate on the "poll_interval" field. func PollIntervalIn(vs ...int) predicate.DeviceToken { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.DeviceToken(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldPollInterval), v...)) - }) + return predicate.DeviceToken(sql.FieldIn(FieldPollInterval, vs...)) } // PollIntervalNotIn applies the NotIn predicate on the "poll_interval" field. func PollIntervalNotIn(vs ...int) predicate.DeviceToken { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.DeviceToken(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldPollInterval), v...)) - }) + return predicate.DeviceToken(sql.FieldNotIn(FieldPollInterval, vs...)) } // PollIntervalGT applies the GT predicate on the "poll_interval" field. func PollIntervalGT(v int) predicate.DeviceToken { - return predicate.DeviceToken(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldPollInterval), v)) - }) + return predicate.DeviceToken(sql.FieldGT(FieldPollInterval, v)) } // PollIntervalGTE applies the GTE predicate on the "poll_interval" field. func PollIntervalGTE(v int) predicate.DeviceToken { - return predicate.DeviceToken(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldPollInterval), v)) - }) + return predicate.DeviceToken(sql.FieldGTE(FieldPollInterval, v)) } // PollIntervalLT applies the LT predicate on the "poll_interval" field. func PollIntervalLT(v int) predicate.DeviceToken { - return predicate.DeviceToken(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldPollInterval), v)) - }) + return predicate.DeviceToken(sql.FieldLT(FieldPollInterval, v)) } // PollIntervalLTE applies the LTE predicate on the "poll_interval" field. func PollIntervalLTE(v int) predicate.DeviceToken { - return predicate.DeviceToken(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldPollInterval), v)) - }) + return predicate.DeviceToken(sql.FieldLTE(FieldPollInterval, v)) } // CodeChallengeEQ applies the EQ predicate on the "code_challenge" field. func CodeChallengeEQ(v string) predicate.DeviceToken { - return predicate.DeviceToken(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldCodeChallenge), v)) - }) + return predicate.DeviceToken(sql.FieldEQ(FieldCodeChallenge, v)) } // CodeChallengeNEQ applies the NEQ predicate on the "code_challenge" field. func CodeChallengeNEQ(v string) predicate.DeviceToken { - return predicate.DeviceToken(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldCodeChallenge), v)) - }) + return predicate.DeviceToken(sql.FieldNEQ(FieldCodeChallenge, v)) } // CodeChallengeIn applies the In predicate on the "code_challenge" field. func CodeChallengeIn(vs ...string) predicate.DeviceToken { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.DeviceToken(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldCodeChallenge), v...)) - }) + return predicate.DeviceToken(sql.FieldIn(FieldCodeChallenge, vs...)) } // CodeChallengeNotIn applies the NotIn predicate on the "code_challenge" field. func CodeChallengeNotIn(vs ...string) predicate.DeviceToken { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.DeviceToken(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldCodeChallenge), v...)) - }) + return predicate.DeviceToken(sql.FieldNotIn(FieldCodeChallenge, vs...)) } // CodeChallengeGT applies the GT predicate on the "code_challenge" field. func CodeChallengeGT(v string) predicate.DeviceToken { - return predicate.DeviceToken(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldCodeChallenge), v)) - }) + return predicate.DeviceToken(sql.FieldGT(FieldCodeChallenge, v)) } // CodeChallengeGTE applies the GTE predicate on the "code_challenge" field. func CodeChallengeGTE(v string) predicate.DeviceToken { - return predicate.DeviceToken(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldCodeChallenge), v)) - }) + return predicate.DeviceToken(sql.FieldGTE(FieldCodeChallenge, v)) } // CodeChallengeLT applies the LT predicate on the "code_challenge" field. func CodeChallengeLT(v string) predicate.DeviceToken { - return predicate.DeviceToken(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldCodeChallenge), v)) - }) + return predicate.DeviceToken(sql.FieldLT(FieldCodeChallenge, v)) } // CodeChallengeLTE applies the LTE predicate on the "code_challenge" field. func CodeChallengeLTE(v string) predicate.DeviceToken { - return predicate.DeviceToken(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldCodeChallenge), v)) - }) + return predicate.DeviceToken(sql.FieldLTE(FieldCodeChallenge, v)) } // CodeChallengeContains applies the Contains predicate on the "code_challenge" field. func CodeChallengeContains(v string) predicate.DeviceToken { - return predicate.DeviceToken(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldCodeChallenge), v)) - }) + return predicate.DeviceToken(sql.FieldContains(FieldCodeChallenge, v)) } // CodeChallengeHasPrefix applies the HasPrefix predicate on the "code_challenge" field. func CodeChallengeHasPrefix(v string) predicate.DeviceToken { - return predicate.DeviceToken(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldCodeChallenge), v)) - }) + return predicate.DeviceToken(sql.FieldHasPrefix(FieldCodeChallenge, v)) } // CodeChallengeHasSuffix applies the HasSuffix predicate on the "code_challenge" field. func CodeChallengeHasSuffix(v string) predicate.DeviceToken { - return predicate.DeviceToken(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldCodeChallenge), v)) - }) + return predicate.DeviceToken(sql.FieldHasSuffix(FieldCodeChallenge, v)) } // CodeChallengeEqualFold applies the EqualFold predicate on the "code_challenge" field. func CodeChallengeEqualFold(v string) predicate.DeviceToken { - return predicate.DeviceToken(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldCodeChallenge), v)) - }) + return predicate.DeviceToken(sql.FieldEqualFold(FieldCodeChallenge, v)) } // CodeChallengeContainsFold applies the ContainsFold predicate on the "code_challenge" field. func CodeChallengeContainsFold(v string) predicate.DeviceToken { - return predicate.DeviceToken(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldCodeChallenge), v)) - }) + return predicate.DeviceToken(sql.FieldContainsFold(FieldCodeChallenge, v)) } // CodeChallengeMethodEQ applies the EQ predicate on the "code_challenge_method" field. func CodeChallengeMethodEQ(v string) predicate.DeviceToken { - return predicate.DeviceToken(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldCodeChallengeMethod), v)) - }) + return predicate.DeviceToken(sql.FieldEQ(FieldCodeChallengeMethod, v)) } // CodeChallengeMethodNEQ applies the NEQ predicate on the "code_challenge_method" field. func CodeChallengeMethodNEQ(v string) predicate.DeviceToken { - return predicate.DeviceToken(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldCodeChallengeMethod), v)) - }) + return predicate.DeviceToken(sql.FieldNEQ(FieldCodeChallengeMethod, v)) } // CodeChallengeMethodIn applies the In predicate on the "code_challenge_method" field. func CodeChallengeMethodIn(vs ...string) predicate.DeviceToken { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.DeviceToken(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldCodeChallengeMethod), v...)) - }) + return predicate.DeviceToken(sql.FieldIn(FieldCodeChallengeMethod, vs...)) } // CodeChallengeMethodNotIn applies the NotIn predicate on the "code_challenge_method" field. func CodeChallengeMethodNotIn(vs ...string) predicate.DeviceToken { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.DeviceToken(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldCodeChallengeMethod), v...)) - }) + return predicate.DeviceToken(sql.FieldNotIn(FieldCodeChallengeMethod, vs...)) } // CodeChallengeMethodGT applies the GT predicate on the "code_challenge_method" field. func CodeChallengeMethodGT(v string) predicate.DeviceToken { - return predicate.DeviceToken(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldCodeChallengeMethod), v)) - }) + return predicate.DeviceToken(sql.FieldGT(FieldCodeChallengeMethod, v)) } // CodeChallengeMethodGTE applies the GTE predicate on the "code_challenge_method" field. func CodeChallengeMethodGTE(v string) predicate.DeviceToken { - return predicate.DeviceToken(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldCodeChallengeMethod), v)) - }) + return predicate.DeviceToken(sql.FieldGTE(FieldCodeChallengeMethod, v)) } // CodeChallengeMethodLT applies the LT predicate on the "code_challenge_method" field. func CodeChallengeMethodLT(v string) predicate.DeviceToken { - return predicate.DeviceToken(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldCodeChallengeMethod), v)) - }) + return predicate.DeviceToken(sql.FieldLT(FieldCodeChallengeMethod, v)) } // CodeChallengeMethodLTE applies the LTE predicate on the "code_challenge_method" field. func CodeChallengeMethodLTE(v string) predicate.DeviceToken { - return predicate.DeviceToken(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldCodeChallengeMethod), v)) - }) + return predicate.DeviceToken(sql.FieldLTE(FieldCodeChallengeMethod, v)) } // CodeChallengeMethodContains applies the Contains predicate on the "code_challenge_method" field. func CodeChallengeMethodContains(v string) predicate.DeviceToken { - return predicate.DeviceToken(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldCodeChallengeMethod), v)) - }) + return predicate.DeviceToken(sql.FieldContains(FieldCodeChallengeMethod, v)) } // CodeChallengeMethodHasPrefix applies the HasPrefix predicate on the "code_challenge_method" field. func CodeChallengeMethodHasPrefix(v string) predicate.DeviceToken { - return predicate.DeviceToken(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldCodeChallengeMethod), v)) - }) + return predicate.DeviceToken(sql.FieldHasPrefix(FieldCodeChallengeMethod, v)) } // CodeChallengeMethodHasSuffix applies the HasSuffix predicate on the "code_challenge_method" field. func CodeChallengeMethodHasSuffix(v string) predicate.DeviceToken { - return predicate.DeviceToken(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldCodeChallengeMethod), v)) - }) + return predicate.DeviceToken(sql.FieldHasSuffix(FieldCodeChallengeMethod, v)) } // CodeChallengeMethodEqualFold applies the EqualFold predicate on the "code_challenge_method" field. func CodeChallengeMethodEqualFold(v string) predicate.DeviceToken { - return predicate.DeviceToken(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldCodeChallengeMethod), v)) - }) + return predicate.DeviceToken(sql.FieldEqualFold(FieldCodeChallengeMethod, v)) } // CodeChallengeMethodContainsFold applies the ContainsFold predicate on the "code_challenge_method" field. func CodeChallengeMethodContainsFold(v string) predicate.DeviceToken { - return predicate.DeviceToken(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldCodeChallengeMethod), v)) - }) + return predicate.DeviceToken(sql.FieldContainsFold(FieldCodeChallengeMethod, v)) } // And groups predicates with the AND operator between them. diff --git a/storage/ent/db/devicetoken_create.go b/storage/ent/db/devicetoken_create.go index bbf67e5a..5d6ba9cc 100644 --- a/storage/ent/db/devicetoken_create.go +++ b/storage/ent/db/devicetoken_create.go @@ -91,50 +91,8 @@ func (dtc *DeviceTokenCreate) Mutation() *DeviceTokenMutation { // Save creates the DeviceToken in the database. func (dtc *DeviceTokenCreate) Save(ctx context.Context) (*DeviceToken, error) { - var ( - err error - node *DeviceToken - ) dtc.defaults() - if len(dtc.hooks) == 0 { - if err = dtc.check(); err != nil { - return nil, err - } - node, err = dtc.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*DeviceTokenMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err = dtc.check(); err != nil { - return nil, err - } - dtc.mutation = mutation - if node, err = dtc.sqlSave(ctx); err != nil { - return nil, err - } - mutation.id = &node.ID - mutation.done = true - return node, err - }) - for i := len(dtc.hooks) - 1; i >= 0; i-- { - if dtc.hooks[i] == nil { - return nil, fmt.Errorf("db: uninitialized hook (forgotten import db/runtime?)") - } - mut = dtc.hooks[i](mut) - } - v, err := mut.Mutate(ctx, dtc.mutation) - if err != nil { - return nil, err - } - nv, ok := v.(*DeviceToken) - if !ok { - return nil, fmt.Errorf("unexpected node type %T returned from DeviceTokenMutation", v) - } - node = nv - } - return node, err + return withHooks[*DeviceToken, DeviceTokenMutation](ctx, dtc.sqlSave, dtc.mutation, dtc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -208,6 +166,9 @@ func (dtc *DeviceTokenCreate) check() error { } func (dtc *DeviceTokenCreate) sqlSave(ctx context.Context) (*DeviceToken, error) { + if err := dtc.check(); err != nil { + return nil, err + } _node, _spec := dtc.createSpec() if err := sqlgraph.CreateNode(ctx, dtc.driver, _spec); err != nil { if sqlgraph.IsConstraintError(err) { @@ -217,82 +178,46 @@ func (dtc *DeviceTokenCreate) sqlSave(ctx context.Context) (*DeviceToken, error) } id := _spec.ID.Value.(int64) _node.ID = int(id) + dtc.mutation.id = &_node.ID + dtc.mutation.done = true return _node, nil } func (dtc *DeviceTokenCreate) createSpec() (*DeviceToken, *sqlgraph.CreateSpec) { var ( _node = &DeviceToken{config: dtc.config} - _spec = &sqlgraph.CreateSpec{ - Table: devicetoken.Table, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeInt, - Column: devicetoken.FieldID, - }, - } + _spec = sqlgraph.NewCreateSpec(devicetoken.Table, sqlgraph.NewFieldSpec(devicetoken.FieldID, field.TypeInt)) ) if value, ok := dtc.mutation.DeviceCode(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: devicetoken.FieldDeviceCode, - }) + _spec.SetField(devicetoken.FieldDeviceCode, field.TypeString, value) _node.DeviceCode = value } if value, ok := dtc.mutation.Status(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: devicetoken.FieldStatus, - }) + _spec.SetField(devicetoken.FieldStatus, field.TypeString, value) _node.Status = value } if value, ok := dtc.mutation.Token(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeBytes, - Value: value, - Column: devicetoken.FieldToken, - }) + _spec.SetField(devicetoken.FieldToken, field.TypeBytes, value) _node.Token = &value } if value, ok := dtc.mutation.Expiry(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeTime, - Value: value, - Column: devicetoken.FieldExpiry, - }) + _spec.SetField(devicetoken.FieldExpiry, field.TypeTime, value) _node.Expiry = value } if value, ok := dtc.mutation.LastRequest(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeTime, - Value: value, - Column: devicetoken.FieldLastRequest, - }) + _spec.SetField(devicetoken.FieldLastRequest, field.TypeTime, value) _node.LastRequest = value } if value, ok := dtc.mutation.PollInterval(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeInt, - Value: value, - Column: devicetoken.FieldPollInterval, - }) + _spec.SetField(devicetoken.FieldPollInterval, field.TypeInt, value) _node.PollInterval = value } if value, ok := dtc.mutation.CodeChallenge(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: devicetoken.FieldCodeChallenge, - }) + _spec.SetField(devicetoken.FieldCodeChallenge, field.TypeString, value) _node.CodeChallenge = value } if value, ok := dtc.mutation.CodeChallengeMethod(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: devicetoken.FieldCodeChallengeMethod, - }) + _spec.SetField(devicetoken.FieldCodeChallengeMethod, field.TypeString, value) _node.CodeChallengeMethod = value } return _node, _spec diff --git a/storage/ent/db/devicetoken_delete.go b/storage/ent/db/devicetoken_delete.go index 3c196aac..8775ba63 100644 --- a/storage/ent/db/devicetoken_delete.go +++ b/storage/ent/db/devicetoken_delete.go @@ -4,7 +4,6 @@ package db import ( "context" - "fmt" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" @@ -28,34 +27,7 @@ func (dtd *DeviceTokenDelete) Where(ps ...predicate.DeviceToken) *DeviceTokenDel // Exec executes the deletion query and returns how many vertices were deleted. func (dtd *DeviceTokenDelete) Exec(ctx context.Context) (int, error) { - var ( - err error - affected int - ) - if len(dtd.hooks) == 0 { - affected, err = dtd.sqlExec(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*DeviceTokenMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - dtd.mutation = mutation - affected, err = dtd.sqlExec(ctx) - mutation.done = true - return affected, err - }) - for i := len(dtd.hooks) - 1; i >= 0; i-- { - if dtd.hooks[i] == nil { - return 0, fmt.Errorf("db: uninitialized hook (forgotten import db/runtime?)") - } - mut = dtd.hooks[i](mut) - } - if _, err := mut.Mutate(ctx, dtd.mutation); err != nil { - return 0, err - } - } - return affected, err + return withHooks[int, DeviceTokenMutation](ctx, dtd.sqlExec, dtd.mutation, dtd.hooks) } // ExecX is like Exec, but panics if an error occurs. @@ -68,15 +40,7 @@ func (dtd *DeviceTokenDelete) ExecX(ctx context.Context) int { } func (dtd *DeviceTokenDelete) sqlExec(ctx context.Context) (int, error) { - _spec := &sqlgraph.DeleteSpec{ - Node: &sqlgraph.NodeSpec{ - Table: devicetoken.Table, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeInt, - Column: devicetoken.FieldID, - }, - }, - } + _spec := sqlgraph.NewDeleteSpec(devicetoken.Table, sqlgraph.NewFieldSpec(devicetoken.FieldID, field.TypeInt)) if ps := dtd.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { @@ -88,6 +52,7 @@ func (dtd *DeviceTokenDelete) sqlExec(ctx context.Context) (int, error) { if err != nil && sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } + dtd.mutation.done = true return affected, err } @@ -96,6 +61,12 @@ type DeviceTokenDeleteOne struct { dtd *DeviceTokenDelete } +// Where appends a list predicates to the DeviceTokenDelete builder. +func (dtdo *DeviceTokenDeleteOne) Where(ps ...predicate.DeviceToken) *DeviceTokenDeleteOne { + dtdo.dtd.mutation.Where(ps...) + return dtdo +} + // Exec executes the deletion query. func (dtdo *DeviceTokenDeleteOne) Exec(ctx context.Context) error { n, err := dtdo.dtd.Exec(ctx) @@ -111,5 +82,7 @@ func (dtdo *DeviceTokenDeleteOne) Exec(ctx context.Context) error { // ExecX is like Exec, but panics if an error occurs. func (dtdo *DeviceTokenDeleteOne) ExecX(ctx context.Context) { - dtdo.dtd.ExecX(ctx) + if err := dtdo.Exec(ctx); err != nil { + panic(err) + } } diff --git a/storage/ent/db/devicetoken_query.go b/storage/ent/db/devicetoken_query.go index 1860a841..f651bb2a 100644 --- a/storage/ent/db/devicetoken_query.go +++ b/storage/ent/db/devicetoken_query.go @@ -17,11 +17,9 @@ import ( // DeviceTokenQuery is the builder for querying DeviceToken entities. type DeviceTokenQuery struct { config - limit *int - offset *int - unique *bool + ctx *QueryContext order []OrderFunc - fields []string + inters []Interceptor predicates []predicate.DeviceToken // intermediate query (i.e. traversal path). sql *sql.Selector @@ -34,26 +32,26 @@ func (dtq *DeviceTokenQuery) Where(ps ...predicate.DeviceToken) *DeviceTokenQuer return dtq } -// Limit adds a limit step to the query. +// Limit the number of records to be returned by this query. func (dtq *DeviceTokenQuery) Limit(limit int) *DeviceTokenQuery { - dtq.limit = &limit + dtq.ctx.Limit = &limit return dtq } -// Offset adds an offset step to the query. +// Offset to start from. func (dtq *DeviceTokenQuery) Offset(offset int) *DeviceTokenQuery { - dtq.offset = &offset + dtq.ctx.Offset = &offset return dtq } // Unique configures the query builder to filter duplicate records on query. // By default, unique is set to true, and can be disabled using this method. func (dtq *DeviceTokenQuery) Unique(unique bool) *DeviceTokenQuery { - dtq.unique = &unique + dtq.ctx.Unique = &unique return dtq } -// Order adds an order step to the query. +// Order specifies how the records should be ordered. func (dtq *DeviceTokenQuery) Order(o ...OrderFunc) *DeviceTokenQuery { dtq.order = append(dtq.order, o...) return dtq @@ -62,7 +60,7 @@ func (dtq *DeviceTokenQuery) Order(o ...OrderFunc) *DeviceTokenQuery { // First returns the first DeviceToken entity from the query. // Returns a *NotFoundError when no DeviceToken was found. func (dtq *DeviceTokenQuery) First(ctx context.Context) (*DeviceToken, error) { - nodes, err := dtq.Limit(1).All(ctx) + nodes, err := dtq.Limit(1).All(setContextOp(ctx, dtq.ctx, "First")) if err != nil { return nil, err } @@ -85,7 +83,7 @@ func (dtq *DeviceTokenQuery) FirstX(ctx context.Context) *DeviceToken { // Returns a *NotFoundError when no DeviceToken ID was found. func (dtq *DeviceTokenQuery) FirstID(ctx context.Context) (id int, err error) { var ids []int - if ids, err = dtq.Limit(1).IDs(ctx); err != nil { + if ids, err = dtq.Limit(1).IDs(setContextOp(ctx, dtq.ctx, "FirstID")); err != nil { return } if len(ids) == 0 { @@ -108,7 +106,7 @@ func (dtq *DeviceTokenQuery) FirstIDX(ctx context.Context) int { // 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) + nodes, err := dtq.Limit(2).All(setContextOp(ctx, dtq.ctx, "Only")) if err != nil { return nil, err } @@ -136,7 +134,7 @@ func (dtq *DeviceTokenQuery) OnlyX(ctx context.Context) *DeviceToken { // Returns a *NotFoundError when no entities are found. func (dtq *DeviceTokenQuery) OnlyID(ctx context.Context) (id int, err error) { var ids []int - if ids, err = dtq.Limit(2).IDs(ctx); err != nil { + if ids, err = dtq.Limit(2).IDs(setContextOp(ctx, dtq.ctx, "OnlyID")); err != nil { return } switch len(ids) { @@ -161,10 +159,12 @@ func (dtq *DeviceTokenQuery) OnlyIDX(ctx context.Context) int { // All executes the query and returns a list of DeviceTokens. func (dtq *DeviceTokenQuery) All(ctx context.Context) ([]*DeviceToken, error) { + ctx = setContextOp(ctx, dtq.ctx, "All") if err := dtq.prepareQuery(ctx); err != nil { return nil, err } - return dtq.sqlAll(ctx) + qr := querierAll[[]*DeviceToken, *DeviceTokenQuery]() + return withInterceptors[[]*DeviceToken](ctx, dtq, qr, dtq.inters) } // AllX is like All, but panics if an error occurs. @@ -177,9 +177,12 @@ func (dtq *DeviceTokenQuery) AllX(ctx context.Context) []*DeviceToken { } // IDs executes the query and returns a list of DeviceToken IDs. -func (dtq *DeviceTokenQuery) IDs(ctx context.Context) ([]int, error) { - var ids []int - if err := dtq.Select(devicetoken.FieldID).Scan(ctx, &ids); err != nil { +func (dtq *DeviceTokenQuery) IDs(ctx context.Context) (ids []int, err error) { + if dtq.ctx.Unique == nil && dtq.path != nil { + dtq.Unique(true) + } + ctx = setContextOp(ctx, dtq.ctx, "IDs") + if err = dtq.Select(devicetoken.FieldID).Scan(ctx, &ids); err != nil { return nil, err } return ids, nil @@ -196,10 +199,11 @@ func (dtq *DeviceTokenQuery) IDsX(ctx context.Context) []int { // Count returns the count of the given query. func (dtq *DeviceTokenQuery) Count(ctx context.Context) (int, error) { + ctx = setContextOp(ctx, dtq.ctx, "Count") if err := dtq.prepareQuery(ctx); err != nil { return 0, err } - return dtq.sqlCount(ctx) + return withInterceptors[int](ctx, dtq, querierCount[*DeviceTokenQuery](), dtq.inters) } // CountX is like Count, but panics if an error occurs. @@ -213,10 +217,15 @@ func (dtq *DeviceTokenQuery) CountX(ctx context.Context) int { // Exist returns true if the query has elements in the graph. func (dtq *DeviceTokenQuery) Exist(ctx context.Context) (bool, error) { - if err := dtq.prepareQuery(ctx); err != nil { - return false, err + ctx = setContextOp(ctx, dtq.ctx, "Exist") + switch _, err := dtq.FirstID(ctx); { + case IsNotFound(err): + return false, nil + case err != nil: + return false, fmt.Errorf("db: check existence: %w", err) + default: + return true, nil } - return dtq.sqlExist(ctx) } // ExistX is like Exist, but panics if an error occurs. @@ -236,14 +245,13 @@ func (dtq *DeviceTokenQuery) Clone() *DeviceTokenQuery { } return &DeviceTokenQuery{ config: dtq.config, - limit: dtq.limit, - offset: dtq.offset, + ctx: dtq.ctx.Clone(), order: append([]OrderFunc{}, dtq.order...), + inters: append([]Interceptor{}, dtq.inters...), predicates: append([]predicate.DeviceToken{}, dtq.predicates...), // clone intermediate query. - sql: dtq.sql.Clone(), - path: dtq.path, - unique: dtq.unique, + sql: dtq.sql.Clone(), + path: dtq.path, } } @@ -261,18 +269,12 @@ func (dtq *DeviceTokenQuery) Clone() *DeviceTokenQuery { // GroupBy(devicetoken.FieldDeviceCode). // Aggregate(db.Count()). // Scan(ctx, &v) -// func (dtq *DeviceTokenQuery) GroupBy(field string, fields ...string) *DeviceTokenGroupBy { - grbuild := &DeviceTokenGroupBy{config: dtq.config} - grbuild.fields = append([]string{field}, fields...) - grbuild.path = func(ctx context.Context) (prev *sql.Selector, err error) { - if err := dtq.prepareQuery(ctx); err != nil { - return nil, err - } - return dtq.sqlQuery(ctx), nil - } + dtq.ctx.Fields = append([]string{field}, fields...) + grbuild := &DeviceTokenGroupBy{build: dtq} + grbuild.flds = &dtq.ctx.Fields grbuild.label = devicetoken.Label - grbuild.flds, grbuild.scan = &grbuild.fields, grbuild.Scan + grbuild.scan = grbuild.Scan return grbuild } @@ -288,17 +290,31 @@ func (dtq *DeviceTokenQuery) GroupBy(field string, fields ...string) *DeviceToke // client.DeviceToken.Query(). // Select(devicetoken.FieldDeviceCode). // Scan(ctx, &v) -// func (dtq *DeviceTokenQuery) Select(fields ...string) *DeviceTokenSelect { - dtq.fields = append(dtq.fields, fields...) - selbuild := &DeviceTokenSelect{DeviceTokenQuery: dtq} - selbuild.label = devicetoken.Label - selbuild.flds, selbuild.scan = &dtq.fields, selbuild.Scan - return selbuild + dtq.ctx.Fields = append(dtq.ctx.Fields, fields...) + sbuild := &DeviceTokenSelect{DeviceTokenQuery: dtq} + sbuild.label = devicetoken.Label + sbuild.flds, sbuild.scan = &dtq.ctx.Fields, sbuild.Scan + return sbuild +} + +// Aggregate returns a DeviceTokenSelect configured with the given aggregations. +func (dtq *DeviceTokenQuery) Aggregate(fns ...AggregateFunc) *DeviceTokenSelect { + return dtq.Select().Aggregate(fns...) } func (dtq *DeviceTokenQuery) prepareQuery(ctx context.Context) error { - for _, f := range dtq.fields { + for _, inter := range dtq.inters { + if inter == nil { + return fmt.Errorf("db: uninitialized interceptor (forgotten import db/runtime?)") + } + if trv, ok := inter.(Traverser); ok { + if err := trv.Traverse(ctx, dtq); err != nil { + return err + } + } + } + for _, f := range dtq.ctx.Fields { if !devicetoken.ValidColumn(f) { return &ValidationError{Name: f, err: fmt.Errorf("db: invalid field %q for query", f)} } @@ -318,10 +334,10 @@ func (dtq *DeviceTokenQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([] nodes = []*DeviceToken{} _spec = dtq.querySpec() ) - _spec.ScanValues = func(columns []string) ([]interface{}, error) { + _spec.ScanValues = func(columns []string) ([]any, error) { return (*DeviceToken).scanValues(nil, columns) } - _spec.Assign = func(columns []string, values []interface{}) error { + _spec.Assign = func(columns []string, values []any) error { node := &DeviceToken{config: dtq.config} nodes = append(nodes, node) return node.assignValues(columns, values) @@ -340,38 +356,22 @@ func (dtq *DeviceTokenQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([] 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 + _spec.Node.Columns = dtq.ctx.Fields + if len(dtq.ctx.Fields) > 0 { + _spec.Unique = dtq.ctx.Unique != nil && *dtq.ctx.Unique } return sqlgraph.CountNodes(ctx, dtq.driver, _spec) } -func (dtq *DeviceTokenQuery) sqlExist(ctx context.Context) (bool, error) { - n, err := dtq.sqlCount(ctx) - if err != nil { - return false, fmt.Errorf("db: check existence: %w", err) - } - return n > 0, nil -} - func (dtq *DeviceTokenQuery) querySpec() *sqlgraph.QuerySpec { - _spec := &sqlgraph.QuerySpec{ - Node: &sqlgraph.NodeSpec{ - Table: devicetoken.Table, - Columns: devicetoken.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeInt, - Column: devicetoken.FieldID, - }, - }, - From: dtq.sql, - Unique: true, - } - if unique := dtq.unique; unique != nil { + _spec := sqlgraph.NewQuerySpec(devicetoken.Table, devicetoken.Columns, sqlgraph.NewFieldSpec(devicetoken.FieldID, field.TypeInt)) + _spec.From = dtq.sql + if unique := dtq.ctx.Unique; unique != nil { _spec.Unique = *unique + } else if dtq.path != nil { + _spec.Unique = true } - if fields := dtq.fields; len(fields) > 0 { + if fields := dtq.ctx.Fields; len(fields) > 0 { _spec.Node.Columns = make([]string, 0, len(fields)) _spec.Node.Columns = append(_spec.Node.Columns, devicetoken.FieldID) for i := range fields { @@ -387,10 +387,10 @@ func (dtq *DeviceTokenQuery) querySpec() *sqlgraph.QuerySpec { } } } - if limit := dtq.limit; limit != nil { + if limit := dtq.ctx.Limit; limit != nil { _spec.Limit = *limit } - if offset := dtq.offset; offset != nil { + if offset := dtq.ctx.Offset; offset != nil { _spec.Offset = *offset } if ps := dtq.order; len(ps) > 0 { @@ -406,7 +406,7 @@ func (dtq *DeviceTokenQuery) querySpec() *sqlgraph.QuerySpec { func (dtq *DeviceTokenQuery) sqlQuery(ctx context.Context) *sql.Selector { builder := sql.Dialect(dtq.driver.Dialect()) t1 := builder.Table(devicetoken.Table) - columns := dtq.fields + columns := dtq.ctx.Fields if len(columns) == 0 { columns = devicetoken.Columns } @@ -415,7 +415,7 @@ func (dtq *DeviceTokenQuery) sqlQuery(ctx context.Context) *sql.Selector { selector = dtq.sql selector.Select(selector.Columns(columns...)...) } - if dtq.unique != nil && *dtq.unique { + if dtq.ctx.Unique != nil && *dtq.ctx.Unique { selector.Distinct() } for _, p := range dtq.predicates { @@ -424,12 +424,12 @@ func (dtq *DeviceTokenQuery) sqlQuery(ctx context.Context) *sql.Selector { for _, p := range dtq.order { p(selector) } - if offset := dtq.offset; offset != nil { + if offset := dtq.ctx.Offset; offset != nil { // limit is mandatory for offset clause. We start // with default value, and override it below if needed. selector.Offset(*offset).Limit(math.MaxInt32) } - if limit := dtq.limit; limit != nil { + if limit := dtq.ctx.Limit; limit != nil { selector.Limit(*limit) } return selector @@ -437,13 +437,8 @@ func (dtq *DeviceTokenQuery) sqlQuery(ctx context.Context) *sql.Selector { // DeviceTokenGroupBy is the group-by builder for DeviceToken entities. type DeviceTokenGroupBy struct { - config selector - fields []string - fns []AggregateFunc - // intermediate query (i.e. traversal path). - sql *sql.Selector - path func(context.Context) (*sql.Selector, error) + build *DeviceTokenQuery } // Aggregate adds the given aggregation functions to the group-by query. @@ -452,74 +447,77 @@ func (dtgb *DeviceTokenGroupBy) Aggregate(fns ...AggregateFunc) *DeviceTokenGrou return dtgb } -// Scan applies the group-by query and scans the result into the given value. -func (dtgb *DeviceTokenGroupBy) Scan(ctx context.Context, v interface{}) error { - query, err := dtgb.path(ctx) - if err != nil { +// Scan applies the selector query and scans the result into the given value. +func (dtgb *DeviceTokenGroupBy) Scan(ctx context.Context, v any) error { + ctx = setContextOp(ctx, dtgb.build.ctx, "GroupBy") + if err := dtgb.build.prepareQuery(ctx); err != nil { return err } - dtgb.sql = query - return dtgb.sqlScan(ctx, v) + return scanWithInterceptors[*DeviceTokenQuery, *DeviceTokenGroupBy](ctx, dtgb.build, dtgb, dtgb.build.inters, v) } -func (dtgb *DeviceTokenGroupBy) sqlScan(ctx context.Context, v interface{}) error { - for _, f := range dtgb.fields { - if !devicetoken.ValidColumn(f) { - return &ValidationError{Name: f, err: fmt.Errorf("invalid field %q for group-by", f)} - } - } - selector := dtgb.sqlQuery() - if err := selector.Err(); err != nil { - return err - } - rows := &sql.Rows{} - query, args := selector.Query() - if err := dtgb.driver.Query(ctx, query, args, rows); err != nil { - return err - } - defer rows.Close() - return sql.ScanSlice(rows, v) -} - -func (dtgb *DeviceTokenGroupBy) sqlQuery() *sql.Selector { - selector := dtgb.sql.Select() +func (dtgb *DeviceTokenGroupBy) sqlScan(ctx context.Context, root *DeviceTokenQuery, v any) error { + selector := root.sqlQuery(ctx).Select() aggregation := make([]string, 0, len(dtgb.fns)) for _, fn := range dtgb.fns { aggregation = append(aggregation, fn(selector)) } - // If no columns were selected in a custom aggregation function, the default - // selection is the fields used for "group-by", and the aggregation functions. if len(selector.SelectedColumns()) == 0 { - columns := make([]string, 0, len(dtgb.fields)+len(dtgb.fns)) - for _, f := range dtgb.fields { + columns := make([]string, 0, len(*dtgb.flds)+len(dtgb.fns)) + for _, f := range *dtgb.flds { columns = append(columns, selector.C(f)) } columns = append(columns, aggregation...) selector.Select(columns...) } - return selector.GroupBy(selector.Columns(dtgb.fields...)...) + selector.GroupBy(selector.Columns(*dtgb.flds...)...) + if err := selector.Err(); err != nil { + return err + } + rows := &sql.Rows{} + query, args := selector.Query() + if err := dtgb.build.driver.Query(ctx, query, args, rows); err != nil { + return err + } + defer rows.Close() + return sql.ScanSlice(rows, v) } // DeviceTokenSelect is the builder for selecting fields of DeviceToken entities. type DeviceTokenSelect struct { *DeviceTokenQuery selector - // intermediate query (i.e. traversal path). - sql *sql.Selector +} + +// Aggregate adds the given aggregation functions to the selector query. +func (dts *DeviceTokenSelect) Aggregate(fns ...AggregateFunc) *DeviceTokenSelect { + dts.fns = append(dts.fns, fns...) + return dts } // Scan applies the selector query and scans the result into the given value. -func (dts *DeviceTokenSelect) Scan(ctx context.Context, v interface{}) error { +func (dts *DeviceTokenSelect) Scan(ctx context.Context, v any) error { + ctx = setContextOp(ctx, dts.ctx, "Select") if err := dts.prepareQuery(ctx); err != nil { return err } - dts.sql = dts.DeviceTokenQuery.sqlQuery(ctx) - return dts.sqlScan(ctx, v) + return scanWithInterceptors[*DeviceTokenQuery, *DeviceTokenSelect](ctx, dts.DeviceTokenQuery, dts, dts.inters, v) } -func (dts *DeviceTokenSelect) sqlScan(ctx context.Context, v interface{}) error { +func (dts *DeviceTokenSelect) sqlScan(ctx context.Context, root *DeviceTokenQuery, v any) error { + selector := root.sqlQuery(ctx) + aggregation := make([]string, 0, len(dts.fns)) + for _, fn := range dts.fns { + aggregation = append(aggregation, fn(selector)) + } + switch n := len(*dts.selector.flds); { + case n == 0 && len(aggregation) > 0: + selector.Select(aggregation...) + case n != 0 && len(aggregation) > 0: + selector.AppendSelect(aggregation...) + } rows := &sql.Rows{} - query, args := dts.sql.Query() + query, args := selector.Query() if err := dts.driver.Query(ctx, query, args, rows); err != nil { return err } diff --git a/storage/ent/db/devicetoken_update.go b/storage/ent/db/devicetoken_update.go index cc0b92f5..1d37d53a 100644 --- a/storage/ent/db/devicetoken_update.go +++ b/storage/ent/db/devicetoken_update.go @@ -112,40 +112,7 @@ func (dtu *DeviceTokenUpdate) Mutation() *DeviceTokenMutation { // Save executes the query and returns the number of nodes affected by the update operation. func (dtu *DeviceTokenUpdate) Save(ctx context.Context) (int, error) { - var ( - err error - affected int - ) - if len(dtu.hooks) == 0 { - if err = dtu.check(); err != nil { - return 0, err - } - affected, err = dtu.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*DeviceTokenMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err = dtu.check(); err != nil { - return 0, err - } - dtu.mutation = mutation - affected, err = dtu.sqlSave(ctx) - mutation.done = true - return affected, err - }) - for i := len(dtu.hooks) - 1; i >= 0; i-- { - if dtu.hooks[i] == nil { - return 0, fmt.Errorf("db: uninitialized hook (forgotten import db/runtime?)") - } - mut = dtu.hooks[i](mut) - } - if _, err := mut.Mutate(ctx, dtu.mutation); err != nil { - return 0, err - } - } - return affected, err + return withHooks[int, DeviceTokenMutation](ctx, dtu.sqlSave, dtu.mutation, dtu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -186,16 +153,10 @@ func (dtu *DeviceTokenUpdate) check() error { } func (dtu *DeviceTokenUpdate) sqlSave(ctx context.Context) (n int, err error) { - _spec := &sqlgraph.UpdateSpec{ - Node: &sqlgraph.NodeSpec{ - Table: devicetoken.Table, - Columns: devicetoken.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeInt, - Column: devicetoken.FieldID, - }, - }, + if err := dtu.check(); err != nil { + return n, err } + _spec := sqlgraph.NewUpdateSpec(devicetoken.Table, devicetoken.Columns, sqlgraph.NewFieldSpec(devicetoken.FieldID, field.TypeInt)) if ps := dtu.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { @@ -204,73 +165,34 @@ func (dtu *DeviceTokenUpdate) sqlSave(ctx context.Context) (n int, err error) { } } if value, ok := dtu.mutation.DeviceCode(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: devicetoken.FieldDeviceCode, - }) + _spec.SetField(devicetoken.FieldDeviceCode, field.TypeString, value) } if value, ok := dtu.mutation.Status(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: devicetoken.FieldStatus, - }) + _spec.SetField(devicetoken.FieldStatus, field.TypeString, value) } if value, ok := dtu.mutation.Token(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeBytes, - Value: value, - Column: devicetoken.FieldToken, - }) + _spec.SetField(devicetoken.FieldToken, field.TypeBytes, value) } if dtu.mutation.TokenCleared() { - _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ - Type: field.TypeBytes, - Column: devicetoken.FieldToken, - }) + _spec.ClearField(devicetoken.FieldToken, field.TypeBytes) } if value, ok := dtu.mutation.Expiry(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeTime, - Value: value, - Column: devicetoken.FieldExpiry, - }) + _spec.SetField(devicetoken.FieldExpiry, field.TypeTime, value) } if value, ok := dtu.mutation.LastRequest(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeTime, - Value: value, - Column: devicetoken.FieldLastRequest, - }) + _spec.SetField(devicetoken.FieldLastRequest, field.TypeTime, value) } if value, ok := dtu.mutation.PollInterval(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeInt, - Value: value, - Column: devicetoken.FieldPollInterval, - }) + _spec.SetField(devicetoken.FieldPollInterval, field.TypeInt, value) } if value, ok := dtu.mutation.AddedPollInterval(); ok { - _spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{ - Type: field.TypeInt, - Value: value, - Column: devicetoken.FieldPollInterval, - }) + _spec.AddField(devicetoken.FieldPollInterval, field.TypeInt, value) } if value, ok := dtu.mutation.CodeChallenge(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: devicetoken.FieldCodeChallenge, - }) + _spec.SetField(devicetoken.FieldCodeChallenge, field.TypeString, value) } if value, ok := dtu.mutation.CodeChallengeMethod(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: devicetoken.FieldCodeChallengeMethod, - }) + _spec.SetField(devicetoken.FieldCodeChallengeMethod, field.TypeString, value) } if n, err = sqlgraph.UpdateNodes(ctx, dtu.driver, _spec); err != nil { if _, ok := err.(*sqlgraph.NotFoundError); ok { @@ -280,6 +202,7 @@ func (dtu *DeviceTokenUpdate) sqlSave(ctx context.Context) (n int, err error) { } return 0, err } + dtu.mutation.done = true return n, nil } @@ -373,6 +296,12 @@ func (dtuo *DeviceTokenUpdateOne) Mutation() *DeviceTokenMutation { return dtuo.mutation } +// Where appends a list predicates to the DeviceTokenUpdate builder. +func (dtuo *DeviceTokenUpdateOne) Where(ps ...predicate.DeviceToken) *DeviceTokenUpdateOne { + dtuo.mutation.Where(ps...) + return dtuo +} + // Select allows selecting one or more fields (columns) of the returned entity. // The default is selecting all fields defined in the entity schema. func (dtuo *DeviceTokenUpdateOne) Select(field string, fields ...string) *DeviceTokenUpdateOne { @@ -382,46 +311,7 @@ func (dtuo *DeviceTokenUpdateOne) Select(field string, fields ...string) *Device // Save executes the query and returns the updated DeviceToken entity. func (dtuo *DeviceTokenUpdateOne) Save(ctx context.Context) (*DeviceToken, error) { - var ( - err error - node *DeviceToken - ) - if len(dtuo.hooks) == 0 { - if err = dtuo.check(); err != nil { - return nil, err - } - node, err = dtuo.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*DeviceTokenMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err = dtuo.check(); err != nil { - return nil, err - } - dtuo.mutation = mutation - node, err = dtuo.sqlSave(ctx) - mutation.done = true - return node, err - }) - for i := len(dtuo.hooks) - 1; i >= 0; i-- { - if dtuo.hooks[i] == nil { - return nil, fmt.Errorf("db: uninitialized hook (forgotten import db/runtime?)") - } - mut = dtuo.hooks[i](mut) - } - v, err := mut.Mutate(ctx, dtuo.mutation) - if err != nil { - return nil, err - } - nv, ok := v.(*DeviceToken) - if !ok { - return nil, fmt.Errorf("unexpected node type %T returned from DeviceTokenMutation", v) - } - node = nv - } - return node, err + return withHooks[*DeviceToken, DeviceTokenMutation](ctx, dtuo.sqlSave, dtuo.mutation, dtuo.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -462,16 +352,10 @@ func (dtuo *DeviceTokenUpdateOne) check() error { } func (dtuo *DeviceTokenUpdateOne) sqlSave(ctx context.Context) (_node *DeviceToken, err error) { - _spec := &sqlgraph.UpdateSpec{ - Node: &sqlgraph.NodeSpec{ - Table: devicetoken.Table, - Columns: devicetoken.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeInt, - Column: devicetoken.FieldID, - }, - }, + if err := dtuo.check(); err != nil { + return _node, err } + _spec := sqlgraph.NewUpdateSpec(devicetoken.Table, devicetoken.Columns, sqlgraph.NewFieldSpec(devicetoken.FieldID, field.TypeInt)) id, ok := dtuo.mutation.ID() if !ok { return nil, &ValidationError{Name: "id", err: errors.New(`db: missing "DeviceToken.id" for update`)} @@ -497,73 +381,34 @@ func (dtuo *DeviceTokenUpdateOne) sqlSave(ctx context.Context) (_node *DeviceTok } } if value, ok := dtuo.mutation.DeviceCode(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: devicetoken.FieldDeviceCode, - }) + _spec.SetField(devicetoken.FieldDeviceCode, field.TypeString, value) } if value, ok := dtuo.mutation.Status(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: devicetoken.FieldStatus, - }) + _spec.SetField(devicetoken.FieldStatus, field.TypeString, value) } if value, ok := dtuo.mutation.Token(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeBytes, - Value: value, - Column: devicetoken.FieldToken, - }) + _spec.SetField(devicetoken.FieldToken, field.TypeBytes, value) } if dtuo.mutation.TokenCleared() { - _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ - Type: field.TypeBytes, - Column: devicetoken.FieldToken, - }) + _spec.ClearField(devicetoken.FieldToken, field.TypeBytes) } if value, ok := dtuo.mutation.Expiry(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeTime, - Value: value, - Column: devicetoken.FieldExpiry, - }) + _spec.SetField(devicetoken.FieldExpiry, field.TypeTime, value) } if value, ok := dtuo.mutation.LastRequest(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeTime, - Value: value, - Column: devicetoken.FieldLastRequest, - }) + _spec.SetField(devicetoken.FieldLastRequest, field.TypeTime, value) } if value, ok := dtuo.mutation.PollInterval(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeInt, - Value: value, - Column: devicetoken.FieldPollInterval, - }) + _spec.SetField(devicetoken.FieldPollInterval, field.TypeInt, value) } if value, ok := dtuo.mutation.AddedPollInterval(); ok { - _spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{ - Type: field.TypeInt, - Value: value, - Column: devicetoken.FieldPollInterval, - }) + _spec.AddField(devicetoken.FieldPollInterval, field.TypeInt, value) } if value, ok := dtuo.mutation.CodeChallenge(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: devicetoken.FieldCodeChallenge, - }) + _spec.SetField(devicetoken.FieldCodeChallenge, field.TypeString, value) } if value, ok := dtuo.mutation.CodeChallengeMethod(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: devicetoken.FieldCodeChallengeMethod, - }) + _spec.SetField(devicetoken.FieldCodeChallengeMethod, field.TypeString, value) } _node = &DeviceToken{config: dtuo.config} _spec.Assign = _node.assignValues @@ -576,5 +421,6 @@ func (dtuo *DeviceTokenUpdateOne) sqlSave(ctx context.Context) (_node *DeviceTok } return nil, err } + dtuo.mutation.done = true return _node, nil } diff --git a/storage/ent/db/ent.go b/storage/ent/db/ent.go index ed76b32b..128c464b 100644 --- a/storage/ent/db/ent.go +++ b/storage/ent/db/ent.go @@ -6,6 +6,7 @@ import ( "context" "errors" "fmt" + "reflect" "entgo.io/ent" "entgo.io/ent/dialect/sql" @@ -24,14 +25,21 @@ import ( // ent aliases to avoid import conflicts in user's code. type ( - Op = ent.Op - Hook = ent.Hook - Value = ent.Value - Query = ent.Query - Policy = ent.Policy - Mutator = ent.Mutator - Mutation = ent.Mutation - MutateFunc = ent.MutateFunc + Op = ent.Op + Hook = ent.Hook + Value = ent.Value + Query = ent.Query + QueryContext = ent.QueryContext + Querier = ent.Querier + QuerierFunc = ent.QuerierFunc + Interceptor = ent.Interceptor + InterceptFunc = ent.InterceptFunc + Traverser = ent.Traverser + TraverseFunc = ent.TraverseFunc + Policy = ent.Policy + Mutator = ent.Mutator + Mutation = ent.Mutation + MutateFunc = ent.MutateFunc ) // OrderFunc applies an ordering on the sql selector. @@ -99,7 +107,6 @@ type AggregateFunc func(*sql.Selector) string // GroupBy(field1, field2). // Aggregate(db.As(db.Sum(field1), "sum_field1"), (db.As(db.Sum(field2), "sum_field2")). // Scan(ctx, &v) -// func As(fn AggregateFunc, end string) AggregateFunc { return func(s *sql.Selector) string { return sql.As(fn(s), end) @@ -282,11 +289,12 @@ func IsConstraintError(err error) bool { type selector struct { label string flds *[]string - scan func(context.Context, interface{}) error + fns []AggregateFunc + scan func(context.Context, any) error } // ScanX is like Scan, but panics if an error occurs. -func (s *selector) ScanX(ctx context.Context, v interface{}) { +func (s *selector) ScanX(ctx context.Context, v any) { if err := s.scan(ctx, v); err != nil { panic(err) } @@ -480,5 +488,121 @@ func (s *selector) BoolX(ctx context.Context) bool { return v } +// withHooks invokes the builder operation with the given hooks, if any. +func withHooks[V Value, M any, PM interface { + *M + Mutation +}](ctx context.Context, exec func(context.Context) (V, error), mutation PM, hooks []Hook) (value V, err error) { + if len(hooks) == 0 { + return exec(ctx) + } + var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { + mutationT, ok := m.(PM) + if !ok { + return nil, fmt.Errorf("unexpected mutation type %T", m) + } + // Set the mutation to the builder. + *mutation = *mutationT + return exec(ctx) + }) + for i := len(hooks) - 1; i >= 0; i-- { + if hooks[i] == nil { + return value, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") + } + mut = hooks[i](mut) + } + v, err := mut.Mutate(ctx, mutation) + if err != nil { + return value, err + } + nv, ok := v.(V) + if !ok { + return value, fmt.Errorf("unexpected node type %T returned from %T", v, mutation) + } + return nv, nil +} + +// setContextOp returns a new context with the given QueryContext attached (including its op) in case it does not exist. +func setContextOp(ctx context.Context, qc *QueryContext, op string) context.Context { + if ent.QueryFromContext(ctx) == nil { + qc.Op = op + ctx = ent.NewQueryContext(ctx, qc) + } + return ctx +} + +func querierAll[V Value, Q interface { + sqlAll(context.Context, ...queryHook) (V, error) +}]() Querier { + return QuerierFunc(func(ctx context.Context, q Query) (Value, error) { + query, ok := q.(Q) + if !ok { + return nil, fmt.Errorf("unexpected query type %T", q) + } + return query.sqlAll(ctx) + }) +} + +func querierCount[Q interface { + sqlCount(context.Context) (int, error) +}]() Querier { + return QuerierFunc(func(ctx context.Context, q Query) (Value, error) { + query, ok := q.(Q) + if !ok { + return nil, fmt.Errorf("unexpected query type %T", q) + } + return query.sqlCount(ctx) + }) +} + +func withInterceptors[V Value](ctx context.Context, q Query, qr Querier, inters []Interceptor) (v V, err error) { + for i := len(inters) - 1; i >= 0; i-- { + qr = inters[i].Intercept(qr) + } + rv, err := qr.Query(ctx, q) + if err != nil { + return v, err + } + vt, ok := rv.(V) + if !ok { + return v, fmt.Errorf("unexpected type %T returned from %T. expected type: %T", vt, q, v) + } + return vt, nil +} + +func scanWithInterceptors[Q1 ent.Query, Q2 interface { + sqlScan(context.Context, Q1, any) error +}](ctx context.Context, rootQuery Q1, selectOrGroup Q2, inters []Interceptor, v any) error { + rv := reflect.ValueOf(v) + var qr Querier = QuerierFunc(func(ctx context.Context, q Query) (Value, error) { + query, ok := q.(Q1) + if !ok { + return nil, fmt.Errorf("unexpected query type %T", q) + } + if err := selectOrGroup.sqlScan(ctx, query, v); err != nil { + return nil, err + } + if k := rv.Kind(); k == reflect.Pointer && rv.Elem().CanInterface() { + return rv.Elem().Interface(), nil + } + return v, nil + }) + for i := len(inters) - 1; i >= 0; i-- { + qr = inters[i].Intercept(qr) + } + vv, err := qr.Query(ctx, rootQuery) + if err != nil { + return err + } + switch rv2 := reflect.ValueOf(vv); { + case rv.IsNil(), rv2.IsNil(), rv.Kind() != reflect.Pointer: + case rv.Type() == rv2.Type(): + rv.Elem().Set(rv2.Elem()) + case rv.Elem().Type() == rv2.Type(): + rv.Elem().Set(rv2) + } + return nil +} + // queryHook describes an internal hook for the different sqlAll methods. type queryHook func(context.Context, *sqlgraph.QuerySpec) diff --git a/storage/ent/db/enttest/enttest.go b/storage/ent/db/enttest/enttest.go index ecbb02d9..65702d99 100644 --- a/storage/ent/db/enttest/enttest.go +++ b/storage/ent/db/enttest/enttest.go @@ -18,7 +18,7 @@ type ( // testing.T and testing.B and used by enttest. TestingT interface { FailNow() - Error(...interface{}) + Error(...any) } // Option configures client creation. diff --git a/storage/ent/db/hook/hook.go b/storage/ent/db/hook/hook.go index 856e5e59..12cb91c6 100644 --- a/storage/ent/db/hook/hook.go +++ b/storage/ent/db/hook/hook.go @@ -15,11 +15,10 @@ type AuthCodeFunc func(context.Context, *db.AuthCodeMutation) (db.Value, error) // Mutate calls f(ctx, m). func (f AuthCodeFunc) Mutate(ctx context.Context, m db.Mutation) (db.Value, error) { - mv, ok := m.(*db.AuthCodeMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T. expect *db.AuthCodeMutation", m) + if mv, ok := m.(*db.AuthCodeMutation); ok { + return f(ctx, mv) } - return f(ctx, mv) + return nil, fmt.Errorf("unexpected mutation type %T. expect *db.AuthCodeMutation", m) } // The AuthRequestFunc type is an adapter to allow the use of ordinary @@ -28,11 +27,10 @@ type AuthRequestFunc func(context.Context, *db.AuthRequestMutation) (db.Value, e // Mutate calls f(ctx, m). func (f AuthRequestFunc) Mutate(ctx context.Context, m db.Mutation) (db.Value, error) { - mv, ok := m.(*db.AuthRequestMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T. expect *db.AuthRequestMutation", m) + if mv, ok := m.(*db.AuthRequestMutation); ok { + return f(ctx, mv) } - return f(ctx, mv) + return nil, fmt.Errorf("unexpected mutation type %T. expect *db.AuthRequestMutation", m) } // The ConnectorFunc type is an adapter to allow the use of ordinary @@ -41,11 +39,10 @@ type ConnectorFunc func(context.Context, *db.ConnectorMutation) (db.Value, error // Mutate calls f(ctx, m). func (f ConnectorFunc) Mutate(ctx context.Context, m db.Mutation) (db.Value, error) { - mv, ok := m.(*db.ConnectorMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T. expect *db.ConnectorMutation", m) + if mv, ok := m.(*db.ConnectorMutation); ok { + return f(ctx, mv) } - return f(ctx, mv) + return nil, fmt.Errorf("unexpected mutation type %T. expect *db.ConnectorMutation", m) } // The DeviceRequestFunc type is an adapter to allow the use of ordinary @@ -54,11 +51,10 @@ type DeviceRequestFunc func(context.Context, *db.DeviceRequestMutation) (db.Valu // Mutate calls f(ctx, m). func (f DeviceRequestFunc) Mutate(ctx context.Context, m db.Mutation) (db.Value, error) { - mv, ok := m.(*db.DeviceRequestMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T. expect *db.DeviceRequestMutation", m) + if mv, ok := m.(*db.DeviceRequestMutation); ok { + return f(ctx, mv) } - return f(ctx, mv) + return nil, fmt.Errorf("unexpected mutation type %T. expect *db.DeviceRequestMutation", m) } // The DeviceTokenFunc type is an adapter to allow the use of ordinary @@ -67,11 +63,10 @@ type DeviceTokenFunc func(context.Context, *db.DeviceTokenMutation) (db.Value, e // Mutate calls f(ctx, m). func (f DeviceTokenFunc) Mutate(ctx context.Context, m db.Mutation) (db.Value, error) { - mv, ok := m.(*db.DeviceTokenMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T. expect *db.DeviceTokenMutation", m) + if mv, ok := m.(*db.DeviceTokenMutation); ok { + return f(ctx, mv) } - return f(ctx, mv) + return nil, fmt.Errorf("unexpected mutation type %T. expect *db.DeviceTokenMutation", m) } // The KeysFunc type is an adapter to allow the use of ordinary @@ -80,11 +75,10 @@ type KeysFunc func(context.Context, *db.KeysMutation) (db.Value, error) // Mutate calls f(ctx, m). func (f KeysFunc) Mutate(ctx context.Context, m db.Mutation) (db.Value, error) { - mv, ok := m.(*db.KeysMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T. expect *db.KeysMutation", m) + if mv, ok := m.(*db.KeysMutation); ok { + return f(ctx, mv) } - return f(ctx, mv) + return nil, fmt.Errorf("unexpected mutation type %T. expect *db.KeysMutation", m) } // The OAuth2ClientFunc type is an adapter to allow the use of ordinary @@ -93,11 +87,10 @@ type OAuth2ClientFunc func(context.Context, *db.OAuth2ClientMutation) (db.Value, // Mutate calls f(ctx, m). func (f OAuth2ClientFunc) Mutate(ctx context.Context, m db.Mutation) (db.Value, error) { - mv, ok := m.(*db.OAuth2ClientMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T. expect *db.OAuth2ClientMutation", m) + if mv, ok := m.(*db.OAuth2ClientMutation); ok { + return f(ctx, mv) } - return f(ctx, mv) + return nil, fmt.Errorf("unexpected mutation type %T. expect *db.OAuth2ClientMutation", m) } // The OfflineSessionFunc type is an adapter to allow the use of ordinary @@ -106,11 +99,10 @@ type OfflineSessionFunc func(context.Context, *db.OfflineSessionMutation) (db.Va // Mutate calls f(ctx, m). func (f OfflineSessionFunc) Mutate(ctx context.Context, m db.Mutation) (db.Value, error) { - mv, ok := m.(*db.OfflineSessionMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T. expect *db.OfflineSessionMutation", m) + if mv, ok := m.(*db.OfflineSessionMutation); ok { + return f(ctx, mv) } - return f(ctx, mv) + return nil, fmt.Errorf("unexpected mutation type %T. expect *db.OfflineSessionMutation", m) } // The PasswordFunc type is an adapter to allow the use of ordinary @@ -119,11 +111,10 @@ type PasswordFunc func(context.Context, *db.PasswordMutation) (db.Value, error) // Mutate calls f(ctx, m). func (f PasswordFunc) Mutate(ctx context.Context, m db.Mutation) (db.Value, error) { - mv, ok := m.(*db.PasswordMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T. expect *db.PasswordMutation", m) + if mv, ok := m.(*db.PasswordMutation); ok { + return f(ctx, mv) } - return f(ctx, mv) + return nil, fmt.Errorf("unexpected mutation type %T. expect *db.PasswordMutation", m) } // The RefreshTokenFunc type is an adapter to allow the use of ordinary @@ -132,11 +123,10 @@ type RefreshTokenFunc func(context.Context, *db.RefreshTokenMutation) (db.Value, // Mutate calls f(ctx, m). func (f RefreshTokenFunc) Mutate(ctx context.Context, m db.Mutation) (db.Value, error) { - mv, ok := m.(*db.RefreshTokenMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T. expect *db.RefreshTokenMutation", m) + if mv, ok := m.(*db.RefreshTokenMutation); ok { + return f(ctx, mv) } - return f(ctx, mv) + return nil, fmt.Errorf("unexpected mutation type %T. expect *db.RefreshTokenMutation", m) } // Condition is a hook condition function. @@ -234,7 +224,6 @@ func HasFields(field string, fields ...string) Condition { // If executes the given hook under condition. // // hook.If(ComputeAverage, And(HasFields(...), HasAddedFields(...))) -// func If(hk db.Hook, cond Condition) db.Hook { return func(next db.Mutator) db.Mutator { return db.MutateFunc(func(ctx context.Context, m db.Mutation) (db.Value, error) { @@ -249,7 +238,6 @@ func If(hk db.Hook, cond Condition) db.Hook { // On executes the given hook only for the given operation. // // hook.On(Log, db.Delete|db.Create) -// func On(hk db.Hook, op db.Op) db.Hook { return If(hk, HasOp(op)) } @@ -257,7 +245,6 @@ func On(hk db.Hook, op db.Op) db.Hook { // Unless skips the given hook only for the given operation. // // hook.Unless(Log, db.Update|db.UpdateOne) -// func Unless(hk db.Hook, op db.Op) db.Hook { return If(hk, Not(HasOp(op))) } @@ -278,7 +265,6 @@ func FixedError(err error) db.Hook { // Reject(db.Delete|db.Update), // } // } -// func Reject(op db.Op) db.Hook { hk := FixedError(fmt.Errorf("%s operation is not allowed", op)) return On(hk, op) diff --git a/storage/ent/db/keys.go b/storage/ent/db/keys.go index d307ad8e..a297f28e 100644 --- a/storage/ent/db/keys.go +++ b/storage/ent/db/keys.go @@ -30,8 +30,8 @@ type Keys struct { } // scanValues returns the types for scanning values from sql.Rows. -func (*Keys) scanValues(columns []string) ([]interface{}, error) { - values := make([]interface{}, len(columns)) +func (*Keys) scanValues(columns []string) ([]any, error) { + values := make([]any, len(columns)) for i := range columns { switch columns[i] { case keys.FieldVerificationKeys, keys.FieldSigningKey, keys.FieldSigningKeyPub: @@ -49,7 +49,7 @@ func (*Keys) scanValues(columns []string) ([]interface{}, error) { // assignValues assigns the values that were returned from sql.Rows (after scanning) // to the Keys fields. -func (k *Keys) assignValues(columns []string, values []interface{}) error { +func (k *Keys) assignValues(columns []string, values []any) error { if m, n := len(values), len(columns); m < n { return fmt.Errorf("mismatch number of scan values: %d != %d", m, n) } @@ -100,7 +100,7 @@ func (k *Keys) assignValues(columns []string, values []interface{}) error { // Note that you need to call Keys.Unwrap() before calling this method if this Keys // was returned from a transaction, and the transaction was committed or rolled back. func (k *Keys) Update() *KeysUpdateOne { - return (&KeysClient{config: k.config}).UpdateOne(k) + return NewKeysClient(k.config).UpdateOne(k) } // Unwrap unwraps the Keys entity that was returned from a transaction after it was closed, @@ -136,9 +136,3 @@ func (k *Keys) String() string { // KeysSlice is a parsable slice of Keys. type KeysSlice []*Keys - -func (k KeysSlice) config(cfg config) { - for _i := range k { - k[_i].config = cfg - } -} diff --git a/storage/ent/db/keys/where.go b/storage/ent/db/keys/where.go index f918579d..b10a431b 100644 --- a/storage/ent/db/keys/where.go +++ b/storage/ent/db/keys/where.go @@ -11,144 +11,92 @@ import ( // ID filters vertices based on their ID field. func ID(id string) predicate.Keys { - return predicate.Keys(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldID), id)) - }) + return predicate.Keys(sql.FieldEQ(FieldID, id)) } // IDEQ applies the EQ predicate on the ID field. func IDEQ(id string) predicate.Keys { - return predicate.Keys(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldID), id)) - }) + return predicate.Keys(sql.FieldEQ(FieldID, id)) } // IDNEQ applies the NEQ predicate on the ID field. func IDNEQ(id string) predicate.Keys { - return predicate.Keys(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldID), id)) - }) + return predicate.Keys(sql.FieldNEQ(FieldID, id)) } // IDIn applies the In predicate on the ID field. func IDIn(ids ...string) predicate.Keys { - return predicate.Keys(func(s *sql.Selector) { - v := make([]interface{}, len(ids)) - for i := range v { - v[i] = ids[i] - } - s.Where(sql.In(s.C(FieldID), v...)) - }) + return predicate.Keys(sql.FieldIn(FieldID, ids...)) } // IDNotIn applies the NotIn predicate on the ID field. func IDNotIn(ids ...string) predicate.Keys { - return predicate.Keys(func(s *sql.Selector) { - v := make([]interface{}, len(ids)) - for i := range v { - v[i] = ids[i] - } - s.Where(sql.NotIn(s.C(FieldID), v...)) - }) + return predicate.Keys(sql.FieldNotIn(FieldID, ids...)) } // IDGT applies the GT predicate on the ID field. func IDGT(id string) predicate.Keys { - return predicate.Keys(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldID), id)) - }) + return predicate.Keys(sql.FieldGT(FieldID, id)) } // IDGTE applies the GTE predicate on the ID field. func IDGTE(id string) predicate.Keys { - return predicate.Keys(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldID), id)) - }) + return predicate.Keys(sql.FieldGTE(FieldID, id)) } // IDLT applies the LT predicate on the ID field. func IDLT(id string) predicate.Keys { - return predicate.Keys(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldID), id)) - }) + return predicate.Keys(sql.FieldLT(FieldID, id)) } // IDLTE applies the LTE predicate on the ID field. func IDLTE(id string) predicate.Keys { - return predicate.Keys(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldID), id)) - }) + return predicate.Keys(sql.FieldLTE(FieldID, id)) } // NextRotation applies equality check predicate on the "next_rotation" field. It's identical to NextRotationEQ. func NextRotation(v time.Time) predicate.Keys { - return predicate.Keys(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldNextRotation), v)) - }) + return predicate.Keys(sql.FieldEQ(FieldNextRotation, v)) } // NextRotationEQ applies the EQ predicate on the "next_rotation" field. func NextRotationEQ(v time.Time) predicate.Keys { - return predicate.Keys(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldNextRotation), v)) - }) + return predicate.Keys(sql.FieldEQ(FieldNextRotation, v)) } // NextRotationNEQ applies the NEQ predicate on the "next_rotation" field. func NextRotationNEQ(v time.Time) predicate.Keys { - return predicate.Keys(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldNextRotation), v)) - }) + return predicate.Keys(sql.FieldNEQ(FieldNextRotation, v)) } // NextRotationIn applies the In predicate on the "next_rotation" field. func NextRotationIn(vs ...time.Time) predicate.Keys { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Keys(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldNextRotation), v...)) - }) + return predicate.Keys(sql.FieldIn(FieldNextRotation, vs...)) } // NextRotationNotIn applies the NotIn predicate on the "next_rotation" field. func NextRotationNotIn(vs ...time.Time) predicate.Keys { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Keys(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldNextRotation), v...)) - }) + return predicate.Keys(sql.FieldNotIn(FieldNextRotation, vs...)) } // NextRotationGT applies the GT predicate on the "next_rotation" field. func NextRotationGT(v time.Time) predicate.Keys { - return predicate.Keys(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldNextRotation), v)) - }) + return predicate.Keys(sql.FieldGT(FieldNextRotation, v)) } // NextRotationGTE applies the GTE predicate on the "next_rotation" field. func NextRotationGTE(v time.Time) predicate.Keys { - return predicate.Keys(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldNextRotation), v)) - }) + return predicate.Keys(sql.FieldGTE(FieldNextRotation, v)) } // NextRotationLT applies the LT predicate on the "next_rotation" field. func NextRotationLT(v time.Time) predicate.Keys { - return predicate.Keys(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldNextRotation), v)) - }) + return predicate.Keys(sql.FieldLT(FieldNextRotation, v)) } // NextRotationLTE applies the LTE predicate on the "next_rotation" field. func NextRotationLTE(v time.Time) predicate.Keys { - return predicate.Keys(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldNextRotation), v)) - }) + return predicate.Keys(sql.FieldLTE(FieldNextRotation, v)) } // And groups predicates with the AND operator between them. diff --git a/storage/ent/db/keys_create.go b/storage/ent/db/keys_create.go index 818ca278..4740c5cb 100644 --- a/storage/ent/db/keys_create.go +++ b/storage/ent/db/keys_create.go @@ -59,49 +59,7 @@ func (kc *KeysCreate) Mutation() *KeysMutation { // Save creates the Keys in the database. func (kc *KeysCreate) Save(ctx context.Context) (*Keys, error) { - var ( - err error - node *Keys - ) - if len(kc.hooks) == 0 { - if err = kc.check(); err != nil { - return nil, err - } - node, err = kc.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*KeysMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err = kc.check(); err != nil { - return nil, err - } - kc.mutation = mutation - if node, err = kc.sqlSave(ctx); err != nil { - return nil, err - } - mutation.id = &node.ID - mutation.done = true - return node, err - }) - for i := len(kc.hooks) - 1; i >= 0; i-- { - if kc.hooks[i] == nil { - return nil, fmt.Errorf("db: uninitialized hook (forgotten import db/runtime?)") - } - mut = kc.hooks[i](mut) - } - v, err := mut.Mutate(ctx, kc.mutation) - if err != nil { - return nil, err - } - nv, ok := v.(*Keys) - if !ok { - return nil, fmt.Errorf("unexpected node type %T returned from KeysMutation", v) - } - node = nv - } - return node, err + return withHooks[*Keys, KeysMutation](ctx, kc.sqlSave, kc.mutation, kc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -149,6 +107,9 @@ func (kc *KeysCreate) check() error { } func (kc *KeysCreate) sqlSave(ctx context.Context) (*Keys, error) { + if err := kc.check(); err != nil { + return nil, err + } _node, _spec := kc.createSpec() if err := sqlgraph.CreateNode(ctx, kc.driver, _spec); err != nil { if sqlgraph.IsConstraintError(err) { @@ -163,54 +124,34 @@ func (kc *KeysCreate) sqlSave(ctx context.Context) (*Keys, error) { return nil, fmt.Errorf("unexpected Keys.ID type: %T", _spec.ID.Value) } } + kc.mutation.id = &_node.ID + kc.mutation.done = true return _node, nil } func (kc *KeysCreate) createSpec() (*Keys, *sqlgraph.CreateSpec) { var ( _node = &Keys{config: kc.config} - _spec = &sqlgraph.CreateSpec{ - Table: keys.Table, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeString, - Column: keys.FieldID, - }, - } + _spec = sqlgraph.NewCreateSpec(keys.Table, sqlgraph.NewFieldSpec(keys.FieldID, field.TypeString)) ) if id, ok := kc.mutation.ID(); ok { _node.ID = id _spec.ID.Value = id } if value, ok := kc.mutation.VerificationKeys(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeJSON, - Value: value, - Column: keys.FieldVerificationKeys, - }) + _spec.SetField(keys.FieldVerificationKeys, field.TypeJSON, value) _node.VerificationKeys = value } if value, ok := kc.mutation.SigningKey(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeJSON, - Value: value, - Column: keys.FieldSigningKey, - }) + _spec.SetField(keys.FieldSigningKey, field.TypeJSON, value) _node.SigningKey = value } if value, ok := kc.mutation.SigningKeyPub(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeJSON, - Value: value, - Column: keys.FieldSigningKeyPub, - }) + _spec.SetField(keys.FieldSigningKeyPub, field.TypeJSON, value) _node.SigningKeyPub = value } if value, ok := kc.mutation.NextRotation(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeTime, - Value: value, - Column: keys.FieldNextRotation, - }) + _spec.SetField(keys.FieldNextRotation, field.TypeTime, value) _node.NextRotation = value } return _node, _spec diff --git a/storage/ent/db/keys_delete.go b/storage/ent/db/keys_delete.go index 5bcf970f..b7a41f28 100644 --- a/storage/ent/db/keys_delete.go +++ b/storage/ent/db/keys_delete.go @@ -4,7 +4,6 @@ package db import ( "context" - "fmt" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" @@ -28,34 +27,7 @@ func (kd *KeysDelete) Where(ps ...predicate.Keys) *KeysDelete { // Exec executes the deletion query and returns how many vertices were deleted. func (kd *KeysDelete) Exec(ctx context.Context) (int, error) { - var ( - err error - affected int - ) - if len(kd.hooks) == 0 { - affected, err = kd.sqlExec(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*KeysMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - kd.mutation = mutation - affected, err = kd.sqlExec(ctx) - mutation.done = true - return affected, err - }) - for i := len(kd.hooks) - 1; i >= 0; i-- { - if kd.hooks[i] == nil { - return 0, fmt.Errorf("db: uninitialized hook (forgotten import db/runtime?)") - } - mut = kd.hooks[i](mut) - } - if _, err := mut.Mutate(ctx, kd.mutation); err != nil { - return 0, err - } - } - return affected, err + return withHooks[int, KeysMutation](ctx, kd.sqlExec, kd.mutation, kd.hooks) } // ExecX is like Exec, but panics if an error occurs. @@ -68,15 +40,7 @@ func (kd *KeysDelete) ExecX(ctx context.Context) int { } func (kd *KeysDelete) sqlExec(ctx context.Context) (int, error) { - _spec := &sqlgraph.DeleteSpec{ - Node: &sqlgraph.NodeSpec{ - Table: keys.Table, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeString, - Column: keys.FieldID, - }, - }, - } + _spec := sqlgraph.NewDeleteSpec(keys.Table, sqlgraph.NewFieldSpec(keys.FieldID, field.TypeString)) if ps := kd.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { @@ -88,6 +52,7 @@ func (kd *KeysDelete) sqlExec(ctx context.Context) (int, error) { if err != nil && sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } + kd.mutation.done = true return affected, err } @@ -96,6 +61,12 @@ type KeysDeleteOne struct { kd *KeysDelete } +// Where appends a list predicates to the KeysDelete builder. +func (kdo *KeysDeleteOne) Where(ps ...predicate.Keys) *KeysDeleteOne { + kdo.kd.mutation.Where(ps...) + return kdo +} + // Exec executes the deletion query. func (kdo *KeysDeleteOne) Exec(ctx context.Context) error { n, err := kdo.kd.Exec(ctx) @@ -111,5 +82,7 @@ func (kdo *KeysDeleteOne) Exec(ctx context.Context) error { // ExecX is like Exec, but panics if an error occurs. func (kdo *KeysDeleteOne) ExecX(ctx context.Context) { - kdo.kd.ExecX(ctx) + if err := kdo.Exec(ctx); err != nil { + panic(err) + } } diff --git a/storage/ent/db/keys_query.go b/storage/ent/db/keys_query.go index 7d9ea908..6b879652 100644 --- a/storage/ent/db/keys_query.go +++ b/storage/ent/db/keys_query.go @@ -17,11 +17,9 @@ import ( // KeysQuery is the builder for querying Keys entities. type KeysQuery struct { config - limit *int - offset *int - unique *bool + ctx *QueryContext order []OrderFunc - fields []string + inters []Interceptor predicates []predicate.Keys // intermediate query (i.e. traversal path). sql *sql.Selector @@ -34,26 +32,26 @@ func (kq *KeysQuery) Where(ps ...predicate.Keys) *KeysQuery { return kq } -// Limit adds a limit step to the query. +// Limit the number of records to be returned by this query. func (kq *KeysQuery) Limit(limit int) *KeysQuery { - kq.limit = &limit + kq.ctx.Limit = &limit return kq } -// Offset adds an offset step to the query. +// Offset to start from. func (kq *KeysQuery) Offset(offset int) *KeysQuery { - kq.offset = &offset + kq.ctx.Offset = &offset return kq } // Unique configures the query builder to filter duplicate records on query. // By default, unique is set to true, and can be disabled using this method. func (kq *KeysQuery) Unique(unique bool) *KeysQuery { - kq.unique = &unique + kq.ctx.Unique = &unique return kq } -// Order adds an order step to the query. +// Order specifies how the records should be ordered. func (kq *KeysQuery) Order(o ...OrderFunc) *KeysQuery { kq.order = append(kq.order, o...) return kq @@ -62,7 +60,7 @@ func (kq *KeysQuery) Order(o ...OrderFunc) *KeysQuery { // First returns the first Keys entity from the query. // Returns a *NotFoundError when no Keys was found. func (kq *KeysQuery) First(ctx context.Context) (*Keys, error) { - nodes, err := kq.Limit(1).All(ctx) + nodes, err := kq.Limit(1).All(setContextOp(ctx, kq.ctx, "First")) if err != nil { return nil, err } @@ -85,7 +83,7 @@ func (kq *KeysQuery) FirstX(ctx context.Context) *Keys { // Returns a *NotFoundError when no Keys ID was found. func (kq *KeysQuery) FirstID(ctx context.Context) (id string, err error) { var ids []string - if ids, err = kq.Limit(1).IDs(ctx); err != nil { + if ids, err = kq.Limit(1).IDs(setContextOp(ctx, kq.ctx, "FirstID")); err != nil { return } if len(ids) == 0 { @@ -108,7 +106,7 @@ func (kq *KeysQuery) FirstIDX(ctx context.Context) string { // 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) + nodes, err := kq.Limit(2).All(setContextOp(ctx, kq.ctx, "Only")) if err != nil { return nil, err } @@ -136,7 +134,7 @@ func (kq *KeysQuery) OnlyX(ctx context.Context) *Keys { // Returns a *NotFoundError when no entities are found. func (kq *KeysQuery) OnlyID(ctx context.Context) (id string, err error) { var ids []string - if ids, err = kq.Limit(2).IDs(ctx); err != nil { + if ids, err = kq.Limit(2).IDs(setContextOp(ctx, kq.ctx, "OnlyID")); err != nil { return } switch len(ids) { @@ -161,10 +159,12 @@ func (kq *KeysQuery) OnlyIDX(ctx context.Context) string { // All executes the query and returns a list of KeysSlice. func (kq *KeysQuery) All(ctx context.Context) ([]*Keys, error) { + ctx = setContextOp(ctx, kq.ctx, "All") if err := kq.prepareQuery(ctx); err != nil { return nil, err } - return kq.sqlAll(ctx) + qr := querierAll[[]*Keys, *KeysQuery]() + return withInterceptors[[]*Keys](ctx, kq, qr, kq.inters) } // AllX is like All, but panics if an error occurs. @@ -177,9 +177,12 @@ func (kq *KeysQuery) AllX(ctx context.Context) []*Keys { } // IDs executes the query and returns a list of Keys IDs. -func (kq *KeysQuery) IDs(ctx context.Context) ([]string, error) { - var ids []string - if err := kq.Select(keys.FieldID).Scan(ctx, &ids); err != nil { +func (kq *KeysQuery) IDs(ctx context.Context) (ids []string, err error) { + if kq.ctx.Unique == nil && kq.path != nil { + kq.Unique(true) + } + ctx = setContextOp(ctx, kq.ctx, "IDs") + if err = kq.Select(keys.FieldID).Scan(ctx, &ids); err != nil { return nil, err } return ids, nil @@ -196,10 +199,11 @@ func (kq *KeysQuery) IDsX(ctx context.Context) []string { // Count returns the count of the given query. func (kq *KeysQuery) Count(ctx context.Context) (int, error) { + ctx = setContextOp(ctx, kq.ctx, "Count") if err := kq.prepareQuery(ctx); err != nil { return 0, err } - return kq.sqlCount(ctx) + return withInterceptors[int](ctx, kq, querierCount[*KeysQuery](), kq.inters) } // CountX is like Count, but panics if an error occurs. @@ -213,10 +217,15 @@ func (kq *KeysQuery) CountX(ctx context.Context) int { // Exist returns true if the query has elements in the graph. func (kq *KeysQuery) Exist(ctx context.Context) (bool, error) { - if err := kq.prepareQuery(ctx); err != nil { - return false, err + ctx = setContextOp(ctx, kq.ctx, "Exist") + switch _, err := kq.FirstID(ctx); { + case IsNotFound(err): + return false, nil + case err != nil: + return false, fmt.Errorf("db: check existence: %w", err) + default: + return true, nil } - return kq.sqlExist(ctx) } // ExistX is like Exist, but panics if an error occurs. @@ -236,14 +245,13 @@ func (kq *KeysQuery) Clone() *KeysQuery { } return &KeysQuery{ config: kq.config, - limit: kq.limit, - offset: kq.offset, + ctx: kq.ctx.Clone(), order: append([]OrderFunc{}, kq.order...), + inters: append([]Interceptor{}, kq.inters...), predicates: append([]predicate.Keys{}, kq.predicates...), // clone intermediate query. - sql: kq.sql.Clone(), - path: kq.path, - unique: kq.unique, + sql: kq.sql.Clone(), + path: kq.path, } } @@ -261,18 +269,12 @@ func (kq *KeysQuery) Clone() *KeysQuery { // GroupBy(keys.FieldVerificationKeys). // Aggregate(db.Count()). // Scan(ctx, &v) -// func (kq *KeysQuery) GroupBy(field string, fields ...string) *KeysGroupBy { - grbuild := &KeysGroupBy{config: kq.config} - grbuild.fields = append([]string{field}, fields...) - grbuild.path = func(ctx context.Context) (prev *sql.Selector, err error) { - if err := kq.prepareQuery(ctx); err != nil { - return nil, err - } - return kq.sqlQuery(ctx), nil - } + kq.ctx.Fields = append([]string{field}, fields...) + grbuild := &KeysGroupBy{build: kq} + grbuild.flds = &kq.ctx.Fields grbuild.label = keys.Label - grbuild.flds, grbuild.scan = &grbuild.fields, grbuild.Scan + grbuild.scan = grbuild.Scan return grbuild } @@ -288,17 +290,31 @@ func (kq *KeysQuery) GroupBy(field string, fields ...string) *KeysGroupBy { // client.Keys.Query(). // Select(keys.FieldVerificationKeys). // Scan(ctx, &v) -// func (kq *KeysQuery) Select(fields ...string) *KeysSelect { - kq.fields = append(kq.fields, fields...) - selbuild := &KeysSelect{KeysQuery: kq} - selbuild.label = keys.Label - selbuild.flds, selbuild.scan = &kq.fields, selbuild.Scan - return selbuild + kq.ctx.Fields = append(kq.ctx.Fields, fields...) + sbuild := &KeysSelect{KeysQuery: kq} + sbuild.label = keys.Label + sbuild.flds, sbuild.scan = &kq.ctx.Fields, sbuild.Scan + return sbuild +} + +// Aggregate returns a KeysSelect configured with the given aggregations. +func (kq *KeysQuery) Aggregate(fns ...AggregateFunc) *KeysSelect { + return kq.Select().Aggregate(fns...) } func (kq *KeysQuery) prepareQuery(ctx context.Context) error { - for _, f := range kq.fields { + for _, inter := range kq.inters { + if inter == nil { + return fmt.Errorf("db: uninitialized interceptor (forgotten import db/runtime?)") + } + if trv, ok := inter.(Traverser); ok { + if err := trv.Traverse(ctx, kq); err != nil { + return err + } + } + } + for _, f := range kq.ctx.Fields { if !keys.ValidColumn(f) { return &ValidationError{Name: f, err: fmt.Errorf("db: invalid field %q for query", f)} } @@ -318,10 +334,10 @@ func (kq *KeysQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Keys, e nodes = []*Keys{} _spec = kq.querySpec() ) - _spec.ScanValues = func(columns []string) ([]interface{}, error) { + _spec.ScanValues = func(columns []string) ([]any, error) { return (*Keys).scanValues(nil, columns) } - _spec.Assign = func(columns []string, values []interface{}) error { + _spec.Assign = func(columns []string, values []any) error { node := &Keys{config: kq.config} nodes = append(nodes, node) return node.assignValues(columns, values) @@ -340,38 +356,22 @@ func (kq *KeysQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Keys, e 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 + _spec.Node.Columns = kq.ctx.Fields + if len(kq.ctx.Fields) > 0 { + _spec.Unique = kq.ctx.Unique != nil && *kq.ctx.Unique } return sqlgraph.CountNodes(ctx, kq.driver, _spec) } -func (kq *KeysQuery) sqlExist(ctx context.Context) (bool, error) { - n, err := kq.sqlCount(ctx) - if err != nil { - return false, fmt.Errorf("db: check existence: %w", err) - } - return n > 0, nil -} - func (kq *KeysQuery) querySpec() *sqlgraph.QuerySpec { - _spec := &sqlgraph.QuerySpec{ - Node: &sqlgraph.NodeSpec{ - Table: keys.Table, - Columns: keys.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeString, - Column: keys.FieldID, - }, - }, - From: kq.sql, - Unique: true, - } - if unique := kq.unique; unique != nil { + _spec := sqlgraph.NewQuerySpec(keys.Table, keys.Columns, sqlgraph.NewFieldSpec(keys.FieldID, field.TypeString)) + _spec.From = kq.sql + if unique := kq.ctx.Unique; unique != nil { _spec.Unique = *unique + } else if kq.path != nil { + _spec.Unique = true } - if fields := kq.fields; len(fields) > 0 { + if fields := kq.ctx.Fields; len(fields) > 0 { _spec.Node.Columns = make([]string, 0, len(fields)) _spec.Node.Columns = append(_spec.Node.Columns, keys.FieldID) for i := range fields { @@ -387,10 +387,10 @@ func (kq *KeysQuery) querySpec() *sqlgraph.QuerySpec { } } } - if limit := kq.limit; limit != nil { + if limit := kq.ctx.Limit; limit != nil { _spec.Limit = *limit } - if offset := kq.offset; offset != nil { + if offset := kq.ctx.Offset; offset != nil { _spec.Offset = *offset } if ps := kq.order; len(ps) > 0 { @@ -406,7 +406,7 @@ func (kq *KeysQuery) querySpec() *sqlgraph.QuerySpec { func (kq *KeysQuery) sqlQuery(ctx context.Context) *sql.Selector { builder := sql.Dialect(kq.driver.Dialect()) t1 := builder.Table(keys.Table) - columns := kq.fields + columns := kq.ctx.Fields if len(columns) == 0 { columns = keys.Columns } @@ -415,7 +415,7 @@ func (kq *KeysQuery) sqlQuery(ctx context.Context) *sql.Selector { selector = kq.sql selector.Select(selector.Columns(columns...)...) } - if kq.unique != nil && *kq.unique { + if kq.ctx.Unique != nil && *kq.ctx.Unique { selector.Distinct() } for _, p := range kq.predicates { @@ -424,12 +424,12 @@ func (kq *KeysQuery) sqlQuery(ctx context.Context) *sql.Selector { for _, p := range kq.order { p(selector) } - if offset := kq.offset; offset != nil { + if offset := kq.ctx.Offset; offset != nil { // limit is mandatory for offset clause. We start // with default value, and override it below if needed. selector.Offset(*offset).Limit(math.MaxInt32) } - if limit := kq.limit; limit != nil { + if limit := kq.ctx.Limit; limit != nil { selector.Limit(*limit) } return selector @@ -437,13 +437,8 @@ func (kq *KeysQuery) sqlQuery(ctx context.Context) *sql.Selector { // KeysGroupBy is the group-by builder for Keys entities. type KeysGroupBy struct { - config selector - fields []string - fns []AggregateFunc - // intermediate query (i.e. traversal path). - sql *sql.Selector - path func(context.Context) (*sql.Selector, error) + build *KeysQuery } // Aggregate adds the given aggregation functions to the group-by query. @@ -452,74 +447,77 @@ func (kgb *KeysGroupBy) Aggregate(fns ...AggregateFunc) *KeysGroupBy { return kgb } -// Scan applies the group-by query and scans the result into the given value. -func (kgb *KeysGroupBy) Scan(ctx context.Context, v interface{}) error { - query, err := kgb.path(ctx) - if err != nil { +// Scan applies the selector query and scans the result into the given value. +func (kgb *KeysGroupBy) Scan(ctx context.Context, v any) error { + ctx = setContextOp(ctx, kgb.build.ctx, "GroupBy") + if err := kgb.build.prepareQuery(ctx); err != nil { return err } - kgb.sql = query - return kgb.sqlScan(ctx, v) + return scanWithInterceptors[*KeysQuery, *KeysGroupBy](ctx, kgb.build, kgb, kgb.build.inters, v) } -func (kgb *KeysGroupBy) sqlScan(ctx context.Context, v interface{}) error { - for _, f := range kgb.fields { - if !keys.ValidColumn(f) { - return &ValidationError{Name: f, err: fmt.Errorf("invalid field %q for group-by", f)} - } - } - selector := kgb.sqlQuery() - if err := selector.Err(); err != nil { - return err - } - rows := &sql.Rows{} - query, args := selector.Query() - if err := kgb.driver.Query(ctx, query, args, rows); err != nil { - return err - } - defer rows.Close() - return sql.ScanSlice(rows, v) -} - -func (kgb *KeysGroupBy) sqlQuery() *sql.Selector { - selector := kgb.sql.Select() +func (kgb *KeysGroupBy) sqlScan(ctx context.Context, root *KeysQuery, v any) error { + selector := root.sqlQuery(ctx).Select() aggregation := make([]string, 0, len(kgb.fns)) for _, fn := range kgb.fns { aggregation = append(aggregation, fn(selector)) } - // If no columns were selected in a custom aggregation function, the default - // selection is the fields used for "group-by", and the aggregation functions. if len(selector.SelectedColumns()) == 0 { - columns := make([]string, 0, len(kgb.fields)+len(kgb.fns)) - for _, f := range kgb.fields { + columns := make([]string, 0, len(*kgb.flds)+len(kgb.fns)) + for _, f := range *kgb.flds { columns = append(columns, selector.C(f)) } columns = append(columns, aggregation...) selector.Select(columns...) } - return selector.GroupBy(selector.Columns(kgb.fields...)...) + selector.GroupBy(selector.Columns(*kgb.flds...)...) + if err := selector.Err(); err != nil { + return err + } + rows := &sql.Rows{} + query, args := selector.Query() + if err := kgb.build.driver.Query(ctx, query, args, rows); err != nil { + return err + } + defer rows.Close() + return sql.ScanSlice(rows, v) } // KeysSelect is the builder for selecting fields of Keys entities. type KeysSelect struct { *KeysQuery selector - // intermediate query (i.e. traversal path). - sql *sql.Selector +} + +// Aggregate adds the given aggregation functions to the selector query. +func (ks *KeysSelect) Aggregate(fns ...AggregateFunc) *KeysSelect { + ks.fns = append(ks.fns, fns...) + return ks } // Scan applies the selector query and scans the result into the given value. -func (ks *KeysSelect) Scan(ctx context.Context, v interface{}) error { +func (ks *KeysSelect) Scan(ctx context.Context, v any) error { + ctx = setContextOp(ctx, ks.ctx, "Select") if err := ks.prepareQuery(ctx); err != nil { return err } - ks.sql = ks.KeysQuery.sqlQuery(ctx) - return ks.sqlScan(ctx, v) + return scanWithInterceptors[*KeysQuery, *KeysSelect](ctx, ks.KeysQuery, ks, ks.inters, v) } -func (ks *KeysSelect) sqlScan(ctx context.Context, v interface{}) error { +func (ks *KeysSelect) sqlScan(ctx context.Context, root *KeysQuery, v any) error { + selector := root.sqlQuery(ctx) + aggregation := make([]string, 0, len(ks.fns)) + for _, fn := range ks.fns { + aggregation = append(aggregation, fn(selector)) + } + switch n := len(*ks.selector.flds); { + case n == 0 && len(aggregation) > 0: + selector.Select(aggregation...) + case n != 0 && len(aggregation) > 0: + selector.AppendSelect(aggregation...) + } rows := &sql.Rows{} - query, args := ks.sql.Query() + query, args := selector.Query() if err := ks.driver.Query(ctx, query, args, rows); err != nil { return err } diff --git a/storage/ent/db/keys_update.go b/storage/ent/db/keys_update.go index b5fbefff..1f8055c3 100644 --- a/storage/ent/db/keys_update.go +++ b/storage/ent/db/keys_update.go @@ -10,6 +10,7 @@ import ( "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/dialect/sql/sqljson" "entgo.io/ent/schema/field" "github.com/dexidp/dex/storage" "github.com/dexidp/dex/storage/ent/db/keys" @@ -36,6 +37,12 @@ func (ku *KeysUpdate) SetVerificationKeys(sk []storage.VerificationKey) *KeysUpd return ku } +// AppendVerificationKeys appends sk to the "verification_keys" field. +func (ku *KeysUpdate) AppendVerificationKeys(sk []storage.VerificationKey) *KeysUpdate { + ku.mutation.AppendVerificationKeys(sk) + return ku +} + // SetSigningKey sets the "signing_key" field. func (ku *KeysUpdate) SetSigningKey(jwk jose.JSONWebKey) *KeysUpdate { ku.mutation.SetSigningKey(jwk) @@ -61,34 +68,7 @@ func (ku *KeysUpdate) Mutation() *KeysMutation { // Save executes the query and returns the number of nodes affected by the update operation. func (ku *KeysUpdate) Save(ctx context.Context) (int, error) { - var ( - err error - affected int - ) - if len(ku.hooks) == 0 { - affected, err = ku.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*KeysMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - ku.mutation = mutation - affected, err = ku.sqlSave(ctx) - mutation.done = true - return affected, err - }) - for i := len(ku.hooks) - 1; i >= 0; i-- { - if ku.hooks[i] == nil { - return 0, fmt.Errorf("db: uninitialized hook (forgotten import db/runtime?)") - } - mut = ku.hooks[i](mut) - } - if _, err := mut.Mutate(ctx, ku.mutation); err != nil { - return 0, err - } - } - return affected, err + return withHooks[int, KeysMutation](ctx, ku.sqlSave, ku.mutation, ku.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -114,16 +94,7 @@ func (ku *KeysUpdate) ExecX(ctx context.Context) { } func (ku *KeysUpdate) sqlSave(ctx context.Context) (n int, err error) { - _spec := &sqlgraph.UpdateSpec{ - Node: &sqlgraph.NodeSpec{ - Table: keys.Table, - Columns: keys.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeString, - Column: keys.FieldID, - }, - }, - } + _spec := sqlgraph.NewUpdateSpec(keys.Table, keys.Columns, sqlgraph.NewFieldSpec(keys.FieldID, field.TypeString)) if ps := ku.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { @@ -132,32 +103,21 @@ func (ku *KeysUpdate) sqlSave(ctx context.Context) (n int, err error) { } } if value, ok := ku.mutation.VerificationKeys(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeJSON, - Value: value, - Column: keys.FieldVerificationKeys, + _spec.SetField(keys.FieldVerificationKeys, field.TypeJSON, value) + } + if value, ok := ku.mutation.AppendedVerificationKeys(); ok { + _spec.AddModifier(func(u *sql.UpdateBuilder) { + sqljson.Append(u, keys.FieldVerificationKeys, value) }) } if value, ok := ku.mutation.SigningKey(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeJSON, - Value: value, - Column: keys.FieldSigningKey, - }) + _spec.SetField(keys.FieldSigningKey, field.TypeJSON, value) } if value, ok := ku.mutation.SigningKeyPub(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeJSON, - Value: value, - Column: keys.FieldSigningKeyPub, - }) + _spec.SetField(keys.FieldSigningKeyPub, field.TypeJSON, value) } if value, ok := ku.mutation.NextRotation(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeTime, - Value: value, - Column: keys.FieldNextRotation, - }) + _spec.SetField(keys.FieldNextRotation, field.TypeTime, value) } if n, err = sqlgraph.UpdateNodes(ctx, ku.driver, _spec); err != nil { if _, ok := err.(*sqlgraph.NotFoundError); ok { @@ -167,6 +127,7 @@ func (ku *KeysUpdate) sqlSave(ctx context.Context) (n int, err error) { } return 0, err } + ku.mutation.done = true return n, nil } @@ -184,6 +145,12 @@ func (kuo *KeysUpdateOne) SetVerificationKeys(sk []storage.VerificationKey) *Key return kuo } +// AppendVerificationKeys appends sk to the "verification_keys" field. +func (kuo *KeysUpdateOne) AppendVerificationKeys(sk []storage.VerificationKey) *KeysUpdateOne { + kuo.mutation.AppendVerificationKeys(sk) + return kuo +} + // SetSigningKey sets the "signing_key" field. func (kuo *KeysUpdateOne) SetSigningKey(jwk jose.JSONWebKey) *KeysUpdateOne { kuo.mutation.SetSigningKey(jwk) @@ -207,6 +174,12 @@ func (kuo *KeysUpdateOne) Mutation() *KeysMutation { return kuo.mutation } +// Where appends a list predicates to the KeysUpdate builder. +func (kuo *KeysUpdateOne) Where(ps ...predicate.Keys) *KeysUpdateOne { + kuo.mutation.Where(ps...) + return kuo +} + // Select allows selecting one or more fields (columns) of the returned entity. // The default is selecting all fields defined in the entity schema. func (kuo *KeysUpdateOne) Select(field string, fields ...string) *KeysUpdateOne { @@ -216,40 +189,7 @@ func (kuo *KeysUpdateOne) Select(field string, fields ...string) *KeysUpdateOne // Save executes the query and returns the updated Keys entity. func (kuo *KeysUpdateOne) Save(ctx context.Context) (*Keys, error) { - var ( - err error - node *Keys - ) - if len(kuo.hooks) == 0 { - node, err = kuo.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*KeysMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - kuo.mutation = mutation - node, err = kuo.sqlSave(ctx) - mutation.done = true - return node, err - }) - for i := len(kuo.hooks) - 1; i >= 0; i-- { - if kuo.hooks[i] == nil { - return nil, fmt.Errorf("db: uninitialized hook (forgotten import db/runtime?)") - } - mut = kuo.hooks[i](mut) - } - v, err := mut.Mutate(ctx, kuo.mutation) - if err != nil { - return nil, err - } - nv, ok := v.(*Keys) - if !ok { - return nil, fmt.Errorf("unexpected node type %T returned from KeysMutation", v) - } - node = nv - } - return node, err + return withHooks[*Keys, KeysMutation](ctx, kuo.sqlSave, kuo.mutation, kuo.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -275,16 +215,7 @@ func (kuo *KeysUpdateOne) ExecX(ctx context.Context) { } func (kuo *KeysUpdateOne) sqlSave(ctx context.Context) (_node *Keys, err error) { - _spec := &sqlgraph.UpdateSpec{ - Node: &sqlgraph.NodeSpec{ - Table: keys.Table, - Columns: keys.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeString, - Column: keys.FieldID, - }, - }, - } + _spec := sqlgraph.NewUpdateSpec(keys.Table, keys.Columns, sqlgraph.NewFieldSpec(keys.FieldID, field.TypeString)) id, ok := kuo.mutation.ID() if !ok { return nil, &ValidationError{Name: "id", err: errors.New(`db: missing "Keys.id" for update`)} @@ -310,32 +241,21 @@ func (kuo *KeysUpdateOne) sqlSave(ctx context.Context) (_node *Keys, err error) } } if value, ok := kuo.mutation.VerificationKeys(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeJSON, - Value: value, - Column: keys.FieldVerificationKeys, + _spec.SetField(keys.FieldVerificationKeys, field.TypeJSON, value) + } + if value, ok := kuo.mutation.AppendedVerificationKeys(); ok { + _spec.AddModifier(func(u *sql.UpdateBuilder) { + sqljson.Append(u, keys.FieldVerificationKeys, value) }) } if value, ok := kuo.mutation.SigningKey(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeJSON, - Value: value, - Column: keys.FieldSigningKey, - }) + _spec.SetField(keys.FieldSigningKey, field.TypeJSON, value) } if value, ok := kuo.mutation.SigningKeyPub(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeJSON, - Value: value, - Column: keys.FieldSigningKeyPub, - }) + _spec.SetField(keys.FieldSigningKeyPub, field.TypeJSON, value) } if value, ok := kuo.mutation.NextRotation(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeTime, - Value: value, - Column: keys.FieldNextRotation, - }) + _spec.SetField(keys.FieldNextRotation, field.TypeTime, value) } _node = &Keys{config: kuo.config} _spec.Assign = _node.assignValues @@ -348,5 +268,6 @@ func (kuo *KeysUpdateOne) sqlSave(ctx context.Context) (_node *Keys, err error) } return nil, err } + kuo.mutation.done = true return _node, nil } diff --git a/storage/ent/db/migrate/migrate.go b/storage/ent/db/migrate/migrate.go index 6bccf391..1956a6bf 100644 --- a/storage/ent/db/migrate/migrate.go +++ b/storage/ent/db/migrate/migrate.go @@ -56,10 +56,9 @@ func Create(ctx context.Context, s *Schema, tables []*schema.Table, opts ...sche // WriteTo writes the schema changes to w instead of running them against the database. // -// if err := client.Schema.WriteTo(context.Background(), os.Stdout); err != nil { +// if err := client.Schema.WriteTo(context.Background(), os.Stdout); err != nil { // log.Fatal(err) -// } -// +// } func (s *Schema) WriteTo(ctx context.Context, w io.Writer, opts ...schema.MigrateOption) error { return Create(ctx, &Schema{drv: &schema.WriteDriver{Writer: w, Driver: s.drv}}, Tables, opts...) } diff --git a/storage/ent/db/mutation.go b/storage/ent/db/mutation.go index 85e1af72..ca854af4 100644 --- a/storage/ent/db/mutation.go +++ b/storage/ent/db/mutation.go @@ -24,6 +24,7 @@ import ( jose "gopkg.in/square/go-jose.v2" "entgo.io/ent" + "entgo.io/ent/dialect/sql" ) const ( @@ -55,6 +56,7 @@ type AuthCodeMutation struct { id *string client_id *string scopes *[]string + appendscopes []string nonce *string redirect_uri *string claims_user_id *string @@ -62,6 +64,7 @@ type AuthCodeMutation struct { claims_email *string claims_email_verified *bool claims_groups *[]string + appendclaims_groups []string claims_preferred_username *string connector_id *string connector_data *[]byte @@ -217,6 +220,7 @@ func (m *AuthCodeMutation) ResetClientID() { // SetScopes sets the "scopes" field. func (m *AuthCodeMutation) SetScopes(s []string) { m.scopes = &s + m.appendscopes = nil } // Scopes returns the value of the "scopes" field in the mutation. @@ -245,9 +249,23 @@ func (m *AuthCodeMutation) OldScopes(ctx context.Context) (v []string, err error return oldValue.Scopes, nil } +// AppendScopes adds s to the "scopes" field. +func (m *AuthCodeMutation) AppendScopes(s []string) { + m.appendscopes = append(m.appendscopes, s...) +} + +// AppendedScopes returns the list of values that were appended to the "scopes" field in this mutation. +func (m *AuthCodeMutation) AppendedScopes() ([]string, bool) { + if len(m.appendscopes) == 0 { + return nil, false + } + return m.appendscopes, true +} + // ClearScopes clears the value of the "scopes" field. func (m *AuthCodeMutation) ClearScopes() { m.scopes = nil + m.appendscopes = nil m.clearedFields[authcode.FieldScopes] = struct{}{} } @@ -260,6 +278,7 @@ func (m *AuthCodeMutation) ScopesCleared() bool { // ResetScopes resets all changes to the "scopes" field. func (m *AuthCodeMutation) ResetScopes() { m.scopes = nil + m.appendscopes = nil delete(m.clearedFields, authcode.FieldScopes) } @@ -482,6 +501,7 @@ func (m *AuthCodeMutation) ResetClaimsEmailVerified() { // SetClaimsGroups sets the "claims_groups" field. func (m *AuthCodeMutation) SetClaimsGroups(s []string) { m.claims_groups = &s + m.appendclaims_groups = nil } // ClaimsGroups returns the value of the "claims_groups" field in the mutation. @@ -510,9 +530,23 @@ func (m *AuthCodeMutation) OldClaimsGroups(ctx context.Context) (v []string, err return oldValue.ClaimsGroups, nil } +// AppendClaimsGroups adds s to the "claims_groups" field. +func (m *AuthCodeMutation) AppendClaimsGroups(s []string) { + m.appendclaims_groups = append(m.appendclaims_groups, s...) +} + +// AppendedClaimsGroups returns the list of values that were appended to the "claims_groups" field in this mutation. +func (m *AuthCodeMutation) AppendedClaimsGroups() ([]string, bool) { + if len(m.appendclaims_groups) == 0 { + return nil, false + } + return m.appendclaims_groups, true +} + // ClearClaimsGroups clears the value of the "claims_groups" field. func (m *AuthCodeMutation) ClearClaimsGroups() { m.claims_groups = nil + m.appendclaims_groups = nil m.clearedFields[authcode.FieldClaimsGroups] = struct{}{} } @@ -525,6 +559,7 @@ func (m *AuthCodeMutation) ClaimsGroupsCleared() bool { // ResetClaimsGroups resets all changes to the "claims_groups" field. func (m *AuthCodeMutation) ResetClaimsGroups() { m.claims_groups = nil + m.appendclaims_groups = nil delete(m.clearedFields, authcode.FieldClaimsGroups) } @@ -762,11 +797,26 @@ func (m *AuthCodeMutation) Where(ps ...predicate.AuthCode) { m.predicates = append(m.predicates, ps...) } +// WhereP appends storage-level predicates to the AuthCodeMutation builder. Using this method, +// users can use type-assertion to append predicates that do not depend on any generated package. +func (m *AuthCodeMutation) WhereP(ps ...func(*sql.Selector)) { + p := make([]predicate.AuthCode, len(ps)) + for i := range ps { + p[i] = ps[i] + } + m.Where(p...) +} + // Op returns the operation name. func (m *AuthCodeMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *AuthCodeMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (AuthCode). func (m *AuthCodeMutation) Type() string { return m.typ @@ -1188,7 +1238,9 @@ type AuthRequestMutation struct { id *string client_id *string scopes *[]string + appendscopes []string response_types *[]string + appendresponse_types []string redirect_uri *string nonce *string state *string @@ -1199,6 +1251,7 @@ type AuthRequestMutation struct { claims_email *string claims_email_verified *bool claims_groups *[]string + appendclaims_groups []string claims_preferred_username *string connector_id *string connector_data *[]byte @@ -1355,6 +1408,7 @@ func (m *AuthRequestMutation) ResetClientID() { // SetScopes sets the "scopes" field. func (m *AuthRequestMutation) SetScopes(s []string) { m.scopes = &s + m.appendscopes = nil } // Scopes returns the value of the "scopes" field in the mutation. @@ -1383,9 +1437,23 @@ func (m *AuthRequestMutation) OldScopes(ctx context.Context) (v []string, err er return oldValue.Scopes, nil } +// AppendScopes adds s to the "scopes" field. +func (m *AuthRequestMutation) AppendScopes(s []string) { + m.appendscopes = append(m.appendscopes, s...) +} + +// AppendedScopes returns the list of values that were appended to the "scopes" field in this mutation. +func (m *AuthRequestMutation) AppendedScopes() ([]string, bool) { + if len(m.appendscopes) == 0 { + return nil, false + } + return m.appendscopes, true +} + // ClearScopes clears the value of the "scopes" field. func (m *AuthRequestMutation) ClearScopes() { m.scopes = nil + m.appendscopes = nil m.clearedFields[authrequest.FieldScopes] = struct{}{} } @@ -1398,12 +1466,14 @@ func (m *AuthRequestMutation) ScopesCleared() bool { // ResetScopes resets all changes to the "scopes" field. func (m *AuthRequestMutation) ResetScopes() { m.scopes = nil + m.appendscopes = nil delete(m.clearedFields, authrequest.FieldScopes) } // SetResponseTypes sets the "response_types" field. func (m *AuthRequestMutation) SetResponseTypes(s []string) { m.response_types = &s + m.appendresponse_types = nil } // ResponseTypes returns the value of the "response_types" field in the mutation. @@ -1432,9 +1502,23 @@ func (m *AuthRequestMutation) OldResponseTypes(ctx context.Context) (v []string, return oldValue.ResponseTypes, nil } +// AppendResponseTypes adds s to the "response_types" field. +func (m *AuthRequestMutation) AppendResponseTypes(s []string) { + m.appendresponse_types = append(m.appendresponse_types, s...) +} + +// AppendedResponseTypes returns the list of values that were appended to the "response_types" field in this mutation. +func (m *AuthRequestMutation) AppendedResponseTypes() ([]string, bool) { + if len(m.appendresponse_types) == 0 { + return nil, false + } + return m.appendresponse_types, true +} + // ClearResponseTypes clears the value of the "response_types" field. func (m *AuthRequestMutation) ClearResponseTypes() { m.response_types = nil + m.appendresponse_types = nil m.clearedFields[authrequest.FieldResponseTypes] = struct{}{} } @@ -1447,6 +1531,7 @@ func (m *AuthRequestMutation) ResponseTypesCleared() bool { // ResetResponseTypes resets all changes to the "response_types" field. func (m *AuthRequestMutation) ResetResponseTypes() { m.response_types = nil + m.appendresponse_types = nil delete(m.clearedFields, authrequest.FieldResponseTypes) } @@ -1777,6 +1862,7 @@ func (m *AuthRequestMutation) ResetClaimsEmailVerified() { // SetClaimsGroups sets the "claims_groups" field. func (m *AuthRequestMutation) SetClaimsGroups(s []string) { m.claims_groups = &s + m.appendclaims_groups = nil } // ClaimsGroups returns the value of the "claims_groups" field in the mutation. @@ -1805,9 +1891,23 @@ func (m *AuthRequestMutation) OldClaimsGroups(ctx context.Context) (v []string, return oldValue.ClaimsGroups, nil } +// AppendClaimsGroups adds s to the "claims_groups" field. +func (m *AuthRequestMutation) AppendClaimsGroups(s []string) { + m.appendclaims_groups = append(m.appendclaims_groups, s...) +} + +// AppendedClaimsGroups returns the list of values that were appended to the "claims_groups" field in this mutation. +func (m *AuthRequestMutation) AppendedClaimsGroups() ([]string, bool) { + if len(m.appendclaims_groups) == 0 { + return nil, false + } + return m.appendclaims_groups, true +} + // ClearClaimsGroups clears the value of the "claims_groups" field. func (m *AuthRequestMutation) ClearClaimsGroups() { m.claims_groups = nil + m.appendclaims_groups = nil m.clearedFields[authrequest.FieldClaimsGroups] = struct{}{} } @@ -1820,6 +1920,7 @@ func (m *AuthRequestMutation) ClaimsGroupsCleared() bool { // ResetClaimsGroups resets all changes to the "claims_groups" field. func (m *AuthRequestMutation) ResetClaimsGroups() { m.claims_groups = nil + m.appendclaims_groups = nil delete(m.clearedFields, authrequest.FieldClaimsGroups) } @@ -2093,11 +2194,26 @@ func (m *AuthRequestMutation) Where(ps ...predicate.AuthRequest) { m.predicates = append(m.predicates, ps...) } +// WhereP appends storage-level predicates to the AuthRequestMutation builder. Using this method, +// users can use type-assertion to append predicates that do not depend on any generated package. +func (m *AuthRequestMutation) WhereP(ps ...func(*sql.Selector)) { + p := make([]predicate.AuthRequest, len(ps)) + for i := range ps { + p[i] = ps[i] + } + m.Where(p...) +} + // Op returns the operation name. func (m *AuthRequestMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *AuthRequestMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (AuthRequest). func (m *AuthRequestMutation) Type() string { return m.typ @@ -2871,11 +2987,26 @@ func (m *ConnectorMutation) Where(ps ...predicate.Connector) { m.predicates = append(m.predicates, ps...) } +// WhereP appends storage-level predicates to the ConnectorMutation builder. Using this method, +// users can use type-assertion to append predicates that do not depend on any generated package. +func (m *ConnectorMutation) WhereP(ps ...func(*sql.Selector)) { + p := make([]predicate.Connector, len(ps)) + for i := range ps { + p[i] = ps[i] + } + m.Where(p...) +} + // Op returns the operation name. func (m *ConnectorMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *ConnectorMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (Connector). func (m *ConnectorMutation) Type() string { return m.typ @@ -3092,6 +3223,7 @@ type DeviceRequestMutation struct { client_id *string client_secret *string scopes *[]string + appendscopes []string expiry *time.Time clearedFields map[string]struct{} done bool @@ -3344,6 +3476,7 @@ func (m *DeviceRequestMutation) ResetClientSecret() { // SetScopes sets the "scopes" field. func (m *DeviceRequestMutation) SetScopes(s []string) { m.scopes = &s + m.appendscopes = nil } // Scopes returns the value of the "scopes" field in the mutation. @@ -3372,9 +3505,23 @@ func (m *DeviceRequestMutation) OldScopes(ctx context.Context) (v []string, err return oldValue.Scopes, nil } +// AppendScopes adds s to the "scopes" field. +func (m *DeviceRequestMutation) AppendScopes(s []string) { + m.appendscopes = append(m.appendscopes, s...) +} + +// AppendedScopes returns the list of values that were appended to the "scopes" field in this mutation. +func (m *DeviceRequestMutation) AppendedScopes() ([]string, bool) { + if len(m.appendscopes) == 0 { + return nil, false + } + return m.appendscopes, true +} + // ClearScopes clears the value of the "scopes" field. func (m *DeviceRequestMutation) ClearScopes() { m.scopes = nil + m.appendscopes = nil m.clearedFields[devicerequest.FieldScopes] = struct{}{} } @@ -3387,6 +3534,7 @@ func (m *DeviceRequestMutation) ScopesCleared() bool { // ResetScopes resets all changes to the "scopes" field. func (m *DeviceRequestMutation) ResetScopes() { m.scopes = nil + m.appendscopes = nil delete(m.clearedFields, devicerequest.FieldScopes) } @@ -3431,11 +3579,26 @@ func (m *DeviceRequestMutation) Where(ps ...predicate.DeviceRequest) { m.predicates = append(m.predicates, ps...) } +// WhereP appends storage-level predicates to the DeviceRequestMutation builder. Using this method, +// users can use type-assertion to append predicates that do not depend on any generated package. +func (m *DeviceRequestMutation) WhereP(ps ...func(*sql.Selector)) { + p := make([]predicate.DeviceRequest, len(ps)) + for i := range ps { + p[i] = ps[i] + } + m.Where(p...) +} + // Op returns the operation name. func (m *DeviceRequestMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *DeviceRequestMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (DeviceRequest). func (m *DeviceRequestMutation) Type() string { return m.typ @@ -4129,11 +4292,26 @@ func (m *DeviceTokenMutation) Where(ps ...predicate.DeviceToken) { m.predicates = append(m.predicates, ps...) } +// WhereP appends storage-level predicates to the DeviceTokenMutation builder. Using this method, +// users can use type-assertion to append predicates that do not depend on any generated package. +func (m *DeviceTokenMutation) WhereP(ps ...func(*sql.Selector)) { + p := make([]predicate.DeviceToken, len(ps)) + for i := range ps { + p[i] = ps[i] + } + m.Where(p...) +} + // Op returns the operation name. func (m *DeviceTokenMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *DeviceTokenMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (DeviceToken). func (m *DeviceTokenMutation) Type() string { return m.typ @@ -4434,17 +4612,18 @@ func (m *DeviceTokenMutation) ResetEdge(name string) error { // KeysMutation represents an operation that mutates the Keys nodes in the graph. type KeysMutation struct { config - op Op - typ string - id *string - verification_keys *[]storage.VerificationKey - signing_key *jose.JSONWebKey - signing_key_pub *jose.JSONWebKey - next_rotation *time.Time - clearedFields map[string]struct{} - done bool - oldValue func(context.Context) (*Keys, error) - predicates []predicate.Keys + op Op + typ string + id *string + verification_keys *[]storage.VerificationKey + appendverification_keys []storage.VerificationKey + signing_key *jose.JSONWebKey + signing_key_pub *jose.JSONWebKey + next_rotation *time.Time + clearedFields map[string]struct{} + done bool + oldValue func(context.Context) (*Keys, error) + predicates []predicate.Keys } var _ ent.Mutation = (*KeysMutation)(nil) @@ -4554,6 +4733,7 @@ func (m *KeysMutation) IDs(ctx context.Context) ([]string, error) { // SetVerificationKeys sets the "verification_keys" field. func (m *KeysMutation) SetVerificationKeys(sk []storage.VerificationKey) { m.verification_keys = &sk + m.appendverification_keys = nil } // VerificationKeys returns the value of the "verification_keys" field in the mutation. @@ -4582,9 +4762,23 @@ func (m *KeysMutation) OldVerificationKeys(ctx context.Context) (v []storage.Ver return oldValue.VerificationKeys, nil } +// AppendVerificationKeys adds sk to the "verification_keys" field. +func (m *KeysMutation) AppendVerificationKeys(sk []storage.VerificationKey) { + m.appendverification_keys = append(m.appendverification_keys, sk...) +} + +// AppendedVerificationKeys returns the list of values that were appended to the "verification_keys" field in this mutation. +func (m *KeysMutation) AppendedVerificationKeys() ([]storage.VerificationKey, bool) { + if len(m.appendverification_keys) == 0 { + return nil, false + } + return m.appendverification_keys, true +} + // ResetVerificationKeys resets all changes to the "verification_keys" field. func (m *KeysMutation) ResetVerificationKeys() { m.verification_keys = nil + m.appendverification_keys = nil } // SetSigningKey sets the "signing_key" field. @@ -4700,11 +4894,26 @@ func (m *KeysMutation) Where(ps ...predicate.Keys) { m.predicates = append(m.predicates, ps...) } +// WhereP appends storage-level predicates to the KeysMutation builder. Using this method, +// users can use type-assertion to append predicates that do not depend on any generated package. +func (m *KeysMutation) WhereP(ps ...func(*sql.Selector)) { + p := make([]predicate.Keys, len(ps)) + for i := range ps { + p[i] = ps[i] + } + m.Where(p...) +} + // Op returns the operation name. func (m *KeysMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *KeysMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (Keys). func (m *KeysMutation) Type() string { return m.typ @@ -4913,19 +5122,21 @@ func (m *KeysMutation) ResetEdge(name string) error { // OAuth2ClientMutation represents an operation that mutates the OAuth2Client nodes in the graph. type OAuth2ClientMutation struct { config - op Op - typ string - id *string - secret *string - redirect_uris *[]string - trusted_peers *[]string - public *bool - name *string - logo_url *string - clearedFields map[string]struct{} - done bool - oldValue func(context.Context) (*OAuth2Client, error) - predicates []predicate.OAuth2Client + op Op + typ string + id *string + secret *string + redirect_uris *[]string + appendredirect_uris []string + trusted_peers *[]string + appendtrusted_peers []string + public *bool + name *string + logo_url *string + clearedFields map[string]struct{} + done bool + oldValue func(context.Context) (*OAuth2Client, error) + predicates []predicate.OAuth2Client } var _ ent.Mutation = (*OAuth2ClientMutation)(nil) @@ -5071,6 +5282,7 @@ func (m *OAuth2ClientMutation) ResetSecret() { // SetRedirectUris sets the "redirect_uris" field. func (m *OAuth2ClientMutation) SetRedirectUris(s []string) { m.redirect_uris = &s + m.appendredirect_uris = nil } // RedirectUris returns the value of the "redirect_uris" field in the mutation. @@ -5099,9 +5311,23 @@ func (m *OAuth2ClientMutation) OldRedirectUris(ctx context.Context) (v []string, return oldValue.RedirectUris, nil } +// AppendRedirectUris adds s to the "redirect_uris" field. +func (m *OAuth2ClientMutation) AppendRedirectUris(s []string) { + m.appendredirect_uris = append(m.appendredirect_uris, s...) +} + +// AppendedRedirectUris returns the list of values that were appended to the "redirect_uris" field in this mutation. +func (m *OAuth2ClientMutation) AppendedRedirectUris() ([]string, bool) { + if len(m.appendredirect_uris) == 0 { + return nil, false + } + return m.appendredirect_uris, true +} + // ClearRedirectUris clears the value of the "redirect_uris" field. func (m *OAuth2ClientMutation) ClearRedirectUris() { m.redirect_uris = nil + m.appendredirect_uris = nil m.clearedFields[oauth2client.FieldRedirectUris] = struct{}{} } @@ -5114,12 +5340,14 @@ func (m *OAuth2ClientMutation) RedirectUrisCleared() bool { // ResetRedirectUris resets all changes to the "redirect_uris" field. func (m *OAuth2ClientMutation) ResetRedirectUris() { m.redirect_uris = nil + m.appendredirect_uris = nil delete(m.clearedFields, oauth2client.FieldRedirectUris) } // SetTrustedPeers sets the "trusted_peers" field. func (m *OAuth2ClientMutation) SetTrustedPeers(s []string) { m.trusted_peers = &s + m.appendtrusted_peers = nil } // TrustedPeers returns the value of the "trusted_peers" field in the mutation. @@ -5148,9 +5376,23 @@ func (m *OAuth2ClientMutation) OldTrustedPeers(ctx context.Context) (v []string, return oldValue.TrustedPeers, nil } +// AppendTrustedPeers adds s to the "trusted_peers" field. +func (m *OAuth2ClientMutation) AppendTrustedPeers(s []string) { + m.appendtrusted_peers = append(m.appendtrusted_peers, s...) +} + +// AppendedTrustedPeers returns the list of values that were appended to the "trusted_peers" field in this mutation. +func (m *OAuth2ClientMutation) AppendedTrustedPeers() ([]string, bool) { + if len(m.appendtrusted_peers) == 0 { + return nil, false + } + return m.appendtrusted_peers, true +} + // ClearTrustedPeers clears the value of the "trusted_peers" field. func (m *OAuth2ClientMutation) ClearTrustedPeers() { m.trusted_peers = nil + m.appendtrusted_peers = nil m.clearedFields[oauth2client.FieldTrustedPeers] = struct{}{} } @@ -5163,6 +5405,7 @@ func (m *OAuth2ClientMutation) TrustedPeersCleared() bool { // ResetTrustedPeers resets all changes to the "trusted_peers" field. func (m *OAuth2ClientMutation) ResetTrustedPeers() { m.trusted_peers = nil + m.appendtrusted_peers = nil delete(m.clearedFields, oauth2client.FieldTrustedPeers) } @@ -5279,11 +5522,26 @@ func (m *OAuth2ClientMutation) Where(ps ...predicate.OAuth2Client) { m.predicates = append(m.predicates, ps...) } +// WhereP appends storage-level predicates to the OAuth2ClientMutation builder. Using this method, +// users can use type-assertion to append predicates that do not depend on any generated package. +func (m *OAuth2ClientMutation) WhereP(ps ...func(*sql.Selector)) { + p := make([]predicate.OAuth2Client, len(ps)) + for i := range ps { + p[i] = ps[i] + } + m.Where(p...) +} + // Op returns the operation name. func (m *OAuth2ClientMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *OAuth2ClientMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (OAuth2Client). func (m *OAuth2ClientMutation) Type() string { return m.typ @@ -5820,11 +6078,26 @@ func (m *OfflineSessionMutation) Where(ps ...predicate.OfflineSession) { m.predicates = append(m.predicates, ps...) } +// WhereP appends storage-level predicates to the OfflineSessionMutation builder. Using this method, +// users can use type-assertion to append predicates that do not depend on any generated package. +func (m *OfflineSessionMutation) WhereP(ps ...func(*sql.Selector)) { + p := make([]predicate.OfflineSession, len(ps)) + for i := range ps { + p[i] = ps[i] + } + m.Where(p...) +} + // Op returns the operation name. func (m *OfflineSessionMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *OfflineSessionMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (OfflineSession). func (m *OfflineSessionMutation) Type() string { return m.typ @@ -6302,11 +6575,26 @@ func (m *PasswordMutation) Where(ps ...predicate.Password) { m.predicates = append(m.predicates, ps...) } +// WhereP appends storage-level predicates to the PasswordMutation builder. Using this method, +// users can use type-assertion to append predicates that do not depend on any generated package. +func (m *PasswordMutation) WhereP(ps ...func(*sql.Selector)) { + p := make([]predicate.Password, len(ps)) + for i := range ps { + p[i] = ps[i] + } + m.Where(p...) +} + // Op returns the operation name. func (m *PasswordMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *PasswordMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (Password). func (m *PasswordMutation) Type() string { return m.typ @@ -6520,12 +6808,14 @@ type RefreshTokenMutation struct { id *string client_id *string scopes *[]string + appendscopes []string nonce *string claims_user_id *string claims_username *string claims_email *string claims_email_verified *bool claims_groups *[]string + appendclaims_groups []string claims_preferred_username *string connector_id *string connector_data *[]byte @@ -6682,6 +6972,7 @@ func (m *RefreshTokenMutation) ResetClientID() { // SetScopes sets the "scopes" field. func (m *RefreshTokenMutation) SetScopes(s []string) { m.scopes = &s + m.appendscopes = nil } // Scopes returns the value of the "scopes" field in the mutation. @@ -6710,9 +7001,23 @@ func (m *RefreshTokenMutation) OldScopes(ctx context.Context) (v []string, err e return oldValue.Scopes, nil } +// AppendScopes adds s to the "scopes" field. +func (m *RefreshTokenMutation) AppendScopes(s []string) { + m.appendscopes = append(m.appendscopes, s...) +} + +// AppendedScopes returns the list of values that were appended to the "scopes" field in this mutation. +func (m *RefreshTokenMutation) AppendedScopes() ([]string, bool) { + if len(m.appendscopes) == 0 { + return nil, false + } + return m.appendscopes, true +} + // ClearScopes clears the value of the "scopes" field. func (m *RefreshTokenMutation) ClearScopes() { m.scopes = nil + m.appendscopes = nil m.clearedFields[refreshtoken.FieldScopes] = struct{}{} } @@ -6725,6 +7030,7 @@ func (m *RefreshTokenMutation) ScopesCleared() bool { // ResetScopes resets all changes to the "scopes" field. func (m *RefreshTokenMutation) ResetScopes() { m.scopes = nil + m.appendscopes = nil delete(m.clearedFields, refreshtoken.FieldScopes) } @@ -6911,6 +7217,7 @@ func (m *RefreshTokenMutation) ResetClaimsEmailVerified() { // SetClaimsGroups sets the "claims_groups" field. func (m *RefreshTokenMutation) SetClaimsGroups(s []string) { m.claims_groups = &s + m.appendclaims_groups = nil } // ClaimsGroups returns the value of the "claims_groups" field in the mutation. @@ -6939,9 +7246,23 @@ func (m *RefreshTokenMutation) OldClaimsGroups(ctx context.Context) (v []string, return oldValue.ClaimsGroups, nil } +// AppendClaimsGroups adds s to the "claims_groups" field. +func (m *RefreshTokenMutation) AppendClaimsGroups(s []string) { + m.appendclaims_groups = append(m.appendclaims_groups, s...) +} + +// AppendedClaimsGroups returns the list of values that were appended to the "claims_groups" field in this mutation. +func (m *RefreshTokenMutation) AppendedClaimsGroups() ([]string, bool) { + if len(m.appendclaims_groups) == 0 { + return nil, false + } + return m.appendclaims_groups, true +} + // ClearClaimsGroups clears the value of the "claims_groups" field. func (m *RefreshTokenMutation) ClearClaimsGroups() { m.claims_groups = nil + m.appendclaims_groups = nil m.clearedFields[refreshtoken.FieldClaimsGroups] = struct{}{} } @@ -6954,6 +7275,7 @@ func (m *RefreshTokenMutation) ClaimsGroupsCleared() bool { // ResetClaimsGroups resets all changes to the "claims_groups" field. func (m *RefreshTokenMutation) ResetClaimsGroups() { m.claims_groups = nil + m.appendclaims_groups = nil delete(m.clearedFields, refreshtoken.FieldClaimsGroups) } @@ -7227,11 +7549,26 @@ func (m *RefreshTokenMutation) Where(ps ...predicate.RefreshToken) { m.predicates = append(m.predicates, ps...) } +// WhereP appends storage-level predicates to the RefreshTokenMutation builder. Using this method, +// users can use type-assertion to append predicates that do not depend on any generated package. +func (m *RefreshTokenMutation) WhereP(ps ...func(*sql.Selector)) { + p := make([]predicate.RefreshToken, len(ps)) + for i := range ps { + p[i] = ps[i] + } + m.Where(p...) +} + // Op returns the operation name. func (m *RefreshTokenMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *RefreshTokenMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (RefreshToken). func (m *RefreshTokenMutation) Type() string { return m.typ diff --git a/storage/ent/db/oauth2client.go b/storage/ent/db/oauth2client.go index f96ca218..3c3fc654 100644 --- a/storage/ent/db/oauth2client.go +++ b/storage/ent/db/oauth2client.go @@ -31,8 +31,8 @@ type OAuth2Client struct { } // scanValues returns the types for scanning values from sql.Rows. -func (*OAuth2Client) scanValues(columns []string) ([]interface{}, error) { - values := make([]interface{}, len(columns)) +func (*OAuth2Client) scanValues(columns []string) ([]any, error) { + values := make([]any, len(columns)) for i := range columns { switch columns[i] { case oauth2client.FieldRedirectUris, oauth2client.FieldTrustedPeers: @@ -50,7 +50,7 @@ func (*OAuth2Client) scanValues(columns []string) ([]interface{}, error) { // assignValues assigns the values that were returned from sql.Rows (after scanning) // to the OAuth2Client fields. -func (o *OAuth2Client) assignValues(columns []string, values []interface{}) error { +func (o *OAuth2Client) assignValues(columns []string, values []any) error { if m, n := len(values), len(columns); m < n { return fmt.Errorf("mismatch number of scan values: %d != %d", m, n) } @@ -111,7 +111,7 @@ func (o *OAuth2Client) assignValues(columns []string, values []interface{}) erro // Note that you need to call OAuth2Client.Unwrap() before calling this method if this OAuth2Client // was returned from a transaction, and the transaction was committed or rolled back. func (o *OAuth2Client) Update() *OAuth2ClientUpdateOne { - return (&OAuth2ClientClient{config: o.config}).UpdateOne(o) + return NewOAuth2ClientClient(o.config).UpdateOne(o) } // Unwrap unwraps the OAuth2Client entity that was returned from a transaction after it was closed, @@ -153,9 +153,3 @@ func (o *OAuth2Client) String() string { // OAuth2Clients is a parsable slice of OAuth2Client. type OAuth2Clients []*OAuth2Client - -func (o OAuth2Clients) config(cfg config) { - for _i := range o { - o[_i].config = cfg - } -} diff --git a/storage/ent/db/oauth2client/where.go b/storage/ent/db/oauth2client/where.go index d74a6ab7..df9114ad 100644 --- a/storage/ent/db/oauth2client/where.go +++ b/storage/ent/db/oauth2client/where.go @@ -9,440 +9,292 @@ import ( // ID filters vertices based on their ID field. func ID(id string) predicate.OAuth2Client { - return predicate.OAuth2Client(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldID), id)) - }) + return predicate.OAuth2Client(sql.FieldEQ(FieldID, id)) } // IDEQ applies the EQ predicate on the ID field. func IDEQ(id string) predicate.OAuth2Client { - return predicate.OAuth2Client(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldID), id)) - }) + return predicate.OAuth2Client(sql.FieldEQ(FieldID, id)) } // IDNEQ applies the NEQ predicate on the ID field. func IDNEQ(id string) predicate.OAuth2Client { - return predicate.OAuth2Client(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldID), id)) - }) + return predicate.OAuth2Client(sql.FieldNEQ(FieldID, id)) } // IDIn applies the In predicate on the ID field. func IDIn(ids ...string) predicate.OAuth2Client { - return predicate.OAuth2Client(func(s *sql.Selector) { - v := make([]interface{}, len(ids)) - for i := range v { - v[i] = ids[i] - } - s.Where(sql.In(s.C(FieldID), v...)) - }) + return predicate.OAuth2Client(sql.FieldIn(FieldID, ids...)) } // IDNotIn applies the NotIn predicate on the ID field. func IDNotIn(ids ...string) predicate.OAuth2Client { - return predicate.OAuth2Client(func(s *sql.Selector) { - v := make([]interface{}, len(ids)) - for i := range v { - v[i] = ids[i] - } - s.Where(sql.NotIn(s.C(FieldID), v...)) - }) + return predicate.OAuth2Client(sql.FieldNotIn(FieldID, ids...)) } // IDGT applies the GT predicate on the ID field. func IDGT(id string) predicate.OAuth2Client { - return predicate.OAuth2Client(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldID), id)) - }) + return predicate.OAuth2Client(sql.FieldGT(FieldID, id)) } // IDGTE applies the GTE predicate on the ID field. func IDGTE(id string) predicate.OAuth2Client { - return predicate.OAuth2Client(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldID), id)) - }) + return predicate.OAuth2Client(sql.FieldGTE(FieldID, id)) } // IDLT applies the LT predicate on the ID field. func IDLT(id string) predicate.OAuth2Client { - return predicate.OAuth2Client(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldID), id)) - }) + return predicate.OAuth2Client(sql.FieldLT(FieldID, id)) } // IDLTE applies the LTE predicate on the ID field. func IDLTE(id string) predicate.OAuth2Client { - return predicate.OAuth2Client(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldID), id)) - }) + return predicate.OAuth2Client(sql.FieldLTE(FieldID, id)) } // Secret applies equality check predicate on the "secret" field. It's identical to SecretEQ. func Secret(v string) predicate.OAuth2Client { - return predicate.OAuth2Client(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldSecret), v)) - }) + return predicate.OAuth2Client(sql.FieldEQ(FieldSecret, v)) } // Public applies equality check predicate on the "public" field. It's identical to PublicEQ. func Public(v bool) predicate.OAuth2Client { - return predicate.OAuth2Client(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldPublic), v)) - }) + return predicate.OAuth2Client(sql.FieldEQ(FieldPublic, v)) } // Name applies equality check predicate on the "name" field. It's identical to NameEQ. func Name(v string) predicate.OAuth2Client { - return predicate.OAuth2Client(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldName), v)) - }) + return predicate.OAuth2Client(sql.FieldEQ(FieldName, v)) } // LogoURL applies equality check predicate on the "logo_url" field. It's identical to LogoURLEQ. func LogoURL(v string) predicate.OAuth2Client { - return predicate.OAuth2Client(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldLogoURL), v)) - }) + return predicate.OAuth2Client(sql.FieldEQ(FieldLogoURL, v)) } // SecretEQ applies the EQ predicate on the "secret" field. func SecretEQ(v string) predicate.OAuth2Client { - return predicate.OAuth2Client(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldSecret), v)) - }) + return predicate.OAuth2Client(sql.FieldEQ(FieldSecret, v)) } // SecretNEQ applies the NEQ predicate on the "secret" field. func SecretNEQ(v string) predicate.OAuth2Client { - return predicate.OAuth2Client(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldSecret), v)) - }) + return predicate.OAuth2Client(sql.FieldNEQ(FieldSecret, v)) } // SecretIn applies the In predicate on the "secret" field. func SecretIn(vs ...string) predicate.OAuth2Client { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.OAuth2Client(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldSecret), v...)) - }) + return predicate.OAuth2Client(sql.FieldIn(FieldSecret, vs...)) } // SecretNotIn applies the NotIn predicate on the "secret" field. func SecretNotIn(vs ...string) predicate.OAuth2Client { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.OAuth2Client(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldSecret), v...)) - }) + return predicate.OAuth2Client(sql.FieldNotIn(FieldSecret, vs...)) } // SecretGT applies the GT predicate on the "secret" field. func SecretGT(v string) predicate.OAuth2Client { - return predicate.OAuth2Client(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldSecret), v)) - }) + return predicate.OAuth2Client(sql.FieldGT(FieldSecret, v)) } // SecretGTE applies the GTE predicate on the "secret" field. func SecretGTE(v string) predicate.OAuth2Client { - return predicate.OAuth2Client(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldSecret), v)) - }) + return predicate.OAuth2Client(sql.FieldGTE(FieldSecret, v)) } // SecretLT applies the LT predicate on the "secret" field. func SecretLT(v string) predicate.OAuth2Client { - return predicate.OAuth2Client(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldSecret), v)) - }) + return predicate.OAuth2Client(sql.FieldLT(FieldSecret, v)) } // SecretLTE applies the LTE predicate on the "secret" field. func SecretLTE(v string) predicate.OAuth2Client { - return predicate.OAuth2Client(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldSecret), v)) - }) + return predicate.OAuth2Client(sql.FieldLTE(FieldSecret, v)) } // SecretContains applies the Contains predicate on the "secret" field. func SecretContains(v string) predicate.OAuth2Client { - return predicate.OAuth2Client(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldSecret), v)) - }) + return predicate.OAuth2Client(sql.FieldContains(FieldSecret, v)) } // SecretHasPrefix applies the HasPrefix predicate on the "secret" field. func SecretHasPrefix(v string) predicate.OAuth2Client { - return predicate.OAuth2Client(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldSecret), v)) - }) + return predicate.OAuth2Client(sql.FieldHasPrefix(FieldSecret, v)) } // SecretHasSuffix applies the HasSuffix predicate on the "secret" field. func SecretHasSuffix(v string) predicate.OAuth2Client { - return predicate.OAuth2Client(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldSecret), v)) - }) + return predicate.OAuth2Client(sql.FieldHasSuffix(FieldSecret, v)) } // SecretEqualFold applies the EqualFold predicate on the "secret" field. func SecretEqualFold(v string) predicate.OAuth2Client { - return predicate.OAuth2Client(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldSecret), v)) - }) + return predicate.OAuth2Client(sql.FieldEqualFold(FieldSecret, v)) } // SecretContainsFold applies the ContainsFold predicate on the "secret" field. func SecretContainsFold(v string) predicate.OAuth2Client { - return predicate.OAuth2Client(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldSecret), v)) - }) + return predicate.OAuth2Client(sql.FieldContainsFold(FieldSecret, v)) } // RedirectUrisIsNil applies the IsNil predicate on the "redirect_uris" field. func RedirectUrisIsNil() predicate.OAuth2Client { - return predicate.OAuth2Client(func(s *sql.Selector) { - s.Where(sql.IsNull(s.C(FieldRedirectUris))) - }) + return predicate.OAuth2Client(sql.FieldIsNull(FieldRedirectUris)) } // RedirectUrisNotNil applies the NotNil predicate on the "redirect_uris" field. func RedirectUrisNotNil() predicate.OAuth2Client { - return predicate.OAuth2Client(func(s *sql.Selector) { - s.Where(sql.NotNull(s.C(FieldRedirectUris))) - }) + return predicate.OAuth2Client(sql.FieldNotNull(FieldRedirectUris)) } // TrustedPeersIsNil applies the IsNil predicate on the "trusted_peers" field. func TrustedPeersIsNil() predicate.OAuth2Client { - return predicate.OAuth2Client(func(s *sql.Selector) { - s.Where(sql.IsNull(s.C(FieldTrustedPeers))) - }) + return predicate.OAuth2Client(sql.FieldIsNull(FieldTrustedPeers)) } // TrustedPeersNotNil applies the NotNil predicate on the "trusted_peers" field. func TrustedPeersNotNil() predicate.OAuth2Client { - return predicate.OAuth2Client(func(s *sql.Selector) { - s.Where(sql.NotNull(s.C(FieldTrustedPeers))) - }) + return predicate.OAuth2Client(sql.FieldNotNull(FieldTrustedPeers)) } // PublicEQ applies the EQ predicate on the "public" field. func PublicEQ(v bool) predicate.OAuth2Client { - return predicate.OAuth2Client(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldPublic), v)) - }) + return predicate.OAuth2Client(sql.FieldEQ(FieldPublic, v)) } // PublicNEQ applies the NEQ predicate on the "public" field. func PublicNEQ(v bool) predicate.OAuth2Client { - return predicate.OAuth2Client(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldPublic), v)) - }) + return predicate.OAuth2Client(sql.FieldNEQ(FieldPublic, v)) } // NameEQ applies the EQ predicate on the "name" field. func NameEQ(v string) predicate.OAuth2Client { - return predicate.OAuth2Client(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldName), v)) - }) + return predicate.OAuth2Client(sql.FieldEQ(FieldName, v)) } // NameNEQ applies the NEQ predicate on the "name" field. func NameNEQ(v string) predicate.OAuth2Client { - return predicate.OAuth2Client(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldName), v)) - }) + return predicate.OAuth2Client(sql.FieldNEQ(FieldName, v)) } // NameIn applies the In predicate on the "name" field. func NameIn(vs ...string) predicate.OAuth2Client { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.OAuth2Client(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldName), v...)) - }) + return predicate.OAuth2Client(sql.FieldIn(FieldName, vs...)) } // NameNotIn applies the NotIn predicate on the "name" field. func NameNotIn(vs ...string) predicate.OAuth2Client { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.OAuth2Client(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldName), v...)) - }) + return predicate.OAuth2Client(sql.FieldNotIn(FieldName, vs...)) } // NameGT applies the GT predicate on the "name" field. func NameGT(v string) predicate.OAuth2Client { - return predicate.OAuth2Client(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldName), v)) - }) + return predicate.OAuth2Client(sql.FieldGT(FieldName, v)) } // NameGTE applies the GTE predicate on the "name" field. func NameGTE(v string) predicate.OAuth2Client { - return predicate.OAuth2Client(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldName), v)) - }) + return predicate.OAuth2Client(sql.FieldGTE(FieldName, v)) } // NameLT applies the LT predicate on the "name" field. func NameLT(v string) predicate.OAuth2Client { - return predicate.OAuth2Client(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldName), v)) - }) + return predicate.OAuth2Client(sql.FieldLT(FieldName, v)) } // NameLTE applies the LTE predicate on the "name" field. func NameLTE(v string) predicate.OAuth2Client { - return predicate.OAuth2Client(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldName), v)) - }) + return predicate.OAuth2Client(sql.FieldLTE(FieldName, v)) } // NameContains applies the Contains predicate on the "name" field. func NameContains(v string) predicate.OAuth2Client { - return predicate.OAuth2Client(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldName), v)) - }) + return predicate.OAuth2Client(sql.FieldContains(FieldName, v)) } // NameHasPrefix applies the HasPrefix predicate on the "name" field. func NameHasPrefix(v string) predicate.OAuth2Client { - return predicate.OAuth2Client(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldName), v)) - }) + return predicate.OAuth2Client(sql.FieldHasPrefix(FieldName, v)) } // NameHasSuffix applies the HasSuffix predicate on the "name" field. func NameHasSuffix(v string) predicate.OAuth2Client { - return predicate.OAuth2Client(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldName), v)) - }) + return predicate.OAuth2Client(sql.FieldHasSuffix(FieldName, v)) } // NameEqualFold applies the EqualFold predicate on the "name" field. func NameEqualFold(v string) predicate.OAuth2Client { - return predicate.OAuth2Client(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldName), v)) - }) + return predicate.OAuth2Client(sql.FieldEqualFold(FieldName, v)) } // NameContainsFold applies the ContainsFold predicate on the "name" field. func NameContainsFold(v string) predicate.OAuth2Client { - return predicate.OAuth2Client(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldName), v)) - }) + return predicate.OAuth2Client(sql.FieldContainsFold(FieldName, v)) } // LogoURLEQ applies the EQ predicate on the "logo_url" field. func LogoURLEQ(v string) predicate.OAuth2Client { - return predicate.OAuth2Client(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldLogoURL), v)) - }) + return predicate.OAuth2Client(sql.FieldEQ(FieldLogoURL, v)) } // LogoURLNEQ applies the NEQ predicate on the "logo_url" field. func LogoURLNEQ(v string) predicate.OAuth2Client { - return predicate.OAuth2Client(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldLogoURL), v)) - }) + return predicate.OAuth2Client(sql.FieldNEQ(FieldLogoURL, v)) } // LogoURLIn applies the In predicate on the "logo_url" field. func LogoURLIn(vs ...string) predicate.OAuth2Client { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.OAuth2Client(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldLogoURL), v...)) - }) + return predicate.OAuth2Client(sql.FieldIn(FieldLogoURL, vs...)) } // LogoURLNotIn applies the NotIn predicate on the "logo_url" field. func LogoURLNotIn(vs ...string) predicate.OAuth2Client { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.OAuth2Client(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldLogoURL), v...)) - }) + return predicate.OAuth2Client(sql.FieldNotIn(FieldLogoURL, vs...)) } // LogoURLGT applies the GT predicate on the "logo_url" field. func LogoURLGT(v string) predicate.OAuth2Client { - return predicate.OAuth2Client(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldLogoURL), v)) - }) + return predicate.OAuth2Client(sql.FieldGT(FieldLogoURL, v)) } // LogoURLGTE applies the GTE predicate on the "logo_url" field. func LogoURLGTE(v string) predicate.OAuth2Client { - return predicate.OAuth2Client(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldLogoURL), v)) - }) + return predicate.OAuth2Client(sql.FieldGTE(FieldLogoURL, v)) } // LogoURLLT applies the LT predicate on the "logo_url" field. func LogoURLLT(v string) predicate.OAuth2Client { - return predicate.OAuth2Client(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldLogoURL), v)) - }) + return predicate.OAuth2Client(sql.FieldLT(FieldLogoURL, v)) } // LogoURLLTE applies the LTE predicate on the "logo_url" field. func LogoURLLTE(v string) predicate.OAuth2Client { - return predicate.OAuth2Client(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldLogoURL), v)) - }) + return predicate.OAuth2Client(sql.FieldLTE(FieldLogoURL, v)) } // LogoURLContains applies the Contains predicate on the "logo_url" field. func LogoURLContains(v string) predicate.OAuth2Client { - return predicate.OAuth2Client(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldLogoURL), v)) - }) + return predicate.OAuth2Client(sql.FieldContains(FieldLogoURL, v)) } // LogoURLHasPrefix applies the HasPrefix predicate on the "logo_url" field. func LogoURLHasPrefix(v string) predicate.OAuth2Client { - return predicate.OAuth2Client(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldLogoURL), v)) - }) + return predicate.OAuth2Client(sql.FieldHasPrefix(FieldLogoURL, v)) } // LogoURLHasSuffix applies the HasSuffix predicate on the "logo_url" field. func LogoURLHasSuffix(v string) predicate.OAuth2Client { - return predicate.OAuth2Client(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldLogoURL), v)) - }) + return predicate.OAuth2Client(sql.FieldHasSuffix(FieldLogoURL, v)) } // LogoURLEqualFold applies the EqualFold predicate on the "logo_url" field. func LogoURLEqualFold(v string) predicate.OAuth2Client { - return predicate.OAuth2Client(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldLogoURL), v)) - }) + return predicate.OAuth2Client(sql.FieldEqualFold(FieldLogoURL, v)) } // LogoURLContainsFold applies the ContainsFold predicate on the "logo_url" field. func LogoURLContainsFold(v string) predicate.OAuth2Client { - return predicate.OAuth2Client(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldLogoURL), v)) - }) + return predicate.OAuth2Client(sql.FieldContainsFold(FieldLogoURL, v)) } // And groups predicates with the AND operator between them. diff --git a/storage/ent/db/oauth2client_create.go b/storage/ent/db/oauth2client_create.go index 02c41a83..15eef174 100644 --- a/storage/ent/db/oauth2client_create.go +++ b/storage/ent/db/oauth2client_create.go @@ -68,49 +68,7 @@ func (oc *OAuth2ClientCreate) Mutation() *OAuth2ClientMutation { // Save creates the OAuth2Client in the database. func (oc *OAuth2ClientCreate) Save(ctx context.Context) (*OAuth2Client, error) { - var ( - err error - node *OAuth2Client - ) - if len(oc.hooks) == 0 { - if err = oc.check(); err != nil { - return nil, err - } - node, err = oc.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*OAuth2ClientMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err = oc.check(); err != nil { - return nil, err - } - oc.mutation = mutation - if node, err = oc.sqlSave(ctx); err != nil { - return nil, err - } - mutation.id = &node.ID - mutation.done = true - return node, err - }) - for i := len(oc.hooks) - 1; i >= 0; i-- { - if oc.hooks[i] == nil { - return nil, fmt.Errorf("db: uninitialized hook (forgotten import db/runtime?)") - } - mut = oc.hooks[i](mut) - } - v, err := mut.Mutate(ctx, oc.mutation) - if err != nil { - return nil, err - } - nv, ok := v.(*OAuth2Client) - if !ok { - return nil, fmt.Errorf("unexpected node type %T returned from OAuth2ClientMutation", v) - } - node = nv - } - return node, err + return withHooks[*OAuth2Client, OAuth2ClientMutation](ctx, oc.sqlSave, oc.mutation, oc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -173,6 +131,9 @@ func (oc *OAuth2ClientCreate) check() error { } func (oc *OAuth2ClientCreate) sqlSave(ctx context.Context) (*OAuth2Client, error) { + if err := oc.check(); err != nil { + return nil, err + } _node, _spec := oc.createSpec() if err := sqlgraph.CreateNode(ctx, oc.driver, _spec); err != nil { if sqlgraph.IsConstraintError(err) { @@ -187,70 +148,42 @@ func (oc *OAuth2ClientCreate) sqlSave(ctx context.Context) (*OAuth2Client, error return nil, fmt.Errorf("unexpected OAuth2Client.ID type: %T", _spec.ID.Value) } } + oc.mutation.id = &_node.ID + oc.mutation.done = true return _node, nil } func (oc *OAuth2ClientCreate) createSpec() (*OAuth2Client, *sqlgraph.CreateSpec) { var ( _node = &OAuth2Client{config: oc.config} - _spec = &sqlgraph.CreateSpec{ - Table: oauth2client.Table, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeString, - Column: oauth2client.FieldID, - }, - } + _spec = sqlgraph.NewCreateSpec(oauth2client.Table, sqlgraph.NewFieldSpec(oauth2client.FieldID, field.TypeString)) ) if id, ok := oc.mutation.ID(); ok { _node.ID = id _spec.ID.Value = id } if value, ok := oc.mutation.Secret(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: oauth2client.FieldSecret, - }) + _spec.SetField(oauth2client.FieldSecret, field.TypeString, value) _node.Secret = value } if value, ok := oc.mutation.RedirectUris(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeJSON, - Value: value, - Column: oauth2client.FieldRedirectUris, - }) + _spec.SetField(oauth2client.FieldRedirectUris, field.TypeJSON, value) _node.RedirectUris = value } if value, ok := oc.mutation.TrustedPeers(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeJSON, - Value: value, - Column: oauth2client.FieldTrustedPeers, - }) + _spec.SetField(oauth2client.FieldTrustedPeers, field.TypeJSON, value) _node.TrustedPeers = value } if value, ok := oc.mutation.Public(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeBool, - Value: value, - Column: oauth2client.FieldPublic, - }) + _spec.SetField(oauth2client.FieldPublic, field.TypeBool, value) _node.Public = value } if value, ok := oc.mutation.Name(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: oauth2client.FieldName, - }) + _spec.SetField(oauth2client.FieldName, field.TypeString, value) _node.Name = value } if value, ok := oc.mutation.LogoURL(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: oauth2client.FieldLogoURL, - }) + _spec.SetField(oauth2client.FieldLogoURL, field.TypeString, value) _node.LogoURL = value } return _node, _spec diff --git a/storage/ent/db/oauth2client_delete.go b/storage/ent/db/oauth2client_delete.go index 239d904d..c53e032a 100644 --- a/storage/ent/db/oauth2client_delete.go +++ b/storage/ent/db/oauth2client_delete.go @@ -4,7 +4,6 @@ package db import ( "context" - "fmt" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" @@ -28,34 +27,7 @@ func (od *OAuth2ClientDelete) Where(ps ...predicate.OAuth2Client) *OAuth2ClientD // Exec executes the deletion query and returns how many vertices were deleted. func (od *OAuth2ClientDelete) Exec(ctx context.Context) (int, error) { - var ( - err error - affected int - ) - if len(od.hooks) == 0 { - affected, err = od.sqlExec(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*OAuth2ClientMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - od.mutation = mutation - affected, err = od.sqlExec(ctx) - mutation.done = true - return affected, err - }) - for i := len(od.hooks) - 1; i >= 0; i-- { - if od.hooks[i] == nil { - return 0, fmt.Errorf("db: uninitialized hook (forgotten import db/runtime?)") - } - mut = od.hooks[i](mut) - } - if _, err := mut.Mutate(ctx, od.mutation); err != nil { - return 0, err - } - } - return affected, err + return withHooks[int, OAuth2ClientMutation](ctx, od.sqlExec, od.mutation, od.hooks) } // ExecX is like Exec, but panics if an error occurs. @@ -68,15 +40,7 @@ func (od *OAuth2ClientDelete) ExecX(ctx context.Context) int { } func (od *OAuth2ClientDelete) sqlExec(ctx context.Context) (int, error) { - _spec := &sqlgraph.DeleteSpec{ - Node: &sqlgraph.NodeSpec{ - Table: oauth2client.Table, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeString, - Column: oauth2client.FieldID, - }, - }, - } + _spec := sqlgraph.NewDeleteSpec(oauth2client.Table, sqlgraph.NewFieldSpec(oauth2client.FieldID, field.TypeString)) if ps := od.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { @@ -88,6 +52,7 @@ func (od *OAuth2ClientDelete) sqlExec(ctx context.Context) (int, error) { if err != nil && sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } + od.mutation.done = true return affected, err } @@ -96,6 +61,12 @@ type OAuth2ClientDeleteOne struct { od *OAuth2ClientDelete } +// Where appends a list predicates to the OAuth2ClientDelete builder. +func (odo *OAuth2ClientDeleteOne) Where(ps ...predicate.OAuth2Client) *OAuth2ClientDeleteOne { + odo.od.mutation.Where(ps...) + return odo +} + // Exec executes the deletion query. func (odo *OAuth2ClientDeleteOne) Exec(ctx context.Context) error { n, err := odo.od.Exec(ctx) @@ -111,5 +82,7 @@ func (odo *OAuth2ClientDeleteOne) Exec(ctx context.Context) error { // ExecX is like Exec, but panics if an error occurs. func (odo *OAuth2ClientDeleteOne) ExecX(ctx context.Context) { - odo.od.ExecX(ctx) + if err := odo.Exec(ctx); err != nil { + panic(err) + } } diff --git a/storage/ent/db/oauth2client_query.go b/storage/ent/db/oauth2client_query.go index 1776c943..9b04b088 100644 --- a/storage/ent/db/oauth2client_query.go +++ b/storage/ent/db/oauth2client_query.go @@ -17,11 +17,9 @@ import ( // OAuth2ClientQuery is the builder for querying OAuth2Client entities. type OAuth2ClientQuery struct { config - limit *int - offset *int - unique *bool + ctx *QueryContext order []OrderFunc - fields []string + inters []Interceptor predicates []predicate.OAuth2Client // intermediate query (i.e. traversal path). sql *sql.Selector @@ -34,26 +32,26 @@ func (oq *OAuth2ClientQuery) Where(ps ...predicate.OAuth2Client) *OAuth2ClientQu return oq } -// Limit adds a limit step to the query. +// Limit the number of records to be returned by this query. func (oq *OAuth2ClientQuery) Limit(limit int) *OAuth2ClientQuery { - oq.limit = &limit + oq.ctx.Limit = &limit return oq } -// Offset adds an offset step to the query. +// Offset to start from. func (oq *OAuth2ClientQuery) Offset(offset int) *OAuth2ClientQuery { - oq.offset = &offset + oq.ctx.Offset = &offset return oq } // Unique configures the query builder to filter duplicate records on query. // By default, unique is set to true, and can be disabled using this method. func (oq *OAuth2ClientQuery) Unique(unique bool) *OAuth2ClientQuery { - oq.unique = &unique + oq.ctx.Unique = &unique return oq } -// Order adds an order step to the query. +// Order specifies how the records should be ordered. func (oq *OAuth2ClientQuery) Order(o ...OrderFunc) *OAuth2ClientQuery { oq.order = append(oq.order, o...) return oq @@ -62,7 +60,7 @@ func (oq *OAuth2ClientQuery) Order(o ...OrderFunc) *OAuth2ClientQuery { // First returns the first OAuth2Client entity from the query. // Returns a *NotFoundError when no OAuth2Client was found. func (oq *OAuth2ClientQuery) First(ctx context.Context) (*OAuth2Client, error) { - nodes, err := oq.Limit(1).All(ctx) + nodes, err := oq.Limit(1).All(setContextOp(ctx, oq.ctx, "First")) if err != nil { return nil, err } @@ -85,7 +83,7 @@ func (oq *OAuth2ClientQuery) FirstX(ctx context.Context) *OAuth2Client { // Returns a *NotFoundError when no OAuth2Client ID was found. func (oq *OAuth2ClientQuery) FirstID(ctx context.Context) (id string, err error) { var ids []string - if ids, err = oq.Limit(1).IDs(ctx); err != nil { + if ids, err = oq.Limit(1).IDs(setContextOp(ctx, oq.ctx, "FirstID")); err != nil { return } if len(ids) == 0 { @@ -108,7 +106,7 @@ func (oq *OAuth2ClientQuery) FirstIDX(ctx context.Context) string { // 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) + nodes, err := oq.Limit(2).All(setContextOp(ctx, oq.ctx, "Only")) if err != nil { return nil, err } @@ -136,7 +134,7 @@ func (oq *OAuth2ClientQuery) OnlyX(ctx context.Context) *OAuth2Client { // Returns a *NotFoundError when no entities are found. func (oq *OAuth2ClientQuery) OnlyID(ctx context.Context) (id string, err error) { var ids []string - if ids, err = oq.Limit(2).IDs(ctx); err != nil { + if ids, err = oq.Limit(2).IDs(setContextOp(ctx, oq.ctx, "OnlyID")); err != nil { return } switch len(ids) { @@ -161,10 +159,12 @@ func (oq *OAuth2ClientQuery) OnlyIDX(ctx context.Context) string { // All executes the query and returns a list of OAuth2Clients. func (oq *OAuth2ClientQuery) All(ctx context.Context) ([]*OAuth2Client, error) { + ctx = setContextOp(ctx, oq.ctx, "All") if err := oq.prepareQuery(ctx); err != nil { return nil, err } - return oq.sqlAll(ctx) + qr := querierAll[[]*OAuth2Client, *OAuth2ClientQuery]() + return withInterceptors[[]*OAuth2Client](ctx, oq, qr, oq.inters) } // AllX is like All, but panics if an error occurs. @@ -177,9 +177,12 @@ func (oq *OAuth2ClientQuery) AllX(ctx context.Context) []*OAuth2Client { } // IDs executes the query and returns a list of OAuth2Client IDs. -func (oq *OAuth2ClientQuery) IDs(ctx context.Context) ([]string, error) { - var ids []string - if err := oq.Select(oauth2client.FieldID).Scan(ctx, &ids); err != nil { +func (oq *OAuth2ClientQuery) IDs(ctx context.Context) (ids []string, err error) { + if oq.ctx.Unique == nil && oq.path != nil { + oq.Unique(true) + } + ctx = setContextOp(ctx, oq.ctx, "IDs") + if err = oq.Select(oauth2client.FieldID).Scan(ctx, &ids); err != nil { return nil, err } return ids, nil @@ -196,10 +199,11 @@ func (oq *OAuth2ClientQuery) IDsX(ctx context.Context) []string { // Count returns the count of the given query. func (oq *OAuth2ClientQuery) Count(ctx context.Context) (int, error) { + ctx = setContextOp(ctx, oq.ctx, "Count") if err := oq.prepareQuery(ctx); err != nil { return 0, err } - return oq.sqlCount(ctx) + return withInterceptors[int](ctx, oq, querierCount[*OAuth2ClientQuery](), oq.inters) } // CountX is like Count, but panics if an error occurs. @@ -213,10 +217,15 @@ func (oq *OAuth2ClientQuery) CountX(ctx context.Context) int { // Exist returns true if the query has elements in the graph. func (oq *OAuth2ClientQuery) Exist(ctx context.Context) (bool, error) { - if err := oq.prepareQuery(ctx); err != nil { - return false, err + ctx = setContextOp(ctx, oq.ctx, "Exist") + switch _, err := oq.FirstID(ctx); { + case IsNotFound(err): + return false, nil + case err != nil: + return false, fmt.Errorf("db: check existence: %w", err) + default: + return true, nil } - return oq.sqlExist(ctx) } // ExistX is like Exist, but panics if an error occurs. @@ -236,14 +245,13 @@ func (oq *OAuth2ClientQuery) Clone() *OAuth2ClientQuery { } return &OAuth2ClientQuery{ config: oq.config, - limit: oq.limit, - offset: oq.offset, + ctx: oq.ctx.Clone(), order: append([]OrderFunc{}, oq.order...), + inters: append([]Interceptor{}, oq.inters...), predicates: append([]predicate.OAuth2Client{}, oq.predicates...), // clone intermediate query. - sql: oq.sql.Clone(), - path: oq.path, - unique: oq.unique, + sql: oq.sql.Clone(), + path: oq.path, } } @@ -261,18 +269,12 @@ func (oq *OAuth2ClientQuery) Clone() *OAuth2ClientQuery { // GroupBy(oauth2client.FieldSecret). // Aggregate(db.Count()). // Scan(ctx, &v) -// func (oq *OAuth2ClientQuery) GroupBy(field string, fields ...string) *OAuth2ClientGroupBy { - grbuild := &OAuth2ClientGroupBy{config: oq.config} - grbuild.fields = append([]string{field}, fields...) - grbuild.path = func(ctx context.Context) (prev *sql.Selector, err error) { - if err := oq.prepareQuery(ctx); err != nil { - return nil, err - } - return oq.sqlQuery(ctx), nil - } + oq.ctx.Fields = append([]string{field}, fields...) + grbuild := &OAuth2ClientGroupBy{build: oq} + grbuild.flds = &oq.ctx.Fields grbuild.label = oauth2client.Label - grbuild.flds, grbuild.scan = &grbuild.fields, grbuild.Scan + grbuild.scan = grbuild.Scan return grbuild } @@ -288,17 +290,31 @@ func (oq *OAuth2ClientQuery) GroupBy(field string, fields ...string) *OAuth2Clie // client.OAuth2Client.Query(). // Select(oauth2client.FieldSecret). // Scan(ctx, &v) -// func (oq *OAuth2ClientQuery) Select(fields ...string) *OAuth2ClientSelect { - oq.fields = append(oq.fields, fields...) - selbuild := &OAuth2ClientSelect{OAuth2ClientQuery: oq} - selbuild.label = oauth2client.Label - selbuild.flds, selbuild.scan = &oq.fields, selbuild.Scan - return selbuild + oq.ctx.Fields = append(oq.ctx.Fields, fields...) + sbuild := &OAuth2ClientSelect{OAuth2ClientQuery: oq} + sbuild.label = oauth2client.Label + sbuild.flds, sbuild.scan = &oq.ctx.Fields, sbuild.Scan + return sbuild +} + +// Aggregate returns a OAuth2ClientSelect configured with the given aggregations. +func (oq *OAuth2ClientQuery) Aggregate(fns ...AggregateFunc) *OAuth2ClientSelect { + return oq.Select().Aggregate(fns...) } func (oq *OAuth2ClientQuery) prepareQuery(ctx context.Context) error { - for _, f := range oq.fields { + for _, inter := range oq.inters { + if inter == nil { + return fmt.Errorf("db: uninitialized interceptor (forgotten import db/runtime?)") + } + if trv, ok := inter.(Traverser); ok { + if err := trv.Traverse(ctx, oq); err != nil { + return err + } + } + } + for _, f := range oq.ctx.Fields { if !oauth2client.ValidColumn(f) { return &ValidationError{Name: f, err: fmt.Errorf("db: invalid field %q for query", f)} } @@ -318,10 +334,10 @@ func (oq *OAuth2ClientQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([] nodes = []*OAuth2Client{} _spec = oq.querySpec() ) - _spec.ScanValues = func(columns []string) ([]interface{}, error) { + _spec.ScanValues = func(columns []string) ([]any, error) { return (*OAuth2Client).scanValues(nil, columns) } - _spec.Assign = func(columns []string, values []interface{}) error { + _spec.Assign = func(columns []string, values []any) error { node := &OAuth2Client{config: oq.config} nodes = append(nodes, node) return node.assignValues(columns, values) @@ -340,38 +356,22 @@ func (oq *OAuth2ClientQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([] 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 + _spec.Node.Columns = oq.ctx.Fields + if len(oq.ctx.Fields) > 0 { + _spec.Unique = oq.ctx.Unique != nil && *oq.ctx.Unique } return sqlgraph.CountNodes(ctx, oq.driver, _spec) } -func (oq *OAuth2ClientQuery) sqlExist(ctx context.Context) (bool, error) { - n, err := oq.sqlCount(ctx) - if err != nil { - return false, fmt.Errorf("db: check existence: %w", err) - } - return n > 0, nil -} - func (oq *OAuth2ClientQuery) querySpec() *sqlgraph.QuerySpec { - _spec := &sqlgraph.QuerySpec{ - Node: &sqlgraph.NodeSpec{ - Table: oauth2client.Table, - Columns: oauth2client.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeString, - Column: oauth2client.FieldID, - }, - }, - From: oq.sql, - Unique: true, - } - if unique := oq.unique; unique != nil { + _spec := sqlgraph.NewQuerySpec(oauth2client.Table, oauth2client.Columns, sqlgraph.NewFieldSpec(oauth2client.FieldID, field.TypeString)) + _spec.From = oq.sql + if unique := oq.ctx.Unique; unique != nil { _spec.Unique = *unique + } else if oq.path != nil { + _spec.Unique = true } - if fields := oq.fields; len(fields) > 0 { + if fields := oq.ctx.Fields; len(fields) > 0 { _spec.Node.Columns = make([]string, 0, len(fields)) _spec.Node.Columns = append(_spec.Node.Columns, oauth2client.FieldID) for i := range fields { @@ -387,10 +387,10 @@ func (oq *OAuth2ClientQuery) querySpec() *sqlgraph.QuerySpec { } } } - if limit := oq.limit; limit != nil { + if limit := oq.ctx.Limit; limit != nil { _spec.Limit = *limit } - if offset := oq.offset; offset != nil { + if offset := oq.ctx.Offset; offset != nil { _spec.Offset = *offset } if ps := oq.order; len(ps) > 0 { @@ -406,7 +406,7 @@ func (oq *OAuth2ClientQuery) querySpec() *sqlgraph.QuerySpec { func (oq *OAuth2ClientQuery) sqlQuery(ctx context.Context) *sql.Selector { builder := sql.Dialect(oq.driver.Dialect()) t1 := builder.Table(oauth2client.Table) - columns := oq.fields + columns := oq.ctx.Fields if len(columns) == 0 { columns = oauth2client.Columns } @@ -415,7 +415,7 @@ func (oq *OAuth2ClientQuery) sqlQuery(ctx context.Context) *sql.Selector { selector = oq.sql selector.Select(selector.Columns(columns...)...) } - if oq.unique != nil && *oq.unique { + if oq.ctx.Unique != nil && *oq.ctx.Unique { selector.Distinct() } for _, p := range oq.predicates { @@ -424,12 +424,12 @@ func (oq *OAuth2ClientQuery) sqlQuery(ctx context.Context) *sql.Selector { for _, p := range oq.order { p(selector) } - if offset := oq.offset; offset != nil { + if offset := oq.ctx.Offset; offset != nil { // limit is mandatory for offset clause. We start // with default value, and override it below if needed. selector.Offset(*offset).Limit(math.MaxInt32) } - if limit := oq.limit; limit != nil { + if limit := oq.ctx.Limit; limit != nil { selector.Limit(*limit) } return selector @@ -437,13 +437,8 @@ func (oq *OAuth2ClientQuery) sqlQuery(ctx context.Context) *sql.Selector { // OAuth2ClientGroupBy is the group-by builder for OAuth2Client entities. type OAuth2ClientGroupBy struct { - config selector - fields []string - fns []AggregateFunc - // intermediate query (i.e. traversal path). - sql *sql.Selector - path func(context.Context) (*sql.Selector, error) + build *OAuth2ClientQuery } // Aggregate adds the given aggregation functions to the group-by query. @@ -452,74 +447,77 @@ func (ogb *OAuth2ClientGroupBy) Aggregate(fns ...AggregateFunc) *OAuth2ClientGro return ogb } -// Scan applies the group-by query and scans the result into the given value. -func (ogb *OAuth2ClientGroupBy) Scan(ctx context.Context, v interface{}) error { - query, err := ogb.path(ctx) - if err != nil { +// Scan applies the selector query and scans the result into the given value. +func (ogb *OAuth2ClientGroupBy) Scan(ctx context.Context, v any) error { + ctx = setContextOp(ctx, ogb.build.ctx, "GroupBy") + if err := ogb.build.prepareQuery(ctx); err != nil { return err } - ogb.sql = query - return ogb.sqlScan(ctx, v) + return scanWithInterceptors[*OAuth2ClientQuery, *OAuth2ClientGroupBy](ctx, ogb.build, ogb, ogb.build.inters, v) } -func (ogb *OAuth2ClientGroupBy) sqlScan(ctx context.Context, v interface{}) error { - for _, f := range ogb.fields { - if !oauth2client.ValidColumn(f) { - return &ValidationError{Name: f, err: fmt.Errorf("invalid field %q for group-by", f)} - } - } - selector := ogb.sqlQuery() - if err := selector.Err(); err != nil { - return err - } - rows := &sql.Rows{} - query, args := selector.Query() - if err := ogb.driver.Query(ctx, query, args, rows); err != nil { - return err - } - defer rows.Close() - return sql.ScanSlice(rows, v) -} - -func (ogb *OAuth2ClientGroupBy) sqlQuery() *sql.Selector { - selector := ogb.sql.Select() +func (ogb *OAuth2ClientGroupBy) sqlScan(ctx context.Context, root *OAuth2ClientQuery, v any) error { + selector := root.sqlQuery(ctx).Select() aggregation := make([]string, 0, len(ogb.fns)) for _, fn := range ogb.fns { aggregation = append(aggregation, fn(selector)) } - // If no columns were selected in a custom aggregation function, the default - // selection is the fields used for "group-by", and the aggregation functions. if len(selector.SelectedColumns()) == 0 { - columns := make([]string, 0, len(ogb.fields)+len(ogb.fns)) - for _, f := range ogb.fields { + columns := make([]string, 0, len(*ogb.flds)+len(ogb.fns)) + for _, f := range *ogb.flds { columns = append(columns, selector.C(f)) } columns = append(columns, aggregation...) selector.Select(columns...) } - return selector.GroupBy(selector.Columns(ogb.fields...)...) + selector.GroupBy(selector.Columns(*ogb.flds...)...) + if err := selector.Err(); err != nil { + return err + } + rows := &sql.Rows{} + query, args := selector.Query() + if err := ogb.build.driver.Query(ctx, query, args, rows); err != nil { + return err + } + defer rows.Close() + return sql.ScanSlice(rows, v) } // OAuth2ClientSelect is the builder for selecting fields of OAuth2Client entities. type OAuth2ClientSelect struct { *OAuth2ClientQuery selector - // intermediate query (i.e. traversal path). - sql *sql.Selector +} + +// Aggregate adds the given aggregation functions to the selector query. +func (os *OAuth2ClientSelect) Aggregate(fns ...AggregateFunc) *OAuth2ClientSelect { + os.fns = append(os.fns, fns...) + return os } // Scan applies the selector query and scans the result into the given value. -func (os *OAuth2ClientSelect) Scan(ctx context.Context, v interface{}) error { +func (os *OAuth2ClientSelect) Scan(ctx context.Context, v any) error { + ctx = setContextOp(ctx, os.ctx, "Select") if err := os.prepareQuery(ctx); err != nil { return err } - os.sql = os.OAuth2ClientQuery.sqlQuery(ctx) - return os.sqlScan(ctx, v) + return scanWithInterceptors[*OAuth2ClientQuery, *OAuth2ClientSelect](ctx, os.OAuth2ClientQuery, os, os.inters, v) } -func (os *OAuth2ClientSelect) sqlScan(ctx context.Context, v interface{}) error { +func (os *OAuth2ClientSelect) sqlScan(ctx context.Context, root *OAuth2ClientQuery, v any) error { + selector := root.sqlQuery(ctx) + aggregation := make([]string, 0, len(os.fns)) + for _, fn := range os.fns { + aggregation = append(aggregation, fn(selector)) + } + switch n := len(*os.selector.flds); { + case n == 0 && len(aggregation) > 0: + selector.Select(aggregation...) + case n != 0 && len(aggregation) > 0: + selector.AppendSelect(aggregation...) + } rows := &sql.Rows{} - query, args := os.sql.Query() + query, args := selector.Query() if err := os.driver.Query(ctx, query, args, rows); err != nil { return err } diff --git a/storage/ent/db/oauth2client_update.go b/storage/ent/db/oauth2client_update.go index aeddbba6..aa272911 100644 --- a/storage/ent/db/oauth2client_update.go +++ b/storage/ent/db/oauth2client_update.go @@ -9,6 +9,7 @@ import ( "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/dialect/sql/sqljson" "entgo.io/ent/schema/field" "github.com/dexidp/dex/storage/ent/db/oauth2client" "github.com/dexidp/dex/storage/ent/db/predicate" @@ -39,6 +40,12 @@ func (ou *OAuth2ClientUpdate) SetRedirectUris(s []string) *OAuth2ClientUpdate { return ou } +// AppendRedirectUris appends s to the "redirect_uris" field. +func (ou *OAuth2ClientUpdate) AppendRedirectUris(s []string) *OAuth2ClientUpdate { + ou.mutation.AppendRedirectUris(s) + return ou +} + // ClearRedirectUris clears the value of the "redirect_uris" field. func (ou *OAuth2ClientUpdate) ClearRedirectUris() *OAuth2ClientUpdate { ou.mutation.ClearRedirectUris() @@ -51,6 +58,12 @@ func (ou *OAuth2ClientUpdate) SetTrustedPeers(s []string) *OAuth2ClientUpdate { return ou } +// AppendTrustedPeers appends s to the "trusted_peers" field. +func (ou *OAuth2ClientUpdate) AppendTrustedPeers(s []string) *OAuth2ClientUpdate { + ou.mutation.AppendTrustedPeers(s) + return ou +} + // ClearTrustedPeers clears the value of the "trusted_peers" field. func (ou *OAuth2ClientUpdate) ClearTrustedPeers() *OAuth2ClientUpdate { ou.mutation.ClearTrustedPeers() @@ -82,40 +95,7 @@ func (ou *OAuth2ClientUpdate) Mutation() *OAuth2ClientMutation { // Save executes the query and returns the number of nodes affected by the update operation. func (ou *OAuth2ClientUpdate) Save(ctx context.Context) (int, error) { - var ( - err error - affected int - ) - if len(ou.hooks) == 0 { - if err = ou.check(); err != nil { - return 0, err - } - affected, err = ou.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*OAuth2ClientMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err = ou.check(); err != nil { - return 0, err - } - ou.mutation = mutation - affected, err = ou.sqlSave(ctx) - mutation.done = true - return affected, err - }) - for i := len(ou.hooks) - 1; i >= 0; i-- { - if ou.hooks[i] == nil { - return 0, fmt.Errorf("db: uninitialized hook (forgotten import db/runtime?)") - } - mut = ou.hooks[i](mut) - } - if _, err := mut.Mutate(ctx, ou.mutation); err != nil { - return 0, err - } - } - return affected, err + return withHooks[int, OAuth2ClientMutation](ctx, ou.sqlSave, ou.mutation, ou.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -161,16 +141,10 @@ func (ou *OAuth2ClientUpdate) check() error { } func (ou *OAuth2ClientUpdate) sqlSave(ctx context.Context) (n int, err error) { - _spec := &sqlgraph.UpdateSpec{ - Node: &sqlgraph.NodeSpec{ - Table: oauth2client.Table, - Columns: oauth2client.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeString, - Column: oauth2client.FieldID, - }, - }, + if err := ou.check(); err != nil { + return n, err } + _spec := sqlgraph.NewUpdateSpec(oauth2client.Table, oauth2client.Columns, sqlgraph.NewFieldSpec(oauth2client.FieldID, field.TypeString)) if ps := ou.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { @@ -179,58 +153,38 @@ func (ou *OAuth2ClientUpdate) sqlSave(ctx context.Context) (n int, err error) { } } if value, ok := ou.mutation.Secret(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: oauth2client.FieldSecret, - }) + _spec.SetField(oauth2client.FieldSecret, field.TypeString, value) } if value, ok := ou.mutation.RedirectUris(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeJSON, - Value: value, - Column: oauth2client.FieldRedirectUris, + _spec.SetField(oauth2client.FieldRedirectUris, field.TypeJSON, value) + } + if value, ok := ou.mutation.AppendedRedirectUris(); ok { + _spec.AddModifier(func(u *sql.UpdateBuilder) { + sqljson.Append(u, oauth2client.FieldRedirectUris, value) }) } if ou.mutation.RedirectUrisCleared() { - _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ - Type: field.TypeJSON, - Column: oauth2client.FieldRedirectUris, - }) + _spec.ClearField(oauth2client.FieldRedirectUris, field.TypeJSON) } if value, ok := ou.mutation.TrustedPeers(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeJSON, - Value: value, - Column: oauth2client.FieldTrustedPeers, + _spec.SetField(oauth2client.FieldTrustedPeers, field.TypeJSON, value) + } + if value, ok := ou.mutation.AppendedTrustedPeers(); ok { + _spec.AddModifier(func(u *sql.UpdateBuilder) { + sqljson.Append(u, oauth2client.FieldTrustedPeers, value) }) } if ou.mutation.TrustedPeersCleared() { - _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ - Type: field.TypeJSON, - Column: oauth2client.FieldTrustedPeers, - }) + _spec.ClearField(oauth2client.FieldTrustedPeers, field.TypeJSON) } if value, ok := ou.mutation.Public(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeBool, - Value: value, - Column: oauth2client.FieldPublic, - }) + _spec.SetField(oauth2client.FieldPublic, field.TypeBool, value) } if value, ok := ou.mutation.Name(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: oauth2client.FieldName, - }) + _spec.SetField(oauth2client.FieldName, field.TypeString, value) } if value, ok := ou.mutation.LogoURL(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: oauth2client.FieldLogoURL, - }) + _spec.SetField(oauth2client.FieldLogoURL, field.TypeString, value) } if n, err = sqlgraph.UpdateNodes(ctx, ou.driver, _spec); err != nil { if _, ok := err.(*sqlgraph.NotFoundError); ok { @@ -240,6 +194,7 @@ func (ou *OAuth2ClientUpdate) sqlSave(ctx context.Context) (n int, err error) { } return 0, err } + ou.mutation.done = true return n, nil } @@ -263,6 +218,12 @@ func (ouo *OAuth2ClientUpdateOne) SetRedirectUris(s []string) *OAuth2ClientUpdat return ouo } +// AppendRedirectUris appends s to the "redirect_uris" field. +func (ouo *OAuth2ClientUpdateOne) AppendRedirectUris(s []string) *OAuth2ClientUpdateOne { + ouo.mutation.AppendRedirectUris(s) + return ouo +} + // ClearRedirectUris clears the value of the "redirect_uris" field. func (ouo *OAuth2ClientUpdateOne) ClearRedirectUris() *OAuth2ClientUpdateOne { ouo.mutation.ClearRedirectUris() @@ -275,6 +236,12 @@ func (ouo *OAuth2ClientUpdateOne) SetTrustedPeers(s []string) *OAuth2ClientUpdat return ouo } +// AppendTrustedPeers appends s to the "trusted_peers" field. +func (ouo *OAuth2ClientUpdateOne) AppendTrustedPeers(s []string) *OAuth2ClientUpdateOne { + ouo.mutation.AppendTrustedPeers(s) + return ouo +} + // ClearTrustedPeers clears the value of the "trusted_peers" field. func (ouo *OAuth2ClientUpdateOne) ClearTrustedPeers() *OAuth2ClientUpdateOne { ouo.mutation.ClearTrustedPeers() @@ -304,6 +271,12 @@ func (ouo *OAuth2ClientUpdateOne) Mutation() *OAuth2ClientMutation { return ouo.mutation } +// Where appends a list predicates to the OAuth2ClientUpdate builder. +func (ouo *OAuth2ClientUpdateOne) Where(ps ...predicate.OAuth2Client) *OAuth2ClientUpdateOne { + ouo.mutation.Where(ps...) + return ouo +} + // Select allows selecting one or more fields (columns) of the returned entity. // The default is selecting all fields defined in the entity schema. func (ouo *OAuth2ClientUpdateOne) Select(field string, fields ...string) *OAuth2ClientUpdateOne { @@ -313,46 +286,7 @@ func (ouo *OAuth2ClientUpdateOne) Select(field string, fields ...string) *OAuth2 // Save executes the query and returns the updated OAuth2Client entity. func (ouo *OAuth2ClientUpdateOne) Save(ctx context.Context) (*OAuth2Client, error) { - var ( - err error - node *OAuth2Client - ) - if len(ouo.hooks) == 0 { - if err = ouo.check(); err != nil { - return nil, err - } - node, err = ouo.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*OAuth2ClientMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err = ouo.check(); err != nil { - return nil, err - } - ouo.mutation = mutation - node, err = ouo.sqlSave(ctx) - mutation.done = true - return node, err - }) - for i := len(ouo.hooks) - 1; i >= 0; i-- { - if ouo.hooks[i] == nil { - return nil, fmt.Errorf("db: uninitialized hook (forgotten import db/runtime?)") - } - mut = ouo.hooks[i](mut) - } - v, err := mut.Mutate(ctx, ouo.mutation) - if err != nil { - return nil, err - } - nv, ok := v.(*OAuth2Client) - if !ok { - return nil, fmt.Errorf("unexpected node type %T returned from OAuth2ClientMutation", v) - } - node = nv - } - return node, err + return withHooks[*OAuth2Client, OAuth2ClientMutation](ctx, ouo.sqlSave, ouo.mutation, ouo.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -398,16 +332,10 @@ func (ouo *OAuth2ClientUpdateOne) check() error { } func (ouo *OAuth2ClientUpdateOne) sqlSave(ctx context.Context) (_node *OAuth2Client, err error) { - _spec := &sqlgraph.UpdateSpec{ - Node: &sqlgraph.NodeSpec{ - Table: oauth2client.Table, - Columns: oauth2client.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeString, - Column: oauth2client.FieldID, - }, - }, + if err := ouo.check(); err != nil { + return _node, err } + _spec := sqlgraph.NewUpdateSpec(oauth2client.Table, oauth2client.Columns, sqlgraph.NewFieldSpec(oauth2client.FieldID, field.TypeString)) id, ok := ouo.mutation.ID() if !ok { return nil, &ValidationError{Name: "id", err: errors.New(`db: missing "OAuth2Client.id" for update`)} @@ -433,58 +361,38 @@ func (ouo *OAuth2ClientUpdateOne) sqlSave(ctx context.Context) (_node *OAuth2Cli } } if value, ok := ouo.mutation.Secret(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: oauth2client.FieldSecret, - }) + _spec.SetField(oauth2client.FieldSecret, field.TypeString, value) } if value, ok := ouo.mutation.RedirectUris(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeJSON, - Value: value, - Column: oauth2client.FieldRedirectUris, + _spec.SetField(oauth2client.FieldRedirectUris, field.TypeJSON, value) + } + if value, ok := ouo.mutation.AppendedRedirectUris(); ok { + _spec.AddModifier(func(u *sql.UpdateBuilder) { + sqljson.Append(u, oauth2client.FieldRedirectUris, value) }) } if ouo.mutation.RedirectUrisCleared() { - _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ - Type: field.TypeJSON, - Column: oauth2client.FieldRedirectUris, - }) + _spec.ClearField(oauth2client.FieldRedirectUris, field.TypeJSON) } if value, ok := ouo.mutation.TrustedPeers(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeJSON, - Value: value, - Column: oauth2client.FieldTrustedPeers, + _spec.SetField(oauth2client.FieldTrustedPeers, field.TypeJSON, value) + } + if value, ok := ouo.mutation.AppendedTrustedPeers(); ok { + _spec.AddModifier(func(u *sql.UpdateBuilder) { + sqljson.Append(u, oauth2client.FieldTrustedPeers, value) }) } if ouo.mutation.TrustedPeersCleared() { - _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ - Type: field.TypeJSON, - Column: oauth2client.FieldTrustedPeers, - }) + _spec.ClearField(oauth2client.FieldTrustedPeers, field.TypeJSON) } if value, ok := ouo.mutation.Public(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeBool, - Value: value, - Column: oauth2client.FieldPublic, - }) + _spec.SetField(oauth2client.FieldPublic, field.TypeBool, value) } if value, ok := ouo.mutation.Name(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: oauth2client.FieldName, - }) + _spec.SetField(oauth2client.FieldName, field.TypeString, value) } if value, ok := ouo.mutation.LogoURL(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: oauth2client.FieldLogoURL, - }) + _spec.SetField(oauth2client.FieldLogoURL, field.TypeString, value) } _node = &OAuth2Client{config: ouo.config} _spec.Assign = _node.assignValues @@ -497,5 +405,6 @@ func (ouo *OAuth2ClientUpdateOne) sqlSave(ctx context.Context) (_node *OAuth2Cli } return nil, err } + ouo.mutation.done = true return _node, nil } diff --git a/storage/ent/db/offlinesession.go b/storage/ent/db/offlinesession.go index 4b797e26..639dcf58 100644 --- a/storage/ent/db/offlinesession.go +++ b/storage/ent/db/offlinesession.go @@ -26,8 +26,8 @@ type OfflineSession struct { } // scanValues returns the types for scanning values from sql.Rows. -func (*OfflineSession) scanValues(columns []string) ([]interface{}, error) { - values := make([]interface{}, len(columns)) +func (*OfflineSession) scanValues(columns []string) ([]any, error) { + values := make([]any, len(columns)) for i := range columns { switch columns[i] { case offlinesession.FieldRefresh, offlinesession.FieldConnectorData: @@ -43,7 +43,7 @@ func (*OfflineSession) scanValues(columns []string) ([]interface{}, error) { // assignValues assigns the values that were returned from sql.Rows (after scanning) // to the OfflineSession fields. -func (os *OfflineSession) assignValues(columns []string, values []interface{}) error { +func (os *OfflineSession) assignValues(columns []string, values []any) error { if m, n := len(values), len(columns); m < n { return fmt.Errorf("mismatch number of scan values: %d != %d", m, n) } @@ -88,7 +88,7 @@ func (os *OfflineSession) assignValues(columns []string, values []interface{}) e // Note that you need to call OfflineSession.Unwrap() before calling this method if this OfflineSession // was returned from a transaction, and the transaction was committed or rolled back. func (os *OfflineSession) Update() *OfflineSessionUpdateOne { - return (&OfflineSessionClient{config: os.config}).UpdateOne(os) + return NewOfflineSessionClient(os.config).UpdateOne(os) } // Unwrap unwraps the OfflineSession entity that was returned from a transaction after it was closed, @@ -126,9 +126,3 @@ func (os *OfflineSession) String() string { // OfflineSessions is a parsable slice of OfflineSession. type OfflineSessions []*OfflineSession - -func (os OfflineSessions) config(cfg config) { - for _i := range os { - os[_i].config = cfg - } -} diff --git a/storage/ent/db/offlinesession/where.go b/storage/ent/db/offlinesession/where.go index 2dbab253..5b7266ea 100644 --- a/storage/ent/db/offlinesession/where.go +++ b/storage/ent/db/offlinesession/where.go @@ -9,441 +9,287 @@ import ( // ID filters vertices based on their ID field. func ID(id string) predicate.OfflineSession { - return predicate.OfflineSession(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldID), id)) - }) + return predicate.OfflineSession(sql.FieldEQ(FieldID, id)) } // IDEQ applies the EQ predicate on the ID field. func IDEQ(id string) predicate.OfflineSession { - return predicate.OfflineSession(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldID), id)) - }) + return predicate.OfflineSession(sql.FieldEQ(FieldID, id)) } // IDNEQ applies the NEQ predicate on the ID field. func IDNEQ(id string) predicate.OfflineSession { - return predicate.OfflineSession(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldID), id)) - }) + return predicate.OfflineSession(sql.FieldNEQ(FieldID, id)) } // IDIn applies the In predicate on the ID field. func IDIn(ids ...string) predicate.OfflineSession { - return predicate.OfflineSession(func(s *sql.Selector) { - v := make([]interface{}, len(ids)) - for i := range v { - v[i] = ids[i] - } - s.Where(sql.In(s.C(FieldID), v...)) - }) + return predicate.OfflineSession(sql.FieldIn(FieldID, ids...)) } // IDNotIn applies the NotIn predicate on the ID field. func IDNotIn(ids ...string) predicate.OfflineSession { - return predicate.OfflineSession(func(s *sql.Selector) { - v := make([]interface{}, len(ids)) - for i := range v { - v[i] = ids[i] - } - s.Where(sql.NotIn(s.C(FieldID), v...)) - }) + return predicate.OfflineSession(sql.FieldNotIn(FieldID, ids...)) } // IDGT applies the GT predicate on the ID field. func IDGT(id string) predicate.OfflineSession { - return predicate.OfflineSession(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldID), id)) - }) + return predicate.OfflineSession(sql.FieldGT(FieldID, id)) } // IDGTE applies the GTE predicate on the ID field. func IDGTE(id string) predicate.OfflineSession { - return predicate.OfflineSession(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldID), id)) - }) + return predicate.OfflineSession(sql.FieldGTE(FieldID, id)) } // IDLT applies the LT predicate on the ID field. func IDLT(id string) predicate.OfflineSession { - return predicate.OfflineSession(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldID), id)) - }) + return predicate.OfflineSession(sql.FieldLT(FieldID, id)) } // IDLTE applies the LTE predicate on the ID field. func IDLTE(id string) predicate.OfflineSession { - return predicate.OfflineSession(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldID), id)) - }) + return predicate.OfflineSession(sql.FieldLTE(FieldID, id)) } // UserID applies equality check predicate on the "user_id" field. It's identical to UserIDEQ. func UserID(v string) predicate.OfflineSession { - return predicate.OfflineSession(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldUserID), v)) - }) + return predicate.OfflineSession(sql.FieldEQ(FieldUserID, v)) } // ConnID applies equality check predicate on the "conn_id" field. It's identical to ConnIDEQ. func ConnID(v string) predicate.OfflineSession { - return predicate.OfflineSession(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldConnID), v)) - }) + return predicate.OfflineSession(sql.FieldEQ(FieldConnID, v)) } // Refresh applies equality check predicate on the "refresh" field. It's identical to RefreshEQ. func Refresh(v []byte) predicate.OfflineSession { - return predicate.OfflineSession(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldRefresh), v)) - }) + return predicate.OfflineSession(sql.FieldEQ(FieldRefresh, v)) } // ConnectorData applies equality check predicate on the "connector_data" field. It's identical to ConnectorDataEQ. func ConnectorData(v []byte) predicate.OfflineSession { - return predicate.OfflineSession(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldConnectorData), v)) - }) + return predicate.OfflineSession(sql.FieldEQ(FieldConnectorData, v)) } // UserIDEQ applies the EQ predicate on the "user_id" field. func UserIDEQ(v string) predicate.OfflineSession { - return predicate.OfflineSession(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldUserID), v)) - }) + return predicate.OfflineSession(sql.FieldEQ(FieldUserID, v)) } // UserIDNEQ applies the NEQ predicate on the "user_id" field. func UserIDNEQ(v string) predicate.OfflineSession { - return predicate.OfflineSession(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldUserID), v)) - }) + return predicate.OfflineSession(sql.FieldNEQ(FieldUserID, v)) } // UserIDIn applies the In predicate on the "user_id" field. func UserIDIn(vs ...string) predicate.OfflineSession { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.OfflineSession(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldUserID), v...)) - }) + return predicate.OfflineSession(sql.FieldIn(FieldUserID, vs...)) } // UserIDNotIn applies the NotIn predicate on the "user_id" field. func UserIDNotIn(vs ...string) predicate.OfflineSession { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.OfflineSession(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldUserID), v...)) - }) + return predicate.OfflineSession(sql.FieldNotIn(FieldUserID, vs...)) } // UserIDGT applies the GT predicate on the "user_id" field. func UserIDGT(v string) predicate.OfflineSession { - return predicate.OfflineSession(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldUserID), v)) - }) + return predicate.OfflineSession(sql.FieldGT(FieldUserID, v)) } // UserIDGTE applies the GTE predicate on the "user_id" field. func UserIDGTE(v string) predicate.OfflineSession { - return predicate.OfflineSession(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldUserID), v)) - }) + return predicate.OfflineSession(sql.FieldGTE(FieldUserID, v)) } // UserIDLT applies the LT predicate on the "user_id" field. func UserIDLT(v string) predicate.OfflineSession { - return predicate.OfflineSession(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldUserID), v)) - }) + return predicate.OfflineSession(sql.FieldLT(FieldUserID, v)) } // UserIDLTE applies the LTE predicate on the "user_id" field. func UserIDLTE(v string) predicate.OfflineSession { - return predicate.OfflineSession(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldUserID), v)) - }) + return predicate.OfflineSession(sql.FieldLTE(FieldUserID, v)) } // UserIDContains applies the Contains predicate on the "user_id" field. func UserIDContains(v string) predicate.OfflineSession { - return predicate.OfflineSession(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldUserID), v)) - }) + return predicate.OfflineSession(sql.FieldContains(FieldUserID, v)) } // UserIDHasPrefix applies the HasPrefix predicate on the "user_id" field. func UserIDHasPrefix(v string) predicate.OfflineSession { - return predicate.OfflineSession(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldUserID), v)) - }) + return predicate.OfflineSession(sql.FieldHasPrefix(FieldUserID, v)) } // UserIDHasSuffix applies the HasSuffix predicate on the "user_id" field. func UserIDHasSuffix(v string) predicate.OfflineSession { - return predicate.OfflineSession(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldUserID), v)) - }) + return predicate.OfflineSession(sql.FieldHasSuffix(FieldUserID, v)) } // UserIDEqualFold applies the EqualFold predicate on the "user_id" field. func UserIDEqualFold(v string) predicate.OfflineSession { - return predicate.OfflineSession(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldUserID), v)) - }) + return predicate.OfflineSession(sql.FieldEqualFold(FieldUserID, v)) } // UserIDContainsFold applies the ContainsFold predicate on the "user_id" field. func UserIDContainsFold(v string) predicate.OfflineSession { - return predicate.OfflineSession(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldUserID), v)) - }) + return predicate.OfflineSession(sql.FieldContainsFold(FieldUserID, v)) } // ConnIDEQ applies the EQ predicate on the "conn_id" field. func ConnIDEQ(v string) predicate.OfflineSession { - return predicate.OfflineSession(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldConnID), v)) - }) + return predicate.OfflineSession(sql.FieldEQ(FieldConnID, v)) } // ConnIDNEQ applies the NEQ predicate on the "conn_id" field. func ConnIDNEQ(v string) predicate.OfflineSession { - return predicate.OfflineSession(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldConnID), v)) - }) + return predicate.OfflineSession(sql.FieldNEQ(FieldConnID, v)) } // ConnIDIn applies the In predicate on the "conn_id" field. func ConnIDIn(vs ...string) predicate.OfflineSession { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.OfflineSession(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldConnID), v...)) - }) + return predicate.OfflineSession(sql.FieldIn(FieldConnID, vs...)) } // ConnIDNotIn applies the NotIn predicate on the "conn_id" field. func ConnIDNotIn(vs ...string) predicate.OfflineSession { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.OfflineSession(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldConnID), v...)) - }) + return predicate.OfflineSession(sql.FieldNotIn(FieldConnID, vs...)) } // ConnIDGT applies the GT predicate on the "conn_id" field. func ConnIDGT(v string) predicate.OfflineSession { - return predicate.OfflineSession(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldConnID), v)) - }) + return predicate.OfflineSession(sql.FieldGT(FieldConnID, v)) } // ConnIDGTE applies the GTE predicate on the "conn_id" field. func ConnIDGTE(v string) predicate.OfflineSession { - return predicate.OfflineSession(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldConnID), v)) - }) + return predicate.OfflineSession(sql.FieldGTE(FieldConnID, v)) } // ConnIDLT applies the LT predicate on the "conn_id" field. func ConnIDLT(v string) predicate.OfflineSession { - return predicate.OfflineSession(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldConnID), v)) - }) + return predicate.OfflineSession(sql.FieldLT(FieldConnID, v)) } // ConnIDLTE applies the LTE predicate on the "conn_id" field. func ConnIDLTE(v string) predicate.OfflineSession { - return predicate.OfflineSession(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldConnID), v)) - }) + return predicate.OfflineSession(sql.FieldLTE(FieldConnID, v)) } // ConnIDContains applies the Contains predicate on the "conn_id" field. func ConnIDContains(v string) predicate.OfflineSession { - return predicate.OfflineSession(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldConnID), v)) - }) + return predicate.OfflineSession(sql.FieldContains(FieldConnID, v)) } // ConnIDHasPrefix applies the HasPrefix predicate on the "conn_id" field. func ConnIDHasPrefix(v string) predicate.OfflineSession { - return predicate.OfflineSession(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldConnID), v)) - }) + return predicate.OfflineSession(sql.FieldHasPrefix(FieldConnID, v)) } // ConnIDHasSuffix applies the HasSuffix predicate on the "conn_id" field. func ConnIDHasSuffix(v string) predicate.OfflineSession { - return predicate.OfflineSession(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldConnID), v)) - }) + return predicate.OfflineSession(sql.FieldHasSuffix(FieldConnID, v)) } // ConnIDEqualFold applies the EqualFold predicate on the "conn_id" field. func ConnIDEqualFold(v string) predicate.OfflineSession { - return predicate.OfflineSession(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldConnID), v)) - }) + return predicate.OfflineSession(sql.FieldEqualFold(FieldConnID, v)) } // ConnIDContainsFold applies the ContainsFold predicate on the "conn_id" field. func ConnIDContainsFold(v string) predicate.OfflineSession { - return predicate.OfflineSession(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldConnID), v)) - }) + return predicate.OfflineSession(sql.FieldContainsFold(FieldConnID, v)) } // RefreshEQ applies the EQ predicate on the "refresh" field. func RefreshEQ(v []byte) predicate.OfflineSession { - return predicate.OfflineSession(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldRefresh), v)) - }) + return predicate.OfflineSession(sql.FieldEQ(FieldRefresh, v)) } // RefreshNEQ applies the NEQ predicate on the "refresh" field. func RefreshNEQ(v []byte) predicate.OfflineSession { - return predicate.OfflineSession(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldRefresh), v)) - }) + return predicate.OfflineSession(sql.FieldNEQ(FieldRefresh, v)) } // RefreshIn applies the In predicate on the "refresh" field. func RefreshIn(vs ...[]byte) predicate.OfflineSession { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.OfflineSession(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldRefresh), v...)) - }) + return predicate.OfflineSession(sql.FieldIn(FieldRefresh, vs...)) } // RefreshNotIn applies the NotIn predicate on the "refresh" field. func RefreshNotIn(vs ...[]byte) predicate.OfflineSession { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.OfflineSession(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldRefresh), v...)) - }) + return predicate.OfflineSession(sql.FieldNotIn(FieldRefresh, vs...)) } // RefreshGT applies the GT predicate on the "refresh" field. func RefreshGT(v []byte) predicate.OfflineSession { - return predicate.OfflineSession(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldRefresh), v)) - }) + return predicate.OfflineSession(sql.FieldGT(FieldRefresh, v)) } // RefreshGTE applies the GTE predicate on the "refresh" field. func RefreshGTE(v []byte) predicate.OfflineSession { - return predicate.OfflineSession(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldRefresh), v)) - }) + return predicate.OfflineSession(sql.FieldGTE(FieldRefresh, v)) } // RefreshLT applies the LT predicate on the "refresh" field. func RefreshLT(v []byte) predicate.OfflineSession { - return predicate.OfflineSession(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldRefresh), v)) - }) + return predicate.OfflineSession(sql.FieldLT(FieldRefresh, v)) } // RefreshLTE applies the LTE predicate on the "refresh" field. func RefreshLTE(v []byte) predicate.OfflineSession { - return predicate.OfflineSession(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldRefresh), v)) - }) + return predicate.OfflineSession(sql.FieldLTE(FieldRefresh, v)) } // ConnectorDataEQ applies the EQ predicate on the "connector_data" field. func ConnectorDataEQ(v []byte) predicate.OfflineSession { - return predicate.OfflineSession(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldConnectorData), v)) - }) + return predicate.OfflineSession(sql.FieldEQ(FieldConnectorData, v)) } // ConnectorDataNEQ applies the NEQ predicate on the "connector_data" field. func ConnectorDataNEQ(v []byte) predicate.OfflineSession { - return predicate.OfflineSession(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldConnectorData), v)) - }) + return predicate.OfflineSession(sql.FieldNEQ(FieldConnectorData, v)) } // ConnectorDataIn applies the In predicate on the "connector_data" field. func ConnectorDataIn(vs ...[]byte) predicate.OfflineSession { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.OfflineSession(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldConnectorData), v...)) - }) + return predicate.OfflineSession(sql.FieldIn(FieldConnectorData, vs...)) } // ConnectorDataNotIn applies the NotIn predicate on the "connector_data" field. func ConnectorDataNotIn(vs ...[]byte) predicate.OfflineSession { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.OfflineSession(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldConnectorData), v...)) - }) + return predicate.OfflineSession(sql.FieldNotIn(FieldConnectorData, vs...)) } // ConnectorDataGT applies the GT predicate on the "connector_data" field. func ConnectorDataGT(v []byte) predicate.OfflineSession { - return predicate.OfflineSession(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldConnectorData), v)) - }) + return predicate.OfflineSession(sql.FieldGT(FieldConnectorData, v)) } // ConnectorDataGTE applies the GTE predicate on the "connector_data" field. func ConnectorDataGTE(v []byte) predicate.OfflineSession { - return predicate.OfflineSession(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldConnectorData), v)) - }) + return predicate.OfflineSession(sql.FieldGTE(FieldConnectorData, v)) } // ConnectorDataLT applies the LT predicate on the "connector_data" field. func ConnectorDataLT(v []byte) predicate.OfflineSession { - return predicate.OfflineSession(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldConnectorData), v)) - }) + return predicate.OfflineSession(sql.FieldLT(FieldConnectorData, v)) } // ConnectorDataLTE applies the LTE predicate on the "connector_data" field. func ConnectorDataLTE(v []byte) predicate.OfflineSession { - return predicate.OfflineSession(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldConnectorData), v)) - }) + return predicate.OfflineSession(sql.FieldLTE(FieldConnectorData, v)) } // ConnectorDataIsNil applies the IsNil predicate on the "connector_data" field. func ConnectorDataIsNil() predicate.OfflineSession { - return predicate.OfflineSession(func(s *sql.Selector) { - s.Where(sql.IsNull(s.C(FieldConnectorData))) - }) + return predicate.OfflineSession(sql.FieldIsNull(FieldConnectorData)) } // ConnectorDataNotNil applies the NotNil predicate on the "connector_data" field. func ConnectorDataNotNil() predicate.OfflineSession { - return predicate.OfflineSession(func(s *sql.Selector) { - s.Where(sql.NotNull(s.C(FieldConnectorData))) - }) + return predicate.OfflineSession(sql.FieldNotNull(FieldConnectorData)) } // And groups predicates with the AND operator between them. diff --git a/storage/ent/db/offlinesession_create.go b/storage/ent/db/offlinesession_create.go index 82b8014f..98b4bc78 100644 --- a/storage/ent/db/offlinesession_create.go +++ b/storage/ent/db/offlinesession_create.go @@ -56,49 +56,7 @@ func (osc *OfflineSessionCreate) Mutation() *OfflineSessionMutation { // Save creates the OfflineSession in the database. func (osc *OfflineSessionCreate) Save(ctx context.Context) (*OfflineSession, error) { - var ( - err error - node *OfflineSession - ) - if len(osc.hooks) == 0 { - if err = osc.check(); err != nil { - return nil, err - } - node, err = osc.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*OfflineSessionMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err = osc.check(); err != nil { - return nil, err - } - osc.mutation = mutation - if node, err = osc.sqlSave(ctx); err != nil { - return nil, err - } - mutation.id = &node.ID - mutation.done = true - return node, err - }) - for i := len(osc.hooks) - 1; i >= 0; i-- { - if osc.hooks[i] == nil { - return nil, fmt.Errorf("db: uninitialized hook (forgotten import db/runtime?)") - } - mut = osc.hooks[i](mut) - } - v, err := mut.Mutate(ctx, osc.mutation) - if err != nil { - return nil, err - } - nv, ok := v.(*OfflineSession) - if !ok { - return nil, fmt.Errorf("unexpected node type %T returned from OfflineSessionMutation", v) - } - node = nv - } - return node, err + return withHooks[*OfflineSession, OfflineSessionMutation](ctx, osc.sqlSave, osc.mutation, osc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -153,6 +111,9 @@ func (osc *OfflineSessionCreate) check() error { } func (osc *OfflineSessionCreate) sqlSave(ctx context.Context) (*OfflineSession, error) { + if err := osc.check(); err != nil { + return nil, err + } _node, _spec := osc.createSpec() if err := sqlgraph.CreateNode(ctx, osc.driver, _spec); err != nil { if sqlgraph.IsConstraintError(err) { @@ -167,54 +128,34 @@ func (osc *OfflineSessionCreate) sqlSave(ctx context.Context) (*OfflineSession, return nil, fmt.Errorf("unexpected OfflineSession.ID type: %T", _spec.ID.Value) } } + osc.mutation.id = &_node.ID + osc.mutation.done = true return _node, nil } func (osc *OfflineSessionCreate) createSpec() (*OfflineSession, *sqlgraph.CreateSpec) { var ( _node = &OfflineSession{config: osc.config} - _spec = &sqlgraph.CreateSpec{ - Table: offlinesession.Table, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeString, - Column: offlinesession.FieldID, - }, - } + _spec = sqlgraph.NewCreateSpec(offlinesession.Table, sqlgraph.NewFieldSpec(offlinesession.FieldID, field.TypeString)) ) if id, ok := osc.mutation.ID(); ok { _node.ID = id _spec.ID.Value = id } if value, ok := osc.mutation.UserID(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: offlinesession.FieldUserID, - }) + _spec.SetField(offlinesession.FieldUserID, field.TypeString, value) _node.UserID = value } if value, ok := osc.mutation.ConnID(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: offlinesession.FieldConnID, - }) + _spec.SetField(offlinesession.FieldConnID, field.TypeString, value) _node.ConnID = value } if value, ok := osc.mutation.Refresh(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeBytes, - Value: value, - Column: offlinesession.FieldRefresh, - }) + _spec.SetField(offlinesession.FieldRefresh, field.TypeBytes, value) _node.Refresh = value } if value, ok := osc.mutation.ConnectorData(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeBytes, - Value: value, - Column: offlinesession.FieldConnectorData, - }) + _spec.SetField(offlinesession.FieldConnectorData, field.TypeBytes, value) _node.ConnectorData = &value } return _node, _spec diff --git a/storage/ent/db/offlinesession_delete.go b/storage/ent/db/offlinesession_delete.go index b9c60ba9..a5d794b2 100644 --- a/storage/ent/db/offlinesession_delete.go +++ b/storage/ent/db/offlinesession_delete.go @@ -4,7 +4,6 @@ package db import ( "context" - "fmt" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" @@ -28,34 +27,7 @@ func (osd *OfflineSessionDelete) Where(ps ...predicate.OfflineSession) *OfflineS // Exec executes the deletion query and returns how many vertices were deleted. func (osd *OfflineSessionDelete) Exec(ctx context.Context) (int, error) { - var ( - err error - affected int - ) - if len(osd.hooks) == 0 { - affected, err = osd.sqlExec(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*OfflineSessionMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - osd.mutation = mutation - affected, err = osd.sqlExec(ctx) - mutation.done = true - return affected, err - }) - for i := len(osd.hooks) - 1; i >= 0; i-- { - if osd.hooks[i] == nil { - return 0, fmt.Errorf("db: uninitialized hook (forgotten import db/runtime?)") - } - mut = osd.hooks[i](mut) - } - if _, err := mut.Mutate(ctx, osd.mutation); err != nil { - return 0, err - } - } - return affected, err + return withHooks[int, OfflineSessionMutation](ctx, osd.sqlExec, osd.mutation, osd.hooks) } // ExecX is like Exec, but panics if an error occurs. @@ -68,15 +40,7 @@ func (osd *OfflineSessionDelete) ExecX(ctx context.Context) int { } func (osd *OfflineSessionDelete) sqlExec(ctx context.Context) (int, error) { - _spec := &sqlgraph.DeleteSpec{ - Node: &sqlgraph.NodeSpec{ - Table: offlinesession.Table, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeString, - Column: offlinesession.FieldID, - }, - }, - } + _spec := sqlgraph.NewDeleteSpec(offlinesession.Table, sqlgraph.NewFieldSpec(offlinesession.FieldID, field.TypeString)) if ps := osd.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { @@ -88,6 +52,7 @@ func (osd *OfflineSessionDelete) sqlExec(ctx context.Context) (int, error) { if err != nil && sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } + osd.mutation.done = true return affected, err } @@ -96,6 +61,12 @@ type OfflineSessionDeleteOne struct { osd *OfflineSessionDelete } +// Where appends a list predicates to the OfflineSessionDelete builder. +func (osdo *OfflineSessionDeleteOne) Where(ps ...predicate.OfflineSession) *OfflineSessionDeleteOne { + osdo.osd.mutation.Where(ps...) + return osdo +} + // Exec executes the deletion query. func (osdo *OfflineSessionDeleteOne) Exec(ctx context.Context) error { n, err := osdo.osd.Exec(ctx) @@ -111,5 +82,7 @@ func (osdo *OfflineSessionDeleteOne) Exec(ctx context.Context) error { // ExecX is like Exec, but panics if an error occurs. func (osdo *OfflineSessionDeleteOne) ExecX(ctx context.Context) { - osdo.osd.ExecX(ctx) + if err := osdo.Exec(ctx); err != nil { + panic(err) + } } diff --git a/storage/ent/db/offlinesession_query.go b/storage/ent/db/offlinesession_query.go index e5e09cf1..47014648 100644 --- a/storage/ent/db/offlinesession_query.go +++ b/storage/ent/db/offlinesession_query.go @@ -17,11 +17,9 @@ import ( // OfflineSessionQuery is the builder for querying OfflineSession entities. type OfflineSessionQuery struct { config - limit *int - offset *int - unique *bool + ctx *QueryContext order []OrderFunc - fields []string + inters []Interceptor predicates []predicate.OfflineSession // intermediate query (i.e. traversal path). sql *sql.Selector @@ -34,26 +32,26 @@ func (osq *OfflineSessionQuery) Where(ps ...predicate.OfflineSession) *OfflineSe return osq } -// Limit adds a limit step to the query. +// Limit the number of records to be returned by this query. func (osq *OfflineSessionQuery) Limit(limit int) *OfflineSessionQuery { - osq.limit = &limit + osq.ctx.Limit = &limit return osq } -// Offset adds an offset step to the query. +// Offset to start from. func (osq *OfflineSessionQuery) Offset(offset int) *OfflineSessionQuery { - osq.offset = &offset + osq.ctx.Offset = &offset return osq } // Unique configures the query builder to filter duplicate records on query. // By default, unique is set to true, and can be disabled using this method. func (osq *OfflineSessionQuery) Unique(unique bool) *OfflineSessionQuery { - osq.unique = &unique + osq.ctx.Unique = &unique return osq } -// Order adds an order step to the query. +// Order specifies how the records should be ordered. func (osq *OfflineSessionQuery) Order(o ...OrderFunc) *OfflineSessionQuery { osq.order = append(osq.order, o...) return osq @@ -62,7 +60,7 @@ func (osq *OfflineSessionQuery) Order(o ...OrderFunc) *OfflineSessionQuery { // First returns the first OfflineSession entity from the query. // Returns a *NotFoundError when no OfflineSession was found. func (osq *OfflineSessionQuery) First(ctx context.Context) (*OfflineSession, error) { - nodes, err := osq.Limit(1).All(ctx) + nodes, err := osq.Limit(1).All(setContextOp(ctx, osq.ctx, "First")) if err != nil { return nil, err } @@ -85,7 +83,7 @@ func (osq *OfflineSessionQuery) FirstX(ctx context.Context) *OfflineSession { // Returns a *NotFoundError when no OfflineSession ID was found. func (osq *OfflineSessionQuery) FirstID(ctx context.Context) (id string, err error) { var ids []string - if ids, err = osq.Limit(1).IDs(ctx); err != nil { + if ids, err = osq.Limit(1).IDs(setContextOp(ctx, osq.ctx, "FirstID")); err != nil { return } if len(ids) == 0 { @@ -108,7 +106,7 @@ func (osq *OfflineSessionQuery) FirstIDX(ctx context.Context) string { // 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) + nodes, err := osq.Limit(2).All(setContextOp(ctx, osq.ctx, "Only")) if err != nil { return nil, err } @@ -136,7 +134,7 @@ func (osq *OfflineSessionQuery) OnlyX(ctx context.Context) *OfflineSession { // Returns a *NotFoundError when no entities are found. func (osq *OfflineSessionQuery) OnlyID(ctx context.Context) (id string, err error) { var ids []string - if ids, err = osq.Limit(2).IDs(ctx); err != nil { + if ids, err = osq.Limit(2).IDs(setContextOp(ctx, osq.ctx, "OnlyID")); err != nil { return } switch len(ids) { @@ -161,10 +159,12 @@ func (osq *OfflineSessionQuery) OnlyIDX(ctx context.Context) string { // All executes the query and returns a list of OfflineSessions. func (osq *OfflineSessionQuery) All(ctx context.Context) ([]*OfflineSession, error) { + ctx = setContextOp(ctx, osq.ctx, "All") if err := osq.prepareQuery(ctx); err != nil { return nil, err } - return osq.sqlAll(ctx) + qr := querierAll[[]*OfflineSession, *OfflineSessionQuery]() + return withInterceptors[[]*OfflineSession](ctx, osq, qr, osq.inters) } // AllX is like All, but panics if an error occurs. @@ -177,9 +177,12 @@ func (osq *OfflineSessionQuery) AllX(ctx context.Context) []*OfflineSession { } // IDs executes the query and returns a list of OfflineSession IDs. -func (osq *OfflineSessionQuery) IDs(ctx context.Context) ([]string, error) { - var ids []string - if err := osq.Select(offlinesession.FieldID).Scan(ctx, &ids); err != nil { +func (osq *OfflineSessionQuery) IDs(ctx context.Context) (ids []string, err error) { + if osq.ctx.Unique == nil && osq.path != nil { + osq.Unique(true) + } + ctx = setContextOp(ctx, osq.ctx, "IDs") + if err = osq.Select(offlinesession.FieldID).Scan(ctx, &ids); err != nil { return nil, err } return ids, nil @@ -196,10 +199,11 @@ func (osq *OfflineSessionQuery) IDsX(ctx context.Context) []string { // Count returns the count of the given query. func (osq *OfflineSessionQuery) Count(ctx context.Context) (int, error) { + ctx = setContextOp(ctx, osq.ctx, "Count") if err := osq.prepareQuery(ctx); err != nil { return 0, err } - return osq.sqlCount(ctx) + return withInterceptors[int](ctx, osq, querierCount[*OfflineSessionQuery](), osq.inters) } // CountX is like Count, but panics if an error occurs. @@ -213,10 +217,15 @@ func (osq *OfflineSessionQuery) CountX(ctx context.Context) int { // Exist returns true if the query has elements in the graph. func (osq *OfflineSessionQuery) Exist(ctx context.Context) (bool, error) { - if err := osq.prepareQuery(ctx); err != nil { - return false, err + ctx = setContextOp(ctx, osq.ctx, "Exist") + switch _, err := osq.FirstID(ctx); { + case IsNotFound(err): + return false, nil + case err != nil: + return false, fmt.Errorf("db: check existence: %w", err) + default: + return true, nil } - return osq.sqlExist(ctx) } // ExistX is like Exist, but panics if an error occurs. @@ -236,14 +245,13 @@ func (osq *OfflineSessionQuery) Clone() *OfflineSessionQuery { } return &OfflineSessionQuery{ config: osq.config, - limit: osq.limit, - offset: osq.offset, + ctx: osq.ctx.Clone(), order: append([]OrderFunc{}, osq.order...), + inters: append([]Interceptor{}, osq.inters...), predicates: append([]predicate.OfflineSession{}, osq.predicates...), // clone intermediate query. - sql: osq.sql.Clone(), - path: osq.path, - unique: osq.unique, + sql: osq.sql.Clone(), + path: osq.path, } } @@ -261,18 +269,12 @@ func (osq *OfflineSessionQuery) Clone() *OfflineSessionQuery { // GroupBy(offlinesession.FieldUserID). // Aggregate(db.Count()). // Scan(ctx, &v) -// func (osq *OfflineSessionQuery) GroupBy(field string, fields ...string) *OfflineSessionGroupBy { - grbuild := &OfflineSessionGroupBy{config: osq.config} - grbuild.fields = append([]string{field}, fields...) - grbuild.path = func(ctx context.Context) (prev *sql.Selector, err error) { - if err := osq.prepareQuery(ctx); err != nil { - return nil, err - } - return osq.sqlQuery(ctx), nil - } + osq.ctx.Fields = append([]string{field}, fields...) + grbuild := &OfflineSessionGroupBy{build: osq} + grbuild.flds = &osq.ctx.Fields grbuild.label = offlinesession.Label - grbuild.flds, grbuild.scan = &grbuild.fields, grbuild.Scan + grbuild.scan = grbuild.Scan return grbuild } @@ -288,17 +290,31 @@ func (osq *OfflineSessionQuery) GroupBy(field string, fields ...string) *Offline // client.OfflineSession.Query(). // Select(offlinesession.FieldUserID). // Scan(ctx, &v) -// func (osq *OfflineSessionQuery) Select(fields ...string) *OfflineSessionSelect { - osq.fields = append(osq.fields, fields...) - selbuild := &OfflineSessionSelect{OfflineSessionQuery: osq} - selbuild.label = offlinesession.Label - selbuild.flds, selbuild.scan = &osq.fields, selbuild.Scan - return selbuild + osq.ctx.Fields = append(osq.ctx.Fields, fields...) + sbuild := &OfflineSessionSelect{OfflineSessionQuery: osq} + sbuild.label = offlinesession.Label + sbuild.flds, sbuild.scan = &osq.ctx.Fields, sbuild.Scan + return sbuild +} + +// Aggregate returns a OfflineSessionSelect configured with the given aggregations. +func (osq *OfflineSessionQuery) Aggregate(fns ...AggregateFunc) *OfflineSessionSelect { + return osq.Select().Aggregate(fns...) } func (osq *OfflineSessionQuery) prepareQuery(ctx context.Context) error { - for _, f := range osq.fields { + for _, inter := range osq.inters { + if inter == nil { + return fmt.Errorf("db: uninitialized interceptor (forgotten import db/runtime?)") + } + if trv, ok := inter.(Traverser); ok { + if err := trv.Traverse(ctx, osq); err != nil { + return err + } + } + } + for _, f := range osq.ctx.Fields { if !offlinesession.ValidColumn(f) { return &ValidationError{Name: f, err: fmt.Errorf("db: invalid field %q for query", f)} } @@ -318,10 +334,10 @@ func (osq *OfflineSessionQuery) sqlAll(ctx context.Context, hooks ...queryHook) nodes = []*OfflineSession{} _spec = osq.querySpec() ) - _spec.ScanValues = func(columns []string) ([]interface{}, error) { + _spec.ScanValues = func(columns []string) ([]any, error) { return (*OfflineSession).scanValues(nil, columns) } - _spec.Assign = func(columns []string, values []interface{}) error { + _spec.Assign = func(columns []string, values []any) error { node := &OfflineSession{config: osq.config} nodes = append(nodes, node) return node.assignValues(columns, values) @@ -340,38 +356,22 @@ func (osq *OfflineSessionQuery) sqlAll(ctx context.Context, hooks ...queryHook) 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 + _spec.Node.Columns = osq.ctx.Fields + if len(osq.ctx.Fields) > 0 { + _spec.Unique = osq.ctx.Unique != nil && *osq.ctx.Unique } return sqlgraph.CountNodes(ctx, osq.driver, _spec) } -func (osq *OfflineSessionQuery) sqlExist(ctx context.Context) (bool, error) { - n, err := osq.sqlCount(ctx) - if err != nil { - return false, fmt.Errorf("db: check existence: %w", err) - } - return n > 0, nil -} - func (osq *OfflineSessionQuery) querySpec() *sqlgraph.QuerySpec { - _spec := &sqlgraph.QuerySpec{ - Node: &sqlgraph.NodeSpec{ - Table: offlinesession.Table, - Columns: offlinesession.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeString, - Column: offlinesession.FieldID, - }, - }, - From: osq.sql, - Unique: true, - } - if unique := osq.unique; unique != nil { + _spec := sqlgraph.NewQuerySpec(offlinesession.Table, offlinesession.Columns, sqlgraph.NewFieldSpec(offlinesession.FieldID, field.TypeString)) + _spec.From = osq.sql + if unique := osq.ctx.Unique; unique != nil { _spec.Unique = *unique + } else if osq.path != nil { + _spec.Unique = true } - if fields := osq.fields; len(fields) > 0 { + if fields := osq.ctx.Fields; len(fields) > 0 { _spec.Node.Columns = make([]string, 0, len(fields)) _spec.Node.Columns = append(_spec.Node.Columns, offlinesession.FieldID) for i := range fields { @@ -387,10 +387,10 @@ func (osq *OfflineSessionQuery) querySpec() *sqlgraph.QuerySpec { } } } - if limit := osq.limit; limit != nil { + if limit := osq.ctx.Limit; limit != nil { _spec.Limit = *limit } - if offset := osq.offset; offset != nil { + if offset := osq.ctx.Offset; offset != nil { _spec.Offset = *offset } if ps := osq.order; len(ps) > 0 { @@ -406,7 +406,7 @@ func (osq *OfflineSessionQuery) querySpec() *sqlgraph.QuerySpec { func (osq *OfflineSessionQuery) sqlQuery(ctx context.Context) *sql.Selector { builder := sql.Dialect(osq.driver.Dialect()) t1 := builder.Table(offlinesession.Table) - columns := osq.fields + columns := osq.ctx.Fields if len(columns) == 0 { columns = offlinesession.Columns } @@ -415,7 +415,7 @@ func (osq *OfflineSessionQuery) sqlQuery(ctx context.Context) *sql.Selector { selector = osq.sql selector.Select(selector.Columns(columns...)...) } - if osq.unique != nil && *osq.unique { + if osq.ctx.Unique != nil && *osq.ctx.Unique { selector.Distinct() } for _, p := range osq.predicates { @@ -424,12 +424,12 @@ func (osq *OfflineSessionQuery) sqlQuery(ctx context.Context) *sql.Selector { for _, p := range osq.order { p(selector) } - if offset := osq.offset; offset != nil { + if offset := osq.ctx.Offset; offset != nil { // limit is mandatory for offset clause. We start // with default value, and override it below if needed. selector.Offset(*offset).Limit(math.MaxInt32) } - if limit := osq.limit; limit != nil { + if limit := osq.ctx.Limit; limit != nil { selector.Limit(*limit) } return selector @@ -437,13 +437,8 @@ func (osq *OfflineSessionQuery) sqlQuery(ctx context.Context) *sql.Selector { // OfflineSessionGroupBy is the group-by builder for OfflineSession entities. type OfflineSessionGroupBy struct { - config selector - fields []string - fns []AggregateFunc - // intermediate query (i.e. traversal path). - sql *sql.Selector - path func(context.Context) (*sql.Selector, error) + build *OfflineSessionQuery } // Aggregate adds the given aggregation functions to the group-by query. @@ -452,74 +447,77 @@ func (osgb *OfflineSessionGroupBy) Aggregate(fns ...AggregateFunc) *OfflineSessi return osgb } -// Scan applies the group-by query and scans the result into the given value. -func (osgb *OfflineSessionGroupBy) Scan(ctx context.Context, v interface{}) error { - query, err := osgb.path(ctx) - if err != nil { +// Scan applies the selector query and scans the result into the given value. +func (osgb *OfflineSessionGroupBy) Scan(ctx context.Context, v any) error { + ctx = setContextOp(ctx, osgb.build.ctx, "GroupBy") + if err := osgb.build.prepareQuery(ctx); err != nil { return err } - osgb.sql = query - return osgb.sqlScan(ctx, v) + return scanWithInterceptors[*OfflineSessionQuery, *OfflineSessionGroupBy](ctx, osgb.build, osgb, osgb.build.inters, v) } -func (osgb *OfflineSessionGroupBy) sqlScan(ctx context.Context, v interface{}) error { - for _, f := range osgb.fields { - if !offlinesession.ValidColumn(f) { - return &ValidationError{Name: f, err: fmt.Errorf("invalid field %q for group-by", f)} - } - } - selector := osgb.sqlQuery() - if err := selector.Err(); err != nil { - return err - } - rows := &sql.Rows{} - query, args := selector.Query() - if err := osgb.driver.Query(ctx, query, args, rows); err != nil { - return err - } - defer rows.Close() - return sql.ScanSlice(rows, v) -} - -func (osgb *OfflineSessionGroupBy) sqlQuery() *sql.Selector { - selector := osgb.sql.Select() +func (osgb *OfflineSessionGroupBy) sqlScan(ctx context.Context, root *OfflineSessionQuery, v any) error { + selector := root.sqlQuery(ctx).Select() aggregation := make([]string, 0, len(osgb.fns)) for _, fn := range osgb.fns { aggregation = append(aggregation, fn(selector)) } - // If no columns were selected in a custom aggregation function, the default - // selection is the fields used for "group-by", and the aggregation functions. if len(selector.SelectedColumns()) == 0 { - columns := make([]string, 0, len(osgb.fields)+len(osgb.fns)) - for _, f := range osgb.fields { + columns := make([]string, 0, len(*osgb.flds)+len(osgb.fns)) + for _, f := range *osgb.flds { columns = append(columns, selector.C(f)) } columns = append(columns, aggregation...) selector.Select(columns...) } - return selector.GroupBy(selector.Columns(osgb.fields...)...) + selector.GroupBy(selector.Columns(*osgb.flds...)...) + if err := selector.Err(); err != nil { + return err + } + rows := &sql.Rows{} + query, args := selector.Query() + if err := osgb.build.driver.Query(ctx, query, args, rows); err != nil { + return err + } + defer rows.Close() + return sql.ScanSlice(rows, v) } // OfflineSessionSelect is the builder for selecting fields of OfflineSession entities. type OfflineSessionSelect struct { *OfflineSessionQuery selector - // intermediate query (i.e. traversal path). - sql *sql.Selector +} + +// Aggregate adds the given aggregation functions to the selector query. +func (oss *OfflineSessionSelect) Aggregate(fns ...AggregateFunc) *OfflineSessionSelect { + oss.fns = append(oss.fns, fns...) + return oss } // Scan applies the selector query and scans the result into the given value. -func (oss *OfflineSessionSelect) Scan(ctx context.Context, v interface{}) error { +func (oss *OfflineSessionSelect) Scan(ctx context.Context, v any) error { + ctx = setContextOp(ctx, oss.ctx, "Select") if err := oss.prepareQuery(ctx); err != nil { return err } - oss.sql = oss.OfflineSessionQuery.sqlQuery(ctx) - return oss.sqlScan(ctx, v) + return scanWithInterceptors[*OfflineSessionQuery, *OfflineSessionSelect](ctx, oss.OfflineSessionQuery, oss, oss.inters, v) } -func (oss *OfflineSessionSelect) sqlScan(ctx context.Context, v interface{}) error { +func (oss *OfflineSessionSelect) sqlScan(ctx context.Context, root *OfflineSessionQuery, v any) error { + selector := root.sqlQuery(ctx) + aggregation := make([]string, 0, len(oss.fns)) + for _, fn := range oss.fns { + aggregation = append(aggregation, fn(selector)) + } + switch n := len(*oss.selector.flds); { + case n == 0 && len(aggregation) > 0: + selector.Select(aggregation...) + case n != 0 && len(aggregation) > 0: + selector.AppendSelect(aggregation...) + } rows := &sql.Rows{} - query, args := oss.sql.Query() + query, args := selector.Query() if err := oss.driver.Query(ctx, query, args, rows); err != nil { return err } diff --git a/storage/ent/db/offlinesession_update.go b/storage/ent/db/offlinesession_update.go index f9f1d9cb..ab815717 100644 --- a/storage/ent/db/offlinesession_update.go +++ b/storage/ent/db/offlinesession_update.go @@ -64,40 +64,7 @@ func (osu *OfflineSessionUpdate) Mutation() *OfflineSessionMutation { // Save executes the query and returns the number of nodes affected by the update operation. func (osu *OfflineSessionUpdate) Save(ctx context.Context) (int, error) { - var ( - err error - affected int - ) - if len(osu.hooks) == 0 { - if err = osu.check(); err != nil { - return 0, err - } - affected, err = osu.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*OfflineSessionMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err = osu.check(); err != nil { - return 0, err - } - osu.mutation = mutation - affected, err = osu.sqlSave(ctx) - mutation.done = true - return affected, err - }) - for i := len(osu.hooks) - 1; i >= 0; i-- { - if osu.hooks[i] == nil { - return 0, fmt.Errorf("db: uninitialized hook (forgotten import db/runtime?)") - } - mut = osu.hooks[i](mut) - } - if _, err := mut.Mutate(ctx, osu.mutation); err != nil { - return 0, err - } - } - return affected, err + return withHooks[int, OfflineSessionMutation](ctx, osu.sqlSave, osu.mutation, osu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -138,16 +105,10 @@ func (osu *OfflineSessionUpdate) check() error { } func (osu *OfflineSessionUpdate) sqlSave(ctx context.Context) (n int, err error) { - _spec := &sqlgraph.UpdateSpec{ - Node: &sqlgraph.NodeSpec{ - Table: offlinesession.Table, - Columns: offlinesession.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeString, - Column: offlinesession.FieldID, - }, - }, + if err := osu.check(); err != nil { + return n, err } + _spec := sqlgraph.NewUpdateSpec(offlinesession.Table, offlinesession.Columns, sqlgraph.NewFieldSpec(offlinesession.FieldID, field.TypeString)) if ps := osu.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { @@ -156,38 +117,19 @@ func (osu *OfflineSessionUpdate) sqlSave(ctx context.Context) (n int, err error) } } if value, ok := osu.mutation.UserID(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: offlinesession.FieldUserID, - }) + _spec.SetField(offlinesession.FieldUserID, field.TypeString, value) } if value, ok := osu.mutation.ConnID(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: offlinesession.FieldConnID, - }) + _spec.SetField(offlinesession.FieldConnID, field.TypeString, value) } if value, ok := osu.mutation.Refresh(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeBytes, - Value: value, - Column: offlinesession.FieldRefresh, - }) + _spec.SetField(offlinesession.FieldRefresh, field.TypeBytes, value) } if value, ok := osu.mutation.ConnectorData(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeBytes, - Value: value, - Column: offlinesession.FieldConnectorData, - }) + _spec.SetField(offlinesession.FieldConnectorData, field.TypeBytes, value) } if osu.mutation.ConnectorDataCleared() { - _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ - Type: field.TypeBytes, - Column: offlinesession.FieldConnectorData, - }) + _spec.ClearField(offlinesession.FieldConnectorData, field.TypeBytes) } if n, err = sqlgraph.UpdateNodes(ctx, osu.driver, _spec); err != nil { if _, ok := err.(*sqlgraph.NotFoundError); ok { @@ -197,6 +139,7 @@ func (osu *OfflineSessionUpdate) sqlSave(ctx context.Context) (n int, err error) } return 0, err } + osu.mutation.done = true return n, nil } @@ -243,6 +186,12 @@ func (osuo *OfflineSessionUpdateOne) Mutation() *OfflineSessionMutation { return osuo.mutation } +// Where appends a list predicates to the OfflineSessionUpdate builder. +func (osuo *OfflineSessionUpdateOne) Where(ps ...predicate.OfflineSession) *OfflineSessionUpdateOne { + osuo.mutation.Where(ps...) + return osuo +} + // Select allows selecting one or more fields (columns) of the returned entity. // The default is selecting all fields defined in the entity schema. func (osuo *OfflineSessionUpdateOne) Select(field string, fields ...string) *OfflineSessionUpdateOne { @@ -252,46 +201,7 @@ func (osuo *OfflineSessionUpdateOne) Select(field string, fields ...string) *Off // Save executes the query and returns the updated OfflineSession entity. func (osuo *OfflineSessionUpdateOne) Save(ctx context.Context) (*OfflineSession, error) { - var ( - err error - node *OfflineSession - ) - if len(osuo.hooks) == 0 { - if err = osuo.check(); err != nil { - return nil, err - } - node, err = osuo.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*OfflineSessionMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err = osuo.check(); err != nil { - return nil, err - } - osuo.mutation = mutation - node, err = osuo.sqlSave(ctx) - mutation.done = true - return node, err - }) - for i := len(osuo.hooks) - 1; i >= 0; i-- { - if osuo.hooks[i] == nil { - return nil, fmt.Errorf("db: uninitialized hook (forgotten import db/runtime?)") - } - mut = osuo.hooks[i](mut) - } - v, err := mut.Mutate(ctx, osuo.mutation) - if err != nil { - return nil, err - } - nv, ok := v.(*OfflineSession) - if !ok { - return nil, fmt.Errorf("unexpected node type %T returned from OfflineSessionMutation", v) - } - node = nv - } - return node, err + return withHooks[*OfflineSession, OfflineSessionMutation](ctx, osuo.sqlSave, osuo.mutation, osuo.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -332,16 +242,10 @@ func (osuo *OfflineSessionUpdateOne) check() error { } func (osuo *OfflineSessionUpdateOne) sqlSave(ctx context.Context) (_node *OfflineSession, err error) { - _spec := &sqlgraph.UpdateSpec{ - Node: &sqlgraph.NodeSpec{ - Table: offlinesession.Table, - Columns: offlinesession.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeString, - Column: offlinesession.FieldID, - }, - }, + if err := osuo.check(); err != nil { + return _node, err } + _spec := sqlgraph.NewUpdateSpec(offlinesession.Table, offlinesession.Columns, sqlgraph.NewFieldSpec(offlinesession.FieldID, field.TypeString)) id, ok := osuo.mutation.ID() if !ok { return nil, &ValidationError{Name: "id", err: errors.New(`db: missing "OfflineSession.id" for update`)} @@ -367,38 +271,19 @@ func (osuo *OfflineSessionUpdateOne) sqlSave(ctx context.Context) (_node *Offlin } } if value, ok := osuo.mutation.UserID(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: offlinesession.FieldUserID, - }) + _spec.SetField(offlinesession.FieldUserID, field.TypeString, value) } if value, ok := osuo.mutation.ConnID(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: offlinesession.FieldConnID, - }) + _spec.SetField(offlinesession.FieldConnID, field.TypeString, value) } if value, ok := osuo.mutation.Refresh(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeBytes, - Value: value, - Column: offlinesession.FieldRefresh, - }) + _spec.SetField(offlinesession.FieldRefresh, field.TypeBytes, value) } if value, ok := osuo.mutation.ConnectorData(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeBytes, - Value: value, - Column: offlinesession.FieldConnectorData, - }) + _spec.SetField(offlinesession.FieldConnectorData, field.TypeBytes, value) } if osuo.mutation.ConnectorDataCleared() { - _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ - Type: field.TypeBytes, - Column: offlinesession.FieldConnectorData, - }) + _spec.ClearField(offlinesession.FieldConnectorData, field.TypeBytes) } _node = &OfflineSession{config: osuo.config} _spec.Assign = _node.assignValues @@ -411,5 +296,6 @@ func (osuo *OfflineSessionUpdateOne) sqlSave(ctx context.Context) (_node *Offlin } return nil, err } + osuo.mutation.done = true return _node, nil } diff --git a/storage/ent/db/password.go b/storage/ent/db/password.go index cd30ec54..5b9f5a1d 100644 --- a/storage/ent/db/password.go +++ b/storage/ent/db/password.go @@ -26,8 +26,8 @@ type Password struct { } // scanValues returns the types for scanning values from sql.Rows. -func (*Password) scanValues(columns []string) ([]interface{}, error) { - values := make([]interface{}, len(columns)) +func (*Password) scanValues(columns []string) ([]any, error) { + values := make([]any, len(columns)) for i := range columns { switch columns[i] { case password.FieldHash: @@ -45,7 +45,7 @@ func (*Password) scanValues(columns []string) ([]interface{}, error) { // assignValues assigns the values that were returned from sql.Rows (after scanning) // to the Password fields. -func (pa *Password) assignValues(columns []string, values []interface{}) error { +func (pa *Password) assignValues(columns []string, values []any) error { if m, n := len(values), len(columns); m < n { return fmt.Errorf("mismatch number of scan values: %d != %d", m, n) } @@ -90,7 +90,7 @@ func (pa *Password) assignValues(columns []string, values []interface{}) error { // Note that you need to call Password.Unwrap() before calling this method if this Password // was returned from a transaction, and the transaction was committed or rolled back. func (pa *Password) Update() *PasswordUpdateOne { - return (&PasswordClient{config: pa.config}).UpdateOne(pa) + return NewPasswordClient(pa.config).UpdateOne(pa) } // Unwrap unwraps the Password entity that was returned from a transaction after it was closed, @@ -126,9 +126,3 @@ func (pa *Password) String() string { // Passwords is a parsable slice of Password. type Passwords []*Password - -func (pa Passwords) config(cfg config) { - for _i := range pa { - pa[_i].config = cfg - } -} diff --git a/storage/ent/db/password/where.go b/storage/ent/db/password/where.go index e33c134f..718ac151 100644 --- a/storage/ent/db/password/where.go +++ b/storage/ent/db/password/where.go @@ -9,462 +9,302 @@ import ( // ID filters vertices based on their ID field. func ID(id int) predicate.Password { - return predicate.Password(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldID), id)) - }) + return predicate.Password(sql.FieldEQ(FieldID, id)) } // IDEQ applies the EQ predicate on the ID field. func IDEQ(id int) predicate.Password { - return predicate.Password(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldID), id)) - }) + return predicate.Password(sql.FieldEQ(FieldID, id)) } // IDNEQ applies the NEQ predicate on the ID field. func IDNEQ(id int) predicate.Password { - return predicate.Password(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldID), id)) - }) + return predicate.Password(sql.FieldNEQ(FieldID, id)) } // IDIn applies the In predicate on the ID field. func IDIn(ids ...int) predicate.Password { - return predicate.Password(func(s *sql.Selector) { - v := make([]interface{}, len(ids)) - for i := range v { - v[i] = ids[i] - } - s.Where(sql.In(s.C(FieldID), v...)) - }) + return predicate.Password(sql.FieldIn(FieldID, ids...)) } // IDNotIn applies the NotIn predicate on the ID field. func IDNotIn(ids ...int) predicate.Password { - return predicate.Password(func(s *sql.Selector) { - v := make([]interface{}, len(ids)) - for i := range v { - v[i] = ids[i] - } - s.Where(sql.NotIn(s.C(FieldID), v...)) - }) + return predicate.Password(sql.FieldNotIn(FieldID, ids...)) } // IDGT applies the GT predicate on the ID field. func IDGT(id int) predicate.Password { - return predicate.Password(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldID), id)) - }) + return predicate.Password(sql.FieldGT(FieldID, id)) } // IDGTE applies the GTE predicate on the ID field. func IDGTE(id int) predicate.Password { - return predicate.Password(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldID), id)) - }) + return predicate.Password(sql.FieldGTE(FieldID, id)) } // IDLT applies the LT predicate on the ID field. func IDLT(id int) predicate.Password { - return predicate.Password(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldID), id)) - }) + return predicate.Password(sql.FieldLT(FieldID, id)) } // IDLTE applies the LTE predicate on the ID field. func IDLTE(id int) predicate.Password { - return predicate.Password(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldID), id)) - }) + return predicate.Password(sql.FieldLTE(FieldID, id)) } // Email applies equality check predicate on the "email" field. It's identical to EmailEQ. func Email(v string) predicate.Password { - return predicate.Password(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldEmail), v)) - }) + return predicate.Password(sql.FieldEQ(FieldEmail, v)) } // Hash applies equality check predicate on the "hash" field. It's identical to HashEQ. func Hash(v []byte) predicate.Password { - return predicate.Password(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldHash), v)) - }) + return predicate.Password(sql.FieldEQ(FieldHash, v)) } // Username applies equality check predicate on the "username" field. It's identical to UsernameEQ. func Username(v string) predicate.Password { - return predicate.Password(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldUsername), v)) - }) + return predicate.Password(sql.FieldEQ(FieldUsername, v)) } // UserID applies equality check predicate on the "user_id" field. It's identical to UserIDEQ. func UserID(v string) predicate.Password { - return predicate.Password(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldUserID), v)) - }) + return predicate.Password(sql.FieldEQ(FieldUserID, v)) } // EmailEQ applies the EQ predicate on the "email" field. func EmailEQ(v string) predicate.Password { - return predicate.Password(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldEmail), v)) - }) + return predicate.Password(sql.FieldEQ(FieldEmail, v)) } // EmailNEQ applies the NEQ predicate on the "email" field. func EmailNEQ(v string) predicate.Password { - return predicate.Password(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldEmail), v)) - }) + return predicate.Password(sql.FieldNEQ(FieldEmail, v)) } // EmailIn applies the In predicate on the "email" field. func EmailIn(vs ...string) predicate.Password { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Password(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldEmail), v...)) - }) + return predicate.Password(sql.FieldIn(FieldEmail, vs...)) } // EmailNotIn applies the NotIn predicate on the "email" field. func EmailNotIn(vs ...string) predicate.Password { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Password(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldEmail), v...)) - }) + return predicate.Password(sql.FieldNotIn(FieldEmail, vs...)) } // EmailGT applies the GT predicate on the "email" field. func EmailGT(v string) predicate.Password { - return predicate.Password(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldEmail), v)) - }) + return predicate.Password(sql.FieldGT(FieldEmail, v)) } // EmailGTE applies the GTE predicate on the "email" field. func EmailGTE(v string) predicate.Password { - return predicate.Password(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldEmail), v)) - }) + return predicate.Password(sql.FieldGTE(FieldEmail, v)) } // EmailLT applies the LT predicate on the "email" field. func EmailLT(v string) predicate.Password { - return predicate.Password(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldEmail), v)) - }) + return predicate.Password(sql.FieldLT(FieldEmail, v)) } // EmailLTE applies the LTE predicate on the "email" field. func EmailLTE(v string) predicate.Password { - return predicate.Password(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldEmail), v)) - }) + return predicate.Password(sql.FieldLTE(FieldEmail, v)) } // EmailContains applies the Contains predicate on the "email" field. func EmailContains(v string) predicate.Password { - return predicate.Password(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldEmail), v)) - }) + return predicate.Password(sql.FieldContains(FieldEmail, v)) } // EmailHasPrefix applies the HasPrefix predicate on the "email" field. func EmailHasPrefix(v string) predicate.Password { - return predicate.Password(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldEmail), v)) - }) + return predicate.Password(sql.FieldHasPrefix(FieldEmail, v)) } // EmailHasSuffix applies the HasSuffix predicate on the "email" field. func EmailHasSuffix(v string) predicate.Password { - return predicate.Password(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldEmail), v)) - }) + return predicate.Password(sql.FieldHasSuffix(FieldEmail, v)) } // EmailEqualFold applies the EqualFold predicate on the "email" field. func EmailEqualFold(v string) predicate.Password { - return predicate.Password(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldEmail), v)) - }) + return predicate.Password(sql.FieldEqualFold(FieldEmail, v)) } // EmailContainsFold applies the ContainsFold predicate on the "email" field. func EmailContainsFold(v string) predicate.Password { - return predicate.Password(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldEmail), v)) - }) + return predicate.Password(sql.FieldContainsFold(FieldEmail, v)) } // HashEQ applies the EQ predicate on the "hash" field. func HashEQ(v []byte) predicate.Password { - return predicate.Password(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldHash), v)) - }) + return predicate.Password(sql.FieldEQ(FieldHash, v)) } // HashNEQ applies the NEQ predicate on the "hash" field. func HashNEQ(v []byte) predicate.Password { - return predicate.Password(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldHash), v)) - }) + return predicate.Password(sql.FieldNEQ(FieldHash, v)) } // HashIn applies the In predicate on the "hash" field. func HashIn(vs ...[]byte) predicate.Password { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Password(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldHash), v...)) - }) + return predicate.Password(sql.FieldIn(FieldHash, vs...)) } // HashNotIn applies the NotIn predicate on the "hash" field. func HashNotIn(vs ...[]byte) predicate.Password { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Password(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldHash), v...)) - }) + return predicate.Password(sql.FieldNotIn(FieldHash, vs...)) } // HashGT applies the GT predicate on the "hash" field. func HashGT(v []byte) predicate.Password { - return predicate.Password(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldHash), v)) - }) + return predicate.Password(sql.FieldGT(FieldHash, v)) } // HashGTE applies the GTE predicate on the "hash" field. func HashGTE(v []byte) predicate.Password { - return predicate.Password(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldHash), v)) - }) + return predicate.Password(sql.FieldGTE(FieldHash, v)) } // HashLT applies the LT predicate on the "hash" field. func HashLT(v []byte) predicate.Password { - return predicate.Password(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldHash), v)) - }) + return predicate.Password(sql.FieldLT(FieldHash, v)) } // HashLTE applies the LTE predicate on the "hash" field. func HashLTE(v []byte) predicate.Password { - return predicate.Password(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldHash), v)) - }) + return predicate.Password(sql.FieldLTE(FieldHash, v)) } // UsernameEQ applies the EQ predicate on the "username" field. func UsernameEQ(v string) predicate.Password { - return predicate.Password(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldUsername), v)) - }) + return predicate.Password(sql.FieldEQ(FieldUsername, v)) } // UsernameNEQ applies the NEQ predicate on the "username" field. func UsernameNEQ(v string) predicate.Password { - return predicate.Password(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldUsername), v)) - }) + return predicate.Password(sql.FieldNEQ(FieldUsername, v)) } // UsernameIn applies the In predicate on the "username" field. func UsernameIn(vs ...string) predicate.Password { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Password(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldUsername), v...)) - }) + return predicate.Password(sql.FieldIn(FieldUsername, vs...)) } // UsernameNotIn applies the NotIn predicate on the "username" field. func UsernameNotIn(vs ...string) predicate.Password { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Password(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldUsername), v...)) - }) + return predicate.Password(sql.FieldNotIn(FieldUsername, vs...)) } // UsernameGT applies the GT predicate on the "username" field. func UsernameGT(v string) predicate.Password { - return predicate.Password(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldUsername), v)) - }) + return predicate.Password(sql.FieldGT(FieldUsername, v)) } // UsernameGTE applies the GTE predicate on the "username" field. func UsernameGTE(v string) predicate.Password { - return predicate.Password(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldUsername), v)) - }) + return predicate.Password(sql.FieldGTE(FieldUsername, v)) } // UsernameLT applies the LT predicate on the "username" field. func UsernameLT(v string) predicate.Password { - return predicate.Password(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldUsername), v)) - }) + return predicate.Password(sql.FieldLT(FieldUsername, v)) } // UsernameLTE applies the LTE predicate on the "username" field. func UsernameLTE(v string) predicate.Password { - return predicate.Password(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldUsername), v)) - }) + return predicate.Password(sql.FieldLTE(FieldUsername, v)) } // UsernameContains applies the Contains predicate on the "username" field. func UsernameContains(v string) predicate.Password { - return predicate.Password(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldUsername), v)) - }) + return predicate.Password(sql.FieldContains(FieldUsername, v)) } // UsernameHasPrefix applies the HasPrefix predicate on the "username" field. func UsernameHasPrefix(v string) predicate.Password { - return predicate.Password(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldUsername), v)) - }) + return predicate.Password(sql.FieldHasPrefix(FieldUsername, v)) } // UsernameHasSuffix applies the HasSuffix predicate on the "username" field. func UsernameHasSuffix(v string) predicate.Password { - return predicate.Password(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldUsername), v)) - }) + return predicate.Password(sql.FieldHasSuffix(FieldUsername, v)) } // UsernameEqualFold applies the EqualFold predicate on the "username" field. func UsernameEqualFold(v string) predicate.Password { - return predicate.Password(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldUsername), v)) - }) + return predicate.Password(sql.FieldEqualFold(FieldUsername, v)) } // UsernameContainsFold applies the ContainsFold predicate on the "username" field. func UsernameContainsFold(v string) predicate.Password { - return predicate.Password(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldUsername), v)) - }) + return predicate.Password(sql.FieldContainsFold(FieldUsername, v)) } // UserIDEQ applies the EQ predicate on the "user_id" field. func UserIDEQ(v string) predicate.Password { - return predicate.Password(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldUserID), v)) - }) + return predicate.Password(sql.FieldEQ(FieldUserID, v)) } // UserIDNEQ applies the NEQ predicate on the "user_id" field. func UserIDNEQ(v string) predicate.Password { - return predicate.Password(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldUserID), v)) - }) + return predicate.Password(sql.FieldNEQ(FieldUserID, v)) } // UserIDIn applies the In predicate on the "user_id" field. func UserIDIn(vs ...string) predicate.Password { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Password(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldUserID), v...)) - }) + return predicate.Password(sql.FieldIn(FieldUserID, vs...)) } // UserIDNotIn applies the NotIn predicate on the "user_id" field. func UserIDNotIn(vs ...string) predicate.Password { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Password(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldUserID), v...)) - }) + return predicate.Password(sql.FieldNotIn(FieldUserID, vs...)) } // UserIDGT applies the GT predicate on the "user_id" field. func UserIDGT(v string) predicate.Password { - return predicate.Password(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldUserID), v)) - }) + return predicate.Password(sql.FieldGT(FieldUserID, v)) } // UserIDGTE applies the GTE predicate on the "user_id" field. func UserIDGTE(v string) predicate.Password { - return predicate.Password(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldUserID), v)) - }) + return predicate.Password(sql.FieldGTE(FieldUserID, v)) } // UserIDLT applies the LT predicate on the "user_id" field. func UserIDLT(v string) predicate.Password { - return predicate.Password(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldUserID), v)) - }) + return predicate.Password(sql.FieldLT(FieldUserID, v)) } // UserIDLTE applies the LTE predicate on the "user_id" field. func UserIDLTE(v string) predicate.Password { - return predicate.Password(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldUserID), v)) - }) + return predicate.Password(sql.FieldLTE(FieldUserID, v)) } // UserIDContains applies the Contains predicate on the "user_id" field. func UserIDContains(v string) predicate.Password { - return predicate.Password(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldUserID), v)) - }) + return predicate.Password(sql.FieldContains(FieldUserID, v)) } // UserIDHasPrefix applies the HasPrefix predicate on the "user_id" field. func UserIDHasPrefix(v string) predicate.Password { - return predicate.Password(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldUserID), v)) - }) + return predicate.Password(sql.FieldHasPrefix(FieldUserID, v)) } // UserIDHasSuffix applies the HasSuffix predicate on the "user_id" field. func UserIDHasSuffix(v string) predicate.Password { - return predicate.Password(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldUserID), v)) - }) + return predicate.Password(sql.FieldHasSuffix(FieldUserID, v)) } // UserIDEqualFold applies the EqualFold predicate on the "user_id" field. func UserIDEqualFold(v string) predicate.Password { - return predicate.Password(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldUserID), v)) - }) + return predicate.Password(sql.FieldEqualFold(FieldUserID, v)) } // UserIDContainsFold applies the ContainsFold predicate on the "user_id" field. func UserIDContainsFold(v string) predicate.Password { - return predicate.Password(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldUserID), v)) - }) + return predicate.Password(sql.FieldContainsFold(FieldUserID, v)) } // And groups predicates with the AND operator between them. diff --git a/storage/ent/db/password_create.go b/storage/ent/db/password_create.go index 277a5c83..ea9ea4b9 100644 --- a/storage/ent/db/password_create.go +++ b/storage/ent/db/password_create.go @@ -50,49 +50,7 @@ func (pc *PasswordCreate) Mutation() *PasswordMutation { // Save creates the Password in the database. func (pc *PasswordCreate) Save(ctx context.Context) (*Password, error) { - var ( - err error - node *Password - ) - if len(pc.hooks) == 0 { - if err = pc.check(); err != nil { - return nil, err - } - node, err = pc.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*PasswordMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err = pc.check(); err != nil { - return nil, err - } - pc.mutation = mutation - if node, err = pc.sqlSave(ctx); err != nil { - return nil, err - } - mutation.id = &node.ID - mutation.done = true - return node, err - }) - for i := len(pc.hooks) - 1; i >= 0; i-- { - if pc.hooks[i] == nil { - return nil, fmt.Errorf("db: uninitialized hook (forgotten import db/runtime?)") - } - mut = pc.hooks[i](mut) - } - v, err := mut.Mutate(ctx, pc.mutation) - if err != nil { - return nil, err - } - nv, ok := v.(*Password) - if !ok { - return nil, fmt.Errorf("unexpected node type %T returned from PasswordMutation", v) - } - node = nv - } - return node, err + return withHooks[*Password, PasswordMutation](ctx, pc.sqlSave, pc.mutation, pc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -150,6 +108,9 @@ func (pc *PasswordCreate) check() error { } func (pc *PasswordCreate) sqlSave(ctx context.Context) (*Password, error) { + if err := pc.check(); err != nil { + return nil, err + } _node, _spec := pc.createSpec() if err := sqlgraph.CreateNode(ctx, pc.driver, _spec); err != nil { if sqlgraph.IsConstraintError(err) { @@ -159,50 +120,30 @@ func (pc *PasswordCreate) sqlSave(ctx context.Context) (*Password, error) { } id := _spec.ID.Value.(int64) _node.ID = int(id) + pc.mutation.id = &_node.ID + pc.mutation.done = true return _node, nil } func (pc *PasswordCreate) createSpec() (*Password, *sqlgraph.CreateSpec) { var ( _node = &Password{config: pc.config} - _spec = &sqlgraph.CreateSpec{ - Table: password.Table, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeInt, - Column: password.FieldID, - }, - } + _spec = sqlgraph.NewCreateSpec(password.Table, sqlgraph.NewFieldSpec(password.FieldID, field.TypeInt)) ) if value, ok := pc.mutation.Email(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: password.FieldEmail, - }) + _spec.SetField(password.FieldEmail, field.TypeString, value) _node.Email = value } if value, ok := pc.mutation.Hash(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeBytes, - Value: value, - Column: password.FieldHash, - }) + _spec.SetField(password.FieldHash, field.TypeBytes, value) _node.Hash = value } if value, ok := pc.mutation.Username(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: password.FieldUsername, - }) + _spec.SetField(password.FieldUsername, field.TypeString, value) _node.Username = value } if value, ok := pc.mutation.UserID(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: password.FieldUserID, - }) + _spec.SetField(password.FieldUserID, field.TypeString, value) _node.UserID = value } return _node, _spec diff --git a/storage/ent/db/password_delete.go b/storage/ent/db/password_delete.go index 6bbe5af5..964430c6 100644 --- a/storage/ent/db/password_delete.go +++ b/storage/ent/db/password_delete.go @@ -4,7 +4,6 @@ package db import ( "context" - "fmt" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" @@ -28,34 +27,7 @@ func (pd *PasswordDelete) Where(ps ...predicate.Password) *PasswordDelete { // Exec executes the deletion query and returns how many vertices were deleted. func (pd *PasswordDelete) Exec(ctx context.Context) (int, error) { - var ( - err error - affected int - ) - if len(pd.hooks) == 0 { - affected, err = pd.sqlExec(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*PasswordMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - pd.mutation = mutation - affected, err = pd.sqlExec(ctx) - mutation.done = true - return affected, err - }) - for i := len(pd.hooks) - 1; i >= 0; i-- { - if pd.hooks[i] == nil { - return 0, fmt.Errorf("db: uninitialized hook (forgotten import db/runtime?)") - } - mut = pd.hooks[i](mut) - } - if _, err := mut.Mutate(ctx, pd.mutation); err != nil { - return 0, err - } - } - return affected, err + return withHooks[int, PasswordMutation](ctx, pd.sqlExec, pd.mutation, pd.hooks) } // ExecX is like Exec, but panics if an error occurs. @@ -68,15 +40,7 @@ func (pd *PasswordDelete) ExecX(ctx context.Context) int { } func (pd *PasswordDelete) sqlExec(ctx context.Context) (int, error) { - _spec := &sqlgraph.DeleteSpec{ - Node: &sqlgraph.NodeSpec{ - Table: password.Table, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeInt, - Column: password.FieldID, - }, - }, - } + _spec := sqlgraph.NewDeleteSpec(password.Table, sqlgraph.NewFieldSpec(password.FieldID, field.TypeInt)) if ps := pd.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { @@ -88,6 +52,7 @@ func (pd *PasswordDelete) sqlExec(ctx context.Context) (int, error) { if err != nil && sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } + pd.mutation.done = true return affected, err } @@ -96,6 +61,12 @@ type PasswordDeleteOne struct { pd *PasswordDelete } +// Where appends a list predicates to the PasswordDelete builder. +func (pdo *PasswordDeleteOne) Where(ps ...predicate.Password) *PasswordDeleteOne { + pdo.pd.mutation.Where(ps...) + return pdo +} + // Exec executes the deletion query. func (pdo *PasswordDeleteOne) Exec(ctx context.Context) error { n, err := pdo.pd.Exec(ctx) @@ -111,5 +82,7 @@ func (pdo *PasswordDeleteOne) Exec(ctx context.Context) error { // ExecX is like Exec, but panics if an error occurs. func (pdo *PasswordDeleteOne) ExecX(ctx context.Context) { - pdo.pd.ExecX(ctx) + if err := pdo.Exec(ctx); err != nil { + panic(err) + } } diff --git a/storage/ent/db/password_query.go b/storage/ent/db/password_query.go index 0da4d08a..6a216658 100644 --- a/storage/ent/db/password_query.go +++ b/storage/ent/db/password_query.go @@ -17,11 +17,9 @@ import ( // PasswordQuery is the builder for querying Password entities. type PasswordQuery struct { config - limit *int - offset *int - unique *bool + ctx *QueryContext order []OrderFunc - fields []string + inters []Interceptor predicates []predicate.Password // intermediate query (i.e. traversal path). sql *sql.Selector @@ -34,26 +32,26 @@ func (pq *PasswordQuery) Where(ps ...predicate.Password) *PasswordQuery { return pq } -// Limit adds a limit step to the query. +// Limit the number of records to be returned by this query. func (pq *PasswordQuery) Limit(limit int) *PasswordQuery { - pq.limit = &limit + pq.ctx.Limit = &limit return pq } -// Offset adds an offset step to the query. +// Offset to start from. func (pq *PasswordQuery) Offset(offset int) *PasswordQuery { - pq.offset = &offset + pq.ctx.Offset = &offset return pq } // Unique configures the query builder to filter duplicate records on query. // By default, unique is set to true, and can be disabled using this method. func (pq *PasswordQuery) Unique(unique bool) *PasswordQuery { - pq.unique = &unique + pq.ctx.Unique = &unique return pq } -// Order adds an order step to the query. +// Order specifies how the records should be ordered. func (pq *PasswordQuery) Order(o ...OrderFunc) *PasswordQuery { pq.order = append(pq.order, o...) return pq @@ -62,7 +60,7 @@ func (pq *PasswordQuery) Order(o ...OrderFunc) *PasswordQuery { // First returns the first Password entity from the query. // Returns a *NotFoundError when no Password was found. func (pq *PasswordQuery) First(ctx context.Context) (*Password, error) { - nodes, err := pq.Limit(1).All(ctx) + nodes, err := pq.Limit(1).All(setContextOp(ctx, pq.ctx, "First")) if err != nil { return nil, err } @@ -85,7 +83,7 @@ func (pq *PasswordQuery) FirstX(ctx context.Context) *Password { // Returns a *NotFoundError when no Password ID was found. func (pq *PasswordQuery) FirstID(ctx context.Context) (id int, err error) { var ids []int - if ids, err = pq.Limit(1).IDs(ctx); err != nil { + if ids, err = pq.Limit(1).IDs(setContextOp(ctx, pq.ctx, "FirstID")); err != nil { return } if len(ids) == 0 { @@ -108,7 +106,7 @@ func (pq *PasswordQuery) FirstIDX(ctx context.Context) int { // 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) + nodes, err := pq.Limit(2).All(setContextOp(ctx, pq.ctx, "Only")) if err != nil { return nil, err } @@ -136,7 +134,7 @@ func (pq *PasswordQuery) OnlyX(ctx context.Context) *Password { // Returns a *NotFoundError when no entities are found. func (pq *PasswordQuery) OnlyID(ctx context.Context) (id int, err error) { var ids []int - if ids, err = pq.Limit(2).IDs(ctx); err != nil { + if ids, err = pq.Limit(2).IDs(setContextOp(ctx, pq.ctx, "OnlyID")); err != nil { return } switch len(ids) { @@ -161,10 +159,12 @@ func (pq *PasswordQuery) OnlyIDX(ctx context.Context) int { // All executes the query and returns a list of Passwords. func (pq *PasswordQuery) All(ctx context.Context) ([]*Password, error) { + ctx = setContextOp(ctx, pq.ctx, "All") if err := pq.prepareQuery(ctx); err != nil { return nil, err } - return pq.sqlAll(ctx) + qr := querierAll[[]*Password, *PasswordQuery]() + return withInterceptors[[]*Password](ctx, pq, qr, pq.inters) } // AllX is like All, but panics if an error occurs. @@ -177,9 +177,12 @@ func (pq *PasswordQuery) AllX(ctx context.Context) []*Password { } // IDs executes the query and returns a list of Password IDs. -func (pq *PasswordQuery) IDs(ctx context.Context) ([]int, error) { - var ids []int - if err := pq.Select(password.FieldID).Scan(ctx, &ids); err != nil { +func (pq *PasswordQuery) IDs(ctx context.Context) (ids []int, err error) { + if pq.ctx.Unique == nil && pq.path != nil { + pq.Unique(true) + } + ctx = setContextOp(ctx, pq.ctx, "IDs") + if err = pq.Select(password.FieldID).Scan(ctx, &ids); err != nil { return nil, err } return ids, nil @@ -196,10 +199,11 @@ func (pq *PasswordQuery) IDsX(ctx context.Context) []int { // Count returns the count of the given query. func (pq *PasswordQuery) Count(ctx context.Context) (int, error) { + ctx = setContextOp(ctx, pq.ctx, "Count") if err := pq.prepareQuery(ctx); err != nil { return 0, err } - return pq.sqlCount(ctx) + return withInterceptors[int](ctx, pq, querierCount[*PasswordQuery](), pq.inters) } // CountX is like Count, but panics if an error occurs. @@ -213,10 +217,15 @@ func (pq *PasswordQuery) CountX(ctx context.Context) int { // Exist returns true if the query has elements in the graph. func (pq *PasswordQuery) Exist(ctx context.Context) (bool, error) { - if err := pq.prepareQuery(ctx); err != nil { - return false, err + ctx = setContextOp(ctx, pq.ctx, "Exist") + switch _, err := pq.FirstID(ctx); { + case IsNotFound(err): + return false, nil + case err != nil: + return false, fmt.Errorf("db: check existence: %w", err) + default: + return true, nil } - return pq.sqlExist(ctx) } // ExistX is like Exist, but panics if an error occurs. @@ -236,14 +245,13 @@ func (pq *PasswordQuery) Clone() *PasswordQuery { } return &PasswordQuery{ config: pq.config, - limit: pq.limit, - offset: pq.offset, + ctx: pq.ctx.Clone(), order: append([]OrderFunc{}, pq.order...), + inters: append([]Interceptor{}, pq.inters...), predicates: append([]predicate.Password{}, pq.predicates...), // clone intermediate query. - sql: pq.sql.Clone(), - path: pq.path, - unique: pq.unique, + sql: pq.sql.Clone(), + path: pq.path, } } @@ -261,18 +269,12 @@ func (pq *PasswordQuery) Clone() *PasswordQuery { // GroupBy(password.FieldEmail). // Aggregate(db.Count()). // Scan(ctx, &v) -// func (pq *PasswordQuery) GroupBy(field string, fields ...string) *PasswordGroupBy { - grbuild := &PasswordGroupBy{config: pq.config} - grbuild.fields = append([]string{field}, fields...) - grbuild.path = func(ctx context.Context) (prev *sql.Selector, err error) { - if err := pq.prepareQuery(ctx); err != nil { - return nil, err - } - return pq.sqlQuery(ctx), nil - } + pq.ctx.Fields = append([]string{field}, fields...) + grbuild := &PasswordGroupBy{build: pq} + grbuild.flds = &pq.ctx.Fields grbuild.label = password.Label - grbuild.flds, grbuild.scan = &grbuild.fields, grbuild.Scan + grbuild.scan = grbuild.Scan return grbuild } @@ -288,17 +290,31 @@ func (pq *PasswordQuery) GroupBy(field string, fields ...string) *PasswordGroupB // client.Password.Query(). // Select(password.FieldEmail). // Scan(ctx, &v) -// func (pq *PasswordQuery) Select(fields ...string) *PasswordSelect { - pq.fields = append(pq.fields, fields...) - selbuild := &PasswordSelect{PasswordQuery: pq} - selbuild.label = password.Label - selbuild.flds, selbuild.scan = &pq.fields, selbuild.Scan - return selbuild + pq.ctx.Fields = append(pq.ctx.Fields, fields...) + sbuild := &PasswordSelect{PasswordQuery: pq} + sbuild.label = password.Label + sbuild.flds, sbuild.scan = &pq.ctx.Fields, sbuild.Scan + return sbuild +} + +// Aggregate returns a PasswordSelect configured with the given aggregations. +func (pq *PasswordQuery) Aggregate(fns ...AggregateFunc) *PasswordSelect { + return pq.Select().Aggregate(fns...) } func (pq *PasswordQuery) prepareQuery(ctx context.Context) error { - for _, f := range pq.fields { + for _, inter := range pq.inters { + if inter == nil { + return fmt.Errorf("db: uninitialized interceptor (forgotten import db/runtime?)") + } + if trv, ok := inter.(Traverser); ok { + if err := trv.Traverse(ctx, pq); err != nil { + return err + } + } + } + for _, f := range pq.ctx.Fields { if !password.ValidColumn(f) { return &ValidationError{Name: f, err: fmt.Errorf("db: invalid field %q for query", f)} } @@ -318,10 +334,10 @@ func (pq *PasswordQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Pas nodes = []*Password{} _spec = pq.querySpec() ) - _spec.ScanValues = func(columns []string) ([]interface{}, error) { + _spec.ScanValues = func(columns []string) ([]any, error) { return (*Password).scanValues(nil, columns) } - _spec.Assign = func(columns []string, values []interface{}) error { + _spec.Assign = func(columns []string, values []any) error { node := &Password{config: pq.config} nodes = append(nodes, node) return node.assignValues(columns, values) @@ -340,38 +356,22 @@ func (pq *PasswordQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Pas 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 + _spec.Node.Columns = pq.ctx.Fields + if len(pq.ctx.Fields) > 0 { + _spec.Unique = pq.ctx.Unique != nil && *pq.ctx.Unique } return sqlgraph.CountNodes(ctx, pq.driver, _spec) } -func (pq *PasswordQuery) sqlExist(ctx context.Context) (bool, error) { - n, err := pq.sqlCount(ctx) - if err != nil { - return false, fmt.Errorf("db: check existence: %w", err) - } - return n > 0, nil -} - func (pq *PasswordQuery) querySpec() *sqlgraph.QuerySpec { - _spec := &sqlgraph.QuerySpec{ - Node: &sqlgraph.NodeSpec{ - Table: password.Table, - Columns: password.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeInt, - Column: password.FieldID, - }, - }, - From: pq.sql, - Unique: true, - } - if unique := pq.unique; unique != nil { + _spec := sqlgraph.NewQuerySpec(password.Table, password.Columns, sqlgraph.NewFieldSpec(password.FieldID, field.TypeInt)) + _spec.From = pq.sql + if unique := pq.ctx.Unique; unique != nil { _spec.Unique = *unique + } else if pq.path != nil { + _spec.Unique = true } - if fields := pq.fields; len(fields) > 0 { + if fields := pq.ctx.Fields; len(fields) > 0 { _spec.Node.Columns = make([]string, 0, len(fields)) _spec.Node.Columns = append(_spec.Node.Columns, password.FieldID) for i := range fields { @@ -387,10 +387,10 @@ func (pq *PasswordQuery) querySpec() *sqlgraph.QuerySpec { } } } - if limit := pq.limit; limit != nil { + if limit := pq.ctx.Limit; limit != nil { _spec.Limit = *limit } - if offset := pq.offset; offset != nil { + if offset := pq.ctx.Offset; offset != nil { _spec.Offset = *offset } if ps := pq.order; len(ps) > 0 { @@ -406,7 +406,7 @@ func (pq *PasswordQuery) querySpec() *sqlgraph.QuerySpec { func (pq *PasswordQuery) sqlQuery(ctx context.Context) *sql.Selector { builder := sql.Dialect(pq.driver.Dialect()) t1 := builder.Table(password.Table) - columns := pq.fields + columns := pq.ctx.Fields if len(columns) == 0 { columns = password.Columns } @@ -415,7 +415,7 @@ func (pq *PasswordQuery) sqlQuery(ctx context.Context) *sql.Selector { selector = pq.sql selector.Select(selector.Columns(columns...)...) } - if pq.unique != nil && *pq.unique { + if pq.ctx.Unique != nil && *pq.ctx.Unique { selector.Distinct() } for _, p := range pq.predicates { @@ -424,12 +424,12 @@ func (pq *PasswordQuery) sqlQuery(ctx context.Context) *sql.Selector { for _, p := range pq.order { p(selector) } - if offset := pq.offset; offset != nil { + if offset := pq.ctx.Offset; offset != nil { // limit is mandatory for offset clause. We start // with default value, and override it below if needed. selector.Offset(*offset).Limit(math.MaxInt32) } - if limit := pq.limit; limit != nil { + if limit := pq.ctx.Limit; limit != nil { selector.Limit(*limit) } return selector @@ -437,13 +437,8 @@ func (pq *PasswordQuery) sqlQuery(ctx context.Context) *sql.Selector { // PasswordGroupBy is the group-by builder for Password entities. type PasswordGroupBy struct { - config selector - fields []string - fns []AggregateFunc - // intermediate query (i.e. traversal path). - sql *sql.Selector - path func(context.Context) (*sql.Selector, error) + build *PasswordQuery } // Aggregate adds the given aggregation functions to the group-by query. @@ -452,74 +447,77 @@ func (pgb *PasswordGroupBy) Aggregate(fns ...AggregateFunc) *PasswordGroupBy { return pgb } -// Scan applies the group-by query and scans the result into the given value. -func (pgb *PasswordGroupBy) Scan(ctx context.Context, v interface{}) error { - query, err := pgb.path(ctx) - if err != nil { +// Scan applies the selector query and scans the result into the given value. +func (pgb *PasswordGroupBy) Scan(ctx context.Context, v any) error { + ctx = setContextOp(ctx, pgb.build.ctx, "GroupBy") + if err := pgb.build.prepareQuery(ctx); err != nil { return err } - pgb.sql = query - return pgb.sqlScan(ctx, v) + return scanWithInterceptors[*PasswordQuery, *PasswordGroupBy](ctx, pgb.build, pgb, pgb.build.inters, v) } -func (pgb *PasswordGroupBy) sqlScan(ctx context.Context, v interface{}) error { - for _, f := range pgb.fields { - if !password.ValidColumn(f) { - return &ValidationError{Name: f, err: fmt.Errorf("invalid field %q for group-by", f)} - } - } - selector := pgb.sqlQuery() - if err := selector.Err(); err != nil { - return err - } - rows := &sql.Rows{} - query, args := selector.Query() - if err := pgb.driver.Query(ctx, query, args, rows); err != nil { - return err - } - defer rows.Close() - return sql.ScanSlice(rows, v) -} - -func (pgb *PasswordGroupBy) sqlQuery() *sql.Selector { - selector := pgb.sql.Select() +func (pgb *PasswordGroupBy) sqlScan(ctx context.Context, root *PasswordQuery, v any) error { + selector := root.sqlQuery(ctx).Select() aggregation := make([]string, 0, len(pgb.fns)) for _, fn := range pgb.fns { aggregation = append(aggregation, fn(selector)) } - // If no columns were selected in a custom aggregation function, the default - // selection is the fields used for "group-by", and the aggregation functions. if len(selector.SelectedColumns()) == 0 { - columns := make([]string, 0, len(pgb.fields)+len(pgb.fns)) - for _, f := range pgb.fields { + columns := make([]string, 0, len(*pgb.flds)+len(pgb.fns)) + for _, f := range *pgb.flds { columns = append(columns, selector.C(f)) } columns = append(columns, aggregation...) selector.Select(columns...) } - return selector.GroupBy(selector.Columns(pgb.fields...)...) + selector.GroupBy(selector.Columns(*pgb.flds...)...) + if err := selector.Err(); err != nil { + return err + } + rows := &sql.Rows{} + query, args := selector.Query() + if err := pgb.build.driver.Query(ctx, query, args, rows); err != nil { + return err + } + defer rows.Close() + return sql.ScanSlice(rows, v) } // PasswordSelect is the builder for selecting fields of Password entities. type PasswordSelect struct { *PasswordQuery selector - // intermediate query (i.e. traversal path). - sql *sql.Selector +} + +// Aggregate adds the given aggregation functions to the selector query. +func (ps *PasswordSelect) Aggregate(fns ...AggregateFunc) *PasswordSelect { + ps.fns = append(ps.fns, fns...) + return ps } // Scan applies the selector query and scans the result into the given value. -func (ps *PasswordSelect) Scan(ctx context.Context, v interface{}) error { +func (ps *PasswordSelect) Scan(ctx context.Context, v any) error { + ctx = setContextOp(ctx, ps.ctx, "Select") if err := ps.prepareQuery(ctx); err != nil { return err } - ps.sql = ps.PasswordQuery.sqlQuery(ctx) - return ps.sqlScan(ctx, v) + return scanWithInterceptors[*PasswordQuery, *PasswordSelect](ctx, ps.PasswordQuery, ps, ps.inters, v) } -func (ps *PasswordSelect) sqlScan(ctx context.Context, v interface{}) error { +func (ps *PasswordSelect) sqlScan(ctx context.Context, root *PasswordQuery, v any) error { + selector := root.sqlQuery(ctx) + aggregation := make([]string, 0, len(ps.fns)) + for _, fn := range ps.fns { + aggregation = append(aggregation, fn(selector)) + } + switch n := len(*ps.selector.flds); { + case n == 0 && len(aggregation) > 0: + selector.Select(aggregation...) + case n != 0 && len(aggregation) > 0: + selector.AppendSelect(aggregation...) + } rows := &sql.Rows{} - query, args := ps.sql.Query() + query, args := selector.Query() if err := ps.driver.Query(ctx, query, args, rows); err != nil { return err } diff --git a/storage/ent/db/password_update.go b/storage/ent/db/password_update.go index 8d149991..03bf6ab4 100644 --- a/storage/ent/db/password_update.go +++ b/storage/ent/db/password_update.go @@ -58,40 +58,7 @@ func (pu *PasswordUpdate) Mutation() *PasswordMutation { // Save executes the query and returns the number of nodes affected by the update operation. func (pu *PasswordUpdate) Save(ctx context.Context) (int, error) { - var ( - err error - affected int - ) - if len(pu.hooks) == 0 { - if err = pu.check(); err != nil { - return 0, err - } - affected, err = pu.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*PasswordMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err = pu.check(); err != nil { - return 0, err - } - pu.mutation = mutation - affected, err = pu.sqlSave(ctx) - mutation.done = true - return affected, err - }) - for i := len(pu.hooks) - 1; i >= 0; i-- { - if pu.hooks[i] == nil { - return 0, fmt.Errorf("db: uninitialized hook (forgotten import db/runtime?)") - } - mut = pu.hooks[i](mut) - } - if _, err := mut.Mutate(ctx, pu.mutation); err != nil { - return 0, err - } - } - return affected, err + return withHooks[int, PasswordMutation](ctx, pu.sqlSave, pu.mutation, pu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -137,16 +104,10 @@ func (pu *PasswordUpdate) check() error { } func (pu *PasswordUpdate) sqlSave(ctx context.Context) (n int, err error) { - _spec := &sqlgraph.UpdateSpec{ - Node: &sqlgraph.NodeSpec{ - Table: password.Table, - Columns: password.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeInt, - Column: password.FieldID, - }, - }, + if err := pu.check(); err != nil { + return n, err } + _spec := sqlgraph.NewUpdateSpec(password.Table, password.Columns, sqlgraph.NewFieldSpec(password.FieldID, field.TypeInt)) if ps := pu.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { @@ -155,32 +116,16 @@ func (pu *PasswordUpdate) sqlSave(ctx context.Context) (n int, err error) { } } if value, ok := pu.mutation.Email(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: password.FieldEmail, - }) + _spec.SetField(password.FieldEmail, field.TypeString, value) } if value, ok := pu.mutation.Hash(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeBytes, - Value: value, - Column: password.FieldHash, - }) + _spec.SetField(password.FieldHash, field.TypeBytes, value) } if value, ok := pu.mutation.Username(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: password.FieldUsername, - }) + _spec.SetField(password.FieldUsername, field.TypeString, value) } if value, ok := pu.mutation.UserID(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: password.FieldUserID, - }) + _spec.SetField(password.FieldUserID, field.TypeString, value) } if n, err = sqlgraph.UpdateNodes(ctx, pu.driver, _spec); err != nil { if _, ok := err.(*sqlgraph.NotFoundError); ok { @@ -190,6 +135,7 @@ func (pu *PasswordUpdate) sqlSave(ctx context.Context) (n int, err error) { } return 0, err } + pu.mutation.done = true return n, nil } @@ -230,6 +176,12 @@ func (puo *PasswordUpdateOne) Mutation() *PasswordMutation { return puo.mutation } +// Where appends a list predicates to the PasswordUpdate builder. +func (puo *PasswordUpdateOne) Where(ps ...predicate.Password) *PasswordUpdateOne { + puo.mutation.Where(ps...) + return puo +} + // Select allows selecting one or more fields (columns) of the returned entity. // The default is selecting all fields defined in the entity schema. func (puo *PasswordUpdateOne) Select(field string, fields ...string) *PasswordUpdateOne { @@ -239,46 +191,7 @@ func (puo *PasswordUpdateOne) Select(field string, fields ...string) *PasswordUp // Save executes the query and returns the updated Password entity. func (puo *PasswordUpdateOne) Save(ctx context.Context) (*Password, error) { - var ( - err error - node *Password - ) - if len(puo.hooks) == 0 { - if err = puo.check(); err != nil { - return nil, err - } - node, err = puo.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*PasswordMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err = puo.check(); err != nil { - return nil, err - } - puo.mutation = mutation - node, err = puo.sqlSave(ctx) - mutation.done = true - return node, err - }) - for i := len(puo.hooks) - 1; i >= 0; i-- { - if puo.hooks[i] == nil { - return nil, fmt.Errorf("db: uninitialized hook (forgotten import db/runtime?)") - } - mut = puo.hooks[i](mut) - } - v, err := mut.Mutate(ctx, puo.mutation) - if err != nil { - return nil, err - } - nv, ok := v.(*Password) - if !ok { - return nil, fmt.Errorf("unexpected node type %T returned from PasswordMutation", v) - } - node = nv - } - return node, err + return withHooks[*Password, PasswordMutation](ctx, puo.sqlSave, puo.mutation, puo.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -324,16 +237,10 @@ func (puo *PasswordUpdateOne) check() error { } func (puo *PasswordUpdateOne) sqlSave(ctx context.Context) (_node *Password, err error) { - _spec := &sqlgraph.UpdateSpec{ - Node: &sqlgraph.NodeSpec{ - Table: password.Table, - Columns: password.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeInt, - Column: password.FieldID, - }, - }, + if err := puo.check(); err != nil { + return _node, err } + _spec := sqlgraph.NewUpdateSpec(password.Table, password.Columns, sqlgraph.NewFieldSpec(password.FieldID, field.TypeInt)) id, ok := puo.mutation.ID() if !ok { return nil, &ValidationError{Name: "id", err: errors.New(`db: missing "Password.id" for update`)} @@ -359,32 +266,16 @@ func (puo *PasswordUpdateOne) sqlSave(ctx context.Context) (_node *Password, err } } if value, ok := puo.mutation.Email(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: password.FieldEmail, - }) + _spec.SetField(password.FieldEmail, field.TypeString, value) } if value, ok := puo.mutation.Hash(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeBytes, - Value: value, - Column: password.FieldHash, - }) + _spec.SetField(password.FieldHash, field.TypeBytes, value) } if value, ok := puo.mutation.Username(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: password.FieldUsername, - }) + _spec.SetField(password.FieldUsername, field.TypeString, value) } if value, ok := puo.mutation.UserID(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: password.FieldUserID, - }) + _spec.SetField(password.FieldUserID, field.TypeString, value) } _node = &Password{config: puo.config} _spec.Assign = _node.assignValues @@ -397,5 +288,6 @@ func (puo *PasswordUpdateOne) sqlSave(ctx context.Context) (_node *Password, err } return nil, err } + puo.mutation.done = true return _node, nil } diff --git a/storage/ent/db/refreshtoken.go b/storage/ent/db/refreshtoken.go index b5c75bb1..78fb79e7 100644 --- a/storage/ent/db/refreshtoken.go +++ b/storage/ent/db/refreshtoken.go @@ -50,8 +50,8 @@ type RefreshToken struct { } // scanValues returns the types for scanning values from sql.Rows. -func (*RefreshToken) scanValues(columns []string) ([]interface{}, error) { - values := make([]interface{}, len(columns)) +func (*RefreshToken) scanValues(columns []string) ([]any, error) { + values := make([]any, len(columns)) for i := range columns { switch columns[i] { case refreshtoken.FieldScopes, refreshtoken.FieldClaimsGroups, refreshtoken.FieldConnectorData: @@ -71,7 +71,7 @@ func (*RefreshToken) scanValues(columns []string) ([]interface{}, error) { // assignValues assigns the values that were returned from sql.Rows (after scanning) // to the RefreshToken fields. -func (rt *RefreshToken) assignValues(columns []string, values []interface{}) error { +func (rt *RefreshToken) assignValues(columns []string, values []any) error { if m, n := len(values), len(columns); m < n { return fmt.Errorf("mismatch number of scan values: %d != %d", m, n) } @@ -186,7 +186,7 @@ func (rt *RefreshToken) assignValues(columns []string, values []interface{}) err // Note that you need to call RefreshToken.Unwrap() before calling this method if this RefreshToken // was returned from a transaction, and the transaction was committed or rolled back. func (rt *RefreshToken) Update() *RefreshTokenUpdateOne { - return (&RefreshTokenClient{config: rt.config}).UpdateOne(rt) + return NewRefreshTokenClient(rt.config).UpdateOne(rt) } // Unwrap unwraps the RefreshToken entity that was returned from a transaction after it was closed, @@ -257,9 +257,3 @@ func (rt *RefreshToken) String() string { // RefreshTokens is a parsable slice of RefreshToken. type RefreshTokens []*RefreshToken - -func (rt RefreshTokens) config(cfg config) { - for _i := range rt { - rt[_i].config = cfg - } -} diff --git a/storage/ent/db/refreshtoken/where.go b/storage/ent/db/refreshtoken/where.go index e6abf982..ce3a10de 100644 --- a/storage/ent/db/refreshtoken/where.go +++ b/storage/ent/db/refreshtoken/where.go @@ -11,1303 +11,857 @@ import ( // ID filters vertices based on their ID field. func ID(id string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldID), id)) - }) + return predicate.RefreshToken(sql.FieldEQ(FieldID, id)) } // IDEQ applies the EQ predicate on the ID field. func IDEQ(id string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldID), id)) - }) + return predicate.RefreshToken(sql.FieldEQ(FieldID, id)) } // IDNEQ applies the NEQ predicate on the ID field. func IDNEQ(id string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldID), id)) - }) + return predicate.RefreshToken(sql.FieldNEQ(FieldID, id)) } // IDIn applies the In predicate on the ID field. func IDIn(ids ...string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - v := make([]interface{}, len(ids)) - for i := range v { - v[i] = ids[i] - } - s.Where(sql.In(s.C(FieldID), v...)) - }) + return predicate.RefreshToken(sql.FieldIn(FieldID, ids...)) } // IDNotIn applies the NotIn predicate on the ID field. func IDNotIn(ids ...string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - v := make([]interface{}, len(ids)) - for i := range v { - v[i] = ids[i] - } - s.Where(sql.NotIn(s.C(FieldID), v...)) - }) + return predicate.RefreshToken(sql.FieldNotIn(FieldID, ids...)) } // IDGT applies the GT predicate on the ID field. func IDGT(id string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldID), id)) - }) + return predicate.RefreshToken(sql.FieldGT(FieldID, id)) } // IDGTE applies the GTE predicate on the ID field. func IDGTE(id string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldID), id)) - }) + return predicate.RefreshToken(sql.FieldGTE(FieldID, id)) } // IDLT applies the LT predicate on the ID field. func IDLT(id string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldID), id)) - }) + return predicate.RefreshToken(sql.FieldLT(FieldID, id)) } // IDLTE applies the LTE predicate on the ID field. func IDLTE(id string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldID), id)) - }) + return predicate.RefreshToken(sql.FieldLTE(FieldID, id)) } // ClientID applies equality check predicate on the "client_id" field. It's identical to ClientIDEQ. func ClientID(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldClientID), v)) - }) + return predicate.RefreshToken(sql.FieldEQ(FieldClientID, v)) } // Nonce applies equality check predicate on the "nonce" field. It's identical to NonceEQ. func Nonce(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldNonce), v)) - }) + return predicate.RefreshToken(sql.FieldEQ(FieldNonce, v)) } // ClaimsUserID applies equality check predicate on the "claims_user_id" field. It's identical to ClaimsUserIDEQ. func ClaimsUserID(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldClaimsUserID), v)) - }) + return predicate.RefreshToken(sql.FieldEQ(FieldClaimsUserID, v)) } // ClaimsUsername applies equality check predicate on the "claims_username" field. It's identical to ClaimsUsernameEQ. func ClaimsUsername(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldClaimsUsername), v)) - }) + return predicate.RefreshToken(sql.FieldEQ(FieldClaimsUsername, v)) } // ClaimsEmail applies equality check predicate on the "claims_email" field. It's identical to ClaimsEmailEQ. func ClaimsEmail(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldClaimsEmail), v)) - }) + return predicate.RefreshToken(sql.FieldEQ(FieldClaimsEmail, v)) } // ClaimsEmailVerified applies equality check predicate on the "claims_email_verified" field. It's identical to ClaimsEmailVerifiedEQ. func ClaimsEmailVerified(v bool) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldClaimsEmailVerified), v)) - }) + return predicate.RefreshToken(sql.FieldEQ(FieldClaimsEmailVerified, v)) } // ClaimsPreferredUsername applies equality check predicate on the "claims_preferred_username" field. It's identical to ClaimsPreferredUsernameEQ. func ClaimsPreferredUsername(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldClaimsPreferredUsername), v)) - }) + return predicate.RefreshToken(sql.FieldEQ(FieldClaimsPreferredUsername, v)) } // ConnectorID applies equality check predicate on the "connector_id" field. It's identical to ConnectorIDEQ. func ConnectorID(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldConnectorID), v)) - }) + return predicate.RefreshToken(sql.FieldEQ(FieldConnectorID, v)) } // ConnectorData applies equality check predicate on the "connector_data" field. It's identical to ConnectorDataEQ. func ConnectorData(v []byte) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldConnectorData), v)) - }) + return predicate.RefreshToken(sql.FieldEQ(FieldConnectorData, v)) } // Token applies equality check predicate on the "token" field. It's identical to TokenEQ. func Token(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldToken), v)) - }) + return predicate.RefreshToken(sql.FieldEQ(FieldToken, v)) } // ObsoleteToken applies equality check predicate on the "obsolete_token" field. It's identical to ObsoleteTokenEQ. func ObsoleteToken(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldObsoleteToken), v)) - }) + return predicate.RefreshToken(sql.FieldEQ(FieldObsoleteToken, v)) } // CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ. func CreatedAt(v time.Time) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldCreatedAt), v)) - }) + return predicate.RefreshToken(sql.FieldEQ(FieldCreatedAt, v)) } // LastUsed applies equality check predicate on the "last_used" field. It's identical to LastUsedEQ. func LastUsed(v time.Time) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldLastUsed), v)) - }) + return predicate.RefreshToken(sql.FieldEQ(FieldLastUsed, v)) } // ClientIDEQ applies the EQ predicate on the "client_id" field. func ClientIDEQ(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldClientID), v)) - }) + return predicate.RefreshToken(sql.FieldEQ(FieldClientID, v)) } // ClientIDNEQ applies the NEQ predicate on the "client_id" field. func ClientIDNEQ(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldClientID), v)) - }) + return predicate.RefreshToken(sql.FieldNEQ(FieldClientID, v)) } // ClientIDIn applies the In predicate on the "client_id" field. func ClientIDIn(vs ...string) predicate.RefreshToken { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldClientID), v...)) - }) + return predicate.RefreshToken(sql.FieldIn(FieldClientID, vs...)) } // ClientIDNotIn applies the NotIn predicate on the "client_id" field. func ClientIDNotIn(vs ...string) predicate.RefreshToken { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldClientID), v...)) - }) + return predicate.RefreshToken(sql.FieldNotIn(FieldClientID, vs...)) } // ClientIDGT applies the GT predicate on the "client_id" field. func ClientIDGT(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldClientID), v)) - }) + return predicate.RefreshToken(sql.FieldGT(FieldClientID, v)) } // ClientIDGTE applies the GTE predicate on the "client_id" field. func ClientIDGTE(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldClientID), v)) - }) + return predicate.RefreshToken(sql.FieldGTE(FieldClientID, v)) } // ClientIDLT applies the LT predicate on the "client_id" field. func ClientIDLT(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldClientID), v)) - }) + return predicate.RefreshToken(sql.FieldLT(FieldClientID, v)) } // ClientIDLTE applies the LTE predicate on the "client_id" field. func ClientIDLTE(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldClientID), v)) - }) + return predicate.RefreshToken(sql.FieldLTE(FieldClientID, v)) } // ClientIDContains applies the Contains predicate on the "client_id" field. func ClientIDContains(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldClientID), v)) - }) + return predicate.RefreshToken(sql.FieldContains(FieldClientID, v)) } // ClientIDHasPrefix applies the HasPrefix predicate on the "client_id" field. func ClientIDHasPrefix(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldClientID), v)) - }) + return predicate.RefreshToken(sql.FieldHasPrefix(FieldClientID, v)) } // ClientIDHasSuffix applies the HasSuffix predicate on the "client_id" field. func ClientIDHasSuffix(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldClientID), v)) - }) + return predicate.RefreshToken(sql.FieldHasSuffix(FieldClientID, v)) } // ClientIDEqualFold applies the EqualFold predicate on the "client_id" field. func ClientIDEqualFold(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldClientID), v)) - }) + return predicate.RefreshToken(sql.FieldEqualFold(FieldClientID, v)) } // ClientIDContainsFold applies the ContainsFold predicate on the "client_id" field. func ClientIDContainsFold(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldClientID), v)) - }) + return predicate.RefreshToken(sql.FieldContainsFold(FieldClientID, v)) } // ScopesIsNil applies the IsNil predicate on the "scopes" field. func ScopesIsNil() predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.IsNull(s.C(FieldScopes))) - }) + return predicate.RefreshToken(sql.FieldIsNull(FieldScopes)) } // ScopesNotNil applies the NotNil predicate on the "scopes" field. func ScopesNotNil() predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.NotNull(s.C(FieldScopes))) - }) + return predicate.RefreshToken(sql.FieldNotNull(FieldScopes)) } // NonceEQ applies the EQ predicate on the "nonce" field. func NonceEQ(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldNonce), v)) - }) + return predicate.RefreshToken(sql.FieldEQ(FieldNonce, v)) } // NonceNEQ applies the NEQ predicate on the "nonce" field. func NonceNEQ(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldNonce), v)) - }) + return predicate.RefreshToken(sql.FieldNEQ(FieldNonce, v)) } // NonceIn applies the In predicate on the "nonce" field. func NonceIn(vs ...string) predicate.RefreshToken { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldNonce), v...)) - }) + return predicate.RefreshToken(sql.FieldIn(FieldNonce, vs...)) } // NonceNotIn applies the NotIn predicate on the "nonce" field. func NonceNotIn(vs ...string) predicate.RefreshToken { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldNonce), v...)) - }) + return predicate.RefreshToken(sql.FieldNotIn(FieldNonce, vs...)) } // NonceGT applies the GT predicate on the "nonce" field. func NonceGT(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldNonce), v)) - }) + return predicate.RefreshToken(sql.FieldGT(FieldNonce, v)) } // NonceGTE applies the GTE predicate on the "nonce" field. func NonceGTE(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldNonce), v)) - }) + return predicate.RefreshToken(sql.FieldGTE(FieldNonce, v)) } // NonceLT applies the LT predicate on the "nonce" field. func NonceLT(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldNonce), v)) - }) + return predicate.RefreshToken(sql.FieldLT(FieldNonce, v)) } // NonceLTE applies the LTE predicate on the "nonce" field. func NonceLTE(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldNonce), v)) - }) + return predicate.RefreshToken(sql.FieldLTE(FieldNonce, v)) } // NonceContains applies the Contains predicate on the "nonce" field. func NonceContains(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldNonce), v)) - }) + return predicate.RefreshToken(sql.FieldContains(FieldNonce, v)) } // NonceHasPrefix applies the HasPrefix predicate on the "nonce" field. func NonceHasPrefix(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldNonce), v)) - }) + return predicate.RefreshToken(sql.FieldHasPrefix(FieldNonce, v)) } // NonceHasSuffix applies the HasSuffix predicate on the "nonce" field. func NonceHasSuffix(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldNonce), v)) - }) + return predicate.RefreshToken(sql.FieldHasSuffix(FieldNonce, v)) } // NonceEqualFold applies the EqualFold predicate on the "nonce" field. func NonceEqualFold(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldNonce), v)) - }) + return predicate.RefreshToken(sql.FieldEqualFold(FieldNonce, v)) } // NonceContainsFold applies the ContainsFold predicate on the "nonce" field. func NonceContainsFold(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldNonce), v)) - }) + return predicate.RefreshToken(sql.FieldContainsFold(FieldNonce, v)) } // ClaimsUserIDEQ applies the EQ predicate on the "claims_user_id" field. func ClaimsUserIDEQ(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldClaimsUserID), v)) - }) + return predicate.RefreshToken(sql.FieldEQ(FieldClaimsUserID, v)) } // ClaimsUserIDNEQ applies the NEQ predicate on the "claims_user_id" field. func ClaimsUserIDNEQ(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldClaimsUserID), v)) - }) + return predicate.RefreshToken(sql.FieldNEQ(FieldClaimsUserID, v)) } // ClaimsUserIDIn applies the In predicate on the "claims_user_id" field. func ClaimsUserIDIn(vs ...string) predicate.RefreshToken { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldClaimsUserID), v...)) - }) + return predicate.RefreshToken(sql.FieldIn(FieldClaimsUserID, vs...)) } // ClaimsUserIDNotIn applies the NotIn predicate on the "claims_user_id" field. func ClaimsUserIDNotIn(vs ...string) predicate.RefreshToken { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldClaimsUserID), v...)) - }) + return predicate.RefreshToken(sql.FieldNotIn(FieldClaimsUserID, vs...)) } // ClaimsUserIDGT applies the GT predicate on the "claims_user_id" field. func ClaimsUserIDGT(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldClaimsUserID), v)) - }) + return predicate.RefreshToken(sql.FieldGT(FieldClaimsUserID, v)) } // ClaimsUserIDGTE applies the GTE predicate on the "claims_user_id" field. func ClaimsUserIDGTE(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldClaimsUserID), v)) - }) + return predicate.RefreshToken(sql.FieldGTE(FieldClaimsUserID, v)) } // ClaimsUserIDLT applies the LT predicate on the "claims_user_id" field. func ClaimsUserIDLT(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldClaimsUserID), v)) - }) + return predicate.RefreshToken(sql.FieldLT(FieldClaimsUserID, v)) } // ClaimsUserIDLTE applies the LTE predicate on the "claims_user_id" field. func ClaimsUserIDLTE(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldClaimsUserID), v)) - }) + return predicate.RefreshToken(sql.FieldLTE(FieldClaimsUserID, v)) } // ClaimsUserIDContains applies the Contains predicate on the "claims_user_id" field. func ClaimsUserIDContains(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldClaimsUserID), v)) - }) + return predicate.RefreshToken(sql.FieldContains(FieldClaimsUserID, v)) } // ClaimsUserIDHasPrefix applies the HasPrefix predicate on the "claims_user_id" field. func ClaimsUserIDHasPrefix(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldClaimsUserID), v)) - }) + return predicate.RefreshToken(sql.FieldHasPrefix(FieldClaimsUserID, v)) } // ClaimsUserIDHasSuffix applies the HasSuffix predicate on the "claims_user_id" field. func ClaimsUserIDHasSuffix(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldClaimsUserID), v)) - }) + return predicate.RefreshToken(sql.FieldHasSuffix(FieldClaimsUserID, v)) } // ClaimsUserIDEqualFold applies the EqualFold predicate on the "claims_user_id" field. func ClaimsUserIDEqualFold(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldClaimsUserID), v)) - }) + return predicate.RefreshToken(sql.FieldEqualFold(FieldClaimsUserID, v)) } // ClaimsUserIDContainsFold applies the ContainsFold predicate on the "claims_user_id" field. func ClaimsUserIDContainsFold(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldClaimsUserID), v)) - }) + return predicate.RefreshToken(sql.FieldContainsFold(FieldClaimsUserID, v)) } // ClaimsUsernameEQ applies the EQ predicate on the "claims_username" field. func ClaimsUsernameEQ(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldClaimsUsername), v)) - }) + return predicate.RefreshToken(sql.FieldEQ(FieldClaimsUsername, v)) } // ClaimsUsernameNEQ applies the NEQ predicate on the "claims_username" field. func ClaimsUsernameNEQ(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldClaimsUsername), v)) - }) + return predicate.RefreshToken(sql.FieldNEQ(FieldClaimsUsername, v)) } // ClaimsUsernameIn applies the In predicate on the "claims_username" field. func ClaimsUsernameIn(vs ...string) predicate.RefreshToken { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldClaimsUsername), v...)) - }) + return predicate.RefreshToken(sql.FieldIn(FieldClaimsUsername, vs...)) } // ClaimsUsernameNotIn applies the NotIn predicate on the "claims_username" field. func ClaimsUsernameNotIn(vs ...string) predicate.RefreshToken { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldClaimsUsername), v...)) - }) + return predicate.RefreshToken(sql.FieldNotIn(FieldClaimsUsername, vs...)) } // ClaimsUsernameGT applies the GT predicate on the "claims_username" field. func ClaimsUsernameGT(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldClaimsUsername), v)) - }) + return predicate.RefreshToken(sql.FieldGT(FieldClaimsUsername, v)) } // ClaimsUsernameGTE applies the GTE predicate on the "claims_username" field. func ClaimsUsernameGTE(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldClaimsUsername), v)) - }) + return predicate.RefreshToken(sql.FieldGTE(FieldClaimsUsername, v)) } // ClaimsUsernameLT applies the LT predicate on the "claims_username" field. func ClaimsUsernameLT(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldClaimsUsername), v)) - }) + return predicate.RefreshToken(sql.FieldLT(FieldClaimsUsername, v)) } // ClaimsUsernameLTE applies the LTE predicate on the "claims_username" field. func ClaimsUsernameLTE(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldClaimsUsername), v)) - }) + return predicate.RefreshToken(sql.FieldLTE(FieldClaimsUsername, v)) } // ClaimsUsernameContains applies the Contains predicate on the "claims_username" field. func ClaimsUsernameContains(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldClaimsUsername), v)) - }) + return predicate.RefreshToken(sql.FieldContains(FieldClaimsUsername, v)) } // ClaimsUsernameHasPrefix applies the HasPrefix predicate on the "claims_username" field. func ClaimsUsernameHasPrefix(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldClaimsUsername), v)) - }) + return predicate.RefreshToken(sql.FieldHasPrefix(FieldClaimsUsername, v)) } // ClaimsUsernameHasSuffix applies the HasSuffix predicate on the "claims_username" field. func ClaimsUsernameHasSuffix(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldClaimsUsername), v)) - }) + return predicate.RefreshToken(sql.FieldHasSuffix(FieldClaimsUsername, v)) } // ClaimsUsernameEqualFold applies the EqualFold predicate on the "claims_username" field. func ClaimsUsernameEqualFold(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldClaimsUsername), v)) - }) + return predicate.RefreshToken(sql.FieldEqualFold(FieldClaimsUsername, v)) } // ClaimsUsernameContainsFold applies the ContainsFold predicate on the "claims_username" field. func ClaimsUsernameContainsFold(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldClaimsUsername), v)) - }) + return predicate.RefreshToken(sql.FieldContainsFold(FieldClaimsUsername, v)) } // ClaimsEmailEQ applies the EQ predicate on the "claims_email" field. func ClaimsEmailEQ(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldClaimsEmail), v)) - }) + return predicate.RefreshToken(sql.FieldEQ(FieldClaimsEmail, v)) } // ClaimsEmailNEQ applies the NEQ predicate on the "claims_email" field. func ClaimsEmailNEQ(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldClaimsEmail), v)) - }) + return predicate.RefreshToken(sql.FieldNEQ(FieldClaimsEmail, v)) } // ClaimsEmailIn applies the In predicate on the "claims_email" field. func ClaimsEmailIn(vs ...string) predicate.RefreshToken { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldClaimsEmail), v...)) - }) + return predicate.RefreshToken(sql.FieldIn(FieldClaimsEmail, vs...)) } // ClaimsEmailNotIn applies the NotIn predicate on the "claims_email" field. func ClaimsEmailNotIn(vs ...string) predicate.RefreshToken { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldClaimsEmail), v...)) - }) + return predicate.RefreshToken(sql.FieldNotIn(FieldClaimsEmail, vs...)) } // ClaimsEmailGT applies the GT predicate on the "claims_email" field. func ClaimsEmailGT(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldClaimsEmail), v)) - }) + return predicate.RefreshToken(sql.FieldGT(FieldClaimsEmail, v)) } // ClaimsEmailGTE applies the GTE predicate on the "claims_email" field. func ClaimsEmailGTE(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldClaimsEmail), v)) - }) + return predicate.RefreshToken(sql.FieldGTE(FieldClaimsEmail, v)) } // ClaimsEmailLT applies the LT predicate on the "claims_email" field. func ClaimsEmailLT(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldClaimsEmail), v)) - }) + return predicate.RefreshToken(sql.FieldLT(FieldClaimsEmail, v)) } // ClaimsEmailLTE applies the LTE predicate on the "claims_email" field. func ClaimsEmailLTE(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldClaimsEmail), v)) - }) + return predicate.RefreshToken(sql.FieldLTE(FieldClaimsEmail, v)) } // ClaimsEmailContains applies the Contains predicate on the "claims_email" field. func ClaimsEmailContains(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldClaimsEmail), v)) - }) + return predicate.RefreshToken(sql.FieldContains(FieldClaimsEmail, v)) } // ClaimsEmailHasPrefix applies the HasPrefix predicate on the "claims_email" field. func ClaimsEmailHasPrefix(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldClaimsEmail), v)) - }) + return predicate.RefreshToken(sql.FieldHasPrefix(FieldClaimsEmail, v)) } // ClaimsEmailHasSuffix applies the HasSuffix predicate on the "claims_email" field. func ClaimsEmailHasSuffix(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldClaimsEmail), v)) - }) + return predicate.RefreshToken(sql.FieldHasSuffix(FieldClaimsEmail, v)) } // ClaimsEmailEqualFold applies the EqualFold predicate on the "claims_email" field. func ClaimsEmailEqualFold(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldClaimsEmail), v)) - }) + return predicate.RefreshToken(sql.FieldEqualFold(FieldClaimsEmail, v)) } // ClaimsEmailContainsFold applies the ContainsFold predicate on the "claims_email" field. func ClaimsEmailContainsFold(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldClaimsEmail), v)) - }) + return predicate.RefreshToken(sql.FieldContainsFold(FieldClaimsEmail, v)) } // ClaimsEmailVerifiedEQ applies the EQ predicate on the "claims_email_verified" field. func ClaimsEmailVerifiedEQ(v bool) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldClaimsEmailVerified), v)) - }) + return predicate.RefreshToken(sql.FieldEQ(FieldClaimsEmailVerified, v)) } // ClaimsEmailVerifiedNEQ applies the NEQ predicate on the "claims_email_verified" field. func ClaimsEmailVerifiedNEQ(v bool) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldClaimsEmailVerified), v)) - }) + return predicate.RefreshToken(sql.FieldNEQ(FieldClaimsEmailVerified, v)) } // ClaimsGroupsIsNil applies the IsNil predicate on the "claims_groups" field. func ClaimsGroupsIsNil() predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.IsNull(s.C(FieldClaimsGroups))) - }) + return predicate.RefreshToken(sql.FieldIsNull(FieldClaimsGroups)) } // ClaimsGroupsNotNil applies the NotNil predicate on the "claims_groups" field. func ClaimsGroupsNotNil() predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.NotNull(s.C(FieldClaimsGroups))) - }) + return predicate.RefreshToken(sql.FieldNotNull(FieldClaimsGroups)) } // ClaimsPreferredUsernameEQ applies the EQ predicate on the "claims_preferred_username" field. func ClaimsPreferredUsernameEQ(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldClaimsPreferredUsername), v)) - }) + return predicate.RefreshToken(sql.FieldEQ(FieldClaimsPreferredUsername, v)) } // ClaimsPreferredUsernameNEQ applies the NEQ predicate on the "claims_preferred_username" field. func ClaimsPreferredUsernameNEQ(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldClaimsPreferredUsername), v)) - }) + return predicate.RefreshToken(sql.FieldNEQ(FieldClaimsPreferredUsername, v)) } // ClaimsPreferredUsernameIn applies the In predicate on the "claims_preferred_username" field. func ClaimsPreferredUsernameIn(vs ...string) predicate.RefreshToken { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldClaimsPreferredUsername), v...)) - }) + return predicate.RefreshToken(sql.FieldIn(FieldClaimsPreferredUsername, vs...)) } // ClaimsPreferredUsernameNotIn applies the NotIn predicate on the "claims_preferred_username" field. func ClaimsPreferredUsernameNotIn(vs ...string) predicate.RefreshToken { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldClaimsPreferredUsername), v...)) - }) + return predicate.RefreshToken(sql.FieldNotIn(FieldClaimsPreferredUsername, vs...)) } // ClaimsPreferredUsernameGT applies the GT predicate on the "claims_preferred_username" field. func ClaimsPreferredUsernameGT(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldClaimsPreferredUsername), v)) - }) + return predicate.RefreshToken(sql.FieldGT(FieldClaimsPreferredUsername, v)) } // ClaimsPreferredUsernameGTE applies the GTE predicate on the "claims_preferred_username" field. func ClaimsPreferredUsernameGTE(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldClaimsPreferredUsername), v)) - }) + return predicate.RefreshToken(sql.FieldGTE(FieldClaimsPreferredUsername, v)) } // ClaimsPreferredUsernameLT applies the LT predicate on the "claims_preferred_username" field. func ClaimsPreferredUsernameLT(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldClaimsPreferredUsername), v)) - }) + return predicate.RefreshToken(sql.FieldLT(FieldClaimsPreferredUsername, v)) } // ClaimsPreferredUsernameLTE applies the LTE predicate on the "claims_preferred_username" field. func ClaimsPreferredUsernameLTE(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldClaimsPreferredUsername), v)) - }) + return predicate.RefreshToken(sql.FieldLTE(FieldClaimsPreferredUsername, v)) } // ClaimsPreferredUsernameContains applies the Contains predicate on the "claims_preferred_username" field. func ClaimsPreferredUsernameContains(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldClaimsPreferredUsername), v)) - }) + return predicate.RefreshToken(sql.FieldContains(FieldClaimsPreferredUsername, v)) } // ClaimsPreferredUsernameHasPrefix applies the HasPrefix predicate on the "claims_preferred_username" field. func ClaimsPreferredUsernameHasPrefix(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldClaimsPreferredUsername), v)) - }) + return predicate.RefreshToken(sql.FieldHasPrefix(FieldClaimsPreferredUsername, v)) } // ClaimsPreferredUsernameHasSuffix applies the HasSuffix predicate on the "claims_preferred_username" field. func ClaimsPreferredUsernameHasSuffix(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldClaimsPreferredUsername), v)) - }) + return predicate.RefreshToken(sql.FieldHasSuffix(FieldClaimsPreferredUsername, v)) } // ClaimsPreferredUsernameEqualFold applies the EqualFold predicate on the "claims_preferred_username" field. func ClaimsPreferredUsernameEqualFold(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldClaimsPreferredUsername), v)) - }) + return predicate.RefreshToken(sql.FieldEqualFold(FieldClaimsPreferredUsername, v)) } // ClaimsPreferredUsernameContainsFold applies the ContainsFold predicate on the "claims_preferred_username" field. func ClaimsPreferredUsernameContainsFold(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldClaimsPreferredUsername), v)) - }) + return predicate.RefreshToken(sql.FieldContainsFold(FieldClaimsPreferredUsername, v)) } // ConnectorIDEQ applies the EQ predicate on the "connector_id" field. func ConnectorIDEQ(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldConnectorID), v)) - }) + return predicate.RefreshToken(sql.FieldEQ(FieldConnectorID, v)) } // ConnectorIDNEQ applies the NEQ predicate on the "connector_id" field. func ConnectorIDNEQ(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldConnectorID), v)) - }) + return predicate.RefreshToken(sql.FieldNEQ(FieldConnectorID, v)) } // ConnectorIDIn applies the In predicate on the "connector_id" field. func ConnectorIDIn(vs ...string) predicate.RefreshToken { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldConnectorID), v...)) - }) + return predicate.RefreshToken(sql.FieldIn(FieldConnectorID, vs...)) } // ConnectorIDNotIn applies the NotIn predicate on the "connector_id" field. func ConnectorIDNotIn(vs ...string) predicate.RefreshToken { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldConnectorID), v...)) - }) + return predicate.RefreshToken(sql.FieldNotIn(FieldConnectorID, vs...)) } // ConnectorIDGT applies the GT predicate on the "connector_id" field. func ConnectorIDGT(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldConnectorID), v)) - }) + return predicate.RefreshToken(sql.FieldGT(FieldConnectorID, v)) } // ConnectorIDGTE applies the GTE predicate on the "connector_id" field. func ConnectorIDGTE(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldConnectorID), v)) - }) + return predicate.RefreshToken(sql.FieldGTE(FieldConnectorID, v)) } // ConnectorIDLT applies the LT predicate on the "connector_id" field. func ConnectorIDLT(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldConnectorID), v)) - }) + return predicate.RefreshToken(sql.FieldLT(FieldConnectorID, v)) } // ConnectorIDLTE applies the LTE predicate on the "connector_id" field. func ConnectorIDLTE(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldConnectorID), v)) - }) + return predicate.RefreshToken(sql.FieldLTE(FieldConnectorID, v)) } // ConnectorIDContains applies the Contains predicate on the "connector_id" field. func ConnectorIDContains(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldConnectorID), v)) - }) + return predicate.RefreshToken(sql.FieldContains(FieldConnectorID, v)) } // ConnectorIDHasPrefix applies the HasPrefix predicate on the "connector_id" field. func ConnectorIDHasPrefix(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldConnectorID), v)) - }) + return predicate.RefreshToken(sql.FieldHasPrefix(FieldConnectorID, v)) } // ConnectorIDHasSuffix applies the HasSuffix predicate on the "connector_id" field. func ConnectorIDHasSuffix(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldConnectorID), v)) - }) + return predicate.RefreshToken(sql.FieldHasSuffix(FieldConnectorID, v)) } // ConnectorIDEqualFold applies the EqualFold predicate on the "connector_id" field. func ConnectorIDEqualFold(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldConnectorID), v)) - }) + return predicate.RefreshToken(sql.FieldEqualFold(FieldConnectorID, v)) } // ConnectorIDContainsFold applies the ContainsFold predicate on the "connector_id" field. func ConnectorIDContainsFold(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldConnectorID), v)) - }) + return predicate.RefreshToken(sql.FieldContainsFold(FieldConnectorID, v)) } // ConnectorDataEQ applies the EQ predicate on the "connector_data" field. func ConnectorDataEQ(v []byte) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldConnectorData), v)) - }) + return predicate.RefreshToken(sql.FieldEQ(FieldConnectorData, v)) } // ConnectorDataNEQ applies the NEQ predicate on the "connector_data" field. func ConnectorDataNEQ(v []byte) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldConnectorData), v)) - }) + return predicate.RefreshToken(sql.FieldNEQ(FieldConnectorData, v)) } // ConnectorDataIn applies the In predicate on the "connector_data" field. func ConnectorDataIn(vs ...[]byte) predicate.RefreshToken { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldConnectorData), v...)) - }) + return predicate.RefreshToken(sql.FieldIn(FieldConnectorData, vs...)) } // ConnectorDataNotIn applies the NotIn predicate on the "connector_data" field. func ConnectorDataNotIn(vs ...[]byte) predicate.RefreshToken { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldConnectorData), v...)) - }) + return predicate.RefreshToken(sql.FieldNotIn(FieldConnectorData, vs...)) } // ConnectorDataGT applies the GT predicate on the "connector_data" field. func ConnectorDataGT(v []byte) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldConnectorData), v)) - }) + return predicate.RefreshToken(sql.FieldGT(FieldConnectorData, v)) } // ConnectorDataGTE applies the GTE predicate on the "connector_data" field. func ConnectorDataGTE(v []byte) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldConnectorData), v)) - }) + return predicate.RefreshToken(sql.FieldGTE(FieldConnectorData, v)) } // ConnectorDataLT applies the LT predicate on the "connector_data" field. func ConnectorDataLT(v []byte) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldConnectorData), v)) - }) + return predicate.RefreshToken(sql.FieldLT(FieldConnectorData, v)) } // ConnectorDataLTE applies the LTE predicate on the "connector_data" field. func ConnectorDataLTE(v []byte) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldConnectorData), v)) - }) + return predicate.RefreshToken(sql.FieldLTE(FieldConnectorData, v)) } // ConnectorDataIsNil applies the IsNil predicate on the "connector_data" field. func ConnectorDataIsNil() predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.IsNull(s.C(FieldConnectorData))) - }) + return predicate.RefreshToken(sql.FieldIsNull(FieldConnectorData)) } // ConnectorDataNotNil applies the NotNil predicate on the "connector_data" field. func ConnectorDataNotNil() predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.NotNull(s.C(FieldConnectorData))) - }) + return predicate.RefreshToken(sql.FieldNotNull(FieldConnectorData)) } // TokenEQ applies the EQ predicate on the "token" field. func TokenEQ(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldToken), v)) - }) + return predicate.RefreshToken(sql.FieldEQ(FieldToken, v)) } // TokenNEQ applies the NEQ predicate on the "token" field. func TokenNEQ(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldToken), v)) - }) + return predicate.RefreshToken(sql.FieldNEQ(FieldToken, v)) } // TokenIn applies the In predicate on the "token" field. func TokenIn(vs ...string) predicate.RefreshToken { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldToken), v...)) - }) + return predicate.RefreshToken(sql.FieldIn(FieldToken, vs...)) } // TokenNotIn applies the NotIn predicate on the "token" field. func TokenNotIn(vs ...string) predicate.RefreshToken { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldToken), v...)) - }) + return predicate.RefreshToken(sql.FieldNotIn(FieldToken, vs...)) } // TokenGT applies the GT predicate on the "token" field. func TokenGT(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldToken), v)) - }) + return predicate.RefreshToken(sql.FieldGT(FieldToken, v)) } // TokenGTE applies the GTE predicate on the "token" field. func TokenGTE(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldToken), v)) - }) + return predicate.RefreshToken(sql.FieldGTE(FieldToken, v)) } // TokenLT applies the LT predicate on the "token" field. func TokenLT(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldToken), v)) - }) + return predicate.RefreshToken(sql.FieldLT(FieldToken, v)) } // TokenLTE applies the LTE predicate on the "token" field. func TokenLTE(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldToken), v)) - }) + return predicate.RefreshToken(sql.FieldLTE(FieldToken, v)) } // TokenContains applies the Contains predicate on the "token" field. func TokenContains(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldToken), v)) - }) + return predicate.RefreshToken(sql.FieldContains(FieldToken, v)) } // TokenHasPrefix applies the HasPrefix predicate on the "token" field. func TokenHasPrefix(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldToken), v)) - }) + return predicate.RefreshToken(sql.FieldHasPrefix(FieldToken, v)) } // TokenHasSuffix applies the HasSuffix predicate on the "token" field. func TokenHasSuffix(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldToken), v)) - }) + return predicate.RefreshToken(sql.FieldHasSuffix(FieldToken, v)) } // TokenEqualFold applies the EqualFold predicate on the "token" field. func TokenEqualFold(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldToken), v)) - }) + return predicate.RefreshToken(sql.FieldEqualFold(FieldToken, v)) } // TokenContainsFold applies the ContainsFold predicate on the "token" field. func TokenContainsFold(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldToken), v)) - }) + return predicate.RefreshToken(sql.FieldContainsFold(FieldToken, v)) } // ObsoleteTokenEQ applies the EQ predicate on the "obsolete_token" field. func ObsoleteTokenEQ(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldObsoleteToken), v)) - }) + return predicate.RefreshToken(sql.FieldEQ(FieldObsoleteToken, v)) } // ObsoleteTokenNEQ applies the NEQ predicate on the "obsolete_token" field. func ObsoleteTokenNEQ(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldObsoleteToken), v)) - }) + return predicate.RefreshToken(sql.FieldNEQ(FieldObsoleteToken, v)) } // ObsoleteTokenIn applies the In predicate on the "obsolete_token" field. func ObsoleteTokenIn(vs ...string) predicate.RefreshToken { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldObsoleteToken), v...)) - }) + return predicate.RefreshToken(sql.FieldIn(FieldObsoleteToken, vs...)) } // ObsoleteTokenNotIn applies the NotIn predicate on the "obsolete_token" field. func ObsoleteTokenNotIn(vs ...string) predicate.RefreshToken { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldObsoleteToken), v...)) - }) + return predicate.RefreshToken(sql.FieldNotIn(FieldObsoleteToken, vs...)) } // ObsoleteTokenGT applies the GT predicate on the "obsolete_token" field. func ObsoleteTokenGT(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldObsoleteToken), v)) - }) + return predicate.RefreshToken(sql.FieldGT(FieldObsoleteToken, v)) } // ObsoleteTokenGTE applies the GTE predicate on the "obsolete_token" field. func ObsoleteTokenGTE(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldObsoleteToken), v)) - }) + return predicate.RefreshToken(sql.FieldGTE(FieldObsoleteToken, v)) } // ObsoleteTokenLT applies the LT predicate on the "obsolete_token" field. func ObsoleteTokenLT(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldObsoleteToken), v)) - }) + return predicate.RefreshToken(sql.FieldLT(FieldObsoleteToken, v)) } // ObsoleteTokenLTE applies the LTE predicate on the "obsolete_token" field. func ObsoleteTokenLTE(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldObsoleteToken), v)) - }) + return predicate.RefreshToken(sql.FieldLTE(FieldObsoleteToken, v)) } // ObsoleteTokenContains applies the Contains predicate on the "obsolete_token" field. func ObsoleteTokenContains(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldObsoleteToken), v)) - }) + return predicate.RefreshToken(sql.FieldContains(FieldObsoleteToken, v)) } // ObsoleteTokenHasPrefix applies the HasPrefix predicate on the "obsolete_token" field. func ObsoleteTokenHasPrefix(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldObsoleteToken), v)) - }) + return predicate.RefreshToken(sql.FieldHasPrefix(FieldObsoleteToken, v)) } // ObsoleteTokenHasSuffix applies the HasSuffix predicate on the "obsolete_token" field. func ObsoleteTokenHasSuffix(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldObsoleteToken), v)) - }) + return predicate.RefreshToken(sql.FieldHasSuffix(FieldObsoleteToken, v)) } // ObsoleteTokenEqualFold applies the EqualFold predicate on the "obsolete_token" field. func ObsoleteTokenEqualFold(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldObsoleteToken), v)) - }) + return predicate.RefreshToken(sql.FieldEqualFold(FieldObsoleteToken, v)) } // ObsoleteTokenContainsFold applies the ContainsFold predicate on the "obsolete_token" field. func ObsoleteTokenContainsFold(v string) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldObsoleteToken), v)) - }) + return predicate.RefreshToken(sql.FieldContainsFold(FieldObsoleteToken, v)) } // CreatedAtEQ applies the EQ predicate on the "created_at" field. func CreatedAtEQ(v time.Time) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldCreatedAt), v)) - }) + return predicate.RefreshToken(sql.FieldEQ(FieldCreatedAt, v)) } // CreatedAtNEQ applies the NEQ predicate on the "created_at" field. func CreatedAtNEQ(v time.Time) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldCreatedAt), v)) - }) + return predicate.RefreshToken(sql.FieldNEQ(FieldCreatedAt, v)) } // CreatedAtIn applies the In predicate on the "created_at" field. func CreatedAtIn(vs ...time.Time) predicate.RefreshToken { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldCreatedAt), v...)) - }) + return predicate.RefreshToken(sql.FieldIn(FieldCreatedAt, vs...)) } // CreatedAtNotIn applies the NotIn predicate on the "created_at" field. func CreatedAtNotIn(vs ...time.Time) predicate.RefreshToken { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldCreatedAt), v...)) - }) + return predicate.RefreshToken(sql.FieldNotIn(FieldCreatedAt, vs...)) } // CreatedAtGT applies the GT predicate on the "created_at" field. func CreatedAtGT(v time.Time) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldCreatedAt), v)) - }) + return predicate.RefreshToken(sql.FieldGT(FieldCreatedAt, v)) } // CreatedAtGTE applies the GTE predicate on the "created_at" field. func CreatedAtGTE(v time.Time) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldCreatedAt), v)) - }) + return predicate.RefreshToken(sql.FieldGTE(FieldCreatedAt, v)) } // CreatedAtLT applies the LT predicate on the "created_at" field. func CreatedAtLT(v time.Time) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldCreatedAt), v)) - }) + return predicate.RefreshToken(sql.FieldLT(FieldCreatedAt, v)) } // CreatedAtLTE applies the LTE predicate on the "created_at" field. func CreatedAtLTE(v time.Time) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldCreatedAt), v)) - }) + return predicate.RefreshToken(sql.FieldLTE(FieldCreatedAt, v)) } // LastUsedEQ applies the EQ predicate on the "last_used" field. func LastUsedEQ(v time.Time) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldLastUsed), v)) - }) + return predicate.RefreshToken(sql.FieldEQ(FieldLastUsed, v)) } // LastUsedNEQ applies the NEQ predicate on the "last_used" field. func LastUsedNEQ(v time.Time) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldLastUsed), v)) - }) + return predicate.RefreshToken(sql.FieldNEQ(FieldLastUsed, v)) } // LastUsedIn applies the In predicate on the "last_used" field. func LastUsedIn(vs ...time.Time) predicate.RefreshToken { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldLastUsed), v...)) - }) + return predicate.RefreshToken(sql.FieldIn(FieldLastUsed, vs...)) } // LastUsedNotIn applies the NotIn predicate on the "last_used" field. func LastUsedNotIn(vs ...time.Time) predicate.RefreshToken { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldLastUsed), v...)) - }) + return predicate.RefreshToken(sql.FieldNotIn(FieldLastUsed, vs...)) } // LastUsedGT applies the GT predicate on the "last_used" field. func LastUsedGT(v time.Time) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldLastUsed), v)) - }) + return predicate.RefreshToken(sql.FieldGT(FieldLastUsed, v)) } // LastUsedGTE applies the GTE predicate on the "last_used" field. func LastUsedGTE(v time.Time) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldLastUsed), v)) - }) + return predicate.RefreshToken(sql.FieldGTE(FieldLastUsed, v)) } // LastUsedLT applies the LT predicate on the "last_used" field. func LastUsedLT(v time.Time) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldLastUsed), v)) - }) + return predicate.RefreshToken(sql.FieldLT(FieldLastUsed, v)) } // LastUsedLTE applies the LTE predicate on the "last_used" field. func LastUsedLTE(v time.Time) predicate.RefreshToken { - return predicate.RefreshToken(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldLastUsed), v)) - }) + return predicate.RefreshToken(sql.FieldLTE(FieldLastUsed, v)) } // And groups predicates with the AND operator between them. diff --git a/storage/ent/db/refreshtoken_create.go b/storage/ent/db/refreshtoken_create.go index e2bd6c2f..e44ab02c 100644 --- a/storage/ent/db/refreshtoken_create.go +++ b/storage/ent/db/refreshtoken_create.go @@ -163,50 +163,8 @@ func (rtc *RefreshTokenCreate) Mutation() *RefreshTokenMutation { // Save creates the RefreshToken in the database. func (rtc *RefreshTokenCreate) Save(ctx context.Context) (*RefreshToken, error) { - var ( - err error - node *RefreshToken - ) rtc.defaults() - if len(rtc.hooks) == 0 { - if err = rtc.check(); err != nil { - return nil, err - } - node, err = rtc.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*RefreshTokenMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err = rtc.check(); err != nil { - return nil, err - } - rtc.mutation = mutation - if node, err = rtc.sqlSave(ctx); err != nil { - return nil, err - } - mutation.id = &node.ID - mutation.done = true - return node, err - }) - for i := len(rtc.hooks) - 1; i >= 0; i-- { - if rtc.hooks[i] == nil { - return nil, fmt.Errorf("db: uninitialized hook (forgotten import db/runtime?)") - } - mut = rtc.hooks[i](mut) - } - v, err := mut.Mutate(ctx, rtc.mutation) - if err != nil { - return nil, err - } - nv, ok := v.(*RefreshToken) - if !ok { - return nil, fmt.Errorf("unexpected node type %T returned from RefreshTokenMutation", v) - } - node = nv - } - return node, err + return withHooks[*RefreshToken, RefreshTokenMutation](ctx, rtc.sqlSave, rtc.mutation, rtc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -332,6 +290,9 @@ func (rtc *RefreshTokenCreate) check() error { } func (rtc *RefreshTokenCreate) sqlSave(ctx context.Context) (*RefreshToken, error) { + if err := rtc.check(); err != nil { + return nil, err + } _node, _spec := rtc.createSpec() if err := sqlgraph.CreateNode(ctx, rtc.driver, _spec); err != nil { if sqlgraph.IsConstraintError(err) { @@ -346,142 +307,78 @@ func (rtc *RefreshTokenCreate) sqlSave(ctx context.Context) (*RefreshToken, erro return nil, fmt.Errorf("unexpected RefreshToken.ID type: %T", _spec.ID.Value) } } + rtc.mutation.id = &_node.ID + rtc.mutation.done = true return _node, nil } func (rtc *RefreshTokenCreate) createSpec() (*RefreshToken, *sqlgraph.CreateSpec) { var ( _node = &RefreshToken{config: rtc.config} - _spec = &sqlgraph.CreateSpec{ - Table: refreshtoken.Table, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeString, - Column: refreshtoken.FieldID, - }, - } + _spec = sqlgraph.NewCreateSpec(refreshtoken.Table, sqlgraph.NewFieldSpec(refreshtoken.FieldID, field.TypeString)) ) if id, ok := rtc.mutation.ID(); ok { _node.ID = id _spec.ID.Value = id } if value, ok := rtc.mutation.ClientID(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: refreshtoken.FieldClientID, - }) + _spec.SetField(refreshtoken.FieldClientID, field.TypeString, value) _node.ClientID = value } if value, ok := rtc.mutation.Scopes(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeJSON, - Value: value, - Column: refreshtoken.FieldScopes, - }) + _spec.SetField(refreshtoken.FieldScopes, field.TypeJSON, value) _node.Scopes = value } if value, ok := rtc.mutation.Nonce(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: refreshtoken.FieldNonce, - }) + _spec.SetField(refreshtoken.FieldNonce, field.TypeString, value) _node.Nonce = value } if value, ok := rtc.mutation.ClaimsUserID(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: refreshtoken.FieldClaimsUserID, - }) + _spec.SetField(refreshtoken.FieldClaimsUserID, field.TypeString, value) _node.ClaimsUserID = value } if value, ok := rtc.mutation.ClaimsUsername(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: refreshtoken.FieldClaimsUsername, - }) + _spec.SetField(refreshtoken.FieldClaimsUsername, field.TypeString, value) _node.ClaimsUsername = value } if value, ok := rtc.mutation.ClaimsEmail(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: refreshtoken.FieldClaimsEmail, - }) + _spec.SetField(refreshtoken.FieldClaimsEmail, field.TypeString, value) _node.ClaimsEmail = value } if value, ok := rtc.mutation.ClaimsEmailVerified(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeBool, - Value: value, - Column: refreshtoken.FieldClaimsEmailVerified, - }) + _spec.SetField(refreshtoken.FieldClaimsEmailVerified, field.TypeBool, value) _node.ClaimsEmailVerified = value } if value, ok := rtc.mutation.ClaimsGroups(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeJSON, - Value: value, - Column: refreshtoken.FieldClaimsGroups, - }) + _spec.SetField(refreshtoken.FieldClaimsGroups, field.TypeJSON, value) _node.ClaimsGroups = value } if value, ok := rtc.mutation.ClaimsPreferredUsername(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: refreshtoken.FieldClaimsPreferredUsername, - }) + _spec.SetField(refreshtoken.FieldClaimsPreferredUsername, field.TypeString, value) _node.ClaimsPreferredUsername = value } if value, ok := rtc.mutation.ConnectorID(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: refreshtoken.FieldConnectorID, - }) + _spec.SetField(refreshtoken.FieldConnectorID, field.TypeString, value) _node.ConnectorID = value } if value, ok := rtc.mutation.ConnectorData(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeBytes, - Value: value, - Column: refreshtoken.FieldConnectorData, - }) + _spec.SetField(refreshtoken.FieldConnectorData, field.TypeBytes, value) _node.ConnectorData = &value } if value, ok := rtc.mutation.Token(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: refreshtoken.FieldToken, - }) + _spec.SetField(refreshtoken.FieldToken, field.TypeString, value) _node.Token = value } if value, ok := rtc.mutation.ObsoleteToken(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: refreshtoken.FieldObsoleteToken, - }) + _spec.SetField(refreshtoken.FieldObsoleteToken, field.TypeString, value) _node.ObsoleteToken = value } if value, ok := rtc.mutation.CreatedAt(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeTime, - Value: value, - Column: refreshtoken.FieldCreatedAt, - }) + _spec.SetField(refreshtoken.FieldCreatedAt, field.TypeTime, value) _node.CreatedAt = value } if value, ok := rtc.mutation.LastUsed(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeTime, - Value: value, - Column: refreshtoken.FieldLastUsed, - }) + _spec.SetField(refreshtoken.FieldLastUsed, field.TypeTime, value) _node.LastUsed = value } return _node, _spec diff --git a/storage/ent/db/refreshtoken_delete.go b/storage/ent/db/refreshtoken_delete.go index 2c8d7c1e..9e604101 100644 --- a/storage/ent/db/refreshtoken_delete.go +++ b/storage/ent/db/refreshtoken_delete.go @@ -4,7 +4,6 @@ package db import ( "context" - "fmt" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" @@ -28,34 +27,7 @@ func (rtd *RefreshTokenDelete) Where(ps ...predicate.RefreshToken) *RefreshToken // Exec executes the deletion query and returns how many vertices were deleted. func (rtd *RefreshTokenDelete) Exec(ctx context.Context) (int, error) { - var ( - err error - affected int - ) - if len(rtd.hooks) == 0 { - affected, err = rtd.sqlExec(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*RefreshTokenMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - rtd.mutation = mutation - affected, err = rtd.sqlExec(ctx) - mutation.done = true - return affected, err - }) - for i := len(rtd.hooks) - 1; i >= 0; i-- { - if rtd.hooks[i] == nil { - return 0, fmt.Errorf("db: uninitialized hook (forgotten import db/runtime?)") - } - mut = rtd.hooks[i](mut) - } - if _, err := mut.Mutate(ctx, rtd.mutation); err != nil { - return 0, err - } - } - return affected, err + return withHooks[int, RefreshTokenMutation](ctx, rtd.sqlExec, rtd.mutation, rtd.hooks) } // ExecX is like Exec, but panics if an error occurs. @@ -68,15 +40,7 @@ func (rtd *RefreshTokenDelete) ExecX(ctx context.Context) int { } func (rtd *RefreshTokenDelete) sqlExec(ctx context.Context) (int, error) { - _spec := &sqlgraph.DeleteSpec{ - Node: &sqlgraph.NodeSpec{ - Table: refreshtoken.Table, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeString, - Column: refreshtoken.FieldID, - }, - }, - } + _spec := sqlgraph.NewDeleteSpec(refreshtoken.Table, sqlgraph.NewFieldSpec(refreshtoken.FieldID, field.TypeString)) if ps := rtd.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { @@ -88,6 +52,7 @@ func (rtd *RefreshTokenDelete) sqlExec(ctx context.Context) (int, error) { if err != nil && sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } + rtd.mutation.done = true return affected, err } @@ -96,6 +61,12 @@ type RefreshTokenDeleteOne struct { rtd *RefreshTokenDelete } +// Where appends a list predicates to the RefreshTokenDelete builder. +func (rtdo *RefreshTokenDeleteOne) Where(ps ...predicate.RefreshToken) *RefreshTokenDeleteOne { + rtdo.rtd.mutation.Where(ps...) + return rtdo +} + // Exec executes the deletion query. func (rtdo *RefreshTokenDeleteOne) Exec(ctx context.Context) error { n, err := rtdo.rtd.Exec(ctx) @@ -111,5 +82,7 @@ func (rtdo *RefreshTokenDeleteOne) Exec(ctx context.Context) error { // ExecX is like Exec, but panics if an error occurs. func (rtdo *RefreshTokenDeleteOne) ExecX(ctx context.Context) { - rtdo.rtd.ExecX(ctx) + if err := rtdo.Exec(ctx); err != nil { + panic(err) + } } diff --git a/storage/ent/db/refreshtoken_query.go b/storage/ent/db/refreshtoken_query.go index a90ac2f9..b7b3dd70 100644 --- a/storage/ent/db/refreshtoken_query.go +++ b/storage/ent/db/refreshtoken_query.go @@ -17,11 +17,9 @@ import ( // RefreshTokenQuery is the builder for querying RefreshToken entities. type RefreshTokenQuery struct { config - limit *int - offset *int - unique *bool + ctx *QueryContext order []OrderFunc - fields []string + inters []Interceptor predicates []predicate.RefreshToken // intermediate query (i.e. traversal path). sql *sql.Selector @@ -34,26 +32,26 @@ func (rtq *RefreshTokenQuery) Where(ps ...predicate.RefreshToken) *RefreshTokenQ return rtq } -// Limit adds a limit step to the query. +// Limit the number of records to be returned by this query. func (rtq *RefreshTokenQuery) Limit(limit int) *RefreshTokenQuery { - rtq.limit = &limit + rtq.ctx.Limit = &limit return rtq } -// Offset adds an offset step to the query. +// Offset to start from. func (rtq *RefreshTokenQuery) Offset(offset int) *RefreshTokenQuery { - rtq.offset = &offset + rtq.ctx.Offset = &offset return rtq } // Unique configures the query builder to filter duplicate records on query. // By default, unique is set to true, and can be disabled using this method. func (rtq *RefreshTokenQuery) Unique(unique bool) *RefreshTokenQuery { - rtq.unique = &unique + rtq.ctx.Unique = &unique return rtq } -// Order adds an order step to the query. +// Order specifies how the records should be ordered. func (rtq *RefreshTokenQuery) Order(o ...OrderFunc) *RefreshTokenQuery { rtq.order = append(rtq.order, o...) return rtq @@ -62,7 +60,7 @@ func (rtq *RefreshTokenQuery) Order(o ...OrderFunc) *RefreshTokenQuery { // First returns the first RefreshToken entity from the query. // Returns a *NotFoundError when no RefreshToken was found. func (rtq *RefreshTokenQuery) First(ctx context.Context) (*RefreshToken, error) { - nodes, err := rtq.Limit(1).All(ctx) + nodes, err := rtq.Limit(1).All(setContextOp(ctx, rtq.ctx, "First")) if err != nil { return nil, err } @@ -85,7 +83,7 @@ func (rtq *RefreshTokenQuery) FirstX(ctx context.Context) *RefreshToken { // Returns a *NotFoundError when no RefreshToken ID was found. func (rtq *RefreshTokenQuery) FirstID(ctx context.Context) (id string, err error) { var ids []string - if ids, err = rtq.Limit(1).IDs(ctx); err != nil { + if ids, err = rtq.Limit(1).IDs(setContextOp(ctx, rtq.ctx, "FirstID")); err != nil { return } if len(ids) == 0 { @@ -108,7 +106,7 @@ func (rtq *RefreshTokenQuery) FirstIDX(ctx context.Context) string { // 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) + nodes, err := rtq.Limit(2).All(setContextOp(ctx, rtq.ctx, "Only")) if err != nil { return nil, err } @@ -136,7 +134,7 @@ func (rtq *RefreshTokenQuery) OnlyX(ctx context.Context) *RefreshToken { // Returns a *NotFoundError when no entities are found. func (rtq *RefreshTokenQuery) OnlyID(ctx context.Context) (id string, err error) { var ids []string - if ids, err = rtq.Limit(2).IDs(ctx); err != nil { + if ids, err = rtq.Limit(2).IDs(setContextOp(ctx, rtq.ctx, "OnlyID")); err != nil { return } switch len(ids) { @@ -161,10 +159,12 @@ func (rtq *RefreshTokenQuery) OnlyIDX(ctx context.Context) string { // All executes the query and returns a list of RefreshTokens. func (rtq *RefreshTokenQuery) All(ctx context.Context) ([]*RefreshToken, error) { + ctx = setContextOp(ctx, rtq.ctx, "All") if err := rtq.prepareQuery(ctx); err != nil { return nil, err } - return rtq.sqlAll(ctx) + qr := querierAll[[]*RefreshToken, *RefreshTokenQuery]() + return withInterceptors[[]*RefreshToken](ctx, rtq, qr, rtq.inters) } // AllX is like All, but panics if an error occurs. @@ -177,9 +177,12 @@ func (rtq *RefreshTokenQuery) AllX(ctx context.Context) []*RefreshToken { } // IDs executes the query and returns a list of RefreshToken IDs. -func (rtq *RefreshTokenQuery) IDs(ctx context.Context) ([]string, error) { - var ids []string - if err := rtq.Select(refreshtoken.FieldID).Scan(ctx, &ids); err != nil { +func (rtq *RefreshTokenQuery) IDs(ctx context.Context) (ids []string, err error) { + if rtq.ctx.Unique == nil && rtq.path != nil { + rtq.Unique(true) + } + ctx = setContextOp(ctx, rtq.ctx, "IDs") + if err = rtq.Select(refreshtoken.FieldID).Scan(ctx, &ids); err != nil { return nil, err } return ids, nil @@ -196,10 +199,11 @@ func (rtq *RefreshTokenQuery) IDsX(ctx context.Context) []string { // Count returns the count of the given query. func (rtq *RefreshTokenQuery) Count(ctx context.Context) (int, error) { + ctx = setContextOp(ctx, rtq.ctx, "Count") if err := rtq.prepareQuery(ctx); err != nil { return 0, err } - return rtq.sqlCount(ctx) + return withInterceptors[int](ctx, rtq, querierCount[*RefreshTokenQuery](), rtq.inters) } // CountX is like Count, but panics if an error occurs. @@ -213,10 +217,15 @@ func (rtq *RefreshTokenQuery) CountX(ctx context.Context) int { // Exist returns true if the query has elements in the graph. func (rtq *RefreshTokenQuery) Exist(ctx context.Context) (bool, error) { - if err := rtq.prepareQuery(ctx); err != nil { - return false, err + ctx = setContextOp(ctx, rtq.ctx, "Exist") + switch _, err := rtq.FirstID(ctx); { + case IsNotFound(err): + return false, nil + case err != nil: + return false, fmt.Errorf("db: check existence: %w", err) + default: + return true, nil } - return rtq.sqlExist(ctx) } // ExistX is like Exist, but panics if an error occurs. @@ -236,14 +245,13 @@ func (rtq *RefreshTokenQuery) Clone() *RefreshTokenQuery { } return &RefreshTokenQuery{ config: rtq.config, - limit: rtq.limit, - offset: rtq.offset, + ctx: rtq.ctx.Clone(), order: append([]OrderFunc{}, rtq.order...), + inters: append([]Interceptor{}, rtq.inters...), predicates: append([]predicate.RefreshToken{}, rtq.predicates...), // clone intermediate query. - sql: rtq.sql.Clone(), - path: rtq.path, - unique: rtq.unique, + sql: rtq.sql.Clone(), + path: rtq.path, } } @@ -261,18 +269,12 @@ func (rtq *RefreshTokenQuery) Clone() *RefreshTokenQuery { // GroupBy(refreshtoken.FieldClientID). // Aggregate(db.Count()). // Scan(ctx, &v) -// func (rtq *RefreshTokenQuery) GroupBy(field string, fields ...string) *RefreshTokenGroupBy { - grbuild := &RefreshTokenGroupBy{config: rtq.config} - grbuild.fields = append([]string{field}, fields...) - grbuild.path = func(ctx context.Context) (prev *sql.Selector, err error) { - if err := rtq.prepareQuery(ctx); err != nil { - return nil, err - } - return rtq.sqlQuery(ctx), nil - } + rtq.ctx.Fields = append([]string{field}, fields...) + grbuild := &RefreshTokenGroupBy{build: rtq} + grbuild.flds = &rtq.ctx.Fields grbuild.label = refreshtoken.Label - grbuild.flds, grbuild.scan = &grbuild.fields, grbuild.Scan + grbuild.scan = grbuild.Scan return grbuild } @@ -288,17 +290,31 @@ func (rtq *RefreshTokenQuery) GroupBy(field string, fields ...string) *RefreshTo // client.RefreshToken.Query(). // Select(refreshtoken.FieldClientID). // Scan(ctx, &v) -// func (rtq *RefreshTokenQuery) Select(fields ...string) *RefreshTokenSelect { - rtq.fields = append(rtq.fields, fields...) - selbuild := &RefreshTokenSelect{RefreshTokenQuery: rtq} - selbuild.label = refreshtoken.Label - selbuild.flds, selbuild.scan = &rtq.fields, selbuild.Scan - return selbuild + rtq.ctx.Fields = append(rtq.ctx.Fields, fields...) + sbuild := &RefreshTokenSelect{RefreshTokenQuery: rtq} + sbuild.label = refreshtoken.Label + sbuild.flds, sbuild.scan = &rtq.ctx.Fields, sbuild.Scan + return sbuild +} + +// Aggregate returns a RefreshTokenSelect configured with the given aggregations. +func (rtq *RefreshTokenQuery) Aggregate(fns ...AggregateFunc) *RefreshTokenSelect { + return rtq.Select().Aggregate(fns...) } func (rtq *RefreshTokenQuery) prepareQuery(ctx context.Context) error { - for _, f := range rtq.fields { + for _, inter := range rtq.inters { + if inter == nil { + return fmt.Errorf("db: uninitialized interceptor (forgotten import db/runtime?)") + } + if trv, ok := inter.(Traverser); ok { + if err := trv.Traverse(ctx, rtq); err != nil { + return err + } + } + } + for _, f := range rtq.ctx.Fields { if !refreshtoken.ValidColumn(f) { return &ValidationError{Name: f, err: fmt.Errorf("db: invalid field %q for query", f)} } @@ -318,10 +334,10 @@ func (rtq *RefreshTokenQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([ nodes = []*RefreshToken{} _spec = rtq.querySpec() ) - _spec.ScanValues = func(columns []string) ([]interface{}, error) { + _spec.ScanValues = func(columns []string) ([]any, error) { return (*RefreshToken).scanValues(nil, columns) } - _spec.Assign = func(columns []string, values []interface{}) error { + _spec.Assign = func(columns []string, values []any) error { node := &RefreshToken{config: rtq.config} nodes = append(nodes, node) return node.assignValues(columns, values) @@ -340,38 +356,22 @@ func (rtq *RefreshTokenQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([ 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 + _spec.Node.Columns = rtq.ctx.Fields + if len(rtq.ctx.Fields) > 0 { + _spec.Unique = rtq.ctx.Unique != nil && *rtq.ctx.Unique } return sqlgraph.CountNodes(ctx, rtq.driver, _spec) } -func (rtq *RefreshTokenQuery) sqlExist(ctx context.Context) (bool, error) { - n, err := rtq.sqlCount(ctx) - if err != nil { - return false, fmt.Errorf("db: check existence: %w", err) - } - return n > 0, nil -} - func (rtq *RefreshTokenQuery) querySpec() *sqlgraph.QuerySpec { - _spec := &sqlgraph.QuerySpec{ - Node: &sqlgraph.NodeSpec{ - Table: refreshtoken.Table, - Columns: refreshtoken.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeString, - Column: refreshtoken.FieldID, - }, - }, - From: rtq.sql, - Unique: true, - } - if unique := rtq.unique; unique != nil { + _spec := sqlgraph.NewQuerySpec(refreshtoken.Table, refreshtoken.Columns, sqlgraph.NewFieldSpec(refreshtoken.FieldID, field.TypeString)) + _spec.From = rtq.sql + if unique := rtq.ctx.Unique; unique != nil { _spec.Unique = *unique + } else if rtq.path != nil { + _spec.Unique = true } - if fields := rtq.fields; len(fields) > 0 { + if fields := rtq.ctx.Fields; len(fields) > 0 { _spec.Node.Columns = make([]string, 0, len(fields)) _spec.Node.Columns = append(_spec.Node.Columns, refreshtoken.FieldID) for i := range fields { @@ -387,10 +387,10 @@ func (rtq *RefreshTokenQuery) querySpec() *sqlgraph.QuerySpec { } } } - if limit := rtq.limit; limit != nil { + if limit := rtq.ctx.Limit; limit != nil { _spec.Limit = *limit } - if offset := rtq.offset; offset != nil { + if offset := rtq.ctx.Offset; offset != nil { _spec.Offset = *offset } if ps := rtq.order; len(ps) > 0 { @@ -406,7 +406,7 @@ func (rtq *RefreshTokenQuery) querySpec() *sqlgraph.QuerySpec { func (rtq *RefreshTokenQuery) sqlQuery(ctx context.Context) *sql.Selector { builder := sql.Dialect(rtq.driver.Dialect()) t1 := builder.Table(refreshtoken.Table) - columns := rtq.fields + columns := rtq.ctx.Fields if len(columns) == 0 { columns = refreshtoken.Columns } @@ -415,7 +415,7 @@ func (rtq *RefreshTokenQuery) sqlQuery(ctx context.Context) *sql.Selector { selector = rtq.sql selector.Select(selector.Columns(columns...)...) } - if rtq.unique != nil && *rtq.unique { + if rtq.ctx.Unique != nil && *rtq.ctx.Unique { selector.Distinct() } for _, p := range rtq.predicates { @@ -424,12 +424,12 @@ func (rtq *RefreshTokenQuery) sqlQuery(ctx context.Context) *sql.Selector { for _, p := range rtq.order { p(selector) } - if offset := rtq.offset; offset != nil { + if offset := rtq.ctx.Offset; offset != nil { // limit is mandatory for offset clause. We start // with default value, and override it below if needed. selector.Offset(*offset).Limit(math.MaxInt32) } - if limit := rtq.limit; limit != nil { + if limit := rtq.ctx.Limit; limit != nil { selector.Limit(*limit) } return selector @@ -437,13 +437,8 @@ func (rtq *RefreshTokenQuery) sqlQuery(ctx context.Context) *sql.Selector { // RefreshTokenGroupBy is the group-by builder for RefreshToken entities. type RefreshTokenGroupBy struct { - config selector - fields []string - fns []AggregateFunc - // intermediate query (i.e. traversal path). - sql *sql.Selector - path func(context.Context) (*sql.Selector, error) + build *RefreshTokenQuery } // Aggregate adds the given aggregation functions to the group-by query. @@ -452,74 +447,77 @@ func (rtgb *RefreshTokenGroupBy) Aggregate(fns ...AggregateFunc) *RefreshTokenGr return rtgb } -// Scan applies the group-by query and scans the result into the given value. -func (rtgb *RefreshTokenGroupBy) Scan(ctx context.Context, v interface{}) error { - query, err := rtgb.path(ctx) - if err != nil { +// Scan applies the selector query and scans the result into the given value. +func (rtgb *RefreshTokenGroupBy) Scan(ctx context.Context, v any) error { + ctx = setContextOp(ctx, rtgb.build.ctx, "GroupBy") + if err := rtgb.build.prepareQuery(ctx); err != nil { return err } - rtgb.sql = query - return rtgb.sqlScan(ctx, v) + return scanWithInterceptors[*RefreshTokenQuery, *RefreshTokenGroupBy](ctx, rtgb.build, rtgb, rtgb.build.inters, v) } -func (rtgb *RefreshTokenGroupBy) sqlScan(ctx context.Context, v interface{}) error { - for _, f := range rtgb.fields { - if !refreshtoken.ValidColumn(f) { - return &ValidationError{Name: f, err: fmt.Errorf("invalid field %q for group-by", f)} - } - } - selector := rtgb.sqlQuery() - if err := selector.Err(); err != nil { - return err - } - rows := &sql.Rows{} - query, args := selector.Query() - if err := rtgb.driver.Query(ctx, query, args, rows); err != nil { - return err - } - defer rows.Close() - return sql.ScanSlice(rows, v) -} - -func (rtgb *RefreshTokenGroupBy) sqlQuery() *sql.Selector { - selector := rtgb.sql.Select() +func (rtgb *RefreshTokenGroupBy) sqlScan(ctx context.Context, root *RefreshTokenQuery, v any) error { + selector := root.sqlQuery(ctx).Select() aggregation := make([]string, 0, len(rtgb.fns)) for _, fn := range rtgb.fns { aggregation = append(aggregation, fn(selector)) } - // If no columns were selected in a custom aggregation function, the default - // selection is the fields used for "group-by", and the aggregation functions. if len(selector.SelectedColumns()) == 0 { - columns := make([]string, 0, len(rtgb.fields)+len(rtgb.fns)) - for _, f := range rtgb.fields { + columns := make([]string, 0, len(*rtgb.flds)+len(rtgb.fns)) + for _, f := range *rtgb.flds { columns = append(columns, selector.C(f)) } columns = append(columns, aggregation...) selector.Select(columns...) } - return selector.GroupBy(selector.Columns(rtgb.fields...)...) + selector.GroupBy(selector.Columns(*rtgb.flds...)...) + if err := selector.Err(); err != nil { + return err + } + rows := &sql.Rows{} + query, args := selector.Query() + if err := rtgb.build.driver.Query(ctx, query, args, rows); err != nil { + return err + } + defer rows.Close() + return sql.ScanSlice(rows, v) } // RefreshTokenSelect is the builder for selecting fields of RefreshToken entities. type RefreshTokenSelect struct { *RefreshTokenQuery selector - // intermediate query (i.e. traversal path). - sql *sql.Selector +} + +// Aggregate adds the given aggregation functions to the selector query. +func (rts *RefreshTokenSelect) Aggregate(fns ...AggregateFunc) *RefreshTokenSelect { + rts.fns = append(rts.fns, fns...) + return rts } // Scan applies the selector query and scans the result into the given value. -func (rts *RefreshTokenSelect) Scan(ctx context.Context, v interface{}) error { +func (rts *RefreshTokenSelect) Scan(ctx context.Context, v any) error { + ctx = setContextOp(ctx, rts.ctx, "Select") if err := rts.prepareQuery(ctx); err != nil { return err } - rts.sql = rts.RefreshTokenQuery.sqlQuery(ctx) - return rts.sqlScan(ctx, v) + return scanWithInterceptors[*RefreshTokenQuery, *RefreshTokenSelect](ctx, rts.RefreshTokenQuery, rts, rts.inters, v) } -func (rts *RefreshTokenSelect) sqlScan(ctx context.Context, v interface{}) error { +func (rts *RefreshTokenSelect) sqlScan(ctx context.Context, root *RefreshTokenQuery, v any) error { + selector := root.sqlQuery(ctx) + aggregation := make([]string, 0, len(rts.fns)) + for _, fn := range rts.fns { + aggregation = append(aggregation, fn(selector)) + } + switch n := len(*rts.selector.flds); { + case n == 0 && len(aggregation) > 0: + selector.Select(aggregation...) + case n != 0 && len(aggregation) > 0: + selector.AppendSelect(aggregation...) + } rows := &sql.Rows{} - query, args := rts.sql.Query() + query, args := selector.Query() if err := rts.driver.Query(ctx, query, args, rows); err != nil { return err } diff --git a/storage/ent/db/refreshtoken_update.go b/storage/ent/db/refreshtoken_update.go index 6c11c7f7..2b6a2344 100644 --- a/storage/ent/db/refreshtoken_update.go +++ b/storage/ent/db/refreshtoken_update.go @@ -10,6 +10,7 @@ import ( "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/dialect/sql/sqljson" "entgo.io/ent/schema/field" "github.com/dexidp/dex/storage/ent/db/predicate" "github.com/dexidp/dex/storage/ent/db/refreshtoken" @@ -40,6 +41,12 @@ func (rtu *RefreshTokenUpdate) SetScopes(s []string) *RefreshTokenUpdate { return rtu } +// AppendScopes appends s to the "scopes" field. +func (rtu *RefreshTokenUpdate) AppendScopes(s []string) *RefreshTokenUpdate { + rtu.mutation.AppendScopes(s) + return rtu +} + // ClearScopes clears the value of the "scopes" field. func (rtu *RefreshTokenUpdate) ClearScopes() *RefreshTokenUpdate { rtu.mutation.ClearScopes() @@ -82,6 +89,12 @@ func (rtu *RefreshTokenUpdate) SetClaimsGroups(s []string) *RefreshTokenUpdate { return rtu } +// AppendClaimsGroups appends s to the "claims_groups" field. +func (rtu *RefreshTokenUpdate) AppendClaimsGroups(s []string) *RefreshTokenUpdate { + rtu.mutation.AppendClaimsGroups(s) + return rtu +} + // ClearClaimsGroups clears the value of the "claims_groups" field. func (rtu *RefreshTokenUpdate) ClearClaimsGroups() *RefreshTokenUpdate { rtu.mutation.ClearClaimsGroups() @@ -183,40 +196,7 @@ func (rtu *RefreshTokenUpdate) Mutation() *RefreshTokenMutation { // Save executes the query and returns the number of nodes affected by the update operation. func (rtu *RefreshTokenUpdate) Save(ctx context.Context) (int, error) { - var ( - err error - affected int - ) - if len(rtu.hooks) == 0 { - if err = rtu.check(); err != nil { - return 0, err - } - affected, err = rtu.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*RefreshTokenMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err = rtu.check(); err != nil { - return 0, err - } - rtu.mutation = mutation - affected, err = rtu.sqlSave(ctx) - mutation.done = true - return affected, err - }) - for i := len(rtu.hooks) - 1; i >= 0; i-- { - if rtu.hooks[i] == nil { - return 0, fmt.Errorf("db: uninitialized hook (forgotten import db/runtime?)") - } - mut = rtu.hooks[i](mut) - } - if _, err := mut.Mutate(ctx, rtu.mutation); err != nil { - return 0, err - } - } - return affected, err + return withHooks[int, RefreshTokenMutation](ctx, rtu.sqlSave, rtu.mutation, rtu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -277,16 +257,10 @@ func (rtu *RefreshTokenUpdate) check() error { } func (rtu *RefreshTokenUpdate) sqlSave(ctx context.Context) (n int, err error) { - _spec := &sqlgraph.UpdateSpec{ - Node: &sqlgraph.NodeSpec{ - Table: refreshtoken.Table, - Columns: refreshtoken.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeString, - Column: refreshtoken.FieldID, - }, - }, + if err := rtu.check(); err != nil { + return n, err } + _spec := sqlgraph.NewUpdateSpec(refreshtoken.Table, refreshtoken.Columns, sqlgraph.NewFieldSpec(refreshtoken.FieldID, field.TypeString)) if ps := rtu.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { @@ -295,127 +269,68 @@ func (rtu *RefreshTokenUpdate) sqlSave(ctx context.Context) (n int, err error) { } } if value, ok := rtu.mutation.ClientID(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: refreshtoken.FieldClientID, - }) + _spec.SetField(refreshtoken.FieldClientID, field.TypeString, value) } if value, ok := rtu.mutation.Scopes(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeJSON, - Value: value, - Column: refreshtoken.FieldScopes, + _spec.SetField(refreshtoken.FieldScopes, field.TypeJSON, value) + } + if value, ok := rtu.mutation.AppendedScopes(); ok { + _spec.AddModifier(func(u *sql.UpdateBuilder) { + sqljson.Append(u, refreshtoken.FieldScopes, value) }) } if rtu.mutation.ScopesCleared() { - _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ - Type: field.TypeJSON, - Column: refreshtoken.FieldScopes, - }) + _spec.ClearField(refreshtoken.FieldScopes, field.TypeJSON) } if value, ok := rtu.mutation.Nonce(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: refreshtoken.FieldNonce, - }) + _spec.SetField(refreshtoken.FieldNonce, field.TypeString, value) } if value, ok := rtu.mutation.ClaimsUserID(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: refreshtoken.FieldClaimsUserID, - }) + _spec.SetField(refreshtoken.FieldClaimsUserID, field.TypeString, value) } if value, ok := rtu.mutation.ClaimsUsername(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: refreshtoken.FieldClaimsUsername, - }) + _spec.SetField(refreshtoken.FieldClaimsUsername, field.TypeString, value) } if value, ok := rtu.mutation.ClaimsEmail(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: refreshtoken.FieldClaimsEmail, - }) + _spec.SetField(refreshtoken.FieldClaimsEmail, field.TypeString, value) } if value, ok := rtu.mutation.ClaimsEmailVerified(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeBool, - Value: value, - Column: refreshtoken.FieldClaimsEmailVerified, - }) + _spec.SetField(refreshtoken.FieldClaimsEmailVerified, field.TypeBool, value) } if value, ok := rtu.mutation.ClaimsGroups(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeJSON, - Value: value, - Column: refreshtoken.FieldClaimsGroups, + _spec.SetField(refreshtoken.FieldClaimsGroups, field.TypeJSON, value) + } + if value, ok := rtu.mutation.AppendedClaimsGroups(); ok { + _spec.AddModifier(func(u *sql.UpdateBuilder) { + sqljson.Append(u, refreshtoken.FieldClaimsGroups, value) }) } if rtu.mutation.ClaimsGroupsCleared() { - _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ - Type: field.TypeJSON, - Column: refreshtoken.FieldClaimsGroups, - }) + _spec.ClearField(refreshtoken.FieldClaimsGroups, field.TypeJSON) } if value, ok := rtu.mutation.ClaimsPreferredUsername(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: refreshtoken.FieldClaimsPreferredUsername, - }) + _spec.SetField(refreshtoken.FieldClaimsPreferredUsername, field.TypeString, value) } if value, ok := rtu.mutation.ConnectorID(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: refreshtoken.FieldConnectorID, - }) + _spec.SetField(refreshtoken.FieldConnectorID, field.TypeString, value) } if value, ok := rtu.mutation.ConnectorData(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeBytes, - Value: value, - Column: refreshtoken.FieldConnectorData, - }) + _spec.SetField(refreshtoken.FieldConnectorData, field.TypeBytes, value) } if rtu.mutation.ConnectorDataCleared() { - _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ - Type: field.TypeBytes, - Column: refreshtoken.FieldConnectorData, - }) + _spec.ClearField(refreshtoken.FieldConnectorData, field.TypeBytes) } if value, ok := rtu.mutation.Token(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: refreshtoken.FieldToken, - }) + _spec.SetField(refreshtoken.FieldToken, field.TypeString, value) } if value, ok := rtu.mutation.ObsoleteToken(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: refreshtoken.FieldObsoleteToken, - }) + _spec.SetField(refreshtoken.FieldObsoleteToken, field.TypeString, value) } if value, ok := rtu.mutation.CreatedAt(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeTime, - Value: value, - Column: refreshtoken.FieldCreatedAt, - }) + _spec.SetField(refreshtoken.FieldCreatedAt, field.TypeTime, value) } if value, ok := rtu.mutation.LastUsed(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeTime, - Value: value, - Column: refreshtoken.FieldLastUsed, - }) + _spec.SetField(refreshtoken.FieldLastUsed, field.TypeTime, value) } if n, err = sqlgraph.UpdateNodes(ctx, rtu.driver, _spec); err != nil { if _, ok := err.(*sqlgraph.NotFoundError); ok { @@ -425,6 +340,7 @@ func (rtu *RefreshTokenUpdate) sqlSave(ctx context.Context) (n int, err error) { } return 0, err } + rtu.mutation.done = true return n, nil } @@ -448,6 +364,12 @@ func (rtuo *RefreshTokenUpdateOne) SetScopes(s []string) *RefreshTokenUpdateOne return rtuo } +// AppendScopes appends s to the "scopes" field. +func (rtuo *RefreshTokenUpdateOne) AppendScopes(s []string) *RefreshTokenUpdateOne { + rtuo.mutation.AppendScopes(s) + return rtuo +} + // ClearScopes clears the value of the "scopes" field. func (rtuo *RefreshTokenUpdateOne) ClearScopes() *RefreshTokenUpdateOne { rtuo.mutation.ClearScopes() @@ -490,6 +412,12 @@ func (rtuo *RefreshTokenUpdateOne) SetClaimsGroups(s []string) *RefreshTokenUpda return rtuo } +// AppendClaimsGroups appends s to the "claims_groups" field. +func (rtuo *RefreshTokenUpdateOne) AppendClaimsGroups(s []string) *RefreshTokenUpdateOne { + rtuo.mutation.AppendClaimsGroups(s) + return rtuo +} + // ClearClaimsGroups clears the value of the "claims_groups" field. func (rtuo *RefreshTokenUpdateOne) ClearClaimsGroups() *RefreshTokenUpdateOne { rtuo.mutation.ClearClaimsGroups() @@ -589,6 +517,12 @@ func (rtuo *RefreshTokenUpdateOne) Mutation() *RefreshTokenMutation { return rtuo.mutation } +// Where appends a list predicates to the RefreshTokenUpdate builder. +func (rtuo *RefreshTokenUpdateOne) Where(ps ...predicate.RefreshToken) *RefreshTokenUpdateOne { + rtuo.mutation.Where(ps...) + return rtuo +} + // Select allows selecting one or more fields (columns) of the returned entity. // The default is selecting all fields defined in the entity schema. func (rtuo *RefreshTokenUpdateOne) Select(field string, fields ...string) *RefreshTokenUpdateOne { @@ -598,46 +532,7 @@ func (rtuo *RefreshTokenUpdateOne) Select(field string, fields ...string) *Refre // Save executes the query and returns the updated RefreshToken entity. func (rtuo *RefreshTokenUpdateOne) Save(ctx context.Context) (*RefreshToken, error) { - var ( - err error - node *RefreshToken - ) - if len(rtuo.hooks) == 0 { - if err = rtuo.check(); err != nil { - return nil, err - } - node, err = rtuo.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*RefreshTokenMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err = rtuo.check(); err != nil { - return nil, err - } - rtuo.mutation = mutation - node, err = rtuo.sqlSave(ctx) - mutation.done = true - return node, err - }) - for i := len(rtuo.hooks) - 1; i >= 0; i-- { - if rtuo.hooks[i] == nil { - return nil, fmt.Errorf("db: uninitialized hook (forgotten import db/runtime?)") - } - mut = rtuo.hooks[i](mut) - } - v, err := mut.Mutate(ctx, rtuo.mutation) - if err != nil { - return nil, err - } - nv, ok := v.(*RefreshToken) - if !ok { - return nil, fmt.Errorf("unexpected node type %T returned from RefreshTokenMutation", v) - } - node = nv - } - return node, err + return withHooks[*RefreshToken, RefreshTokenMutation](ctx, rtuo.sqlSave, rtuo.mutation, rtuo.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -698,16 +593,10 @@ func (rtuo *RefreshTokenUpdateOne) check() error { } func (rtuo *RefreshTokenUpdateOne) sqlSave(ctx context.Context) (_node *RefreshToken, err error) { - _spec := &sqlgraph.UpdateSpec{ - Node: &sqlgraph.NodeSpec{ - Table: refreshtoken.Table, - Columns: refreshtoken.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeString, - Column: refreshtoken.FieldID, - }, - }, + if err := rtuo.check(); err != nil { + return _node, err } + _spec := sqlgraph.NewUpdateSpec(refreshtoken.Table, refreshtoken.Columns, sqlgraph.NewFieldSpec(refreshtoken.FieldID, field.TypeString)) id, ok := rtuo.mutation.ID() if !ok { return nil, &ValidationError{Name: "id", err: errors.New(`db: missing "RefreshToken.id" for update`)} @@ -733,127 +622,68 @@ func (rtuo *RefreshTokenUpdateOne) sqlSave(ctx context.Context) (_node *RefreshT } } if value, ok := rtuo.mutation.ClientID(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: refreshtoken.FieldClientID, - }) + _spec.SetField(refreshtoken.FieldClientID, field.TypeString, value) } if value, ok := rtuo.mutation.Scopes(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeJSON, - Value: value, - Column: refreshtoken.FieldScopes, + _spec.SetField(refreshtoken.FieldScopes, field.TypeJSON, value) + } + if value, ok := rtuo.mutation.AppendedScopes(); ok { + _spec.AddModifier(func(u *sql.UpdateBuilder) { + sqljson.Append(u, refreshtoken.FieldScopes, value) }) } if rtuo.mutation.ScopesCleared() { - _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ - Type: field.TypeJSON, - Column: refreshtoken.FieldScopes, - }) + _spec.ClearField(refreshtoken.FieldScopes, field.TypeJSON) } if value, ok := rtuo.mutation.Nonce(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: refreshtoken.FieldNonce, - }) + _spec.SetField(refreshtoken.FieldNonce, field.TypeString, value) } if value, ok := rtuo.mutation.ClaimsUserID(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: refreshtoken.FieldClaimsUserID, - }) + _spec.SetField(refreshtoken.FieldClaimsUserID, field.TypeString, value) } if value, ok := rtuo.mutation.ClaimsUsername(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: refreshtoken.FieldClaimsUsername, - }) + _spec.SetField(refreshtoken.FieldClaimsUsername, field.TypeString, value) } if value, ok := rtuo.mutation.ClaimsEmail(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: refreshtoken.FieldClaimsEmail, - }) + _spec.SetField(refreshtoken.FieldClaimsEmail, field.TypeString, value) } if value, ok := rtuo.mutation.ClaimsEmailVerified(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeBool, - Value: value, - Column: refreshtoken.FieldClaimsEmailVerified, - }) + _spec.SetField(refreshtoken.FieldClaimsEmailVerified, field.TypeBool, value) } if value, ok := rtuo.mutation.ClaimsGroups(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeJSON, - Value: value, - Column: refreshtoken.FieldClaimsGroups, + _spec.SetField(refreshtoken.FieldClaimsGroups, field.TypeJSON, value) + } + if value, ok := rtuo.mutation.AppendedClaimsGroups(); ok { + _spec.AddModifier(func(u *sql.UpdateBuilder) { + sqljson.Append(u, refreshtoken.FieldClaimsGroups, value) }) } if rtuo.mutation.ClaimsGroupsCleared() { - _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ - Type: field.TypeJSON, - Column: refreshtoken.FieldClaimsGroups, - }) + _spec.ClearField(refreshtoken.FieldClaimsGroups, field.TypeJSON) } if value, ok := rtuo.mutation.ClaimsPreferredUsername(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: refreshtoken.FieldClaimsPreferredUsername, - }) + _spec.SetField(refreshtoken.FieldClaimsPreferredUsername, field.TypeString, value) } if value, ok := rtuo.mutation.ConnectorID(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: refreshtoken.FieldConnectorID, - }) + _spec.SetField(refreshtoken.FieldConnectorID, field.TypeString, value) } if value, ok := rtuo.mutation.ConnectorData(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeBytes, - Value: value, - Column: refreshtoken.FieldConnectorData, - }) + _spec.SetField(refreshtoken.FieldConnectorData, field.TypeBytes, value) } if rtuo.mutation.ConnectorDataCleared() { - _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ - Type: field.TypeBytes, - Column: refreshtoken.FieldConnectorData, - }) + _spec.ClearField(refreshtoken.FieldConnectorData, field.TypeBytes) } if value, ok := rtuo.mutation.Token(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: refreshtoken.FieldToken, - }) + _spec.SetField(refreshtoken.FieldToken, field.TypeString, value) } if value, ok := rtuo.mutation.ObsoleteToken(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: refreshtoken.FieldObsoleteToken, - }) + _spec.SetField(refreshtoken.FieldObsoleteToken, field.TypeString, value) } if value, ok := rtuo.mutation.CreatedAt(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeTime, - Value: value, - Column: refreshtoken.FieldCreatedAt, - }) + _spec.SetField(refreshtoken.FieldCreatedAt, field.TypeTime, value) } if value, ok := rtuo.mutation.LastUsed(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeTime, - Value: value, - Column: refreshtoken.FieldLastUsed, - }) + _spec.SetField(refreshtoken.FieldLastUsed, field.TypeTime, value) } _node = &RefreshToken{config: rtuo.config} _spec.Assign = _node.assignValues @@ -866,5 +696,6 @@ func (rtuo *RefreshTokenUpdateOne) sqlSave(ctx context.Context) (_node *RefreshT } return nil, err } + rtuo.mutation.done = true return _node, nil } diff --git a/storage/ent/db/runtime/runtime.go b/storage/ent/db/runtime/runtime.go index 9000ac47..0b87a8ea 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.11.2" // Version of ent codegen. - Sum = "h1:UM2/BUhF2FfsxPHRxLjQbhqJNaDdVlOwNIAMLs2jyto=" // Sum of ent codegen. + Version = "v0.11.8" // Version of ent codegen. + Sum = "h1:M/M0QL1CYCUSdqGRXUrXhFYSDRJPsOOrr+RLEej/gyQ=" // Sum of ent codegen. ) diff --git a/storage/ent/db/tx.go b/storage/ent/db/tx.go index 73d19447..42ba241a 100644 --- a/storage/ent/db/tx.go +++ b/storage/ent/db/tx.go @@ -36,12 +36,6 @@ type Tx struct { // lazily loaded. client *Client clientOnce sync.Once - - // completion callbacks. - mu sync.Mutex - onCommit []CommitHook - onRollback []RollbackHook - // ctx lives for the life of the transaction. It is // the same context used by the underlying connection. ctx context.Context @@ -86,9 +80,9 @@ func (tx *Tx) Commit() error { var fn Committer = CommitFunc(func(context.Context, *Tx) error { return txDriver.tx.Commit() }) - tx.mu.Lock() - hooks := append([]CommitHook(nil), tx.onCommit...) - tx.mu.Unlock() + txDriver.mu.Lock() + hooks := append([]CommitHook(nil), txDriver.onCommit...) + txDriver.mu.Unlock() for i := len(hooks) - 1; i >= 0; i-- { fn = hooks[i](fn) } @@ -97,9 +91,10 @@ func (tx *Tx) Commit() error { // OnCommit adds a hook to call on commit. func (tx *Tx) OnCommit(f CommitHook) { - tx.mu.Lock() - defer tx.mu.Unlock() - tx.onCommit = append(tx.onCommit, f) + txDriver := tx.config.driver.(*txDriver) + txDriver.mu.Lock() + txDriver.onCommit = append(txDriver.onCommit, f) + txDriver.mu.Unlock() } type ( @@ -141,9 +136,9 @@ func (tx *Tx) Rollback() error { var fn Rollbacker = RollbackFunc(func(context.Context, *Tx) error { return txDriver.tx.Rollback() }) - tx.mu.Lock() - hooks := append([]RollbackHook(nil), tx.onRollback...) - tx.mu.Unlock() + txDriver.mu.Lock() + hooks := append([]RollbackHook(nil), txDriver.onRollback...) + txDriver.mu.Unlock() for i := len(hooks) - 1; i >= 0; i-- { fn = hooks[i](fn) } @@ -152,9 +147,10 @@ func (tx *Tx) Rollback() error { // OnRollback adds a hook to call on rollback. func (tx *Tx) OnRollback(f RollbackHook) { - tx.mu.Lock() - defer tx.mu.Unlock() - tx.onRollback = append(tx.onRollback, f) + txDriver := tx.config.driver.(*txDriver) + txDriver.mu.Lock() + txDriver.onRollback = append(txDriver.onRollback, f) + txDriver.mu.Unlock() } // Client returns a Client that binds to current transaction. @@ -195,6 +191,10 @@ type txDriver struct { drv dialect.Driver // tx is the underlying transaction. tx dialect.Tx + // completion hooks. + mu sync.Mutex + onCommit []CommitHook + onRollback []RollbackHook } // newTx creates a new transactional driver. @@ -225,12 +225,12 @@ func (*txDriver) Commit() error { return nil } func (*txDriver) Rollback() error { return nil } // Exec calls tx.Exec. -func (tx *txDriver) Exec(ctx context.Context, query string, args, v interface{}) error { +func (tx *txDriver) Exec(ctx context.Context, query string, args, v any) error { return tx.tx.Exec(ctx, query, args, v) } // Query calls tx.Query. -func (tx *txDriver) Query(ctx context.Context, query string, args, v interface{}) error { +func (tx *txDriver) Query(ctx context.Context, query string, args, v any) error { return tx.tx.Query(ctx, query, args, v) }