2021-01-02 02:04:47 +05:30
|
|
|
// Code generated by entc, DO NOT EDIT.
|
|
|
|
|
|
|
|
package db
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2022-03-07 14:45:01 +05:30
|
|
|
"errors"
|
2021-01-02 02:04:47 +05:30
|
|
|
"fmt"
|
|
|
|
|
2021-03-24 12:07:51 +05:30
|
|
|
"entgo.io/ent/dialect/sql"
|
|
|
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
|
|
|
"entgo.io/ent/schema/field"
|
2021-01-02 02:04:47 +05:30
|
|
|
"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
|
|
|
|
}
|
|
|
|
|
2021-09-13 19:18:02 +05:30
|
|
|
// Where appends a list predicates to the ConnectorUpdate builder.
|
2021-01-02 02:04:47 +05:30
|
|
|
func (cu *ConnectorUpdate) Where(ps ...predicate.Connector) *ConnectorUpdate {
|
2021-09-13 19:18:02 +05:30
|
|
|
cu.mutation.Where(ps...)
|
2021-01-02 02:04:47 +05:30
|
|
|
return cu
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetType sets the "type" field.
|
|
|
|
func (cu *ConnectorUpdate) SetType(s string) *ConnectorUpdate {
|
|
|
|
cu.mutation.SetType(s)
|
|
|
|
return cu
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetName sets the "name" field.
|
|
|
|
func (cu *ConnectorUpdate) SetName(s string) *ConnectorUpdate {
|
|
|
|
cu.mutation.SetName(s)
|
|
|
|
return cu
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetResourceVersion sets the "resource_version" field.
|
|
|
|
func (cu *ConnectorUpdate) SetResourceVersion(s string) *ConnectorUpdate {
|
|
|
|
cu.mutation.SetResourceVersion(s)
|
|
|
|
return cu
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetConfig sets the "config" field.
|
|
|
|
func (cu *ConnectorUpdate) SetConfig(b []byte) *ConnectorUpdate {
|
|
|
|
cu.mutation.SetConfig(b)
|
|
|
|
return cu
|
|
|
|
}
|
|
|
|
|
|
|
|
// Mutation returns the ConnectorMutation object of the builder.
|
|
|
|
func (cu *ConnectorUpdate) Mutation() *ConnectorMutation {
|
|
|
|
return cu.mutation
|
|
|
|
}
|
|
|
|
|
|
|
|
// Save executes the query and returns the number of nodes affected by the update operation.
|
|
|
|
func (cu *ConnectorUpdate) Save(ctx context.Context) (int, error) {
|
|
|
|
var (
|
|
|
|
err error
|
|
|
|
affected int
|
|
|
|
)
|
|
|
|
if len(cu.hooks) == 0 {
|
|
|
|
if err = cu.check(); err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
affected, err = cu.sqlSave(ctx)
|
|
|
|
} else {
|
|
|
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
|
|
|
mutation, ok := m.(*ConnectorMutation)
|
|
|
|
if !ok {
|
|
|
|
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
|
|
|
}
|
|
|
|
if err = cu.check(); err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
cu.mutation = mutation
|
|
|
|
affected, err = cu.sqlSave(ctx)
|
|
|
|
mutation.done = true
|
|
|
|
return affected, err
|
|
|
|
})
|
|
|
|
for i := len(cu.hooks) - 1; i >= 0; i-- {
|
2021-09-13 19:18:02 +05:30
|
|
|
if cu.hooks[i] == nil {
|
|
|
|
return 0, fmt.Errorf("db: uninitialized hook (forgotten import db/runtime?)")
|
|
|
|
}
|
2021-01-02 02:04:47 +05:30
|
|
|
mut = cu.hooks[i](mut)
|
|
|
|
}
|
|
|
|
if _, err := mut.Mutate(ctx, cu.mutation); err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return affected, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
|
|
func (cu *ConnectorUpdate) SaveX(ctx context.Context) int {
|
|
|
|
affected, err := cu.Save(ctx)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return affected
|
|
|
|
}
|
|
|
|
|
|
|
|
// Exec executes the query.
|
|
|
|
func (cu *ConnectorUpdate) Exec(ctx context.Context) error {
|
|
|
|
_, err := cu.Save(ctx)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
|
|
func (cu *ConnectorUpdate) ExecX(ctx context.Context) {
|
|
|
|
if err := cu.Exec(ctx); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
|
|
func (cu *ConnectorUpdate) check() error {
|
|
|
|
if v, ok := cu.mutation.GetType(); ok {
|
|
|
|
if err := connector.TypeValidator(v); err != nil {
|
2022-03-07 14:45:01 +05:30
|
|
|
return &ValidationError{Name: "type", err: fmt.Errorf(`db: validator failed for field "Connector.type": %w`, err)}
|
2021-01-02 02:04:47 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
if v, ok := cu.mutation.Name(); ok {
|
|
|
|
if err := connector.NameValidator(v); err != nil {
|
2022-03-07 14:45:01 +05:30
|
|
|
return &ValidationError{Name: "name", err: fmt.Errorf(`db: validator failed for field "Connector.name": %w`, err)}
|
2021-01-02 02:04:47 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (cu *ConnectorUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
|
|
|
_spec := &sqlgraph.UpdateSpec{
|
|
|
|
Node: &sqlgraph.NodeSpec{
|
|
|
|
Table: connector.Table,
|
|
|
|
Columns: connector.Columns,
|
|
|
|
ID: &sqlgraph.FieldSpec{
|
|
|
|
Type: field.TypeString,
|
|
|
|
Column: connector.FieldID,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
if ps := cu.mutation.predicates; len(ps) > 0 {
|
|
|
|
_spec.Predicate = func(selector *sql.Selector) {
|
|
|
|
for i := range ps {
|
|
|
|
ps[i](selector)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if value, ok := cu.mutation.GetType(); ok {
|
|
|
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
|
|
|
Type: field.TypeString,
|
|
|
|
Value: value,
|
|
|
|
Column: connector.FieldType,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
if value, ok := cu.mutation.Name(); ok {
|
|
|
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
|
|
|
Type: field.TypeString,
|
|
|
|
Value: value,
|
|
|
|
Column: connector.FieldName,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
if value, ok := cu.mutation.ResourceVersion(); ok {
|
|
|
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
|
|
|
Type: field.TypeString,
|
|
|
|
Value: value,
|
|
|
|
Column: connector.FieldResourceVersion,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
if value, ok := cu.mutation.Config(); ok {
|
|
|
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
|
|
|
Type: field.TypeBytes,
|
|
|
|
Value: value,
|
|
|
|
Column: connector.FieldConfig,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
if n, err = sqlgraph.UpdateNodes(ctx, cu.driver, _spec); err != nil {
|
|
|
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
|
|
|
err = &NotFoundError{connector.Label}
|
2021-09-13 19:18:02 +05:30
|
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
|
|
err = &ConstraintError{err.Error(), err}
|
2021-01-02 02:04:47 +05:30
|
|
|
}
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
return n, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// ConnectorUpdateOne is the builder for updating a single Connector entity.
|
|
|
|
type ConnectorUpdateOne struct {
|
|
|
|
config
|
2021-04-30 20:01:49 +05:30
|
|
|
fields []string
|
2021-01-02 02:04:47 +05:30
|
|
|
hooks []Hook
|
|
|
|
mutation *ConnectorMutation
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetType sets the "type" field.
|
|
|
|
func (cuo *ConnectorUpdateOne) SetType(s string) *ConnectorUpdateOne {
|
|
|
|
cuo.mutation.SetType(s)
|
|
|
|
return cuo
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetName sets the "name" field.
|
|
|
|
func (cuo *ConnectorUpdateOne) SetName(s string) *ConnectorUpdateOne {
|
|
|
|
cuo.mutation.SetName(s)
|
|
|
|
return cuo
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetResourceVersion sets the "resource_version" field.
|
|
|
|
func (cuo *ConnectorUpdateOne) SetResourceVersion(s string) *ConnectorUpdateOne {
|
|
|
|
cuo.mutation.SetResourceVersion(s)
|
|
|
|
return cuo
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetConfig sets the "config" field.
|
|
|
|
func (cuo *ConnectorUpdateOne) SetConfig(b []byte) *ConnectorUpdateOne {
|
|
|
|
cuo.mutation.SetConfig(b)
|
|
|
|
return cuo
|
|
|
|
}
|
|
|
|
|
|
|
|
// Mutation returns the ConnectorMutation object of the builder.
|
|
|
|
func (cuo *ConnectorUpdateOne) Mutation() *ConnectorMutation {
|
|
|
|
return cuo.mutation
|
|
|
|
}
|
|
|
|
|
2021-04-30 20:01:49 +05:30
|
|
|
// Select allows selecting one or more fields (columns) of the returned entity.
|
|
|
|
// The default is selecting all fields defined in the entity schema.
|
|
|
|
func (cuo *ConnectorUpdateOne) Select(field string, fields ...string) *ConnectorUpdateOne {
|
|
|
|
cuo.fields = append([]string{field}, fields...)
|
|
|
|
return cuo
|
|
|
|
}
|
|
|
|
|
2021-01-02 02:04:47 +05:30
|
|
|
// Save executes the query and returns the updated Connector entity.
|
|
|
|
func (cuo *ConnectorUpdateOne) Save(ctx context.Context) (*Connector, error) {
|
|
|
|
var (
|
|
|
|
err error
|
|
|
|
node *Connector
|
|
|
|
)
|
|
|
|
if len(cuo.hooks) == 0 {
|
|
|
|
if err = cuo.check(); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
node, err = cuo.sqlSave(ctx)
|
|
|
|
} else {
|
|
|
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
|
|
|
mutation, ok := m.(*ConnectorMutation)
|
|
|
|
if !ok {
|
|
|
|
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
|
|
|
}
|
|
|
|
if err = cuo.check(); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
cuo.mutation = mutation
|
|
|
|
node, err = cuo.sqlSave(ctx)
|
|
|
|
mutation.done = true
|
|
|
|
return node, err
|
|
|
|
})
|
|
|
|
for i := len(cuo.hooks) - 1; i >= 0; i-- {
|
2021-09-13 19:18:02 +05:30
|
|
|
if cuo.hooks[i] == nil {
|
|
|
|
return nil, fmt.Errorf("db: uninitialized hook (forgotten import db/runtime?)")
|
|
|
|
}
|
2021-01-02 02:04:47 +05:30
|
|
|
mut = cuo.hooks[i](mut)
|
|
|
|
}
|
|
|
|
if _, err := mut.Mutate(ctx, cuo.mutation); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return node, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
|
|
func (cuo *ConnectorUpdateOne) SaveX(ctx context.Context) *Connector {
|
|
|
|
node, err := cuo.Save(ctx)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return node
|
|
|
|
}
|
|
|
|
|
|
|
|
// Exec executes the query on the entity.
|
|
|
|
func (cuo *ConnectorUpdateOne) Exec(ctx context.Context) error {
|
|
|
|
_, err := cuo.Save(ctx)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
|
|
func (cuo *ConnectorUpdateOne) ExecX(ctx context.Context) {
|
|
|
|
if err := cuo.Exec(ctx); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
|
|
func (cuo *ConnectorUpdateOne) check() error {
|
|
|
|
if v, ok := cuo.mutation.GetType(); ok {
|
|
|
|
if err := connector.TypeValidator(v); err != nil {
|
2022-03-07 14:45:01 +05:30
|
|
|
return &ValidationError{Name: "type", err: fmt.Errorf(`db: validator failed for field "Connector.type": %w`, err)}
|
2021-01-02 02:04:47 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
if v, ok := cuo.mutation.Name(); ok {
|
|
|
|
if err := connector.NameValidator(v); err != nil {
|
2022-03-07 14:45:01 +05:30
|
|
|
return &ValidationError{Name: "name", err: fmt.Errorf(`db: validator failed for field "Connector.name": %w`, err)}
|
2021-01-02 02:04:47 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (cuo *ConnectorUpdateOne) sqlSave(ctx context.Context) (_node *Connector, err error) {
|
|
|
|
_spec := &sqlgraph.UpdateSpec{
|
|
|
|
Node: &sqlgraph.NodeSpec{
|
|
|
|
Table: connector.Table,
|
|
|
|
Columns: connector.Columns,
|
|
|
|
ID: &sqlgraph.FieldSpec{
|
|
|
|
Type: field.TypeString,
|
|
|
|
Column: connector.FieldID,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
id, ok := cuo.mutation.ID()
|
|
|
|
if !ok {
|
2022-03-07 14:45:01 +05:30
|
|
|
return nil, &ValidationError{Name: "id", err: errors.New(`db: missing "Connector.id" for update`)}
|
2021-01-02 02:04:47 +05:30
|
|
|
}
|
|
|
|
_spec.Node.ID.Value = id
|
2021-04-30 20:01:49 +05:30
|
|
|
if fields := cuo.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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-03-24 12:07:51 +05:30
|
|
|
if ps := cuo.mutation.predicates; len(ps) > 0 {
|
|
|
|
_spec.Predicate = func(selector *sql.Selector) {
|
|
|
|
for i := range ps {
|
|
|
|
ps[i](selector)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-01-02 02:04:47 +05:30
|
|
|
if value, ok := cuo.mutation.GetType(); ok {
|
|
|
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
|
|
|
Type: field.TypeString,
|
|
|
|
Value: value,
|
|
|
|
Column: connector.FieldType,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
if value, ok := cuo.mutation.Name(); ok {
|
|
|
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
|
|
|
Type: field.TypeString,
|
|
|
|
Value: value,
|
|
|
|
Column: connector.FieldName,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
if value, ok := cuo.mutation.ResourceVersion(); ok {
|
|
|
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
|
|
|
Type: field.TypeString,
|
|
|
|
Value: value,
|
|
|
|
Column: connector.FieldResourceVersion,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
if value, ok := cuo.mutation.Config(); ok {
|
|
|
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
|
|
|
Type: field.TypeBytes,
|
|
|
|
Value: value,
|
|
|
|
Column: connector.FieldConfig,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
_node = &Connector{config: cuo.config}
|
|
|
|
_spec.Assign = _node.assignValues
|
|
|
|
_spec.ScanValues = _node.scanValues
|
|
|
|
if err = sqlgraph.UpdateNode(ctx, cuo.driver, _spec); err != nil {
|
|
|
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
|
|
|
err = &NotFoundError{connector.Label}
|
2021-09-13 19:18:02 +05:30
|
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
|
|
err = &ConstraintError{err.Error(), err}
|
2021-01-02 02:04:47 +05:30
|
|
|
}
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return _node, nil
|
|
|
|
}
|