mirror of
https://github.com/netbirdio/dex.git
synced 2026-05-22 18:43:53 -07:00
391 lines
11 KiB
Go
391 lines
11 KiB
Go
// 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/dialect/sql/sqljson"
|
|
"entgo.io/ent/schema/field"
|
|
"github.com/dexidp/dex/storage/ent/db/connector"
|
|
"github.com/dexidp/dex/storage/ent/db/predicate"
|
|
)
|
|
|
|
// ConnectorUpdate is the builder for updating Connector entities.
|
|
type ConnectorUpdate struct {
|
|
config
|
|
hooks []Hook
|
|
mutation *ConnectorMutation
|
|
}
|
|
|
|
// Where appends a list predicates to the ConnectorUpdate builder.
|
|
func (_u *ConnectorUpdate) Where(ps ...predicate.Connector) *ConnectorUpdate {
|
|
_u.mutation.Where(ps...)
|
|
return _u
|
|
}
|
|
|
|
// SetType sets the "type" field.
|
|
func (_u *ConnectorUpdate) SetType(v string) *ConnectorUpdate {
|
|
_u.mutation.SetType(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableType sets the "type" field if the given value is not nil.
|
|
func (_u *ConnectorUpdate) SetNillableType(v *string) *ConnectorUpdate {
|
|
if v != nil {
|
|
_u.SetType(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetName sets the "name" field.
|
|
func (_u *ConnectorUpdate) SetName(v string) *ConnectorUpdate {
|
|
_u.mutation.SetName(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableName sets the "name" field if the given value is not nil.
|
|
func (_u *ConnectorUpdate) SetNillableName(v *string) *ConnectorUpdate {
|
|
if v != nil {
|
|
_u.SetName(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetResourceVersion sets the "resource_version" field.
|
|
func (_u *ConnectorUpdate) SetResourceVersion(v string) *ConnectorUpdate {
|
|
_u.mutation.SetResourceVersion(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableResourceVersion sets the "resource_version" field if the given value is not nil.
|
|
func (_u *ConnectorUpdate) SetNillableResourceVersion(v *string) *ConnectorUpdate {
|
|
if v != nil {
|
|
_u.SetResourceVersion(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetConfig sets the "config" field.
|
|
func (_u *ConnectorUpdate) SetConfig(v []byte) *ConnectorUpdate {
|
|
_u.mutation.SetConfig(v)
|
|
return _u
|
|
}
|
|
|
|
// SetGrantTypes sets the "grant_types" field.
|
|
func (_u *ConnectorUpdate) SetGrantTypes(v []string) *ConnectorUpdate {
|
|
_u.mutation.SetGrantTypes(v)
|
|
return _u
|
|
}
|
|
|
|
// AppendGrantTypes appends value to the "grant_types" field.
|
|
func (_u *ConnectorUpdate) AppendGrantTypes(v []string) *ConnectorUpdate {
|
|
_u.mutation.AppendGrantTypes(v)
|
|
return _u
|
|
}
|
|
|
|
// ClearGrantTypes clears the value of the "grant_types" field.
|
|
func (_u *ConnectorUpdate) ClearGrantTypes() *ConnectorUpdate {
|
|
_u.mutation.ClearGrantTypes()
|
|
return _u
|
|
}
|
|
|
|
// Mutation returns the ConnectorMutation object of the builder.
|
|
func (_u *ConnectorUpdate) Mutation() *ConnectorMutation {
|
|
return _u.mutation
|
|
}
|
|
|
|
// Save executes the query and returns the number of nodes affected by the update operation.
|
|
func (_u *ConnectorUpdate) 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 *ConnectorUpdate) SaveX(ctx context.Context) int {
|
|
affected, err := _u.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return affected
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_u *ConnectorUpdate) Exec(ctx context.Context) error {
|
|
_, err := _u.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_u *ConnectorUpdate) 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 *ConnectorUpdate) check() error {
|
|
if v, ok := _u.mutation.GetType(); ok {
|
|
if err := connector.TypeValidator(v); err != nil {
|
|
return &ValidationError{Name: "type", err: fmt.Errorf(`db: validator failed for field "Connector.type": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.Name(); ok {
|
|
if err := connector.NameValidator(v); err != nil {
|
|
return &ValidationError{Name: "name", err: fmt.Errorf(`db: validator failed for field "Connector.name": %w`, err)}
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (_u *ConnectorUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
|
if err := _u.check(); err != nil {
|
|
return _node, err
|
|
}
|
|
_spec := sqlgraph.NewUpdateSpec(connector.Table, connector.Columns, sqlgraph.NewFieldSpec(connector.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.GetType(); ok {
|
|
_spec.SetField(connector.FieldType, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Name(); ok {
|
|
_spec.SetField(connector.FieldName, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.ResourceVersion(); ok {
|
|
_spec.SetField(connector.FieldResourceVersion, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Config(); ok {
|
|
_spec.SetField(connector.FieldConfig, field.TypeBytes, value)
|
|
}
|
|
if value, ok := _u.mutation.GrantTypes(); ok {
|
|
_spec.SetField(connector.FieldGrantTypes, field.TypeJSON, value)
|
|
}
|
|
if value, ok := _u.mutation.AppendedGrantTypes(); ok {
|
|
_spec.AddModifier(func(u *sql.UpdateBuilder) {
|
|
sqljson.Append(u, connector.FieldGrantTypes, value)
|
|
})
|
|
}
|
|
if _u.mutation.GrantTypesCleared() {
|
|
_spec.ClearField(connector.FieldGrantTypes, field.TypeJSON)
|
|
}
|
|
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
|
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
|
err = &NotFoundError{connector.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return 0, err
|
|
}
|
|
_u.mutation.done = true
|
|
return _node, nil
|
|
}
|
|
|
|
// ConnectorUpdateOne is the builder for updating a single Connector entity.
|
|
type ConnectorUpdateOne struct {
|
|
config
|
|
fields []string
|
|
hooks []Hook
|
|
mutation *ConnectorMutation
|
|
}
|
|
|
|
// SetType sets the "type" field.
|
|
func (_u *ConnectorUpdateOne) SetType(v string) *ConnectorUpdateOne {
|
|
_u.mutation.SetType(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableType sets the "type" field if the given value is not nil.
|
|
func (_u *ConnectorUpdateOne) SetNillableType(v *string) *ConnectorUpdateOne {
|
|
if v != nil {
|
|
_u.SetType(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetName sets the "name" field.
|
|
func (_u *ConnectorUpdateOne) SetName(v string) *ConnectorUpdateOne {
|
|
_u.mutation.SetName(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableName sets the "name" field if the given value is not nil.
|
|
func (_u *ConnectorUpdateOne) SetNillableName(v *string) *ConnectorUpdateOne {
|
|
if v != nil {
|
|
_u.SetName(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetResourceVersion sets the "resource_version" field.
|
|
func (_u *ConnectorUpdateOne) SetResourceVersion(v string) *ConnectorUpdateOne {
|
|
_u.mutation.SetResourceVersion(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableResourceVersion sets the "resource_version" field if the given value is not nil.
|
|
func (_u *ConnectorUpdateOne) SetNillableResourceVersion(v *string) *ConnectorUpdateOne {
|
|
if v != nil {
|
|
_u.SetResourceVersion(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetConfig sets the "config" field.
|
|
func (_u *ConnectorUpdateOne) SetConfig(v []byte) *ConnectorUpdateOne {
|
|
_u.mutation.SetConfig(v)
|
|
return _u
|
|
}
|
|
|
|
// SetGrantTypes sets the "grant_types" field.
|
|
func (_u *ConnectorUpdateOne) SetGrantTypes(v []string) *ConnectorUpdateOne {
|
|
_u.mutation.SetGrantTypes(v)
|
|
return _u
|
|
}
|
|
|
|
// AppendGrantTypes appends value to the "grant_types" field.
|
|
func (_u *ConnectorUpdateOne) AppendGrantTypes(v []string) *ConnectorUpdateOne {
|
|
_u.mutation.AppendGrantTypes(v)
|
|
return _u
|
|
}
|
|
|
|
// ClearGrantTypes clears the value of the "grant_types" field.
|
|
func (_u *ConnectorUpdateOne) ClearGrantTypes() *ConnectorUpdateOne {
|
|
_u.mutation.ClearGrantTypes()
|
|
return _u
|
|
}
|
|
|
|
// Mutation returns the ConnectorMutation object of the builder.
|
|
func (_u *ConnectorUpdateOne) Mutation() *ConnectorMutation {
|
|
return _u.mutation
|
|
}
|
|
|
|
// Where appends a list predicates to the ConnectorUpdate builder.
|
|
func (_u *ConnectorUpdateOne) Where(ps ...predicate.Connector) *ConnectorUpdateOne {
|
|
_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 *ConnectorUpdateOne) Select(field string, fields ...string) *ConnectorUpdateOne {
|
|
_u.fields = append([]string{field}, fields...)
|
|
return _u
|
|
}
|
|
|
|
// Save executes the query and returns the updated Connector entity.
|
|
func (_u *ConnectorUpdateOne) Save(ctx context.Context) (*Connector, error) {
|
|
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (_u *ConnectorUpdateOne) SaveX(ctx context.Context) *Connector {
|
|
node, err := _u.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return node
|
|
}
|
|
|
|
// Exec executes the query on the entity.
|
|
func (_u *ConnectorUpdateOne) Exec(ctx context.Context) error {
|
|
_, err := _u.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_u *ConnectorUpdateOne) 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 *ConnectorUpdateOne) check() error {
|
|
if v, ok := _u.mutation.GetType(); ok {
|
|
if err := connector.TypeValidator(v); err != nil {
|
|
return &ValidationError{Name: "type", err: fmt.Errorf(`db: validator failed for field "Connector.type": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.Name(); ok {
|
|
if err := connector.NameValidator(v); err != nil {
|
|
return &ValidationError{Name: "name", err: fmt.Errorf(`db: validator failed for field "Connector.name": %w`, err)}
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (_u *ConnectorUpdateOne) sqlSave(ctx context.Context) (_node *Connector, err error) {
|
|
if err := _u.check(); err != nil {
|
|
return _node, err
|
|
}
|
|
_spec := sqlgraph.NewUpdateSpec(connector.Table, connector.Columns, sqlgraph.NewFieldSpec(connector.FieldID, field.TypeString))
|
|
id, ok := _u.mutation.ID()
|
|
if !ok {
|
|
return nil, &ValidationError{Name: "id", err: errors.New(`db: missing "Connector.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, connector.FieldID)
|
|
for _, f := range fields {
|
|
if !connector.ValidColumn(f) {
|
|
return nil, &ValidationError{Name: f, err: fmt.Errorf("db: invalid field %q for query", f)}
|
|
}
|
|
if f != connector.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.GetType(); ok {
|
|
_spec.SetField(connector.FieldType, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Name(); ok {
|
|
_spec.SetField(connector.FieldName, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.ResourceVersion(); ok {
|
|
_spec.SetField(connector.FieldResourceVersion, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Config(); ok {
|
|
_spec.SetField(connector.FieldConfig, field.TypeBytes, value)
|
|
}
|
|
if value, ok := _u.mutation.GrantTypes(); ok {
|
|
_spec.SetField(connector.FieldGrantTypes, field.TypeJSON, value)
|
|
}
|
|
if value, ok := _u.mutation.AppendedGrantTypes(); ok {
|
|
_spec.AddModifier(func(u *sql.UpdateBuilder) {
|
|
sqljson.Append(u, connector.FieldGrantTypes, value)
|
|
})
|
|
}
|
|
if _u.mutation.GrantTypesCleared() {
|
|
_spec.ClearField(connector.FieldGrantTypes, field.TypeJSON)
|
|
}
|
|
_node = &Connector{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{connector.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return nil, err
|
|
}
|
|
_u.mutation.done = true
|
|
return _node, nil
|
|
}
|