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.
333 lines
10 KiB
333 lines
10 KiB
// Code generated by ent, DO NOT EDIT. |
|
|
|
package db |
|
|
|
import ( |
|
"context" |
|
"errors" |
|
"fmt" |
|
|
|
"entgo.io/ent/dialect/sql" |
|
"entgo.io/ent/dialect/sql/sqlgraph" |
|
"entgo.io/ent/schema/field" |
|
"github.com/dexidp/dex/storage/ent/db/offlinesession" |
|
"github.com/dexidp/dex/storage/ent/db/predicate" |
|
) |
|
|
|
// OfflineSessionUpdate is the builder for updating OfflineSession entities. |
|
type OfflineSessionUpdate struct { |
|
config |
|
hooks []Hook |
|
mutation *OfflineSessionMutation |
|
} |
|
|
|
// Where appends a list predicates to the OfflineSessionUpdate builder. |
|
func (_u *OfflineSessionUpdate) Where(ps ...predicate.OfflineSession) *OfflineSessionUpdate { |
|
_u.mutation.Where(ps...) |
|
return _u |
|
} |
|
|
|
// SetUserID sets the "user_id" field. |
|
func (_u *OfflineSessionUpdate) SetUserID(v string) *OfflineSessionUpdate { |
|
_u.mutation.SetUserID(v) |
|
return _u |
|
} |
|
|
|
// SetNillableUserID sets the "user_id" field if the given value is not nil. |
|
func (_u *OfflineSessionUpdate) SetNillableUserID(v *string) *OfflineSessionUpdate { |
|
if v != nil { |
|
_u.SetUserID(*v) |
|
} |
|
return _u |
|
} |
|
|
|
// SetConnID sets the "conn_id" field. |
|
func (_u *OfflineSessionUpdate) SetConnID(v string) *OfflineSessionUpdate { |
|
_u.mutation.SetConnID(v) |
|
return _u |
|
} |
|
|
|
// SetNillableConnID sets the "conn_id" field if the given value is not nil. |
|
func (_u *OfflineSessionUpdate) SetNillableConnID(v *string) *OfflineSessionUpdate { |
|
if v != nil { |
|
_u.SetConnID(*v) |
|
} |
|
return _u |
|
} |
|
|
|
// SetRefresh sets the "refresh" field. |
|
func (_u *OfflineSessionUpdate) SetRefresh(v []byte) *OfflineSessionUpdate { |
|
_u.mutation.SetRefresh(v) |
|
return _u |
|
} |
|
|
|
// SetConnectorData sets the "connector_data" field. |
|
func (_u *OfflineSessionUpdate) SetConnectorData(v []byte) *OfflineSessionUpdate { |
|
_u.mutation.SetConnectorData(v) |
|
return _u |
|
} |
|
|
|
// ClearConnectorData clears the value of the "connector_data" field. |
|
func (_u *OfflineSessionUpdate) ClearConnectorData() *OfflineSessionUpdate { |
|
_u.mutation.ClearConnectorData() |
|
return _u |
|
} |
|
|
|
// Mutation returns the OfflineSessionMutation object of the builder. |
|
func (_u *OfflineSessionUpdate) Mutation() *OfflineSessionMutation { |
|
return _u.mutation |
|
} |
|
|
|
// Save executes the query and returns the number of nodes affected by the update operation. |
|
func (_u *OfflineSessionUpdate) 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 *OfflineSessionUpdate) SaveX(ctx context.Context) int { |
|
affected, err := _u.Save(ctx) |
|
if err != nil { |
|
panic(err) |
|
} |
|
return affected |
|
} |
|
|
|
// Exec executes the query. |
|
func (_u *OfflineSessionUpdate) Exec(ctx context.Context) error { |
|
_, err := _u.Save(ctx) |
|
return err |
|
} |
|
|
|
// ExecX is like Exec, but panics if an error occurs. |
|
func (_u *OfflineSessionUpdate) 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 *OfflineSessionUpdate) check() error { |
|
if v, ok := _u.mutation.UserID(); ok { |
|
if err := offlinesession.UserIDValidator(v); err != nil { |
|
return &ValidationError{Name: "user_id", err: fmt.Errorf(`db: validator failed for field "OfflineSession.user_id": %w`, err)} |
|
} |
|
} |
|
if v, ok := _u.mutation.ConnID(); ok { |
|
if err := offlinesession.ConnIDValidator(v); err != nil { |
|
return &ValidationError{Name: "conn_id", err: fmt.Errorf(`db: validator failed for field "OfflineSession.conn_id": %w`, err)} |
|
} |
|
} |
|
return nil |
|
} |
|
|
|
func (_u *OfflineSessionUpdate) sqlSave(ctx context.Context) (_node int, err error) { |
|
if err := _u.check(); err != nil { |
|
return _node, err |
|
} |
|
_spec := sqlgraph.NewUpdateSpec(offlinesession.Table, offlinesession.Columns, sqlgraph.NewFieldSpec(offlinesession.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.UserID(); ok { |
|
_spec.SetField(offlinesession.FieldUserID, field.TypeString, value) |
|
} |
|
if value, ok := _u.mutation.ConnID(); ok { |
|
_spec.SetField(offlinesession.FieldConnID, field.TypeString, value) |
|
} |
|
if value, ok := _u.mutation.Refresh(); ok { |
|
_spec.SetField(offlinesession.FieldRefresh, field.TypeBytes, value) |
|
} |
|
if value, ok := _u.mutation.ConnectorData(); ok { |
|
_spec.SetField(offlinesession.FieldConnectorData, field.TypeBytes, value) |
|
} |
|
if _u.mutation.ConnectorDataCleared() { |
|
_spec.ClearField(offlinesession.FieldConnectorData, field.TypeBytes) |
|
} |
|
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil { |
|
if _, ok := err.(*sqlgraph.NotFoundError); ok { |
|
err = &NotFoundError{offlinesession.Label} |
|
} else if sqlgraph.IsConstraintError(err) { |
|
err = &ConstraintError{msg: err.Error(), wrap: err} |
|
} |
|
return 0, err |
|
} |
|
_u.mutation.done = true |
|
return _node, nil |
|
} |
|
|
|
// OfflineSessionUpdateOne is the builder for updating a single OfflineSession entity. |
|
type OfflineSessionUpdateOne struct { |
|
config |
|
fields []string |
|
hooks []Hook |
|
mutation *OfflineSessionMutation |
|
} |
|
|
|
// SetUserID sets the "user_id" field. |
|
func (_u *OfflineSessionUpdateOne) SetUserID(v string) *OfflineSessionUpdateOne { |
|
_u.mutation.SetUserID(v) |
|
return _u |
|
} |
|
|
|
// SetNillableUserID sets the "user_id" field if the given value is not nil. |
|
func (_u *OfflineSessionUpdateOne) SetNillableUserID(v *string) *OfflineSessionUpdateOne { |
|
if v != nil { |
|
_u.SetUserID(*v) |
|
} |
|
return _u |
|
} |
|
|
|
// SetConnID sets the "conn_id" field. |
|
func (_u *OfflineSessionUpdateOne) SetConnID(v string) *OfflineSessionUpdateOne { |
|
_u.mutation.SetConnID(v) |
|
return _u |
|
} |
|
|
|
// SetNillableConnID sets the "conn_id" field if the given value is not nil. |
|
func (_u *OfflineSessionUpdateOne) SetNillableConnID(v *string) *OfflineSessionUpdateOne { |
|
if v != nil { |
|
_u.SetConnID(*v) |
|
} |
|
return _u |
|
} |
|
|
|
// SetRefresh sets the "refresh" field. |
|
func (_u *OfflineSessionUpdateOne) SetRefresh(v []byte) *OfflineSessionUpdateOne { |
|
_u.mutation.SetRefresh(v) |
|
return _u |
|
} |
|
|
|
// SetConnectorData sets the "connector_data" field. |
|
func (_u *OfflineSessionUpdateOne) SetConnectorData(v []byte) *OfflineSessionUpdateOne { |
|
_u.mutation.SetConnectorData(v) |
|
return _u |
|
} |
|
|
|
// ClearConnectorData clears the value of the "connector_data" field. |
|
func (_u *OfflineSessionUpdateOne) ClearConnectorData() *OfflineSessionUpdateOne { |
|
_u.mutation.ClearConnectorData() |
|
return _u |
|
} |
|
|
|
// Mutation returns the OfflineSessionMutation object of the builder. |
|
func (_u *OfflineSessionUpdateOne) Mutation() *OfflineSessionMutation { |
|
return _u.mutation |
|
} |
|
|
|
// Where appends a list predicates to the OfflineSessionUpdate builder. |
|
func (_u *OfflineSessionUpdateOne) Where(ps ...predicate.OfflineSession) *OfflineSessionUpdateOne { |
|
_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 *OfflineSessionUpdateOne) Select(field string, fields ...string) *OfflineSessionUpdateOne { |
|
_u.fields = append([]string{field}, fields...) |
|
return _u |
|
} |
|
|
|
// Save executes the query and returns the updated OfflineSession entity. |
|
func (_u *OfflineSessionUpdateOne) Save(ctx context.Context) (*OfflineSession, error) { |
|
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) |
|
} |
|
|
|
// SaveX is like Save, but panics if an error occurs. |
|
func (_u *OfflineSessionUpdateOne) SaveX(ctx context.Context) *OfflineSession { |
|
node, err := _u.Save(ctx) |
|
if err != nil { |
|
panic(err) |
|
} |
|
return node |
|
} |
|
|
|
// Exec executes the query on the entity. |
|
func (_u *OfflineSessionUpdateOne) Exec(ctx context.Context) error { |
|
_, err := _u.Save(ctx) |
|
return err |
|
} |
|
|
|
// ExecX is like Exec, but panics if an error occurs. |
|
func (_u *OfflineSessionUpdateOne) 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 *OfflineSessionUpdateOne) check() error { |
|
if v, ok := _u.mutation.UserID(); ok { |
|
if err := offlinesession.UserIDValidator(v); err != nil { |
|
return &ValidationError{Name: "user_id", err: fmt.Errorf(`db: validator failed for field "OfflineSession.user_id": %w`, err)} |
|
} |
|
} |
|
if v, ok := _u.mutation.ConnID(); ok { |
|
if err := offlinesession.ConnIDValidator(v); err != nil { |
|
return &ValidationError{Name: "conn_id", err: fmt.Errorf(`db: validator failed for field "OfflineSession.conn_id": %w`, err)} |
|
} |
|
} |
|
return nil |
|
} |
|
|
|
func (_u *OfflineSessionUpdateOne) sqlSave(ctx context.Context) (_node *OfflineSession, err error) { |
|
if err := _u.check(); err != nil { |
|
return _node, err |
|
} |
|
_spec := sqlgraph.NewUpdateSpec(offlinesession.Table, offlinesession.Columns, sqlgraph.NewFieldSpec(offlinesession.FieldID, field.TypeString)) |
|
id, ok := _u.mutation.ID() |
|
if !ok { |
|
return nil, &ValidationError{Name: "id", err: errors.New(`db: missing "OfflineSession.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, offlinesession.FieldID) |
|
for _, f := range fields { |
|
if !offlinesession.ValidColumn(f) { |
|
return nil, &ValidationError{Name: f, err: fmt.Errorf("db: invalid field %q for query", f)} |
|
} |
|
if f != offlinesession.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.UserID(); ok { |
|
_spec.SetField(offlinesession.FieldUserID, field.TypeString, value) |
|
} |
|
if value, ok := _u.mutation.ConnID(); ok { |
|
_spec.SetField(offlinesession.FieldConnID, field.TypeString, value) |
|
} |
|
if value, ok := _u.mutation.Refresh(); ok { |
|
_spec.SetField(offlinesession.FieldRefresh, field.TypeBytes, value) |
|
} |
|
if value, ok := _u.mutation.ConnectorData(); ok { |
|
_spec.SetField(offlinesession.FieldConnectorData, field.TypeBytes, value) |
|
} |
|
if _u.mutation.ConnectorDataCleared() { |
|
_spec.ClearField(offlinesession.FieldConnectorData, field.TypeBytes) |
|
} |
|
_node = &OfflineSession{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{offlinesession.Label} |
|
} else if sqlgraph.IsConstraintError(err) { |
|
err = &ConstraintError{msg: err.Error(), wrap: err} |
|
} |
|
return nil, err |
|
} |
|
_u.mutation.done = true |
|
return _node, nil |
|
}
|
|
|