mirror of https://github.com/dexidp/dex.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
330 lines
9.8 KiB
330 lines
9.8 KiB
// 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 |
|
}
|
|
|