|
|
|
|
// 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/password"
|
|
|
|
|
"github.com/dexidp/dex/storage/ent/db/predicate"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// PasswordUpdate is the builder for updating Password entities.
|
|
|
|
|
type PasswordUpdate struct {
|
|
|
|
|
config
|
|
|
|
|
hooks []Hook
|
|
|
|
|
mutation *PasswordMutation
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Where appends a list predicates to the PasswordUpdate builder.
|
|
|
|
|
func (_u *PasswordUpdate) Where(ps ...predicate.Password) *PasswordUpdate {
|
|
|
|
|
_u.mutation.Where(ps...)
|
|
|
|
|
return _u
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SetEmail sets the "email" field.
|
|
|
|
|
func (_u *PasswordUpdate) SetEmail(v string) *PasswordUpdate {
|
|
|
|
|
_u.mutation.SetEmail(v)
|
|
|
|
|
return _u
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SetNillableEmail sets the "email" field if the given value is not nil.
|
|
|
|
|
func (_u *PasswordUpdate) SetNillableEmail(v *string) *PasswordUpdate {
|
|
|
|
|
if v != nil {
|
|
|
|
|
_u.SetEmail(*v)
|
|
|
|
|
}
|
|
|
|
|
return _u
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SetHash sets the "hash" field.
|
|
|
|
|
func (_u *PasswordUpdate) SetHash(v []byte) *PasswordUpdate {
|
|
|
|
|
_u.mutation.SetHash(v)
|
|
|
|
|
return _u
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SetUsername sets the "username" field.
|
|
|
|
|
func (_u *PasswordUpdate) SetUsername(v string) *PasswordUpdate {
|
|
|
|
|
_u.mutation.SetUsername(v)
|
|
|
|
|
return _u
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SetNillableUsername sets the "username" field if the given value is not nil.
|
|
|
|
|
func (_u *PasswordUpdate) SetNillableUsername(v *string) *PasswordUpdate {
|
|
|
|
|
if v != nil {
|
|
|
|
|
_u.SetUsername(*v)
|
|
|
|
|
}
|
|
|
|
|
return _u
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SetName sets the "name" field.
|
|
|
|
|
func (_u *PasswordUpdate) SetName(v string) *PasswordUpdate {
|
|
|
|
|
_u.mutation.SetName(v)
|
|
|
|
|
return _u
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SetNillableName sets the "name" field if the given value is not nil.
|
|
|
|
|
func (_u *PasswordUpdate) SetNillableName(v *string) *PasswordUpdate {
|
|
|
|
|
if v != nil {
|
|
|
|
|
_u.SetName(*v)
|
|
|
|
|
}
|
|
|
|
|
return _u
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SetPreferredUsername sets the "preferred_username" field.
|
|
|
|
|
func (_u *PasswordUpdate) SetPreferredUsername(v string) *PasswordUpdate {
|
|
|
|
|
_u.mutation.SetPreferredUsername(v)
|
|
|
|
|
return _u
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SetNillablePreferredUsername sets the "preferred_username" field if the given value is not nil.
|
|
|
|
|
func (_u *PasswordUpdate) SetNillablePreferredUsername(v *string) *PasswordUpdate {
|
|
|
|
|
if v != nil {
|
|
|
|
|
_u.SetPreferredUsername(*v)
|
|
|
|
|
}
|
|
|
|
|
return _u
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SetEmailVerified sets the "email_verified" field.
|
|
|
|
|
func (_u *PasswordUpdate) SetEmailVerified(v bool) *PasswordUpdate {
|
|
|
|
|
_u.mutation.SetEmailVerified(v)
|
|
|
|
|
return _u
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SetNillableEmailVerified sets the "email_verified" field if the given value is not nil.
|
|
|
|
|
func (_u *PasswordUpdate) SetNillableEmailVerified(v *bool) *PasswordUpdate {
|
|
|
|
|
if v != nil {
|
|
|
|
|
_u.SetEmailVerified(*v)
|
|
|
|
|
}
|
|
|
|
|
return _u
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ClearEmailVerified clears the value of the "email_verified" field.
|
|
|
|
|
func (_u *PasswordUpdate) ClearEmailVerified() *PasswordUpdate {
|
|
|
|
|
_u.mutation.ClearEmailVerified()
|
|
|
|
|
return _u
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SetUserID sets the "user_id" field.
|
|
|
|
|
func (_u *PasswordUpdate) SetUserID(v string) *PasswordUpdate {
|
|
|
|
|
_u.mutation.SetUserID(v)
|
|
|
|
|
return _u
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SetNillableUserID sets the "user_id" field if the given value is not nil.
|
|
|
|
|
func (_u *PasswordUpdate) SetNillableUserID(v *string) *PasswordUpdate {
|
|
|
|
|
if v != nil {
|
|
|
|
|
_u.SetUserID(*v)
|
|
|
|
|
}
|
|
|
|
|
return _u
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SetGroups sets the "groups" field.
|
|
|
|
|
func (_u *PasswordUpdate) SetGroups(v []string) *PasswordUpdate {
|
|
|
|
|
_u.mutation.SetGroups(v)
|
|
|
|
|
return _u
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// AppendGroups appends value to the "groups" field.
|
|
|
|
|
func (_u *PasswordUpdate) AppendGroups(v []string) *PasswordUpdate {
|
|
|
|
|
_u.mutation.AppendGroups(v)
|
|
|
|
|
return _u
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ClearGroups clears the value of the "groups" field.
|
|
|
|
|
func (_u *PasswordUpdate) ClearGroups() *PasswordUpdate {
|
|
|
|
|
_u.mutation.ClearGroups()
|
|
|
|
|
return _u
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Mutation returns the PasswordMutation object of the builder.
|
|
|
|
|
func (_u *PasswordUpdate) Mutation() *PasswordMutation {
|
|
|
|
|
return _u.mutation
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Save executes the query and returns the number of nodes affected by the update operation.
|
|
|
|
|
func (_u *PasswordUpdate) 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 *PasswordUpdate) SaveX(ctx context.Context) int {
|
|
|
|
|
affected, err := _u.Save(ctx)
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
return affected
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Exec executes the query.
|
|
|
|
|
func (_u *PasswordUpdate) Exec(ctx context.Context) error {
|
|
|
|
|
_, err := _u.Save(ctx)
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
|
|
|
func (_u *PasswordUpdate) 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 *PasswordUpdate) check() error {
|
|
|
|
|
if v, ok := _u.mutation.Email(); ok {
|
|
|
|
|
if err := password.EmailValidator(v); err != nil {
|
|
|
|
|
return &ValidationError{Name: "email", err: fmt.Errorf(`db: validator failed for field "Password.email": %w`, err)}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if v, ok := _u.mutation.Username(); ok {
|
|
|
|
|
if err := password.UsernameValidator(v); err != nil {
|
|
|
|
|
return &ValidationError{Name: "username", err: fmt.Errorf(`db: validator failed for field "Password.username": %w`, err)}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if v, ok := _u.mutation.UserID(); ok {
|
|
|
|
|
if err := password.UserIDValidator(v); err != nil {
|
|
|
|
|
return &ValidationError{Name: "user_id", err: fmt.Errorf(`db: validator failed for field "Password.user_id": %w`, err)}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (_u *PasswordUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
|
|
|
|
if err := _u.check(); err != nil {
|
|
|
|
|
return _node, err
|
|
|
|
|
}
|
|
|
|
|
_spec := sqlgraph.NewUpdateSpec(password.Table, password.Columns, sqlgraph.NewFieldSpec(password.FieldID, field.TypeInt))
|
|
|
|
|
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.Email(); ok {
|
|
|
|
|
_spec.SetField(password.FieldEmail, field.TypeString, value)
|
|
|
|
|
}
|
|
|
|
|
if value, ok := _u.mutation.Hash(); ok {
|
|
|
|
|
_spec.SetField(password.FieldHash, field.TypeBytes, value)
|
|
|
|
|
}
|
|
|
|
|
if value, ok := _u.mutation.Username(); ok {
|
|
|
|
|
_spec.SetField(password.FieldUsername, field.TypeString, value)
|
|
|
|
|
}
|
|
|
|
|
if value, ok := _u.mutation.Name(); ok {
|
|
|
|
|
_spec.SetField(password.FieldName, field.TypeString, value)
|
|
|
|
|
}
|
|
|
|
|
if value, ok := _u.mutation.PreferredUsername(); ok {
|
|
|
|
|
_spec.SetField(password.FieldPreferredUsername, field.TypeString, value)
|
|
|
|
|
}
|
|
|
|
|
if value, ok := _u.mutation.EmailVerified(); ok {
|
|
|
|
|
_spec.SetField(password.FieldEmailVerified, field.TypeBool, value)
|
|
|
|
|
}
|
|
|
|
|
if _u.mutation.EmailVerifiedCleared() {
|
|
|
|
|
_spec.ClearField(password.FieldEmailVerified, field.TypeBool)
|
|
|
|
|
}
|
|
|
|
|
if value, ok := _u.mutation.UserID(); ok {
|
|
|
|
|
_spec.SetField(password.FieldUserID, field.TypeString, value)
|
|
|
|
|
}
|
|
|
|
|
if value, ok := _u.mutation.Groups(); ok {
|
|
|
|
|
_spec.SetField(password.FieldGroups, field.TypeJSON, value)
|
|
|
|
|
}
|
|
|
|
|
if value, ok := _u.mutation.AppendedGroups(); ok {
|
|
|
|
|
_spec.AddModifier(func(u *sql.UpdateBuilder) {
|
|
|
|
|
sqljson.Append(u, password.FieldGroups, value)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
if _u.mutation.GroupsCleared() {
|
|
|
|
|
_spec.ClearField(password.FieldGroups, field.TypeJSON)
|
|
|
|
|
}
|
|
|
|
|
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
|
|
|
|
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
|
|
|
|
err = &NotFoundError{password.Label}
|
|
|
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
|
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
|
|
|
}
|
|
|
|
|
return 0, err
|
|
|
|
|
}
|
|
|
|
|
_u.mutation.done = true
|
|
|
|
|
return _node, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// PasswordUpdateOne is the builder for updating a single Password entity.
|
|
|
|
|
type PasswordUpdateOne struct {
|
|
|
|
|
config
|
|
|
|
|
fields []string
|
|
|
|
|
hooks []Hook
|
|
|
|
|
mutation *PasswordMutation
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SetEmail sets the "email" field.
|
|
|
|
|
func (_u *PasswordUpdateOne) SetEmail(v string) *PasswordUpdateOne {
|
|
|
|
|
_u.mutation.SetEmail(v)
|
|
|
|
|
return _u
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SetNillableEmail sets the "email" field if the given value is not nil.
|
|
|
|
|
func (_u *PasswordUpdateOne) SetNillableEmail(v *string) *PasswordUpdateOne {
|
|
|
|
|
if v != nil {
|
|
|
|
|
_u.SetEmail(*v)
|
|
|
|
|
}
|
|
|
|
|
return _u
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SetHash sets the "hash" field.
|
|
|
|
|
func (_u *PasswordUpdateOne) SetHash(v []byte) *PasswordUpdateOne {
|
|
|
|
|
_u.mutation.SetHash(v)
|
|
|
|
|
return _u
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SetUsername sets the "username" field.
|
|
|
|
|
func (_u *PasswordUpdateOne) SetUsername(v string) *PasswordUpdateOne {
|
|
|
|
|
_u.mutation.SetUsername(v)
|
|
|
|
|
return _u
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SetNillableUsername sets the "username" field if the given value is not nil.
|
|
|
|
|
func (_u *PasswordUpdateOne) SetNillableUsername(v *string) *PasswordUpdateOne {
|
|
|
|
|
if v != nil {
|
|
|
|
|
_u.SetUsername(*v)
|
|
|
|
|
}
|
|
|
|
|
return _u
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SetName sets the "name" field.
|
|
|
|
|
func (_u *PasswordUpdateOne) SetName(v string) *PasswordUpdateOne {
|
|
|
|
|
_u.mutation.SetName(v)
|
|
|
|
|
return _u
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SetNillableName sets the "name" field if the given value is not nil.
|
|
|
|
|
func (_u *PasswordUpdateOne) SetNillableName(v *string) *PasswordUpdateOne {
|
|
|
|
|
if v != nil {
|
|
|
|
|
_u.SetName(*v)
|
|
|
|
|
}
|
|
|
|
|
return _u
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SetPreferredUsername sets the "preferred_username" field.
|
|
|
|
|
func (_u *PasswordUpdateOne) SetPreferredUsername(v string) *PasswordUpdateOne {
|
|
|
|
|
_u.mutation.SetPreferredUsername(v)
|
|
|
|
|
return _u
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SetNillablePreferredUsername sets the "preferred_username" field if the given value is not nil.
|
|
|
|
|
func (_u *PasswordUpdateOne) SetNillablePreferredUsername(v *string) *PasswordUpdateOne {
|
|
|
|
|
if v != nil {
|
|
|
|
|
_u.SetPreferredUsername(*v)
|
|
|
|
|
}
|
|
|
|
|
return _u
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SetEmailVerified sets the "email_verified" field.
|
|
|
|
|
func (_u *PasswordUpdateOne) SetEmailVerified(v bool) *PasswordUpdateOne {
|
|
|
|
|
_u.mutation.SetEmailVerified(v)
|
|
|
|
|
return _u
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SetNillableEmailVerified sets the "email_verified" field if the given value is not nil.
|
|
|
|
|
func (_u *PasswordUpdateOne) SetNillableEmailVerified(v *bool) *PasswordUpdateOne {
|
|
|
|
|
if v != nil {
|
|
|
|
|
_u.SetEmailVerified(*v)
|
|
|
|
|
}
|
|
|
|
|
return _u
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ClearEmailVerified clears the value of the "email_verified" field.
|
|
|
|
|
func (_u *PasswordUpdateOne) ClearEmailVerified() *PasswordUpdateOne {
|
|
|
|
|
_u.mutation.ClearEmailVerified()
|
|
|
|
|
return _u
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SetUserID sets the "user_id" field.
|
|
|
|
|
func (_u *PasswordUpdateOne) SetUserID(v string) *PasswordUpdateOne {
|
|
|
|
|
_u.mutation.SetUserID(v)
|
|
|
|
|
return _u
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SetNillableUserID sets the "user_id" field if the given value is not nil.
|
|
|
|
|
func (_u *PasswordUpdateOne) SetNillableUserID(v *string) *PasswordUpdateOne {
|
|
|
|
|
if v != nil {
|
|
|
|
|
_u.SetUserID(*v)
|
|
|
|
|
}
|
|
|
|
|
return _u
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SetGroups sets the "groups" field.
|
|
|
|
|
func (_u *PasswordUpdateOne) SetGroups(v []string) *PasswordUpdateOne {
|
|
|
|
|
_u.mutation.SetGroups(v)
|
|
|
|
|
return _u
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// AppendGroups appends value to the "groups" field.
|
|
|
|
|
func (_u *PasswordUpdateOne) AppendGroups(v []string) *PasswordUpdateOne {
|
|
|
|
|
_u.mutation.AppendGroups(v)
|
|
|
|
|
return _u
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ClearGroups clears the value of the "groups" field.
|
|
|
|
|
func (_u *PasswordUpdateOne) ClearGroups() *PasswordUpdateOne {
|
|
|
|
|
_u.mutation.ClearGroups()
|
|
|
|
|
return _u
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Mutation returns the PasswordMutation object of the builder.
|
|
|
|
|
func (_u *PasswordUpdateOne) Mutation() *PasswordMutation {
|
|
|
|
|
return _u.mutation
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Where appends a list predicates to the PasswordUpdate builder.
|
|
|
|
|
func (_u *PasswordUpdateOne) Where(ps ...predicate.Password) *PasswordUpdateOne {
|
|
|
|
|
_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 *PasswordUpdateOne) Select(field string, fields ...string) *PasswordUpdateOne {
|
|
|
|
|
_u.fields = append([]string{field}, fields...)
|
|
|
|
|
return _u
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Save executes the query and returns the updated Password entity.
|
|
|
|
|
func (_u *PasswordUpdateOne) Save(ctx context.Context) (*Password, error) {
|
|
|
|
|
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
|
|
|
func (_u *PasswordUpdateOne) SaveX(ctx context.Context) *Password {
|
|
|
|
|
node, err := _u.Save(ctx)
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
return node
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Exec executes the query on the entity.
|
|
|
|
|
func (_u *PasswordUpdateOne) Exec(ctx context.Context) error {
|
|
|
|
|
_, err := _u.Save(ctx)
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
|
|
|
func (_u *PasswordUpdateOne) 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 *PasswordUpdateOne) check() error {
|
|
|
|
|
if v, ok := _u.mutation.Email(); ok {
|
|
|
|
|
if err := password.EmailValidator(v); err != nil {
|
|
|
|
|
return &ValidationError{Name: "email", err: fmt.Errorf(`db: validator failed for field "Password.email": %w`, err)}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if v, ok := _u.mutation.Username(); ok {
|
|
|
|
|
if err := password.UsernameValidator(v); err != nil {
|
|
|
|
|
return &ValidationError{Name: "username", err: fmt.Errorf(`db: validator failed for field "Password.username": %w`, err)}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if v, ok := _u.mutation.UserID(); ok {
|
|
|
|
|
if err := password.UserIDValidator(v); err != nil {
|
|
|
|
|
return &ValidationError{Name: "user_id", err: fmt.Errorf(`db: validator failed for field "Password.user_id": %w`, err)}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (_u *PasswordUpdateOne) sqlSave(ctx context.Context) (_node *Password, err error) {
|
|
|
|
|
if err := _u.check(); err != nil {
|
|
|
|
|
return _node, err
|
|
|
|
|
}
|
|
|
|
|
_spec := sqlgraph.NewUpdateSpec(password.Table, password.Columns, sqlgraph.NewFieldSpec(password.FieldID, field.TypeInt))
|
|
|
|
|
id, ok := _u.mutation.ID()
|
|
|
|
|
if !ok {
|
|
|
|
|
return nil, &ValidationError{Name: "id", err: errors.New(`db: missing "Password.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, password.FieldID)
|
|
|
|
|
for _, f := range fields {
|
|
|
|
|
if !password.ValidColumn(f) {
|
|
|
|
|
return nil, &ValidationError{Name: f, err: fmt.Errorf("db: invalid field %q for query", f)}
|
|
|
|
|
}
|
|
|
|
|
if f != password.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.Email(); ok {
|
|
|
|
|
_spec.SetField(password.FieldEmail, field.TypeString, value)
|
|
|
|
|
}
|
|
|
|
|
if value, ok := _u.mutation.Hash(); ok {
|
|
|
|
|
_spec.SetField(password.FieldHash, field.TypeBytes, value)
|
|
|
|
|
}
|
|
|
|
|
if value, ok := _u.mutation.Username(); ok {
|
|
|
|
|
_spec.SetField(password.FieldUsername, field.TypeString, value)
|
|
|
|
|
}
|
|
|
|
|
if value, ok := _u.mutation.Name(); ok {
|
|
|
|
|
_spec.SetField(password.FieldName, field.TypeString, value)
|
|
|
|
|
}
|
|
|
|
|
if value, ok := _u.mutation.PreferredUsername(); ok {
|
|
|
|
|
_spec.SetField(password.FieldPreferredUsername, field.TypeString, value)
|
|
|
|
|
}
|
|
|
|
|
if value, ok := _u.mutation.EmailVerified(); ok {
|
|
|
|
|
_spec.SetField(password.FieldEmailVerified, field.TypeBool, value)
|
|
|
|
|
}
|
|
|
|
|
if _u.mutation.EmailVerifiedCleared() {
|
|
|
|
|
_spec.ClearField(password.FieldEmailVerified, field.TypeBool)
|
|
|
|
|
}
|
|
|
|
|
if value, ok := _u.mutation.UserID(); ok {
|
|
|
|
|
_spec.SetField(password.FieldUserID, field.TypeString, value)
|
|
|
|
|
}
|
|
|
|
|
if value, ok := _u.mutation.Groups(); ok {
|
|
|
|
|
_spec.SetField(password.FieldGroups, field.TypeJSON, value)
|
|
|
|
|
}
|
|
|
|
|
if value, ok := _u.mutation.AppendedGroups(); ok {
|
|
|
|
|
_spec.AddModifier(func(u *sql.UpdateBuilder) {
|
|
|
|
|
sqljson.Append(u, password.FieldGroups, value)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
if _u.mutation.GroupsCleared() {
|
|
|
|
|
_spec.ClearField(password.FieldGroups, field.TypeJSON)
|
|
|
|
|
}
|
|
|
|
|
_node = &Password{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{password.Label}
|
|
|
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
|
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
|
|
|
}
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
_u.mutation.done = true
|
|
|
|
|
return _node, nil
|
|
|
|
|
}
|