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.
 
 
 
 
 
 

506 lines
15 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/devicetoken"
"github.com/dexidp/dex/storage/ent/db/predicate"
)
// DeviceTokenUpdate is the builder for updating DeviceToken entities.
type DeviceTokenUpdate struct {
config
hooks []Hook
mutation *DeviceTokenMutation
}
// Where appends a list predicates to the DeviceTokenUpdate builder.
func (_u *DeviceTokenUpdate) Where(ps ...predicate.DeviceToken) *DeviceTokenUpdate {
_u.mutation.Where(ps...)
return _u
}
// SetDeviceCode sets the "device_code" field.
func (_u *DeviceTokenUpdate) SetDeviceCode(v string) *DeviceTokenUpdate {
_u.mutation.SetDeviceCode(v)
return _u
}
// SetNillableDeviceCode sets the "device_code" field if the given value is not nil.
func (_u *DeviceTokenUpdate) SetNillableDeviceCode(v *string) *DeviceTokenUpdate {
if v != nil {
_u.SetDeviceCode(*v)
}
return _u
}
// SetStatus sets the "status" field.
func (_u *DeviceTokenUpdate) SetStatus(v string) *DeviceTokenUpdate {
_u.mutation.SetStatus(v)
return _u
}
// SetNillableStatus sets the "status" field if the given value is not nil.
func (_u *DeviceTokenUpdate) SetNillableStatus(v *string) *DeviceTokenUpdate {
if v != nil {
_u.SetStatus(*v)
}
return _u
}
// SetToken sets the "token" field.
func (_u *DeviceTokenUpdate) SetToken(v []byte) *DeviceTokenUpdate {
_u.mutation.SetToken(v)
return _u
}
// ClearToken clears the value of the "token" field.
func (_u *DeviceTokenUpdate) ClearToken() *DeviceTokenUpdate {
_u.mutation.ClearToken()
return _u
}
// SetExpiry sets the "expiry" field.
func (_u *DeviceTokenUpdate) SetExpiry(v time.Time) *DeviceTokenUpdate {
_u.mutation.SetExpiry(v)
return _u
}
// SetNillableExpiry sets the "expiry" field if the given value is not nil.
func (_u *DeviceTokenUpdate) SetNillableExpiry(v *time.Time) *DeviceTokenUpdate {
if v != nil {
_u.SetExpiry(*v)
}
return _u
}
// SetLastRequest sets the "last_request" field.
func (_u *DeviceTokenUpdate) SetLastRequest(v time.Time) *DeviceTokenUpdate {
_u.mutation.SetLastRequest(v)
return _u
}
// SetNillableLastRequest sets the "last_request" field if the given value is not nil.
func (_u *DeviceTokenUpdate) SetNillableLastRequest(v *time.Time) *DeviceTokenUpdate {
if v != nil {
_u.SetLastRequest(*v)
}
return _u
}
// SetPollInterval sets the "poll_interval" field.
func (_u *DeviceTokenUpdate) SetPollInterval(v int) *DeviceTokenUpdate {
_u.mutation.ResetPollInterval()
_u.mutation.SetPollInterval(v)
return _u
}
// SetNillablePollInterval sets the "poll_interval" field if the given value is not nil.
func (_u *DeviceTokenUpdate) SetNillablePollInterval(v *int) *DeviceTokenUpdate {
if v != nil {
_u.SetPollInterval(*v)
}
return _u
}
// AddPollInterval adds value to the "poll_interval" field.
func (_u *DeviceTokenUpdate) AddPollInterval(v int) *DeviceTokenUpdate {
_u.mutation.AddPollInterval(v)
return _u
}
// SetCodeChallenge sets the "code_challenge" field.
func (_u *DeviceTokenUpdate) SetCodeChallenge(v string) *DeviceTokenUpdate {
_u.mutation.SetCodeChallenge(v)
return _u
}
// SetNillableCodeChallenge sets the "code_challenge" field if the given value is not nil.
func (_u *DeviceTokenUpdate) SetNillableCodeChallenge(v *string) *DeviceTokenUpdate {
if v != nil {
_u.SetCodeChallenge(*v)
}
return _u
}
// SetCodeChallengeMethod sets the "code_challenge_method" field.
func (_u *DeviceTokenUpdate) SetCodeChallengeMethod(v string) *DeviceTokenUpdate {
_u.mutation.SetCodeChallengeMethod(v)
return _u
}
// SetNillableCodeChallengeMethod sets the "code_challenge_method" field if the given value is not nil.
func (_u *DeviceTokenUpdate) SetNillableCodeChallengeMethod(v *string) *DeviceTokenUpdate {
if v != nil {
_u.SetCodeChallengeMethod(*v)
}
return _u
}
// Mutation returns the DeviceTokenMutation object of the builder.
func (_u *DeviceTokenUpdate) Mutation() *DeviceTokenMutation {
return _u.mutation
}
// Save executes the query and returns the number of nodes affected by the update operation.
func (_u *DeviceTokenUpdate) 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 *DeviceTokenUpdate) SaveX(ctx context.Context) int {
affected, err := _u.Save(ctx)
if err != nil {
panic(err)
}
return affected
}
// Exec executes the query.
func (_u *DeviceTokenUpdate) Exec(ctx context.Context) error {
_, err := _u.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_u *DeviceTokenUpdate) 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 *DeviceTokenUpdate) check() error {
if v, ok := _u.mutation.DeviceCode(); ok {
if err := devicetoken.DeviceCodeValidator(v); err != nil {
return &ValidationError{Name: "device_code", err: fmt.Errorf(`db: validator failed for field "DeviceToken.device_code": %w`, err)}
}
}
if v, ok := _u.mutation.Status(); ok {
if err := devicetoken.StatusValidator(v); err != nil {
return &ValidationError{Name: "status", err: fmt.Errorf(`db: validator failed for field "DeviceToken.status": %w`, err)}
}
}
return nil
}
func (_u *DeviceTokenUpdate) sqlSave(ctx context.Context) (_node int, err error) {
if err := _u.check(); err != nil {
return _node, err
}
_spec := sqlgraph.NewUpdateSpec(devicetoken.Table, devicetoken.Columns, sqlgraph.NewFieldSpec(devicetoken.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.DeviceCode(); ok {
_spec.SetField(devicetoken.FieldDeviceCode, field.TypeString, value)
}
if value, ok := _u.mutation.Status(); ok {
_spec.SetField(devicetoken.FieldStatus, field.TypeString, value)
}
if value, ok := _u.mutation.Token(); ok {
_spec.SetField(devicetoken.FieldToken, field.TypeBytes, value)
}
if _u.mutation.TokenCleared() {
_spec.ClearField(devicetoken.FieldToken, field.TypeBytes)
}
if value, ok := _u.mutation.Expiry(); ok {
_spec.SetField(devicetoken.FieldExpiry, field.TypeTime, value)
}
if value, ok := _u.mutation.LastRequest(); ok {
_spec.SetField(devicetoken.FieldLastRequest, field.TypeTime, value)
}
if value, ok := _u.mutation.PollInterval(); ok {
_spec.SetField(devicetoken.FieldPollInterval, field.TypeInt, value)
}
if value, ok := _u.mutation.AddedPollInterval(); ok {
_spec.AddField(devicetoken.FieldPollInterval, field.TypeInt, value)
}
if value, ok := _u.mutation.CodeChallenge(); ok {
_spec.SetField(devicetoken.FieldCodeChallenge, field.TypeString, value)
}
if value, ok := _u.mutation.CodeChallengeMethod(); ok {
_spec.SetField(devicetoken.FieldCodeChallengeMethod, field.TypeString, value)
}
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{devicetoken.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return 0, err
}
_u.mutation.done = true
return _node, nil
}
// DeviceTokenUpdateOne is the builder for updating a single DeviceToken entity.
type DeviceTokenUpdateOne struct {
config
fields []string
hooks []Hook
mutation *DeviceTokenMutation
}
// SetDeviceCode sets the "device_code" field.
func (_u *DeviceTokenUpdateOne) SetDeviceCode(v string) *DeviceTokenUpdateOne {
_u.mutation.SetDeviceCode(v)
return _u
}
// SetNillableDeviceCode sets the "device_code" field if the given value is not nil.
func (_u *DeviceTokenUpdateOne) SetNillableDeviceCode(v *string) *DeviceTokenUpdateOne {
if v != nil {
_u.SetDeviceCode(*v)
}
return _u
}
// SetStatus sets the "status" field.
func (_u *DeviceTokenUpdateOne) SetStatus(v string) *DeviceTokenUpdateOne {
_u.mutation.SetStatus(v)
return _u
}
// SetNillableStatus sets the "status" field if the given value is not nil.
func (_u *DeviceTokenUpdateOne) SetNillableStatus(v *string) *DeviceTokenUpdateOne {
if v != nil {
_u.SetStatus(*v)
}
return _u
}
// SetToken sets the "token" field.
func (_u *DeviceTokenUpdateOne) SetToken(v []byte) *DeviceTokenUpdateOne {
_u.mutation.SetToken(v)
return _u
}
// ClearToken clears the value of the "token" field.
func (_u *DeviceTokenUpdateOne) ClearToken() *DeviceTokenUpdateOne {
_u.mutation.ClearToken()
return _u
}
// SetExpiry sets the "expiry" field.
func (_u *DeviceTokenUpdateOne) SetExpiry(v time.Time) *DeviceTokenUpdateOne {
_u.mutation.SetExpiry(v)
return _u
}
// SetNillableExpiry sets the "expiry" field if the given value is not nil.
func (_u *DeviceTokenUpdateOne) SetNillableExpiry(v *time.Time) *DeviceTokenUpdateOne {
if v != nil {
_u.SetExpiry(*v)
}
return _u
}
// SetLastRequest sets the "last_request" field.
func (_u *DeviceTokenUpdateOne) SetLastRequest(v time.Time) *DeviceTokenUpdateOne {
_u.mutation.SetLastRequest(v)
return _u
}
// SetNillableLastRequest sets the "last_request" field if the given value is not nil.
func (_u *DeviceTokenUpdateOne) SetNillableLastRequest(v *time.Time) *DeviceTokenUpdateOne {
if v != nil {
_u.SetLastRequest(*v)
}
return _u
}
// SetPollInterval sets the "poll_interval" field.
func (_u *DeviceTokenUpdateOne) SetPollInterval(v int) *DeviceTokenUpdateOne {
_u.mutation.ResetPollInterval()
_u.mutation.SetPollInterval(v)
return _u
}
// SetNillablePollInterval sets the "poll_interval" field if the given value is not nil.
func (_u *DeviceTokenUpdateOne) SetNillablePollInterval(v *int) *DeviceTokenUpdateOne {
if v != nil {
_u.SetPollInterval(*v)
}
return _u
}
// AddPollInterval adds value to the "poll_interval" field.
func (_u *DeviceTokenUpdateOne) AddPollInterval(v int) *DeviceTokenUpdateOne {
_u.mutation.AddPollInterval(v)
return _u
}
// SetCodeChallenge sets the "code_challenge" field.
func (_u *DeviceTokenUpdateOne) SetCodeChallenge(v string) *DeviceTokenUpdateOne {
_u.mutation.SetCodeChallenge(v)
return _u
}
// SetNillableCodeChallenge sets the "code_challenge" field if the given value is not nil.
func (_u *DeviceTokenUpdateOne) SetNillableCodeChallenge(v *string) *DeviceTokenUpdateOne {
if v != nil {
_u.SetCodeChallenge(*v)
}
return _u
}
// SetCodeChallengeMethod sets the "code_challenge_method" field.
func (_u *DeviceTokenUpdateOne) SetCodeChallengeMethod(v string) *DeviceTokenUpdateOne {
_u.mutation.SetCodeChallengeMethod(v)
return _u
}
// SetNillableCodeChallengeMethod sets the "code_challenge_method" field if the given value is not nil.
func (_u *DeviceTokenUpdateOne) SetNillableCodeChallengeMethod(v *string) *DeviceTokenUpdateOne {
if v != nil {
_u.SetCodeChallengeMethod(*v)
}
return _u
}
// Mutation returns the DeviceTokenMutation object of the builder.
func (_u *DeviceTokenUpdateOne) Mutation() *DeviceTokenMutation {
return _u.mutation
}
// Where appends a list predicates to the DeviceTokenUpdate builder.
func (_u *DeviceTokenUpdateOne) Where(ps ...predicate.DeviceToken) *DeviceTokenUpdateOne {
_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 *DeviceTokenUpdateOne) Select(field string, fields ...string) *DeviceTokenUpdateOne {
_u.fields = append([]string{field}, fields...)
return _u
}
// Save executes the query and returns the updated DeviceToken entity.
func (_u *DeviceTokenUpdateOne) Save(ctx context.Context) (*DeviceToken, error) {
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (_u *DeviceTokenUpdateOne) SaveX(ctx context.Context) *DeviceToken {
node, err := _u.Save(ctx)
if err != nil {
panic(err)
}
return node
}
// Exec executes the query on the entity.
func (_u *DeviceTokenUpdateOne) Exec(ctx context.Context) error {
_, err := _u.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_u *DeviceTokenUpdateOne) 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 *DeviceTokenUpdateOne) check() error {
if v, ok := _u.mutation.DeviceCode(); ok {
if err := devicetoken.DeviceCodeValidator(v); err != nil {
return &ValidationError{Name: "device_code", err: fmt.Errorf(`db: validator failed for field "DeviceToken.device_code": %w`, err)}
}
}
if v, ok := _u.mutation.Status(); ok {
if err := devicetoken.StatusValidator(v); err != nil {
return &ValidationError{Name: "status", err: fmt.Errorf(`db: validator failed for field "DeviceToken.status": %w`, err)}
}
}
return nil
}
func (_u *DeviceTokenUpdateOne) sqlSave(ctx context.Context) (_node *DeviceToken, err error) {
if err := _u.check(); err != nil {
return _node, err
}
_spec := sqlgraph.NewUpdateSpec(devicetoken.Table, devicetoken.Columns, sqlgraph.NewFieldSpec(devicetoken.FieldID, field.TypeInt))
id, ok := _u.mutation.ID()
if !ok {
return nil, &ValidationError{Name: "id", err: errors.New(`db: missing "DeviceToken.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, devicetoken.FieldID)
for _, f := range fields {
if !devicetoken.ValidColumn(f) {
return nil, &ValidationError{Name: f, err: fmt.Errorf("db: invalid field %q for query", f)}
}
if f != devicetoken.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.DeviceCode(); ok {
_spec.SetField(devicetoken.FieldDeviceCode, field.TypeString, value)
}
if value, ok := _u.mutation.Status(); ok {
_spec.SetField(devicetoken.FieldStatus, field.TypeString, value)
}
if value, ok := _u.mutation.Token(); ok {
_spec.SetField(devicetoken.FieldToken, field.TypeBytes, value)
}
if _u.mutation.TokenCleared() {
_spec.ClearField(devicetoken.FieldToken, field.TypeBytes)
}
if value, ok := _u.mutation.Expiry(); ok {
_spec.SetField(devicetoken.FieldExpiry, field.TypeTime, value)
}
if value, ok := _u.mutation.LastRequest(); ok {
_spec.SetField(devicetoken.FieldLastRequest, field.TypeTime, value)
}
if value, ok := _u.mutation.PollInterval(); ok {
_spec.SetField(devicetoken.FieldPollInterval, field.TypeInt, value)
}
if value, ok := _u.mutation.AddedPollInterval(); ok {
_spec.AddField(devicetoken.FieldPollInterval, field.TypeInt, value)
}
if value, ok := _u.mutation.CodeChallenge(); ok {
_spec.SetField(devicetoken.FieldCodeChallenge, field.TypeString, value)
}
if value, ok := _u.mutation.CodeChallengeMethod(); ok {
_spec.SetField(devicetoken.FieldCodeChallengeMethod, field.TypeString, value)
}
_node = &DeviceToken{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{devicetoken.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return nil, err
}
_u.mutation.done = true
return _node, nil
}