mirror of https://github.com/dexidp/dex.git
27 changed files with 3272 additions and 6 deletions
@ -0,0 +1,108 @@ |
|||||||
|
package client |
||||||
|
|
||||||
|
import ( |
||||||
|
"context" |
||||||
|
"encoding/json" |
||||||
|
"fmt" |
||||||
|
|
||||||
|
"github.com/dexidp/dex/storage" |
||||||
|
) |
||||||
|
|
||||||
|
// CreateAuthSession saves provided auth session into the database.
|
||||||
|
func (d *Database) CreateAuthSession(ctx context.Context, session storage.AuthSession) error { |
||||||
|
if session.ClientStates == nil { |
||||||
|
session.ClientStates = make(map[string]*storage.ClientAuthState) |
||||||
|
} |
||||||
|
encodedStates, err := json.Marshal(session.ClientStates) |
||||||
|
if err != nil { |
||||||
|
return fmt.Errorf("encode client states auth session: %w", err) |
||||||
|
} |
||||||
|
|
||||||
|
_, err = d.client.AuthSession.Create(). |
||||||
|
SetID(session.ID). |
||||||
|
SetClientStates(encodedStates). |
||||||
|
SetCreatedAt(session.CreatedAt). |
||||||
|
SetLastActivity(session.LastActivity). |
||||||
|
SetIPAddress(session.IPAddress). |
||||||
|
SetUserAgent(session.UserAgent). |
||||||
|
Save(ctx) |
||||||
|
if err != nil { |
||||||
|
return convertDBError("create auth session: %w", err) |
||||||
|
} |
||||||
|
return nil |
||||||
|
} |
||||||
|
|
||||||
|
// GetAuthSession extracts an auth session from the database by session ID.
|
||||||
|
func (d *Database) GetAuthSession(ctx context.Context, sessionID string) (storage.AuthSession, error) { |
||||||
|
authSession, err := d.client.AuthSession.Get(ctx, sessionID) |
||||||
|
if err != nil { |
||||||
|
return storage.AuthSession{}, convertDBError("get auth session: %w", err) |
||||||
|
} |
||||||
|
return toStorageAuthSession(authSession), nil |
||||||
|
} |
||||||
|
|
||||||
|
// ListAuthSessions extracts all auth sessions from the database.
|
||||||
|
func (d *Database) ListAuthSessions(ctx context.Context) ([]storage.AuthSession, error) { |
||||||
|
authSessions, err := d.client.AuthSession.Query().All(ctx) |
||||||
|
if err != nil { |
||||||
|
return nil, convertDBError("list auth sessions: %w", err) |
||||||
|
} |
||||||
|
|
||||||
|
storageAuthSessions := make([]storage.AuthSession, 0, len(authSessions)) |
||||||
|
for _, s := range authSessions { |
||||||
|
storageAuthSessions = append(storageAuthSessions, toStorageAuthSession(s)) |
||||||
|
} |
||||||
|
return storageAuthSessions, nil |
||||||
|
} |
||||||
|
|
||||||
|
// DeleteAuthSession deletes an auth session from the database by session ID.
|
||||||
|
func (d *Database) DeleteAuthSession(ctx context.Context, sessionID string) error { |
||||||
|
err := d.client.AuthSession.DeleteOneID(sessionID).Exec(ctx) |
||||||
|
if err != nil { |
||||||
|
return convertDBError("delete auth session: %w", err) |
||||||
|
} |
||||||
|
return nil |
||||||
|
} |
||||||
|
|
||||||
|
// UpdateAuthSession changes an auth session using an updater function.
|
||||||
|
func (d *Database) UpdateAuthSession(ctx context.Context, sessionID string, updater func(s storage.AuthSession) (storage.AuthSession, error)) error { |
||||||
|
tx, err := d.BeginTx(ctx) |
||||||
|
if err != nil { |
||||||
|
return convertDBError("update auth session tx: %w", err) |
||||||
|
} |
||||||
|
|
||||||
|
authSession, err := tx.AuthSession.Get(ctx, sessionID) |
||||||
|
if err != nil { |
||||||
|
return rollback(tx, "update auth session database: %w", err) |
||||||
|
} |
||||||
|
|
||||||
|
newSession, err := updater(toStorageAuthSession(authSession)) |
||||||
|
if err != nil { |
||||||
|
return rollback(tx, "update auth session updating: %w", err) |
||||||
|
} |
||||||
|
|
||||||
|
if newSession.ClientStates == nil { |
||||||
|
newSession.ClientStates = make(map[string]*storage.ClientAuthState) |
||||||
|
} |
||||||
|
|
||||||
|
encodedStates, err := json.Marshal(newSession.ClientStates) |
||||||
|
if err != nil { |
||||||
|
return rollback(tx, "encode client states auth session: %w", err) |
||||||
|
} |
||||||
|
|
||||||
|
_, err = tx.AuthSession.UpdateOneID(sessionID). |
||||||
|
SetClientStates(encodedStates). |
||||||
|
SetLastActivity(newSession.LastActivity). |
||||||
|
SetIPAddress(newSession.IPAddress). |
||||||
|
SetUserAgent(newSession.UserAgent). |
||||||
|
Save(ctx) |
||||||
|
if err != nil { |
||||||
|
return rollback(tx, "update auth session updating: %w", err) |
||||||
|
} |
||||||
|
|
||||||
|
if err = tx.Commit(); err != nil { |
||||||
|
return rollback(tx, "update auth session commit: %w", err) |
||||||
|
} |
||||||
|
|
||||||
|
return nil |
||||||
|
} |
||||||
@ -0,0 +1,150 @@ |
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package db |
||||||
|
|
||||||
|
import ( |
||||||
|
"fmt" |
||||||
|
"strings" |
||||||
|
"time" |
||||||
|
|
||||||
|
"entgo.io/ent" |
||||||
|
"entgo.io/ent/dialect/sql" |
||||||
|
"github.com/dexidp/dex/storage/ent/db/authsession" |
||||||
|
) |
||||||
|
|
||||||
|
// AuthSession is the model entity for the AuthSession schema.
|
||||||
|
type AuthSession struct { |
||||||
|
config `json:"-"` |
||||||
|
// ID of the ent.
|
||||||
|
ID string `json:"id,omitempty"` |
||||||
|
// ClientStates holds the value of the "client_states" field.
|
||||||
|
ClientStates []byte `json:"client_states,omitempty"` |
||||||
|
// CreatedAt holds the value of the "created_at" field.
|
||||||
|
CreatedAt time.Time `json:"created_at,omitempty"` |
||||||
|
// LastActivity holds the value of the "last_activity" field.
|
||||||
|
LastActivity time.Time `json:"last_activity,omitempty"` |
||||||
|
// IPAddress holds the value of the "ip_address" field.
|
||||||
|
IPAddress string `json:"ip_address,omitempty"` |
||||||
|
// UserAgent holds the value of the "user_agent" field.
|
||||||
|
UserAgent string `json:"user_agent,omitempty"` |
||||||
|
selectValues sql.SelectValues |
||||||
|
} |
||||||
|
|
||||||
|
// scanValues returns the types for scanning values from sql.Rows.
|
||||||
|
func (*AuthSession) scanValues(columns []string) ([]any, error) { |
||||||
|
values := make([]any, len(columns)) |
||||||
|
for i := range columns { |
||||||
|
switch columns[i] { |
||||||
|
case authsession.FieldClientStates: |
||||||
|
values[i] = new([]byte) |
||||||
|
case authsession.FieldID, authsession.FieldIPAddress, authsession.FieldUserAgent: |
||||||
|
values[i] = new(sql.NullString) |
||||||
|
case authsession.FieldCreatedAt, authsession.FieldLastActivity: |
||||||
|
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 AuthSession fields.
|
||||||
|
func (_m *AuthSession) 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 authsession.FieldID: |
||||||
|
if value, ok := values[i].(*sql.NullString); !ok { |
||||||
|
return fmt.Errorf("unexpected type %T for field id", values[i]) |
||||||
|
} else if value.Valid { |
||||||
|
_m.ID = value.String |
||||||
|
} |
||||||
|
case authsession.FieldClientStates: |
||||||
|
if value, ok := values[i].(*[]byte); !ok { |
||||||
|
return fmt.Errorf("unexpected type %T for field client_states", values[i]) |
||||||
|
} else if value != nil { |
||||||
|
_m.ClientStates = *value |
||||||
|
} |
||||||
|
case authsession.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 { |
||||||
|
_m.CreatedAt = value.Time |
||||||
|
} |
||||||
|
case authsession.FieldLastActivity: |
||||||
|
if value, ok := values[i].(*sql.NullTime); !ok { |
||||||
|
return fmt.Errorf("unexpected type %T for field last_activity", values[i]) |
||||||
|
} else if value.Valid { |
||||||
|
_m.LastActivity = value.Time |
||||||
|
} |
||||||
|
case authsession.FieldIPAddress: |
||||||
|
if value, ok := values[i].(*sql.NullString); !ok { |
||||||
|
return fmt.Errorf("unexpected type %T for field ip_address", values[i]) |
||||||
|
} else if value.Valid { |
||||||
|
_m.IPAddress = value.String |
||||||
|
} |
||||||
|
case authsession.FieldUserAgent: |
||||||
|
if value, ok := values[i].(*sql.NullString); !ok { |
||||||
|
return fmt.Errorf("unexpected type %T for field user_agent", values[i]) |
||||||
|
} else if value.Valid { |
||||||
|
_m.UserAgent = value.String |
||||||
|
} |
||||||
|
default: |
||||||
|
_m.selectValues.Set(columns[i], values[i]) |
||||||
|
} |
||||||
|
} |
||||||
|
return nil |
||||||
|
} |
||||||
|
|
||||||
|
// Value returns the ent.Value that was dynamically selected and assigned to the AuthSession.
|
||||||
|
// This includes values selected through modifiers, order, etc.
|
||||||
|
func (_m *AuthSession) Value(name string) (ent.Value, error) { |
||||||
|
return _m.selectValues.Get(name) |
||||||
|
} |
||||||
|
|
||||||
|
// Update returns a builder for updating this AuthSession.
|
||||||
|
// Note that you need to call AuthSession.Unwrap() before calling this method if this AuthSession
|
||||||
|
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||||
|
func (_m *AuthSession) Update() *AuthSessionUpdateOne { |
||||||
|
return NewAuthSessionClient(_m.config).UpdateOne(_m) |
||||||
|
} |
||||||
|
|
||||||
|
// Unwrap unwraps the AuthSession 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 (_m *AuthSession) Unwrap() *AuthSession { |
||||||
|
_tx, ok := _m.config.driver.(*txDriver) |
||||||
|
if !ok { |
||||||
|
panic("db: AuthSession is not a transactional entity") |
||||||
|
} |
||||||
|
_m.config.driver = _tx.drv |
||||||
|
return _m |
||||||
|
} |
||||||
|
|
||||||
|
// String implements the fmt.Stringer.
|
||||||
|
func (_m *AuthSession) String() string { |
||||||
|
var builder strings.Builder |
||||||
|
builder.WriteString("AuthSession(") |
||||||
|
builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID)) |
||||||
|
builder.WriteString("client_states=") |
||||||
|
builder.WriteString(fmt.Sprintf("%v", _m.ClientStates)) |
||||||
|
builder.WriteString(", ") |
||||||
|
builder.WriteString("created_at=") |
||||||
|
builder.WriteString(_m.CreatedAt.Format(time.ANSIC)) |
||||||
|
builder.WriteString(", ") |
||||||
|
builder.WriteString("last_activity=") |
||||||
|
builder.WriteString(_m.LastActivity.Format(time.ANSIC)) |
||||||
|
builder.WriteString(", ") |
||||||
|
builder.WriteString("ip_address=") |
||||||
|
builder.WriteString(_m.IPAddress) |
||||||
|
builder.WriteString(", ") |
||||||
|
builder.WriteString("user_agent=") |
||||||
|
builder.WriteString(_m.UserAgent) |
||||||
|
builder.WriteByte(')') |
||||||
|
return builder.String() |
||||||
|
} |
||||||
|
|
||||||
|
// AuthSessions is a parsable slice of AuthSession.
|
||||||
|
type AuthSessions []*AuthSession |
||||||
@ -0,0 +1,83 @@ |
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package authsession |
||||||
|
|
||||||
|
import ( |
||||||
|
"entgo.io/ent/dialect/sql" |
||||||
|
) |
||||||
|
|
||||||
|
const ( |
||||||
|
// Label holds the string label denoting the authsession type in the database.
|
||||||
|
Label = "auth_session" |
||||||
|
// FieldID holds the string denoting the id field in the database.
|
||||||
|
FieldID = "id" |
||||||
|
// FieldClientStates holds the string denoting the client_states field in the database.
|
||||||
|
FieldClientStates = "client_states" |
||||||
|
// FieldCreatedAt holds the string denoting the created_at field in the database.
|
||||||
|
FieldCreatedAt = "created_at" |
||||||
|
// FieldLastActivity holds the string denoting the last_activity field in the database.
|
||||||
|
FieldLastActivity = "last_activity" |
||||||
|
// FieldIPAddress holds the string denoting the ip_address field in the database.
|
||||||
|
FieldIPAddress = "ip_address" |
||||||
|
// FieldUserAgent holds the string denoting the user_agent field in the database.
|
||||||
|
FieldUserAgent = "user_agent" |
||||||
|
// Table holds the table name of the authsession in the database.
|
||||||
|
Table = "auth_sessions" |
||||||
|
) |
||||||
|
|
||||||
|
// Columns holds all SQL columns for authsession fields.
|
||||||
|
var Columns = []string{ |
||||||
|
FieldID, |
||||||
|
FieldClientStates, |
||||||
|
FieldCreatedAt, |
||||||
|
FieldLastActivity, |
||||||
|
FieldIPAddress, |
||||||
|
FieldUserAgent, |
||||||
|
} |
||||||
|
|
||||||
|
// 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 |
||||||
|
} |
||||||
|
|
||||||
|
var ( |
||||||
|
// DefaultIPAddress holds the default value on creation for the "ip_address" field.
|
||||||
|
DefaultIPAddress string |
||||||
|
// DefaultUserAgent holds the default value on creation for the "user_agent" field.
|
||||||
|
DefaultUserAgent string |
||||||
|
// IDValidator is a validator for the "id" field. It is called by the builders before save.
|
||||||
|
IDValidator func(string) error |
||||||
|
) |
||||||
|
|
||||||
|
// OrderOption defines the ordering options for the AuthSession 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() |
||||||
|
} |
||||||
|
|
||||||
|
// ByLastActivity orders the results by the last_activity field.
|
||||||
|
func ByLastActivity(opts ...sql.OrderTermOption) OrderOption { |
||||||
|
return sql.OrderByField(FieldLastActivity, opts...).ToFunc() |
||||||
|
} |
||||||
|
|
||||||
|
// ByIPAddress orders the results by the ip_address field.
|
||||||
|
func ByIPAddress(opts ...sql.OrderTermOption) OrderOption { |
||||||
|
return sql.OrderByField(FieldIPAddress, opts...).ToFunc() |
||||||
|
} |
||||||
|
|
||||||
|
// ByUserAgent orders the results by the user_agent field.
|
||||||
|
func ByUserAgent(opts ...sql.OrderTermOption) OrderOption { |
||||||
|
return sql.OrderByField(FieldUserAgent, opts...).ToFunc() |
||||||
|
} |
||||||
@ -0,0 +1,355 @@ |
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package authsession |
||||||
|
|
||||||
|
import ( |
||||||
|
"time" |
||||||
|
|
||||||
|
"entgo.io/ent/dialect/sql" |
||||||
|
"github.com/dexidp/dex/storage/ent/db/predicate" |
||||||
|
) |
||||||
|
|
||||||
|
// ID filters vertices based on their ID field.
|
||||||
|
func ID(id string) predicate.AuthSession { |
||||||
|
return predicate.AuthSession(sql.FieldEQ(FieldID, id)) |
||||||
|
} |
||||||
|
|
||||||
|
// IDEQ applies the EQ predicate on the ID field.
|
||||||
|
func IDEQ(id string) predicate.AuthSession { |
||||||
|
return predicate.AuthSession(sql.FieldEQ(FieldID, id)) |
||||||
|
} |
||||||
|
|
||||||
|
// IDNEQ applies the NEQ predicate on the ID field.
|
||||||
|
func IDNEQ(id string) predicate.AuthSession { |
||||||
|
return predicate.AuthSession(sql.FieldNEQ(FieldID, id)) |
||||||
|
} |
||||||
|
|
||||||
|
// IDIn applies the In predicate on the ID field.
|
||||||
|
func IDIn(ids ...string) predicate.AuthSession { |
||||||
|
return predicate.AuthSession(sql.FieldIn(FieldID, ids...)) |
||||||
|
} |
||||||
|
|
||||||
|
// IDNotIn applies the NotIn predicate on the ID field.
|
||||||
|
func IDNotIn(ids ...string) predicate.AuthSession { |
||||||
|
return predicate.AuthSession(sql.FieldNotIn(FieldID, ids...)) |
||||||
|
} |
||||||
|
|
||||||
|
// IDGT applies the GT predicate on the ID field.
|
||||||
|
func IDGT(id string) predicate.AuthSession { |
||||||
|
return predicate.AuthSession(sql.FieldGT(FieldID, id)) |
||||||
|
} |
||||||
|
|
||||||
|
// IDGTE applies the GTE predicate on the ID field.
|
||||||
|
func IDGTE(id string) predicate.AuthSession { |
||||||
|
return predicate.AuthSession(sql.FieldGTE(FieldID, id)) |
||||||
|
} |
||||||
|
|
||||||
|
// IDLT applies the LT predicate on the ID field.
|
||||||
|
func IDLT(id string) predicate.AuthSession { |
||||||
|
return predicate.AuthSession(sql.FieldLT(FieldID, id)) |
||||||
|
} |
||||||
|
|
||||||
|
// IDLTE applies the LTE predicate on the ID field.
|
||||||
|
func IDLTE(id string) predicate.AuthSession { |
||||||
|
return predicate.AuthSession(sql.FieldLTE(FieldID, id)) |
||||||
|
} |
||||||
|
|
||||||
|
// IDEqualFold applies the EqualFold predicate on the ID field.
|
||||||
|
func IDEqualFold(id string) predicate.AuthSession { |
||||||
|
return predicate.AuthSession(sql.FieldEqualFold(FieldID, id)) |
||||||
|
} |
||||||
|
|
||||||
|
// IDContainsFold applies the ContainsFold predicate on the ID field.
|
||||||
|
func IDContainsFold(id string) predicate.AuthSession { |
||||||
|
return predicate.AuthSession(sql.FieldContainsFold(FieldID, id)) |
||||||
|
} |
||||||
|
|
||||||
|
// ClientStates applies equality check predicate on the "client_states" field. It's identical to ClientStatesEQ.
|
||||||
|
func ClientStates(v []byte) predicate.AuthSession { |
||||||
|
return predicate.AuthSession(sql.FieldEQ(FieldClientStates, v)) |
||||||
|
} |
||||||
|
|
||||||
|
// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ.
|
||||||
|
func CreatedAt(v time.Time) predicate.AuthSession { |
||||||
|
return predicate.AuthSession(sql.FieldEQ(FieldCreatedAt, v)) |
||||||
|
} |
||||||
|
|
||||||
|
// LastActivity applies equality check predicate on the "last_activity" field. It's identical to LastActivityEQ.
|
||||||
|
func LastActivity(v time.Time) predicate.AuthSession { |
||||||
|
return predicate.AuthSession(sql.FieldEQ(FieldLastActivity, v)) |
||||||
|
} |
||||||
|
|
||||||
|
// IPAddress applies equality check predicate on the "ip_address" field. It's identical to IPAddressEQ.
|
||||||
|
func IPAddress(v string) predicate.AuthSession { |
||||||
|
return predicate.AuthSession(sql.FieldEQ(FieldIPAddress, v)) |
||||||
|
} |
||||||
|
|
||||||
|
// UserAgent applies equality check predicate on the "user_agent" field. It's identical to UserAgentEQ.
|
||||||
|
func UserAgent(v string) predicate.AuthSession { |
||||||
|
return predicate.AuthSession(sql.FieldEQ(FieldUserAgent, v)) |
||||||
|
} |
||||||
|
|
||||||
|
// ClientStatesEQ applies the EQ predicate on the "client_states" field.
|
||||||
|
func ClientStatesEQ(v []byte) predicate.AuthSession { |
||||||
|
return predicate.AuthSession(sql.FieldEQ(FieldClientStates, v)) |
||||||
|
} |
||||||
|
|
||||||
|
// ClientStatesNEQ applies the NEQ predicate on the "client_states" field.
|
||||||
|
func ClientStatesNEQ(v []byte) predicate.AuthSession { |
||||||
|
return predicate.AuthSession(sql.FieldNEQ(FieldClientStates, v)) |
||||||
|
} |
||||||
|
|
||||||
|
// ClientStatesIn applies the In predicate on the "client_states" field.
|
||||||
|
func ClientStatesIn(vs ...[]byte) predicate.AuthSession { |
||||||
|
return predicate.AuthSession(sql.FieldIn(FieldClientStates, vs...)) |
||||||
|
} |
||||||
|
|
||||||
|
// ClientStatesNotIn applies the NotIn predicate on the "client_states" field.
|
||||||
|
func ClientStatesNotIn(vs ...[]byte) predicate.AuthSession { |
||||||
|
return predicate.AuthSession(sql.FieldNotIn(FieldClientStates, vs...)) |
||||||
|
} |
||||||
|
|
||||||
|
// ClientStatesGT applies the GT predicate on the "client_states" field.
|
||||||
|
func ClientStatesGT(v []byte) predicate.AuthSession { |
||||||
|
return predicate.AuthSession(sql.FieldGT(FieldClientStates, v)) |
||||||
|
} |
||||||
|
|
||||||
|
// ClientStatesGTE applies the GTE predicate on the "client_states" field.
|
||||||
|
func ClientStatesGTE(v []byte) predicate.AuthSession { |
||||||
|
return predicate.AuthSession(sql.FieldGTE(FieldClientStates, v)) |
||||||
|
} |
||||||
|
|
||||||
|
// ClientStatesLT applies the LT predicate on the "client_states" field.
|
||||||
|
func ClientStatesLT(v []byte) predicate.AuthSession { |
||||||
|
return predicate.AuthSession(sql.FieldLT(FieldClientStates, v)) |
||||||
|
} |
||||||
|
|
||||||
|
// ClientStatesLTE applies the LTE predicate on the "client_states" field.
|
||||||
|
func ClientStatesLTE(v []byte) predicate.AuthSession { |
||||||
|
return predicate.AuthSession(sql.FieldLTE(FieldClientStates, v)) |
||||||
|
} |
||||||
|
|
||||||
|
// CreatedAtEQ applies the EQ predicate on the "created_at" field.
|
||||||
|
func CreatedAtEQ(v time.Time) predicate.AuthSession { |
||||||
|
return predicate.AuthSession(sql.FieldEQ(FieldCreatedAt, v)) |
||||||
|
} |
||||||
|
|
||||||
|
// CreatedAtNEQ applies the NEQ predicate on the "created_at" field.
|
||||||
|
func CreatedAtNEQ(v time.Time) predicate.AuthSession { |
||||||
|
return predicate.AuthSession(sql.FieldNEQ(FieldCreatedAt, v)) |
||||||
|
} |
||||||
|
|
||||||
|
// CreatedAtIn applies the In predicate on the "created_at" field.
|
||||||
|
func CreatedAtIn(vs ...time.Time) predicate.AuthSession { |
||||||
|
return predicate.AuthSession(sql.FieldIn(FieldCreatedAt, vs...)) |
||||||
|
} |
||||||
|
|
||||||
|
// CreatedAtNotIn applies the NotIn predicate on the "created_at" field.
|
||||||
|
func CreatedAtNotIn(vs ...time.Time) predicate.AuthSession { |
||||||
|
return predicate.AuthSession(sql.FieldNotIn(FieldCreatedAt, vs...)) |
||||||
|
} |
||||||
|
|
||||||
|
// CreatedAtGT applies the GT predicate on the "created_at" field.
|
||||||
|
func CreatedAtGT(v time.Time) predicate.AuthSession { |
||||||
|
return predicate.AuthSession(sql.FieldGT(FieldCreatedAt, v)) |
||||||
|
} |
||||||
|
|
||||||
|
// CreatedAtGTE applies the GTE predicate on the "created_at" field.
|
||||||
|
func CreatedAtGTE(v time.Time) predicate.AuthSession { |
||||||
|
return predicate.AuthSession(sql.FieldGTE(FieldCreatedAt, v)) |
||||||
|
} |
||||||
|
|
||||||
|
// CreatedAtLT applies the LT predicate on the "created_at" field.
|
||||||
|
func CreatedAtLT(v time.Time) predicate.AuthSession { |
||||||
|
return predicate.AuthSession(sql.FieldLT(FieldCreatedAt, v)) |
||||||
|
} |
||||||
|
|
||||||
|
// CreatedAtLTE applies the LTE predicate on the "created_at" field.
|
||||||
|
func CreatedAtLTE(v time.Time) predicate.AuthSession { |
||||||
|
return predicate.AuthSession(sql.FieldLTE(FieldCreatedAt, v)) |
||||||
|
} |
||||||
|
|
||||||
|
// LastActivityEQ applies the EQ predicate on the "last_activity" field.
|
||||||
|
func LastActivityEQ(v time.Time) predicate.AuthSession { |
||||||
|
return predicate.AuthSession(sql.FieldEQ(FieldLastActivity, v)) |
||||||
|
} |
||||||
|
|
||||||
|
// LastActivityNEQ applies the NEQ predicate on the "last_activity" field.
|
||||||
|
func LastActivityNEQ(v time.Time) predicate.AuthSession { |
||||||
|
return predicate.AuthSession(sql.FieldNEQ(FieldLastActivity, v)) |
||||||
|
} |
||||||
|
|
||||||
|
// LastActivityIn applies the In predicate on the "last_activity" field.
|
||||||
|
func LastActivityIn(vs ...time.Time) predicate.AuthSession { |
||||||
|
return predicate.AuthSession(sql.FieldIn(FieldLastActivity, vs...)) |
||||||
|
} |
||||||
|
|
||||||
|
// LastActivityNotIn applies the NotIn predicate on the "last_activity" field.
|
||||||
|
func LastActivityNotIn(vs ...time.Time) predicate.AuthSession { |
||||||
|
return predicate.AuthSession(sql.FieldNotIn(FieldLastActivity, vs...)) |
||||||
|
} |
||||||
|
|
||||||
|
// LastActivityGT applies the GT predicate on the "last_activity" field.
|
||||||
|
func LastActivityGT(v time.Time) predicate.AuthSession { |
||||||
|
return predicate.AuthSession(sql.FieldGT(FieldLastActivity, v)) |
||||||
|
} |
||||||
|
|
||||||
|
// LastActivityGTE applies the GTE predicate on the "last_activity" field.
|
||||||
|
func LastActivityGTE(v time.Time) predicate.AuthSession { |
||||||
|
return predicate.AuthSession(sql.FieldGTE(FieldLastActivity, v)) |
||||||
|
} |
||||||
|
|
||||||
|
// LastActivityLT applies the LT predicate on the "last_activity" field.
|
||||||
|
func LastActivityLT(v time.Time) predicate.AuthSession { |
||||||
|
return predicate.AuthSession(sql.FieldLT(FieldLastActivity, v)) |
||||||
|
} |
||||||
|
|
||||||
|
// LastActivityLTE applies the LTE predicate on the "last_activity" field.
|
||||||
|
func LastActivityLTE(v time.Time) predicate.AuthSession { |
||||||
|
return predicate.AuthSession(sql.FieldLTE(FieldLastActivity, v)) |
||||||
|
} |
||||||
|
|
||||||
|
// IPAddressEQ applies the EQ predicate on the "ip_address" field.
|
||||||
|
func IPAddressEQ(v string) predicate.AuthSession { |
||||||
|
return predicate.AuthSession(sql.FieldEQ(FieldIPAddress, v)) |
||||||
|
} |
||||||
|
|
||||||
|
// IPAddressNEQ applies the NEQ predicate on the "ip_address" field.
|
||||||
|
func IPAddressNEQ(v string) predicate.AuthSession { |
||||||
|
return predicate.AuthSession(sql.FieldNEQ(FieldIPAddress, v)) |
||||||
|
} |
||||||
|
|
||||||
|
// IPAddressIn applies the In predicate on the "ip_address" field.
|
||||||
|
func IPAddressIn(vs ...string) predicate.AuthSession { |
||||||
|
return predicate.AuthSession(sql.FieldIn(FieldIPAddress, vs...)) |
||||||
|
} |
||||||
|
|
||||||
|
// IPAddressNotIn applies the NotIn predicate on the "ip_address" field.
|
||||||
|
func IPAddressNotIn(vs ...string) predicate.AuthSession { |
||||||
|
return predicate.AuthSession(sql.FieldNotIn(FieldIPAddress, vs...)) |
||||||
|
} |
||||||
|
|
||||||
|
// IPAddressGT applies the GT predicate on the "ip_address" field.
|
||||||
|
func IPAddressGT(v string) predicate.AuthSession { |
||||||
|
return predicate.AuthSession(sql.FieldGT(FieldIPAddress, v)) |
||||||
|
} |
||||||
|
|
||||||
|
// IPAddressGTE applies the GTE predicate on the "ip_address" field.
|
||||||
|
func IPAddressGTE(v string) predicate.AuthSession { |
||||||
|
return predicate.AuthSession(sql.FieldGTE(FieldIPAddress, v)) |
||||||
|
} |
||||||
|
|
||||||
|
// IPAddressLT applies the LT predicate on the "ip_address" field.
|
||||||
|
func IPAddressLT(v string) predicate.AuthSession { |
||||||
|
return predicate.AuthSession(sql.FieldLT(FieldIPAddress, v)) |
||||||
|
} |
||||||
|
|
||||||
|
// IPAddressLTE applies the LTE predicate on the "ip_address" field.
|
||||||
|
func IPAddressLTE(v string) predicate.AuthSession { |
||||||
|
return predicate.AuthSession(sql.FieldLTE(FieldIPAddress, v)) |
||||||
|
} |
||||||
|
|
||||||
|
// IPAddressContains applies the Contains predicate on the "ip_address" field.
|
||||||
|
func IPAddressContains(v string) predicate.AuthSession { |
||||||
|
return predicate.AuthSession(sql.FieldContains(FieldIPAddress, v)) |
||||||
|
} |
||||||
|
|
||||||
|
// IPAddressHasPrefix applies the HasPrefix predicate on the "ip_address" field.
|
||||||
|
func IPAddressHasPrefix(v string) predicate.AuthSession { |
||||||
|
return predicate.AuthSession(sql.FieldHasPrefix(FieldIPAddress, v)) |
||||||
|
} |
||||||
|
|
||||||
|
// IPAddressHasSuffix applies the HasSuffix predicate on the "ip_address" field.
|
||||||
|
func IPAddressHasSuffix(v string) predicate.AuthSession { |
||||||
|
return predicate.AuthSession(sql.FieldHasSuffix(FieldIPAddress, v)) |
||||||
|
} |
||||||
|
|
||||||
|
// IPAddressEqualFold applies the EqualFold predicate on the "ip_address" field.
|
||||||
|
func IPAddressEqualFold(v string) predicate.AuthSession { |
||||||
|
return predicate.AuthSession(sql.FieldEqualFold(FieldIPAddress, v)) |
||||||
|
} |
||||||
|
|
||||||
|
// IPAddressContainsFold applies the ContainsFold predicate on the "ip_address" field.
|
||||||
|
func IPAddressContainsFold(v string) predicate.AuthSession { |
||||||
|
return predicate.AuthSession(sql.FieldContainsFold(FieldIPAddress, v)) |
||||||
|
} |
||||||
|
|
||||||
|
// UserAgentEQ applies the EQ predicate on the "user_agent" field.
|
||||||
|
func UserAgentEQ(v string) predicate.AuthSession { |
||||||
|
return predicate.AuthSession(sql.FieldEQ(FieldUserAgent, v)) |
||||||
|
} |
||||||
|
|
||||||
|
// UserAgentNEQ applies the NEQ predicate on the "user_agent" field.
|
||||||
|
func UserAgentNEQ(v string) predicate.AuthSession { |
||||||
|
return predicate.AuthSession(sql.FieldNEQ(FieldUserAgent, v)) |
||||||
|
} |
||||||
|
|
||||||
|
// UserAgentIn applies the In predicate on the "user_agent" field.
|
||||||
|
func UserAgentIn(vs ...string) predicate.AuthSession { |
||||||
|
return predicate.AuthSession(sql.FieldIn(FieldUserAgent, vs...)) |
||||||
|
} |
||||||
|
|
||||||
|
// UserAgentNotIn applies the NotIn predicate on the "user_agent" field.
|
||||||
|
func UserAgentNotIn(vs ...string) predicate.AuthSession { |
||||||
|
return predicate.AuthSession(sql.FieldNotIn(FieldUserAgent, vs...)) |
||||||
|
} |
||||||
|
|
||||||
|
// UserAgentGT applies the GT predicate on the "user_agent" field.
|
||||||
|
func UserAgentGT(v string) predicate.AuthSession { |
||||||
|
return predicate.AuthSession(sql.FieldGT(FieldUserAgent, v)) |
||||||
|
} |
||||||
|
|
||||||
|
// UserAgentGTE applies the GTE predicate on the "user_agent" field.
|
||||||
|
func UserAgentGTE(v string) predicate.AuthSession { |
||||||
|
return predicate.AuthSession(sql.FieldGTE(FieldUserAgent, v)) |
||||||
|
} |
||||||
|
|
||||||
|
// UserAgentLT applies the LT predicate on the "user_agent" field.
|
||||||
|
func UserAgentLT(v string) predicate.AuthSession { |
||||||
|
return predicate.AuthSession(sql.FieldLT(FieldUserAgent, v)) |
||||||
|
} |
||||||
|
|
||||||
|
// UserAgentLTE applies the LTE predicate on the "user_agent" field.
|
||||||
|
func UserAgentLTE(v string) predicate.AuthSession { |
||||||
|
return predicate.AuthSession(sql.FieldLTE(FieldUserAgent, v)) |
||||||
|
} |
||||||
|
|
||||||
|
// UserAgentContains applies the Contains predicate on the "user_agent" field.
|
||||||
|
func UserAgentContains(v string) predicate.AuthSession { |
||||||
|
return predicate.AuthSession(sql.FieldContains(FieldUserAgent, v)) |
||||||
|
} |
||||||
|
|
||||||
|
// UserAgentHasPrefix applies the HasPrefix predicate on the "user_agent" field.
|
||||||
|
func UserAgentHasPrefix(v string) predicate.AuthSession { |
||||||
|
return predicate.AuthSession(sql.FieldHasPrefix(FieldUserAgent, v)) |
||||||
|
} |
||||||
|
|
||||||
|
// UserAgentHasSuffix applies the HasSuffix predicate on the "user_agent" field.
|
||||||
|
func UserAgentHasSuffix(v string) predicate.AuthSession { |
||||||
|
return predicate.AuthSession(sql.FieldHasSuffix(FieldUserAgent, v)) |
||||||
|
} |
||||||
|
|
||||||
|
// UserAgentEqualFold applies the EqualFold predicate on the "user_agent" field.
|
||||||
|
func UserAgentEqualFold(v string) predicate.AuthSession { |
||||||
|
return predicate.AuthSession(sql.FieldEqualFold(FieldUserAgent, v)) |
||||||
|
} |
||||||
|
|
||||||
|
// UserAgentContainsFold applies the ContainsFold predicate on the "user_agent" field.
|
||||||
|
func UserAgentContainsFold(v string) predicate.AuthSession { |
||||||
|
return predicate.AuthSession(sql.FieldContainsFold(FieldUserAgent, v)) |
||||||
|
} |
||||||
|
|
||||||
|
// And groups predicates with the AND operator between them.
|
||||||
|
func And(predicates ...predicate.AuthSession) predicate.AuthSession { |
||||||
|
return predicate.AuthSession(sql.AndPredicates(predicates...)) |
||||||
|
} |
||||||
|
|
||||||
|
// Or groups predicates with the OR operator between them.
|
||||||
|
func Or(predicates ...predicate.AuthSession) predicate.AuthSession { |
||||||
|
return predicate.AuthSession(sql.OrPredicates(predicates...)) |
||||||
|
} |
||||||
|
|
||||||
|
// Not applies the not operator on the given predicate.
|
||||||
|
func Not(p predicate.AuthSession) predicate.AuthSession { |
||||||
|
return predicate.AuthSession(sql.NotPredicates(p)) |
||||||
|
} |
||||||
@ -0,0 +1,282 @@ |
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package db |
||||||
|
|
||||||
|
import ( |
||||||
|
"context" |
||||||
|
"errors" |
||||||
|
"fmt" |
||||||
|
"time" |
||||||
|
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph" |
||||||
|
"entgo.io/ent/schema/field" |
||||||
|
"github.com/dexidp/dex/storage/ent/db/authsession" |
||||||
|
) |
||||||
|
|
||||||
|
// AuthSessionCreate is the builder for creating a AuthSession entity.
|
||||||
|
type AuthSessionCreate struct { |
||||||
|
config |
||||||
|
mutation *AuthSessionMutation |
||||||
|
hooks []Hook |
||||||
|
} |
||||||
|
|
||||||
|
// SetClientStates sets the "client_states" field.
|
||||||
|
func (_c *AuthSessionCreate) SetClientStates(v []byte) *AuthSessionCreate { |
||||||
|
_c.mutation.SetClientStates(v) |
||||||
|
return _c |
||||||
|
} |
||||||
|
|
||||||
|
// SetCreatedAt sets the "created_at" field.
|
||||||
|
func (_c *AuthSessionCreate) SetCreatedAt(v time.Time) *AuthSessionCreate { |
||||||
|
_c.mutation.SetCreatedAt(v) |
||||||
|
return _c |
||||||
|
} |
||||||
|
|
||||||
|
// SetLastActivity sets the "last_activity" field.
|
||||||
|
func (_c *AuthSessionCreate) SetLastActivity(v time.Time) *AuthSessionCreate { |
||||||
|
_c.mutation.SetLastActivity(v) |
||||||
|
return _c |
||||||
|
} |
||||||
|
|
||||||
|
// SetIPAddress sets the "ip_address" field.
|
||||||
|
func (_c *AuthSessionCreate) SetIPAddress(v string) *AuthSessionCreate { |
||||||
|
_c.mutation.SetIPAddress(v) |
||||||
|
return _c |
||||||
|
} |
||||||
|
|
||||||
|
// SetNillableIPAddress sets the "ip_address" field if the given value is not nil.
|
||||||
|
func (_c *AuthSessionCreate) SetNillableIPAddress(v *string) *AuthSessionCreate { |
||||||
|
if v != nil { |
||||||
|
_c.SetIPAddress(*v) |
||||||
|
} |
||||||
|
return _c |
||||||
|
} |
||||||
|
|
||||||
|
// SetUserAgent sets the "user_agent" field.
|
||||||
|
func (_c *AuthSessionCreate) SetUserAgent(v string) *AuthSessionCreate { |
||||||
|
_c.mutation.SetUserAgent(v) |
||||||
|
return _c |
||||||
|
} |
||||||
|
|
||||||
|
// SetNillableUserAgent sets the "user_agent" field if the given value is not nil.
|
||||||
|
func (_c *AuthSessionCreate) SetNillableUserAgent(v *string) *AuthSessionCreate { |
||||||
|
if v != nil { |
||||||
|
_c.SetUserAgent(*v) |
||||||
|
} |
||||||
|
return _c |
||||||
|
} |
||||||
|
|
||||||
|
// SetID sets the "id" field.
|
||||||
|
func (_c *AuthSessionCreate) SetID(v string) *AuthSessionCreate { |
||||||
|
_c.mutation.SetID(v) |
||||||
|
return _c |
||||||
|
} |
||||||
|
|
||||||
|
// Mutation returns the AuthSessionMutation object of the builder.
|
||||||
|
func (_c *AuthSessionCreate) Mutation() *AuthSessionMutation { |
||||||
|
return _c.mutation |
||||||
|
} |
||||||
|
|
||||||
|
// Save creates the AuthSession in the database.
|
||||||
|
func (_c *AuthSessionCreate) Save(ctx context.Context) (*AuthSession, error) { |
||||||
|
_c.defaults() |
||||||
|
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks) |
||||||
|
} |
||||||
|
|
||||||
|
// SaveX calls Save and panics if Save returns an error.
|
||||||
|
func (_c *AuthSessionCreate) SaveX(ctx context.Context) *AuthSession { |
||||||
|
v, err := _c.Save(ctx) |
||||||
|
if err != nil { |
||||||
|
panic(err) |
||||||
|
} |
||||||
|
return v |
||||||
|
} |
||||||
|
|
||||||
|
// Exec executes the query.
|
||||||
|
func (_c *AuthSessionCreate) Exec(ctx context.Context) error { |
||||||
|
_, err := _c.Save(ctx) |
||||||
|
return err |
||||||
|
} |
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (_c *AuthSessionCreate) ExecX(ctx context.Context) { |
||||||
|
if err := _c.Exec(ctx); err != nil { |
||||||
|
panic(err) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
// defaults sets the default values of the builder before save.
|
||||||
|
func (_c *AuthSessionCreate) defaults() { |
||||||
|
if _, ok := _c.mutation.IPAddress(); !ok { |
||||||
|
v := authsession.DefaultIPAddress |
||||||
|
_c.mutation.SetIPAddress(v) |
||||||
|
} |
||||||
|
if _, ok := _c.mutation.UserAgent(); !ok { |
||||||
|
v := authsession.DefaultUserAgent |
||||||
|
_c.mutation.SetUserAgent(v) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
// check runs all checks and user-defined validators on the builder.
|
||||||
|
func (_c *AuthSessionCreate) check() error { |
||||||
|
if _, ok := _c.mutation.ClientStates(); !ok { |
||||||
|
return &ValidationError{Name: "client_states", err: errors.New(`db: missing required field "AuthSession.client_states"`)} |
||||||
|
} |
||||||
|
if _, ok := _c.mutation.CreatedAt(); !ok { |
||||||
|
return &ValidationError{Name: "created_at", err: errors.New(`db: missing required field "AuthSession.created_at"`)} |
||||||
|
} |
||||||
|
if _, ok := _c.mutation.LastActivity(); !ok { |
||||||
|
return &ValidationError{Name: "last_activity", err: errors.New(`db: missing required field "AuthSession.last_activity"`)} |
||||||
|
} |
||||||
|
if _, ok := _c.mutation.IPAddress(); !ok { |
||||||
|
return &ValidationError{Name: "ip_address", err: errors.New(`db: missing required field "AuthSession.ip_address"`)} |
||||||
|
} |
||||||
|
if _, ok := _c.mutation.UserAgent(); !ok { |
||||||
|
return &ValidationError{Name: "user_agent", err: errors.New(`db: missing required field "AuthSession.user_agent"`)} |
||||||
|
} |
||||||
|
if v, ok := _c.mutation.ID(); ok { |
||||||
|
if err := authsession.IDValidator(v); err != nil { |
||||||
|
return &ValidationError{Name: "id", err: fmt.Errorf(`db: validator failed for field "AuthSession.id": %w`, err)} |
||||||
|
} |
||||||
|
} |
||||||
|
return nil |
||||||
|
} |
||||||
|
|
||||||
|
func (_c *AuthSessionCreate) sqlSave(ctx context.Context) (*AuthSession, error) { |
||||||
|
if err := _c.check(); err != nil { |
||||||
|
return nil, err |
||||||
|
} |
||||||
|
_node, _spec := _c.createSpec() |
||||||
|
if err := sqlgraph.CreateNode(ctx, _c.driver, _spec); err != nil { |
||||||
|
if sqlgraph.IsConstraintError(err) { |
||||||
|
err = &ConstraintError{msg: err.Error(), wrap: err} |
||||||
|
} |
||||||
|
return nil, err |
||||||
|
} |
||||||
|
if _spec.ID.Value != nil { |
||||||
|
if id, ok := _spec.ID.Value.(string); ok { |
||||||
|
_node.ID = id |
||||||
|
} else { |
||||||
|
return nil, fmt.Errorf("unexpected AuthSession.ID type: %T", _spec.ID.Value) |
||||||
|
} |
||||||
|
} |
||||||
|
_c.mutation.id = &_node.ID |
||||||
|
_c.mutation.done = true |
||||||
|
return _node, nil |
||||||
|
} |
||||||
|
|
||||||
|
func (_c *AuthSessionCreate) createSpec() (*AuthSession, *sqlgraph.CreateSpec) { |
||||||
|
var ( |
||||||
|
_node = &AuthSession{config: _c.config} |
||||||
|
_spec = sqlgraph.NewCreateSpec(authsession.Table, sqlgraph.NewFieldSpec(authsession.FieldID, field.TypeString)) |
||||||
|
) |
||||||
|
if id, ok := _c.mutation.ID(); ok { |
||||||
|
_node.ID = id |
||||||
|
_spec.ID.Value = id |
||||||
|
} |
||||||
|
if value, ok := _c.mutation.ClientStates(); ok { |
||||||
|
_spec.SetField(authsession.FieldClientStates, field.TypeBytes, value) |
||||||
|
_node.ClientStates = value |
||||||
|
} |
||||||
|
if value, ok := _c.mutation.CreatedAt(); ok { |
||||||
|
_spec.SetField(authsession.FieldCreatedAt, field.TypeTime, value) |
||||||
|
_node.CreatedAt = value |
||||||
|
} |
||||||
|
if value, ok := _c.mutation.LastActivity(); ok { |
||||||
|
_spec.SetField(authsession.FieldLastActivity, field.TypeTime, value) |
||||||
|
_node.LastActivity = value |
||||||
|
} |
||||||
|
if value, ok := _c.mutation.IPAddress(); ok { |
||||||
|
_spec.SetField(authsession.FieldIPAddress, field.TypeString, value) |
||||||
|
_node.IPAddress = value |
||||||
|
} |
||||||
|
if value, ok := _c.mutation.UserAgent(); ok { |
||||||
|
_spec.SetField(authsession.FieldUserAgent, field.TypeString, value) |
||||||
|
_node.UserAgent = value |
||||||
|
} |
||||||
|
return _node, _spec |
||||||
|
} |
||||||
|
|
||||||
|
// AuthSessionCreateBulk is the builder for creating many AuthSession entities in bulk.
|
||||||
|
type AuthSessionCreateBulk struct { |
||||||
|
config |
||||||
|
err error |
||||||
|
builders []*AuthSessionCreate |
||||||
|
} |
||||||
|
|
||||||
|
// Save creates the AuthSession entities in the database.
|
||||||
|
func (_c *AuthSessionCreateBulk) Save(ctx context.Context) ([]*AuthSession, error) { |
||||||
|
if _c.err != nil { |
||||||
|
return nil, _c.err |
||||||
|
} |
||||||
|
specs := make([]*sqlgraph.CreateSpec, len(_c.builders)) |
||||||
|
nodes := make([]*AuthSession, len(_c.builders)) |
||||||
|
mutators := make([]Mutator, len(_c.builders)) |
||||||
|
for i := range _c.builders { |
||||||
|
func(i int, root context.Context) { |
||||||
|
builder := _c.builders[i] |
||||||
|
builder.defaults() |
||||||
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { |
||||||
|
mutation, ok := m.(*AuthSessionMutation) |
||||||
|
if !ok { |
||||||
|
return nil, fmt.Errorf("unexpected mutation type %T", m) |
||||||
|
} |
||||||
|
if err := builder.check(); err != nil { |
||||||
|
return nil, err |
||||||
|
} |
||||||
|
builder.mutation = mutation |
||||||
|
var err error |
||||||
|
nodes[i], specs[i] = builder.createSpec() |
||||||
|
if i < len(mutators)-1 { |
||||||
|
_, err = mutators[i+1].Mutate(root, _c.builders[i+1].mutation) |
||||||
|
} else { |
||||||
|
spec := &sqlgraph.BatchCreateSpec{Nodes: specs} |
||||||
|
// Invoke the actual operation on the latest mutation in the chain.
|
||||||
|
if err = sqlgraph.BatchCreate(ctx, _c.driver, spec); err != nil { |
||||||
|
if sqlgraph.IsConstraintError(err) { |
||||||
|
err = &ConstraintError{msg: err.Error(), wrap: err} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
if err != nil { |
||||||
|
return nil, err |
||||||
|
} |
||||||
|
mutation.id = &nodes[i].ID |
||||||
|
mutation.done = true |
||||||
|
return nodes[i], nil |
||||||
|
}) |
||||||
|
for i := len(builder.hooks) - 1; i >= 0; i-- { |
||||||
|
mut = builder.hooks[i](mut) |
||||||
|
} |
||||||
|
mutators[i] = mut |
||||||
|
}(i, ctx) |
||||||
|
} |
||||||
|
if len(mutators) > 0 { |
||||||
|
if _, err := mutators[0].Mutate(ctx, _c.builders[0].mutation); err != nil { |
||||||
|
return nil, err |
||||||
|
} |
||||||
|
} |
||||||
|
return nodes, nil |
||||||
|
} |
||||||
|
|
||||||
|
// SaveX is like Save, but panics if an error occurs.
|
||||||
|
func (_c *AuthSessionCreateBulk) SaveX(ctx context.Context) []*AuthSession { |
||||||
|
v, err := _c.Save(ctx) |
||||||
|
if err != nil { |
||||||
|
panic(err) |
||||||
|
} |
||||||
|
return v |
||||||
|
} |
||||||
|
|
||||||
|
// Exec executes the query.
|
||||||
|
func (_c *AuthSessionCreateBulk) Exec(ctx context.Context) error { |
||||||
|
_, err := _c.Save(ctx) |
||||||
|
return err |
||||||
|
} |
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (_c *AuthSessionCreateBulk) ExecX(ctx context.Context) { |
||||||
|
if err := _c.Exec(ctx); err != nil { |
||||||
|
panic(err) |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,88 @@ |
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package db |
||||||
|
|
||||||
|
import ( |
||||||
|
"context" |
||||||
|
|
||||||
|
"entgo.io/ent/dialect/sql" |
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph" |
||||||
|
"entgo.io/ent/schema/field" |
||||||
|
"github.com/dexidp/dex/storage/ent/db/authsession" |
||||||
|
"github.com/dexidp/dex/storage/ent/db/predicate" |
||||||
|
) |
||||||
|
|
||||||
|
// AuthSessionDelete is the builder for deleting a AuthSession entity.
|
||||||
|
type AuthSessionDelete struct { |
||||||
|
config |
||||||
|
hooks []Hook |
||||||
|
mutation *AuthSessionMutation |
||||||
|
} |
||||||
|
|
||||||
|
// Where appends a list predicates to the AuthSessionDelete builder.
|
||||||
|
func (_d *AuthSessionDelete) Where(ps ...predicate.AuthSession) *AuthSessionDelete { |
||||||
|
_d.mutation.Where(ps...) |
||||||
|
return _d |
||||||
|
} |
||||||
|
|
||||||
|
// Exec executes the deletion query and returns how many vertices were deleted.
|
||||||
|
func (_d *AuthSessionDelete) Exec(ctx context.Context) (int, error) { |
||||||
|
return withHooks(ctx, _d.sqlExec, _d.mutation, _d.hooks) |
||||||
|
} |
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (_d *AuthSessionDelete) ExecX(ctx context.Context) int { |
||||||
|
n, err := _d.Exec(ctx) |
||||||
|
if err != nil { |
||||||
|
panic(err) |
||||||
|
} |
||||||
|
return n |
||||||
|
} |
||||||
|
|
||||||
|
func (_d *AuthSessionDelete) sqlExec(ctx context.Context) (int, error) { |
||||||
|
_spec := sqlgraph.NewDeleteSpec(authsession.Table, sqlgraph.NewFieldSpec(authsession.FieldID, field.TypeString)) |
||||||
|
if ps := _d.mutation.predicates; len(ps) > 0 { |
||||||
|
_spec.Predicate = func(selector *sql.Selector) { |
||||||
|
for i := range ps { |
||||||
|
ps[i](selector) |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
affected, err := sqlgraph.DeleteNodes(ctx, _d.driver, _spec) |
||||||
|
if err != nil && sqlgraph.IsConstraintError(err) { |
||||||
|
err = &ConstraintError{msg: err.Error(), wrap: err} |
||||||
|
} |
||||||
|
_d.mutation.done = true |
||||||
|
return affected, err |
||||||
|
} |
||||||
|
|
||||||
|
// AuthSessionDeleteOne is the builder for deleting a single AuthSession entity.
|
||||||
|
type AuthSessionDeleteOne struct { |
||||||
|
_d *AuthSessionDelete |
||||||
|
} |
||||||
|
|
||||||
|
// Where appends a list predicates to the AuthSessionDelete builder.
|
||||||
|
func (_d *AuthSessionDeleteOne) Where(ps ...predicate.AuthSession) *AuthSessionDeleteOne { |
||||||
|
_d._d.mutation.Where(ps...) |
||||||
|
return _d |
||||||
|
} |
||||||
|
|
||||||
|
// Exec executes the deletion query.
|
||||||
|
func (_d *AuthSessionDeleteOne) Exec(ctx context.Context) error { |
||||||
|
n, err := _d._d.Exec(ctx) |
||||||
|
switch { |
||||||
|
case err != nil: |
||||||
|
return err |
||||||
|
case n == 0: |
||||||
|
return &NotFoundError{authsession.Label} |
||||||
|
default: |
||||||
|
return nil |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (_d *AuthSessionDeleteOne) ExecX(ctx context.Context) { |
||||||
|
if err := _d.Exec(ctx); err != nil { |
||||||
|
panic(err) |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,527 @@ |
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package db |
||||||
|
|
||||||
|
import ( |
||||||
|
"context" |
||||||
|
"fmt" |
||||||
|
"math" |
||||||
|
|
||||||
|
"entgo.io/ent" |
||||||
|
"entgo.io/ent/dialect/sql" |
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph" |
||||||
|
"entgo.io/ent/schema/field" |
||||||
|
"github.com/dexidp/dex/storage/ent/db/authsession" |
||||||
|
"github.com/dexidp/dex/storage/ent/db/predicate" |
||||||
|
) |
||||||
|
|
||||||
|
// AuthSessionQuery is the builder for querying AuthSession entities.
|
||||||
|
type AuthSessionQuery struct { |
||||||
|
config |
||||||
|
ctx *QueryContext |
||||||
|
order []authsession.OrderOption |
||||||
|
inters []Interceptor |
||||||
|
predicates []predicate.AuthSession |
||||||
|
// intermediate query (i.e. traversal path).
|
||||||
|
sql *sql.Selector |
||||||
|
path func(context.Context) (*sql.Selector, error) |
||||||
|
} |
||||||
|
|
||||||
|
// Where adds a new predicate for the AuthSessionQuery builder.
|
||||||
|
func (_q *AuthSessionQuery) Where(ps ...predicate.AuthSession) *AuthSessionQuery { |
||||||
|
_q.predicates = append(_q.predicates, ps...) |
||||||
|
return _q |
||||||
|
} |
||||||
|
|
||||||
|
// Limit the number of records to be returned by this query.
|
||||||
|
func (_q *AuthSessionQuery) Limit(limit int) *AuthSessionQuery { |
||||||
|
_q.ctx.Limit = &limit |
||||||
|
return _q |
||||||
|
} |
||||||
|
|
||||||
|
// Offset to start from.
|
||||||
|
func (_q *AuthSessionQuery) Offset(offset int) *AuthSessionQuery { |
||||||
|
_q.ctx.Offset = &offset |
||||||
|
return _q |
||||||
|
} |
||||||
|
|
||||||
|
// 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 (_q *AuthSessionQuery) Unique(unique bool) *AuthSessionQuery { |
||||||
|
_q.ctx.Unique = &unique |
||||||
|
return _q |
||||||
|
} |
||||||
|
|
||||||
|
// Order specifies how the records should be ordered.
|
||||||
|
func (_q *AuthSessionQuery) Order(o ...authsession.OrderOption) *AuthSessionQuery { |
||||||
|
_q.order = append(_q.order, o...) |
||||||
|
return _q |
||||||
|
} |
||||||
|
|
||||||
|
// First returns the first AuthSession entity from the query.
|
||||||
|
// Returns a *NotFoundError when no AuthSession was found.
|
||||||
|
func (_q *AuthSessionQuery) First(ctx context.Context) (*AuthSession, error) { |
||||||
|
nodes, err := _q.Limit(1).All(setContextOp(ctx, _q.ctx, ent.OpQueryFirst)) |
||||||
|
if err != nil { |
||||||
|
return nil, err |
||||||
|
} |
||||||
|
if len(nodes) == 0 { |
||||||
|
return nil, &NotFoundError{authsession.Label} |
||||||
|
} |
||||||
|
return nodes[0], nil |
||||||
|
} |
||||||
|
|
||||||
|
// FirstX is like First, but panics if an error occurs.
|
||||||
|
func (_q *AuthSessionQuery) FirstX(ctx context.Context) *AuthSession { |
||||||
|
node, err := _q.First(ctx) |
||||||
|
if err != nil && !IsNotFound(err) { |
||||||
|
panic(err) |
||||||
|
} |
||||||
|
return node |
||||||
|
} |
||||||
|
|
||||||
|
// FirstID returns the first AuthSession ID from the query.
|
||||||
|
// Returns a *NotFoundError when no AuthSession ID was found.
|
||||||
|
func (_q *AuthSessionQuery) FirstID(ctx context.Context) (id string, err error) { |
||||||
|
var ids []string |
||||||
|
if ids, err = _q.Limit(1).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryFirstID)); err != nil { |
||||||
|
return |
||||||
|
} |
||||||
|
if len(ids) == 0 { |
||||||
|
err = &NotFoundError{authsession.Label} |
||||||
|
return |
||||||
|
} |
||||||
|
return ids[0], nil |
||||||
|
} |
||||||
|
|
||||||
|
// FirstIDX is like FirstID, but panics if an error occurs.
|
||||||
|
func (_q *AuthSessionQuery) FirstIDX(ctx context.Context) string { |
||||||
|
id, err := _q.FirstID(ctx) |
||||||
|
if err != nil && !IsNotFound(err) { |
||||||
|
panic(err) |
||||||
|
} |
||||||
|
return id |
||||||
|
} |
||||||
|
|
||||||
|
// Only returns a single AuthSession entity found by the query, ensuring it only returns one.
|
||||||
|
// Returns a *NotSingularError when more than one AuthSession entity is found.
|
||||||
|
// Returns a *NotFoundError when no AuthSession entities are found.
|
||||||
|
func (_q *AuthSessionQuery) Only(ctx context.Context) (*AuthSession, error) { |
||||||
|
nodes, err := _q.Limit(2).All(setContextOp(ctx, _q.ctx, ent.OpQueryOnly)) |
||||||
|
if err != nil { |
||||||
|
return nil, err |
||||||
|
} |
||||||
|
switch len(nodes) { |
||||||
|
case 1: |
||||||
|
return nodes[0], nil |
||||||
|
case 0: |
||||||
|
return nil, &NotFoundError{authsession.Label} |
||||||
|
default: |
||||||
|
return nil, &NotSingularError{authsession.Label} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
// OnlyX is like Only, but panics if an error occurs.
|
||||||
|
func (_q *AuthSessionQuery) OnlyX(ctx context.Context) *AuthSession { |
||||||
|
node, err := _q.Only(ctx) |
||||||
|
if err != nil { |
||||||
|
panic(err) |
||||||
|
} |
||||||
|
return node |
||||||
|
} |
||||||
|
|
||||||
|
// OnlyID is like Only, but returns the only AuthSession ID in the query.
|
||||||
|
// Returns a *NotSingularError when more than one AuthSession ID is found.
|
||||||
|
// Returns a *NotFoundError when no entities are found.
|
||||||
|
func (_q *AuthSessionQuery) OnlyID(ctx context.Context) (id string, err error) { |
||||||
|
var ids []string |
||||||
|
if ids, err = _q.Limit(2).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryOnlyID)); err != nil { |
||||||
|
return |
||||||
|
} |
||||||
|
switch len(ids) { |
||||||
|
case 1: |
||||||
|
id = ids[0] |
||||||
|
case 0: |
||||||
|
err = &NotFoundError{authsession.Label} |
||||||
|
default: |
||||||
|
err = &NotSingularError{authsession.Label} |
||||||
|
} |
||||||
|
return |
||||||
|
} |
||||||
|
|
||||||
|
// OnlyIDX is like OnlyID, but panics if an error occurs.
|
||||||
|
func (_q *AuthSessionQuery) OnlyIDX(ctx context.Context) string { |
||||||
|
id, err := _q.OnlyID(ctx) |
||||||
|
if err != nil { |
||||||
|
panic(err) |
||||||
|
} |
||||||
|
return id |
||||||
|
} |
||||||
|
|
||||||
|
// All executes the query and returns a list of AuthSessions.
|
||||||
|
func (_q *AuthSessionQuery) All(ctx context.Context) ([]*AuthSession, error) { |
||||||
|
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll) |
||||||
|
if err := _q.prepareQuery(ctx); err != nil { |
||||||
|
return nil, err |
||||||
|
} |
||||||
|
qr := querierAll[[]*AuthSession, *AuthSessionQuery]() |
||||||
|
return withInterceptors[[]*AuthSession](ctx, _q, qr, _q.inters) |
||||||
|
} |
||||||
|
|
||||||
|
// AllX is like All, but panics if an error occurs.
|
||||||
|
func (_q *AuthSessionQuery) AllX(ctx context.Context) []*AuthSession { |
||||||
|
nodes, err := _q.All(ctx) |
||||||
|
if err != nil { |
||||||
|
panic(err) |
||||||
|
} |
||||||
|
return nodes |
||||||
|
} |
||||||
|
|
||||||
|
// IDs executes the query and returns a list of AuthSession IDs.
|
||||||
|
func (_q *AuthSessionQuery) IDs(ctx context.Context) (ids []string, err error) { |
||||||
|
if _q.ctx.Unique == nil && _q.path != nil { |
||||||
|
_q.Unique(true) |
||||||
|
} |
||||||
|
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryIDs) |
||||||
|
if err = _q.Select(authsession.FieldID).Scan(ctx, &ids); err != nil { |
||||||
|
return nil, err |
||||||
|
} |
||||||
|
return ids, nil |
||||||
|
} |
||||||
|
|
||||||
|
// IDsX is like IDs, but panics if an error occurs.
|
||||||
|
func (_q *AuthSessionQuery) IDsX(ctx context.Context) []string { |
||||||
|
ids, err := _q.IDs(ctx) |
||||||
|
if err != nil { |
||||||
|
panic(err) |
||||||
|
} |
||||||
|
return ids |
||||||
|
} |
||||||
|
|
||||||
|
// Count returns the count of the given query.
|
||||||
|
func (_q *AuthSessionQuery) Count(ctx context.Context) (int, error) { |
||||||
|
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryCount) |
||||||
|
if err := _q.prepareQuery(ctx); err != nil { |
||||||
|
return 0, err |
||||||
|
} |
||||||
|
return withInterceptors[int](ctx, _q, querierCount[*AuthSessionQuery](), _q.inters) |
||||||
|
} |
||||||
|
|
||||||
|
// CountX is like Count, but panics if an error occurs.
|
||||||
|
func (_q *AuthSessionQuery) CountX(ctx context.Context) int { |
||||||
|
count, err := _q.Count(ctx) |
||||||
|
if err != nil { |
||||||
|
panic(err) |
||||||
|
} |
||||||
|
return count |
||||||
|
} |
||||||
|
|
||||||
|
// Exist returns true if the query has elements in the graph.
|
||||||
|
func (_q *AuthSessionQuery) Exist(ctx context.Context) (bool, error) { |
||||||
|
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryExist) |
||||||
|
switch _, err := _q.FirstID(ctx); { |
||||||
|
case IsNotFound(err): |
||||||
|
return false, nil |
||||||
|
case err != nil: |
||||||
|
return false, fmt.Errorf("db: check existence: %w", err) |
||||||
|
default: |
||||||
|
return true, nil |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
// ExistX is like Exist, but panics if an error occurs.
|
||||||
|
func (_q *AuthSessionQuery) ExistX(ctx context.Context) bool { |
||||||
|
exist, err := _q.Exist(ctx) |
||||||
|
if err != nil { |
||||||
|
panic(err) |
||||||
|
} |
||||||
|
return exist |
||||||
|
} |
||||||
|
|
||||||
|
// Clone returns a duplicate of the AuthSessionQuery builder, including all associated steps. It can be
|
||||||
|
// used to prepare common query builders and use them differently after the clone is made.
|
||||||
|
func (_q *AuthSessionQuery) Clone() *AuthSessionQuery { |
||||||
|
if _q == nil { |
||||||
|
return nil |
||||||
|
} |
||||||
|
return &AuthSessionQuery{ |
||||||
|
config: _q.config, |
||||||
|
ctx: _q.ctx.Clone(), |
||||||
|
order: append([]authsession.OrderOption{}, _q.order...), |
||||||
|
inters: append([]Interceptor{}, _q.inters...), |
||||||
|
predicates: append([]predicate.AuthSession{}, _q.predicates...), |
||||||
|
// clone intermediate query.
|
||||||
|
sql: _q.sql.Clone(), |
||||||
|
path: _q.path, |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
// 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 {
|
||||||
|
// ClientStates []byte `json:"client_states,omitempty"`
|
||||||
|
// Count int `json:"count,omitempty"`
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// client.AuthSession.Query().
|
||||||
|
// GroupBy(authsession.FieldClientStates).
|
||||||
|
// Aggregate(db.Count()).
|
||||||
|
// Scan(ctx, &v)
|
||||||
|
func (_q *AuthSessionQuery) GroupBy(field string, fields ...string) *AuthSessionGroupBy { |
||||||
|
_q.ctx.Fields = append([]string{field}, fields...) |
||||||
|
grbuild := &AuthSessionGroupBy{build: _q} |
||||||
|
grbuild.flds = &_q.ctx.Fields |
||||||
|
grbuild.label = authsession.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 {
|
||||||
|
// ClientStates []byte `json:"client_states,omitempty"`
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// client.AuthSession.Query().
|
||||||
|
// Select(authsession.FieldClientStates).
|
||||||
|
// Scan(ctx, &v)
|
||||||
|
func (_q *AuthSessionQuery) Select(fields ...string) *AuthSessionSelect { |
||||||
|
_q.ctx.Fields = append(_q.ctx.Fields, fields...) |
||||||
|
sbuild := &AuthSessionSelect{AuthSessionQuery: _q} |
||||||
|
sbuild.label = authsession.Label |
||||||
|
sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan |
||||||
|
return sbuild |
||||||
|
} |
||||||
|
|
||||||
|
// Aggregate returns a AuthSessionSelect configured with the given aggregations.
|
||||||
|
func (_q *AuthSessionQuery) Aggregate(fns ...AggregateFunc) *AuthSessionSelect { |
||||||
|
return _q.Select().Aggregate(fns...) |
||||||
|
} |
||||||
|
|
||||||
|
func (_q *AuthSessionQuery) prepareQuery(ctx context.Context) error { |
||||||
|
for _, inter := range _q.inters { |
||||||
|
if inter == nil { |
||||||
|
return fmt.Errorf("db: uninitialized interceptor (forgotten import db/runtime?)") |
||||||
|
} |
||||||
|
if trv, ok := inter.(Traverser); ok { |
||||||
|
if err := trv.Traverse(ctx, _q); err != nil { |
||||||
|
return err |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
for _, f := range _q.ctx.Fields { |
||||||
|
if !authsession.ValidColumn(f) { |
||||||
|
return &ValidationError{Name: f, err: fmt.Errorf("db: invalid field %q for query", f)} |
||||||
|
} |
||||||
|
} |
||||||
|
if _q.path != nil { |
||||||
|
prev, err := _q.path(ctx) |
||||||
|
if err != nil { |
||||||
|
return err |
||||||
|
} |
||||||
|
_q.sql = prev |
||||||
|
} |
||||||
|
return nil |
||||||
|
} |
||||||
|
|
||||||
|
func (_q *AuthSessionQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*AuthSession, error) { |
||||||
|
var ( |
||||||
|
nodes = []*AuthSession{} |
||||||
|
_spec = _q.querySpec() |
||||||
|
) |
||||||
|
_spec.ScanValues = func(columns []string) ([]any, error) { |
||||||
|
return (*AuthSession).scanValues(nil, columns) |
||||||
|
} |
||||||
|
_spec.Assign = func(columns []string, values []any) error { |
||||||
|
node := &AuthSession{config: _q.config} |
||||||
|
nodes = append(nodes, node) |
||||||
|
return node.assignValues(columns, values) |
||||||
|
} |
||||||
|
for i := range hooks { |
||||||
|
hooks[i](ctx, _spec) |
||||||
|
} |
||||||
|
if err := sqlgraph.QueryNodes(ctx, _q.driver, _spec); err != nil { |
||||||
|
return nil, err |
||||||
|
} |
||||||
|
if len(nodes) == 0 { |
||||||
|
return nodes, nil |
||||||
|
} |
||||||
|
return nodes, nil |
||||||
|
} |
||||||
|
|
||||||
|
func (_q *AuthSessionQuery) sqlCount(ctx context.Context) (int, error) { |
||||||
|
_spec := _q.querySpec() |
||||||
|
_spec.Node.Columns = _q.ctx.Fields |
||||||
|
if len(_q.ctx.Fields) > 0 { |
||||||
|
_spec.Unique = _q.ctx.Unique != nil && *_q.ctx.Unique |
||||||
|
} |
||||||
|
return sqlgraph.CountNodes(ctx, _q.driver, _spec) |
||||||
|
} |
||||||
|
|
||||||
|
func (_q *AuthSessionQuery) querySpec() *sqlgraph.QuerySpec { |
||||||
|
_spec := sqlgraph.NewQuerySpec(authsession.Table, authsession.Columns, sqlgraph.NewFieldSpec(authsession.FieldID, field.TypeString)) |
||||||
|
_spec.From = _q.sql |
||||||
|
if unique := _q.ctx.Unique; unique != nil { |
||||||
|
_spec.Unique = *unique |
||||||
|
} else if _q.path != nil { |
||||||
|
_spec.Unique = true |
||||||
|
} |
||||||
|
if fields := _q.ctx.Fields; len(fields) > 0 { |
||||||
|
_spec.Node.Columns = make([]string, 0, len(fields)) |
||||||
|
_spec.Node.Columns = append(_spec.Node.Columns, authsession.FieldID) |
||||||
|
for i := range fields { |
||||||
|
if fields[i] != authsession.FieldID { |
||||||
|
_spec.Node.Columns = append(_spec.Node.Columns, fields[i]) |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
if ps := _q.predicates; len(ps) > 0 { |
||||||
|
_spec.Predicate = func(selector *sql.Selector) { |
||||||
|
for i := range ps { |
||||||
|
ps[i](selector) |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
if limit := _q.ctx.Limit; limit != nil { |
||||||
|
_spec.Limit = *limit |
||||||
|
} |
||||||
|
if offset := _q.ctx.Offset; offset != nil { |
||||||
|
_spec.Offset = *offset |
||||||
|
} |
||||||
|
if ps := _q.order; len(ps) > 0 { |
||||||
|
_spec.Order = func(selector *sql.Selector) { |
||||||
|
for i := range ps { |
||||||
|
ps[i](selector) |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
return _spec |
||||||
|
} |
||||||
|
|
||||||
|
func (_q *AuthSessionQuery) sqlQuery(ctx context.Context) *sql.Selector { |
||||||
|
builder := sql.Dialect(_q.driver.Dialect()) |
||||||
|
t1 := builder.Table(authsession.Table) |
||||||
|
columns := _q.ctx.Fields |
||||||
|
if len(columns) == 0 { |
||||||
|
columns = authsession.Columns |
||||||
|
} |
||||||
|
selector := builder.Select(t1.Columns(columns...)...).From(t1) |
||||||
|
if _q.sql != nil { |
||||||
|
selector = _q.sql |
||||||
|
selector.Select(selector.Columns(columns...)...) |
||||||
|
} |
||||||
|
if _q.ctx.Unique != nil && *_q.ctx.Unique { |
||||||
|
selector.Distinct() |
||||||
|
} |
||||||
|
for _, p := range _q.predicates { |
||||||
|
p(selector) |
||||||
|
} |
||||||
|
for _, p := range _q.order { |
||||||
|
p(selector) |
||||||
|
} |
||||||
|
if offset := _q.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 := _q.ctx.Limit; limit != nil { |
||||||
|
selector.Limit(*limit) |
||||||
|
} |
||||||
|
return selector |
||||||
|
} |
||||||
|
|
||||||
|
// AuthSessionGroupBy is the group-by builder for AuthSession entities.
|
||||||
|
type AuthSessionGroupBy struct { |
||||||
|
selector |
||||||
|
build *AuthSessionQuery |
||||||
|
} |
||||||
|
|
||||||
|
// Aggregate adds the given aggregation functions to the group-by query.
|
||||||
|
func (_g *AuthSessionGroupBy) Aggregate(fns ...AggregateFunc) *AuthSessionGroupBy { |
||||||
|
_g.fns = append(_g.fns, fns...) |
||||||
|
return _g |
||||||
|
} |
||||||
|
|
||||||
|
// Scan applies the selector query and scans the result into the given value.
|
||||||
|
func (_g *AuthSessionGroupBy) Scan(ctx context.Context, v any) error { |
||||||
|
ctx = setContextOp(ctx, _g.build.ctx, ent.OpQueryGroupBy) |
||||||
|
if err := _g.build.prepareQuery(ctx); err != nil { |
||||||
|
return err |
||||||
|
} |
||||||
|
return scanWithInterceptors[*AuthSessionQuery, *AuthSessionGroupBy](ctx, _g.build, _g, _g.build.inters, v) |
||||||
|
} |
||||||
|
|
||||||
|
func (_g *AuthSessionGroupBy) sqlScan(ctx context.Context, root *AuthSessionQuery, v any) error { |
||||||
|
selector := root.sqlQuery(ctx).Select() |
||||||
|
aggregation := make([]string, 0, len(_g.fns)) |
||||||
|
for _, fn := range _g.fns { |
||||||
|
aggregation = append(aggregation, fn(selector)) |
||||||
|
} |
||||||
|
if len(selector.SelectedColumns()) == 0 { |
||||||
|
columns := make([]string, 0, len(*_g.flds)+len(_g.fns)) |
||||||
|
for _, f := range *_g.flds { |
||||||
|
columns = append(columns, selector.C(f)) |
||||||
|
} |
||||||
|
columns = append(columns, aggregation...) |
||||||
|
selector.Select(columns...) |
||||||
|
} |
||||||
|
selector.GroupBy(selector.Columns(*_g.flds...)...) |
||||||
|
if err := selector.Err(); err != nil { |
||||||
|
return err |
||||||
|
} |
||||||
|
rows := &sql.Rows{} |
||||||
|
query, args := selector.Query() |
||||||
|
if err := _g.build.driver.Query(ctx, query, args, rows); err != nil { |
||||||
|
return err |
||||||
|
} |
||||||
|
defer rows.Close() |
||||||
|
return sql.ScanSlice(rows, v) |
||||||
|
} |
||||||
|
|
||||||
|
// AuthSessionSelect is the builder for selecting fields of AuthSession entities.
|
||||||
|
type AuthSessionSelect struct { |
||||||
|
*AuthSessionQuery |
||||||
|
selector |
||||||
|
} |
||||||
|
|
||||||
|
// Aggregate adds the given aggregation functions to the selector query.
|
||||||
|
func (_s *AuthSessionSelect) Aggregate(fns ...AggregateFunc) *AuthSessionSelect { |
||||||
|
_s.fns = append(_s.fns, fns...) |
||||||
|
return _s |
||||||
|
} |
||||||
|
|
||||||
|
// Scan applies the selector query and scans the result into the given value.
|
||||||
|
func (_s *AuthSessionSelect) Scan(ctx context.Context, v any) error { |
||||||
|
ctx = setContextOp(ctx, _s.ctx, ent.OpQuerySelect) |
||||||
|
if err := _s.prepareQuery(ctx); err != nil { |
||||||
|
return err |
||||||
|
} |
||||||
|
return scanWithInterceptors[*AuthSessionQuery, *AuthSessionSelect](ctx, _s.AuthSessionQuery, _s, _s.inters, v) |
||||||
|
} |
||||||
|
|
||||||
|
func (_s *AuthSessionSelect) sqlScan(ctx context.Context, root *AuthSessionQuery, v any) error { |
||||||
|
selector := root.sqlQuery(ctx) |
||||||
|
aggregation := make([]string, 0, len(_s.fns)) |
||||||
|
for _, fn := range _s.fns { |
||||||
|
aggregation = append(aggregation, fn(selector)) |
||||||
|
} |
||||||
|
switch n := len(*_s.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 := _s.driver.Query(ctx, query, args, rows); err != nil { |
||||||
|
return err |
||||||
|
} |
||||||
|
defer rows.Close() |
||||||
|
return sql.ScanSlice(rows, v) |
||||||
|
} |
||||||
@ -0,0 +1,330 @@ |
|||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package db |
||||||
|
|
||||||
|
import ( |
||||||
|
"context" |
||||||
|
"errors" |
||||||
|
"fmt" |
||||||
|
"time" |
||||||
|
|
||||||
|
"entgo.io/ent/dialect/sql" |
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph" |
||||||
|
"entgo.io/ent/schema/field" |
||||||
|
"github.com/dexidp/dex/storage/ent/db/authsession" |
||||||
|
"github.com/dexidp/dex/storage/ent/db/predicate" |
||||||
|
) |
||||||
|
|
||||||
|
// AuthSessionUpdate is the builder for updating AuthSession entities.
|
||||||
|
type AuthSessionUpdate struct { |
||||||
|
config |
||||||
|
hooks []Hook |
||||||
|
mutation *AuthSessionMutation |
||||||
|
} |
||||||
|
|
||||||
|
// Where appends a list predicates to the AuthSessionUpdate builder.
|
||||||
|
func (_u *AuthSessionUpdate) Where(ps ...predicate.AuthSession) *AuthSessionUpdate { |
||||||
|
_u.mutation.Where(ps...) |
||||||
|
return _u |
||||||
|
} |
||||||
|
|
||||||
|
// SetClientStates sets the "client_states" field.
|
||||||
|
func (_u *AuthSessionUpdate) SetClientStates(v []byte) *AuthSessionUpdate { |
||||||
|
_u.mutation.SetClientStates(v) |
||||||
|
return _u |
||||||
|
} |
||||||
|
|
||||||
|
// SetCreatedAt sets the "created_at" field.
|
||||||
|
func (_u *AuthSessionUpdate) SetCreatedAt(v time.Time) *AuthSessionUpdate { |
||||||
|
_u.mutation.SetCreatedAt(v) |
||||||
|
return _u |
||||||
|
} |
||||||
|
|
||||||
|
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
||||||
|
func (_u *AuthSessionUpdate) SetNillableCreatedAt(v *time.Time) *AuthSessionUpdate { |
||||||
|
if v != nil { |
||||||
|
_u.SetCreatedAt(*v) |
||||||
|
} |
||||||
|
return _u |
||||||
|
} |
||||||
|
|
||||||
|
// SetLastActivity sets the "last_activity" field.
|
||||||
|
func (_u *AuthSessionUpdate) SetLastActivity(v time.Time) *AuthSessionUpdate { |
||||||
|
_u.mutation.SetLastActivity(v) |
||||||
|
return _u |
||||||
|
} |
||||||
|
|
||||||
|
// SetNillableLastActivity sets the "last_activity" field if the given value is not nil.
|
||||||
|
func (_u *AuthSessionUpdate) SetNillableLastActivity(v *time.Time) *AuthSessionUpdate { |
||||||
|
if v != nil { |
||||||
|
_u.SetLastActivity(*v) |
||||||
|
} |
||||||
|
return _u |
||||||
|
} |
||||||
|
|
||||||
|
// SetIPAddress sets the "ip_address" field.
|
||||||
|
func (_u *AuthSessionUpdate) SetIPAddress(v string) *AuthSessionUpdate { |
||||||
|
_u.mutation.SetIPAddress(v) |
||||||
|
return _u |
||||||
|
} |
||||||
|
|
||||||
|
// SetNillableIPAddress sets the "ip_address" field if the given value is not nil.
|
||||||
|
func (_u *AuthSessionUpdate) SetNillableIPAddress(v *string) *AuthSessionUpdate { |
||||||
|
if v != nil { |
||||||
|
_u.SetIPAddress(*v) |
||||||
|
} |
||||||
|
return _u |
||||||
|
} |
||||||
|
|
||||||
|
// SetUserAgent sets the "user_agent" field.
|
||||||
|
func (_u *AuthSessionUpdate) SetUserAgent(v string) *AuthSessionUpdate { |
||||||
|
_u.mutation.SetUserAgent(v) |
||||||
|
return _u |
||||||
|
} |
||||||
|
|
||||||
|
// SetNillableUserAgent sets the "user_agent" field if the given value is not nil.
|
||||||
|
func (_u *AuthSessionUpdate) SetNillableUserAgent(v *string) *AuthSessionUpdate { |
||||||
|
if v != nil { |
||||||
|
_u.SetUserAgent(*v) |
||||||
|
} |
||||||
|
return _u |
||||||
|
} |
||||||
|
|
||||||
|
// Mutation returns the AuthSessionMutation object of the builder.
|
||||||
|
func (_u *AuthSessionUpdate) Mutation() *AuthSessionMutation { |
||||||
|
return _u.mutation |
||||||
|
} |
||||||
|
|
||||||
|
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||||
|
func (_u *AuthSessionUpdate) Save(ctx context.Context) (int, error) { |
||||||
|
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) |
||||||
|
} |
||||||
|
|
||||||
|
// SaveX is like Save, but panics if an error occurs.
|
||||||
|
func (_u *AuthSessionUpdate) SaveX(ctx context.Context) int { |
||||||
|
affected, err := _u.Save(ctx) |
||||||
|
if err != nil { |
||||||
|
panic(err) |
||||||
|
} |
||||||
|
return affected |
||||||
|
} |
||||||
|
|
||||||
|
// Exec executes the query.
|
||||||
|
func (_u *AuthSessionUpdate) Exec(ctx context.Context) error { |
||||||
|
_, err := _u.Save(ctx) |
||||||
|
return err |
||||||
|
} |
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (_u *AuthSessionUpdate) ExecX(ctx context.Context) { |
||||||
|
if err := _u.Exec(ctx); err != nil { |
||||||
|
panic(err) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
func (_u *AuthSessionUpdate) sqlSave(ctx context.Context) (_node int, err error) { |
||||||
|
_spec := sqlgraph.NewUpdateSpec(authsession.Table, authsession.Columns, sqlgraph.NewFieldSpec(authsession.FieldID, field.TypeString)) |
||||||
|
if ps := _u.mutation.predicates; len(ps) > 0 { |
||||||
|
_spec.Predicate = func(selector *sql.Selector) { |
||||||
|
for i := range ps { |
||||||
|
ps[i](selector) |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
if value, ok := _u.mutation.ClientStates(); ok { |
||||||
|
_spec.SetField(authsession.FieldClientStates, field.TypeBytes, value) |
||||||
|
} |
||||||
|
if value, ok := _u.mutation.CreatedAt(); ok { |
||||||
|
_spec.SetField(authsession.FieldCreatedAt, field.TypeTime, value) |
||||||
|
} |
||||||
|
if value, ok := _u.mutation.LastActivity(); ok { |
||||||
|
_spec.SetField(authsession.FieldLastActivity, field.TypeTime, value) |
||||||
|
} |
||||||
|
if value, ok := _u.mutation.IPAddress(); ok { |
||||||
|
_spec.SetField(authsession.FieldIPAddress, field.TypeString, value) |
||||||
|
} |
||||||
|
if value, ok := _u.mutation.UserAgent(); ok { |
||||||
|
_spec.SetField(authsession.FieldUserAgent, field.TypeString, value) |
||||||
|
} |
||||||
|
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil { |
||||||
|
if _, ok := err.(*sqlgraph.NotFoundError); ok { |
||||||
|
err = &NotFoundError{authsession.Label} |
||||||
|
} else if sqlgraph.IsConstraintError(err) { |
||||||
|
err = &ConstraintError{msg: err.Error(), wrap: err} |
||||||
|
} |
||||||
|
return 0, err |
||||||
|
} |
||||||
|
_u.mutation.done = true |
||||||
|
return _node, nil |
||||||
|
} |
||||||
|
|
||||||
|
// AuthSessionUpdateOne is the builder for updating a single AuthSession entity.
|
||||||
|
type AuthSessionUpdateOne struct { |
||||||
|
config |
||||||
|
fields []string |
||||||
|
hooks []Hook |
||||||
|
mutation *AuthSessionMutation |
||||||
|
} |
||||||
|
|
||||||
|
// SetClientStates sets the "client_states" field.
|
||||||
|
func (_u *AuthSessionUpdateOne) SetClientStates(v []byte) *AuthSessionUpdateOne { |
||||||
|
_u.mutation.SetClientStates(v) |
||||||
|
return _u |
||||||
|
} |
||||||
|
|
||||||
|
// SetCreatedAt sets the "created_at" field.
|
||||||
|
func (_u *AuthSessionUpdateOne) SetCreatedAt(v time.Time) *AuthSessionUpdateOne { |
||||||
|
_u.mutation.SetCreatedAt(v) |
||||||
|
return _u |
||||||
|
} |
||||||
|
|
||||||
|
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
||||||
|
func (_u *AuthSessionUpdateOne) SetNillableCreatedAt(v *time.Time) *AuthSessionUpdateOne { |
||||||
|
if v != nil { |
||||||
|
_u.SetCreatedAt(*v) |
||||||
|
} |
||||||
|
return _u |
||||||
|
} |
||||||
|
|
||||||
|
// SetLastActivity sets the "last_activity" field.
|
||||||
|
func (_u *AuthSessionUpdateOne) SetLastActivity(v time.Time) *AuthSessionUpdateOne { |
||||||
|
_u.mutation.SetLastActivity(v) |
||||||
|
return _u |
||||||
|
} |
||||||
|
|
||||||
|
// SetNillableLastActivity sets the "last_activity" field if the given value is not nil.
|
||||||
|
func (_u *AuthSessionUpdateOne) SetNillableLastActivity(v *time.Time) *AuthSessionUpdateOne { |
||||||
|
if v != nil { |
||||||
|
_u.SetLastActivity(*v) |
||||||
|
} |
||||||
|
return _u |
||||||
|
} |
||||||
|
|
||||||
|
// SetIPAddress sets the "ip_address" field.
|
||||||
|
func (_u *AuthSessionUpdateOne) SetIPAddress(v string) *AuthSessionUpdateOne { |
||||||
|
_u.mutation.SetIPAddress(v) |
||||||
|
return _u |
||||||
|
} |
||||||
|
|
||||||
|
// SetNillableIPAddress sets the "ip_address" field if the given value is not nil.
|
||||||
|
func (_u *AuthSessionUpdateOne) SetNillableIPAddress(v *string) *AuthSessionUpdateOne { |
||||||
|
if v != nil { |
||||||
|
_u.SetIPAddress(*v) |
||||||
|
} |
||||||
|
return _u |
||||||
|
} |
||||||
|
|
||||||
|
// SetUserAgent sets the "user_agent" field.
|
||||||
|
func (_u *AuthSessionUpdateOne) SetUserAgent(v string) *AuthSessionUpdateOne { |
||||||
|
_u.mutation.SetUserAgent(v) |
||||||
|
return _u |
||||||
|
} |
||||||
|
|
||||||
|
// SetNillableUserAgent sets the "user_agent" field if the given value is not nil.
|
||||||
|
func (_u *AuthSessionUpdateOne) SetNillableUserAgent(v *string) *AuthSessionUpdateOne { |
||||||
|
if v != nil { |
||||||
|
_u.SetUserAgent(*v) |
||||||
|
} |
||||||
|
return _u |
||||||
|
} |
||||||
|
|
||||||
|
// Mutation returns the AuthSessionMutation object of the builder.
|
||||||
|
func (_u *AuthSessionUpdateOne) Mutation() *AuthSessionMutation { |
||||||
|
return _u.mutation |
||||||
|
} |
||||||
|
|
||||||
|
// Where appends a list predicates to the AuthSessionUpdate builder.
|
||||||
|
func (_u *AuthSessionUpdateOne) Where(ps ...predicate.AuthSession) *AuthSessionUpdateOne { |
||||||
|
_u.mutation.Where(ps...) |
||||||
|
return _u |
||||||
|
} |
||||||
|
|
||||||
|
// Select allows selecting one or more fields (columns) of the returned entity.
|
||||||
|
// The default is selecting all fields defined in the entity schema.
|
||||||
|
func (_u *AuthSessionUpdateOne) Select(field string, fields ...string) *AuthSessionUpdateOne { |
||||||
|
_u.fields = append([]string{field}, fields...) |
||||||
|
return _u |
||||||
|
} |
||||||
|
|
||||||
|
// Save executes the query and returns the updated AuthSession entity.
|
||||||
|
func (_u *AuthSessionUpdateOne) Save(ctx context.Context) (*AuthSession, error) { |
||||||
|
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) |
||||||
|
} |
||||||
|
|
||||||
|
// SaveX is like Save, but panics if an error occurs.
|
||||||
|
func (_u *AuthSessionUpdateOne) SaveX(ctx context.Context) *AuthSession { |
||||||
|
node, err := _u.Save(ctx) |
||||||
|
if err != nil { |
||||||
|
panic(err) |
||||||
|
} |
||||||
|
return node |
||||||
|
} |
||||||
|
|
||||||
|
// Exec executes the query on the entity.
|
||||||
|
func (_u *AuthSessionUpdateOne) Exec(ctx context.Context) error { |
||||||
|
_, err := _u.Save(ctx) |
||||||
|
return err |
||||||
|
} |
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (_u *AuthSessionUpdateOne) ExecX(ctx context.Context) { |
||||||
|
if err := _u.Exec(ctx); err != nil { |
||||||
|
panic(err) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
func (_u *AuthSessionUpdateOne) sqlSave(ctx context.Context) (_node *AuthSession, err error) { |
||||||
|
_spec := sqlgraph.NewUpdateSpec(authsession.Table, authsession.Columns, sqlgraph.NewFieldSpec(authsession.FieldID, field.TypeString)) |
||||||
|
id, ok := _u.mutation.ID() |
||||||
|
if !ok { |
||||||
|
return nil, &ValidationError{Name: "id", err: errors.New(`db: missing "AuthSession.id" for update`)} |
||||||
|
} |
||||||
|
_spec.Node.ID.Value = id |
||||||
|
if fields := _u.fields; len(fields) > 0 { |
||||||
|
_spec.Node.Columns = make([]string, 0, len(fields)) |
||||||
|
_spec.Node.Columns = append(_spec.Node.Columns, authsession.FieldID) |
||||||
|
for _, f := range fields { |
||||||
|
if !authsession.ValidColumn(f) { |
||||||
|
return nil, &ValidationError{Name: f, err: fmt.Errorf("db: invalid field %q for query", f)} |
||||||
|
} |
||||||
|
if f != authsession.FieldID { |
||||||
|
_spec.Node.Columns = append(_spec.Node.Columns, f) |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
if ps := _u.mutation.predicates; len(ps) > 0 { |
||||||
|
_spec.Predicate = func(selector *sql.Selector) { |
||||||
|
for i := range ps { |
||||||
|
ps[i](selector) |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
if value, ok := _u.mutation.ClientStates(); ok { |
||||||
|
_spec.SetField(authsession.FieldClientStates, field.TypeBytes, value) |
||||||
|
} |
||||||
|
if value, ok := _u.mutation.CreatedAt(); ok { |
||||||
|
_spec.SetField(authsession.FieldCreatedAt, field.TypeTime, value) |
||||||
|
} |
||||||
|
if value, ok := _u.mutation.LastActivity(); ok { |
||||||
|
_spec.SetField(authsession.FieldLastActivity, field.TypeTime, value) |
||||||
|
} |
||||||
|
if value, ok := _u.mutation.IPAddress(); ok { |
||||||
|
_spec.SetField(authsession.FieldIPAddress, field.TypeString, value) |
||||||
|
} |
||||||
|
if value, ok := _u.mutation.UserAgent(); ok { |
||||||
|
_spec.SetField(authsession.FieldUserAgent, field.TypeString, value) |
||||||
|
} |
||||||
|
_node = &AuthSession{config: _u.config} |
||||||
|
_spec.Assign = _node.assignValues |
||||||
|
_spec.ScanValues = _node.scanValues |
||||||
|
if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil { |
||||||
|
if _, ok := err.(*sqlgraph.NotFoundError); ok { |
||||||
|
err = &NotFoundError{authsession.Label} |
||||||
|
} else if sqlgraph.IsConstraintError(err) { |
||||||
|
err = &ConstraintError{msg: err.Error(), wrap: err} |
||||||
|
} |
||||||
|
return nil, err |
||||||
|
} |
||||||
|
_u.mutation.done = true |
||||||
|
return _node, nil |
||||||
|
} |
||||||
@ -0,0 +1,37 @@ |
|||||||
|
package schema |
||||||
|
|
||||||
|
import ( |
||||||
|
"entgo.io/ent" |
||||||
|
"entgo.io/ent/schema/field" |
||||||
|
) |
||||||
|
|
||||||
|
// AuthSession holds the schema definition for the AuthSession entity.
|
||||||
|
type AuthSession struct { |
||||||
|
ent.Schema |
||||||
|
} |
||||||
|
|
||||||
|
// Fields of the AuthSession.
|
||||||
|
func (AuthSession) Fields() []ent.Field { |
||||||
|
return []ent.Field{ |
||||||
|
field.Text("id"). |
||||||
|
SchemaType(textSchema). |
||||||
|
NotEmpty(). |
||||||
|
Unique(), |
||||||
|
field.Bytes("client_states"), |
||||||
|
field.Time("created_at"). |
||||||
|
SchemaType(timeSchema), |
||||||
|
field.Time("last_activity"). |
||||||
|
SchemaType(timeSchema), |
||||||
|
field.Text("ip_address"). |
||||||
|
SchemaType(textSchema). |
||||||
|
Default(""), |
||||||
|
field.Text("user_agent"). |
||||||
|
SchemaType(textSchema). |
||||||
|
Default(""), |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
// Edges of the AuthSession.
|
||||||
|
func (AuthSession) Edges() []ent.Edge { |
||||||
|
return []ent.Edge{} |
||||||
|
} |
||||||
Loading…
Reference in new issue