// Code generated by ent, DO NOT EDIT. package db import ( "context" "errors" "fmt" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" "github.com/dexidp/dex/storage/ent/db/oauth2client" ) // OAuth2ClientCreate is the builder for creating a OAuth2Client entity. type OAuth2ClientCreate struct { config mutation *OAuth2ClientMutation hooks []Hook } // SetSecret sets the "secret" field. func (_c *OAuth2ClientCreate) SetSecret(v string) *OAuth2ClientCreate { _c.mutation.SetSecret(v) return _c } // SetRedirectUris sets the "redirect_uris" field. func (_c *OAuth2ClientCreate) SetRedirectUris(v []string) *OAuth2ClientCreate { _c.mutation.SetRedirectUris(v) return _c } // SetTrustedPeers sets the "trusted_peers" field. func (_c *OAuth2ClientCreate) SetTrustedPeers(v []string) *OAuth2ClientCreate { _c.mutation.SetTrustedPeers(v) return _c } // SetPublic sets the "public" field. func (_c *OAuth2ClientCreate) SetPublic(v bool) *OAuth2ClientCreate { _c.mutation.SetPublic(v) return _c } // SetName sets the "name" field. func (_c *OAuth2ClientCreate) SetName(v string) *OAuth2ClientCreate { _c.mutation.SetName(v) return _c } // SetLogoURL sets the "logo_url" field. func (_c *OAuth2ClientCreate) SetLogoURL(v string) *OAuth2ClientCreate { _c.mutation.SetLogoURL(v) return _c } // SetAllowedConnectors sets the "allowed_connectors" field. func (_c *OAuth2ClientCreate) SetAllowedConnectors(v []string) *OAuth2ClientCreate { _c.mutation.SetAllowedConnectors(v) return _c } // SetMfaChain sets the "mfa_chain" field. func (_c *OAuth2ClientCreate) SetMfaChain(v []string) *OAuth2ClientCreate { _c.mutation.SetMfaChain(v) return _c } // SetPostLogoutRedirectUris sets the "post_logout_redirect_uris" field. func (_c *OAuth2ClientCreate) SetPostLogoutRedirectUris(v []string) *OAuth2ClientCreate { _c.mutation.SetPostLogoutRedirectUris(v) return _c } // SetSSOSharedWith sets the "sso_shared_with" field. func (_c *OAuth2ClientCreate) SetSSOSharedWith(v []string) *OAuth2ClientCreate { _c.mutation.SetSSOSharedWith(v) return _c } // SetID sets the "id" field. func (_c *OAuth2ClientCreate) SetID(v string) *OAuth2ClientCreate { _c.mutation.SetID(v) return _c } // Mutation returns the OAuth2ClientMutation object of the builder. func (_c *OAuth2ClientCreate) Mutation() *OAuth2ClientMutation { return _c.mutation } // Save creates the OAuth2Client in the database. func (_c *OAuth2ClientCreate) Save(ctx context.Context) (*OAuth2Client, error) { return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks) } // SaveX calls Save and panics if Save returns an error. func (_c *OAuth2ClientCreate) SaveX(ctx context.Context) *OAuth2Client { v, err := _c.Save(ctx) if err != nil { panic(err) } return v } // Exec executes the query. func (_c *OAuth2ClientCreate) Exec(ctx context.Context) error { _, err := _c.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (_c *OAuth2ClientCreate) ExecX(ctx context.Context) { if err := _c.Exec(ctx); err != nil { panic(err) } } // check runs all checks and user-defined validators on the builder. func (_c *OAuth2ClientCreate) check() error { if _, ok := _c.mutation.Secret(); !ok { return &ValidationError{Name: "secret", err: errors.New(`db: missing required field "OAuth2Client.secret"`)} } if v, ok := _c.mutation.Secret(); ok { if err := oauth2client.SecretValidator(v); err != nil { return &ValidationError{Name: "secret", err: fmt.Errorf(`db: validator failed for field "OAuth2Client.secret": %w`, err)} } } if _, ok := _c.mutation.Public(); !ok { return &ValidationError{Name: "public", err: errors.New(`db: missing required field "OAuth2Client.public"`)} } if _, ok := _c.mutation.Name(); !ok { return &ValidationError{Name: "name", err: errors.New(`db: missing required field "OAuth2Client.name"`)} } if v, ok := _c.mutation.Name(); ok { if err := oauth2client.NameValidator(v); err != nil { return &ValidationError{Name: "name", err: fmt.Errorf(`db: validator failed for field "OAuth2Client.name": %w`, err)} } } if _, ok := _c.mutation.LogoURL(); !ok { return &ValidationError{Name: "logo_url", err: errors.New(`db: missing required field "OAuth2Client.logo_url"`)} } if v, ok := _c.mutation.LogoURL(); ok { if err := oauth2client.LogoURLValidator(v); err != nil { return &ValidationError{Name: "logo_url", err: fmt.Errorf(`db: validator failed for field "OAuth2Client.logo_url": %w`, err)} } } if v, ok := _c.mutation.ID(); ok { if err := oauth2client.IDValidator(v); err != nil { return &ValidationError{Name: "id", err: fmt.Errorf(`db: validator failed for field "OAuth2Client.id": %w`, err)} } } return nil } func (_c *OAuth2ClientCreate) sqlSave(ctx context.Context) (*OAuth2Client, error) { if err := _c.check(); err != nil { return nil, err } _node, _spec := _c.createSpec() if err := sqlgraph.CreateNode(ctx, _c.driver, _spec); err != nil { if sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } return nil, err } if _spec.ID.Value != nil { if id, ok := _spec.ID.Value.(string); ok { _node.ID = id } else { return nil, fmt.Errorf("unexpected OAuth2Client.ID type: %T", _spec.ID.Value) } } _c.mutation.id = &_node.ID _c.mutation.done = true return _node, nil } func (_c *OAuth2ClientCreate) createSpec() (*OAuth2Client, *sqlgraph.CreateSpec) { var ( _node = &OAuth2Client{config: _c.config} _spec = sqlgraph.NewCreateSpec(oauth2client.Table, sqlgraph.NewFieldSpec(oauth2client.FieldID, field.TypeString)) ) if id, ok := _c.mutation.ID(); ok { _node.ID = id _spec.ID.Value = id } if value, ok := _c.mutation.Secret(); ok { _spec.SetField(oauth2client.FieldSecret, field.TypeString, value) _node.Secret = value } if value, ok := _c.mutation.RedirectUris(); ok { _spec.SetField(oauth2client.FieldRedirectUris, field.TypeJSON, value) _node.RedirectUris = value } if value, ok := _c.mutation.TrustedPeers(); ok { _spec.SetField(oauth2client.FieldTrustedPeers, field.TypeJSON, value) _node.TrustedPeers = value } if value, ok := _c.mutation.Public(); ok { _spec.SetField(oauth2client.FieldPublic, field.TypeBool, value) _node.Public = value } if value, ok := _c.mutation.Name(); ok { _spec.SetField(oauth2client.FieldName, field.TypeString, value) _node.Name = value } if value, ok := _c.mutation.LogoURL(); ok { _spec.SetField(oauth2client.FieldLogoURL, field.TypeString, value) _node.LogoURL = value } if value, ok := _c.mutation.AllowedConnectors(); ok { _spec.SetField(oauth2client.FieldAllowedConnectors, field.TypeJSON, value) _node.AllowedConnectors = value } if value, ok := _c.mutation.MfaChain(); ok { _spec.SetField(oauth2client.FieldMfaChain, field.TypeJSON, value) _node.MfaChain = value } if value, ok := _c.mutation.PostLogoutRedirectUris(); ok { _spec.SetField(oauth2client.FieldPostLogoutRedirectUris, field.TypeJSON, value) _node.PostLogoutRedirectUris = value } if value, ok := _c.mutation.SSOSharedWith(); ok { _spec.SetField(oauth2client.FieldSSOSharedWith, field.TypeJSON, value) _node.SSOSharedWith = value } return _node, _spec } // OAuth2ClientCreateBulk is the builder for creating many OAuth2Client entities in bulk. type OAuth2ClientCreateBulk struct { config err error builders []*OAuth2ClientCreate } // Save creates the OAuth2Client entities in the database. func (_c *OAuth2ClientCreateBulk) Save(ctx context.Context) ([]*OAuth2Client, error) { if _c.err != nil { return nil, _c.err } specs := make([]*sqlgraph.CreateSpec, len(_c.builders)) nodes := make([]*OAuth2Client, len(_c.builders)) mutators := make([]Mutator, len(_c.builders)) for i := range _c.builders { func(i int, root context.Context) { builder := _c.builders[i] var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { mutation, ok := m.(*OAuth2ClientMutation) if !ok { return nil, fmt.Errorf("unexpected mutation type %T", m) } if err := builder.check(); err != nil { return nil, err } builder.mutation = mutation var err error nodes[i], specs[i] = builder.createSpec() if i < len(mutators)-1 { _, err = mutators[i+1].Mutate(root, _c.builders[i+1].mutation) } else { spec := &sqlgraph.BatchCreateSpec{Nodes: specs} // Invoke the actual operation on the latest mutation in the chain. if err = sqlgraph.BatchCreate(ctx, _c.driver, spec); err != nil { if sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } } } if err != nil { return nil, err } mutation.id = &nodes[i].ID mutation.done = true return nodes[i], nil }) for i := len(builder.hooks) - 1; i >= 0; i-- { mut = builder.hooks[i](mut) } mutators[i] = mut }(i, ctx) } if len(mutators) > 0 { if _, err := mutators[0].Mutate(ctx, _c.builders[0].mutation); err != nil { return nil, err } } return nodes, nil } // SaveX is like Save, but panics if an error occurs. func (_c *OAuth2ClientCreateBulk) SaveX(ctx context.Context) []*OAuth2Client { v, err := _c.Save(ctx) if err != nil { panic(err) } return v } // Exec executes the query. func (_c *OAuth2ClientCreateBulk) Exec(ctx context.Context) error { _, err := _c.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (_c *OAuth2ClientCreateBulk) ExecX(ctx context.Context) { if err := _c.Exec(ctx); err != nil { panic(err) } }