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.
321 lines
9.3 KiB
321 lines
9.3 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/dialect/sql/sqljson" |
|
"entgo.io/ent/schema/field" |
|
"github.com/dexidp/dex/storage" |
|
"github.com/dexidp/dex/storage/ent/db/keys" |
|
"github.com/dexidp/dex/storage/ent/db/predicate" |
|
jose "github.com/go-jose/go-jose/v4" |
|
) |
|
|
|
// KeysUpdate is the builder for updating Keys entities. |
|
type KeysUpdate struct { |
|
config |
|
hooks []Hook |
|
mutation *KeysMutation |
|
} |
|
|
|
// Where appends a list predicates to the KeysUpdate builder. |
|
func (_u *KeysUpdate) Where(ps ...predicate.Keys) *KeysUpdate { |
|
_u.mutation.Where(ps...) |
|
return _u |
|
} |
|
|
|
// SetVerificationKeys sets the "verification_keys" field. |
|
func (_u *KeysUpdate) SetVerificationKeys(v []storage.VerificationKey) *KeysUpdate { |
|
_u.mutation.SetVerificationKeys(v) |
|
return _u |
|
} |
|
|
|
// AppendVerificationKeys appends value to the "verification_keys" field. |
|
func (_u *KeysUpdate) AppendVerificationKeys(v []storage.VerificationKey) *KeysUpdate { |
|
_u.mutation.AppendVerificationKeys(v) |
|
return _u |
|
} |
|
|
|
// SetSigningKey sets the "signing_key" field. |
|
func (_u *KeysUpdate) SetSigningKey(v jose.JSONWebKey) *KeysUpdate { |
|
_u.mutation.SetSigningKey(v) |
|
return _u |
|
} |
|
|
|
// SetNillableSigningKey sets the "signing_key" field if the given value is not nil. |
|
func (_u *KeysUpdate) SetNillableSigningKey(v *jose.JSONWebKey) *KeysUpdate { |
|
if v != nil { |
|
_u.SetSigningKey(*v) |
|
} |
|
return _u |
|
} |
|
|
|
// SetSigningKeyPub sets the "signing_key_pub" field. |
|
func (_u *KeysUpdate) SetSigningKeyPub(v jose.JSONWebKey) *KeysUpdate { |
|
_u.mutation.SetSigningKeyPub(v) |
|
return _u |
|
} |
|
|
|
// SetNillableSigningKeyPub sets the "signing_key_pub" field if the given value is not nil. |
|
func (_u *KeysUpdate) SetNillableSigningKeyPub(v *jose.JSONWebKey) *KeysUpdate { |
|
if v != nil { |
|
_u.SetSigningKeyPub(*v) |
|
} |
|
return _u |
|
} |
|
|
|
// SetNextRotation sets the "next_rotation" field. |
|
func (_u *KeysUpdate) SetNextRotation(v time.Time) *KeysUpdate { |
|
_u.mutation.SetNextRotation(v) |
|
return _u |
|
} |
|
|
|
// SetNillableNextRotation sets the "next_rotation" field if the given value is not nil. |
|
func (_u *KeysUpdate) SetNillableNextRotation(v *time.Time) *KeysUpdate { |
|
if v != nil { |
|
_u.SetNextRotation(*v) |
|
} |
|
return _u |
|
} |
|
|
|
// Mutation returns the KeysMutation object of the builder. |
|
func (_u *KeysUpdate) Mutation() *KeysMutation { |
|
return _u.mutation |
|
} |
|
|
|
// Save executes the query and returns the number of nodes affected by the update operation. |
|
func (_u *KeysUpdate) 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 *KeysUpdate) SaveX(ctx context.Context) int { |
|
affected, err := _u.Save(ctx) |
|
if err != nil { |
|
panic(err) |
|
} |
|
return affected |
|
} |
|
|
|
// Exec executes the query. |
|
func (_u *KeysUpdate) Exec(ctx context.Context) error { |
|
_, err := _u.Save(ctx) |
|
return err |
|
} |
|
|
|
// ExecX is like Exec, but panics if an error occurs. |
|
func (_u *KeysUpdate) ExecX(ctx context.Context) { |
|
if err := _u.Exec(ctx); err != nil { |
|
panic(err) |
|
} |
|
} |
|
|
|
func (_u *KeysUpdate) sqlSave(ctx context.Context) (_node int, err error) { |
|
_spec := sqlgraph.NewUpdateSpec(keys.Table, keys.Columns, sqlgraph.NewFieldSpec(keys.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.VerificationKeys(); ok { |
|
_spec.SetField(keys.FieldVerificationKeys, field.TypeJSON, value) |
|
} |
|
if value, ok := _u.mutation.AppendedVerificationKeys(); ok { |
|
_spec.AddModifier(func(u *sql.UpdateBuilder) { |
|
sqljson.Append(u, keys.FieldVerificationKeys, value) |
|
}) |
|
} |
|
if value, ok := _u.mutation.SigningKey(); ok { |
|
_spec.SetField(keys.FieldSigningKey, field.TypeJSON, value) |
|
} |
|
if value, ok := _u.mutation.SigningKeyPub(); ok { |
|
_spec.SetField(keys.FieldSigningKeyPub, field.TypeJSON, value) |
|
} |
|
if value, ok := _u.mutation.NextRotation(); ok { |
|
_spec.SetField(keys.FieldNextRotation, field.TypeTime, value) |
|
} |
|
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil { |
|
if _, ok := err.(*sqlgraph.NotFoundError); ok { |
|
err = &NotFoundError{keys.Label} |
|
} else if sqlgraph.IsConstraintError(err) { |
|
err = &ConstraintError{msg: err.Error(), wrap: err} |
|
} |
|
return 0, err |
|
} |
|
_u.mutation.done = true |
|
return _node, nil |
|
} |
|
|
|
// KeysUpdateOne is the builder for updating a single Keys entity. |
|
type KeysUpdateOne struct { |
|
config |
|
fields []string |
|
hooks []Hook |
|
mutation *KeysMutation |
|
} |
|
|
|
// SetVerificationKeys sets the "verification_keys" field. |
|
func (_u *KeysUpdateOne) SetVerificationKeys(v []storage.VerificationKey) *KeysUpdateOne { |
|
_u.mutation.SetVerificationKeys(v) |
|
return _u |
|
} |
|
|
|
// AppendVerificationKeys appends value to the "verification_keys" field. |
|
func (_u *KeysUpdateOne) AppendVerificationKeys(v []storage.VerificationKey) *KeysUpdateOne { |
|
_u.mutation.AppendVerificationKeys(v) |
|
return _u |
|
} |
|
|
|
// SetSigningKey sets the "signing_key" field. |
|
func (_u *KeysUpdateOne) SetSigningKey(v jose.JSONWebKey) *KeysUpdateOne { |
|
_u.mutation.SetSigningKey(v) |
|
return _u |
|
} |
|
|
|
// SetNillableSigningKey sets the "signing_key" field if the given value is not nil. |
|
func (_u *KeysUpdateOne) SetNillableSigningKey(v *jose.JSONWebKey) *KeysUpdateOne { |
|
if v != nil { |
|
_u.SetSigningKey(*v) |
|
} |
|
return _u |
|
} |
|
|
|
// SetSigningKeyPub sets the "signing_key_pub" field. |
|
func (_u *KeysUpdateOne) SetSigningKeyPub(v jose.JSONWebKey) *KeysUpdateOne { |
|
_u.mutation.SetSigningKeyPub(v) |
|
return _u |
|
} |
|
|
|
// SetNillableSigningKeyPub sets the "signing_key_pub" field if the given value is not nil. |
|
func (_u *KeysUpdateOne) SetNillableSigningKeyPub(v *jose.JSONWebKey) *KeysUpdateOne { |
|
if v != nil { |
|
_u.SetSigningKeyPub(*v) |
|
} |
|
return _u |
|
} |
|
|
|
// SetNextRotation sets the "next_rotation" field. |
|
func (_u *KeysUpdateOne) SetNextRotation(v time.Time) *KeysUpdateOne { |
|
_u.mutation.SetNextRotation(v) |
|
return _u |
|
} |
|
|
|
// SetNillableNextRotation sets the "next_rotation" field if the given value is not nil. |
|
func (_u *KeysUpdateOne) SetNillableNextRotation(v *time.Time) *KeysUpdateOne { |
|
if v != nil { |
|
_u.SetNextRotation(*v) |
|
} |
|
return _u |
|
} |
|
|
|
// Mutation returns the KeysMutation object of the builder. |
|
func (_u *KeysUpdateOne) Mutation() *KeysMutation { |
|
return _u.mutation |
|
} |
|
|
|
// Where appends a list predicates to the KeysUpdate builder. |
|
func (_u *KeysUpdateOne) Where(ps ...predicate.Keys) *KeysUpdateOne { |
|
_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 *KeysUpdateOne) Select(field string, fields ...string) *KeysUpdateOne { |
|
_u.fields = append([]string{field}, fields...) |
|
return _u |
|
} |
|
|
|
// Save executes the query and returns the updated Keys entity. |
|
func (_u *KeysUpdateOne) Save(ctx context.Context) (*Keys, error) { |
|
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) |
|
} |
|
|
|
// SaveX is like Save, but panics if an error occurs. |
|
func (_u *KeysUpdateOne) SaveX(ctx context.Context) *Keys { |
|
node, err := _u.Save(ctx) |
|
if err != nil { |
|
panic(err) |
|
} |
|
return node |
|
} |
|
|
|
// Exec executes the query on the entity. |
|
func (_u *KeysUpdateOne) Exec(ctx context.Context) error { |
|
_, err := _u.Save(ctx) |
|
return err |
|
} |
|
|
|
// ExecX is like Exec, but panics if an error occurs. |
|
func (_u *KeysUpdateOne) ExecX(ctx context.Context) { |
|
if err := _u.Exec(ctx); err != nil { |
|
panic(err) |
|
} |
|
} |
|
|
|
func (_u *KeysUpdateOne) sqlSave(ctx context.Context) (_node *Keys, err error) { |
|
_spec := sqlgraph.NewUpdateSpec(keys.Table, keys.Columns, sqlgraph.NewFieldSpec(keys.FieldID, field.TypeString)) |
|
id, ok := _u.mutation.ID() |
|
if !ok { |
|
return nil, &ValidationError{Name: "id", err: errors.New(`db: missing "Keys.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, keys.FieldID) |
|
for _, f := range fields { |
|
if !keys.ValidColumn(f) { |
|
return nil, &ValidationError{Name: f, err: fmt.Errorf("db: invalid field %q for query", f)} |
|
} |
|
if f != keys.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.VerificationKeys(); ok { |
|
_spec.SetField(keys.FieldVerificationKeys, field.TypeJSON, value) |
|
} |
|
if value, ok := _u.mutation.AppendedVerificationKeys(); ok { |
|
_spec.AddModifier(func(u *sql.UpdateBuilder) { |
|
sqljson.Append(u, keys.FieldVerificationKeys, value) |
|
}) |
|
} |
|
if value, ok := _u.mutation.SigningKey(); ok { |
|
_spec.SetField(keys.FieldSigningKey, field.TypeJSON, value) |
|
} |
|
if value, ok := _u.mutation.SigningKeyPub(); ok { |
|
_spec.SetField(keys.FieldSigningKeyPub, field.TypeJSON, value) |
|
} |
|
if value, ok := _u.mutation.NextRotation(); ok { |
|
_spec.SetField(keys.FieldNextRotation, field.TypeTime, value) |
|
} |
|
_node = &Keys{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{keys.Label} |
|
} else if sqlgraph.IsConstraintError(err) { |
|
err = &ConstraintError{msg: err.Error(), wrap: err} |
|
} |
|
return nil, err |
|
} |
|
_u.mutation.done = true |
|
return _node, nil |
|
}
|
|
|