OpenID Connect (OIDC) identity and OAuth 2.0 provider with pluggable connectors
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.
 
 
 
 
 
 

461 lines
14 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/ent/db/devicerequest"
"github.com/dexidp/dex/storage/ent/db/predicate"
)
// DeviceRequestUpdate is the builder for updating DeviceRequest entities.
type DeviceRequestUpdate struct {
config
hooks []Hook
mutation *DeviceRequestMutation
}
// Where appends a list predicates to the DeviceRequestUpdate builder.
func (_u *DeviceRequestUpdate) Where(ps ...predicate.DeviceRequest) *DeviceRequestUpdate {
_u.mutation.Where(ps...)
return _u
}
// SetUserCode sets the "user_code" field.
func (_u *DeviceRequestUpdate) SetUserCode(v string) *DeviceRequestUpdate {
_u.mutation.SetUserCode(v)
return _u
}
// SetNillableUserCode sets the "user_code" field if the given value is not nil.
func (_u *DeviceRequestUpdate) SetNillableUserCode(v *string) *DeviceRequestUpdate {
if v != nil {
_u.SetUserCode(*v)
}
return _u
}
// SetDeviceCode sets the "device_code" field.
func (_u *DeviceRequestUpdate) SetDeviceCode(v string) *DeviceRequestUpdate {
_u.mutation.SetDeviceCode(v)
return _u
}
// SetNillableDeviceCode sets the "device_code" field if the given value is not nil.
func (_u *DeviceRequestUpdate) SetNillableDeviceCode(v *string) *DeviceRequestUpdate {
if v != nil {
_u.SetDeviceCode(*v)
}
return _u
}
// SetClientID sets the "client_id" field.
func (_u *DeviceRequestUpdate) SetClientID(v string) *DeviceRequestUpdate {
_u.mutation.SetClientID(v)
return _u
}
// SetNillableClientID sets the "client_id" field if the given value is not nil.
func (_u *DeviceRequestUpdate) SetNillableClientID(v *string) *DeviceRequestUpdate {
if v != nil {
_u.SetClientID(*v)
}
return _u
}
// SetClientSecret sets the "client_secret" field.
func (_u *DeviceRequestUpdate) SetClientSecret(v string) *DeviceRequestUpdate {
_u.mutation.SetClientSecret(v)
return _u
}
// SetNillableClientSecret sets the "client_secret" field if the given value is not nil.
func (_u *DeviceRequestUpdate) SetNillableClientSecret(v *string) *DeviceRequestUpdate {
if v != nil {
_u.SetClientSecret(*v)
}
return _u
}
// SetScopes sets the "scopes" field.
func (_u *DeviceRequestUpdate) SetScopes(v []string) *DeviceRequestUpdate {
_u.mutation.SetScopes(v)
return _u
}
// AppendScopes appends value to the "scopes" field.
func (_u *DeviceRequestUpdate) AppendScopes(v []string) *DeviceRequestUpdate {
_u.mutation.AppendScopes(v)
return _u
}
// ClearScopes clears the value of the "scopes" field.
func (_u *DeviceRequestUpdate) ClearScopes() *DeviceRequestUpdate {
_u.mutation.ClearScopes()
return _u
}
// SetExpiry sets the "expiry" field.
func (_u *DeviceRequestUpdate) SetExpiry(v time.Time) *DeviceRequestUpdate {
_u.mutation.SetExpiry(v)
return _u
}
// SetNillableExpiry sets the "expiry" field if the given value is not nil.
func (_u *DeviceRequestUpdate) SetNillableExpiry(v *time.Time) *DeviceRequestUpdate {
if v != nil {
_u.SetExpiry(*v)
}
return _u
}
// Mutation returns the DeviceRequestMutation object of the builder.
func (_u *DeviceRequestUpdate) Mutation() *DeviceRequestMutation {
return _u.mutation
}
// Save executes the query and returns the number of nodes affected by the update operation.
func (_u *DeviceRequestUpdate) 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 *DeviceRequestUpdate) SaveX(ctx context.Context) int {
affected, err := _u.Save(ctx)
if err != nil {
panic(err)
}
return affected
}
// Exec executes the query.
func (_u *DeviceRequestUpdate) Exec(ctx context.Context) error {
_, err := _u.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_u *DeviceRequestUpdate) ExecX(ctx context.Context) {
if err := _u.Exec(ctx); err != nil {
panic(err)
}
}
// check runs all checks and user-defined validators on the builder.
func (_u *DeviceRequestUpdate) check() error {
if v, ok := _u.mutation.UserCode(); ok {
if err := devicerequest.UserCodeValidator(v); err != nil {
return &ValidationError{Name: "user_code", err: fmt.Errorf(`db: validator failed for field "DeviceRequest.user_code": %w`, err)}
}
}
if v, ok := _u.mutation.DeviceCode(); ok {
if err := devicerequest.DeviceCodeValidator(v); err != nil {
return &ValidationError{Name: "device_code", err: fmt.Errorf(`db: validator failed for field "DeviceRequest.device_code": %w`, err)}
}
}
if v, ok := _u.mutation.ClientID(); ok {
if err := devicerequest.ClientIDValidator(v); err != nil {
return &ValidationError{Name: "client_id", err: fmt.Errorf(`db: validator failed for field "DeviceRequest.client_id": %w`, err)}
}
}
if v, ok := _u.mutation.ClientSecret(); ok {
if err := devicerequest.ClientSecretValidator(v); err != nil {
return &ValidationError{Name: "client_secret", err: fmt.Errorf(`db: validator failed for field "DeviceRequest.client_secret": %w`, err)}
}
}
return nil
}
func (_u *DeviceRequestUpdate) sqlSave(ctx context.Context) (_node int, err error) {
if err := _u.check(); err != nil {
return _node, err
}
_spec := sqlgraph.NewUpdateSpec(devicerequest.Table, devicerequest.Columns, sqlgraph.NewFieldSpec(devicerequest.FieldID, field.TypeInt))
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.UserCode(); ok {
_spec.SetField(devicerequest.FieldUserCode, field.TypeString, value)
}
if value, ok := _u.mutation.DeviceCode(); ok {
_spec.SetField(devicerequest.FieldDeviceCode, field.TypeString, value)
}
if value, ok := _u.mutation.ClientID(); ok {
_spec.SetField(devicerequest.FieldClientID, field.TypeString, value)
}
if value, ok := _u.mutation.ClientSecret(); ok {
_spec.SetField(devicerequest.FieldClientSecret, field.TypeString, value)
}
if value, ok := _u.mutation.Scopes(); ok {
_spec.SetField(devicerequest.FieldScopes, field.TypeJSON, value)
}
if value, ok := _u.mutation.AppendedScopes(); ok {
_spec.AddModifier(func(u *sql.UpdateBuilder) {
sqljson.Append(u, devicerequest.FieldScopes, value)
})
}
if _u.mutation.ScopesCleared() {
_spec.ClearField(devicerequest.FieldScopes, field.TypeJSON)
}
if value, ok := _u.mutation.Expiry(); ok {
_spec.SetField(devicerequest.FieldExpiry, field.TypeTime, value)
}
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{devicerequest.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return 0, err
}
_u.mutation.done = true
return _node, nil
}
// DeviceRequestUpdateOne is the builder for updating a single DeviceRequest entity.
type DeviceRequestUpdateOne struct {
config
fields []string
hooks []Hook
mutation *DeviceRequestMutation
}
// SetUserCode sets the "user_code" field.
func (_u *DeviceRequestUpdateOne) SetUserCode(v string) *DeviceRequestUpdateOne {
_u.mutation.SetUserCode(v)
return _u
}
// SetNillableUserCode sets the "user_code" field if the given value is not nil.
func (_u *DeviceRequestUpdateOne) SetNillableUserCode(v *string) *DeviceRequestUpdateOne {
if v != nil {
_u.SetUserCode(*v)
}
return _u
}
// SetDeviceCode sets the "device_code" field.
func (_u *DeviceRequestUpdateOne) SetDeviceCode(v string) *DeviceRequestUpdateOne {
_u.mutation.SetDeviceCode(v)
return _u
}
// SetNillableDeviceCode sets the "device_code" field if the given value is not nil.
func (_u *DeviceRequestUpdateOne) SetNillableDeviceCode(v *string) *DeviceRequestUpdateOne {
if v != nil {
_u.SetDeviceCode(*v)
}
return _u
}
// SetClientID sets the "client_id" field.
func (_u *DeviceRequestUpdateOne) SetClientID(v string) *DeviceRequestUpdateOne {
_u.mutation.SetClientID(v)
return _u
}
// SetNillableClientID sets the "client_id" field if the given value is not nil.
func (_u *DeviceRequestUpdateOne) SetNillableClientID(v *string) *DeviceRequestUpdateOne {
if v != nil {
_u.SetClientID(*v)
}
return _u
}
// SetClientSecret sets the "client_secret" field.
func (_u *DeviceRequestUpdateOne) SetClientSecret(v string) *DeviceRequestUpdateOne {
_u.mutation.SetClientSecret(v)
return _u
}
// SetNillableClientSecret sets the "client_secret" field if the given value is not nil.
func (_u *DeviceRequestUpdateOne) SetNillableClientSecret(v *string) *DeviceRequestUpdateOne {
if v != nil {
_u.SetClientSecret(*v)
}
return _u
}
// SetScopes sets the "scopes" field.
func (_u *DeviceRequestUpdateOne) SetScopes(v []string) *DeviceRequestUpdateOne {
_u.mutation.SetScopes(v)
return _u
}
// AppendScopes appends value to the "scopes" field.
func (_u *DeviceRequestUpdateOne) AppendScopes(v []string) *DeviceRequestUpdateOne {
_u.mutation.AppendScopes(v)
return _u
}
// ClearScopes clears the value of the "scopes" field.
func (_u *DeviceRequestUpdateOne) ClearScopes() *DeviceRequestUpdateOne {
_u.mutation.ClearScopes()
return _u
}
// SetExpiry sets the "expiry" field.
func (_u *DeviceRequestUpdateOne) SetExpiry(v time.Time) *DeviceRequestUpdateOne {
_u.mutation.SetExpiry(v)
return _u
}
// SetNillableExpiry sets the "expiry" field if the given value is not nil.
func (_u *DeviceRequestUpdateOne) SetNillableExpiry(v *time.Time) *DeviceRequestUpdateOne {
if v != nil {
_u.SetExpiry(*v)
}
return _u
}
// Mutation returns the DeviceRequestMutation object of the builder.
func (_u *DeviceRequestUpdateOne) Mutation() *DeviceRequestMutation {
return _u.mutation
}
// Where appends a list predicates to the DeviceRequestUpdate builder.
func (_u *DeviceRequestUpdateOne) Where(ps ...predicate.DeviceRequest) *DeviceRequestUpdateOne {
_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 *DeviceRequestUpdateOne) Select(field string, fields ...string) *DeviceRequestUpdateOne {
_u.fields = append([]string{field}, fields...)
return _u
}
// Save executes the query and returns the updated DeviceRequest entity.
func (_u *DeviceRequestUpdateOne) Save(ctx context.Context) (*DeviceRequest, error) {
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (_u *DeviceRequestUpdateOne) SaveX(ctx context.Context) *DeviceRequest {
node, err := _u.Save(ctx)
if err != nil {
panic(err)
}
return node
}
// Exec executes the query on the entity.
func (_u *DeviceRequestUpdateOne) Exec(ctx context.Context) error {
_, err := _u.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_u *DeviceRequestUpdateOne) ExecX(ctx context.Context) {
if err := _u.Exec(ctx); err != nil {
panic(err)
}
}
// check runs all checks and user-defined validators on the builder.
func (_u *DeviceRequestUpdateOne) check() error {
if v, ok := _u.mutation.UserCode(); ok {
if err := devicerequest.UserCodeValidator(v); err != nil {
return &ValidationError{Name: "user_code", err: fmt.Errorf(`db: validator failed for field "DeviceRequest.user_code": %w`, err)}
}
}
if v, ok := _u.mutation.DeviceCode(); ok {
if err := devicerequest.DeviceCodeValidator(v); err != nil {
return &ValidationError{Name: "device_code", err: fmt.Errorf(`db: validator failed for field "DeviceRequest.device_code": %w`, err)}
}
}
if v, ok := _u.mutation.ClientID(); ok {
if err := devicerequest.ClientIDValidator(v); err != nil {
return &ValidationError{Name: "client_id", err: fmt.Errorf(`db: validator failed for field "DeviceRequest.client_id": %w`, err)}
}
}
if v, ok := _u.mutation.ClientSecret(); ok {
if err := devicerequest.ClientSecretValidator(v); err != nil {
return &ValidationError{Name: "client_secret", err: fmt.Errorf(`db: validator failed for field "DeviceRequest.client_secret": %w`, err)}
}
}
return nil
}
func (_u *DeviceRequestUpdateOne) sqlSave(ctx context.Context) (_node *DeviceRequest, err error) {
if err := _u.check(); err != nil {
return _node, err
}
_spec := sqlgraph.NewUpdateSpec(devicerequest.Table, devicerequest.Columns, sqlgraph.NewFieldSpec(devicerequest.FieldID, field.TypeInt))
id, ok := _u.mutation.ID()
if !ok {
return nil, &ValidationError{Name: "id", err: errors.New(`db: missing "DeviceRequest.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, devicerequest.FieldID)
for _, f := range fields {
if !devicerequest.ValidColumn(f) {
return nil, &ValidationError{Name: f, err: fmt.Errorf("db: invalid field %q for query", f)}
}
if f != devicerequest.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.UserCode(); ok {
_spec.SetField(devicerequest.FieldUserCode, field.TypeString, value)
}
if value, ok := _u.mutation.DeviceCode(); ok {
_spec.SetField(devicerequest.FieldDeviceCode, field.TypeString, value)
}
if value, ok := _u.mutation.ClientID(); ok {
_spec.SetField(devicerequest.FieldClientID, field.TypeString, value)
}
if value, ok := _u.mutation.ClientSecret(); ok {
_spec.SetField(devicerequest.FieldClientSecret, field.TypeString, value)
}
if value, ok := _u.mutation.Scopes(); ok {
_spec.SetField(devicerequest.FieldScopes, field.TypeJSON, value)
}
if value, ok := _u.mutation.AppendedScopes(); ok {
_spec.AddModifier(func(u *sql.UpdateBuilder) {
sqljson.Append(u, devicerequest.FieldScopes, value)
})
}
if _u.mutation.ScopesCleared() {
_spec.ClearField(devicerequest.FieldScopes, field.TypeJSON)
}
if value, ok := _u.mutation.Expiry(); ok {
_spec.SetField(devicerequest.FieldExpiry, field.TypeTime, value)
}
_node = &DeviceRequest{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{devicerequest.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return nil, err
}
_u.mutation.done = true
return _node, nil
}