parent
a908ec462f
commit
a84c5d8e97
@ -1 +1 @@
|
||||
Subproject commit 49245dc9c19544f1f291fc939f8f00190df7aa00
|
||||
Subproject commit ee51bb6483d69f99c86db4c370ca742e486cfad9
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,262 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"github.com/cloudreve/Cloudreve/v4/ent/oauthclient"
|
||||
"github.com/cloudreve/Cloudreve/v4/inventory/types"
|
||||
)
|
||||
|
||||
// OAuthClient is the model entity for the OAuthClient schema.
|
||||
type OAuthClient struct {
|
||||
config `json:"-"`
|
||||
// ID of the ent.
|
||||
ID int `json:"id,omitempty"`
|
||||
// CreatedAt holds the value of the "created_at" field.
|
||||
CreatedAt time.Time `json:"created_at,omitempty"`
|
||||
// UpdatedAt holds the value of the "updated_at" field.
|
||||
UpdatedAt time.Time `json:"updated_at,omitempty"`
|
||||
// DeletedAt holds the value of the "deleted_at" field.
|
||||
DeletedAt *time.Time `json:"deleted_at,omitempty"`
|
||||
// GUID holds the value of the "guid" field.
|
||||
GUID string `json:"guid,omitempty"`
|
||||
// Secret holds the value of the "secret" field.
|
||||
Secret string `json:"-"`
|
||||
// Name holds the value of the "name" field.
|
||||
Name string `json:"name,omitempty"`
|
||||
// HomepageURL holds the value of the "homepage_url" field.
|
||||
HomepageURL string `json:"homepage_url,omitempty"`
|
||||
// RedirectUris holds the value of the "redirect_uris" field.
|
||||
RedirectUris []string `json:"redirect_uris,omitempty"`
|
||||
// Scopes holds the value of the "scopes" field.
|
||||
Scopes []string `json:"scopes,omitempty"`
|
||||
// Props holds the value of the "props" field.
|
||||
Props *types.OAuthClientProps `json:"props,omitempty"`
|
||||
// IsEnabled holds the value of the "is_enabled" field.
|
||||
IsEnabled bool `json:"is_enabled,omitempty"`
|
||||
// Edges holds the relations/edges for other nodes in the graph.
|
||||
// The values are being populated by the OAuthClientQuery when eager-loading is set.
|
||||
Edges OAuthClientEdges `json:"edges"`
|
||||
selectValues sql.SelectValues
|
||||
}
|
||||
|
||||
// OAuthClientEdges holds the relations/edges for other nodes in the graph.
|
||||
type OAuthClientEdges struct {
|
||||
// Grants holds the value of the grants edge.
|
||||
Grants []*OAuthGrant `json:"grants,omitempty"`
|
||||
// loadedTypes holds the information for reporting if a
|
||||
// type was loaded (or requested) in eager-loading or not.
|
||||
loadedTypes [1]bool
|
||||
}
|
||||
|
||||
// GrantsOrErr returns the Grants value or an error if the edge
|
||||
// was not loaded in eager-loading.
|
||||
func (e OAuthClientEdges) GrantsOrErr() ([]*OAuthGrant, error) {
|
||||
if e.loadedTypes[0] {
|
||||
return e.Grants, nil
|
||||
}
|
||||
return nil, &NotLoadedError{edge: "grants"}
|
||||
}
|
||||
|
||||
// scanValues returns the types for scanning values from sql.Rows.
|
||||
func (*OAuthClient) scanValues(columns []string) ([]any, error) {
|
||||
values := make([]any, len(columns))
|
||||
for i := range columns {
|
||||
switch columns[i] {
|
||||
case oauthclient.FieldRedirectUris, oauthclient.FieldScopes, oauthclient.FieldProps:
|
||||
values[i] = new([]byte)
|
||||
case oauthclient.FieldIsEnabled:
|
||||
values[i] = new(sql.NullBool)
|
||||
case oauthclient.FieldID:
|
||||
values[i] = new(sql.NullInt64)
|
||||
case oauthclient.FieldGUID, oauthclient.FieldSecret, oauthclient.FieldName, oauthclient.FieldHomepageURL:
|
||||
values[i] = new(sql.NullString)
|
||||
case oauthclient.FieldCreatedAt, oauthclient.FieldUpdatedAt, oauthclient.FieldDeletedAt:
|
||||
values[i] = new(sql.NullTime)
|
||||
default:
|
||||
values[i] = new(sql.UnknownType)
|
||||
}
|
||||
}
|
||||
return values, nil
|
||||
}
|
||||
|
||||
// assignValues assigns the values that were returned from sql.Rows (after scanning)
|
||||
// to the OAuthClient fields.
|
||||
func (oc *OAuthClient) 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)
|
||||
}
|
||||
for i := range columns {
|
||||
switch columns[i] {
|
||||
case oauthclient.FieldID:
|
||||
value, ok := values[i].(*sql.NullInt64)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field id", value)
|
||||
}
|
||||
oc.ID = int(value.Int64)
|
||||
case oauthclient.FieldCreatedAt:
|
||||
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field created_at", values[i])
|
||||
} else if value.Valid {
|
||||
oc.CreatedAt = value.Time
|
||||
}
|
||||
case oauthclient.FieldUpdatedAt:
|
||||
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field updated_at", values[i])
|
||||
} else if value.Valid {
|
||||
oc.UpdatedAt = value.Time
|
||||
}
|
||||
case oauthclient.FieldDeletedAt:
|
||||
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field deleted_at", values[i])
|
||||
} else if value.Valid {
|
||||
oc.DeletedAt = new(time.Time)
|
||||
*oc.DeletedAt = value.Time
|
||||
}
|
||||
case oauthclient.FieldGUID:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field guid", values[i])
|
||||
} else if value.Valid {
|
||||
oc.GUID = value.String
|
||||
}
|
||||
case oauthclient.FieldSecret:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field secret", values[i])
|
||||
} else if value.Valid {
|
||||
oc.Secret = value.String
|
||||
}
|
||||
case oauthclient.FieldName:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field name", values[i])
|
||||
} else if value.Valid {
|
||||
oc.Name = value.String
|
||||
}
|
||||
case oauthclient.FieldHomepageURL:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field homepage_url", values[i])
|
||||
} else if value.Valid {
|
||||
oc.HomepageURL = value.String
|
||||
}
|
||||
case oauthclient.FieldRedirectUris:
|
||||
if value, ok := values[i].(*[]byte); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field redirect_uris", values[i])
|
||||
} else if value != nil && len(*value) > 0 {
|
||||
if err := json.Unmarshal(*value, &oc.RedirectUris); err != nil {
|
||||
return fmt.Errorf("unmarshal field redirect_uris: %w", err)
|
||||
}
|
||||
}
|
||||
case oauthclient.FieldScopes:
|
||||
if value, ok := values[i].(*[]byte); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field scopes", values[i])
|
||||
} else if value != nil && len(*value) > 0 {
|
||||
if err := json.Unmarshal(*value, &oc.Scopes); err != nil {
|
||||
return fmt.Errorf("unmarshal field scopes: %w", err)
|
||||
}
|
||||
}
|
||||
case oauthclient.FieldProps:
|
||||
if value, ok := values[i].(*[]byte); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field props", values[i])
|
||||
} else if value != nil && len(*value) > 0 {
|
||||
if err := json.Unmarshal(*value, &oc.Props); err != nil {
|
||||
return fmt.Errorf("unmarshal field props: %w", err)
|
||||
}
|
||||
}
|
||||
case oauthclient.FieldIsEnabled:
|
||||
if value, ok := values[i].(*sql.NullBool); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field is_enabled", values[i])
|
||||
} else if value.Valid {
|
||||
oc.IsEnabled = value.Bool
|
||||
}
|
||||
default:
|
||||
oc.selectValues.Set(columns[i], values[i])
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Value returns the ent.Value that was dynamically selected and assigned to the OAuthClient.
|
||||
// This includes values selected through modifiers, order, etc.
|
||||
func (oc *OAuthClient) Value(name string) (ent.Value, error) {
|
||||
return oc.selectValues.Get(name)
|
||||
}
|
||||
|
||||
// QueryGrants queries the "grants" edge of the OAuthClient entity.
|
||||
func (oc *OAuthClient) QueryGrants() *OAuthGrantQuery {
|
||||
return NewOAuthClientClient(oc.config).QueryGrants(oc)
|
||||
}
|
||||
|
||||
// Update returns a builder for updating this OAuthClient.
|
||||
// Note that you need to call OAuthClient.Unwrap() before calling this method if this OAuthClient
|
||||
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||
func (oc *OAuthClient) Update() *OAuthClientUpdateOne {
|
||||
return NewOAuthClientClient(oc.config).UpdateOne(oc)
|
||||
}
|
||||
|
||||
// Unwrap unwraps the OAuthClient entity that was returned from a transaction after it was closed,
|
||||
// so that all future queries will be executed through the driver which created the transaction.
|
||||
func (oc *OAuthClient) Unwrap() *OAuthClient {
|
||||
_tx, ok := oc.config.driver.(*txDriver)
|
||||
if !ok {
|
||||
panic("ent: OAuthClient is not a transactional entity")
|
||||
}
|
||||
oc.config.driver = _tx.drv
|
||||
return oc
|
||||
}
|
||||
|
||||
// String implements the fmt.Stringer.
|
||||
func (oc *OAuthClient) String() string {
|
||||
var builder strings.Builder
|
||||
builder.WriteString("OAuthClient(")
|
||||
builder.WriteString(fmt.Sprintf("id=%v, ", oc.ID))
|
||||
builder.WriteString("created_at=")
|
||||
builder.WriteString(oc.CreatedAt.Format(time.ANSIC))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("updated_at=")
|
||||
builder.WriteString(oc.UpdatedAt.Format(time.ANSIC))
|
||||
builder.WriteString(", ")
|
||||
if v := oc.DeletedAt; v != nil {
|
||||
builder.WriteString("deleted_at=")
|
||||
builder.WriteString(v.Format(time.ANSIC))
|
||||
}
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("guid=")
|
||||
builder.WriteString(oc.GUID)
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("secret=<sensitive>")
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("name=")
|
||||
builder.WriteString(oc.Name)
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("homepage_url=")
|
||||
builder.WriteString(oc.HomepageURL)
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("redirect_uris=")
|
||||
builder.WriteString(fmt.Sprintf("%v", oc.RedirectUris))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("scopes=")
|
||||
builder.WriteString(fmt.Sprintf("%v", oc.Scopes))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("props=")
|
||||
builder.WriteString(fmt.Sprintf("%v", oc.Props))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("is_enabled=")
|
||||
builder.WriteString(fmt.Sprintf("%v", oc.IsEnabled))
|
||||
builder.WriteByte(')')
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
// SetGrants manually set the edge as loaded state.
|
||||
func (e *OAuthClient) SetGrants(v []*OAuthGrant) {
|
||||
e.Edges.Grants = v
|
||||
e.Edges.loadedTypes[0] = true
|
||||
}
|
||||
|
||||
// OAuthClients is a parsable slice of OAuthClient.
|
||||
type OAuthClients []*OAuthClient
|
||||
@ -0,0 +1,179 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package oauthclient
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"github.com/cloudreve/Cloudreve/v4/inventory/types"
|
||||
)
|
||||
|
||||
const (
|
||||
// Label holds the string label denoting the oauthclient type in the database.
|
||||
Label = "oauth_client"
|
||||
// FieldID holds the string denoting the id field in the database.
|
||||
FieldID = "id"
|
||||
// FieldCreatedAt holds the string denoting the created_at field in the database.
|
||||
FieldCreatedAt = "created_at"
|
||||
// FieldUpdatedAt holds the string denoting the updated_at field in the database.
|
||||
FieldUpdatedAt = "updated_at"
|
||||
// FieldDeletedAt holds the string denoting the deleted_at field in the database.
|
||||
FieldDeletedAt = "deleted_at"
|
||||
// FieldGUID holds the string denoting the guid field in the database.
|
||||
FieldGUID = "guid"
|
||||
// FieldSecret holds the string denoting the secret field in the database.
|
||||
FieldSecret = "secret"
|
||||
// FieldName holds the string denoting the name field in the database.
|
||||
FieldName = "name"
|
||||
// FieldHomepageURL holds the string denoting the homepage_url field in the database.
|
||||
FieldHomepageURL = "homepage_url"
|
||||
// FieldRedirectUris holds the string denoting the redirect_uris field in the database.
|
||||
FieldRedirectUris = "redirect_uris"
|
||||
// FieldScopes holds the string denoting the scopes field in the database.
|
||||
FieldScopes = "scopes"
|
||||
// FieldProps holds the string denoting the props field in the database.
|
||||
FieldProps = "props"
|
||||
// FieldIsEnabled holds the string denoting the is_enabled field in the database.
|
||||
FieldIsEnabled = "is_enabled"
|
||||
// EdgeGrants holds the string denoting the grants edge name in mutations.
|
||||
EdgeGrants = "grants"
|
||||
// Table holds the table name of the oauthclient in the database.
|
||||
Table = "oauth_clients"
|
||||
// GrantsTable is the table that holds the grants relation/edge.
|
||||
GrantsTable = "oauth_grants"
|
||||
// GrantsInverseTable is the table name for the OAuthGrant entity.
|
||||
// It exists in this package in order to avoid circular dependency with the "oauthgrant" package.
|
||||
GrantsInverseTable = "oauth_grants"
|
||||
// GrantsColumn is the table column denoting the grants relation/edge.
|
||||
GrantsColumn = "client_id"
|
||||
)
|
||||
|
||||
// Columns holds all SQL columns for oauthclient fields.
|
||||
var Columns = []string{
|
||||
FieldID,
|
||||
FieldCreatedAt,
|
||||
FieldUpdatedAt,
|
||||
FieldDeletedAt,
|
||||
FieldGUID,
|
||||
FieldSecret,
|
||||
FieldName,
|
||||
FieldHomepageURL,
|
||||
FieldRedirectUris,
|
||||
FieldScopes,
|
||||
FieldProps,
|
||||
FieldIsEnabled,
|
||||
}
|
||||
|
||||
// ValidColumn reports if the column name is valid (part of the table columns).
|
||||
func ValidColumn(column string) bool {
|
||||
for i := range Columns {
|
||||
if column == Columns[i] {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Note that the variables below are initialized by the runtime
|
||||
// package on the initialization of the application. Therefore,
|
||||
// it should be imported in the main as follows:
|
||||
//
|
||||
// import _ "github.com/cloudreve/Cloudreve/v4/ent/runtime"
|
||||
var (
|
||||
Hooks [1]ent.Hook
|
||||
Interceptors [1]ent.Interceptor
|
||||
// DefaultCreatedAt holds the default value on creation for the "created_at" field.
|
||||
DefaultCreatedAt func() time.Time
|
||||
// DefaultUpdatedAt holds the default value on creation for the "updated_at" field.
|
||||
DefaultUpdatedAt func() time.Time
|
||||
// UpdateDefaultUpdatedAt holds the default value on update for the "updated_at" field.
|
||||
UpdateDefaultUpdatedAt func() time.Time
|
||||
// GUIDValidator is a validator for the "guid" field. It is called by the builders before save.
|
||||
GUIDValidator func(string) error
|
||||
// SecretValidator is a validator for the "secret" field. It is called by the builders before save.
|
||||
SecretValidator func(string) error
|
||||
// NameValidator is a validator for the "name" field. It is called by the builders before save.
|
||||
NameValidator func(string) error
|
||||
// HomepageURLValidator is a validator for the "homepage_url" field. It is called by the builders before save.
|
||||
HomepageURLValidator func(string) error
|
||||
// DefaultRedirectUris holds the default value on creation for the "redirect_uris" field.
|
||||
DefaultRedirectUris []string
|
||||
// DefaultScopes holds the default value on creation for the "scopes" field.
|
||||
DefaultScopes []string
|
||||
// DefaultProps holds the default value on creation for the "props" field.
|
||||
DefaultProps *types.OAuthClientProps
|
||||
// DefaultIsEnabled holds the default value on creation for the "is_enabled" field.
|
||||
DefaultIsEnabled bool
|
||||
)
|
||||
|
||||
// OrderOption defines the ordering options for the OAuthClient queries.
|
||||
type OrderOption func(*sql.Selector)
|
||||
|
||||
// ByID orders the results by the id field.
|
||||
func ByID(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldID, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByCreatedAt orders the results by the created_at field.
|
||||
func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldCreatedAt, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByUpdatedAt orders the results by the updated_at field.
|
||||
func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByDeletedAt orders the results by the deleted_at field.
|
||||
func ByDeletedAt(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldDeletedAt, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByGUID orders the results by the guid field.
|
||||
func ByGUID(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldGUID, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// BySecret orders the results by the secret field.
|
||||
func BySecret(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldSecret, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByName orders the results by the name field.
|
||||
func ByName(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldName, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByHomepageURL orders the results by the homepage_url field.
|
||||
func ByHomepageURL(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldHomepageURL, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByIsEnabled orders the results by the is_enabled field.
|
||||
func ByIsEnabled(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldIsEnabled, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByGrantsCount orders the results by grants count.
|
||||
func ByGrantsCount(opts ...sql.OrderTermOption) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
sqlgraph.OrderByNeighborsCount(s, newGrantsStep(), opts...)
|
||||
}
|
||||
}
|
||||
|
||||
// ByGrants orders the results by grants terms.
|
||||
func ByGrants(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
sqlgraph.OrderByNeighborTerms(s, newGrantsStep(), append([]sql.OrderTerm{term}, terms...)...)
|
||||
}
|
||||
}
|
||||
func newGrantsStep() *sqlgraph.Step {
|
||||
return sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.To(GrantsInverseTable, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2M, false, GrantsTable, GrantsColumn),
|
||||
)
|
||||
}
|
||||
@ -0,0 +1,544 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package oauthclient
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"github.com/cloudreve/Cloudreve/v4/ent/predicate"
|
||||
)
|
||||
|
||||
// ID filters vertices based on their ID field.
|
||||
func ID(id int) predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDEQ applies the EQ predicate on the ID field.
|
||||
func IDEQ(id int) predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDNEQ applies the NEQ predicate on the ID field.
|
||||
func IDNEQ(id int) predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.FieldNEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDIn applies the In predicate on the ID field.
|
||||
func IDIn(ids ...int) predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.FieldIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDNotIn applies the NotIn predicate on the ID field.
|
||||
func IDNotIn(ids ...int) predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.FieldNotIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDGT applies the GT predicate on the ID field.
|
||||
func IDGT(id int) predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.FieldGT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDGTE applies the GTE predicate on the ID field.
|
||||
func IDGTE(id int) predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.FieldGTE(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLT applies the LT predicate on the ID field.
|
||||
func IDLT(id int) predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.FieldLT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLTE applies the LTE predicate on the ID field.
|
||||
func IDLTE(id int) predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.FieldLTE(FieldID, id))
|
||||
}
|
||||
|
||||
// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ.
|
||||
func CreatedAt(v time.Time) predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.FieldEQ(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// UpdatedAt applies equality check predicate on the "updated_at" field. It's identical to UpdatedAtEQ.
|
||||
func UpdatedAt(v time.Time) predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.FieldEQ(FieldUpdatedAt, v))
|
||||
}
|
||||
|
||||
// DeletedAt applies equality check predicate on the "deleted_at" field. It's identical to DeletedAtEQ.
|
||||
func DeletedAt(v time.Time) predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.FieldEQ(FieldDeletedAt, v))
|
||||
}
|
||||
|
||||
// GUID applies equality check predicate on the "guid" field. It's identical to GUIDEQ.
|
||||
func GUID(v string) predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.FieldEQ(FieldGUID, v))
|
||||
}
|
||||
|
||||
// Secret applies equality check predicate on the "secret" field. It's identical to SecretEQ.
|
||||
func Secret(v string) predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.FieldEQ(FieldSecret, v))
|
||||
}
|
||||
|
||||
// Name applies equality check predicate on the "name" field. It's identical to NameEQ.
|
||||
func Name(v string) predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.FieldEQ(FieldName, v))
|
||||
}
|
||||
|
||||
// HomepageURL applies equality check predicate on the "homepage_url" field. It's identical to HomepageURLEQ.
|
||||
func HomepageURL(v string) predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.FieldEQ(FieldHomepageURL, v))
|
||||
}
|
||||
|
||||
// IsEnabled applies equality check predicate on the "is_enabled" field. It's identical to IsEnabledEQ.
|
||||
func IsEnabled(v bool) predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.FieldEQ(FieldIsEnabled, v))
|
||||
}
|
||||
|
||||
// CreatedAtEQ applies the EQ predicate on the "created_at" field.
|
||||
func CreatedAtEQ(v time.Time) predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.FieldEQ(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// CreatedAtNEQ applies the NEQ predicate on the "created_at" field.
|
||||
func CreatedAtNEQ(v time.Time) predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.FieldNEQ(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// CreatedAtIn applies the In predicate on the "created_at" field.
|
||||
func CreatedAtIn(vs ...time.Time) predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.FieldIn(FieldCreatedAt, vs...))
|
||||
}
|
||||
|
||||
// CreatedAtNotIn applies the NotIn predicate on the "created_at" field.
|
||||
func CreatedAtNotIn(vs ...time.Time) predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.FieldNotIn(FieldCreatedAt, vs...))
|
||||
}
|
||||
|
||||
// CreatedAtGT applies the GT predicate on the "created_at" field.
|
||||
func CreatedAtGT(v time.Time) predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.FieldGT(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// CreatedAtGTE applies the GTE predicate on the "created_at" field.
|
||||
func CreatedAtGTE(v time.Time) predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.FieldGTE(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// CreatedAtLT applies the LT predicate on the "created_at" field.
|
||||
func CreatedAtLT(v time.Time) predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.FieldLT(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// CreatedAtLTE applies the LTE predicate on the "created_at" field.
|
||||
func CreatedAtLTE(v time.Time) predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.FieldLTE(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// UpdatedAtEQ applies the EQ predicate on the "updated_at" field.
|
||||
func UpdatedAtEQ(v time.Time) predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.FieldEQ(FieldUpdatedAt, v))
|
||||
}
|
||||
|
||||
// UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field.
|
||||
func UpdatedAtNEQ(v time.Time) predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.FieldNEQ(FieldUpdatedAt, v))
|
||||
}
|
||||
|
||||
// UpdatedAtIn applies the In predicate on the "updated_at" field.
|
||||
func UpdatedAtIn(vs ...time.Time) predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.FieldIn(FieldUpdatedAt, vs...))
|
||||
}
|
||||
|
||||
// UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field.
|
||||
func UpdatedAtNotIn(vs ...time.Time) predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.FieldNotIn(FieldUpdatedAt, vs...))
|
||||
}
|
||||
|
||||
// UpdatedAtGT applies the GT predicate on the "updated_at" field.
|
||||
func UpdatedAtGT(v time.Time) predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.FieldGT(FieldUpdatedAt, v))
|
||||
}
|
||||
|
||||
// UpdatedAtGTE applies the GTE predicate on the "updated_at" field.
|
||||
func UpdatedAtGTE(v time.Time) predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.FieldGTE(FieldUpdatedAt, v))
|
||||
}
|
||||
|
||||
// UpdatedAtLT applies the LT predicate on the "updated_at" field.
|
||||
func UpdatedAtLT(v time.Time) predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.FieldLT(FieldUpdatedAt, v))
|
||||
}
|
||||
|
||||
// UpdatedAtLTE applies the LTE predicate on the "updated_at" field.
|
||||
func UpdatedAtLTE(v time.Time) predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.FieldLTE(FieldUpdatedAt, v))
|
||||
}
|
||||
|
||||
// DeletedAtEQ applies the EQ predicate on the "deleted_at" field.
|
||||
func DeletedAtEQ(v time.Time) predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.FieldEQ(FieldDeletedAt, v))
|
||||
}
|
||||
|
||||
// DeletedAtNEQ applies the NEQ predicate on the "deleted_at" field.
|
||||
func DeletedAtNEQ(v time.Time) predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.FieldNEQ(FieldDeletedAt, v))
|
||||
}
|
||||
|
||||
// DeletedAtIn applies the In predicate on the "deleted_at" field.
|
||||
func DeletedAtIn(vs ...time.Time) predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.FieldIn(FieldDeletedAt, vs...))
|
||||
}
|
||||
|
||||
// DeletedAtNotIn applies the NotIn predicate on the "deleted_at" field.
|
||||
func DeletedAtNotIn(vs ...time.Time) predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.FieldNotIn(FieldDeletedAt, vs...))
|
||||
}
|
||||
|
||||
// DeletedAtGT applies the GT predicate on the "deleted_at" field.
|
||||
func DeletedAtGT(v time.Time) predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.FieldGT(FieldDeletedAt, v))
|
||||
}
|
||||
|
||||
// DeletedAtGTE applies the GTE predicate on the "deleted_at" field.
|
||||
func DeletedAtGTE(v time.Time) predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.FieldGTE(FieldDeletedAt, v))
|
||||
}
|
||||
|
||||
// DeletedAtLT applies the LT predicate on the "deleted_at" field.
|
||||
func DeletedAtLT(v time.Time) predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.FieldLT(FieldDeletedAt, v))
|
||||
}
|
||||
|
||||
// DeletedAtLTE applies the LTE predicate on the "deleted_at" field.
|
||||
func DeletedAtLTE(v time.Time) predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.FieldLTE(FieldDeletedAt, v))
|
||||
}
|
||||
|
||||
// DeletedAtIsNil applies the IsNil predicate on the "deleted_at" field.
|
||||
func DeletedAtIsNil() predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.FieldIsNull(FieldDeletedAt))
|
||||
}
|
||||
|
||||
// DeletedAtNotNil applies the NotNil predicate on the "deleted_at" field.
|
||||
func DeletedAtNotNil() predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.FieldNotNull(FieldDeletedAt))
|
||||
}
|
||||
|
||||
// GUIDEQ applies the EQ predicate on the "guid" field.
|
||||
func GUIDEQ(v string) predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.FieldEQ(FieldGUID, v))
|
||||
}
|
||||
|
||||
// GUIDNEQ applies the NEQ predicate on the "guid" field.
|
||||
func GUIDNEQ(v string) predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.FieldNEQ(FieldGUID, v))
|
||||
}
|
||||
|
||||
// GUIDIn applies the In predicate on the "guid" field.
|
||||
func GUIDIn(vs ...string) predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.FieldIn(FieldGUID, vs...))
|
||||
}
|
||||
|
||||
// GUIDNotIn applies the NotIn predicate on the "guid" field.
|
||||
func GUIDNotIn(vs ...string) predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.FieldNotIn(FieldGUID, vs...))
|
||||
}
|
||||
|
||||
// GUIDGT applies the GT predicate on the "guid" field.
|
||||
func GUIDGT(v string) predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.FieldGT(FieldGUID, v))
|
||||
}
|
||||
|
||||
// GUIDGTE applies the GTE predicate on the "guid" field.
|
||||
func GUIDGTE(v string) predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.FieldGTE(FieldGUID, v))
|
||||
}
|
||||
|
||||
// GUIDLT applies the LT predicate on the "guid" field.
|
||||
func GUIDLT(v string) predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.FieldLT(FieldGUID, v))
|
||||
}
|
||||
|
||||
// GUIDLTE applies the LTE predicate on the "guid" field.
|
||||
func GUIDLTE(v string) predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.FieldLTE(FieldGUID, v))
|
||||
}
|
||||
|
||||
// GUIDContains applies the Contains predicate on the "guid" field.
|
||||
func GUIDContains(v string) predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.FieldContains(FieldGUID, v))
|
||||
}
|
||||
|
||||
// GUIDHasPrefix applies the HasPrefix predicate on the "guid" field.
|
||||
func GUIDHasPrefix(v string) predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.FieldHasPrefix(FieldGUID, v))
|
||||
}
|
||||
|
||||
// GUIDHasSuffix applies the HasSuffix predicate on the "guid" field.
|
||||
func GUIDHasSuffix(v string) predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.FieldHasSuffix(FieldGUID, v))
|
||||
}
|
||||
|
||||
// GUIDEqualFold applies the EqualFold predicate on the "guid" field.
|
||||
func GUIDEqualFold(v string) predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.FieldEqualFold(FieldGUID, v))
|
||||
}
|
||||
|
||||
// GUIDContainsFold applies the ContainsFold predicate on the "guid" field.
|
||||
func GUIDContainsFold(v string) predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.FieldContainsFold(FieldGUID, v))
|
||||
}
|
||||
|
||||
// SecretEQ applies the EQ predicate on the "secret" field.
|
||||
func SecretEQ(v string) predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.FieldEQ(FieldSecret, v))
|
||||
}
|
||||
|
||||
// SecretNEQ applies the NEQ predicate on the "secret" field.
|
||||
func SecretNEQ(v string) predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.FieldNEQ(FieldSecret, v))
|
||||
}
|
||||
|
||||
// SecretIn applies the In predicate on the "secret" field.
|
||||
func SecretIn(vs ...string) predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.FieldIn(FieldSecret, vs...))
|
||||
}
|
||||
|
||||
// SecretNotIn applies the NotIn predicate on the "secret" field.
|
||||
func SecretNotIn(vs ...string) predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.FieldNotIn(FieldSecret, vs...))
|
||||
}
|
||||
|
||||
// SecretGT applies the GT predicate on the "secret" field.
|
||||
func SecretGT(v string) predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.FieldGT(FieldSecret, v))
|
||||
}
|
||||
|
||||
// SecretGTE applies the GTE predicate on the "secret" field.
|
||||
func SecretGTE(v string) predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.FieldGTE(FieldSecret, v))
|
||||
}
|
||||
|
||||
// SecretLT applies the LT predicate on the "secret" field.
|
||||
func SecretLT(v string) predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.FieldLT(FieldSecret, v))
|
||||
}
|
||||
|
||||
// SecretLTE applies the LTE predicate on the "secret" field.
|
||||
func SecretLTE(v string) predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.FieldLTE(FieldSecret, v))
|
||||
}
|
||||
|
||||
// SecretContains applies the Contains predicate on the "secret" field.
|
||||
func SecretContains(v string) predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.FieldContains(FieldSecret, v))
|
||||
}
|
||||
|
||||
// SecretHasPrefix applies the HasPrefix predicate on the "secret" field.
|
||||
func SecretHasPrefix(v string) predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.FieldHasPrefix(FieldSecret, v))
|
||||
}
|
||||
|
||||
// SecretHasSuffix applies the HasSuffix predicate on the "secret" field.
|
||||
func SecretHasSuffix(v string) predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.FieldHasSuffix(FieldSecret, v))
|
||||
}
|
||||
|
||||
// SecretEqualFold applies the EqualFold predicate on the "secret" field.
|
||||
func SecretEqualFold(v string) predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.FieldEqualFold(FieldSecret, v))
|
||||
}
|
||||
|
||||
// SecretContainsFold applies the ContainsFold predicate on the "secret" field.
|
||||
func SecretContainsFold(v string) predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.FieldContainsFold(FieldSecret, v))
|
||||
}
|
||||
|
||||
// NameEQ applies the EQ predicate on the "name" field.
|
||||
func NameEQ(v string) predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.FieldEQ(FieldName, v))
|
||||
}
|
||||
|
||||
// NameNEQ applies the NEQ predicate on the "name" field.
|
||||
func NameNEQ(v string) predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.FieldNEQ(FieldName, v))
|
||||
}
|
||||
|
||||
// NameIn applies the In predicate on the "name" field.
|
||||
func NameIn(vs ...string) predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.FieldIn(FieldName, vs...))
|
||||
}
|
||||
|
||||
// NameNotIn applies the NotIn predicate on the "name" field.
|
||||
func NameNotIn(vs ...string) predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.FieldNotIn(FieldName, vs...))
|
||||
}
|
||||
|
||||
// NameGT applies the GT predicate on the "name" field.
|
||||
func NameGT(v string) predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.FieldGT(FieldName, v))
|
||||
}
|
||||
|
||||
// NameGTE applies the GTE predicate on the "name" field.
|
||||
func NameGTE(v string) predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.FieldGTE(FieldName, v))
|
||||
}
|
||||
|
||||
// NameLT applies the LT predicate on the "name" field.
|
||||
func NameLT(v string) predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.FieldLT(FieldName, v))
|
||||
}
|
||||
|
||||
// NameLTE applies the LTE predicate on the "name" field.
|
||||
func NameLTE(v string) predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.FieldLTE(FieldName, v))
|
||||
}
|
||||
|
||||
// NameContains applies the Contains predicate on the "name" field.
|
||||
func NameContains(v string) predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.FieldContains(FieldName, v))
|
||||
}
|
||||
|
||||
// NameHasPrefix applies the HasPrefix predicate on the "name" field.
|
||||
func NameHasPrefix(v string) predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.FieldHasPrefix(FieldName, v))
|
||||
}
|
||||
|
||||
// NameHasSuffix applies the HasSuffix predicate on the "name" field.
|
||||
func NameHasSuffix(v string) predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.FieldHasSuffix(FieldName, v))
|
||||
}
|
||||
|
||||
// NameEqualFold applies the EqualFold predicate on the "name" field.
|
||||
func NameEqualFold(v string) predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.FieldEqualFold(FieldName, v))
|
||||
}
|
||||
|
||||
// NameContainsFold applies the ContainsFold predicate on the "name" field.
|
||||
func NameContainsFold(v string) predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.FieldContainsFold(FieldName, v))
|
||||
}
|
||||
|
||||
// HomepageURLEQ applies the EQ predicate on the "homepage_url" field.
|
||||
func HomepageURLEQ(v string) predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.FieldEQ(FieldHomepageURL, v))
|
||||
}
|
||||
|
||||
// HomepageURLNEQ applies the NEQ predicate on the "homepage_url" field.
|
||||
func HomepageURLNEQ(v string) predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.FieldNEQ(FieldHomepageURL, v))
|
||||
}
|
||||
|
||||
// HomepageURLIn applies the In predicate on the "homepage_url" field.
|
||||
func HomepageURLIn(vs ...string) predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.FieldIn(FieldHomepageURL, vs...))
|
||||
}
|
||||
|
||||
// HomepageURLNotIn applies the NotIn predicate on the "homepage_url" field.
|
||||
func HomepageURLNotIn(vs ...string) predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.FieldNotIn(FieldHomepageURL, vs...))
|
||||
}
|
||||
|
||||
// HomepageURLGT applies the GT predicate on the "homepage_url" field.
|
||||
func HomepageURLGT(v string) predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.FieldGT(FieldHomepageURL, v))
|
||||
}
|
||||
|
||||
// HomepageURLGTE applies the GTE predicate on the "homepage_url" field.
|
||||
func HomepageURLGTE(v string) predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.FieldGTE(FieldHomepageURL, v))
|
||||
}
|
||||
|
||||
// HomepageURLLT applies the LT predicate on the "homepage_url" field.
|
||||
func HomepageURLLT(v string) predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.FieldLT(FieldHomepageURL, v))
|
||||
}
|
||||
|
||||
// HomepageURLLTE applies the LTE predicate on the "homepage_url" field.
|
||||
func HomepageURLLTE(v string) predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.FieldLTE(FieldHomepageURL, v))
|
||||
}
|
||||
|
||||
// HomepageURLContains applies the Contains predicate on the "homepage_url" field.
|
||||
func HomepageURLContains(v string) predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.FieldContains(FieldHomepageURL, v))
|
||||
}
|
||||
|
||||
// HomepageURLHasPrefix applies the HasPrefix predicate on the "homepage_url" field.
|
||||
func HomepageURLHasPrefix(v string) predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.FieldHasPrefix(FieldHomepageURL, v))
|
||||
}
|
||||
|
||||
// HomepageURLHasSuffix applies the HasSuffix predicate on the "homepage_url" field.
|
||||
func HomepageURLHasSuffix(v string) predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.FieldHasSuffix(FieldHomepageURL, v))
|
||||
}
|
||||
|
||||
// HomepageURLIsNil applies the IsNil predicate on the "homepage_url" field.
|
||||
func HomepageURLIsNil() predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.FieldIsNull(FieldHomepageURL))
|
||||
}
|
||||
|
||||
// HomepageURLNotNil applies the NotNil predicate on the "homepage_url" field.
|
||||
func HomepageURLNotNil() predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.FieldNotNull(FieldHomepageURL))
|
||||
}
|
||||
|
||||
// HomepageURLEqualFold applies the EqualFold predicate on the "homepage_url" field.
|
||||
func HomepageURLEqualFold(v string) predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.FieldEqualFold(FieldHomepageURL, v))
|
||||
}
|
||||
|
||||
// HomepageURLContainsFold applies the ContainsFold predicate on the "homepage_url" field.
|
||||
func HomepageURLContainsFold(v string) predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.FieldContainsFold(FieldHomepageURL, v))
|
||||
}
|
||||
|
||||
// IsEnabledEQ applies the EQ predicate on the "is_enabled" field.
|
||||
func IsEnabledEQ(v bool) predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.FieldEQ(FieldIsEnabled, v))
|
||||
}
|
||||
|
||||
// IsEnabledNEQ applies the NEQ predicate on the "is_enabled" field.
|
||||
func IsEnabledNEQ(v bool) predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.FieldNEQ(FieldIsEnabled, v))
|
||||
}
|
||||
|
||||
// HasGrants applies the HasEdge predicate on the "grants" edge.
|
||||
func HasGrants() predicate.OAuthClient {
|
||||
return predicate.OAuthClient(func(s *sql.Selector) {
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2M, false, GrantsTable, GrantsColumn),
|
||||
)
|
||||
sqlgraph.HasNeighbors(s, step)
|
||||
})
|
||||
}
|
||||
|
||||
// HasGrantsWith applies the HasEdge predicate on the "grants" edge with a given conditions (other predicates).
|
||||
func HasGrantsWith(preds ...predicate.OAuthGrant) predicate.OAuthClient {
|
||||
return predicate.OAuthClient(func(s *sql.Selector) {
|
||||
step := newGrantsStep()
|
||||
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
|
||||
for _, p := range preds {
|
||||
p(s)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// And groups predicates with the AND operator between them.
|
||||
func And(predicates ...predicate.OAuthClient) predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.AndPredicates(predicates...))
|
||||
}
|
||||
|
||||
// Or groups predicates with the OR operator between them.
|
||||
func Or(predicates ...predicate.OAuthClient) predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.OrPredicates(predicates...))
|
||||
}
|
||||
|
||||
// Not applies the not operator on the given predicate.
|
||||
func Not(p predicate.OAuthClient) predicate.OAuthClient {
|
||||
return predicate.OAuthClient(sql.NotPredicates(p))
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,88 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
"github.com/cloudreve/Cloudreve/v4/ent/oauthclient"
|
||||
"github.com/cloudreve/Cloudreve/v4/ent/predicate"
|
||||
)
|
||||
|
||||
// OAuthClientDelete is the builder for deleting a OAuthClient entity.
|
||||
type OAuthClientDelete struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *OAuthClientMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the OAuthClientDelete builder.
|
||||
func (ocd *OAuthClientDelete) Where(ps ...predicate.OAuthClient) *OAuthClientDelete {
|
||||
ocd.mutation.Where(ps...)
|
||||
return ocd
|
||||
}
|
||||
|
||||
// Exec executes the deletion query and returns how many vertices were deleted.
|
||||
func (ocd *OAuthClientDelete) Exec(ctx context.Context) (int, error) {
|
||||
return withHooks(ctx, ocd.sqlExec, ocd.mutation, ocd.hooks)
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (ocd *OAuthClientDelete) ExecX(ctx context.Context) int {
|
||||
n, err := ocd.Exec(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func (ocd *OAuthClientDelete) sqlExec(ctx context.Context) (int, error) {
|
||||
_spec := sqlgraph.NewDeleteSpec(oauthclient.Table, sqlgraph.NewFieldSpec(oauthclient.FieldID, field.TypeInt))
|
||||
if ps := ocd.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
affected, err := sqlgraph.DeleteNodes(ctx, ocd.driver, _spec)
|
||||
if err != nil && sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
ocd.mutation.done = true
|
||||
return affected, err
|
||||
}
|
||||
|
||||
// OAuthClientDeleteOne is the builder for deleting a single OAuthClient entity.
|
||||
type OAuthClientDeleteOne struct {
|
||||
ocd *OAuthClientDelete
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the OAuthClientDelete builder.
|
||||
func (ocdo *OAuthClientDeleteOne) Where(ps ...predicate.OAuthClient) *OAuthClientDeleteOne {
|
||||
ocdo.ocd.mutation.Where(ps...)
|
||||
return ocdo
|
||||
}
|
||||
|
||||
// Exec executes the deletion query.
|
||||
func (ocdo *OAuthClientDeleteOne) Exec(ctx context.Context) error {
|
||||
n, err := ocdo.ocd.Exec(ctx)
|
||||
switch {
|
||||
case err != nil:
|
||||
return err
|
||||
case n == 0:
|
||||
return &NotFoundError{oauthclient.Label}
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (ocdo *OAuthClientDeleteOne) ExecX(ctx context.Context) {
|
||||
if err := ocdo.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,605 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql/driver"
|
||||
"fmt"
|
||||
"math"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
"github.com/cloudreve/Cloudreve/v4/ent/oauthclient"
|
||||
"github.com/cloudreve/Cloudreve/v4/ent/oauthgrant"
|
||||
"github.com/cloudreve/Cloudreve/v4/ent/predicate"
|
||||
)
|
||||
|
||||
// OAuthClientQuery is the builder for querying OAuthClient entities.
|
||||
type OAuthClientQuery struct {
|
||||
config
|
||||
ctx *QueryContext
|
||||
order []oauthclient.OrderOption
|
||||
inters []Interceptor
|
||||
predicates []predicate.OAuthClient
|
||||
withGrants *OAuthGrantQuery
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
}
|
||||
|
||||
// Where adds a new predicate for the OAuthClientQuery builder.
|
||||
func (ocq *OAuthClientQuery) Where(ps ...predicate.OAuthClient) *OAuthClientQuery {
|
||||
ocq.predicates = append(ocq.predicates, ps...)
|
||||
return ocq
|
||||
}
|
||||
|
||||
// Limit the number of records to be returned by this query.
|
||||
func (ocq *OAuthClientQuery) Limit(limit int) *OAuthClientQuery {
|
||||
ocq.ctx.Limit = &limit
|
||||
return ocq
|
||||
}
|
||||
|
||||
// Offset to start from.
|
||||
func (ocq *OAuthClientQuery) Offset(offset int) *OAuthClientQuery {
|
||||
ocq.ctx.Offset = &offset
|
||||
return ocq
|
||||
}
|
||||
|
||||
// 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 (ocq *OAuthClientQuery) Unique(unique bool) *OAuthClientQuery {
|
||||
ocq.ctx.Unique = &unique
|
||||
return ocq
|
||||
}
|
||||
|
||||
// Order specifies how the records should be ordered.
|
||||
func (ocq *OAuthClientQuery) Order(o ...oauthclient.OrderOption) *OAuthClientQuery {
|
||||
ocq.order = append(ocq.order, o...)
|
||||
return ocq
|
||||
}
|
||||
|
||||
// QueryGrants chains the current query on the "grants" edge.
|
||||
func (ocq *OAuthClientQuery) QueryGrants() *OAuthGrantQuery {
|
||||
query := (&OAuthGrantClient{config: ocq.config}).Query()
|
||||
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||||
if err := ocq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
selector := ocq.sqlQuery(ctx)
|
||||
if err := selector.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(oauthclient.Table, oauthclient.FieldID, selector),
|
||||
sqlgraph.To(oauthgrant.Table, oauthgrant.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2M, false, oauthclient.GrantsTable, oauthclient.GrantsColumn),
|
||||
)
|
||||
fromU = sqlgraph.SetNeighbors(ocq.driver.Dialect(), step)
|
||||
return fromU, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// First returns the first OAuthClient entity from the query.
|
||||
// Returns a *NotFoundError when no OAuthClient was found.
|
||||
func (ocq *OAuthClientQuery) First(ctx context.Context) (*OAuthClient, error) {
|
||||
nodes, err := ocq.Limit(1).All(setContextOp(ctx, ocq.ctx, "First"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(nodes) == 0 {
|
||||
return nil, &NotFoundError{oauthclient.Label}
|
||||
}
|
||||
return nodes[0], nil
|
||||
}
|
||||
|
||||
// FirstX is like First, but panics if an error occurs.
|
||||
func (ocq *OAuthClientQuery) FirstX(ctx context.Context) *OAuthClient {
|
||||
node, err := ocq.First(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// FirstID returns the first OAuthClient ID from the query.
|
||||
// Returns a *NotFoundError when no OAuthClient ID was found.
|
||||
func (ocq *OAuthClientQuery) FirstID(ctx context.Context) (id int, err error) {
|
||||
var ids []int
|
||||
if ids, err = ocq.Limit(1).IDs(setContextOp(ctx, ocq.ctx, "FirstID")); err != nil {
|
||||
return
|
||||
}
|
||||
if len(ids) == 0 {
|
||||
err = &NotFoundError{oauthclient.Label}
|
||||
return
|
||||
}
|
||||
return ids[0], nil
|
||||
}
|
||||
|
||||
// FirstIDX is like FirstID, but panics if an error occurs.
|
||||
func (ocq *OAuthClientQuery) FirstIDX(ctx context.Context) int {
|
||||
id, err := ocq.FirstID(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// Only returns a single OAuthClient entity found by the query, ensuring it only returns one.
|
||||
// Returns a *NotSingularError when more than one OAuthClient entity is found.
|
||||
// Returns a *NotFoundError when no OAuthClient entities are found.
|
||||
func (ocq *OAuthClientQuery) Only(ctx context.Context) (*OAuthClient, error) {
|
||||
nodes, err := ocq.Limit(2).All(setContextOp(ctx, ocq.ctx, "Only"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
switch len(nodes) {
|
||||
case 1:
|
||||
return nodes[0], nil
|
||||
case 0:
|
||||
return nil, &NotFoundError{oauthclient.Label}
|
||||
default:
|
||||
return nil, &NotSingularError{oauthclient.Label}
|
||||
}
|
||||
}
|
||||
|
||||
// OnlyX is like Only, but panics if an error occurs.
|
||||
func (ocq *OAuthClientQuery) OnlyX(ctx context.Context) *OAuthClient {
|
||||
node, err := ocq.Only(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// OnlyID is like Only, but returns the only OAuthClient ID in the query.
|
||||
// Returns a *NotSingularError when more than one OAuthClient ID is found.
|
||||
// Returns a *NotFoundError when no entities are found.
|
||||
func (ocq *OAuthClientQuery) OnlyID(ctx context.Context) (id int, err error) {
|
||||
var ids []int
|
||||
if ids, err = ocq.Limit(2).IDs(setContextOp(ctx, ocq.ctx, "OnlyID")); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(ids) {
|
||||
case 1:
|
||||
id = ids[0]
|
||||
case 0:
|
||||
err = &NotFoundError{oauthclient.Label}
|
||||
default:
|
||||
err = &NotSingularError{oauthclient.Label}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// OnlyIDX is like OnlyID, but panics if an error occurs.
|
||||
func (ocq *OAuthClientQuery) OnlyIDX(ctx context.Context) int {
|
||||
id, err := ocq.OnlyID(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// All executes the query and returns a list of OAuthClients.
|
||||
func (ocq *OAuthClientQuery) All(ctx context.Context) ([]*OAuthClient, error) {
|
||||
ctx = setContextOp(ctx, ocq.ctx, "All")
|
||||
if err := ocq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
qr := querierAll[[]*OAuthClient, *OAuthClientQuery]()
|
||||
return withInterceptors[[]*OAuthClient](ctx, ocq, qr, ocq.inters)
|
||||
}
|
||||
|
||||
// AllX is like All, but panics if an error occurs.
|
||||
func (ocq *OAuthClientQuery) AllX(ctx context.Context) []*OAuthClient {
|
||||
nodes, err := ocq.All(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return nodes
|
||||
}
|
||||
|
||||
// IDs executes the query and returns a list of OAuthClient IDs.
|
||||
func (ocq *OAuthClientQuery) IDs(ctx context.Context) (ids []int, err error) {
|
||||
if ocq.ctx.Unique == nil && ocq.path != nil {
|
||||
ocq.Unique(true)
|
||||
}
|
||||
ctx = setContextOp(ctx, ocq.ctx, "IDs")
|
||||
if err = ocq.Select(oauthclient.FieldID).Scan(ctx, &ids); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
// IDsX is like IDs, but panics if an error occurs.
|
||||
func (ocq *OAuthClientQuery) IDsX(ctx context.Context) []int {
|
||||
ids, err := ocq.IDs(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return ids
|
||||
}
|
||||
|
||||
// Count returns the count of the given query.
|
||||
func (ocq *OAuthClientQuery) Count(ctx context.Context) (int, error) {
|
||||
ctx = setContextOp(ctx, ocq.ctx, "Count")
|
||||
if err := ocq.prepareQuery(ctx); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return withInterceptors[int](ctx, ocq, querierCount[*OAuthClientQuery](), ocq.inters)
|
||||
}
|
||||
|
||||
// CountX is like Count, but panics if an error occurs.
|
||||
func (ocq *OAuthClientQuery) CountX(ctx context.Context) int {
|
||||
count, err := ocq.Count(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
||||
// Exist returns true if the query has elements in the graph.
|
||||
func (ocq *OAuthClientQuery) Exist(ctx context.Context) (bool, error) {
|
||||
ctx = setContextOp(ctx, ocq.ctx, "Exist")
|
||||
switch _, err := ocq.FirstID(ctx); {
|
||||
case IsNotFound(err):
|
||||
return false, nil
|
||||
case err != nil:
|
||||
return false, fmt.Errorf("ent: check existence: %w", err)
|
||||
default:
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
|
||||
// ExistX is like Exist, but panics if an error occurs.
|
||||
func (ocq *OAuthClientQuery) ExistX(ctx context.Context) bool {
|
||||
exist, err := ocq.Exist(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return exist
|
||||
}
|
||||
|
||||
// Clone returns a duplicate of the OAuthClientQuery builder, including all associated steps. It can be
|
||||
// used to prepare common query builders and use them differently after the clone is made.
|
||||
func (ocq *OAuthClientQuery) Clone() *OAuthClientQuery {
|
||||
if ocq == nil {
|
||||
return nil
|
||||
}
|
||||
return &OAuthClientQuery{
|
||||
config: ocq.config,
|
||||
ctx: ocq.ctx.Clone(),
|
||||
order: append([]oauthclient.OrderOption{}, ocq.order...),
|
||||
inters: append([]Interceptor{}, ocq.inters...),
|
||||
predicates: append([]predicate.OAuthClient{}, ocq.predicates...),
|
||||
withGrants: ocq.withGrants.Clone(),
|
||||
// clone intermediate query.
|
||||
sql: ocq.sql.Clone(),
|
||||
path: ocq.path,
|
||||
}
|
||||
}
|
||||
|
||||
// WithGrants tells the query-builder to eager-load the nodes that are connected to
|
||||
// the "grants" edge. The optional arguments are used to configure the query builder of the edge.
|
||||
func (ocq *OAuthClientQuery) WithGrants(opts ...func(*OAuthGrantQuery)) *OAuthClientQuery {
|
||||
query := (&OAuthGrantClient{config: ocq.config}).Query()
|
||||
for _, opt := range opts {
|
||||
opt(query)
|
||||
}
|
||||
ocq.withGrants = query
|
||||
return ocq
|
||||
}
|
||||
|
||||
// GroupBy is used to group vertices by one or more fields/columns.
|
||||
// It is often used with aggregate functions, like: count, max, mean, min, sum.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// var v []struct {
|
||||
// CreatedAt time.Time `json:"created_at,omitempty"`
|
||||
// Count int `json:"count,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.OAuthClient.Query().
|
||||
// GroupBy(oauthclient.FieldCreatedAt).
|
||||
// Aggregate(ent.Count()).
|
||||
// Scan(ctx, &v)
|
||||
func (ocq *OAuthClientQuery) GroupBy(field string, fields ...string) *OAuthClientGroupBy {
|
||||
ocq.ctx.Fields = append([]string{field}, fields...)
|
||||
grbuild := &OAuthClientGroupBy{build: ocq}
|
||||
grbuild.flds = &ocq.ctx.Fields
|
||||
grbuild.label = oauthclient.Label
|
||||
grbuild.scan = grbuild.Scan
|
||||
return grbuild
|
||||
}
|
||||
|
||||
// Select allows the selection one or more fields/columns for the given query,
|
||||
// instead of selecting all fields in the entity.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// var v []struct {
|
||||
// CreatedAt time.Time `json:"created_at,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.OAuthClient.Query().
|
||||
// Select(oauthclient.FieldCreatedAt).
|
||||
// Scan(ctx, &v)
|
||||
func (ocq *OAuthClientQuery) Select(fields ...string) *OAuthClientSelect {
|
||||
ocq.ctx.Fields = append(ocq.ctx.Fields, fields...)
|
||||
sbuild := &OAuthClientSelect{OAuthClientQuery: ocq}
|
||||
sbuild.label = oauthclient.Label
|
||||
sbuild.flds, sbuild.scan = &ocq.ctx.Fields, sbuild.Scan
|
||||
return sbuild
|
||||
}
|
||||
|
||||
// Aggregate returns a OAuthClientSelect configured with the given aggregations.
|
||||
func (ocq *OAuthClientQuery) Aggregate(fns ...AggregateFunc) *OAuthClientSelect {
|
||||
return ocq.Select().Aggregate(fns...)
|
||||
}
|
||||
|
||||
func (ocq *OAuthClientQuery) prepareQuery(ctx context.Context) error {
|
||||
for _, inter := range ocq.inters {
|
||||
if inter == nil {
|
||||
return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)")
|
||||
}
|
||||
if trv, ok := inter.(Traverser); ok {
|
||||
if err := trv.Traverse(ctx, ocq); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, f := range ocq.ctx.Fields {
|
||||
if !oauthclient.ValidColumn(f) {
|
||||
return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||
}
|
||||
}
|
||||
if ocq.path != nil {
|
||||
prev, err := ocq.path(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
ocq.sql = prev
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ocq *OAuthClientQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*OAuthClient, error) {
|
||||
var (
|
||||
nodes = []*OAuthClient{}
|
||||
_spec = ocq.querySpec()
|
||||
loadedTypes = [1]bool{
|
||||
ocq.withGrants != nil,
|
||||
}
|
||||
)
|
||||
_spec.ScanValues = func(columns []string) ([]any, error) {
|
||||
return (*OAuthClient).scanValues(nil, columns)
|
||||
}
|
||||
_spec.Assign = func(columns []string, values []any) error {
|
||||
node := &OAuthClient{config: ocq.config}
|
||||
nodes = append(nodes, node)
|
||||
node.Edges.loadedTypes = loadedTypes
|
||||
return node.assignValues(columns, values)
|
||||
}
|
||||
for i := range hooks {
|
||||
hooks[i](ctx, _spec)
|
||||
}
|
||||
if err := sqlgraph.QueryNodes(ctx, ocq.driver, _spec); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(nodes) == 0 {
|
||||
return nodes, nil
|
||||
}
|
||||
if query := ocq.withGrants; query != nil {
|
||||
if err := ocq.loadGrants(ctx, query, nodes,
|
||||
func(n *OAuthClient) { n.Edges.Grants = []*OAuthGrant{} },
|
||||
func(n *OAuthClient, e *OAuthGrant) { n.Edges.Grants = append(n.Edges.Grants, e) }); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
func (ocq *OAuthClientQuery) loadGrants(ctx context.Context, query *OAuthGrantQuery, nodes []*OAuthClient, init func(*OAuthClient), assign func(*OAuthClient, *OAuthGrant)) error {
|
||||
fks := make([]driver.Value, 0, len(nodes))
|
||||
nodeids := make(map[int]*OAuthClient)
|
||||
for i := range nodes {
|
||||
fks = append(fks, nodes[i].ID)
|
||||
nodeids[nodes[i].ID] = nodes[i]
|
||||
if init != nil {
|
||||
init(nodes[i])
|
||||
}
|
||||
}
|
||||
if len(query.ctx.Fields) > 0 {
|
||||
query.ctx.AppendFieldOnce(oauthgrant.FieldClientID)
|
||||
}
|
||||
query.Where(predicate.OAuthGrant(func(s *sql.Selector) {
|
||||
s.Where(sql.InValues(s.C(oauthclient.GrantsColumn), fks...))
|
||||
}))
|
||||
neighbors, err := query.All(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, n := range neighbors {
|
||||
fk := n.ClientID
|
||||
node, ok := nodeids[fk]
|
||||
if !ok {
|
||||
return fmt.Errorf(`unexpected referenced foreign-key "client_id" returned %v for node %v`, fk, n.ID)
|
||||
}
|
||||
assign(node, n)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ocq *OAuthClientQuery) sqlCount(ctx context.Context) (int, error) {
|
||||
_spec := ocq.querySpec()
|
||||
_spec.Node.Columns = ocq.ctx.Fields
|
||||
if len(ocq.ctx.Fields) > 0 {
|
||||
_spec.Unique = ocq.ctx.Unique != nil && *ocq.ctx.Unique
|
||||
}
|
||||
return sqlgraph.CountNodes(ctx, ocq.driver, _spec)
|
||||
}
|
||||
|
||||
func (ocq *OAuthClientQuery) querySpec() *sqlgraph.QuerySpec {
|
||||
_spec := sqlgraph.NewQuerySpec(oauthclient.Table, oauthclient.Columns, sqlgraph.NewFieldSpec(oauthclient.FieldID, field.TypeInt))
|
||||
_spec.From = ocq.sql
|
||||
if unique := ocq.ctx.Unique; unique != nil {
|
||||
_spec.Unique = *unique
|
||||
} else if ocq.path != nil {
|
||||
_spec.Unique = true
|
||||
}
|
||||
if fields := ocq.ctx.Fields; len(fields) > 0 {
|
||||
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, oauthclient.FieldID)
|
||||
for i := range fields {
|
||||
if fields[i] != oauthclient.FieldID {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
if ps := ocq.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if limit := ocq.ctx.Limit; limit != nil {
|
||||
_spec.Limit = *limit
|
||||
}
|
||||
if offset := ocq.ctx.Offset; offset != nil {
|
||||
_spec.Offset = *offset
|
||||
}
|
||||
if ps := ocq.order; len(ps) > 0 {
|
||||
_spec.Order = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
return _spec
|
||||
}
|
||||
|
||||
func (ocq *OAuthClientQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
||||
builder := sql.Dialect(ocq.driver.Dialect())
|
||||
t1 := builder.Table(oauthclient.Table)
|
||||
columns := ocq.ctx.Fields
|
||||
if len(columns) == 0 {
|
||||
columns = oauthclient.Columns
|
||||
}
|
||||
selector := builder.Select(t1.Columns(columns...)...).From(t1)
|
||||
if ocq.sql != nil {
|
||||
selector = ocq.sql
|
||||
selector.Select(selector.Columns(columns...)...)
|
||||
}
|
||||
if ocq.ctx.Unique != nil && *ocq.ctx.Unique {
|
||||
selector.Distinct()
|
||||
}
|
||||
for _, p := range ocq.predicates {
|
||||
p(selector)
|
||||
}
|
||||
for _, p := range ocq.order {
|
||||
p(selector)
|
||||
}
|
||||
if offset := ocq.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 := ocq.ctx.Limit; limit != nil {
|
||||
selector.Limit(*limit)
|
||||
}
|
||||
return selector
|
||||
}
|
||||
|
||||
// OAuthClientGroupBy is the group-by builder for OAuthClient entities.
|
||||
type OAuthClientGroupBy struct {
|
||||
selector
|
||||
build *OAuthClientQuery
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the group-by query.
|
||||
func (ocgb *OAuthClientGroupBy) Aggregate(fns ...AggregateFunc) *OAuthClientGroupBy {
|
||||
ocgb.fns = append(ocgb.fns, fns...)
|
||||
return ocgb
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (ocgb *OAuthClientGroupBy) Scan(ctx context.Context, v any) error {
|
||||
ctx = setContextOp(ctx, ocgb.build.ctx, "GroupBy")
|
||||
if err := ocgb.build.prepareQuery(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return scanWithInterceptors[*OAuthClientQuery, *OAuthClientGroupBy](ctx, ocgb.build, ocgb, ocgb.build.inters, v)
|
||||
}
|
||||
|
||||
func (ocgb *OAuthClientGroupBy) sqlScan(ctx context.Context, root *OAuthClientQuery, v any) error {
|
||||
selector := root.sqlQuery(ctx).Select()
|
||||
aggregation := make([]string, 0, len(ocgb.fns))
|
||||
for _, fn := range ocgb.fns {
|
||||
aggregation = append(aggregation, fn(selector))
|
||||
}
|
||||
if len(selector.SelectedColumns()) == 0 {
|
||||
columns := make([]string, 0, len(*ocgb.flds)+len(ocgb.fns))
|
||||
for _, f := range *ocgb.flds {
|
||||
columns = append(columns, selector.C(f))
|
||||
}
|
||||
columns = append(columns, aggregation...)
|
||||
selector.Select(columns...)
|
||||
}
|
||||
selector.GroupBy(selector.Columns(*ocgb.flds...)...)
|
||||
if err := selector.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
rows := &sql.Rows{}
|
||||
query, args := selector.Query()
|
||||
if err := ocgb.build.driver.Query(ctx, query, args, rows); err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
return sql.ScanSlice(rows, v)
|
||||
}
|
||||
|
||||
// OAuthClientSelect is the builder for selecting fields of OAuthClient entities.
|
||||
type OAuthClientSelect struct {
|
||||
*OAuthClientQuery
|
||||
selector
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the selector query.
|
||||
func (ocs *OAuthClientSelect) Aggregate(fns ...AggregateFunc) *OAuthClientSelect {
|
||||
ocs.fns = append(ocs.fns, fns...)
|
||||
return ocs
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (ocs *OAuthClientSelect) Scan(ctx context.Context, v any) error {
|
||||
ctx = setContextOp(ctx, ocs.ctx, "Select")
|
||||
if err := ocs.prepareQuery(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return scanWithInterceptors[*OAuthClientQuery, *OAuthClientSelect](ctx, ocs.OAuthClientQuery, ocs, ocs.inters, v)
|
||||
}
|
||||
|
||||
func (ocs *OAuthClientSelect) sqlScan(ctx context.Context, root *OAuthClientQuery, v any) error {
|
||||
selector := root.sqlQuery(ctx)
|
||||
aggregation := make([]string, 0, len(ocs.fns))
|
||||
for _, fn := range ocs.fns {
|
||||
aggregation = append(aggregation, fn(selector))
|
||||
}
|
||||
switch n := len(*ocs.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 := selector.Query()
|
||||
if err := ocs.driver.Query(ctx, query, args, rows); err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
return sql.ScanSlice(rows, v)
|
||||
}
|
||||
@ -0,0 +1,783 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/dialect/sql/sqljson"
|
||||
"entgo.io/ent/schema/field"
|
||||
"github.com/cloudreve/Cloudreve/v4/ent/oauthclient"
|
||||
"github.com/cloudreve/Cloudreve/v4/ent/oauthgrant"
|
||||
"github.com/cloudreve/Cloudreve/v4/ent/predicate"
|
||||
"github.com/cloudreve/Cloudreve/v4/inventory/types"
|
||||
)
|
||||
|
||||
// OAuthClientUpdate is the builder for updating OAuthClient entities.
|
||||
type OAuthClientUpdate struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *OAuthClientMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the OAuthClientUpdate builder.
|
||||
func (ocu *OAuthClientUpdate) Where(ps ...predicate.OAuthClient) *OAuthClientUpdate {
|
||||
ocu.mutation.Where(ps...)
|
||||
return ocu
|
||||
}
|
||||
|
||||
// SetUpdatedAt sets the "updated_at" field.
|
||||
func (ocu *OAuthClientUpdate) SetUpdatedAt(t time.Time) *OAuthClientUpdate {
|
||||
ocu.mutation.SetUpdatedAt(t)
|
||||
return ocu
|
||||
}
|
||||
|
||||
// SetDeletedAt sets the "deleted_at" field.
|
||||
func (ocu *OAuthClientUpdate) SetDeletedAt(t time.Time) *OAuthClientUpdate {
|
||||
ocu.mutation.SetDeletedAt(t)
|
||||
return ocu
|
||||
}
|
||||
|
||||
// SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
|
||||
func (ocu *OAuthClientUpdate) SetNillableDeletedAt(t *time.Time) *OAuthClientUpdate {
|
||||
if t != nil {
|
||||
ocu.SetDeletedAt(*t)
|
||||
}
|
||||
return ocu
|
||||
}
|
||||
|
||||
// ClearDeletedAt clears the value of the "deleted_at" field.
|
||||
func (ocu *OAuthClientUpdate) ClearDeletedAt() *OAuthClientUpdate {
|
||||
ocu.mutation.ClearDeletedAt()
|
||||
return ocu
|
||||
}
|
||||
|
||||
// SetGUID sets the "guid" field.
|
||||
func (ocu *OAuthClientUpdate) SetGUID(s string) *OAuthClientUpdate {
|
||||
ocu.mutation.SetGUID(s)
|
||||
return ocu
|
||||
}
|
||||
|
||||
// SetNillableGUID sets the "guid" field if the given value is not nil.
|
||||
func (ocu *OAuthClientUpdate) SetNillableGUID(s *string) *OAuthClientUpdate {
|
||||
if s != nil {
|
||||
ocu.SetGUID(*s)
|
||||
}
|
||||
return ocu
|
||||
}
|
||||
|
||||
// SetSecret sets the "secret" field.
|
||||
func (ocu *OAuthClientUpdate) SetSecret(s string) *OAuthClientUpdate {
|
||||
ocu.mutation.SetSecret(s)
|
||||
return ocu
|
||||
}
|
||||
|
||||
// SetNillableSecret sets the "secret" field if the given value is not nil.
|
||||
func (ocu *OAuthClientUpdate) SetNillableSecret(s *string) *OAuthClientUpdate {
|
||||
if s != nil {
|
||||
ocu.SetSecret(*s)
|
||||
}
|
||||
return ocu
|
||||
}
|
||||
|
||||
// SetName sets the "name" field.
|
||||
func (ocu *OAuthClientUpdate) SetName(s string) *OAuthClientUpdate {
|
||||
ocu.mutation.SetName(s)
|
||||
return ocu
|
||||
}
|
||||
|
||||
// SetNillableName sets the "name" field if the given value is not nil.
|
||||
func (ocu *OAuthClientUpdate) SetNillableName(s *string) *OAuthClientUpdate {
|
||||
if s != nil {
|
||||
ocu.SetName(*s)
|
||||
}
|
||||
return ocu
|
||||
}
|
||||
|
||||
// SetHomepageURL sets the "homepage_url" field.
|
||||
func (ocu *OAuthClientUpdate) SetHomepageURL(s string) *OAuthClientUpdate {
|
||||
ocu.mutation.SetHomepageURL(s)
|
||||
return ocu
|
||||
}
|
||||
|
||||
// SetNillableHomepageURL sets the "homepage_url" field if the given value is not nil.
|
||||
func (ocu *OAuthClientUpdate) SetNillableHomepageURL(s *string) *OAuthClientUpdate {
|
||||
if s != nil {
|
||||
ocu.SetHomepageURL(*s)
|
||||
}
|
||||
return ocu
|
||||
}
|
||||
|
||||
// ClearHomepageURL clears the value of the "homepage_url" field.
|
||||
func (ocu *OAuthClientUpdate) ClearHomepageURL() *OAuthClientUpdate {
|
||||
ocu.mutation.ClearHomepageURL()
|
||||
return ocu
|
||||
}
|
||||
|
||||
// SetRedirectUris sets the "redirect_uris" field.
|
||||
func (ocu *OAuthClientUpdate) SetRedirectUris(s []string) *OAuthClientUpdate {
|
||||
ocu.mutation.SetRedirectUris(s)
|
||||
return ocu
|
||||
}
|
||||
|
||||
// AppendRedirectUris appends s to the "redirect_uris" field.
|
||||
func (ocu *OAuthClientUpdate) AppendRedirectUris(s []string) *OAuthClientUpdate {
|
||||
ocu.mutation.AppendRedirectUris(s)
|
||||
return ocu
|
||||
}
|
||||
|
||||
// SetScopes sets the "scopes" field.
|
||||
func (ocu *OAuthClientUpdate) SetScopes(s []string) *OAuthClientUpdate {
|
||||
ocu.mutation.SetScopes(s)
|
||||
return ocu
|
||||
}
|
||||
|
||||
// AppendScopes appends s to the "scopes" field.
|
||||
func (ocu *OAuthClientUpdate) AppendScopes(s []string) *OAuthClientUpdate {
|
||||
ocu.mutation.AppendScopes(s)
|
||||
return ocu
|
||||
}
|
||||
|
||||
// SetProps sets the "props" field.
|
||||
func (ocu *OAuthClientUpdate) SetProps(tacp *types.OAuthClientProps) *OAuthClientUpdate {
|
||||
ocu.mutation.SetProps(tacp)
|
||||
return ocu
|
||||
}
|
||||
|
||||
// SetIsEnabled sets the "is_enabled" field.
|
||||
func (ocu *OAuthClientUpdate) SetIsEnabled(b bool) *OAuthClientUpdate {
|
||||
ocu.mutation.SetIsEnabled(b)
|
||||
return ocu
|
||||
}
|
||||
|
||||
// SetNillableIsEnabled sets the "is_enabled" field if the given value is not nil.
|
||||
func (ocu *OAuthClientUpdate) SetNillableIsEnabled(b *bool) *OAuthClientUpdate {
|
||||
if b != nil {
|
||||
ocu.SetIsEnabled(*b)
|
||||
}
|
||||
return ocu
|
||||
}
|
||||
|
||||
// AddGrantIDs adds the "grants" edge to the OAuthGrant entity by IDs.
|
||||
func (ocu *OAuthClientUpdate) AddGrantIDs(ids ...int) *OAuthClientUpdate {
|
||||
ocu.mutation.AddGrantIDs(ids...)
|
||||
return ocu
|
||||
}
|
||||
|
||||
// AddGrants adds the "grants" edges to the OAuthGrant entity.
|
||||
func (ocu *OAuthClientUpdate) AddGrants(o ...*OAuthGrant) *OAuthClientUpdate {
|
||||
ids := make([]int, len(o))
|
||||
for i := range o {
|
||||
ids[i] = o[i].ID
|
||||
}
|
||||
return ocu.AddGrantIDs(ids...)
|
||||
}
|
||||
|
||||
// Mutation returns the OAuthClientMutation object of the builder.
|
||||
func (ocu *OAuthClientUpdate) Mutation() *OAuthClientMutation {
|
||||
return ocu.mutation
|
||||
}
|
||||
|
||||
// ClearGrants clears all "grants" edges to the OAuthGrant entity.
|
||||
func (ocu *OAuthClientUpdate) ClearGrants() *OAuthClientUpdate {
|
||||
ocu.mutation.ClearGrants()
|
||||
return ocu
|
||||
}
|
||||
|
||||
// RemoveGrantIDs removes the "grants" edge to OAuthGrant entities by IDs.
|
||||
func (ocu *OAuthClientUpdate) RemoveGrantIDs(ids ...int) *OAuthClientUpdate {
|
||||
ocu.mutation.RemoveGrantIDs(ids...)
|
||||
return ocu
|
||||
}
|
||||
|
||||
// RemoveGrants removes "grants" edges to OAuthGrant entities.
|
||||
func (ocu *OAuthClientUpdate) RemoveGrants(o ...*OAuthGrant) *OAuthClientUpdate {
|
||||
ids := make([]int, len(o))
|
||||
for i := range o {
|
||||
ids[i] = o[i].ID
|
||||
}
|
||||
return ocu.RemoveGrantIDs(ids...)
|
||||
}
|
||||
|
||||
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||
func (ocu *OAuthClientUpdate) Save(ctx context.Context) (int, error) {
|
||||
if err := ocu.defaults(); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return withHooks(ctx, ocu.sqlSave, ocu.mutation, ocu.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (ocu *OAuthClientUpdate) SaveX(ctx context.Context) int {
|
||||
affected, err := ocu.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return affected
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (ocu *OAuthClientUpdate) Exec(ctx context.Context) error {
|
||||
_, err := ocu.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (ocu *OAuthClientUpdate) ExecX(ctx context.Context) {
|
||||
if err := ocu.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// defaults sets the default values of the builder before save.
|
||||
func (ocu *OAuthClientUpdate) defaults() error {
|
||||
if _, ok := ocu.mutation.UpdatedAt(); !ok {
|
||||
if oauthclient.UpdateDefaultUpdatedAt == nil {
|
||||
return fmt.Errorf("ent: uninitialized oauthclient.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
|
||||
}
|
||||
v := oauthclient.UpdateDefaultUpdatedAt()
|
||||
ocu.mutation.SetUpdatedAt(v)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (ocu *OAuthClientUpdate) check() error {
|
||||
if v, ok := ocu.mutation.GUID(); ok {
|
||||
if err := oauthclient.GUIDValidator(v); err != nil {
|
||||
return &ValidationError{Name: "guid", err: fmt.Errorf(`ent: validator failed for field "OAuthClient.guid": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := ocu.mutation.Secret(); ok {
|
||||
if err := oauthclient.SecretValidator(v); err != nil {
|
||||
return &ValidationError{Name: "secret", err: fmt.Errorf(`ent: validator failed for field "OAuthClient.secret": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := ocu.mutation.Name(); ok {
|
||||
if err := oauthclient.NameValidator(v); err != nil {
|
||||
return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "OAuthClient.name": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := ocu.mutation.HomepageURL(); ok {
|
||||
if err := oauthclient.HomepageURLValidator(v); err != nil {
|
||||
return &ValidationError{Name: "homepage_url", err: fmt.Errorf(`ent: validator failed for field "OAuthClient.homepage_url": %w`, err)}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ocu *OAuthClientUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
if err := ocu.check(); err != nil {
|
||||
return n, err
|
||||
}
|
||||
_spec := sqlgraph.NewUpdateSpec(oauthclient.Table, oauthclient.Columns, sqlgraph.NewFieldSpec(oauthclient.FieldID, field.TypeInt))
|
||||
if ps := ocu.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if value, ok := ocu.mutation.UpdatedAt(); ok {
|
||||
_spec.SetField(oauthclient.FieldUpdatedAt, field.TypeTime, value)
|
||||
}
|
||||
if value, ok := ocu.mutation.DeletedAt(); ok {
|
||||
_spec.SetField(oauthclient.FieldDeletedAt, field.TypeTime, value)
|
||||
}
|
||||
if ocu.mutation.DeletedAtCleared() {
|
||||
_spec.ClearField(oauthclient.FieldDeletedAt, field.TypeTime)
|
||||
}
|
||||
if value, ok := ocu.mutation.GUID(); ok {
|
||||
_spec.SetField(oauthclient.FieldGUID, field.TypeString, value)
|
||||
}
|
||||
if value, ok := ocu.mutation.Secret(); ok {
|
||||
_spec.SetField(oauthclient.FieldSecret, field.TypeString, value)
|
||||
}
|
||||
if value, ok := ocu.mutation.Name(); ok {
|
||||
_spec.SetField(oauthclient.FieldName, field.TypeString, value)
|
||||
}
|
||||
if value, ok := ocu.mutation.HomepageURL(); ok {
|
||||
_spec.SetField(oauthclient.FieldHomepageURL, field.TypeString, value)
|
||||
}
|
||||
if ocu.mutation.HomepageURLCleared() {
|
||||
_spec.ClearField(oauthclient.FieldHomepageURL, field.TypeString)
|
||||
}
|
||||
if value, ok := ocu.mutation.RedirectUris(); ok {
|
||||
_spec.SetField(oauthclient.FieldRedirectUris, field.TypeJSON, value)
|
||||
}
|
||||
if value, ok := ocu.mutation.AppendedRedirectUris(); ok {
|
||||
_spec.AddModifier(func(u *sql.UpdateBuilder) {
|
||||
sqljson.Append(u, oauthclient.FieldRedirectUris, value)
|
||||
})
|
||||
}
|
||||
if value, ok := ocu.mutation.Scopes(); ok {
|
||||
_spec.SetField(oauthclient.FieldScopes, field.TypeJSON, value)
|
||||
}
|
||||
if value, ok := ocu.mutation.AppendedScopes(); ok {
|
||||
_spec.AddModifier(func(u *sql.UpdateBuilder) {
|
||||
sqljson.Append(u, oauthclient.FieldScopes, value)
|
||||
})
|
||||
}
|
||||
if value, ok := ocu.mutation.Props(); ok {
|
||||
_spec.SetField(oauthclient.FieldProps, field.TypeJSON, value)
|
||||
}
|
||||
if value, ok := ocu.mutation.IsEnabled(); ok {
|
||||
_spec.SetField(oauthclient.FieldIsEnabled, field.TypeBool, value)
|
||||
}
|
||||
if ocu.mutation.GrantsCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: oauthclient.GrantsTable,
|
||||
Columns: []string{oauthclient.GrantsColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(oauthgrant.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := ocu.mutation.RemovedGrantsIDs(); len(nodes) > 0 && !ocu.mutation.GrantsCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: oauthclient.GrantsTable,
|
||||
Columns: []string{oauthclient.GrantsColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(oauthgrant.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := ocu.mutation.GrantsIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: oauthclient.GrantsTable,
|
||||
Columns: []string{oauthclient.GrantsColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(oauthgrant.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
if n, err = sqlgraph.UpdateNodes(ctx, ocu.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{oauthclient.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
ocu.mutation.done = true
|
||||
return n, nil
|
||||
}
|
||||
|
||||
// OAuthClientUpdateOne is the builder for updating a single OAuthClient entity.
|
||||
type OAuthClientUpdateOne struct {
|
||||
config
|
||||
fields []string
|
||||
hooks []Hook
|
||||
mutation *OAuthClientMutation
|
||||
}
|
||||
|
||||
// SetUpdatedAt sets the "updated_at" field.
|
||||
func (ocuo *OAuthClientUpdateOne) SetUpdatedAt(t time.Time) *OAuthClientUpdateOne {
|
||||
ocuo.mutation.SetUpdatedAt(t)
|
||||
return ocuo
|
||||
}
|
||||
|
||||
// SetDeletedAt sets the "deleted_at" field.
|
||||
func (ocuo *OAuthClientUpdateOne) SetDeletedAt(t time.Time) *OAuthClientUpdateOne {
|
||||
ocuo.mutation.SetDeletedAt(t)
|
||||
return ocuo
|
||||
}
|
||||
|
||||
// SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
|
||||
func (ocuo *OAuthClientUpdateOne) SetNillableDeletedAt(t *time.Time) *OAuthClientUpdateOne {
|
||||
if t != nil {
|
||||
ocuo.SetDeletedAt(*t)
|
||||
}
|
||||
return ocuo
|
||||
}
|
||||
|
||||
// ClearDeletedAt clears the value of the "deleted_at" field.
|
||||
func (ocuo *OAuthClientUpdateOne) ClearDeletedAt() *OAuthClientUpdateOne {
|
||||
ocuo.mutation.ClearDeletedAt()
|
||||
return ocuo
|
||||
}
|
||||
|
||||
// SetGUID sets the "guid" field.
|
||||
func (ocuo *OAuthClientUpdateOne) SetGUID(s string) *OAuthClientUpdateOne {
|
||||
ocuo.mutation.SetGUID(s)
|
||||
return ocuo
|
||||
}
|
||||
|
||||
// SetNillableGUID sets the "guid" field if the given value is not nil.
|
||||
func (ocuo *OAuthClientUpdateOne) SetNillableGUID(s *string) *OAuthClientUpdateOne {
|
||||
if s != nil {
|
||||
ocuo.SetGUID(*s)
|
||||
}
|
||||
return ocuo
|
||||
}
|
||||
|
||||
// SetSecret sets the "secret" field.
|
||||
func (ocuo *OAuthClientUpdateOne) SetSecret(s string) *OAuthClientUpdateOne {
|
||||
ocuo.mutation.SetSecret(s)
|
||||
return ocuo
|
||||
}
|
||||
|
||||
// SetNillableSecret sets the "secret" field if the given value is not nil.
|
||||
func (ocuo *OAuthClientUpdateOne) SetNillableSecret(s *string) *OAuthClientUpdateOne {
|
||||
if s != nil {
|
||||
ocuo.SetSecret(*s)
|
||||
}
|
||||
return ocuo
|
||||
}
|
||||
|
||||
// SetName sets the "name" field.
|
||||
func (ocuo *OAuthClientUpdateOne) SetName(s string) *OAuthClientUpdateOne {
|
||||
ocuo.mutation.SetName(s)
|
||||
return ocuo
|
||||
}
|
||||
|
||||
// SetNillableName sets the "name" field if the given value is not nil.
|
||||
func (ocuo *OAuthClientUpdateOne) SetNillableName(s *string) *OAuthClientUpdateOne {
|
||||
if s != nil {
|
||||
ocuo.SetName(*s)
|
||||
}
|
||||
return ocuo
|
||||
}
|
||||
|
||||
// SetHomepageURL sets the "homepage_url" field.
|
||||
func (ocuo *OAuthClientUpdateOne) SetHomepageURL(s string) *OAuthClientUpdateOne {
|
||||
ocuo.mutation.SetHomepageURL(s)
|
||||
return ocuo
|
||||
}
|
||||
|
||||
// SetNillableHomepageURL sets the "homepage_url" field if the given value is not nil.
|
||||
func (ocuo *OAuthClientUpdateOne) SetNillableHomepageURL(s *string) *OAuthClientUpdateOne {
|
||||
if s != nil {
|
||||
ocuo.SetHomepageURL(*s)
|
||||
}
|
||||
return ocuo
|
||||
}
|
||||
|
||||
// ClearHomepageURL clears the value of the "homepage_url" field.
|
||||
func (ocuo *OAuthClientUpdateOne) ClearHomepageURL() *OAuthClientUpdateOne {
|
||||
ocuo.mutation.ClearHomepageURL()
|
||||
return ocuo
|
||||
}
|
||||
|
||||
// SetRedirectUris sets the "redirect_uris" field.
|
||||
func (ocuo *OAuthClientUpdateOne) SetRedirectUris(s []string) *OAuthClientUpdateOne {
|
||||
ocuo.mutation.SetRedirectUris(s)
|
||||
return ocuo
|
||||
}
|
||||
|
||||
// AppendRedirectUris appends s to the "redirect_uris" field.
|
||||
func (ocuo *OAuthClientUpdateOne) AppendRedirectUris(s []string) *OAuthClientUpdateOne {
|
||||
ocuo.mutation.AppendRedirectUris(s)
|
||||
return ocuo
|
||||
}
|
||||
|
||||
// SetScopes sets the "scopes" field.
|
||||
func (ocuo *OAuthClientUpdateOne) SetScopes(s []string) *OAuthClientUpdateOne {
|
||||
ocuo.mutation.SetScopes(s)
|
||||
return ocuo
|
||||
}
|
||||
|
||||
// AppendScopes appends s to the "scopes" field.
|
||||
func (ocuo *OAuthClientUpdateOne) AppendScopes(s []string) *OAuthClientUpdateOne {
|
||||
ocuo.mutation.AppendScopes(s)
|
||||
return ocuo
|
||||
}
|
||||
|
||||
// SetProps sets the "props" field.
|
||||
func (ocuo *OAuthClientUpdateOne) SetProps(tacp *types.OAuthClientProps) *OAuthClientUpdateOne {
|
||||
ocuo.mutation.SetProps(tacp)
|
||||
return ocuo
|
||||
}
|
||||
|
||||
// SetIsEnabled sets the "is_enabled" field.
|
||||
func (ocuo *OAuthClientUpdateOne) SetIsEnabled(b bool) *OAuthClientUpdateOne {
|
||||
ocuo.mutation.SetIsEnabled(b)
|
||||
return ocuo
|
||||
}
|
||||
|
||||
// SetNillableIsEnabled sets the "is_enabled" field if the given value is not nil.
|
||||
func (ocuo *OAuthClientUpdateOne) SetNillableIsEnabled(b *bool) *OAuthClientUpdateOne {
|
||||
if b != nil {
|
||||
ocuo.SetIsEnabled(*b)
|
||||
}
|
||||
return ocuo
|
||||
}
|
||||
|
||||
// AddGrantIDs adds the "grants" edge to the OAuthGrant entity by IDs.
|
||||
func (ocuo *OAuthClientUpdateOne) AddGrantIDs(ids ...int) *OAuthClientUpdateOne {
|
||||
ocuo.mutation.AddGrantIDs(ids...)
|
||||
return ocuo
|
||||
}
|
||||
|
||||
// AddGrants adds the "grants" edges to the OAuthGrant entity.
|
||||
func (ocuo *OAuthClientUpdateOne) AddGrants(o ...*OAuthGrant) *OAuthClientUpdateOne {
|
||||
ids := make([]int, len(o))
|
||||
for i := range o {
|
||||
ids[i] = o[i].ID
|
||||
}
|
||||
return ocuo.AddGrantIDs(ids...)
|
||||
}
|
||||
|
||||
// Mutation returns the OAuthClientMutation object of the builder.
|
||||
func (ocuo *OAuthClientUpdateOne) Mutation() *OAuthClientMutation {
|
||||
return ocuo.mutation
|
||||
}
|
||||
|
||||
// ClearGrants clears all "grants" edges to the OAuthGrant entity.
|
||||
func (ocuo *OAuthClientUpdateOne) ClearGrants() *OAuthClientUpdateOne {
|
||||
ocuo.mutation.ClearGrants()
|
||||
return ocuo
|
||||
}
|
||||
|
||||
// RemoveGrantIDs removes the "grants" edge to OAuthGrant entities by IDs.
|
||||
func (ocuo *OAuthClientUpdateOne) RemoveGrantIDs(ids ...int) *OAuthClientUpdateOne {
|
||||
ocuo.mutation.RemoveGrantIDs(ids...)
|
||||
return ocuo
|
||||
}
|
||||
|
||||
// RemoveGrants removes "grants" edges to OAuthGrant entities.
|
||||
func (ocuo *OAuthClientUpdateOne) RemoveGrants(o ...*OAuthGrant) *OAuthClientUpdateOne {
|
||||
ids := make([]int, len(o))
|
||||
for i := range o {
|
||||
ids[i] = o[i].ID
|
||||
}
|
||||
return ocuo.RemoveGrantIDs(ids...)
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the OAuthClientUpdate builder.
|
||||
func (ocuo *OAuthClientUpdateOne) Where(ps ...predicate.OAuthClient) *OAuthClientUpdateOne {
|
||||
ocuo.mutation.Where(ps...)
|
||||
return ocuo
|
||||
}
|
||||
|
||||
// Select allows selecting one or more fields (columns) of the returned entity.
|
||||
// The default is selecting all fields defined in the entity schema.
|
||||
func (ocuo *OAuthClientUpdateOne) Select(field string, fields ...string) *OAuthClientUpdateOne {
|
||||
ocuo.fields = append([]string{field}, fields...)
|
||||
return ocuo
|
||||
}
|
||||
|
||||
// Save executes the query and returns the updated OAuthClient entity.
|
||||
func (ocuo *OAuthClientUpdateOne) Save(ctx context.Context) (*OAuthClient, error) {
|
||||
if err := ocuo.defaults(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return withHooks(ctx, ocuo.sqlSave, ocuo.mutation, ocuo.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (ocuo *OAuthClientUpdateOne) SaveX(ctx context.Context) *OAuthClient {
|
||||
node, err := ocuo.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// Exec executes the query on the entity.
|
||||
func (ocuo *OAuthClientUpdateOne) Exec(ctx context.Context) error {
|
||||
_, err := ocuo.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (ocuo *OAuthClientUpdateOne) ExecX(ctx context.Context) {
|
||||
if err := ocuo.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// defaults sets the default values of the builder before save.
|
||||
func (ocuo *OAuthClientUpdateOne) defaults() error {
|
||||
if _, ok := ocuo.mutation.UpdatedAt(); !ok {
|
||||
if oauthclient.UpdateDefaultUpdatedAt == nil {
|
||||
return fmt.Errorf("ent: uninitialized oauthclient.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
|
||||
}
|
||||
v := oauthclient.UpdateDefaultUpdatedAt()
|
||||
ocuo.mutation.SetUpdatedAt(v)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (ocuo *OAuthClientUpdateOne) check() error {
|
||||
if v, ok := ocuo.mutation.GUID(); ok {
|
||||
if err := oauthclient.GUIDValidator(v); err != nil {
|
||||
return &ValidationError{Name: "guid", err: fmt.Errorf(`ent: validator failed for field "OAuthClient.guid": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := ocuo.mutation.Secret(); ok {
|
||||
if err := oauthclient.SecretValidator(v); err != nil {
|
||||
return &ValidationError{Name: "secret", err: fmt.Errorf(`ent: validator failed for field "OAuthClient.secret": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := ocuo.mutation.Name(); ok {
|
||||
if err := oauthclient.NameValidator(v); err != nil {
|
||||
return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "OAuthClient.name": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := ocuo.mutation.HomepageURL(); ok {
|
||||
if err := oauthclient.HomepageURLValidator(v); err != nil {
|
||||
return &ValidationError{Name: "homepage_url", err: fmt.Errorf(`ent: validator failed for field "OAuthClient.homepage_url": %w`, err)}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ocuo *OAuthClientUpdateOne) sqlSave(ctx context.Context) (_node *OAuthClient, err error) {
|
||||
if err := ocuo.check(); err != nil {
|
||||
return _node, err
|
||||
}
|
||||
_spec := sqlgraph.NewUpdateSpec(oauthclient.Table, oauthclient.Columns, sqlgraph.NewFieldSpec(oauthclient.FieldID, field.TypeInt))
|
||||
id, ok := ocuo.mutation.ID()
|
||||
if !ok {
|
||||
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "OAuthClient.id" for update`)}
|
||||
}
|
||||
_spec.Node.ID.Value = id
|
||||
if fields := ocuo.fields; len(fields) > 0 {
|
||||
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, oauthclient.FieldID)
|
||||
for _, f := range fields {
|
||||
if !oauthclient.ValidColumn(f) {
|
||||
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||
}
|
||||
if f != oauthclient.FieldID {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, f)
|
||||
}
|
||||
}
|
||||
}
|
||||
if ps := ocuo.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if value, ok := ocuo.mutation.UpdatedAt(); ok {
|
||||
_spec.SetField(oauthclient.FieldUpdatedAt, field.TypeTime, value)
|
||||
}
|
||||
if value, ok := ocuo.mutation.DeletedAt(); ok {
|
||||
_spec.SetField(oauthclient.FieldDeletedAt, field.TypeTime, value)
|
||||
}
|
||||
if ocuo.mutation.DeletedAtCleared() {
|
||||
_spec.ClearField(oauthclient.FieldDeletedAt, field.TypeTime)
|
||||
}
|
||||
if value, ok := ocuo.mutation.GUID(); ok {
|
||||
_spec.SetField(oauthclient.FieldGUID, field.TypeString, value)
|
||||
}
|
||||
if value, ok := ocuo.mutation.Secret(); ok {
|
||||
_spec.SetField(oauthclient.FieldSecret, field.TypeString, value)
|
||||
}
|
||||
if value, ok := ocuo.mutation.Name(); ok {
|
||||
_spec.SetField(oauthclient.FieldName, field.TypeString, value)
|
||||
}
|
||||
if value, ok := ocuo.mutation.HomepageURL(); ok {
|
||||
_spec.SetField(oauthclient.FieldHomepageURL, field.TypeString, value)
|
||||
}
|
||||
if ocuo.mutation.HomepageURLCleared() {
|
||||
_spec.ClearField(oauthclient.FieldHomepageURL, field.TypeString)
|
||||
}
|
||||
if value, ok := ocuo.mutation.RedirectUris(); ok {
|
||||
_spec.SetField(oauthclient.FieldRedirectUris, field.TypeJSON, value)
|
||||
}
|
||||
if value, ok := ocuo.mutation.AppendedRedirectUris(); ok {
|
||||
_spec.AddModifier(func(u *sql.UpdateBuilder) {
|
||||
sqljson.Append(u, oauthclient.FieldRedirectUris, value)
|
||||
})
|
||||
}
|
||||
if value, ok := ocuo.mutation.Scopes(); ok {
|
||||
_spec.SetField(oauthclient.FieldScopes, field.TypeJSON, value)
|
||||
}
|
||||
if value, ok := ocuo.mutation.AppendedScopes(); ok {
|
||||
_spec.AddModifier(func(u *sql.UpdateBuilder) {
|
||||
sqljson.Append(u, oauthclient.FieldScopes, value)
|
||||
})
|
||||
}
|
||||
if value, ok := ocuo.mutation.Props(); ok {
|
||||
_spec.SetField(oauthclient.FieldProps, field.TypeJSON, value)
|
||||
}
|
||||
if value, ok := ocuo.mutation.IsEnabled(); ok {
|
||||
_spec.SetField(oauthclient.FieldIsEnabled, field.TypeBool, value)
|
||||
}
|
||||
if ocuo.mutation.GrantsCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: oauthclient.GrantsTable,
|
||||
Columns: []string{oauthclient.GrantsColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(oauthgrant.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := ocuo.mutation.RemovedGrantsIDs(); len(nodes) > 0 && !ocuo.mutation.GrantsCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: oauthclient.GrantsTable,
|
||||
Columns: []string{oauthclient.GrantsColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(oauthgrant.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := ocuo.mutation.GrantsIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: oauthclient.GrantsTable,
|
||||
Columns: []string{oauthclient.GrantsColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(oauthgrant.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
_node = &OAuthClient{config: ocuo.config}
|
||||
_spec.Assign = _node.assignValues
|
||||
_spec.ScanValues = _node.scanValues
|
||||
if err = sqlgraph.UpdateNode(ctx, ocuo.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{oauthclient.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
ocuo.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
@ -0,0 +1,245 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"github.com/cloudreve/Cloudreve/v4/ent/oauthclient"
|
||||
"github.com/cloudreve/Cloudreve/v4/ent/oauthgrant"
|
||||
"github.com/cloudreve/Cloudreve/v4/ent/user"
|
||||
)
|
||||
|
||||
// OAuthGrant is the model entity for the OAuthGrant schema.
|
||||
type OAuthGrant struct {
|
||||
config `json:"-"`
|
||||
// ID of the ent.
|
||||
ID int `json:"id,omitempty"`
|
||||
// CreatedAt holds the value of the "created_at" field.
|
||||
CreatedAt time.Time `json:"created_at,omitempty"`
|
||||
// UpdatedAt holds the value of the "updated_at" field.
|
||||
UpdatedAt time.Time `json:"updated_at,omitempty"`
|
||||
// DeletedAt holds the value of the "deleted_at" field.
|
||||
DeletedAt *time.Time `json:"deleted_at,omitempty"`
|
||||
// UserID holds the value of the "user_id" field.
|
||||
UserID int `json:"user_id,omitempty"`
|
||||
// ClientID holds the value of the "client_id" field.
|
||||
ClientID int `json:"client_id,omitempty"`
|
||||
// Scopes holds the value of the "scopes" field.
|
||||
Scopes []string `json:"scopes,omitempty"`
|
||||
// LastUsedAt holds the value of the "last_used_at" field.
|
||||
LastUsedAt *time.Time `json:"last_used_at,omitempty"`
|
||||
// Edges holds the relations/edges for other nodes in the graph.
|
||||
// The values are being populated by the OAuthGrantQuery when eager-loading is set.
|
||||
Edges OAuthGrantEdges `json:"edges"`
|
||||
selectValues sql.SelectValues
|
||||
}
|
||||
|
||||
// OAuthGrantEdges holds the relations/edges for other nodes in the graph.
|
||||
type OAuthGrantEdges struct {
|
||||
// User holds the value of the user edge.
|
||||
User *User `json:"user,omitempty"`
|
||||
// Client holds the value of the client edge.
|
||||
Client *OAuthClient `json:"client,omitempty"`
|
||||
// loadedTypes holds the information for reporting if a
|
||||
// type was loaded (or requested) in eager-loading or not.
|
||||
loadedTypes [2]bool
|
||||
}
|
||||
|
||||
// UserOrErr returns the User value or an error if the edge
|
||||
// was not loaded in eager-loading, or loaded but was not found.
|
||||
func (e OAuthGrantEdges) UserOrErr() (*User, error) {
|
||||
if e.loadedTypes[0] {
|
||||
if e.User == nil {
|
||||
// Edge was loaded but was not found.
|
||||
return nil, &NotFoundError{label: user.Label}
|
||||
}
|
||||
return e.User, nil
|
||||
}
|
||||
return nil, &NotLoadedError{edge: "user"}
|
||||
}
|
||||
|
||||
// ClientOrErr returns the Client value or an error if the edge
|
||||
// was not loaded in eager-loading, or loaded but was not found.
|
||||
func (e OAuthGrantEdges) ClientOrErr() (*OAuthClient, error) {
|
||||
if e.loadedTypes[1] {
|
||||
if e.Client == nil {
|
||||
// Edge was loaded but was not found.
|
||||
return nil, &NotFoundError{label: oauthclient.Label}
|
||||
}
|
||||
return e.Client, nil
|
||||
}
|
||||
return nil, &NotLoadedError{edge: "client"}
|
||||
}
|
||||
|
||||
// scanValues returns the types for scanning values from sql.Rows.
|
||||
func (*OAuthGrant) scanValues(columns []string) ([]any, error) {
|
||||
values := make([]any, len(columns))
|
||||
for i := range columns {
|
||||
switch columns[i] {
|
||||
case oauthgrant.FieldScopes:
|
||||
values[i] = new([]byte)
|
||||
case oauthgrant.FieldID, oauthgrant.FieldUserID, oauthgrant.FieldClientID:
|
||||
values[i] = new(sql.NullInt64)
|
||||
case oauthgrant.FieldCreatedAt, oauthgrant.FieldUpdatedAt, oauthgrant.FieldDeletedAt, oauthgrant.FieldLastUsedAt:
|
||||
values[i] = new(sql.NullTime)
|
||||
default:
|
||||
values[i] = new(sql.UnknownType)
|
||||
}
|
||||
}
|
||||
return values, nil
|
||||
}
|
||||
|
||||
// assignValues assigns the values that were returned from sql.Rows (after scanning)
|
||||
// to the OAuthGrant fields.
|
||||
func (og *OAuthGrant) 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)
|
||||
}
|
||||
for i := range columns {
|
||||
switch columns[i] {
|
||||
case oauthgrant.FieldID:
|
||||
value, ok := values[i].(*sql.NullInt64)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field id", value)
|
||||
}
|
||||
og.ID = int(value.Int64)
|
||||
case oauthgrant.FieldCreatedAt:
|
||||
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field created_at", values[i])
|
||||
} else if value.Valid {
|
||||
og.CreatedAt = value.Time
|
||||
}
|
||||
case oauthgrant.FieldUpdatedAt:
|
||||
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field updated_at", values[i])
|
||||
} else if value.Valid {
|
||||
og.UpdatedAt = value.Time
|
||||
}
|
||||
case oauthgrant.FieldDeletedAt:
|
||||
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field deleted_at", values[i])
|
||||
} else if value.Valid {
|
||||
og.DeletedAt = new(time.Time)
|
||||
*og.DeletedAt = value.Time
|
||||
}
|
||||
case oauthgrant.FieldUserID:
|
||||
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field user_id", values[i])
|
||||
} else if value.Valid {
|
||||
og.UserID = int(value.Int64)
|
||||
}
|
||||
case oauthgrant.FieldClientID:
|
||||
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field client_id", values[i])
|
||||
} else if value.Valid {
|
||||
og.ClientID = int(value.Int64)
|
||||
}
|
||||
case oauthgrant.FieldScopes:
|
||||
if value, ok := values[i].(*[]byte); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field scopes", values[i])
|
||||
} else if value != nil && len(*value) > 0 {
|
||||
if err := json.Unmarshal(*value, &og.Scopes); err != nil {
|
||||
return fmt.Errorf("unmarshal field scopes: %w", err)
|
||||
}
|
||||
}
|
||||
case oauthgrant.FieldLastUsedAt:
|
||||
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field last_used_at", values[i])
|
||||
} else if value.Valid {
|
||||
og.LastUsedAt = new(time.Time)
|
||||
*og.LastUsedAt = value.Time
|
||||
}
|
||||
default:
|
||||
og.selectValues.Set(columns[i], values[i])
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Value returns the ent.Value that was dynamically selected and assigned to the OAuthGrant.
|
||||
// This includes values selected through modifiers, order, etc.
|
||||
func (og *OAuthGrant) Value(name string) (ent.Value, error) {
|
||||
return og.selectValues.Get(name)
|
||||
}
|
||||
|
||||
// QueryUser queries the "user" edge of the OAuthGrant entity.
|
||||
func (og *OAuthGrant) QueryUser() *UserQuery {
|
||||
return NewOAuthGrantClient(og.config).QueryUser(og)
|
||||
}
|
||||
|
||||
// QueryClient queries the "client" edge of the OAuthGrant entity.
|
||||
func (og *OAuthGrant) QueryClient() *OAuthClientQuery {
|
||||
return NewOAuthGrantClient(og.config).QueryClient(og)
|
||||
}
|
||||
|
||||
// Update returns a builder for updating this OAuthGrant.
|
||||
// Note that you need to call OAuthGrant.Unwrap() before calling this method if this OAuthGrant
|
||||
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||
func (og *OAuthGrant) Update() *OAuthGrantUpdateOne {
|
||||
return NewOAuthGrantClient(og.config).UpdateOne(og)
|
||||
}
|
||||
|
||||
// Unwrap unwraps the OAuthGrant entity that was returned from a transaction after it was closed,
|
||||
// so that all future queries will be executed through the driver which created the transaction.
|
||||
func (og *OAuthGrant) Unwrap() *OAuthGrant {
|
||||
_tx, ok := og.config.driver.(*txDriver)
|
||||
if !ok {
|
||||
panic("ent: OAuthGrant is not a transactional entity")
|
||||
}
|
||||
og.config.driver = _tx.drv
|
||||
return og
|
||||
}
|
||||
|
||||
// String implements the fmt.Stringer.
|
||||
func (og *OAuthGrant) String() string {
|
||||
var builder strings.Builder
|
||||
builder.WriteString("OAuthGrant(")
|
||||
builder.WriteString(fmt.Sprintf("id=%v, ", og.ID))
|
||||
builder.WriteString("created_at=")
|
||||
builder.WriteString(og.CreatedAt.Format(time.ANSIC))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("updated_at=")
|
||||
builder.WriteString(og.UpdatedAt.Format(time.ANSIC))
|
||||
builder.WriteString(", ")
|
||||
if v := og.DeletedAt; v != nil {
|
||||
builder.WriteString("deleted_at=")
|
||||
builder.WriteString(v.Format(time.ANSIC))
|
||||
}
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("user_id=")
|
||||
builder.WriteString(fmt.Sprintf("%v", og.UserID))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("client_id=")
|
||||
builder.WriteString(fmt.Sprintf("%v", og.ClientID))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("scopes=")
|
||||
builder.WriteString(fmt.Sprintf("%v", og.Scopes))
|
||||
builder.WriteString(", ")
|
||||
if v := og.LastUsedAt; v != nil {
|
||||
builder.WriteString("last_used_at=")
|
||||
builder.WriteString(v.Format(time.ANSIC))
|
||||
}
|
||||
builder.WriteByte(')')
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
// SetUser manually set the edge as loaded state.
|
||||
func (e *OAuthGrant) SetUser(v *User) {
|
||||
e.Edges.User = v
|
||||
e.Edges.loadedTypes[0] = true
|
||||
}
|
||||
|
||||
// SetClient manually set the edge as loaded state.
|
||||
func (e *OAuthGrant) SetClient(v *OAuthClient) {
|
||||
e.Edges.Client = v
|
||||
e.Edges.loadedTypes[1] = true
|
||||
}
|
||||
|
||||
// OAuthGrants is a parsable slice of OAuthGrant.
|
||||
type OAuthGrants []*OAuthGrant
|
||||
@ -0,0 +1,158 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package oauthgrant
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
)
|
||||
|
||||
const (
|
||||
// Label holds the string label denoting the oauthgrant type in the database.
|
||||
Label = "oauth_grant"
|
||||
// FieldID holds the string denoting the id field in the database.
|
||||
FieldID = "id"
|
||||
// FieldCreatedAt holds the string denoting the created_at field in the database.
|
||||
FieldCreatedAt = "created_at"
|
||||
// FieldUpdatedAt holds the string denoting the updated_at field in the database.
|
||||
FieldUpdatedAt = "updated_at"
|
||||
// FieldDeletedAt holds the string denoting the deleted_at field in the database.
|
||||
FieldDeletedAt = "deleted_at"
|
||||
// FieldUserID holds the string denoting the user_id field in the database.
|
||||
FieldUserID = "user_id"
|
||||
// FieldClientID holds the string denoting the client_id field in the database.
|
||||
FieldClientID = "client_id"
|
||||
// FieldScopes holds the string denoting the scopes field in the database.
|
||||
FieldScopes = "scopes"
|
||||
// FieldLastUsedAt holds the string denoting the last_used_at field in the database.
|
||||
FieldLastUsedAt = "last_used_at"
|
||||
// EdgeUser holds the string denoting the user edge name in mutations.
|
||||
EdgeUser = "user"
|
||||
// EdgeClient holds the string denoting the client edge name in mutations.
|
||||
EdgeClient = "client"
|
||||
// Table holds the table name of the oauthgrant in the database.
|
||||
Table = "oauth_grants"
|
||||
// UserTable is the table that holds the user relation/edge.
|
||||
UserTable = "oauth_grants"
|
||||
// UserInverseTable is the table name for the User entity.
|
||||
// It exists in this package in order to avoid circular dependency with the "user" package.
|
||||
UserInverseTable = "users"
|
||||
// UserColumn is the table column denoting the user relation/edge.
|
||||
UserColumn = "user_id"
|
||||
// ClientTable is the table that holds the client relation/edge.
|
||||
ClientTable = "oauth_grants"
|
||||
// ClientInverseTable is the table name for the OAuthClient entity.
|
||||
// It exists in this package in order to avoid circular dependency with the "oauthclient" package.
|
||||
ClientInverseTable = "oauth_clients"
|
||||
// ClientColumn is the table column denoting the client relation/edge.
|
||||
ClientColumn = "client_id"
|
||||
)
|
||||
|
||||
// Columns holds all SQL columns for oauthgrant fields.
|
||||
var Columns = []string{
|
||||
FieldID,
|
||||
FieldCreatedAt,
|
||||
FieldUpdatedAt,
|
||||
FieldDeletedAt,
|
||||
FieldUserID,
|
||||
FieldClientID,
|
||||
FieldScopes,
|
||||
FieldLastUsedAt,
|
||||
}
|
||||
|
||||
// ValidColumn reports if the column name is valid (part of the table columns).
|
||||
func ValidColumn(column string) bool {
|
||||
for i := range Columns {
|
||||
if column == Columns[i] {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Note that the variables below are initialized by the runtime
|
||||
// package on the initialization of the application. Therefore,
|
||||
// it should be imported in the main as follows:
|
||||
//
|
||||
// import _ "github.com/cloudreve/Cloudreve/v4/ent/runtime"
|
||||
var (
|
||||
Hooks [1]ent.Hook
|
||||
Interceptors [1]ent.Interceptor
|
||||
// DefaultCreatedAt holds the default value on creation for the "created_at" field.
|
||||
DefaultCreatedAt func() time.Time
|
||||
// DefaultUpdatedAt holds the default value on creation for the "updated_at" field.
|
||||
DefaultUpdatedAt func() time.Time
|
||||
// UpdateDefaultUpdatedAt holds the default value on update for the "updated_at" field.
|
||||
UpdateDefaultUpdatedAt func() time.Time
|
||||
// DefaultScopes holds the default value on creation for the "scopes" field.
|
||||
DefaultScopes []string
|
||||
)
|
||||
|
||||
// OrderOption defines the ordering options for the OAuthGrant queries.
|
||||
type OrderOption func(*sql.Selector)
|
||||
|
||||
// ByID orders the results by the id field.
|
||||
func ByID(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldID, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByCreatedAt orders the results by the created_at field.
|
||||
func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldCreatedAt, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByUpdatedAt orders the results by the updated_at field.
|
||||
func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByDeletedAt orders the results by the deleted_at field.
|
||||
func ByDeletedAt(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldDeletedAt, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByUserID orders the results by the user_id field.
|
||||
func ByUserID(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldUserID, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByClientID orders the results by the client_id field.
|
||||
func ByClientID(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldClientID, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByLastUsedAt orders the results by the last_used_at field.
|
||||
func ByLastUsedAt(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldLastUsedAt, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByUserField orders the results by user field.
|
||||
func ByUserField(field string, opts ...sql.OrderTermOption) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
sqlgraph.OrderByNeighborTerms(s, newUserStep(), sql.OrderByField(field, opts...))
|
||||
}
|
||||
}
|
||||
|
||||
// ByClientField orders the results by client field.
|
||||
func ByClientField(field string, opts ...sql.OrderTermOption) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
sqlgraph.OrderByNeighborTerms(s, newClientStep(), sql.OrderByField(field, opts...))
|
||||
}
|
||||
}
|
||||
func newUserStep() *sqlgraph.Step {
|
||||
return sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.To(UserInverseTable, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, true, UserTable, UserColumn),
|
||||
)
|
||||
}
|
||||
func newClientStep() *sqlgraph.Step {
|
||||
return sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.To(ClientInverseTable, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, true, ClientTable, ClientColumn),
|
||||
)
|
||||
}
|
||||
@ -0,0 +1,367 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package oauthgrant
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"github.com/cloudreve/Cloudreve/v4/ent/predicate"
|
||||
)
|
||||
|
||||
// ID filters vertices based on their ID field.
|
||||
func ID(id int) predicate.OAuthGrant {
|
||||
return predicate.OAuthGrant(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDEQ applies the EQ predicate on the ID field.
|
||||
func IDEQ(id int) predicate.OAuthGrant {
|
||||
return predicate.OAuthGrant(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDNEQ applies the NEQ predicate on the ID field.
|
||||
func IDNEQ(id int) predicate.OAuthGrant {
|
||||
return predicate.OAuthGrant(sql.FieldNEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDIn applies the In predicate on the ID field.
|
||||
func IDIn(ids ...int) predicate.OAuthGrant {
|
||||
return predicate.OAuthGrant(sql.FieldIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDNotIn applies the NotIn predicate on the ID field.
|
||||
func IDNotIn(ids ...int) predicate.OAuthGrant {
|
||||
return predicate.OAuthGrant(sql.FieldNotIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDGT applies the GT predicate on the ID field.
|
||||
func IDGT(id int) predicate.OAuthGrant {
|
||||
return predicate.OAuthGrant(sql.FieldGT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDGTE applies the GTE predicate on the ID field.
|
||||
func IDGTE(id int) predicate.OAuthGrant {
|
||||
return predicate.OAuthGrant(sql.FieldGTE(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLT applies the LT predicate on the ID field.
|
||||
func IDLT(id int) predicate.OAuthGrant {
|
||||
return predicate.OAuthGrant(sql.FieldLT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLTE applies the LTE predicate on the ID field.
|
||||
func IDLTE(id int) predicate.OAuthGrant {
|
||||
return predicate.OAuthGrant(sql.FieldLTE(FieldID, id))
|
||||
}
|
||||
|
||||
// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ.
|
||||
func CreatedAt(v time.Time) predicate.OAuthGrant {
|
||||
return predicate.OAuthGrant(sql.FieldEQ(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// UpdatedAt applies equality check predicate on the "updated_at" field. It's identical to UpdatedAtEQ.
|
||||
func UpdatedAt(v time.Time) predicate.OAuthGrant {
|
||||
return predicate.OAuthGrant(sql.FieldEQ(FieldUpdatedAt, v))
|
||||
}
|
||||
|
||||
// DeletedAt applies equality check predicate on the "deleted_at" field. It's identical to DeletedAtEQ.
|
||||
func DeletedAt(v time.Time) predicate.OAuthGrant {
|
||||
return predicate.OAuthGrant(sql.FieldEQ(FieldDeletedAt, v))
|
||||
}
|
||||
|
||||
// UserID applies equality check predicate on the "user_id" field. It's identical to UserIDEQ.
|
||||
func UserID(v int) predicate.OAuthGrant {
|
||||
return predicate.OAuthGrant(sql.FieldEQ(FieldUserID, v))
|
||||
}
|
||||
|
||||
// ClientID applies equality check predicate on the "client_id" field. It's identical to ClientIDEQ.
|
||||
func ClientID(v int) predicate.OAuthGrant {
|
||||
return predicate.OAuthGrant(sql.FieldEQ(FieldClientID, v))
|
||||
}
|
||||
|
||||
// LastUsedAt applies equality check predicate on the "last_used_at" field. It's identical to LastUsedAtEQ.
|
||||
func LastUsedAt(v time.Time) predicate.OAuthGrant {
|
||||
return predicate.OAuthGrant(sql.FieldEQ(FieldLastUsedAt, v))
|
||||
}
|
||||
|
||||
// CreatedAtEQ applies the EQ predicate on the "created_at" field.
|
||||
func CreatedAtEQ(v time.Time) predicate.OAuthGrant {
|
||||
return predicate.OAuthGrant(sql.FieldEQ(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// CreatedAtNEQ applies the NEQ predicate on the "created_at" field.
|
||||
func CreatedAtNEQ(v time.Time) predicate.OAuthGrant {
|
||||
return predicate.OAuthGrant(sql.FieldNEQ(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// CreatedAtIn applies the In predicate on the "created_at" field.
|
||||
func CreatedAtIn(vs ...time.Time) predicate.OAuthGrant {
|
||||
return predicate.OAuthGrant(sql.FieldIn(FieldCreatedAt, vs...))
|
||||
}
|
||||
|
||||
// CreatedAtNotIn applies the NotIn predicate on the "created_at" field.
|
||||
func CreatedAtNotIn(vs ...time.Time) predicate.OAuthGrant {
|
||||
return predicate.OAuthGrant(sql.FieldNotIn(FieldCreatedAt, vs...))
|
||||
}
|
||||
|
||||
// CreatedAtGT applies the GT predicate on the "created_at" field.
|
||||
func CreatedAtGT(v time.Time) predicate.OAuthGrant {
|
||||
return predicate.OAuthGrant(sql.FieldGT(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// CreatedAtGTE applies the GTE predicate on the "created_at" field.
|
||||
func CreatedAtGTE(v time.Time) predicate.OAuthGrant {
|
||||
return predicate.OAuthGrant(sql.FieldGTE(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// CreatedAtLT applies the LT predicate on the "created_at" field.
|
||||
func CreatedAtLT(v time.Time) predicate.OAuthGrant {
|
||||
return predicate.OAuthGrant(sql.FieldLT(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// CreatedAtLTE applies the LTE predicate on the "created_at" field.
|
||||
func CreatedAtLTE(v time.Time) predicate.OAuthGrant {
|
||||
return predicate.OAuthGrant(sql.FieldLTE(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// UpdatedAtEQ applies the EQ predicate on the "updated_at" field.
|
||||
func UpdatedAtEQ(v time.Time) predicate.OAuthGrant {
|
||||
return predicate.OAuthGrant(sql.FieldEQ(FieldUpdatedAt, v))
|
||||
}
|
||||
|
||||
// UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field.
|
||||
func UpdatedAtNEQ(v time.Time) predicate.OAuthGrant {
|
||||
return predicate.OAuthGrant(sql.FieldNEQ(FieldUpdatedAt, v))
|
||||
}
|
||||
|
||||
// UpdatedAtIn applies the In predicate on the "updated_at" field.
|
||||
func UpdatedAtIn(vs ...time.Time) predicate.OAuthGrant {
|
||||
return predicate.OAuthGrant(sql.FieldIn(FieldUpdatedAt, vs...))
|
||||
}
|
||||
|
||||
// UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field.
|
||||
func UpdatedAtNotIn(vs ...time.Time) predicate.OAuthGrant {
|
||||
return predicate.OAuthGrant(sql.FieldNotIn(FieldUpdatedAt, vs...))
|
||||
}
|
||||
|
||||
// UpdatedAtGT applies the GT predicate on the "updated_at" field.
|
||||
func UpdatedAtGT(v time.Time) predicate.OAuthGrant {
|
||||
return predicate.OAuthGrant(sql.FieldGT(FieldUpdatedAt, v))
|
||||
}
|
||||
|
||||
// UpdatedAtGTE applies the GTE predicate on the "updated_at" field.
|
||||
func UpdatedAtGTE(v time.Time) predicate.OAuthGrant {
|
||||
return predicate.OAuthGrant(sql.FieldGTE(FieldUpdatedAt, v))
|
||||
}
|
||||
|
||||
// UpdatedAtLT applies the LT predicate on the "updated_at" field.
|
||||
func UpdatedAtLT(v time.Time) predicate.OAuthGrant {
|
||||
return predicate.OAuthGrant(sql.FieldLT(FieldUpdatedAt, v))
|
||||
}
|
||||
|
||||
// UpdatedAtLTE applies the LTE predicate on the "updated_at" field.
|
||||
func UpdatedAtLTE(v time.Time) predicate.OAuthGrant {
|
||||
return predicate.OAuthGrant(sql.FieldLTE(FieldUpdatedAt, v))
|
||||
}
|
||||
|
||||
// DeletedAtEQ applies the EQ predicate on the "deleted_at" field.
|
||||
func DeletedAtEQ(v time.Time) predicate.OAuthGrant {
|
||||
return predicate.OAuthGrant(sql.FieldEQ(FieldDeletedAt, v))
|
||||
}
|
||||
|
||||
// DeletedAtNEQ applies the NEQ predicate on the "deleted_at" field.
|
||||
func DeletedAtNEQ(v time.Time) predicate.OAuthGrant {
|
||||
return predicate.OAuthGrant(sql.FieldNEQ(FieldDeletedAt, v))
|
||||
}
|
||||
|
||||
// DeletedAtIn applies the In predicate on the "deleted_at" field.
|
||||
func DeletedAtIn(vs ...time.Time) predicate.OAuthGrant {
|
||||
return predicate.OAuthGrant(sql.FieldIn(FieldDeletedAt, vs...))
|
||||
}
|
||||
|
||||
// DeletedAtNotIn applies the NotIn predicate on the "deleted_at" field.
|
||||
func DeletedAtNotIn(vs ...time.Time) predicate.OAuthGrant {
|
||||
return predicate.OAuthGrant(sql.FieldNotIn(FieldDeletedAt, vs...))
|
||||
}
|
||||
|
||||
// DeletedAtGT applies the GT predicate on the "deleted_at" field.
|
||||
func DeletedAtGT(v time.Time) predicate.OAuthGrant {
|
||||
return predicate.OAuthGrant(sql.FieldGT(FieldDeletedAt, v))
|
||||
}
|
||||
|
||||
// DeletedAtGTE applies the GTE predicate on the "deleted_at" field.
|
||||
func DeletedAtGTE(v time.Time) predicate.OAuthGrant {
|
||||
return predicate.OAuthGrant(sql.FieldGTE(FieldDeletedAt, v))
|
||||
}
|
||||
|
||||
// DeletedAtLT applies the LT predicate on the "deleted_at" field.
|
||||
func DeletedAtLT(v time.Time) predicate.OAuthGrant {
|
||||
return predicate.OAuthGrant(sql.FieldLT(FieldDeletedAt, v))
|
||||
}
|
||||
|
||||
// DeletedAtLTE applies the LTE predicate on the "deleted_at" field.
|
||||
func DeletedAtLTE(v time.Time) predicate.OAuthGrant {
|
||||
return predicate.OAuthGrant(sql.FieldLTE(FieldDeletedAt, v))
|
||||
}
|
||||
|
||||
// DeletedAtIsNil applies the IsNil predicate on the "deleted_at" field.
|
||||
func DeletedAtIsNil() predicate.OAuthGrant {
|
||||
return predicate.OAuthGrant(sql.FieldIsNull(FieldDeletedAt))
|
||||
}
|
||||
|
||||
// DeletedAtNotNil applies the NotNil predicate on the "deleted_at" field.
|
||||
func DeletedAtNotNil() predicate.OAuthGrant {
|
||||
return predicate.OAuthGrant(sql.FieldNotNull(FieldDeletedAt))
|
||||
}
|
||||
|
||||
// UserIDEQ applies the EQ predicate on the "user_id" field.
|
||||
func UserIDEQ(v int) predicate.OAuthGrant {
|
||||
return predicate.OAuthGrant(sql.FieldEQ(FieldUserID, v))
|
||||
}
|
||||
|
||||
// UserIDNEQ applies the NEQ predicate on the "user_id" field.
|
||||
func UserIDNEQ(v int) predicate.OAuthGrant {
|
||||
return predicate.OAuthGrant(sql.FieldNEQ(FieldUserID, v))
|
||||
}
|
||||
|
||||
// UserIDIn applies the In predicate on the "user_id" field.
|
||||
func UserIDIn(vs ...int) predicate.OAuthGrant {
|
||||
return predicate.OAuthGrant(sql.FieldIn(FieldUserID, vs...))
|
||||
}
|
||||
|
||||
// UserIDNotIn applies the NotIn predicate on the "user_id" field.
|
||||
func UserIDNotIn(vs ...int) predicate.OAuthGrant {
|
||||
return predicate.OAuthGrant(sql.FieldNotIn(FieldUserID, vs...))
|
||||
}
|
||||
|
||||
// ClientIDEQ applies the EQ predicate on the "client_id" field.
|
||||
func ClientIDEQ(v int) predicate.OAuthGrant {
|
||||
return predicate.OAuthGrant(sql.FieldEQ(FieldClientID, v))
|
||||
}
|
||||
|
||||
// ClientIDNEQ applies the NEQ predicate on the "client_id" field.
|
||||
func ClientIDNEQ(v int) predicate.OAuthGrant {
|
||||
return predicate.OAuthGrant(sql.FieldNEQ(FieldClientID, v))
|
||||
}
|
||||
|
||||
// ClientIDIn applies the In predicate on the "client_id" field.
|
||||
func ClientIDIn(vs ...int) predicate.OAuthGrant {
|
||||
return predicate.OAuthGrant(sql.FieldIn(FieldClientID, vs...))
|
||||
}
|
||||
|
||||
// ClientIDNotIn applies the NotIn predicate on the "client_id" field.
|
||||
func ClientIDNotIn(vs ...int) predicate.OAuthGrant {
|
||||
return predicate.OAuthGrant(sql.FieldNotIn(FieldClientID, vs...))
|
||||
}
|
||||
|
||||
// LastUsedAtEQ applies the EQ predicate on the "last_used_at" field.
|
||||
func LastUsedAtEQ(v time.Time) predicate.OAuthGrant {
|
||||
return predicate.OAuthGrant(sql.FieldEQ(FieldLastUsedAt, v))
|
||||
}
|
||||
|
||||
// LastUsedAtNEQ applies the NEQ predicate on the "last_used_at" field.
|
||||
func LastUsedAtNEQ(v time.Time) predicate.OAuthGrant {
|
||||
return predicate.OAuthGrant(sql.FieldNEQ(FieldLastUsedAt, v))
|
||||
}
|
||||
|
||||
// LastUsedAtIn applies the In predicate on the "last_used_at" field.
|
||||
func LastUsedAtIn(vs ...time.Time) predicate.OAuthGrant {
|
||||
return predicate.OAuthGrant(sql.FieldIn(FieldLastUsedAt, vs...))
|
||||
}
|
||||
|
||||
// LastUsedAtNotIn applies the NotIn predicate on the "last_used_at" field.
|
||||
func LastUsedAtNotIn(vs ...time.Time) predicate.OAuthGrant {
|
||||
return predicate.OAuthGrant(sql.FieldNotIn(FieldLastUsedAt, vs...))
|
||||
}
|
||||
|
||||
// LastUsedAtGT applies the GT predicate on the "last_used_at" field.
|
||||
func LastUsedAtGT(v time.Time) predicate.OAuthGrant {
|
||||
return predicate.OAuthGrant(sql.FieldGT(FieldLastUsedAt, v))
|
||||
}
|
||||
|
||||
// LastUsedAtGTE applies the GTE predicate on the "last_used_at" field.
|
||||
func LastUsedAtGTE(v time.Time) predicate.OAuthGrant {
|
||||
return predicate.OAuthGrant(sql.FieldGTE(FieldLastUsedAt, v))
|
||||
}
|
||||
|
||||
// LastUsedAtLT applies the LT predicate on the "last_used_at" field.
|
||||
func LastUsedAtLT(v time.Time) predicate.OAuthGrant {
|
||||
return predicate.OAuthGrant(sql.FieldLT(FieldLastUsedAt, v))
|
||||
}
|
||||
|
||||
// LastUsedAtLTE applies the LTE predicate on the "last_used_at" field.
|
||||
func LastUsedAtLTE(v time.Time) predicate.OAuthGrant {
|
||||
return predicate.OAuthGrant(sql.FieldLTE(FieldLastUsedAt, v))
|
||||
}
|
||||
|
||||
// LastUsedAtIsNil applies the IsNil predicate on the "last_used_at" field.
|
||||
func LastUsedAtIsNil() predicate.OAuthGrant {
|
||||
return predicate.OAuthGrant(sql.FieldIsNull(FieldLastUsedAt))
|
||||
}
|
||||
|
||||
// LastUsedAtNotNil applies the NotNil predicate on the "last_used_at" field.
|
||||
func LastUsedAtNotNil() predicate.OAuthGrant {
|
||||
return predicate.OAuthGrant(sql.FieldNotNull(FieldLastUsedAt))
|
||||
}
|
||||
|
||||
// HasUser applies the HasEdge predicate on the "user" edge.
|
||||
func HasUser() predicate.OAuthGrant {
|
||||
return predicate.OAuthGrant(func(s *sql.Selector) {
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, true, UserTable, UserColumn),
|
||||
)
|
||||
sqlgraph.HasNeighbors(s, step)
|
||||
})
|
||||
}
|
||||
|
||||
// HasUserWith applies the HasEdge predicate on the "user" edge with a given conditions (other predicates).
|
||||
func HasUserWith(preds ...predicate.User) predicate.OAuthGrant {
|
||||
return predicate.OAuthGrant(func(s *sql.Selector) {
|
||||
step := newUserStep()
|
||||
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
|
||||
for _, p := range preds {
|
||||
p(s)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// HasClient applies the HasEdge predicate on the "client" edge.
|
||||
func HasClient() predicate.OAuthGrant {
|
||||
return predicate.OAuthGrant(func(s *sql.Selector) {
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, true, ClientTable, ClientColumn),
|
||||
)
|
||||
sqlgraph.HasNeighbors(s, step)
|
||||
})
|
||||
}
|
||||
|
||||
// HasClientWith applies the HasEdge predicate on the "client" edge with a given conditions (other predicates).
|
||||
func HasClientWith(preds ...predicate.OAuthClient) predicate.OAuthGrant {
|
||||
return predicate.OAuthGrant(func(s *sql.Selector) {
|
||||
step := newClientStep()
|
||||
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
|
||||
for _, p := range preds {
|
||||
p(s)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// And groups predicates with the AND operator between them.
|
||||
func And(predicates ...predicate.OAuthGrant) predicate.OAuthGrant {
|
||||
return predicate.OAuthGrant(sql.AndPredicates(predicates...))
|
||||
}
|
||||
|
||||
// Or groups predicates with the OR operator between them.
|
||||
func Or(predicates ...predicate.OAuthGrant) predicate.OAuthGrant {
|
||||
return predicate.OAuthGrant(sql.OrPredicates(predicates...))
|
||||
}
|
||||
|
||||
// Not applies the not operator on the given predicate.
|
||||
func Not(p predicate.OAuthGrant) predicate.OAuthGrant {
|
||||
return predicate.OAuthGrant(sql.NotPredicates(p))
|
||||
}
|
||||
@ -0,0 +1,894 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
"github.com/cloudreve/Cloudreve/v4/ent/oauthclient"
|
||||
"github.com/cloudreve/Cloudreve/v4/ent/oauthgrant"
|
||||
"github.com/cloudreve/Cloudreve/v4/ent/user"
|
||||
)
|
||||
|
||||
// OAuthGrantCreate is the builder for creating a OAuthGrant entity.
|
||||
type OAuthGrantCreate struct {
|
||||
config
|
||||
mutation *OAuthGrantMutation
|
||||
hooks []Hook
|
||||
conflict []sql.ConflictOption
|
||||
}
|
||||
|
||||
// SetCreatedAt sets the "created_at" field.
|
||||
func (ogc *OAuthGrantCreate) SetCreatedAt(t time.Time) *OAuthGrantCreate {
|
||||
ogc.mutation.SetCreatedAt(t)
|
||||
return ogc
|
||||
}
|
||||
|
||||
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
||||
func (ogc *OAuthGrantCreate) SetNillableCreatedAt(t *time.Time) *OAuthGrantCreate {
|
||||
if t != nil {
|
||||
ogc.SetCreatedAt(*t)
|
||||
}
|
||||
return ogc
|
||||
}
|
||||
|
||||
// SetUpdatedAt sets the "updated_at" field.
|
||||
func (ogc *OAuthGrantCreate) SetUpdatedAt(t time.Time) *OAuthGrantCreate {
|
||||
ogc.mutation.SetUpdatedAt(t)
|
||||
return ogc
|
||||
}
|
||||
|
||||
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
|
||||
func (ogc *OAuthGrantCreate) SetNillableUpdatedAt(t *time.Time) *OAuthGrantCreate {
|
||||
if t != nil {
|
||||
ogc.SetUpdatedAt(*t)
|
||||
}
|
||||
return ogc
|
||||
}
|
||||
|
||||
// SetDeletedAt sets the "deleted_at" field.
|
||||
func (ogc *OAuthGrantCreate) SetDeletedAt(t time.Time) *OAuthGrantCreate {
|
||||
ogc.mutation.SetDeletedAt(t)
|
||||
return ogc
|
||||
}
|
||||
|
||||
// SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
|
||||
func (ogc *OAuthGrantCreate) SetNillableDeletedAt(t *time.Time) *OAuthGrantCreate {
|
||||
if t != nil {
|
||||
ogc.SetDeletedAt(*t)
|
||||
}
|
||||
return ogc
|
||||
}
|
||||
|
||||
// SetUserID sets the "user_id" field.
|
||||
func (ogc *OAuthGrantCreate) SetUserID(i int) *OAuthGrantCreate {
|
||||
ogc.mutation.SetUserID(i)
|
||||
return ogc
|
||||
}
|
||||
|
||||
// SetClientID sets the "client_id" field.
|
||||
func (ogc *OAuthGrantCreate) SetClientID(i int) *OAuthGrantCreate {
|
||||
ogc.mutation.SetClientID(i)
|
||||
return ogc
|
||||
}
|
||||
|
||||
// SetScopes sets the "scopes" field.
|
||||
func (ogc *OAuthGrantCreate) SetScopes(s []string) *OAuthGrantCreate {
|
||||
ogc.mutation.SetScopes(s)
|
||||
return ogc
|
||||
}
|
||||
|
||||
// SetLastUsedAt sets the "last_used_at" field.
|
||||
func (ogc *OAuthGrantCreate) SetLastUsedAt(t time.Time) *OAuthGrantCreate {
|
||||
ogc.mutation.SetLastUsedAt(t)
|
||||
return ogc
|
||||
}
|
||||
|
||||
// SetNillableLastUsedAt sets the "last_used_at" field if the given value is not nil.
|
||||
func (ogc *OAuthGrantCreate) SetNillableLastUsedAt(t *time.Time) *OAuthGrantCreate {
|
||||
if t != nil {
|
||||
ogc.SetLastUsedAt(*t)
|
||||
}
|
||||
return ogc
|
||||
}
|
||||
|
||||
// SetUser sets the "user" edge to the User entity.
|
||||
func (ogc *OAuthGrantCreate) SetUser(u *User) *OAuthGrantCreate {
|
||||
return ogc.SetUserID(u.ID)
|
||||
}
|
||||
|
||||
// SetClient sets the "client" edge to the OAuthClient entity.
|
||||
func (ogc *OAuthGrantCreate) SetClient(o *OAuthClient) *OAuthGrantCreate {
|
||||
return ogc.SetClientID(o.ID)
|
||||
}
|
||||
|
||||
// Mutation returns the OAuthGrantMutation object of the builder.
|
||||
func (ogc *OAuthGrantCreate) Mutation() *OAuthGrantMutation {
|
||||
return ogc.mutation
|
||||
}
|
||||
|
||||
// Save creates the OAuthGrant in the database.
|
||||
func (ogc *OAuthGrantCreate) Save(ctx context.Context) (*OAuthGrant, error) {
|
||||
if err := ogc.defaults(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return withHooks(ctx, ogc.sqlSave, ogc.mutation, ogc.hooks)
|
||||
}
|
||||
|
||||
// SaveX calls Save and panics if Save returns an error.
|
||||
func (ogc *OAuthGrantCreate) SaveX(ctx context.Context) *OAuthGrant {
|
||||
v, err := ogc.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (ogc *OAuthGrantCreate) Exec(ctx context.Context) error {
|
||||
_, err := ogc.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (ogc *OAuthGrantCreate) ExecX(ctx context.Context) {
|
||||
if err := ogc.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// defaults sets the default values of the builder before save.
|
||||
func (ogc *OAuthGrantCreate) defaults() error {
|
||||
if _, ok := ogc.mutation.CreatedAt(); !ok {
|
||||
if oauthgrant.DefaultCreatedAt == nil {
|
||||
return fmt.Errorf("ent: uninitialized oauthgrant.DefaultCreatedAt (forgotten import ent/runtime?)")
|
||||
}
|
||||
v := oauthgrant.DefaultCreatedAt()
|
||||
ogc.mutation.SetCreatedAt(v)
|
||||
}
|
||||
if _, ok := ogc.mutation.UpdatedAt(); !ok {
|
||||
if oauthgrant.DefaultUpdatedAt == nil {
|
||||
return fmt.Errorf("ent: uninitialized oauthgrant.DefaultUpdatedAt (forgotten import ent/runtime?)")
|
||||
}
|
||||
v := oauthgrant.DefaultUpdatedAt()
|
||||
ogc.mutation.SetUpdatedAt(v)
|
||||
}
|
||||
if _, ok := ogc.mutation.Scopes(); !ok {
|
||||
v := oauthgrant.DefaultScopes
|
||||
ogc.mutation.SetScopes(v)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (ogc *OAuthGrantCreate) check() error {
|
||||
if _, ok := ogc.mutation.CreatedAt(); !ok {
|
||||
return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "OAuthGrant.created_at"`)}
|
||||
}
|
||||
if _, ok := ogc.mutation.UpdatedAt(); !ok {
|
||||
return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "OAuthGrant.updated_at"`)}
|
||||
}
|
||||
if _, ok := ogc.mutation.UserID(); !ok {
|
||||
return &ValidationError{Name: "user_id", err: errors.New(`ent: missing required field "OAuthGrant.user_id"`)}
|
||||
}
|
||||
if _, ok := ogc.mutation.ClientID(); !ok {
|
||||
return &ValidationError{Name: "client_id", err: errors.New(`ent: missing required field "OAuthGrant.client_id"`)}
|
||||
}
|
||||
if _, ok := ogc.mutation.Scopes(); !ok {
|
||||
return &ValidationError{Name: "scopes", err: errors.New(`ent: missing required field "OAuthGrant.scopes"`)}
|
||||
}
|
||||
if _, ok := ogc.mutation.UserID(); !ok {
|
||||
return &ValidationError{Name: "user", err: errors.New(`ent: missing required edge "OAuthGrant.user"`)}
|
||||
}
|
||||
if _, ok := ogc.mutation.ClientID(); !ok {
|
||||
return &ValidationError{Name: "client", err: errors.New(`ent: missing required edge "OAuthGrant.client"`)}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ogc *OAuthGrantCreate) sqlSave(ctx context.Context) (*OAuthGrant, error) {
|
||||
if err := ogc.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_node, _spec := ogc.createSpec()
|
||||
if err := sqlgraph.CreateNode(ctx, ogc.driver, _spec); err != nil {
|
||||
if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
id := _spec.ID.Value.(int64)
|
||||
_node.ID = int(id)
|
||||
ogc.mutation.id = &_node.ID
|
||||
ogc.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
|
||||
func (ogc *OAuthGrantCreate) createSpec() (*OAuthGrant, *sqlgraph.CreateSpec) {
|
||||
var (
|
||||
_node = &OAuthGrant{config: ogc.config}
|
||||
_spec = sqlgraph.NewCreateSpec(oauthgrant.Table, sqlgraph.NewFieldSpec(oauthgrant.FieldID, field.TypeInt))
|
||||
)
|
||||
|
||||
if id, ok := ogc.mutation.ID(); ok {
|
||||
_node.ID = id
|
||||
id64 := int64(id)
|
||||
_spec.ID.Value = id64
|
||||
}
|
||||
|
||||
_spec.OnConflict = ogc.conflict
|
||||
if value, ok := ogc.mutation.CreatedAt(); ok {
|
||||
_spec.SetField(oauthgrant.FieldCreatedAt, field.TypeTime, value)
|
||||
_node.CreatedAt = value
|
||||
}
|
||||
if value, ok := ogc.mutation.UpdatedAt(); ok {
|
||||
_spec.SetField(oauthgrant.FieldUpdatedAt, field.TypeTime, value)
|
||||
_node.UpdatedAt = value
|
||||
}
|
||||
if value, ok := ogc.mutation.DeletedAt(); ok {
|
||||
_spec.SetField(oauthgrant.FieldDeletedAt, field.TypeTime, value)
|
||||
_node.DeletedAt = &value
|
||||
}
|
||||
if value, ok := ogc.mutation.Scopes(); ok {
|
||||
_spec.SetField(oauthgrant.FieldScopes, field.TypeJSON, value)
|
||||
_node.Scopes = value
|
||||
}
|
||||
if value, ok := ogc.mutation.LastUsedAt(); ok {
|
||||
_spec.SetField(oauthgrant.FieldLastUsedAt, field.TypeTime, value)
|
||||
_node.LastUsedAt = &value
|
||||
}
|
||||
if nodes := ogc.mutation.UserIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
Table: oauthgrant.UserTable,
|
||||
Columns: []string{oauthgrant.UserColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_node.UserID = nodes[0]
|
||||
_spec.Edges = append(_spec.Edges, edge)
|
||||
}
|
||||
if nodes := ogc.mutation.ClientIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
Table: oauthgrant.ClientTable,
|
||||
Columns: []string{oauthgrant.ClientColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(oauthclient.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_node.ClientID = nodes[0]
|
||||
_spec.Edges = append(_spec.Edges, edge)
|
||||
}
|
||||
return _node, _spec
|
||||
}
|
||||
|
||||
// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
|
||||
// of the `INSERT` statement. For example:
|
||||
//
|
||||
// client.OAuthGrant.Create().
|
||||
// SetCreatedAt(v).
|
||||
// OnConflict(
|
||||
// // Update the row with the new values
|
||||
// // the was proposed for insertion.
|
||||
// sql.ResolveWithNewValues(),
|
||||
// ).
|
||||
// // Override some of the fields with custom
|
||||
// // update values.
|
||||
// Update(func(u *ent.OAuthGrantUpsert) {
|
||||
// SetCreatedAt(v+v).
|
||||
// }).
|
||||
// Exec(ctx)
|
||||
func (ogc *OAuthGrantCreate) OnConflict(opts ...sql.ConflictOption) *OAuthGrantUpsertOne {
|
||||
ogc.conflict = opts
|
||||
return &OAuthGrantUpsertOne{
|
||||
create: ogc,
|
||||
}
|
||||
}
|
||||
|
||||
// OnConflictColumns calls `OnConflict` and configures the columns
|
||||
// as conflict target. Using this option is equivalent to using:
|
||||
//
|
||||
// client.OAuthGrant.Create().
|
||||
// OnConflict(sql.ConflictColumns(columns...)).
|
||||
// Exec(ctx)
|
||||
func (ogc *OAuthGrantCreate) OnConflictColumns(columns ...string) *OAuthGrantUpsertOne {
|
||||
ogc.conflict = append(ogc.conflict, sql.ConflictColumns(columns...))
|
||||
return &OAuthGrantUpsertOne{
|
||||
create: ogc,
|
||||
}
|
||||
}
|
||||
|
||||
type (
|
||||
// OAuthGrantUpsertOne is the builder for "upsert"-ing
|
||||
// one OAuthGrant node.
|
||||
OAuthGrantUpsertOne struct {
|
||||
create *OAuthGrantCreate
|
||||
}
|
||||
|
||||
// OAuthGrantUpsert is the "OnConflict" setter.
|
||||
OAuthGrantUpsert struct {
|
||||
*sql.UpdateSet
|
||||
}
|
||||
)
|
||||
|
||||
// SetUpdatedAt sets the "updated_at" field.
|
||||
func (u *OAuthGrantUpsert) SetUpdatedAt(v time.Time) *OAuthGrantUpsert {
|
||||
u.Set(oauthgrant.FieldUpdatedAt, v)
|
||||
return u
|
||||
}
|
||||
|
||||
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
|
||||
func (u *OAuthGrantUpsert) UpdateUpdatedAt() *OAuthGrantUpsert {
|
||||
u.SetExcluded(oauthgrant.FieldUpdatedAt)
|
||||
return u
|
||||
}
|
||||
|
||||
// SetDeletedAt sets the "deleted_at" field.
|
||||
func (u *OAuthGrantUpsert) SetDeletedAt(v time.Time) *OAuthGrantUpsert {
|
||||
u.Set(oauthgrant.FieldDeletedAt, v)
|
||||
return u
|
||||
}
|
||||
|
||||
// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
|
||||
func (u *OAuthGrantUpsert) UpdateDeletedAt() *OAuthGrantUpsert {
|
||||
u.SetExcluded(oauthgrant.FieldDeletedAt)
|
||||
return u
|
||||
}
|
||||
|
||||
// ClearDeletedAt clears the value of the "deleted_at" field.
|
||||
func (u *OAuthGrantUpsert) ClearDeletedAt() *OAuthGrantUpsert {
|
||||
u.SetNull(oauthgrant.FieldDeletedAt)
|
||||
return u
|
||||
}
|
||||
|
||||
// SetUserID sets the "user_id" field.
|
||||
func (u *OAuthGrantUpsert) SetUserID(v int) *OAuthGrantUpsert {
|
||||
u.Set(oauthgrant.FieldUserID, v)
|
||||
return u
|
||||
}
|
||||
|
||||
// UpdateUserID sets the "user_id" field to the value that was provided on create.
|
||||
func (u *OAuthGrantUpsert) UpdateUserID() *OAuthGrantUpsert {
|
||||
u.SetExcluded(oauthgrant.FieldUserID)
|
||||
return u
|
||||
}
|
||||
|
||||
// SetClientID sets the "client_id" field.
|
||||
func (u *OAuthGrantUpsert) SetClientID(v int) *OAuthGrantUpsert {
|
||||
u.Set(oauthgrant.FieldClientID, v)
|
||||
return u
|
||||
}
|
||||
|
||||
// UpdateClientID sets the "client_id" field to the value that was provided on create.
|
||||
func (u *OAuthGrantUpsert) UpdateClientID() *OAuthGrantUpsert {
|
||||
u.SetExcluded(oauthgrant.FieldClientID)
|
||||
return u
|
||||
}
|
||||
|
||||
// SetScopes sets the "scopes" field.
|
||||
func (u *OAuthGrantUpsert) SetScopes(v []string) *OAuthGrantUpsert {
|
||||
u.Set(oauthgrant.FieldScopes, v)
|
||||
return u
|
||||
}
|
||||
|
||||
// UpdateScopes sets the "scopes" field to the value that was provided on create.
|
||||
func (u *OAuthGrantUpsert) UpdateScopes() *OAuthGrantUpsert {
|
||||
u.SetExcluded(oauthgrant.FieldScopes)
|
||||
return u
|
||||
}
|
||||
|
||||
// SetLastUsedAt sets the "last_used_at" field.
|
||||
func (u *OAuthGrantUpsert) SetLastUsedAt(v time.Time) *OAuthGrantUpsert {
|
||||
u.Set(oauthgrant.FieldLastUsedAt, v)
|
||||
return u
|
||||
}
|
||||
|
||||
// UpdateLastUsedAt sets the "last_used_at" field to the value that was provided on create.
|
||||
func (u *OAuthGrantUpsert) UpdateLastUsedAt() *OAuthGrantUpsert {
|
||||
u.SetExcluded(oauthgrant.FieldLastUsedAt)
|
||||
return u
|
||||
}
|
||||
|
||||
// ClearLastUsedAt clears the value of the "last_used_at" field.
|
||||
func (u *OAuthGrantUpsert) ClearLastUsedAt() *OAuthGrantUpsert {
|
||||
u.SetNull(oauthgrant.FieldLastUsedAt)
|
||||
return u
|
||||
}
|
||||
|
||||
// UpdateNewValues updates the mutable fields using the new values that were set on create.
|
||||
// Using this option is equivalent to using:
|
||||
//
|
||||
// client.OAuthGrant.Create().
|
||||
// OnConflict(
|
||||
// sql.ResolveWithNewValues(),
|
||||
// ).
|
||||
// Exec(ctx)
|
||||
func (u *OAuthGrantUpsertOne) UpdateNewValues() *OAuthGrantUpsertOne {
|
||||
u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
|
||||
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
|
||||
if _, exists := u.create.mutation.CreatedAt(); exists {
|
||||
s.SetIgnore(oauthgrant.FieldCreatedAt)
|
||||
}
|
||||
}))
|
||||
return u
|
||||
}
|
||||
|
||||
// Ignore sets each column to itself in case of conflict.
|
||||
// Using this option is equivalent to using:
|
||||
//
|
||||
// client.OAuthGrant.Create().
|
||||
// OnConflict(sql.ResolveWithIgnore()).
|
||||
// Exec(ctx)
|
||||
func (u *OAuthGrantUpsertOne) Ignore() *OAuthGrantUpsertOne {
|
||||
u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
|
||||
return u
|
||||
}
|
||||
|
||||
// DoNothing configures the conflict_action to `DO NOTHING`.
|
||||
// Supported only by SQLite and PostgreSQL.
|
||||
func (u *OAuthGrantUpsertOne) DoNothing() *OAuthGrantUpsertOne {
|
||||
u.create.conflict = append(u.create.conflict, sql.DoNothing())
|
||||
return u
|
||||
}
|
||||
|
||||
// Update allows overriding fields `UPDATE` values. See the OAuthGrantCreate.OnConflict
|
||||
// documentation for more info.
|
||||
func (u *OAuthGrantUpsertOne) Update(set func(*OAuthGrantUpsert)) *OAuthGrantUpsertOne {
|
||||
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
|
||||
set(&OAuthGrantUpsert{UpdateSet: update})
|
||||
}))
|
||||
return u
|
||||
}
|
||||
|
||||
// SetUpdatedAt sets the "updated_at" field.
|
||||
func (u *OAuthGrantUpsertOne) SetUpdatedAt(v time.Time) *OAuthGrantUpsertOne {
|
||||
return u.Update(func(s *OAuthGrantUpsert) {
|
||||
s.SetUpdatedAt(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
|
||||
func (u *OAuthGrantUpsertOne) UpdateUpdatedAt() *OAuthGrantUpsertOne {
|
||||
return u.Update(func(s *OAuthGrantUpsert) {
|
||||
s.UpdateUpdatedAt()
|
||||
})
|
||||
}
|
||||
|
||||
// SetDeletedAt sets the "deleted_at" field.
|
||||
func (u *OAuthGrantUpsertOne) SetDeletedAt(v time.Time) *OAuthGrantUpsertOne {
|
||||
return u.Update(func(s *OAuthGrantUpsert) {
|
||||
s.SetDeletedAt(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
|
||||
func (u *OAuthGrantUpsertOne) UpdateDeletedAt() *OAuthGrantUpsertOne {
|
||||
return u.Update(func(s *OAuthGrantUpsert) {
|
||||
s.UpdateDeletedAt()
|
||||
})
|
||||
}
|
||||
|
||||
// ClearDeletedAt clears the value of the "deleted_at" field.
|
||||
func (u *OAuthGrantUpsertOne) ClearDeletedAt() *OAuthGrantUpsertOne {
|
||||
return u.Update(func(s *OAuthGrantUpsert) {
|
||||
s.ClearDeletedAt()
|
||||
})
|
||||
}
|
||||
|
||||
// SetUserID sets the "user_id" field.
|
||||
func (u *OAuthGrantUpsertOne) SetUserID(v int) *OAuthGrantUpsertOne {
|
||||
return u.Update(func(s *OAuthGrantUpsert) {
|
||||
s.SetUserID(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateUserID sets the "user_id" field to the value that was provided on create.
|
||||
func (u *OAuthGrantUpsertOne) UpdateUserID() *OAuthGrantUpsertOne {
|
||||
return u.Update(func(s *OAuthGrantUpsert) {
|
||||
s.UpdateUserID()
|
||||
})
|
||||
}
|
||||
|
||||
// SetClientID sets the "client_id" field.
|
||||
func (u *OAuthGrantUpsertOne) SetClientID(v int) *OAuthGrantUpsertOne {
|
||||
return u.Update(func(s *OAuthGrantUpsert) {
|
||||
s.SetClientID(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateClientID sets the "client_id" field to the value that was provided on create.
|
||||
func (u *OAuthGrantUpsertOne) UpdateClientID() *OAuthGrantUpsertOne {
|
||||
return u.Update(func(s *OAuthGrantUpsert) {
|
||||
s.UpdateClientID()
|
||||
})
|
||||
}
|
||||
|
||||
// SetScopes sets the "scopes" field.
|
||||
func (u *OAuthGrantUpsertOne) SetScopes(v []string) *OAuthGrantUpsertOne {
|
||||
return u.Update(func(s *OAuthGrantUpsert) {
|
||||
s.SetScopes(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateScopes sets the "scopes" field to the value that was provided on create.
|
||||
func (u *OAuthGrantUpsertOne) UpdateScopes() *OAuthGrantUpsertOne {
|
||||
return u.Update(func(s *OAuthGrantUpsert) {
|
||||
s.UpdateScopes()
|
||||
})
|
||||
}
|
||||
|
||||
// SetLastUsedAt sets the "last_used_at" field.
|
||||
func (u *OAuthGrantUpsertOne) SetLastUsedAt(v time.Time) *OAuthGrantUpsertOne {
|
||||
return u.Update(func(s *OAuthGrantUpsert) {
|
||||
s.SetLastUsedAt(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateLastUsedAt sets the "last_used_at" field to the value that was provided on create.
|
||||
func (u *OAuthGrantUpsertOne) UpdateLastUsedAt() *OAuthGrantUpsertOne {
|
||||
return u.Update(func(s *OAuthGrantUpsert) {
|
||||
s.UpdateLastUsedAt()
|
||||
})
|
||||
}
|
||||
|
||||
// ClearLastUsedAt clears the value of the "last_used_at" field.
|
||||
func (u *OAuthGrantUpsertOne) ClearLastUsedAt() *OAuthGrantUpsertOne {
|
||||
return u.Update(func(s *OAuthGrantUpsert) {
|
||||
s.ClearLastUsedAt()
|
||||
})
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (u *OAuthGrantUpsertOne) Exec(ctx context.Context) error {
|
||||
if len(u.create.conflict) == 0 {
|
||||
return errors.New("ent: missing options for OAuthGrantCreate.OnConflict")
|
||||
}
|
||||
return u.create.Exec(ctx)
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (u *OAuthGrantUpsertOne) ExecX(ctx context.Context) {
|
||||
if err := u.create.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// Exec executes the UPSERT query and returns the inserted/updated ID.
|
||||
func (u *OAuthGrantUpsertOne) ID(ctx context.Context) (id int, err error) {
|
||||
node, err := u.create.Save(ctx)
|
||||
if err != nil {
|
||||
return id, err
|
||||
}
|
||||
return node.ID, nil
|
||||
}
|
||||
|
||||
// IDX is like ID, but panics if an error occurs.
|
||||
func (u *OAuthGrantUpsertOne) IDX(ctx context.Context) int {
|
||||
id, err := u.ID(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
func (m *OAuthGrantCreate) SetRawID(t int) *OAuthGrantCreate {
|
||||
m.mutation.SetRawID(t)
|
||||
return m
|
||||
}
|
||||
|
||||
// OAuthGrantCreateBulk is the builder for creating many OAuthGrant entities in bulk.
|
||||
type OAuthGrantCreateBulk struct {
|
||||
config
|
||||
err error
|
||||
builders []*OAuthGrantCreate
|
||||
conflict []sql.ConflictOption
|
||||
}
|
||||
|
||||
// Save creates the OAuthGrant entities in the database.
|
||||
func (ogcb *OAuthGrantCreateBulk) Save(ctx context.Context) ([]*OAuthGrant, error) {
|
||||
if ogcb.err != nil {
|
||||
return nil, ogcb.err
|
||||
}
|
||||
specs := make([]*sqlgraph.CreateSpec, len(ogcb.builders))
|
||||
nodes := make([]*OAuthGrant, len(ogcb.builders))
|
||||
mutators := make([]Mutator, len(ogcb.builders))
|
||||
for i := range ogcb.builders {
|
||||
func(i int, root context.Context) {
|
||||
builder := ogcb.builders[i]
|
||||
builder.defaults()
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
mutation, ok := m.(*OAuthGrantMutation)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||
}
|
||||
if err := builder.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
builder.mutation = mutation
|
||||
var err error
|
||||
nodes[i], specs[i] = builder.createSpec()
|
||||
if i < len(mutators)-1 {
|
||||
_, err = mutators[i+1].Mutate(root, ogcb.builders[i+1].mutation)
|
||||
} else {
|
||||
spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
|
||||
spec.OnConflict = ogcb.conflict
|
||||
// Invoke the actual operation on the latest mutation in the chain.
|
||||
if err = sqlgraph.BatchCreate(ctx, ogcb.driver, spec); err != nil {
|
||||
if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
mutation.id = &nodes[i].ID
|
||||
if specs[i].ID.Value != nil {
|
||||
id := specs[i].ID.Value.(int64)
|
||||
nodes[i].ID = int(id)
|
||||
}
|
||||
mutation.done = true
|
||||
return nodes[i], nil
|
||||
})
|
||||
for i := len(builder.hooks) - 1; i >= 0; i-- {
|
||||
mut = builder.hooks[i](mut)
|
||||
}
|
||||
mutators[i] = mut
|
||||
}(i, ctx)
|
||||
}
|
||||
if len(mutators) > 0 {
|
||||
if _, err := mutators[0].Mutate(ctx, ogcb.builders[0].mutation); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (ogcb *OAuthGrantCreateBulk) SaveX(ctx context.Context) []*OAuthGrant {
|
||||
v, err := ogcb.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (ogcb *OAuthGrantCreateBulk) Exec(ctx context.Context) error {
|
||||
_, err := ogcb.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (ogcb *OAuthGrantCreateBulk) ExecX(ctx context.Context) {
|
||||
if err := ogcb.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
|
||||
// of the `INSERT` statement. For example:
|
||||
//
|
||||
// client.OAuthGrant.CreateBulk(builders...).
|
||||
// OnConflict(
|
||||
// // Update the row with the new values
|
||||
// // the was proposed for insertion.
|
||||
// sql.ResolveWithNewValues(),
|
||||
// ).
|
||||
// // Override some of the fields with custom
|
||||
// // update values.
|
||||
// Update(func(u *ent.OAuthGrantUpsert) {
|
||||
// SetCreatedAt(v+v).
|
||||
// }).
|
||||
// Exec(ctx)
|
||||
func (ogcb *OAuthGrantCreateBulk) OnConflict(opts ...sql.ConflictOption) *OAuthGrantUpsertBulk {
|
||||
ogcb.conflict = opts
|
||||
return &OAuthGrantUpsertBulk{
|
||||
create: ogcb,
|
||||
}
|
||||
}
|
||||
|
||||
// OnConflictColumns calls `OnConflict` and configures the columns
|
||||
// as conflict target. Using this option is equivalent to using:
|
||||
//
|
||||
// client.OAuthGrant.Create().
|
||||
// OnConflict(sql.ConflictColumns(columns...)).
|
||||
// Exec(ctx)
|
||||
func (ogcb *OAuthGrantCreateBulk) OnConflictColumns(columns ...string) *OAuthGrantUpsertBulk {
|
||||
ogcb.conflict = append(ogcb.conflict, sql.ConflictColumns(columns...))
|
||||
return &OAuthGrantUpsertBulk{
|
||||
create: ogcb,
|
||||
}
|
||||
}
|
||||
|
||||
// OAuthGrantUpsertBulk is the builder for "upsert"-ing
|
||||
// a bulk of OAuthGrant nodes.
|
||||
type OAuthGrantUpsertBulk struct {
|
||||
create *OAuthGrantCreateBulk
|
||||
}
|
||||
|
||||
// UpdateNewValues updates the mutable fields using the new values that
|
||||
// were set on create. Using this option is equivalent to using:
|
||||
//
|
||||
// client.OAuthGrant.Create().
|
||||
// OnConflict(
|
||||
// sql.ResolveWithNewValues(),
|
||||
// ).
|
||||
// Exec(ctx)
|
||||
func (u *OAuthGrantUpsertBulk) UpdateNewValues() *OAuthGrantUpsertBulk {
|
||||
u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
|
||||
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
|
||||
for _, b := range u.create.builders {
|
||||
if _, exists := b.mutation.CreatedAt(); exists {
|
||||
s.SetIgnore(oauthgrant.FieldCreatedAt)
|
||||
}
|
||||
}
|
||||
}))
|
||||
return u
|
||||
}
|
||||
|
||||
// Ignore sets each column to itself in case of conflict.
|
||||
// Using this option is equivalent to using:
|
||||
//
|
||||
// client.OAuthGrant.Create().
|
||||
// OnConflict(sql.ResolveWithIgnore()).
|
||||
// Exec(ctx)
|
||||
func (u *OAuthGrantUpsertBulk) Ignore() *OAuthGrantUpsertBulk {
|
||||
u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
|
||||
return u
|
||||
}
|
||||
|
||||
// DoNothing configures the conflict_action to `DO NOTHING`.
|
||||
// Supported only by SQLite and PostgreSQL.
|
||||
func (u *OAuthGrantUpsertBulk) DoNothing() *OAuthGrantUpsertBulk {
|
||||
u.create.conflict = append(u.create.conflict, sql.DoNothing())
|
||||
return u
|
||||
}
|
||||
|
||||
// Update allows overriding fields `UPDATE` values. See the OAuthGrantCreateBulk.OnConflict
|
||||
// documentation for more info.
|
||||
func (u *OAuthGrantUpsertBulk) Update(set func(*OAuthGrantUpsert)) *OAuthGrantUpsertBulk {
|
||||
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
|
||||
set(&OAuthGrantUpsert{UpdateSet: update})
|
||||
}))
|
||||
return u
|
||||
}
|
||||
|
||||
// SetUpdatedAt sets the "updated_at" field.
|
||||
func (u *OAuthGrantUpsertBulk) SetUpdatedAt(v time.Time) *OAuthGrantUpsertBulk {
|
||||
return u.Update(func(s *OAuthGrantUpsert) {
|
||||
s.SetUpdatedAt(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
|
||||
func (u *OAuthGrantUpsertBulk) UpdateUpdatedAt() *OAuthGrantUpsertBulk {
|
||||
return u.Update(func(s *OAuthGrantUpsert) {
|
||||
s.UpdateUpdatedAt()
|
||||
})
|
||||
}
|
||||
|
||||
// SetDeletedAt sets the "deleted_at" field.
|
||||
func (u *OAuthGrantUpsertBulk) SetDeletedAt(v time.Time) *OAuthGrantUpsertBulk {
|
||||
return u.Update(func(s *OAuthGrantUpsert) {
|
||||
s.SetDeletedAt(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
|
||||
func (u *OAuthGrantUpsertBulk) UpdateDeletedAt() *OAuthGrantUpsertBulk {
|
||||
return u.Update(func(s *OAuthGrantUpsert) {
|
||||
s.UpdateDeletedAt()
|
||||
})
|
||||
}
|
||||
|
||||
// ClearDeletedAt clears the value of the "deleted_at" field.
|
||||
func (u *OAuthGrantUpsertBulk) ClearDeletedAt() *OAuthGrantUpsertBulk {
|
||||
return u.Update(func(s *OAuthGrantUpsert) {
|
||||
s.ClearDeletedAt()
|
||||
})
|
||||
}
|
||||
|
||||
// SetUserID sets the "user_id" field.
|
||||
func (u *OAuthGrantUpsertBulk) SetUserID(v int) *OAuthGrantUpsertBulk {
|
||||
return u.Update(func(s *OAuthGrantUpsert) {
|
||||
s.SetUserID(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateUserID sets the "user_id" field to the value that was provided on create.
|
||||
func (u *OAuthGrantUpsertBulk) UpdateUserID() *OAuthGrantUpsertBulk {
|
||||
return u.Update(func(s *OAuthGrantUpsert) {
|
||||
s.UpdateUserID()
|
||||
})
|
||||
}
|
||||
|
||||
// SetClientID sets the "client_id" field.
|
||||
func (u *OAuthGrantUpsertBulk) SetClientID(v int) *OAuthGrantUpsertBulk {
|
||||
return u.Update(func(s *OAuthGrantUpsert) {
|
||||
s.SetClientID(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateClientID sets the "client_id" field to the value that was provided on create.
|
||||
func (u *OAuthGrantUpsertBulk) UpdateClientID() *OAuthGrantUpsertBulk {
|
||||
return u.Update(func(s *OAuthGrantUpsert) {
|
||||
s.UpdateClientID()
|
||||
})
|
||||
}
|
||||
|
||||
// SetScopes sets the "scopes" field.
|
||||
func (u *OAuthGrantUpsertBulk) SetScopes(v []string) *OAuthGrantUpsertBulk {
|
||||
return u.Update(func(s *OAuthGrantUpsert) {
|
||||
s.SetScopes(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateScopes sets the "scopes" field to the value that was provided on create.
|
||||
func (u *OAuthGrantUpsertBulk) UpdateScopes() *OAuthGrantUpsertBulk {
|
||||
return u.Update(func(s *OAuthGrantUpsert) {
|
||||
s.UpdateScopes()
|
||||
})
|
||||
}
|
||||
|
||||
// SetLastUsedAt sets the "last_used_at" field.
|
||||
func (u *OAuthGrantUpsertBulk) SetLastUsedAt(v time.Time) *OAuthGrantUpsertBulk {
|
||||
return u.Update(func(s *OAuthGrantUpsert) {
|
||||
s.SetLastUsedAt(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateLastUsedAt sets the "last_used_at" field to the value that was provided on create.
|
||||
func (u *OAuthGrantUpsertBulk) UpdateLastUsedAt() *OAuthGrantUpsertBulk {
|
||||
return u.Update(func(s *OAuthGrantUpsert) {
|
||||
s.UpdateLastUsedAt()
|
||||
})
|
||||
}
|
||||
|
||||
// ClearLastUsedAt clears the value of the "last_used_at" field.
|
||||
func (u *OAuthGrantUpsertBulk) ClearLastUsedAt() *OAuthGrantUpsertBulk {
|
||||
return u.Update(func(s *OAuthGrantUpsert) {
|
||||
s.ClearLastUsedAt()
|
||||
})
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (u *OAuthGrantUpsertBulk) Exec(ctx context.Context) error {
|
||||
if u.create.err != nil {
|
||||
return u.create.err
|
||||
}
|
||||
for i, b := range u.create.builders {
|
||||
if len(b.conflict) != 0 {
|
||||
return fmt.Errorf("ent: OnConflict was set for builder %d. Set it on the OAuthGrantCreateBulk instead", i)
|
||||
}
|
||||
}
|
||||
if len(u.create.conflict) == 0 {
|
||||
return errors.New("ent: missing options for OAuthGrantCreateBulk.OnConflict")
|
||||
}
|
||||
return u.create.Exec(ctx)
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (u *OAuthGrantUpsertBulk) ExecX(ctx context.Context) {
|
||||
if err := u.create.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,88 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
"github.com/cloudreve/Cloudreve/v4/ent/oauthgrant"
|
||||
"github.com/cloudreve/Cloudreve/v4/ent/predicate"
|
||||
)
|
||||
|
||||
// OAuthGrantDelete is the builder for deleting a OAuthGrant entity.
|
||||
type OAuthGrantDelete struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *OAuthGrantMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the OAuthGrantDelete builder.
|
||||
func (ogd *OAuthGrantDelete) Where(ps ...predicate.OAuthGrant) *OAuthGrantDelete {
|
||||
ogd.mutation.Where(ps...)
|
||||
return ogd
|
||||
}
|
||||
|
||||
// Exec executes the deletion query and returns how many vertices were deleted.
|
||||
func (ogd *OAuthGrantDelete) Exec(ctx context.Context) (int, error) {
|
||||
return withHooks(ctx, ogd.sqlExec, ogd.mutation, ogd.hooks)
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (ogd *OAuthGrantDelete) ExecX(ctx context.Context) int {
|
||||
n, err := ogd.Exec(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func (ogd *OAuthGrantDelete) sqlExec(ctx context.Context) (int, error) {
|
||||
_spec := sqlgraph.NewDeleteSpec(oauthgrant.Table, sqlgraph.NewFieldSpec(oauthgrant.FieldID, field.TypeInt))
|
||||
if ps := ogd.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
affected, err := sqlgraph.DeleteNodes(ctx, ogd.driver, _spec)
|
||||
if err != nil && sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
ogd.mutation.done = true
|
||||
return affected, err
|
||||
}
|
||||
|
||||
// OAuthGrantDeleteOne is the builder for deleting a single OAuthGrant entity.
|
||||
type OAuthGrantDeleteOne struct {
|
||||
ogd *OAuthGrantDelete
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the OAuthGrantDelete builder.
|
||||
func (ogdo *OAuthGrantDeleteOne) Where(ps ...predicate.OAuthGrant) *OAuthGrantDeleteOne {
|
||||
ogdo.ogd.mutation.Where(ps...)
|
||||
return ogdo
|
||||
}
|
||||
|
||||
// Exec executes the deletion query.
|
||||
func (ogdo *OAuthGrantDeleteOne) Exec(ctx context.Context) error {
|
||||
n, err := ogdo.ogd.Exec(ctx)
|
||||
switch {
|
||||
case err != nil:
|
||||
return err
|
||||
case n == 0:
|
||||
return &NotFoundError{oauthgrant.Label}
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (ogdo *OAuthGrantDeleteOne) ExecX(ctx context.Context) {
|
||||
if err := ogdo.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,680 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"math"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
"github.com/cloudreve/Cloudreve/v4/ent/oauthclient"
|
||||
"github.com/cloudreve/Cloudreve/v4/ent/oauthgrant"
|
||||
"github.com/cloudreve/Cloudreve/v4/ent/predicate"
|
||||
"github.com/cloudreve/Cloudreve/v4/ent/user"
|
||||
)
|
||||
|
||||
// OAuthGrantQuery is the builder for querying OAuthGrant entities.
|
||||
type OAuthGrantQuery struct {
|
||||
config
|
||||
ctx *QueryContext
|
||||
order []oauthgrant.OrderOption
|
||||
inters []Interceptor
|
||||
predicates []predicate.OAuthGrant
|
||||
withUser *UserQuery
|
||||
withClient *OAuthClientQuery
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
}
|
||||
|
||||
// Where adds a new predicate for the OAuthGrantQuery builder.
|
||||
func (ogq *OAuthGrantQuery) Where(ps ...predicate.OAuthGrant) *OAuthGrantQuery {
|
||||
ogq.predicates = append(ogq.predicates, ps...)
|
||||
return ogq
|
||||
}
|
||||
|
||||
// Limit the number of records to be returned by this query.
|
||||
func (ogq *OAuthGrantQuery) Limit(limit int) *OAuthGrantQuery {
|
||||
ogq.ctx.Limit = &limit
|
||||
return ogq
|
||||
}
|
||||
|
||||
// Offset to start from.
|
||||
func (ogq *OAuthGrantQuery) Offset(offset int) *OAuthGrantQuery {
|
||||
ogq.ctx.Offset = &offset
|
||||
return ogq
|
||||
}
|
||||
|
||||
// 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 (ogq *OAuthGrantQuery) Unique(unique bool) *OAuthGrantQuery {
|
||||
ogq.ctx.Unique = &unique
|
||||
return ogq
|
||||
}
|
||||
|
||||
// Order specifies how the records should be ordered.
|
||||
func (ogq *OAuthGrantQuery) Order(o ...oauthgrant.OrderOption) *OAuthGrantQuery {
|
||||
ogq.order = append(ogq.order, o...)
|
||||
return ogq
|
||||
}
|
||||
|
||||
// QueryUser chains the current query on the "user" edge.
|
||||
func (ogq *OAuthGrantQuery) QueryUser() *UserQuery {
|
||||
query := (&UserClient{config: ogq.config}).Query()
|
||||
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||||
if err := ogq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
selector := ogq.sqlQuery(ctx)
|
||||
if err := selector.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(oauthgrant.Table, oauthgrant.FieldID, selector),
|
||||
sqlgraph.To(user.Table, user.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, true, oauthgrant.UserTable, oauthgrant.UserColumn),
|
||||
)
|
||||
fromU = sqlgraph.SetNeighbors(ogq.driver.Dialect(), step)
|
||||
return fromU, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// QueryClient chains the current query on the "client" edge.
|
||||
func (ogq *OAuthGrantQuery) QueryClient() *OAuthClientQuery {
|
||||
query := (&OAuthClientClient{config: ogq.config}).Query()
|
||||
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||||
if err := ogq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
selector := ogq.sqlQuery(ctx)
|
||||
if err := selector.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(oauthgrant.Table, oauthgrant.FieldID, selector),
|
||||
sqlgraph.To(oauthclient.Table, oauthclient.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, true, oauthgrant.ClientTable, oauthgrant.ClientColumn),
|
||||
)
|
||||
fromU = sqlgraph.SetNeighbors(ogq.driver.Dialect(), step)
|
||||
return fromU, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// First returns the first OAuthGrant entity from the query.
|
||||
// Returns a *NotFoundError when no OAuthGrant was found.
|
||||
func (ogq *OAuthGrantQuery) First(ctx context.Context) (*OAuthGrant, error) {
|
||||
nodes, err := ogq.Limit(1).All(setContextOp(ctx, ogq.ctx, "First"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(nodes) == 0 {
|
||||
return nil, &NotFoundError{oauthgrant.Label}
|
||||
}
|
||||
return nodes[0], nil
|
||||
}
|
||||
|
||||
// FirstX is like First, but panics if an error occurs.
|
||||
func (ogq *OAuthGrantQuery) FirstX(ctx context.Context) *OAuthGrant {
|
||||
node, err := ogq.First(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// FirstID returns the first OAuthGrant ID from the query.
|
||||
// Returns a *NotFoundError when no OAuthGrant ID was found.
|
||||
func (ogq *OAuthGrantQuery) FirstID(ctx context.Context) (id int, err error) {
|
||||
var ids []int
|
||||
if ids, err = ogq.Limit(1).IDs(setContextOp(ctx, ogq.ctx, "FirstID")); err != nil {
|
||||
return
|
||||
}
|
||||
if len(ids) == 0 {
|
||||
err = &NotFoundError{oauthgrant.Label}
|
||||
return
|
||||
}
|
||||
return ids[0], nil
|
||||
}
|
||||
|
||||
// FirstIDX is like FirstID, but panics if an error occurs.
|
||||
func (ogq *OAuthGrantQuery) FirstIDX(ctx context.Context) int {
|
||||
id, err := ogq.FirstID(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// Only returns a single OAuthGrant entity found by the query, ensuring it only returns one.
|
||||
// Returns a *NotSingularError when more than one OAuthGrant entity is found.
|
||||
// Returns a *NotFoundError when no OAuthGrant entities are found.
|
||||
func (ogq *OAuthGrantQuery) Only(ctx context.Context) (*OAuthGrant, error) {
|
||||
nodes, err := ogq.Limit(2).All(setContextOp(ctx, ogq.ctx, "Only"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
switch len(nodes) {
|
||||
case 1:
|
||||
return nodes[0], nil
|
||||
case 0:
|
||||
return nil, &NotFoundError{oauthgrant.Label}
|
||||
default:
|
||||
return nil, &NotSingularError{oauthgrant.Label}
|
||||
}
|
||||
}
|
||||
|
||||
// OnlyX is like Only, but panics if an error occurs.
|
||||
func (ogq *OAuthGrantQuery) OnlyX(ctx context.Context) *OAuthGrant {
|
||||
node, err := ogq.Only(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// OnlyID is like Only, but returns the only OAuthGrant ID in the query.
|
||||
// Returns a *NotSingularError when more than one OAuthGrant ID is found.
|
||||
// Returns a *NotFoundError when no entities are found.
|
||||
func (ogq *OAuthGrantQuery) OnlyID(ctx context.Context) (id int, err error) {
|
||||
var ids []int
|
||||
if ids, err = ogq.Limit(2).IDs(setContextOp(ctx, ogq.ctx, "OnlyID")); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(ids) {
|
||||
case 1:
|
||||
id = ids[0]
|
||||
case 0:
|
||||
err = &NotFoundError{oauthgrant.Label}
|
||||
default:
|
||||
err = &NotSingularError{oauthgrant.Label}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// OnlyIDX is like OnlyID, but panics if an error occurs.
|
||||
func (ogq *OAuthGrantQuery) OnlyIDX(ctx context.Context) int {
|
||||
id, err := ogq.OnlyID(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// All executes the query and returns a list of OAuthGrants.
|
||||
func (ogq *OAuthGrantQuery) All(ctx context.Context) ([]*OAuthGrant, error) {
|
||||
ctx = setContextOp(ctx, ogq.ctx, "All")
|
||||
if err := ogq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
qr := querierAll[[]*OAuthGrant, *OAuthGrantQuery]()
|
||||
return withInterceptors[[]*OAuthGrant](ctx, ogq, qr, ogq.inters)
|
||||
}
|
||||
|
||||
// AllX is like All, but panics if an error occurs.
|
||||
func (ogq *OAuthGrantQuery) AllX(ctx context.Context) []*OAuthGrant {
|
||||
nodes, err := ogq.All(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return nodes
|
||||
}
|
||||
|
||||
// IDs executes the query and returns a list of OAuthGrant IDs.
|
||||
func (ogq *OAuthGrantQuery) IDs(ctx context.Context) (ids []int, err error) {
|
||||
if ogq.ctx.Unique == nil && ogq.path != nil {
|
||||
ogq.Unique(true)
|
||||
}
|
||||
ctx = setContextOp(ctx, ogq.ctx, "IDs")
|
||||
if err = ogq.Select(oauthgrant.FieldID).Scan(ctx, &ids); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
// IDsX is like IDs, but panics if an error occurs.
|
||||
func (ogq *OAuthGrantQuery) IDsX(ctx context.Context) []int {
|
||||
ids, err := ogq.IDs(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return ids
|
||||
}
|
||||
|
||||
// Count returns the count of the given query.
|
||||
func (ogq *OAuthGrantQuery) Count(ctx context.Context) (int, error) {
|
||||
ctx = setContextOp(ctx, ogq.ctx, "Count")
|
||||
if err := ogq.prepareQuery(ctx); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return withInterceptors[int](ctx, ogq, querierCount[*OAuthGrantQuery](), ogq.inters)
|
||||
}
|
||||
|
||||
// CountX is like Count, but panics if an error occurs.
|
||||
func (ogq *OAuthGrantQuery) CountX(ctx context.Context) int {
|
||||
count, err := ogq.Count(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
||||
// Exist returns true if the query has elements in the graph.
|
||||
func (ogq *OAuthGrantQuery) Exist(ctx context.Context) (bool, error) {
|
||||
ctx = setContextOp(ctx, ogq.ctx, "Exist")
|
||||
switch _, err := ogq.FirstID(ctx); {
|
||||
case IsNotFound(err):
|
||||
return false, nil
|
||||
case err != nil:
|
||||
return false, fmt.Errorf("ent: check existence: %w", err)
|
||||
default:
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
|
||||
// ExistX is like Exist, but panics if an error occurs.
|
||||
func (ogq *OAuthGrantQuery) ExistX(ctx context.Context) bool {
|
||||
exist, err := ogq.Exist(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return exist
|
||||
}
|
||||
|
||||
// Clone returns a duplicate of the OAuthGrantQuery builder, including all associated steps. It can be
|
||||
// used to prepare common query builders and use them differently after the clone is made.
|
||||
func (ogq *OAuthGrantQuery) Clone() *OAuthGrantQuery {
|
||||
if ogq == nil {
|
||||
return nil
|
||||
}
|
||||
return &OAuthGrantQuery{
|
||||
config: ogq.config,
|
||||
ctx: ogq.ctx.Clone(),
|
||||
order: append([]oauthgrant.OrderOption{}, ogq.order...),
|
||||
inters: append([]Interceptor{}, ogq.inters...),
|
||||
predicates: append([]predicate.OAuthGrant{}, ogq.predicates...),
|
||||
withUser: ogq.withUser.Clone(),
|
||||
withClient: ogq.withClient.Clone(),
|
||||
// clone intermediate query.
|
||||
sql: ogq.sql.Clone(),
|
||||
path: ogq.path,
|
||||
}
|
||||
}
|
||||
|
||||
// WithUser tells the query-builder to eager-load the nodes that are connected to
|
||||
// the "user" edge. The optional arguments are used to configure the query builder of the edge.
|
||||
func (ogq *OAuthGrantQuery) WithUser(opts ...func(*UserQuery)) *OAuthGrantQuery {
|
||||
query := (&UserClient{config: ogq.config}).Query()
|
||||
for _, opt := range opts {
|
||||
opt(query)
|
||||
}
|
||||
ogq.withUser = query
|
||||
return ogq
|
||||
}
|
||||
|
||||
// WithClient tells the query-builder to eager-load the nodes that are connected to
|
||||
// the "client" edge. The optional arguments are used to configure the query builder of the edge.
|
||||
func (ogq *OAuthGrantQuery) WithClient(opts ...func(*OAuthClientQuery)) *OAuthGrantQuery {
|
||||
query := (&OAuthClientClient{config: ogq.config}).Query()
|
||||
for _, opt := range opts {
|
||||
opt(query)
|
||||
}
|
||||
ogq.withClient = query
|
||||
return ogq
|
||||
}
|
||||
|
||||
// GroupBy is used to group vertices by one or more fields/columns.
|
||||
// It is often used with aggregate functions, like: count, max, mean, min, sum.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// var v []struct {
|
||||
// CreatedAt time.Time `json:"created_at,omitempty"`
|
||||
// Count int `json:"count,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.OAuthGrant.Query().
|
||||
// GroupBy(oauthgrant.FieldCreatedAt).
|
||||
// Aggregate(ent.Count()).
|
||||
// Scan(ctx, &v)
|
||||
func (ogq *OAuthGrantQuery) GroupBy(field string, fields ...string) *OAuthGrantGroupBy {
|
||||
ogq.ctx.Fields = append([]string{field}, fields...)
|
||||
grbuild := &OAuthGrantGroupBy{build: ogq}
|
||||
grbuild.flds = &ogq.ctx.Fields
|
||||
grbuild.label = oauthgrant.Label
|
||||
grbuild.scan = grbuild.Scan
|
||||
return grbuild
|
||||
}
|
||||
|
||||
// Select allows the selection one or more fields/columns for the given query,
|
||||
// instead of selecting all fields in the entity.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// var v []struct {
|
||||
// CreatedAt time.Time `json:"created_at,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.OAuthGrant.Query().
|
||||
// Select(oauthgrant.FieldCreatedAt).
|
||||
// Scan(ctx, &v)
|
||||
func (ogq *OAuthGrantQuery) Select(fields ...string) *OAuthGrantSelect {
|
||||
ogq.ctx.Fields = append(ogq.ctx.Fields, fields...)
|
||||
sbuild := &OAuthGrantSelect{OAuthGrantQuery: ogq}
|
||||
sbuild.label = oauthgrant.Label
|
||||
sbuild.flds, sbuild.scan = &ogq.ctx.Fields, sbuild.Scan
|
||||
return sbuild
|
||||
}
|
||||
|
||||
// Aggregate returns a OAuthGrantSelect configured with the given aggregations.
|
||||
func (ogq *OAuthGrantQuery) Aggregate(fns ...AggregateFunc) *OAuthGrantSelect {
|
||||
return ogq.Select().Aggregate(fns...)
|
||||
}
|
||||
|
||||
func (ogq *OAuthGrantQuery) prepareQuery(ctx context.Context) error {
|
||||
for _, inter := range ogq.inters {
|
||||
if inter == nil {
|
||||
return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)")
|
||||
}
|
||||
if trv, ok := inter.(Traverser); ok {
|
||||
if err := trv.Traverse(ctx, ogq); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, f := range ogq.ctx.Fields {
|
||||
if !oauthgrant.ValidColumn(f) {
|
||||
return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||
}
|
||||
}
|
||||
if ogq.path != nil {
|
||||
prev, err := ogq.path(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
ogq.sql = prev
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ogq *OAuthGrantQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*OAuthGrant, error) {
|
||||
var (
|
||||
nodes = []*OAuthGrant{}
|
||||
_spec = ogq.querySpec()
|
||||
loadedTypes = [2]bool{
|
||||
ogq.withUser != nil,
|
||||
ogq.withClient != nil,
|
||||
}
|
||||
)
|
||||
_spec.ScanValues = func(columns []string) ([]any, error) {
|
||||
return (*OAuthGrant).scanValues(nil, columns)
|
||||
}
|
||||
_spec.Assign = func(columns []string, values []any) error {
|
||||
node := &OAuthGrant{config: ogq.config}
|
||||
nodes = append(nodes, node)
|
||||
node.Edges.loadedTypes = loadedTypes
|
||||
return node.assignValues(columns, values)
|
||||
}
|
||||
for i := range hooks {
|
||||
hooks[i](ctx, _spec)
|
||||
}
|
||||
if err := sqlgraph.QueryNodes(ctx, ogq.driver, _spec); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(nodes) == 0 {
|
||||
return nodes, nil
|
||||
}
|
||||
if query := ogq.withUser; query != nil {
|
||||
if err := ogq.loadUser(ctx, query, nodes, nil,
|
||||
func(n *OAuthGrant, e *User) { n.Edges.User = e }); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if query := ogq.withClient; query != nil {
|
||||
if err := ogq.loadClient(ctx, query, nodes, nil,
|
||||
func(n *OAuthGrant, e *OAuthClient) { n.Edges.Client = e }); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
func (ogq *OAuthGrantQuery) loadUser(ctx context.Context, query *UserQuery, nodes []*OAuthGrant, init func(*OAuthGrant), assign func(*OAuthGrant, *User)) error {
|
||||
ids := make([]int, 0, len(nodes))
|
||||
nodeids := make(map[int][]*OAuthGrant)
|
||||
for i := range nodes {
|
||||
fk := nodes[i].UserID
|
||||
if _, ok := nodeids[fk]; !ok {
|
||||
ids = append(ids, fk)
|
||||
}
|
||||
nodeids[fk] = append(nodeids[fk], nodes[i])
|
||||
}
|
||||
if len(ids) == 0 {
|
||||
return nil
|
||||
}
|
||||
query.Where(user.IDIn(ids...))
|
||||
neighbors, err := query.All(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, n := range neighbors {
|
||||
nodes, ok := nodeids[n.ID]
|
||||
if !ok {
|
||||
return fmt.Errorf(`unexpected foreign-key "user_id" returned %v`, n.ID)
|
||||
}
|
||||
for i := range nodes {
|
||||
assign(nodes[i], n)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (ogq *OAuthGrantQuery) loadClient(ctx context.Context, query *OAuthClientQuery, nodes []*OAuthGrant, init func(*OAuthGrant), assign func(*OAuthGrant, *OAuthClient)) error {
|
||||
ids := make([]int, 0, len(nodes))
|
||||
nodeids := make(map[int][]*OAuthGrant)
|
||||
for i := range nodes {
|
||||
fk := nodes[i].ClientID
|
||||
if _, ok := nodeids[fk]; !ok {
|
||||
ids = append(ids, fk)
|
||||
}
|
||||
nodeids[fk] = append(nodeids[fk], nodes[i])
|
||||
}
|
||||
if len(ids) == 0 {
|
||||
return nil
|
||||
}
|
||||
query.Where(oauthclient.IDIn(ids...))
|
||||
neighbors, err := query.All(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, n := range neighbors {
|
||||
nodes, ok := nodeids[n.ID]
|
||||
if !ok {
|
||||
return fmt.Errorf(`unexpected foreign-key "client_id" returned %v`, n.ID)
|
||||
}
|
||||
for i := range nodes {
|
||||
assign(nodes[i], n)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ogq *OAuthGrantQuery) sqlCount(ctx context.Context) (int, error) {
|
||||
_spec := ogq.querySpec()
|
||||
_spec.Node.Columns = ogq.ctx.Fields
|
||||
if len(ogq.ctx.Fields) > 0 {
|
||||
_spec.Unique = ogq.ctx.Unique != nil && *ogq.ctx.Unique
|
||||
}
|
||||
return sqlgraph.CountNodes(ctx, ogq.driver, _spec)
|
||||
}
|
||||
|
||||
func (ogq *OAuthGrantQuery) querySpec() *sqlgraph.QuerySpec {
|
||||
_spec := sqlgraph.NewQuerySpec(oauthgrant.Table, oauthgrant.Columns, sqlgraph.NewFieldSpec(oauthgrant.FieldID, field.TypeInt))
|
||||
_spec.From = ogq.sql
|
||||
if unique := ogq.ctx.Unique; unique != nil {
|
||||
_spec.Unique = *unique
|
||||
} else if ogq.path != nil {
|
||||
_spec.Unique = true
|
||||
}
|
||||
if fields := ogq.ctx.Fields; len(fields) > 0 {
|
||||
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, oauthgrant.FieldID)
|
||||
for i := range fields {
|
||||
if fields[i] != oauthgrant.FieldID {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
|
||||
}
|
||||
}
|
||||
if ogq.withUser != nil {
|
||||
_spec.Node.AddColumnOnce(oauthgrant.FieldUserID)
|
||||
}
|
||||
if ogq.withClient != nil {
|
||||
_spec.Node.AddColumnOnce(oauthgrant.FieldClientID)
|
||||
}
|
||||
}
|
||||
if ps := ogq.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if limit := ogq.ctx.Limit; limit != nil {
|
||||
_spec.Limit = *limit
|
||||
}
|
||||
if offset := ogq.ctx.Offset; offset != nil {
|
||||
_spec.Offset = *offset
|
||||
}
|
||||
if ps := ogq.order; len(ps) > 0 {
|
||||
_spec.Order = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
return _spec
|
||||
}
|
||||
|
||||
func (ogq *OAuthGrantQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
||||
builder := sql.Dialect(ogq.driver.Dialect())
|
||||
t1 := builder.Table(oauthgrant.Table)
|
||||
columns := ogq.ctx.Fields
|
||||
if len(columns) == 0 {
|
||||
columns = oauthgrant.Columns
|
||||
}
|
||||
selector := builder.Select(t1.Columns(columns...)...).From(t1)
|
||||
if ogq.sql != nil {
|
||||
selector = ogq.sql
|
||||
selector.Select(selector.Columns(columns...)...)
|
||||
}
|
||||
if ogq.ctx.Unique != nil && *ogq.ctx.Unique {
|
||||
selector.Distinct()
|
||||
}
|
||||
for _, p := range ogq.predicates {
|
||||
p(selector)
|
||||
}
|
||||
for _, p := range ogq.order {
|
||||
p(selector)
|
||||
}
|
||||
if offset := ogq.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 := ogq.ctx.Limit; limit != nil {
|
||||
selector.Limit(*limit)
|
||||
}
|
||||
return selector
|
||||
}
|
||||
|
||||
// OAuthGrantGroupBy is the group-by builder for OAuthGrant entities.
|
||||
type OAuthGrantGroupBy struct {
|
||||
selector
|
||||
build *OAuthGrantQuery
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the group-by query.
|
||||
func (oggb *OAuthGrantGroupBy) Aggregate(fns ...AggregateFunc) *OAuthGrantGroupBy {
|
||||
oggb.fns = append(oggb.fns, fns...)
|
||||
return oggb
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (oggb *OAuthGrantGroupBy) Scan(ctx context.Context, v any) error {
|
||||
ctx = setContextOp(ctx, oggb.build.ctx, "GroupBy")
|
||||
if err := oggb.build.prepareQuery(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return scanWithInterceptors[*OAuthGrantQuery, *OAuthGrantGroupBy](ctx, oggb.build, oggb, oggb.build.inters, v)
|
||||
}
|
||||
|
||||
func (oggb *OAuthGrantGroupBy) sqlScan(ctx context.Context, root *OAuthGrantQuery, v any) error {
|
||||
selector := root.sqlQuery(ctx).Select()
|
||||
aggregation := make([]string, 0, len(oggb.fns))
|
||||
for _, fn := range oggb.fns {
|
||||
aggregation = append(aggregation, fn(selector))
|
||||
}
|
||||
if len(selector.SelectedColumns()) == 0 {
|
||||
columns := make([]string, 0, len(*oggb.flds)+len(oggb.fns))
|
||||
for _, f := range *oggb.flds {
|
||||
columns = append(columns, selector.C(f))
|
||||
}
|
||||
columns = append(columns, aggregation...)
|
||||
selector.Select(columns...)
|
||||
}
|
||||
selector.GroupBy(selector.Columns(*oggb.flds...)...)
|
||||
if err := selector.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
rows := &sql.Rows{}
|
||||
query, args := selector.Query()
|
||||
if err := oggb.build.driver.Query(ctx, query, args, rows); err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
return sql.ScanSlice(rows, v)
|
||||
}
|
||||
|
||||
// OAuthGrantSelect is the builder for selecting fields of OAuthGrant entities.
|
||||
type OAuthGrantSelect struct {
|
||||
*OAuthGrantQuery
|
||||
selector
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the selector query.
|
||||
func (ogs *OAuthGrantSelect) Aggregate(fns ...AggregateFunc) *OAuthGrantSelect {
|
||||
ogs.fns = append(ogs.fns, fns...)
|
||||
return ogs
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (ogs *OAuthGrantSelect) Scan(ctx context.Context, v any) error {
|
||||
ctx = setContextOp(ctx, ogs.ctx, "Select")
|
||||
if err := ogs.prepareQuery(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return scanWithInterceptors[*OAuthGrantQuery, *OAuthGrantSelect](ctx, ogs.OAuthGrantQuery, ogs, ogs.inters, v)
|
||||
}
|
||||
|
||||
func (ogs *OAuthGrantSelect) sqlScan(ctx context.Context, root *OAuthGrantQuery, v any) error {
|
||||
selector := root.sqlQuery(ctx)
|
||||
aggregation := make([]string, 0, len(ogs.fns))
|
||||
for _, fn := range ogs.fns {
|
||||
aggregation = append(aggregation, fn(selector))
|
||||
}
|
||||
switch n := len(*ogs.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 := selector.Query()
|
||||
if err := ogs.driver.Query(ctx, query, args, rows); err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
return sql.ScanSlice(rows, v)
|
||||
}
|
||||
@ -0,0 +1,615 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/dialect/sql/sqljson"
|
||||
"entgo.io/ent/schema/field"
|
||||
"github.com/cloudreve/Cloudreve/v4/ent/oauthclient"
|
||||
"github.com/cloudreve/Cloudreve/v4/ent/oauthgrant"
|
||||
"github.com/cloudreve/Cloudreve/v4/ent/predicate"
|
||||
"github.com/cloudreve/Cloudreve/v4/ent/user"
|
||||
)
|
||||
|
||||
// OAuthGrantUpdate is the builder for updating OAuthGrant entities.
|
||||
type OAuthGrantUpdate struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *OAuthGrantMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the OAuthGrantUpdate builder.
|
||||
func (ogu *OAuthGrantUpdate) Where(ps ...predicate.OAuthGrant) *OAuthGrantUpdate {
|
||||
ogu.mutation.Where(ps...)
|
||||
return ogu
|
||||
}
|
||||
|
||||
// SetUpdatedAt sets the "updated_at" field.
|
||||
func (ogu *OAuthGrantUpdate) SetUpdatedAt(t time.Time) *OAuthGrantUpdate {
|
||||
ogu.mutation.SetUpdatedAt(t)
|
||||
return ogu
|
||||
}
|
||||
|
||||
// SetDeletedAt sets the "deleted_at" field.
|
||||
func (ogu *OAuthGrantUpdate) SetDeletedAt(t time.Time) *OAuthGrantUpdate {
|
||||
ogu.mutation.SetDeletedAt(t)
|
||||
return ogu
|
||||
}
|
||||
|
||||
// SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
|
||||
func (ogu *OAuthGrantUpdate) SetNillableDeletedAt(t *time.Time) *OAuthGrantUpdate {
|
||||
if t != nil {
|
||||
ogu.SetDeletedAt(*t)
|
||||
}
|
||||
return ogu
|
||||
}
|
||||
|
||||
// ClearDeletedAt clears the value of the "deleted_at" field.
|
||||
func (ogu *OAuthGrantUpdate) ClearDeletedAt() *OAuthGrantUpdate {
|
||||
ogu.mutation.ClearDeletedAt()
|
||||
return ogu
|
||||
}
|
||||
|
||||
// SetUserID sets the "user_id" field.
|
||||
func (ogu *OAuthGrantUpdate) SetUserID(i int) *OAuthGrantUpdate {
|
||||
ogu.mutation.SetUserID(i)
|
||||
return ogu
|
||||
}
|
||||
|
||||
// SetNillableUserID sets the "user_id" field if the given value is not nil.
|
||||
func (ogu *OAuthGrantUpdate) SetNillableUserID(i *int) *OAuthGrantUpdate {
|
||||
if i != nil {
|
||||
ogu.SetUserID(*i)
|
||||
}
|
||||
return ogu
|
||||
}
|
||||
|
||||
// SetClientID sets the "client_id" field.
|
||||
func (ogu *OAuthGrantUpdate) SetClientID(i int) *OAuthGrantUpdate {
|
||||
ogu.mutation.SetClientID(i)
|
||||
return ogu
|
||||
}
|
||||
|
||||
// SetNillableClientID sets the "client_id" field if the given value is not nil.
|
||||
func (ogu *OAuthGrantUpdate) SetNillableClientID(i *int) *OAuthGrantUpdate {
|
||||
if i != nil {
|
||||
ogu.SetClientID(*i)
|
||||
}
|
||||
return ogu
|
||||
}
|
||||
|
||||
// SetScopes sets the "scopes" field.
|
||||
func (ogu *OAuthGrantUpdate) SetScopes(s []string) *OAuthGrantUpdate {
|
||||
ogu.mutation.SetScopes(s)
|
||||
return ogu
|
||||
}
|
||||
|
||||
// AppendScopes appends s to the "scopes" field.
|
||||
func (ogu *OAuthGrantUpdate) AppendScopes(s []string) *OAuthGrantUpdate {
|
||||
ogu.mutation.AppendScopes(s)
|
||||
return ogu
|
||||
}
|
||||
|
||||
// SetLastUsedAt sets the "last_used_at" field.
|
||||
func (ogu *OAuthGrantUpdate) SetLastUsedAt(t time.Time) *OAuthGrantUpdate {
|
||||
ogu.mutation.SetLastUsedAt(t)
|
||||
return ogu
|
||||
}
|
||||
|
||||
// SetNillableLastUsedAt sets the "last_used_at" field if the given value is not nil.
|
||||
func (ogu *OAuthGrantUpdate) SetNillableLastUsedAt(t *time.Time) *OAuthGrantUpdate {
|
||||
if t != nil {
|
||||
ogu.SetLastUsedAt(*t)
|
||||
}
|
||||
return ogu
|
||||
}
|
||||
|
||||
// ClearLastUsedAt clears the value of the "last_used_at" field.
|
||||
func (ogu *OAuthGrantUpdate) ClearLastUsedAt() *OAuthGrantUpdate {
|
||||
ogu.mutation.ClearLastUsedAt()
|
||||
return ogu
|
||||
}
|
||||
|
||||
// SetUser sets the "user" edge to the User entity.
|
||||
func (ogu *OAuthGrantUpdate) SetUser(u *User) *OAuthGrantUpdate {
|
||||
return ogu.SetUserID(u.ID)
|
||||
}
|
||||
|
||||
// SetClient sets the "client" edge to the OAuthClient entity.
|
||||
func (ogu *OAuthGrantUpdate) SetClient(o *OAuthClient) *OAuthGrantUpdate {
|
||||
return ogu.SetClientID(o.ID)
|
||||
}
|
||||
|
||||
// Mutation returns the OAuthGrantMutation object of the builder.
|
||||
func (ogu *OAuthGrantUpdate) Mutation() *OAuthGrantMutation {
|
||||
return ogu.mutation
|
||||
}
|
||||
|
||||
// ClearUser clears the "user" edge to the User entity.
|
||||
func (ogu *OAuthGrantUpdate) ClearUser() *OAuthGrantUpdate {
|
||||
ogu.mutation.ClearUser()
|
||||
return ogu
|
||||
}
|
||||
|
||||
// ClearClient clears the "client" edge to the OAuthClient entity.
|
||||
func (ogu *OAuthGrantUpdate) ClearClient() *OAuthGrantUpdate {
|
||||
ogu.mutation.ClearClient()
|
||||
return ogu
|
||||
}
|
||||
|
||||
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||
func (ogu *OAuthGrantUpdate) Save(ctx context.Context) (int, error) {
|
||||
if err := ogu.defaults(); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return withHooks(ctx, ogu.sqlSave, ogu.mutation, ogu.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (ogu *OAuthGrantUpdate) SaveX(ctx context.Context) int {
|
||||
affected, err := ogu.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return affected
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (ogu *OAuthGrantUpdate) Exec(ctx context.Context) error {
|
||||
_, err := ogu.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (ogu *OAuthGrantUpdate) ExecX(ctx context.Context) {
|
||||
if err := ogu.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// defaults sets the default values of the builder before save.
|
||||
func (ogu *OAuthGrantUpdate) defaults() error {
|
||||
if _, ok := ogu.mutation.UpdatedAt(); !ok {
|
||||
if oauthgrant.UpdateDefaultUpdatedAt == nil {
|
||||
return fmt.Errorf("ent: uninitialized oauthgrant.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
|
||||
}
|
||||
v := oauthgrant.UpdateDefaultUpdatedAt()
|
||||
ogu.mutation.SetUpdatedAt(v)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (ogu *OAuthGrantUpdate) check() error {
|
||||
if _, ok := ogu.mutation.UserID(); ogu.mutation.UserCleared() && !ok {
|
||||
return errors.New(`ent: clearing a required unique edge "OAuthGrant.user"`)
|
||||
}
|
||||
if _, ok := ogu.mutation.ClientID(); ogu.mutation.ClientCleared() && !ok {
|
||||
return errors.New(`ent: clearing a required unique edge "OAuthGrant.client"`)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ogu *OAuthGrantUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
if err := ogu.check(); err != nil {
|
||||
return n, err
|
||||
}
|
||||
_spec := sqlgraph.NewUpdateSpec(oauthgrant.Table, oauthgrant.Columns, sqlgraph.NewFieldSpec(oauthgrant.FieldID, field.TypeInt))
|
||||
if ps := ogu.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if value, ok := ogu.mutation.UpdatedAt(); ok {
|
||||
_spec.SetField(oauthgrant.FieldUpdatedAt, field.TypeTime, value)
|
||||
}
|
||||
if value, ok := ogu.mutation.DeletedAt(); ok {
|
||||
_spec.SetField(oauthgrant.FieldDeletedAt, field.TypeTime, value)
|
||||
}
|
||||
if ogu.mutation.DeletedAtCleared() {
|
||||
_spec.ClearField(oauthgrant.FieldDeletedAt, field.TypeTime)
|
||||
}
|
||||
if value, ok := ogu.mutation.Scopes(); ok {
|
||||
_spec.SetField(oauthgrant.FieldScopes, field.TypeJSON, value)
|
||||
}
|
||||
if value, ok := ogu.mutation.AppendedScopes(); ok {
|
||||
_spec.AddModifier(func(u *sql.UpdateBuilder) {
|
||||
sqljson.Append(u, oauthgrant.FieldScopes, value)
|
||||
})
|
||||
}
|
||||
if value, ok := ogu.mutation.LastUsedAt(); ok {
|
||||
_spec.SetField(oauthgrant.FieldLastUsedAt, field.TypeTime, value)
|
||||
}
|
||||
if ogu.mutation.LastUsedAtCleared() {
|
||||
_spec.ClearField(oauthgrant.FieldLastUsedAt, field.TypeTime)
|
||||
}
|
||||
if ogu.mutation.UserCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
Table: oauthgrant.UserTable,
|
||||
Columns: []string{oauthgrant.UserColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := ogu.mutation.UserIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
Table: oauthgrant.UserTable,
|
||||
Columns: []string{oauthgrant.UserColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
if ogu.mutation.ClientCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
Table: oauthgrant.ClientTable,
|
||||
Columns: []string{oauthgrant.ClientColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(oauthclient.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := ogu.mutation.ClientIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
Table: oauthgrant.ClientTable,
|
||||
Columns: []string{oauthgrant.ClientColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(oauthclient.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
if n, err = sqlgraph.UpdateNodes(ctx, ogu.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{oauthgrant.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
ogu.mutation.done = true
|
||||
return n, nil
|
||||
}
|
||||
|
||||
// OAuthGrantUpdateOne is the builder for updating a single OAuthGrant entity.
|
||||
type OAuthGrantUpdateOne struct {
|
||||
config
|
||||
fields []string
|
||||
hooks []Hook
|
||||
mutation *OAuthGrantMutation
|
||||
}
|
||||
|
||||
// SetUpdatedAt sets the "updated_at" field.
|
||||
func (oguo *OAuthGrantUpdateOne) SetUpdatedAt(t time.Time) *OAuthGrantUpdateOne {
|
||||
oguo.mutation.SetUpdatedAt(t)
|
||||
return oguo
|
||||
}
|
||||
|
||||
// SetDeletedAt sets the "deleted_at" field.
|
||||
func (oguo *OAuthGrantUpdateOne) SetDeletedAt(t time.Time) *OAuthGrantUpdateOne {
|
||||
oguo.mutation.SetDeletedAt(t)
|
||||
return oguo
|
||||
}
|
||||
|
||||
// SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
|
||||
func (oguo *OAuthGrantUpdateOne) SetNillableDeletedAt(t *time.Time) *OAuthGrantUpdateOne {
|
||||
if t != nil {
|
||||
oguo.SetDeletedAt(*t)
|
||||
}
|
||||
return oguo
|
||||
}
|
||||
|
||||
// ClearDeletedAt clears the value of the "deleted_at" field.
|
||||
func (oguo *OAuthGrantUpdateOne) ClearDeletedAt() *OAuthGrantUpdateOne {
|
||||
oguo.mutation.ClearDeletedAt()
|
||||
return oguo
|
||||
}
|
||||
|
||||
// SetUserID sets the "user_id" field.
|
||||
func (oguo *OAuthGrantUpdateOne) SetUserID(i int) *OAuthGrantUpdateOne {
|
||||
oguo.mutation.SetUserID(i)
|
||||
return oguo
|
||||
}
|
||||
|
||||
// SetNillableUserID sets the "user_id" field if the given value is not nil.
|
||||
func (oguo *OAuthGrantUpdateOne) SetNillableUserID(i *int) *OAuthGrantUpdateOne {
|
||||
if i != nil {
|
||||
oguo.SetUserID(*i)
|
||||
}
|
||||
return oguo
|
||||
}
|
||||
|
||||
// SetClientID sets the "client_id" field.
|
||||
func (oguo *OAuthGrantUpdateOne) SetClientID(i int) *OAuthGrantUpdateOne {
|
||||
oguo.mutation.SetClientID(i)
|
||||
return oguo
|
||||
}
|
||||
|
||||
// SetNillableClientID sets the "client_id" field if the given value is not nil.
|
||||
func (oguo *OAuthGrantUpdateOne) SetNillableClientID(i *int) *OAuthGrantUpdateOne {
|
||||
if i != nil {
|
||||
oguo.SetClientID(*i)
|
||||
}
|
||||
return oguo
|
||||
}
|
||||
|
||||
// SetScopes sets the "scopes" field.
|
||||
func (oguo *OAuthGrantUpdateOne) SetScopes(s []string) *OAuthGrantUpdateOne {
|
||||
oguo.mutation.SetScopes(s)
|
||||
return oguo
|
||||
}
|
||||
|
||||
// AppendScopes appends s to the "scopes" field.
|
||||
func (oguo *OAuthGrantUpdateOne) AppendScopes(s []string) *OAuthGrantUpdateOne {
|
||||
oguo.mutation.AppendScopes(s)
|
||||
return oguo
|
||||
}
|
||||
|
||||
// SetLastUsedAt sets the "last_used_at" field.
|
||||
func (oguo *OAuthGrantUpdateOne) SetLastUsedAt(t time.Time) *OAuthGrantUpdateOne {
|
||||
oguo.mutation.SetLastUsedAt(t)
|
||||
return oguo
|
||||
}
|
||||
|
||||
// SetNillableLastUsedAt sets the "last_used_at" field if the given value is not nil.
|
||||
func (oguo *OAuthGrantUpdateOne) SetNillableLastUsedAt(t *time.Time) *OAuthGrantUpdateOne {
|
||||
if t != nil {
|
||||
oguo.SetLastUsedAt(*t)
|
||||
}
|
||||
return oguo
|
||||
}
|
||||
|
||||
// ClearLastUsedAt clears the value of the "last_used_at" field.
|
||||
func (oguo *OAuthGrantUpdateOne) ClearLastUsedAt() *OAuthGrantUpdateOne {
|
||||
oguo.mutation.ClearLastUsedAt()
|
||||
return oguo
|
||||
}
|
||||
|
||||
// SetUser sets the "user" edge to the User entity.
|
||||
func (oguo *OAuthGrantUpdateOne) SetUser(u *User) *OAuthGrantUpdateOne {
|
||||
return oguo.SetUserID(u.ID)
|
||||
}
|
||||
|
||||
// SetClient sets the "client" edge to the OAuthClient entity.
|
||||
func (oguo *OAuthGrantUpdateOne) SetClient(o *OAuthClient) *OAuthGrantUpdateOne {
|
||||
return oguo.SetClientID(o.ID)
|
||||
}
|
||||
|
||||
// Mutation returns the OAuthGrantMutation object of the builder.
|
||||
func (oguo *OAuthGrantUpdateOne) Mutation() *OAuthGrantMutation {
|
||||
return oguo.mutation
|
||||
}
|
||||
|
||||
// ClearUser clears the "user" edge to the User entity.
|
||||
func (oguo *OAuthGrantUpdateOne) ClearUser() *OAuthGrantUpdateOne {
|
||||
oguo.mutation.ClearUser()
|
||||
return oguo
|
||||
}
|
||||
|
||||
// ClearClient clears the "client" edge to the OAuthClient entity.
|
||||
func (oguo *OAuthGrantUpdateOne) ClearClient() *OAuthGrantUpdateOne {
|
||||
oguo.mutation.ClearClient()
|
||||
return oguo
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the OAuthGrantUpdate builder.
|
||||
func (oguo *OAuthGrantUpdateOne) Where(ps ...predicate.OAuthGrant) *OAuthGrantUpdateOne {
|
||||
oguo.mutation.Where(ps...)
|
||||
return oguo
|
||||
}
|
||||
|
||||
// Select allows selecting one or more fields (columns) of the returned entity.
|
||||
// The default is selecting all fields defined in the entity schema.
|
||||
func (oguo *OAuthGrantUpdateOne) Select(field string, fields ...string) *OAuthGrantUpdateOne {
|
||||
oguo.fields = append([]string{field}, fields...)
|
||||
return oguo
|
||||
}
|
||||
|
||||
// Save executes the query and returns the updated OAuthGrant entity.
|
||||
func (oguo *OAuthGrantUpdateOne) Save(ctx context.Context) (*OAuthGrant, error) {
|
||||
if err := oguo.defaults(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return withHooks(ctx, oguo.sqlSave, oguo.mutation, oguo.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (oguo *OAuthGrantUpdateOne) SaveX(ctx context.Context) *OAuthGrant {
|
||||
node, err := oguo.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// Exec executes the query on the entity.
|
||||
func (oguo *OAuthGrantUpdateOne) Exec(ctx context.Context) error {
|
||||
_, err := oguo.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (oguo *OAuthGrantUpdateOne) ExecX(ctx context.Context) {
|
||||
if err := oguo.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// defaults sets the default values of the builder before save.
|
||||
func (oguo *OAuthGrantUpdateOne) defaults() error {
|
||||
if _, ok := oguo.mutation.UpdatedAt(); !ok {
|
||||
if oauthgrant.UpdateDefaultUpdatedAt == nil {
|
||||
return fmt.Errorf("ent: uninitialized oauthgrant.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
|
||||
}
|
||||
v := oauthgrant.UpdateDefaultUpdatedAt()
|
||||
oguo.mutation.SetUpdatedAt(v)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (oguo *OAuthGrantUpdateOne) check() error {
|
||||
if _, ok := oguo.mutation.UserID(); oguo.mutation.UserCleared() && !ok {
|
||||
return errors.New(`ent: clearing a required unique edge "OAuthGrant.user"`)
|
||||
}
|
||||
if _, ok := oguo.mutation.ClientID(); oguo.mutation.ClientCleared() && !ok {
|
||||
return errors.New(`ent: clearing a required unique edge "OAuthGrant.client"`)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (oguo *OAuthGrantUpdateOne) sqlSave(ctx context.Context) (_node *OAuthGrant, err error) {
|
||||
if err := oguo.check(); err != nil {
|
||||
return _node, err
|
||||
}
|
||||
_spec := sqlgraph.NewUpdateSpec(oauthgrant.Table, oauthgrant.Columns, sqlgraph.NewFieldSpec(oauthgrant.FieldID, field.TypeInt))
|
||||
id, ok := oguo.mutation.ID()
|
||||
if !ok {
|
||||
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "OAuthGrant.id" for update`)}
|
||||
}
|
||||
_spec.Node.ID.Value = id
|
||||
if fields := oguo.fields; len(fields) > 0 {
|
||||
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, oauthgrant.FieldID)
|
||||
for _, f := range fields {
|
||||
if !oauthgrant.ValidColumn(f) {
|
||||
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||
}
|
||||
if f != oauthgrant.FieldID {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, f)
|
||||
}
|
||||
}
|
||||
}
|
||||
if ps := oguo.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if value, ok := oguo.mutation.UpdatedAt(); ok {
|
||||
_spec.SetField(oauthgrant.FieldUpdatedAt, field.TypeTime, value)
|
||||
}
|
||||
if value, ok := oguo.mutation.DeletedAt(); ok {
|
||||
_spec.SetField(oauthgrant.FieldDeletedAt, field.TypeTime, value)
|
||||
}
|
||||
if oguo.mutation.DeletedAtCleared() {
|
||||
_spec.ClearField(oauthgrant.FieldDeletedAt, field.TypeTime)
|
||||
}
|
||||
if value, ok := oguo.mutation.Scopes(); ok {
|
||||
_spec.SetField(oauthgrant.FieldScopes, field.TypeJSON, value)
|
||||
}
|
||||
if value, ok := oguo.mutation.AppendedScopes(); ok {
|
||||
_spec.AddModifier(func(u *sql.UpdateBuilder) {
|
||||
sqljson.Append(u, oauthgrant.FieldScopes, value)
|
||||
})
|
||||
}
|
||||
if value, ok := oguo.mutation.LastUsedAt(); ok {
|
||||
_spec.SetField(oauthgrant.FieldLastUsedAt, field.TypeTime, value)
|
||||
}
|
||||
if oguo.mutation.LastUsedAtCleared() {
|
||||
_spec.ClearField(oauthgrant.FieldLastUsedAt, field.TypeTime)
|
||||
}
|
||||
if oguo.mutation.UserCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
Table: oauthgrant.UserTable,
|
||||
Columns: []string{oauthgrant.UserColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := oguo.mutation.UserIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
Table: oauthgrant.UserTable,
|
||||
Columns: []string{oauthgrant.UserColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
if oguo.mutation.ClientCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
Table: oauthgrant.ClientTable,
|
||||
Columns: []string{oauthgrant.ClientColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(oauthclient.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := oguo.mutation.ClientIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
Table: oauthgrant.ClientTable,
|
||||
Columns: []string{oauthgrant.ClientColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(oauthclient.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
_node = &OAuthGrant{config: oguo.config}
|
||||
_spec.Assign = _node.assignValues
|
||||
_spec.ScanValues = _node.scanValues
|
||||
if err = sqlgraph.UpdateNode(ctx, oguo.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{oauthgrant.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
oguo.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
@ -0,0 +1,51 @@
|
||||
package schema
|
||||
|
||||
import (
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/schema/edge"
|
||||
"entgo.io/ent/schema/field"
|
||||
"github.com/cloudreve/Cloudreve/v4/inventory/types"
|
||||
)
|
||||
|
||||
// OAuthClient holds the schema definition for the OAuthClient entity.
|
||||
type OAuthClient struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
// Fields of the OAuthClient.
|
||||
func (OAuthClient) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.String("guid").
|
||||
MaxLen(255).
|
||||
Unique(),
|
||||
field.String("secret").
|
||||
MaxLen(255).
|
||||
Sensitive(),
|
||||
field.String("name").
|
||||
MaxLen(255),
|
||||
field.String("homepage_url").
|
||||
MaxLen(2048).
|
||||
Optional(),
|
||||
field.JSON("redirect_uris", []string{}).
|
||||
Default([]string{}),
|
||||
field.JSON("scopes", []string{}).
|
||||
Default([]string{}),
|
||||
field.JSON("props", &types.OAuthClientProps{}).
|
||||
Default(&types.OAuthClientProps{}),
|
||||
field.Bool("is_enabled").
|
||||
Default(true),
|
||||
}
|
||||
}
|
||||
|
||||
// Edges of the OAuthClient.
|
||||
func (OAuthClient) Edges() []ent.Edge {
|
||||
return []ent.Edge{
|
||||
edge.To("grants", OAuthGrant.Type),
|
||||
}
|
||||
}
|
||||
|
||||
func (OAuthClient) Mixin() []ent.Mixin {
|
||||
return []ent.Mixin{
|
||||
CommonMixin{},
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,60 @@
|
||||
package schema
|
||||
|
||||
import (
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect"
|
||||
"entgo.io/ent/schema/edge"
|
||||
"entgo.io/ent/schema/field"
|
||||
"entgo.io/ent/schema/index"
|
||||
)
|
||||
|
||||
// OAuthGrant holds the schema definition for the OAuthGrant entity.
|
||||
type OAuthGrant struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
// Fields of the OAuthGrant.
|
||||
func (OAuthGrant) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.Int("user_id"),
|
||||
field.Int("client_id"),
|
||||
field.JSON("scopes", []string{}).
|
||||
Default([]string{}),
|
||||
field.Time("last_used_at").
|
||||
Optional().
|
||||
Nillable().
|
||||
SchemaType(map[string]string{
|
||||
dialect.MySQL: "datetime",
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
// Edges of the OAuthGrant.
|
||||
func (OAuthGrant) Edges() []ent.Edge {
|
||||
return []ent.Edge{
|
||||
edge.From("user", User.Type).
|
||||
Field("user_id").
|
||||
Ref("oauth_grants").
|
||||
Unique().
|
||||
Required(),
|
||||
edge.From("client", OAuthClient.Type).
|
||||
Field("client_id").
|
||||
Ref("grants").
|
||||
Unique().
|
||||
Required(),
|
||||
}
|
||||
}
|
||||
|
||||
func (OAuthGrant) Mixin() []ent.Mixin {
|
||||
return []ent.Mixin{
|
||||
CommonMixin{},
|
||||
}
|
||||
}
|
||||
|
||||
// Indexes of the OAuthGrant.
|
||||
func (OAuthGrant) Indexes() []ent.Index {
|
||||
return []ent.Index{
|
||||
index.Fields("user_id", "client_id").
|
||||
Unique(),
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,82 @@
|
||||
package inventory
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"github.com/cloudreve/Cloudreve/v4/ent"
|
||||
"github.com/cloudreve/Cloudreve/v4/ent/oauthclient"
|
||||
"github.com/cloudreve/Cloudreve/v4/ent/oauthgrant"
|
||||
)
|
||||
|
||||
type (
|
||||
OAuthClientClient interface {
|
||||
TxOperator
|
||||
// GetByGUID returns the OAuth client by its GUID (client_id).
|
||||
GetByGUID(ctx context.Context, guid string) (*ent.OAuthClient, error)
|
||||
// GetByGUIDWithGrants returns the OAuth client by its GUID (client_id) with the grants for the user.
|
||||
GetByGUIDWithGrants(ctx context.Context, guid string, uid int) (*ent.OAuthClient, error)
|
||||
// UpsertGrant creates or updates an OAuth grant for a user and client.
|
||||
UpsertGrant(ctx context.Context, userID, clientID int, scopes []string) error
|
||||
// UpdateGrantLastUsedAt updates the last used at for an OAuth grant for a user and client.
|
||||
UpdateGrantLastUsedAt(ctx context.Context, userID, clientID int) error
|
||||
}
|
||||
)
|
||||
|
||||
func NewOAuthClientClient(client *ent.Client) OAuthClientClient {
|
||||
return &oauthClientClient{
|
||||
client: client,
|
||||
}
|
||||
}
|
||||
|
||||
type oauthClientClient struct {
|
||||
client *ent.Client
|
||||
}
|
||||
|
||||
func (c *oauthClientClient) SetClient(newClient *ent.Client) TxOperator {
|
||||
return &oauthClientClient{client: newClient}
|
||||
}
|
||||
|
||||
func (c *oauthClientClient) GetClient() *ent.Client {
|
||||
return c.client
|
||||
}
|
||||
|
||||
func (c *oauthClientClient) GetByGUID(ctx context.Context, guid string) (*ent.OAuthClient, error) {
|
||||
return c.client.OAuthClient.Query().
|
||||
Where(oauthclient.GUID(guid), oauthclient.IsEnabled(true)).
|
||||
First(ctx)
|
||||
}
|
||||
|
||||
func (c *oauthClientClient) GetByGUIDWithGrants(ctx context.Context, guid string, uid int) (*ent.OAuthClient, error) {
|
||||
stm := c.client.OAuthClient.Query().
|
||||
Where(oauthclient.GUID(guid), oauthclient.IsEnabled(true))
|
||||
if uid > 0 {
|
||||
stm.WithGrants(func(ogq *ent.OAuthGrantQuery) {
|
||||
ogq.Where(oauthgrant.UserID(uid))
|
||||
})
|
||||
}
|
||||
|
||||
return stm.First(ctx)
|
||||
}
|
||||
|
||||
func (c *oauthClientClient) UpsertGrant(ctx context.Context, userID, clientID int, scopes []string) error {
|
||||
return c.client.OAuthGrant.Create().
|
||||
SetUserID(userID).
|
||||
SetClientID(clientID).
|
||||
SetScopes(scopes).
|
||||
SetLastUsedAt(time.Now()).
|
||||
OnConflict(
|
||||
sql.ConflictColumns(oauthgrant.FieldUserID, oauthgrant.FieldClientID),
|
||||
).
|
||||
UpdateScopes().
|
||||
UpdateLastUsedAt().
|
||||
Exec(ctx)
|
||||
}
|
||||
|
||||
func (c *oauthClientClient) UpdateGrantLastUsedAt(ctx context.Context, userID, clientID int) error {
|
||||
return c.client.OAuthGrant.Update().
|
||||
Where(oauthgrant.UserID(userID), oauthgrant.ClientID(clientID)).
|
||||
SetLastUsedAt(time.Now()).
|
||||
Exec(ctx)
|
||||
}
|
||||
@ -0,0 +1,68 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"github.com/cloudreve/Cloudreve/v4/pkg/serializer"
|
||||
"github.com/cloudreve/Cloudreve/v4/service/oauth"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func GetAppRegistration(c *gin.Context) {
|
||||
service := ParametersFromContext[*oauth.GetAppRegistrationService](c, oauth.GetAppRegistrationParamCtx{})
|
||||
app, err := service.Get(c)
|
||||
if err != nil {
|
||||
c.JSON(200, serializer.Err(c, err))
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(200, serializer.Response{Data: app})
|
||||
}
|
||||
|
||||
func GrantAppConsent(c *gin.Context) {
|
||||
service := ParametersFromContext[*oauth.GrantService](c, oauth.GrantParamCtx{})
|
||||
res, err := service.Get(c)
|
||||
if err != nil {
|
||||
c.JSON(200, serializer.Err(c, err))
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(200, serializer.Response{Data: res})
|
||||
}
|
||||
|
||||
type ExchangeErrorResponse struct {
|
||||
Error string `json:"error"`
|
||||
ErrorDescription string `json:"error_description"`
|
||||
ErrorCodes []int `json:"error_codes"`
|
||||
CorrelationID string `json:"correlation_id"`
|
||||
}
|
||||
|
||||
func ExchangeToken(c *gin.Context) {
|
||||
service := ParametersFromContext[*oauth.ExchangeTokenService](c, oauth.ExchangeTokenParamCtx{})
|
||||
res, err := service.Exchange(c)
|
||||
if err != nil {
|
||||
errResp := serializer.Err(c, err)
|
||||
c.JSON(400, ExchangeErrorResponse{
|
||||
Error: errResp.Msg,
|
||||
ErrorDescription: errResp.Error,
|
||||
ErrorCodes: []int{errResp.Code},
|
||||
CorrelationID: errResp.CorrelationID,
|
||||
})
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(200, res)
|
||||
}
|
||||
|
||||
func OpenIDUserInfo(c *gin.Context) {
|
||||
service := ParametersFromContext[*oauth.UserInfoService](c, oauth.UserInfoParamCtx{})
|
||||
res, err := service.GetUserInfo(c)
|
||||
if err != nil {
|
||||
c.JSON(200, serializer.Err(c, err))
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(200, res)
|
||||
}
|
||||
@ -0,0 +1,281 @@
|
||||
package oauth
|
||||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"encoding/base64"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/cloudreve/Cloudreve/v4/application/dependency"
|
||||
"github.com/cloudreve/Cloudreve/v4/ent"
|
||||
"github.com/cloudreve/Cloudreve/v4/inventory"
|
||||
"github.com/cloudreve/Cloudreve/v4/inventory/types"
|
||||
"github.com/cloudreve/Cloudreve/v4/pkg/auth"
|
||||
"github.com/cloudreve/Cloudreve/v4/pkg/cluster/routes"
|
||||
"github.com/cloudreve/Cloudreve/v4/pkg/hashid"
|
||||
"github.com/cloudreve/Cloudreve/v4/pkg/serializer"
|
||||
"github.com/cloudreve/Cloudreve/v4/pkg/util"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type (
|
||||
GetAppRegistrationParamCtx struct{}
|
||||
GetAppRegistrationService struct {
|
||||
AppID string `uri:"app_id" binding:"required"`
|
||||
}
|
||||
)
|
||||
|
||||
func (s *GetAppRegistrationService) Get(c *gin.Context) (*AppRegistration, error) {
|
||||
dep := dependency.FromContext(c)
|
||||
oAuthClient := dep.OAuthClientClient()
|
||||
|
||||
app, err := oAuthClient.GetByGUIDWithGrants(c, s.AppID, inventory.UserIDFromContext(c))
|
||||
if err != nil {
|
||||
return nil, serializer.NewError(serializer.CodeNotFound, "App not found", err)
|
||||
}
|
||||
|
||||
var grant *ent.OAuthGrant
|
||||
if len(app.Edges.Grants) == 1 {
|
||||
grant = app.Edges.Grants[0]
|
||||
}
|
||||
|
||||
return BuildAppRegistration(app, grant), nil
|
||||
}
|
||||
|
||||
type (
|
||||
GrantParamCtx struct{}
|
||||
GrantService struct {
|
||||
ClientID string `json:"client_id" binding:"required"`
|
||||
ResponseType string `json:"response_type" binding:"required,eq=code"`
|
||||
RedirectURI string `json:"redirect_uri" binding:"required"`
|
||||
State string `json:"state" binding:"max=255"`
|
||||
Scope string `json:"scope" binding:"required"`
|
||||
CodeChallenge string `json:"code_challenge" binding:"max=255"`
|
||||
CodeChallengeMethod string `json:"code_challenge_method" binding:"eq=S256,omitempty"`
|
||||
}
|
||||
)
|
||||
|
||||
func (s *GrantService) Get(c *gin.Context) (*GrantResponse, error) {
|
||||
dep := dependency.FromContext(c)
|
||||
user := inventory.UserFromContext(c)
|
||||
kv := dep.KV()
|
||||
oAuthClient := dep.OAuthClientClient()
|
||||
|
||||
// 1. Get app registration and grant
|
||||
app, err := oAuthClient.GetByGUIDWithGrants(c, s.ClientID, user.ID)
|
||||
if err != nil {
|
||||
return nil, serializer.NewError(serializer.CodeNotFound, "App not found", err)
|
||||
}
|
||||
|
||||
// 2. Validate redirect URL: must match one of the registered redirect URIs
|
||||
redirectValid := false
|
||||
for _, uri := range app.RedirectUris {
|
||||
if uri == s.RedirectURI {
|
||||
redirectValid = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !redirectValid {
|
||||
return nil, serializer.NewError(serializer.CodeParamErr, "Invalid redirect URI", nil)
|
||||
}
|
||||
|
||||
// Parse requested scopes (space-separated per OAuth 2.0 spec)
|
||||
requestedScopes := strings.Split(s.Scope, " ")
|
||||
|
||||
// Validate requested scopes: must be a subset of registered app scopes
|
||||
if !auth.ValidateScopes(requestedScopes, app.Scopes) {
|
||||
return nil, serializer.NewError(serializer.CodeParamErr, "Invalid scope requested", nil)
|
||||
}
|
||||
|
||||
// 3. Create/update grant
|
||||
if err := oAuthClient.UpsertGrant(c, user.ID, app.ID, requestedScopes); err != nil {
|
||||
return nil, serializer.NewError(serializer.CodeDBError, "Failed to create grant", err)
|
||||
}
|
||||
|
||||
// 4. Generate code and save required state into KV for future token exchange request.
|
||||
code := util.RandStringRunesCrypto(128)
|
||||
authCode := &AuthorizationCode{
|
||||
ClientID: s.ClientID,
|
||||
UserID: user.ID,
|
||||
Scopes: requestedScopes,
|
||||
RedirectURI: s.RedirectURI,
|
||||
CodeChallenge: s.CodeChallenge,
|
||||
}
|
||||
|
||||
// Store auth code in KV with 10 minute TTL
|
||||
if err := kv.Set(authCodeKey(code), authCode, 600); err != nil {
|
||||
return nil, serializer.NewError(serializer.CodeCacheOperation, "Failed to store authorization code", err)
|
||||
}
|
||||
|
||||
return &GrantResponse{
|
||||
Code: code,
|
||||
State: s.State,
|
||||
}, nil
|
||||
}
|
||||
|
||||
type (
|
||||
ExchangeTokenParamCtx struct{}
|
||||
ExchangeTokenService struct {
|
||||
ClientID string `form:"client_id" binding:"required"`
|
||||
ClientSecret string `form:"client_secret" binding:"required"`
|
||||
GrantType string `form:"grant_type" binding:"required,eq=authorization_code"`
|
||||
Code string `form:"code" binding:"required"`
|
||||
CodeVerifier string `form:"code_verifier"`
|
||||
}
|
||||
)
|
||||
|
||||
func (s *ExchangeTokenService) Exchange(c *gin.Context) (*TokenResponse, error) {
|
||||
dep := dependency.FromContext(c)
|
||||
kv := dep.KV()
|
||||
oAuthClient := dep.OAuthClientClient()
|
||||
userClient := dep.UserClient()
|
||||
tokenAuth := dep.TokenAuth()
|
||||
|
||||
// 1. Retrieve and validate authorization code from KV
|
||||
codeKey := authCodeKey(s.Code)
|
||||
authCodeRaw, ok := kv.Get(codeKey)
|
||||
if !ok {
|
||||
return nil, serializer.NewError(serializer.CodeCredentialInvalid, "Invalid or expired authorization code", nil)
|
||||
}
|
||||
|
||||
authCode, ok := authCodeRaw.(*AuthorizationCode)
|
||||
if !ok {
|
||||
return nil, serializer.NewError(serializer.CodeCredentialInvalid, "Invalid authorization code", nil)
|
||||
}
|
||||
|
||||
// Delete the code immediately to prevent replay attacks
|
||||
_ = kv.Delete("", codeKey)
|
||||
|
||||
// 2. Validate client_id matches the one in authorization code
|
||||
if authCode.ClientID != s.ClientID {
|
||||
return nil, serializer.NewError(serializer.CodeCredentialInvalid, "Client ID mismatch", nil)
|
||||
}
|
||||
|
||||
// 3. Verify PKCE: SHA256(code_verifier) should match code_challenge
|
||||
if authCode.CodeChallenge != "" {
|
||||
verifierHash := sha256.Sum256([]byte(s.CodeVerifier))
|
||||
expectedChallenge := base64.RawURLEncoding.EncodeToString(verifierHash[:])
|
||||
if expectedChallenge != authCode.CodeChallenge {
|
||||
return nil, serializer.NewError(serializer.CodeCredentialInvalid, "Invalid code verifier", nil)
|
||||
}
|
||||
}
|
||||
|
||||
// 4. Validate client secret
|
||||
app, err := oAuthClient.GetByGUID(c, s.ClientID)
|
||||
if err != nil {
|
||||
return nil, serializer.NewError(serializer.CodeNotFound, "App not found", err)
|
||||
}
|
||||
|
||||
if app.Secret != s.ClientSecret {
|
||||
return nil, serializer.NewError(serializer.CodeCredentialInvalid, "Invalid client secret", nil)
|
||||
}
|
||||
|
||||
// 5. Validate scopes are still valid for this app
|
||||
if !auth.ValidateScopes(authCode.Scopes, app.Scopes) {
|
||||
return nil, serializer.NewError(serializer.CodeParamErr, "Invalid scope", nil)
|
||||
}
|
||||
|
||||
// 6. Get user
|
||||
user, err := userClient.GetActiveByID(c, authCode.UserID)
|
||||
if err != nil {
|
||||
return nil, serializer.NewError(serializer.CodeUserNotFound, "User not found", err)
|
||||
}
|
||||
|
||||
// 7. Determine refresh token TTL override from app settings
|
||||
var refreshTTLOverride time.Duration
|
||||
if app.Props != nil && app.Props.RefreshTokenTTL > 0 {
|
||||
refreshTTLOverride = time.Duration(app.Props.RefreshTokenTTL) * time.Second
|
||||
}
|
||||
|
||||
// 8. Issue tokens
|
||||
token, err := tokenAuth.Issue(c, &auth.IssueTokenArgs{
|
||||
User: user,
|
||||
ClientID: s.ClientID,
|
||||
Scopes: authCode.Scopes,
|
||||
RefreshTTLOverride: refreshTTLOverride,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, serializer.NewError(serializer.CodeCredentialInvalid, "Failed to issue token", err)
|
||||
}
|
||||
|
||||
// 9. Update grant last used at
|
||||
if err := oAuthClient.UpdateGrantLastUsedAt(c, user.ID, app.ID); err != nil {
|
||||
dep.Logger().Warning("Failed to update grant last used at: %s", err)
|
||||
}
|
||||
|
||||
// 10.
|
||||
|
||||
// 11. Build response, only include refresh token if offline_access scope is present
|
||||
resp := &TokenResponse{
|
||||
AccessToken: token.AccessToken,
|
||||
TokenType: "Bearer",
|
||||
ExpiresIn: int64(time.Until(token.AccessExpires).Seconds()),
|
||||
RefreshTokenExpiresIn: int64(time.Until(token.RefreshExpires).Seconds()),
|
||||
Scope: strings.Join(authCode.Scopes, " "),
|
||||
}
|
||||
|
||||
for _, scope := range authCode.Scopes {
|
||||
if scope == types.ScopeOfflineAccess {
|
||||
resp.RefreshToken = token.RefreshToken
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
type (
|
||||
UserInfoParamCtx struct{}
|
||||
UserInfoService struct{}
|
||||
)
|
||||
|
||||
// GetUserInfo returns OpenID Connect userinfo based on the access token's scopes.
|
||||
// The response fields are conditionally included based on granted scopes:
|
||||
// - openid: sub (always required)
|
||||
// - profile: name, preferred_username, picture, updated_at
|
||||
// - email: email, email_verified
|
||||
func (s *UserInfoService) GetUserInfo(c *gin.Context) (*UserInfoResponse, error) {
|
||||
dep := dependency.FromContext(c)
|
||||
u := inventory.UserFromContext(c)
|
||||
hashIDEncoder := dep.HashIDEncoder()
|
||||
|
||||
// 1. Get and parse the access token from Authorization header
|
||||
hasScopes, scopes := auth.GetScopesFromContext(c)
|
||||
if hasScopes {
|
||||
// 2. Verify openid scope is present (required for userinfo endpoint)
|
||||
hasOpenID := false
|
||||
for _, scope := range scopes {
|
||||
if scope == types.ScopeOpenID {
|
||||
hasOpenID = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !hasOpenID {
|
||||
return nil, serializer.NewError(serializer.CodeNoPermissionErr, "openid scope required", nil)
|
||||
}
|
||||
} else {
|
||||
scopes = []string{types.ScopeOpenID, types.ScopeProfile, types.ScopeEmail}
|
||||
}
|
||||
|
||||
// 4. Build response based on scopes
|
||||
resp := &UserInfoResponse{
|
||||
Sub: hashid.EncodeUserID(hashIDEncoder, u.ID),
|
||||
}
|
||||
|
||||
// Check scopes and populate fields accordingly
|
||||
for _, scope := range scopes {
|
||||
switch scope {
|
||||
case types.ScopeProfile:
|
||||
siteUrl := dep.SettingProvider().SiteURL(c)
|
||||
resp.Name = u.Nick
|
||||
resp.PreferredUsername = u.Nick
|
||||
resp.Picture = routes.MasterUserAvatarUrl(siteUrl, hashid.EncodeUserID(hashIDEncoder, u.ID)).String()
|
||||
resp.UpdatedAt = u.UpdatedAt.Unix()
|
||||
case types.ScopeEmail:
|
||||
resp.Email = u.Email
|
||||
resp.EmailVerified = true // Users in Cloudreve have verified emails
|
||||
}
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
@ -0,0 +1,89 @@
|
||||
package oauth
|
||||
|
||||
import (
|
||||
"encoding/gob"
|
||||
|
||||
"github.com/cloudreve/Cloudreve/v4/ent"
|
||||
)
|
||||
|
||||
const (
|
||||
authCodeKeyPrefix = "oauth_code_"
|
||||
)
|
||||
|
||||
type AppRegistration struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
HomepageURL string `json:"homepage_url,omitempty"`
|
||||
Icon string `json:"icon,omitempty"`
|
||||
Description string `json:"description,omitempty"`
|
||||
ConstentedScopes []string `json:"consented_scopes,omitempty"`
|
||||
}
|
||||
|
||||
func BuildAppRegistration(app *ent.OAuthClient, grant *ent.OAuthGrant) *AppRegistration {
|
||||
res := &AppRegistration{
|
||||
ID: app.GUID,
|
||||
Name: app.Name,
|
||||
HomepageURL: app.HomepageURL,
|
||||
}
|
||||
|
||||
if app.Props != nil {
|
||||
res.Description = app.Props.Description
|
||||
res.Icon = app.Props.Icon
|
||||
}
|
||||
|
||||
if grant != nil {
|
||||
res.ConstentedScopes = grant.Scopes
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
type GrantResponse struct {
|
||||
Code string `json:"code"`
|
||||
State string `json:"state"`
|
||||
}
|
||||
|
||||
// TokenResponse represents the OAuth token response.
|
||||
type TokenResponse struct {
|
||||
AccessToken string `json:"access_token"`
|
||||
TokenType string `json:"token_type"`
|
||||
ExpiresIn int64 `json:"expires_in"`
|
||||
RefreshTokenExpiresIn int64 `json:"refresh_token_expires_in"`
|
||||
RefreshToken string `json:"refresh_token,omitempty"`
|
||||
Scope string `json:"scope"`
|
||||
}
|
||||
|
||||
// UserInfoResponse represents the OpenID Connect userinfo response.
|
||||
// Fields are conditionally included based on granted scopes.
|
||||
type UserInfoResponse struct {
|
||||
// Always included (openid scope)
|
||||
Sub string `json:"sub"`
|
||||
|
||||
// Profile scope
|
||||
Name string `json:"name,omitempty"`
|
||||
PreferredUsername string `json:"preferred_username,omitempty"`
|
||||
Picture string `json:"picture,omitempty"`
|
||||
UpdatedAt int64 `json:"updated_at,omitempty"`
|
||||
|
||||
// Email scope
|
||||
Email string `json:"email,omitempty"`
|
||||
EmailVerified bool `json:"email_verified,omitempty"`
|
||||
}
|
||||
|
||||
// AuthorizationCode represents the data stored in KV for an OAuth authorization code.
|
||||
// Used for PKCE verification during token exchange.
|
||||
type AuthorizationCode struct {
|
||||
ClientID string `json:"client_id"`
|
||||
UserID int `json:"user_id"`
|
||||
Scopes []string `json:"scopes"`
|
||||
RedirectURI string `json:"redirect_uri"`
|
||||
CodeChallenge string `json:"code_challenge"`
|
||||
}
|
||||
|
||||
func authCodeKey(code string) string {
|
||||
return authCodeKeyPrefix + code
|
||||
}
|
||||
|
||||
func init() {
|
||||
gob.Register(&AuthorizationCode{})
|
||||
}
|
||||
Loading…
Reference in new issue