You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1297 lines
39 KiB
Go

// Code generated by ent, DO NOT EDIT.
package ent
import (
"context"
"errors"
"fmt"
"time"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"git.noahlan.cn/n-admin/n-admin-server/rpc/core/ent/oauthprovider"
)
// OauthProviderCreate is the builder for creating a OauthProvider entity.
type OauthProviderCreate struct {
config
mutation *OauthProviderMutation
hooks []Hook
conflict []sql.ConflictOption
}
// SetCreatedAt sets the "created_at" field.
func (opc *OauthProviderCreate) SetCreatedAt(t time.Time) *OauthProviderCreate {
opc.mutation.SetCreatedAt(t)
return opc
}
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
func (opc *OauthProviderCreate) SetNillableCreatedAt(t *time.Time) *OauthProviderCreate {
if t != nil {
opc.SetCreatedAt(*t)
}
return opc
}
// SetUpdatedAt sets the "updated_at" field.
func (opc *OauthProviderCreate) SetUpdatedAt(t time.Time) *OauthProviderCreate {
opc.mutation.SetUpdatedAt(t)
return opc
}
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
func (opc *OauthProviderCreate) SetNillableUpdatedAt(t *time.Time) *OauthProviderCreate {
if t != nil {
opc.SetUpdatedAt(*t)
}
return opc
}
// SetDeletedAt sets the "deleted_at" field.
func (opc *OauthProviderCreate) SetDeletedAt(t time.Time) *OauthProviderCreate {
opc.mutation.SetDeletedAt(t)
return opc
}
// SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
func (opc *OauthProviderCreate) SetNillableDeletedAt(t *time.Time) *OauthProviderCreate {
if t != nil {
opc.SetDeletedAt(*t)
}
return opc
}
// SetName sets the "name" field.
func (opc *OauthProviderCreate) SetName(s string) *OauthProviderCreate {
opc.mutation.SetName(s)
return opc
}
// SetClientID sets the "client_id" field.
func (opc *OauthProviderCreate) SetClientID(s string) *OauthProviderCreate {
opc.mutation.SetClientID(s)
return opc
}
// SetClientSecret sets the "client_secret" field.
func (opc *OauthProviderCreate) SetClientSecret(s string) *OauthProviderCreate {
opc.mutation.SetClientSecret(s)
return opc
}
// SetRedirectURL sets the "redirect_url" field.
func (opc *OauthProviderCreate) SetRedirectURL(s string) *OauthProviderCreate {
opc.mutation.SetRedirectURL(s)
return opc
}
// SetNillableRedirectURL sets the "redirect_url" field if the given value is not nil.
func (opc *OauthProviderCreate) SetNillableRedirectURL(s *string) *OauthProviderCreate {
if s != nil {
opc.SetRedirectURL(*s)
}
return opc
}
// SetScopes sets the "scopes" field.
func (opc *OauthProviderCreate) SetScopes(s string) *OauthProviderCreate {
opc.mutation.SetScopes(s)
return opc
}
// SetNillableScopes sets the "scopes" field if the given value is not nil.
func (opc *OauthProviderCreate) SetNillableScopes(s *string) *OauthProviderCreate {
if s != nil {
opc.SetScopes(*s)
}
return opc
}
// SetAuthURL sets the "auth_url" field.
func (opc *OauthProviderCreate) SetAuthURL(s string) *OauthProviderCreate {
opc.mutation.SetAuthURL(s)
return opc
}
// SetNillableAuthURL sets the "auth_url" field if the given value is not nil.
func (opc *OauthProviderCreate) SetNillableAuthURL(s *string) *OauthProviderCreate {
if s != nil {
opc.SetAuthURL(*s)
}
return opc
}
// SetTokenURL sets the "token_url" field.
func (opc *OauthProviderCreate) SetTokenURL(s string) *OauthProviderCreate {
opc.mutation.SetTokenURL(s)
return opc
}
// SetNillableTokenURL sets the "token_url" field if the given value is not nil.
func (opc *OauthProviderCreate) SetNillableTokenURL(s *string) *OauthProviderCreate {
if s != nil {
opc.SetTokenURL(*s)
}
return opc
}
// SetInfoURL sets the "info_url" field.
func (opc *OauthProviderCreate) SetInfoURL(s string) *OauthProviderCreate {
opc.mutation.SetInfoURL(s)
return opc
}
// SetNillableInfoURL sets the "info_url" field if the given value is not nil.
func (opc *OauthProviderCreate) SetNillableInfoURL(s *string) *OauthProviderCreate {
if s != nil {
opc.SetInfoURL(*s)
}
return opc
}
// SetDescription sets the "description" field.
func (opc *OauthProviderCreate) SetDescription(s string) *OauthProviderCreate {
opc.mutation.SetDescription(s)
return opc
}
// SetNillableDescription sets the "description" field if the given value is not nil.
func (opc *OauthProviderCreate) SetNillableDescription(s *string) *OauthProviderCreate {
if s != nil {
opc.SetDescription(*s)
}
return opc
}
// SetSystem sets the "system" field.
func (opc *OauthProviderCreate) SetSystem(b bool) *OauthProviderCreate {
opc.mutation.SetSystem(b)
return opc
}
// SetNillableSystem sets the "system" field if the given value is not nil.
func (opc *OauthProviderCreate) SetNillableSystem(b *bool) *OauthProviderCreate {
if b != nil {
opc.SetSystem(*b)
}
return opc
}
// SetInit sets the "init" field.
func (opc *OauthProviderCreate) SetInit(b bool) *OauthProviderCreate {
opc.mutation.SetInit(b)
return opc
}
// SetNillableInit sets the "init" field if the given value is not nil.
func (opc *OauthProviderCreate) SetNillableInit(b *bool) *OauthProviderCreate {
if b != nil {
opc.SetInit(*b)
}
return opc
}
// SetID sets the "id" field.
func (opc *OauthProviderCreate) SetID(i int64) *OauthProviderCreate {
opc.mutation.SetID(i)
return opc
}
// SetNillableID sets the "id" field if the given value is not nil.
func (opc *OauthProviderCreate) SetNillableID(i *int64) *OauthProviderCreate {
if i != nil {
opc.SetID(*i)
}
return opc
}
// Mutation returns the OauthProviderMutation object of the builder.
func (opc *OauthProviderCreate) Mutation() *OauthProviderMutation {
return opc.mutation
}
// Save creates the OauthProvider in the database.
func (opc *OauthProviderCreate) Save(ctx context.Context) (*OauthProvider, error) {
opc.defaults()
return withHooks(ctx, opc.sqlSave, opc.mutation, opc.hooks)
}
// SaveX calls Save and panics if Save returns an error.
func (opc *OauthProviderCreate) SaveX(ctx context.Context) *OauthProvider {
v, err := opc.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (opc *OauthProviderCreate) Exec(ctx context.Context) error {
_, err := opc.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (opc *OauthProviderCreate) ExecX(ctx context.Context) {
if err := opc.Exec(ctx); err != nil {
panic(err)
}
}
// defaults sets the default values of the builder before save.
func (opc *OauthProviderCreate) defaults() {
if _, ok := opc.mutation.CreatedAt(); !ok {
v := oauthprovider.DefaultCreatedAt()
opc.mutation.SetCreatedAt(v)
}
if _, ok := opc.mutation.UpdatedAt(); !ok {
v := oauthprovider.DefaultUpdatedAt()
opc.mutation.SetUpdatedAt(v)
}
if _, ok := opc.mutation.RedirectURL(); !ok {
v := oauthprovider.DefaultRedirectURL
opc.mutation.SetRedirectURL(v)
}
if _, ok := opc.mutation.Scopes(); !ok {
v := oauthprovider.DefaultScopes
opc.mutation.SetScopes(v)
}
if _, ok := opc.mutation.AuthURL(); !ok {
v := oauthprovider.DefaultAuthURL
opc.mutation.SetAuthURL(v)
}
if _, ok := opc.mutation.TokenURL(); !ok {
v := oauthprovider.DefaultTokenURL
opc.mutation.SetTokenURL(v)
}
if _, ok := opc.mutation.InfoURL(); !ok {
v := oauthprovider.DefaultInfoURL
opc.mutation.SetInfoURL(v)
}
if _, ok := opc.mutation.Description(); !ok {
v := oauthprovider.DefaultDescription
opc.mutation.SetDescription(v)
}
if _, ok := opc.mutation.System(); !ok {
v := oauthprovider.DefaultSystem
opc.mutation.SetSystem(v)
}
if _, ok := opc.mutation.Init(); !ok {
v := oauthprovider.DefaultInit
opc.mutation.SetInit(v)
}
if _, ok := opc.mutation.ID(); !ok {
v := oauthprovider.DefaultID()
opc.mutation.SetID(v)
}
}
// check runs all checks and user-defined validators on the builder.
func (opc *OauthProviderCreate) check() error {
if _, ok := opc.mutation.CreatedAt(); !ok {
return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "OauthProvider.created_at"`)}
}
if _, ok := opc.mutation.UpdatedAt(); !ok {
return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "OauthProvider.updated_at"`)}
}
if _, ok := opc.mutation.Name(); !ok {
return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "OauthProvider.name"`)}
}
if _, ok := opc.mutation.ClientID(); !ok {
return &ValidationError{Name: "client_id", err: errors.New(`ent: missing required field "OauthProvider.client_id"`)}
}
if _, ok := opc.mutation.ClientSecret(); !ok {
return &ValidationError{Name: "client_secret", err: errors.New(`ent: missing required field "OauthProvider.client_secret"`)}
}
if _, ok := opc.mutation.RedirectURL(); !ok {
return &ValidationError{Name: "redirect_url", err: errors.New(`ent: missing required field "OauthProvider.redirect_url"`)}
}
if _, ok := opc.mutation.Scopes(); !ok {
return &ValidationError{Name: "scopes", err: errors.New(`ent: missing required field "OauthProvider.scopes"`)}
}
if _, ok := opc.mutation.AuthURL(); !ok {
return &ValidationError{Name: "auth_url", err: errors.New(`ent: missing required field "OauthProvider.auth_url"`)}
}
if _, ok := opc.mutation.TokenURL(); !ok {
return &ValidationError{Name: "token_url", err: errors.New(`ent: missing required field "OauthProvider.token_url"`)}
}
if _, ok := opc.mutation.InfoURL(); !ok {
return &ValidationError{Name: "info_url", err: errors.New(`ent: missing required field "OauthProvider.info_url"`)}
}
if _, ok := opc.mutation.Description(); !ok {
return &ValidationError{Name: "description", err: errors.New(`ent: missing required field "OauthProvider.description"`)}
}
if _, ok := opc.mutation.System(); !ok {
return &ValidationError{Name: "system", err: errors.New(`ent: missing required field "OauthProvider.system"`)}
}
if _, ok := opc.mutation.Init(); !ok {
return &ValidationError{Name: "init", err: errors.New(`ent: missing required field "OauthProvider.init"`)}
}
return nil
}
func (opc *OauthProviderCreate) sqlSave(ctx context.Context) (*OauthProvider, error) {
if err := opc.check(); err != nil {
return nil, err
}
_node, _spec := opc.createSpec()
if err := sqlgraph.CreateNode(ctx, opc.driver, _spec); err != nil {
if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return nil, err
}
if _spec.ID.Value != _node.ID {
id := _spec.ID.Value.(int64)
_node.ID = int64(id)
}
opc.mutation.id = &_node.ID
opc.mutation.done = true
return _node, nil
}
func (opc *OauthProviderCreate) createSpec() (*OauthProvider, *sqlgraph.CreateSpec) {
var (
_node = &OauthProvider{config: opc.config}
_spec = sqlgraph.NewCreateSpec(oauthprovider.Table, sqlgraph.NewFieldSpec(oauthprovider.FieldID, field.TypeInt64))
)
_spec.OnConflict = opc.conflict
if id, ok := opc.mutation.ID(); ok {
_node.ID = id
_spec.ID.Value = id
}
if value, ok := opc.mutation.CreatedAt(); ok {
_spec.SetField(oauthprovider.FieldCreatedAt, field.TypeTime, value)
_node.CreatedAt = value
}
if value, ok := opc.mutation.UpdatedAt(); ok {
_spec.SetField(oauthprovider.FieldUpdatedAt, field.TypeTime, value)
_node.UpdatedAt = value
}
if value, ok := opc.mutation.DeletedAt(); ok {
_spec.SetField(oauthprovider.FieldDeletedAt, field.TypeTime, value)
_node.DeletedAt = value
}
if value, ok := opc.mutation.Name(); ok {
_spec.SetField(oauthprovider.FieldName, field.TypeString, value)
_node.Name = value
}
if value, ok := opc.mutation.ClientID(); ok {
_spec.SetField(oauthprovider.FieldClientID, field.TypeString, value)
_node.ClientID = value
}
if value, ok := opc.mutation.ClientSecret(); ok {
_spec.SetField(oauthprovider.FieldClientSecret, field.TypeString, value)
_node.ClientSecret = value
}
if value, ok := opc.mutation.RedirectURL(); ok {
_spec.SetField(oauthprovider.FieldRedirectURL, field.TypeString, value)
_node.RedirectURL = value
}
if value, ok := opc.mutation.Scopes(); ok {
_spec.SetField(oauthprovider.FieldScopes, field.TypeString, value)
_node.Scopes = value
}
if value, ok := opc.mutation.AuthURL(); ok {
_spec.SetField(oauthprovider.FieldAuthURL, field.TypeString, value)
_node.AuthURL = value
}
if value, ok := opc.mutation.TokenURL(); ok {
_spec.SetField(oauthprovider.FieldTokenURL, field.TypeString, value)
_node.TokenURL = value
}
if value, ok := opc.mutation.InfoURL(); ok {
_spec.SetField(oauthprovider.FieldInfoURL, field.TypeString, value)
_node.InfoURL = value
}
if value, ok := opc.mutation.Description(); ok {
_spec.SetField(oauthprovider.FieldDescription, field.TypeString, value)
_node.Description = value
}
if value, ok := opc.mutation.System(); ok {
_spec.SetField(oauthprovider.FieldSystem, field.TypeBool, value)
_node.System = value
}
if value, ok := opc.mutation.Init(); ok {
_spec.SetField(oauthprovider.FieldInit, field.TypeBool, value)
_node.Init = value
}
return _node, _spec
}
// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
// of the `INSERT` statement. For example:
//
// client.OauthProvider.Create().
// SetCreatedAt(v).
// OnConflict(
// // Update the row with the new values
// // the was proposed for insertion.
// sql.ResolveWithNewValues(),
// ).
// // Override some of the fields with custom
// // update values.
// Update(func(u *ent.OauthProviderUpsert) {
// SetCreatedAt(v+v).
// }).
// Exec(ctx)
func (opc *OauthProviderCreate) OnConflict(opts ...sql.ConflictOption) *OauthProviderUpsertOne {
opc.conflict = opts
return &OauthProviderUpsertOne{
create: opc,
}
}
// OnConflictColumns calls `OnConflict` and configures the columns
// as conflict target. Using this option is equivalent to using:
//
// client.OauthProvider.Create().
// OnConflict(sql.ConflictColumns(columns...)).
// Exec(ctx)
func (opc *OauthProviderCreate) OnConflictColumns(columns ...string) *OauthProviderUpsertOne {
opc.conflict = append(opc.conflict, sql.ConflictColumns(columns...))
return &OauthProviderUpsertOne{
create: opc,
}
}
type (
// OauthProviderUpsertOne is the builder for "upsert"-ing
// one OauthProvider node.
OauthProviderUpsertOne struct {
create *OauthProviderCreate
}
// OauthProviderUpsert is the "OnConflict" setter.
OauthProviderUpsert struct {
*sql.UpdateSet
}
)
// SetUpdatedAt sets the "updated_at" field.
func (u *OauthProviderUpsert) SetUpdatedAt(v time.Time) *OauthProviderUpsert {
u.Set(oauthprovider.FieldUpdatedAt, v)
return u
}
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
func (u *OauthProviderUpsert) UpdateUpdatedAt() *OauthProviderUpsert {
u.SetExcluded(oauthprovider.FieldUpdatedAt)
return u
}
// SetDeletedAt sets the "deleted_at" field.
func (u *OauthProviderUpsert) SetDeletedAt(v time.Time) *OauthProviderUpsert {
u.Set(oauthprovider.FieldDeletedAt, v)
return u
}
// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
func (u *OauthProviderUpsert) UpdateDeletedAt() *OauthProviderUpsert {
u.SetExcluded(oauthprovider.FieldDeletedAt)
return u
}
// ClearDeletedAt clears the value of the "deleted_at" field.
func (u *OauthProviderUpsert) ClearDeletedAt() *OauthProviderUpsert {
u.SetNull(oauthprovider.FieldDeletedAt)
return u
}
// SetName sets the "name" field.
func (u *OauthProviderUpsert) SetName(v string) *OauthProviderUpsert {
u.Set(oauthprovider.FieldName, v)
return u
}
// UpdateName sets the "name" field to the value that was provided on create.
func (u *OauthProviderUpsert) UpdateName() *OauthProviderUpsert {
u.SetExcluded(oauthprovider.FieldName)
return u
}
// SetClientID sets the "client_id" field.
func (u *OauthProviderUpsert) SetClientID(v string) *OauthProviderUpsert {
u.Set(oauthprovider.FieldClientID, v)
return u
}
// UpdateClientID sets the "client_id" field to the value that was provided on create.
func (u *OauthProviderUpsert) UpdateClientID() *OauthProviderUpsert {
u.SetExcluded(oauthprovider.FieldClientID)
return u
}
// SetClientSecret sets the "client_secret" field.
func (u *OauthProviderUpsert) SetClientSecret(v string) *OauthProviderUpsert {
u.Set(oauthprovider.FieldClientSecret, v)
return u
}
// UpdateClientSecret sets the "client_secret" field to the value that was provided on create.
func (u *OauthProviderUpsert) UpdateClientSecret() *OauthProviderUpsert {
u.SetExcluded(oauthprovider.FieldClientSecret)
return u
}
// SetRedirectURL sets the "redirect_url" field.
func (u *OauthProviderUpsert) SetRedirectURL(v string) *OauthProviderUpsert {
u.Set(oauthprovider.FieldRedirectURL, v)
return u
}
// UpdateRedirectURL sets the "redirect_url" field to the value that was provided on create.
func (u *OauthProviderUpsert) UpdateRedirectURL() *OauthProviderUpsert {
u.SetExcluded(oauthprovider.FieldRedirectURL)
return u
}
// SetScopes sets the "scopes" field.
func (u *OauthProviderUpsert) SetScopes(v string) *OauthProviderUpsert {
u.Set(oauthprovider.FieldScopes, v)
return u
}
// UpdateScopes sets the "scopes" field to the value that was provided on create.
func (u *OauthProviderUpsert) UpdateScopes() *OauthProviderUpsert {
u.SetExcluded(oauthprovider.FieldScopes)
return u
}
// SetAuthURL sets the "auth_url" field.
func (u *OauthProviderUpsert) SetAuthURL(v string) *OauthProviderUpsert {
u.Set(oauthprovider.FieldAuthURL, v)
return u
}
// UpdateAuthURL sets the "auth_url" field to the value that was provided on create.
func (u *OauthProviderUpsert) UpdateAuthURL() *OauthProviderUpsert {
u.SetExcluded(oauthprovider.FieldAuthURL)
return u
}
// SetTokenURL sets the "token_url" field.
func (u *OauthProviderUpsert) SetTokenURL(v string) *OauthProviderUpsert {
u.Set(oauthprovider.FieldTokenURL, v)
return u
}
// UpdateTokenURL sets the "token_url" field to the value that was provided on create.
func (u *OauthProviderUpsert) UpdateTokenURL() *OauthProviderUpsert {
u.SetExcluded(oauthprovider.FieldTokenURL)
return u
}
// SetInfoURL sets the "info_url" field.
func (u *OauthProviderUpsert) SetInfoURL(v string) *OauthProviderUpsert {
u.Set(oauthprovider.FieldInfoURL, v)
return u
}
// UpdateInfoURL sets the "info_url" field to the value that was provided on create.
func (u *OauthProviderUpsert) UpdateInfoURL() *OauthProviderUpsert {
u.SetExcluded(oauthprovider.FieldInfoURL)
return u
}
// SetDescription sets the "description" field.
func (u *OauthProviderUpsert) SetDescription(v string) *OauthProviderUpsert {
u.Set(oauthprovider.FieldDescription, v)
return u
}
// UpdateDescription sets the "description" field to the value that was provided on create.
func (u *OauthProviderUpsert) UpdateDescription() *OauthProviderUpsert {
u.SetExcluded(oauthprovider.FieldDescription)
return u
}
// SetSystem sets the "system" field.
func (u *OauthProviderUpsert) SetSystem(v bool) *OauthProviderUpsert {
u.Set(oauthprovider.FieldSystem, v)
return u
}
// UpdateSystem sets the "system" field to the value that was provided on create.
func (u *OauthProviderUpsert) UpdateSystem() *OauthProviderUpsert {
u.SetExcluded(oauthprovider.FieldSystem)
return u
}
// SetInit sets the "init" field.
func (u *OauthProviderUpsert) SetInit(v bool) *OauthProviderUpsert {
u.Set(oauthprovider.FieldInit, v)
return u
}
// UpdateInit sets the "init" field to the value that was provided on create.
func (u *OauthProviderUpsert) UpdateInit() *OauthProviderUpsert {
u.SetExcluded(oauthprovider.FieldInit)
return u
}
// UpdateNewValues updates the mutable fields using the new values that were set on create except the ID field.
// Using this option is equivalent to using:
//
// client.OauthProvider.Create().
// OnConflict(
// sql.ResolveWithNewValues(),
// sql.ResolveWith(func(u *sql.UpdateSet) {
// u.SetIgnore(oauthprovider.FieldID)
// }),
// ).
// Exec(ctx)
func (u *OauthProviderUpsertOne) UpdateNewValues() *OauthProviderUpsertOne {
u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
if _, exists := u.create.mutation.ID(); exists {
s.SetIgnore(oauthprovider.FieldID)
}
if _, exists := u.create.mutation.CreatedAt(); exists {
s.SetIgnore(oauthprovider.FieldCreatedAt)
}
}))
return u
}
// Ignore sets each column to itself in case of conflict.
// Using this option is equivalent to using:
//
// client.OauthProvider.Create().
// OnConflict(sql.ResolveWithIgnore()).
// Exec(ctx)
func (u *OauthProviderUpsertOne) Ignore() *OauthProviderUpsertOne {
u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
return u
}
// DoNothing configures the conflict_action to `DO NOTHING`.
// Supported only by SQLite and PostgreSQL.
func (u *OauthProviderUpsertOne) DoNothing() *OauthProviderUpsertOne {
u.create.conflict = append(u.create.conflict, sql.DoNothing())
return u
}
// Update allows overriding fields `UPDATE` values. See the OauthProviderCreate.OnConflict
// documentation for more info.
func (u *OauthProviderUpsertOne) Update(set func(*OauthProviderUpsert)) *OauthProviderUpsertOne {
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
set(&OauthProviderUpsert{UpdateSet: update})
}))
return u
}
// SetUpdatedAt sets the "updated_at" field.
func (u *OauthProviderUpsertOne) SetUpdatedAt(v time.Time) *OauthProviderUpsertOne {
return u.Update(func(s *OauthProviderUpsert) {
s.SetUpdatedAt(v)
})
}
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
func (u *OauthProviderUpsertOne) UpdateUpdatedAt() *OauthProviderUpsertOne {
return u.Update(func(s *OauthProviderUpsert) {
s.UpdateUpdatedAt()
})
}
// SetDeletedAt sets the "deleted_at" field.
func (u *OauthProviderUpsertOne) SetDeletedAt(v time.Time) *OauthProviderUpsertOne {
return u.Update(func(s *OauthProviderUpsert) {
s.SetDeletedAt(v)
})
}
// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
func (u *OauthProviderUpsertOne) UpdateDeletedAt() *OauthProviderUpsertOne {
return u.Update(func(s *OauthProviderUpsert) {
s.UpdateDeletedAt()
})
}
// ClearDeletedAt clears the value of the "deleted_at" field.
func (u *OauthProviderUpsertOne) ClearDeletedAt() *OauthProviderUpsertOne {
return u.Update(func(s *OauthProviderUpsert) {
s.ClearDeletedAt()
})
}
// SetName sets the "name" field.
func (u *OauthProviderUpsertOne) SetName(v string) *OauthProviderUpsertOne {
return u.Update(func(s *OauthProviderUpsert) {
s.SetName(v)
})
}
// UpdateName sets the "name" field to the value that was provided on create.
func (u *OauthProviderUpsertOne) UpdateName() *OauthProviderUpsertOne {
return u.Update(func(s *OauthProviderUpsert) {
s.UpdateName()
})
}
// SetClientID sets the "client_id" field.
func (u *OauthProviderUpsertOne) SetClientID(v string) *OauthProviderUpsertOne {
return u.Update(func(s *OauthProviderUpsert) {
s.SetClientID(v)
})
}
// UpdateClientID sets the "client_id" field to the value that was provided on create.
func (u *OauthProviderUpsertOne) UpdateClientID() *OauthProviderUpsertOne {
return u.Update(func(s *OauthProviderUpsert) {
s.UpdateClientID()
})
}
// SetClientSecret sets the "client_secret" field.
func (u *OauthProviderUpsertOne) SetClientSecret(v string) *OauthProviderUpsertOne {
return u.Update(func(s *OauthProviderUpsert) {
s.SetClientSecret(v)
})
}
// UpdateClientSecret sets the "client_secret" field to the value that was provided on create.
func (u *OauthProviderUpsertOne) UpdateClientSecret() *OauthProviderUpsertOne {
return u.Update(func(s *OauthProviderUpsert) {
s.UpdateClientSecret()
})
}
// SetRedirectURL sets the "redirect_url" field.
func (u *OauthProviderUpsertOne) SetRedirectURL(v string) *OauthProviderUpsertOne {
return u.Update(func(s *OauthProviderUpsert) {
s.SetRedirectURL(v)
})
}
// UpdateRedirectURL sets the "redirect_url" field to the value that was provided on create.
func (u *OauthProviderUpsertOne) UpdateRedirectURL() *OauthProviderUpsertOne {
return u.Update(func(s *OauthProviderUpsert) {
s.UpdateRedirectURL()
})
}
// SetScopes sets the "scopes" field.
func (u *OauthProviderUpsertOne) SetScopes(v string) *OauthProviderUpsertOne {
return u.Update(func(s *OauthProviderUpsert) {
s.SetScopes(v)
})
}
// UpdateScopes sets the "scopes" field to the value that was provided on create.
func (u *OauthProviderUpsertOne) UpdateScopes() *OauthProviderUpsertOne {
return u.Update(func(s *OauthProviderUpsert) {
s.UpdateScopes()
})
}
// SetAuthURL sets the "auth_url" field.
func (u *OauthProviderUpsertOne) SetAuthURL(v string) *OauthProviderUpsertOne {
return u.Update(func(s *OauthProviderUpsert) {
s.SetAuthURL(v)
})
}
// UpdateAuthURL sets the "auth_url" field to the value that was provided on create.
func (u *OauthProviderUpsertOne) UpdateAuthURL() *OauthProviderUpsertOne {
return u.Update(func(s *OauthProviderUpsert) {
s.UpdateAuthURL()
})
}
// SetTokenURL sets the "token_url" field.
func (u *OauthProviderUpsertOne) SetTokenURL(v string) *OauthProviderUpsertOne {
return u.Update(func(s *OauthProviderUpsert) {
s.SetTokenURL(v)
})
}
// UpdateTokenURL sets the "token_url" field to the value that was provided on create.
func (u *OauthProviderUpsertOne) UpdateTokenURL() *OauthProviderUpsertOne {
return u.Update(func(s *OauthProviderUpsert) {
s.UpdateTokenURL()
})
}
// SetInfoURL sets the "info_url" field.
func (u *OauthProviderUpsertOne) SetInfoURL(v string) *OauthProviderUpsertOne {
return u.Update(func(s *OauthProviderUpsert) {
s.SetInfoURL(v)
})
}
// UpdateInfoURL sets the "info_url" field to the value that was provided on create.
func (u *OauthProviderUpsertOne) UpdateInfoURL() *OauthProviderUpsertOne {
return u.Update(func(s *OauthProviderUpsert) {
s.UpdateInfoURL()
})
}
// SetDescription sets the "description" field.
func (u *OauthProviderUpsertOne) SetDescription(v string) *OauthProviderUpsertOne {
return u.Update(func(s *OauthProviderUpsert) {
s.SetDescription(v)
})
}
// UpdateDescription sets the "description" field to the value that was provided on create.
func (u *OauthProviderUpsertOne) UpdateDescription() *OauthProviderUpsertOne {
return u.Update(func(s *OauthProviderUpsert) {
s.UpdateDescription()
})
}
// SetSystem sets the "system" field.
func (u *OauthProviderUpsertOne) SetSystem(v bool) *OauthProviderUpsertOne {
return u.Update(func(s *OauthProviderUpsert) {
s.SetSystem(v)
})
}
// UpdateSystem sets the "system" field to the value that was provided on create.
func (u *OauthProviderUpsertOne) UpdateSystem() *OauthProviderUpsertOne {
return u.Update(func(s *OauthProviderUpsert) {
s.UpdateSystem()
})
}
// SetInit sets the "init" field.
func (u *OauthProviderUpsertOne) SetInit(v bool) *OauthProviderUpsertOne {
return u.Update(func(s *OauthProviderUpsert) {
s.SetInit(v)
})
}
// UpdateInit sets the "init" field to the value that was provided on create.
func (u *OauthProviderUpsertOne) UpdateInit() *OauthProviderUpsertOne {
return u.Update(func(s *OauthProviderUpsert) {
s.UpdateInit()
})
}
// Exec executes the query.
func (u *OauthProviderUpsertOne) Exec(ctx context.Context) error {
if len(u.create.conflict) == 0 {
return errors.New("ent: missing options for OauthProviderCreate.OnConflict")
}
return u.create.Exec(ctx)
}
// ExecX is like Exec, but panics if an error occurs.
func (u *OauthProviderUpsertOne) ExecX(ctx context.Context) {
if err := u.create.Exec(ctx); err != nil {
panic(err)
}
}
// Exec executes the UPSERT query and returns the inserted/updated ID.
func (u *OauthProviderUpsertOne) ID(ctx context.Context) (id int64, err error) {
node, err := u.create.Save(ctx)
if err != nil {
return id, err
}
return node.ID, nil
}
// IDX is like ID, but panics if an error occurs.
func (u *OauthProviderUpsertOne) IDX(ctx context.Context) int64 {
id, err := u.ID(ctx)
if err != nil {
panic(err)
}
return id
}
// OauthProviderCreateBulk is the builder for creating many OauthProvider entities in bulk.
type OauthProviderCreateBulk struct {
config
builders []*OauthProviderCreate
conflict []sql.ConflictOption
}
// Save creates the OauthProvider entities in the database.
func (opcb *OauthProviderCreateBulk) Save(ctx context.Context) ([]*OauthProvider, error) {
specs := make([]*sqlgraph.CreateSpec, len(opcb.builders))
nodes := make([]*OauthProvider, len(opcb.builders))
mutators := make([]Mutator, len(opcb.builders))
for i := range opcb.builders {
func(i int, root context.Context) {
builder := opcb.builders[i]
builder.defaults()
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
mutation, ok := m.(*OauthProviderMutation)
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, opcb.builders[i+1].mutation)
} else {
spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
spec.OnConflict = opcb.conflict
// Invoke the actual operation on the latest mutation in the chain.
if err = sqlgraph.BatchCreate(ctx, opcb.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
if specs[i].ID.Value != nil && nodes[i].ID == 0 {
id := specs[i].ID.Value.(int64)
nodes[i].ID = int64(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, opcb.builders[0].mutation); err != nil {
return nil, err
}
}
return nodes, nil
}
// SaveX is like Save, but panics if an error occurs.
func (opcb *OauthProviderCreateBulk) SaveX(ctx context.Context) []*OauthProvider {
v, err := opcb.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (opcb *OauthProviderCreateBulk) Exec(ctx context.Context) error {
_, err := opcb.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (opcb *OauthProviderCreateBulk) ExecX(ctx context.Context) {
if err := opcb.Exec(ctx); err != nil {
panic(err)
}
}
// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
// of the `INSERT` statement. For example:
//
// client.OauthProvider.CreateBulk(builders...).
// OnConflict(
// // Update the row with the new values
// // the was proposed for insertion.
// sql.ResolveWithNewValues(),
// ).
// // Override some of the fields with custom
// // update values.
// Update(func(u *ent.OauthProviderUpsert) {
// SetCreatedAt(v+v).
// }).
// Exec(ctx)
func (opcb *OauthProviderCreateBulk) OnConflict(opts ...sql.ConflictOption) *OauthProviderUpsertBulk {
opcb.conflict = opts
return &OauthProviderUpsertBulk{
create: opcb,
}
}
// OnConflictColumns calls `OnConflict` and configures the columns
// as conflict target. Using this option is equivalent to using:
//
// client.OauthProvider.Create().
// OnConflict(sql.ConflictColumns(columns...)).
// Exec(ctx)
func (opcb *OauthProviderCreateBulk) OnConflictColumns(columns ...string) *OauthProviderUpsertBulk {
opcb.conflict = append(opcb.conflict, sql.ConflictColumns(columns...))
return &OauthProviderUpsertBulk{
create: opcb,
}
}
// OauthProviderUpsertBulk is the builder for "upsert"-ing
// a bulk of OauthProvider nodes.
type OauthProviderUpsertBulk struct {
create *OauthProviderCreateBulk
}
// UpdateNewValues updates the mutable fields using the new values that
// were set on create. Using this option is equivalent to using:
//
// client.OauthProvider.Create().
// OnConflict(
// sql.ResolveWithNewValues(),
// sql.ResolveWith(func(u *sql.UpdateSet) {
// u.SetIgnore(oauthprovider.FieldID)
// }),
// ).
// Exec(ctx)
func (u *OauthProviderUpsertBulk) UpdateNewValues() *OauthProviderUpsertBulk {
u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
for _, b := range u.create.builders {
if _, exists := b.mutation.ID(); exists {
s.SetIgnore(oauthprovider.FieldID)
}
if _, exists := b.mutation.CreatedAt(); exists {
s.SetIgnore(oauthprovider.FieldCreatedAt)
}
}
}))
return u
}
// Ignore sets each column to itself in case of conflict.
// Using this option is equivalent to using:
//
// client.OauthProvider.Create().
// OnConflict(sql.ResolveWithIgnore()).
// Exec(ctx)
func (u *OauthProviderUpsertBulk) Ignore() *OauthProviderUpsertBulk {
u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
return u
}
// DoNothing configures the conflict_action to `DO NOTHING`.
// Supported only by SQLite and PostgreSQL.
func (u *OauthProviderUpsertBulk) DoNothing() *OauthProviderUpsertBulk {
u.create.conflict = append(u.create.conflict, sql.DoNothing())
return u
}
// Update allows overriding fields `UPDATE` values. See the OauthProviderCreateBulk.OnConflict
// documentation for more info.
func (u *OauthProviderUpsertBulk) Update(set func(*OauthProviderUpsert)) *OauthProviderUpsertBulk {
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
set(&OauthProviderUpsert{UpdateSet: update})
}))
return u
}
// SetUpdatedAt sets the "updated_at" field.
func (u *OauthProviderUpsertBulk) SetUpdatedAt(v time.Time) *OauthProviderUpsertBulk {
return u.Update(func(s *OauthProviderUpsert) {
s.SetUpdatedAt(v)
})
}
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
func (u *OauthProviderUpsertBulk) UpdateUpdatedAt() *OauthProviderUpsertBulk {
return u.Update(func(s *OauthProviderUpsert) {
s.UpdateUpdatedAt()
})
}
// SetDeletedAt sets the "deleted_at" field.
func (u *OauthProviderUpsertBulk) SetDeletedAt(v time.Time) *OauthProviderUpsertBulk {
return u.Update(func(s *OauthProviderUpsert) {
s.SetDeletedAt(v)
})
}
// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
func (u *OauthProviderUpsertBulk) UpdateDeletedAt() *OauthProviderUpsertBulk {
return u.Update(func(s *OauthProviderUpsert) {
s.UpdateDeletedAt()
})
}
// ClearDeletedAt clears the value of the "deleted_at" field.
func (u *OauthProviderUpsertBulk) ClearDeletedAt() *OauthProviderUpsertBulk {
return u.Update(func(s *OauthProviderUpsert) {
s.ClearDeletedAt()
})
}
// SetName sets the "name" field.
func (u *OauthProviderUpsertBulk) SetName(v string) *OauthProviderUpsertBulk {
return u.Update(func(s *OauthProviderUpsert) {
s.SetName(v)
})
}
// UpdateName sets the "name" field to the value that was provided on create.
func (u *OauthProviderUpsertBulk) UpdateName() *OauthProviderUpsertBulk {
return u.Update(func(s *OauthProviderUpsert) {
s.UpdateName()
})
}
// SetClientID sets the "client_id" field.
func (u *OauthProviderUpsertBulk) SetClientID(v string) *OauthProviderUpsertBulk {
return u.Update(func(s *OauthProviderUpsert) {
s.SetClientID(v)
})
}
// UpdateClientID sets the "client_id" field to the value that was provided on create.
func (u *OauthProviderUpsertBulk) UpdateClientID() *OauthProviderUpsertBulk {
return u.Update(func(s *OauthProviderUpsert) {
s.UpdateClientID()
})
}
// SetClientSecret sets the "client_secret" field.
func (u *OauthProviderUpsertBulk) SetClientSecret(v string) *OauthProviderUpsertBulk {
return u.Update(func(s *OauthProviderUpsert) {
s.SetClientSecret(v)
})
}
// UpdateClientSecret sets the "client_secret" field to the value that was provided on create.
func (u *OauthProviderUpsertBulk) UpdateClientSecret() *OauthProviderUpsertBulk {
return u.Update(func(s *OauthProviderUpsert) {
s.UpdateClientSecret()
})
}
// SetRedirectURL sets the "redirect_url" field.
func (u *OauthProviderUpsertBulk) SetRedirectURL(v string) *OauthProviderUpsertBulk {
return u.Update(func(s *OauthProviderUpsert) {
s.SetRedirectURL(v)
})
}
// UpdateRedirectURL sets the "redirect_url" field to the value that was provided on create.
func (u *OauthProviderUpsertBulk) UpdateRedirectURL() *OauthProviderUpsertBulk {
return u.Update(func(s *OauthProviderUpsert) {
s.UpdateRedirectURL()
})
}
// SetScopes sets the "scopes" field.
func (u *OauthProviderUpsertBulk) SetScopes(v string) *OauthProviderUpsertBulk {
return u.Update(func(s *OauthProviderUpsert) {
s.SetScopes(v)
})
}
// UpdateScopes sets the "scopes" field to the value that was provided on create.
func (u *OauthProviderUpsertBulk) UpdateScopes() *OauthProviderUpsertBulk {
return u.Update(func(s *OauthProviderUpsert) {
s.UpdateScopes()
})
}
// SetAuthURL sets the "auth_url" field.
func (u *OauthProviderUpsertBulk) SetAuthURL(v string) *OauthProviderUpsertBulk {
return u.Update(func(s *OauthProviderUpsert) {
s.SetAuthURL(v)
})
}
// UpdateAuthURL sets the "auth_url" field to the value that was provided on create.
func (u *OauthProviderUpsertBulk) UpdateAuthURL() *OauthProviderUpsertBulk {
return u.Update(func(s *OauthProviderUpsert) {
s.UpdateAuthURL()
})
}
// SetTokenURL sets the "token_url" field.
func (u *OauthProviderUpsertBulk) SetTokenURL(v string) *OauthProviderUpsertBulk {
return u.Update(func(s *OauthProviderUpsert) {
s.SetTokenURL(v)
})
}
// UpdateTokenURL sets the "token_url" field to the value that was provided on create.
func (u *OauthProviderUpsertBulk) UpdateTokenURL() *OauthProviderUpsertBulk {
return u.Update(func(s *OauthProviderUpsert) {
s.UpdateTokenURL()
})
}
// SetInfoURL sets the "info_url" field.
func (u *OauthProviderUpsertBulk) SetInfoURL(v string) *OauthProviderUpsertBulk {
return u.Update(func(s *OauthProviderUpsert) {
s.SetInfoURL(v)
})
}
// UpdateInfoURL sets the "info_url" field to the value that was provided on create.
func (u *OauthProviderUpsertBulk) UpdateInfoURL() *OauthProviderUpsertBulk {
return u.Update(func(s *OauthProviderUpsert) {
s.UpdateInfoURL()
})
}
// SetDescription sets the "description" field.
func (u *OauthProviderUpsertBulk) SetDescription(v string) *OauthProviderUpsertBulk {
return u.Update(func(s *OauthProviderUpsert) {
s.SetDescription(v)
})
}
// UpdateDescription sets the "description" field to the value that was provided on create.
func (u *OauthProviderUpsertBulk) UpdateDescription() *OauthProviderUpsertBulk {
return u.Update(func(s *OauthProviderUpsert) {
s.UpdateDescription()
})
}
// SetSystem sets the "system" field.
func (u *OauthProviderUpsertBulk) SetSystem(v bool) *OauthProviderUpsertBulk {
return u.Update(func(s *OauthProviderUpsert) {
s.SetSystem(v)
})
}
// UpdateSystem sets the "system" field to the value that was provided on create.
func (u *OauthProviderUpsertBulk) UpdateSystem() *OauthProviderUpsertBulk {
return u.Update(func(s *OauthProviderUpsert) {
s.UpdateSystem()
})
}
// SetInit sets the "init" field.
func (u *OauthProviderUpsertBulk) SetInit(v bool) *OauthProviderUpsertBulk {
return u.Update(func(s *OauthProviderUpsert) {
s.SetInit(v)
})
}
// UpdateInit sets the "init" field to the value that was provided on create.
func (u *OauthProviderUpsertBulk) UpdateInit() *OauthProviderUpsertBulk {
return u.Update(func(s *OauthProviderUpsert) {
s.UpdateInit()
})
}
// Exec executes the query.
func (u *OauthProviderUpsertBulk) Exec(ctx context.Context) error {
for i, b := range u.create.builders {
if len(b.conflict) != 0 {
return fmt.Errorf("ent: OnConflict was set for builder %d. Set it on the OauthProviderCreateBulk instead", i)
}
}
if len(u.create.conflict) == 0 {
return errors.New("ent: missing options for OauthProviderCreateBulk.OnConflict")
}
return u.create.Exec(ctx)
}
// ExecX is like Exec, but panics if an error occurs.
func (u *OauthProviderUpsertBulk) ExecX(ctx context.Context) {
if err := u.create.Exec(ctx); err != nil {
panic(err)
}
}