mirror of
https://github.com/ent/ent.git
synced 2026-05-24 09:31:56 +03:00
* examples: ensure tests is stable * entc/gen/template: remove receiver conflict handling logic * examples: codegen * entc/integration: codegen
1570 lines
43 KiB
Go
1570 lines
43 KiB
Go
// Copyright 2019-present Facebook Inc. All rights reserved.
|
|
// This source code is licensed under the Apache 2.0 license found
|
|
// in the LICENSE file in the root directory of this source tree.
|
|
|
|
// Code generated by ent, DO NOT EDIT.
|
|
|
|
package entv2
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"time"
|
|
|
|
"entgo.io/ent/dialect/sql"
|
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
|
"entgo.io/ent/dialect/sql/sqljson"
|
|
"entgo.io/ent/entc/integration/migrate/entv2/car"
|
|
"entgo.io/ent/entc/integration/migrate/entv2/pet"
|
|
"entgo.io/ent/entc/integration/migrate/entv2/predicate"
|
|
"entgo.io/ent/entc/integration/migrate/entv2/user"
|
|
"entgo.io/ent/schema/field"
|
|
)
|
|
|
|
// UserUpdate is the builder for updating User entities.
|
|
type UserUpdate struct {
|
|
config
|
|
hooks []Hook
|
|
mutation *UserMutation
|
|
}
|
|
|
|
// Where appends a list predicates to the UserUpdate builder.
|
|
func (_u *UserUpdate) Where(ps ...predicate.User) *UserUpdate {
|
|
_u.mutation.Where(ps...)
|
|
return _u
|
|
}
|
|
|
|
// SetMixedString sets the "mixed_string" field.
|
|
func (_u *UserUpdate) SetMixedString(v string) *UserUpdate {
|
|
_u.mutation.SetMixedString(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableMixedString sets the "mixed_string" field if the given value is not nil.
|
|
func (_u *UserUpdate) SetNillableMixedString(v *string) *UserUpdate {
|
|
if v != nil {
|
|
_u.SetMixedString(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetMixedEnum sets the "mixed_enum" field.
|
|
func (_u *UserUpdate) SetMixedEnum(v user.MixedEnum) *UserUpdate {
|
|
_u.mutation.SetMixedEnum(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableMixedEnum sets the "mixed_enum" field if the given value is not nil.
|
|
func (_u *UserUpdate) SetNillableMixedEnum(v *user.MixedEnum) *UserUpdate {
|
|
if v != nil {
|
|
_u.SetMixedEnum(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetActive sets the "active" field.
|
|
func (_u *UserUpdate) SetActive(v bool) *UserUpdate {
|
|
_u.mutation.SetActive(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableActive sets the "active" field if the given value is not nil.
|
|
func (_u *UserUpdate) SetNillableActive(v *bool) *UserUpdate {
|
|
if v != nil {
|
|
_u.SetActive(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetAge sets the "age" field.
|
|
func (_u *UserUpdate) SetAge(v int) *UserUpdate {
|
|
_u.mutation.ResetAge()
|
|
_u.mutation.SetAge(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableAge sets the "age" field if the given value is not nil.
|
|
func (_u *UserUpdate) SetNillableAge(v *int) *UserUpdate {
|
|
if v != nil {
|
|
_u.SetAge(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// AddAge adds value to the "age" field.
|
|
func (_u *UserUpdate) AddAge(v int) *UserUpdate {
|
|
_u.mutation.AddAge(v)
|
|
return _u
|
|
}
|
|
|
|
// SetName sets the "name" field.
|
|
func (_u *UserUpdate) SetName(v string) *UserUpdate {
|
|
_u.mutation.SetName(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableName sets the "name" field if the given value is not nil.
|
|
func (_u *UserUpdate) SetNillableName(v *string) *UserUpdate {
|
|
if v != nil {
|
|
_u.SetName(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetDescription sets the "description" field.
|
|
func (_u *UserUpdate) SetDescription(v string) *UserUpdate {
|
|
_u.mutation.SetDescription(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableDescription sets the "description" field if the given value is not nil.
|
|
func (_u *UserUpdate) SetNillableDescription(v *string) *UserUpdate {
|
|
if v != nil {
|
|
_u.SetDescription(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearDescription clears the value of the "description" field.
|
|
func (_u *UserUpdate) ClearDescription() *UserUpdate {
|
|
_u.mutation.ClearDescription()
|
|
return _u
|
|
}
|
|
|
|
// SetNickname sets the "nickname" field.
|
|
func (_u *UserUpdate) SetNickname(v string) *UserUpdate {
|
|
_u.mutation.SetNickname(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableNickname sets the "nickname" field if the given value is not nil.
|
|
func (_u *UserUpdate) SetNillableNickname(v *string) *UserUpdate {
|
|
if v != nil {
|
|
_u.SetNickname(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetPhone sets the "phone" field.
|
|
func (_u *UserUpdate) SetPhone(v string) *UserUpdate {
|
|
_u.mutation.SetPhone(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillablePhone sets the "phone" field if the given value is not nil.
|
|
func (_u *UserUpdate) SetNillablePhone(v *string) *UserUpdate {
|
|
if v != nil {
|
|
_u.SetPhone(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetBuffer sets the "buffer" field.
|
|
func (_u *UserUpdate) SetBuffer(v []byte) *UserUpdate {
|
|
_u.mutation.SetBuffer(v)
|
|
return _u
|
|
}
|
|
|
|
// ClearBuffer clears the value of the "buffer" field.
|
|
func (_u *UserUpdate) ClearBuffer() *UserUpdate {
|
|
_u.mutation.ClearBuffer()
|
|
return _u
|
|
}
|
|
|
|
// SetTitle sets the "title" field.
|
|
func (_u *UserUpdate) SetTitle(v string) *UserUpdate {
|
|
_u.mutation.SetTitle(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableTitle sets the "title" field if the given value is not nil.
|
|
func (_u *UserUpdate) SetNillableTitle(v *string) *UserUpdate {
|
|
if v != nil {
|
|
_u.SetTitle(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetNewName sets the "new_name" field.
|
|
func (_u *UserUpdate) SetNewName(v string) *UserUpdate {
|
|
_u.mutation.SetNewName(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableNewName sets the "new_name" field if the given value is not nil.
|
|
func (_u *UserUpdate) SetNillableNewName(v *string) *UserUpdate {
|
|
if v != nil {
|
|
_u.SetNewName(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearNewName clears the value of the "new_name" field.
|
|
func (_u *UserUpdate) ClearNewName() *UserUpdate {
|
|
_u.mutation.ClearNewName()
|
|
return _u
|
|
}
|
|
|
|
// SetNewToken sets the "new_token" field.
|
|
func (_u *UserUpdate) SetNewToken(v string) *UserUpdate {
|
|
_u.mutation.SetNewToken(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableNewToken sets the "new_token" field if the given value is not nil.
|
|
func (_u *UserUpdate) SetNillableNewToken(v *string) *UserUpdate {
|
|
if v != nil {
|
|
_u.SetNewToken(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetBlob sets the "blob" field.
|
|
func (_u *UserUpdate) SetBlob(v []byte) *UserUpdate {
|
|
_u.mutation.SetBlob(v)
|
|
return _u
|
|
}
|
|
|
|
// ClearBlob clears the value of the "blob" field.
|
|
func (_u *UserUpdate) ClearBlob() *UserUpdate {
|
|
_u.mutation.ClearBlob()
|
|
return _u
|
|
}
|
|
|
|
// SetState sets the "state" field.
|
|
func (_u *UserUpdate) SetState(v user.State) *UserUpdate {
|
|
_u.mutation.SetState(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableState sets the "state" field if the given value is not nil.
|
|
func (_u *UserUpdate) SetNillableState(v *user.State) *UserUpdate {
|
|
if v != nil {
|
|
_u.SetState(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearState clears the value of the "state" field.
|
|
func (_u *UserUpdate) ClearState() *UserUpdate {
|
|
_u.mutation.ClearState()
|
|
return _u
|
|
}
|
|
|
|
// SetStatus sets the "status" field.
|
|
func (_u *UserUpdate) SetStatus(v user.Status) *UserUpdate {
|
|
_u.mutation.SetStatus(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableStatus sets the "status" field if the given value is not nil.
|
|
func (_u *UserUpdate) SetNillableStatus(v *user.Status) *UserUpdate {
|
|
if v != nil {
|
|
_u.SetStatus(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearStatus clears the value of the "status" field.
|
|
func (_u *UserUpdate) ClearStatus() *UserUpdate {
|
|
_u.mutation.ClearStatus()
|
|
return _u
|
|
}
|
|
|
|
// SetWorkplace sets the "workplace" field.
|
|
func (_u *UserUpdate) SetWorkplace(v string) *UserUpdate {
|
|
_u.mutation.SetWorkplace(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableWorkplace sets the "workplace" field if the given value is not nil.
|
|
func (_u *UserUpdate) SetNillableWorkplace(v *string) *UserUpdate {
|
|
if v != nil {
|
|
_u.SetWorkplace(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearWorkplace clears the value of the "workplace" field.
|
|
func (_u *UserUpdate) ClearWorkplace() *UserUpdate {
|
|
_u.mutation.ClearWorkplace()
|
|
return _u
|
|
}
|
|
|
|
// SetRoles sets the "roles" field.
|
|
func (_u *UserUpdate) SetRoles(v []string) *UserUpdate {
|
|
_u.mutation.SetRoles(v)
|
|
return _u
|
|
}
|
|
|
|
// AppendRoles appends value to the "roles" field.
|
|
func (_u *UserUpdate) AppendRoles(v []string) *UserUpdate {
|
|
_u.mutation.AppendRoles(v)
|
|
return _u
|
|
}
|
|
|
|
// ClearRoles clears the value of the "roles" field.
|
|
func (_u *UserUpdate) ClearRoles() *UserUpdate {
|
|
_u.mutation.ClearRoles()
|
|
return _u
|
|
}
|
|
|
|
// SetDefaultExpr sets the "default_expr" field.
|
|
func (_u *UserUpdate) SetDefaultExpr(v string) *UserUpdate {
|
|
_u.mutation.SetDefaultExpr(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableDefaultExpr sets the "default_expr" field if the given value is not nil.
|
|
func (_u *UserUpdate) SetNillableDefaultExpr(v *string) *UserUpdate {
|
|
if v != nil {
|
|
_u.SetDefaultExpr(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearDefaultExpr clears the value of the "default_expr" field.
|
|
func (_u *UserUpdate) ClearDefaultExpr() *UserUpdate {
|
|
_u.mutation.ClearDefaultExpr()
|
|
return _u
|
|
}
|
|
|
|
// SetDefaultExprs sets the "default_exprs" field.
|
|
func (_u *UserUpdate) SetDefaultExprs(v string) *UserUpdate {
|
|
_u.mutation.SetDefaultExprs(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableDefaultExprs sets the "default_exprs" field if the given value is not nil.
|
|
func (_u *UserUpdate) SetNillableDefaultExprs(v *string) *UserUpdate {
|
|
if v != nil {
|
|
_u.SetDefaultExprs(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearDefaultExprs clears the value of the "default_exprs" field.
|
|
func (_u *UserUpdate) ClearDefaultExprs() *UserUpdate {
|
|
_u.mutation.ClearDefaultExprs()
|
|
return _u
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (_u *UserUpdate) SetCreatedAt(v time.Time) *UserUpdate {
|
|
_u.mutation.SetCreatedAt(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
|
func (_u *UserUpdate) SetNillableCreatedAt(v *time.Time) *UserUpdate {
|
|
if v != nil {
|
|
_u.SetCreatedAt(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetDropOptional sets the "drop_optional" field.
|
|
func (_u *UserUpdate) SetDropOptional(v string) *UserUpdate {
|
|
_u.mutation.SetDropOptional(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableDropOptional sets the "drop_optional" field if the given value is not nil.
|
|
func (_u *UserUpdate) SetNillableDropOptional(v *string) *UserUpdate {
|
|
if v != nil {
|
|
_u.SetDropOptional(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// AddCarIDs adds the "car" edge to the Car entity by IDs.
|
|
func (_u *UserUpdate) AddCarIDs(ids ...int) *UserUpdate {
|
|
_u.mutation.AddCarIDs(ids...)
|
|
return _u
|
|
}
|
|
|
|
// AddCar adds the "car" edges to the Car entity.
|
|
func (_u *UserUpdate) AddCar(v ...*Car) *UserUpdate {
|
|
ids := make([]int, len(v))
|
|
for i := range v {
|
|
ids[i] = v[i].ID
|
|
}
|
|
return _u.AddCarIDs(ids...)
|
|
}
|
|
|
|
// SetPetsID sets the "pets" edge to the Pet entity by ID.
|
|
func (_u *UserUpdate) SetPetsID(id int) *UserUpdate {
|
|
_u.mutation.SetPetsID(id)
|
|
return _u
|
|
}
|
|
|
|
// SetNillablePetsID sets the "pets" edge to the Pet entity by ID if the given value is not nil.
|
|
func (_u *UserUpdate) SetNillablePetsID(id *int) *UserUpdate {
|
|
if id != nil {
|
|
_u = _u.SetPetsID(*id)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetPets sets the "pets" edge to the Pet entity.
|
|
func (_u *UserUpdate) SetPets(v *Pet) *UserUpdate {
|
|
return _u.SetPetsID(v.ID)
|
|
}
|
|
|
|
// AddFriendIDs adds the "friends" edge to the User entity by IDs.
|
|
func (_u *UserUpdate) AddFriendIDs(ids ...int) *UserUpdate {
|
|
_u.mutation.AddFriendIDs(ids...)
|
|
return _u
|
|
}
|
|
|
|
// AddFriends adds the "friends" edges to the User entity.
|
|
func (_u *UserUpdate) AddFriends(v ...*User) *UserUpdate {
|
|
ids := make([]int, len(v))
|
|
for i := range v {
|
|
ids[i] = v[i].ID
|
|
}
|
|
return _u.AddFriendIDs(ids...)
|
|
}
|
|
|
|
// Mutation returns the UserMutation object of the builder.
|
|
func (_u *UserUpdate) Mutation() *UserMutation {
|
|
return _u.mutation
|
|
}
|
|
|
|
// ClearCar clears all "car" edges to the Car entity.
|
|
func (_u *UserUpdate) ClearCar() *UserUpdate {
|
|
_u.mutation.ClearCar()
|
|
return _u
|
|
}
|
|
|
|
// RemoveCarIDs removes the "car" edge to Car entities by IDs.
|
|
func (_u *UserUpdate) RemoveCarIDs(ids ...int) *UserUpdate {
|
|
_u.mutation.RemoveCarIDs(ids...)
|
|
return _u
|
|
}
|
|
|
|
// RemoveCar removes "car" edges to Car entities.
|
|
func (_u *UserUpdate) RemoveCar(v ...*Car) *UserUpdate {
|
|
ids := make([]int, len(v))
|
|
for i := range v {
|
|
ids[i] = v[i].ID
|
|
}
|
|
return _u.RemoveCarIDs(ids...)
|
|
}
|
|
|
|
// ClearPets clears the "pets" edge to the Pet entity.
|
|
func (_u *UserUpdate) ClearPets() *UserUpdate {
|
|
_u.mutation.ClearPets()
|
|
return _u
|
|
}
|
|
|
|
// ClearFriends clears all "friends" edges to the User entity.
|
|
func (_u *UserUpdate) ClearFriends() *UserUpdate {
|
|
_u.mutation.ClearFriends()
|
|
return _u
|
|
}
|
|
|
|
// RemoveFriendIDs removes the "friends" edge to User entities by IDs.
|
|
func (_u *UserUpdate) RemoveFriendIDs(ids ...int) *UserUpdate {
|
|
_u.mutation.RemoveFriendIDs(ids...)
|
|
return _u
|
|
}
|
|
|
|
// RemoveFriends removes "friends" edges to User entities.
|
|
func (_u *UserUpdate) RemoveFriends(v ...*User) *UserUpdate {
|
|
ids := make([]int, len(v))
|
|
for i := range v {
|
|
ids[i] = v[i].ID
|
|
}
|
|
return _u.RemoveFriendIDs(ids...)
|
|
}
|
|
|
|
// Save executes the query and returns the number of nodes affected by the update operation.
|
|
func (_u *UserUpdate) 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 *UserUpdate) SaveX(ctx context.Context) int {
|
|
affected, err := _u.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return affected
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_u *UserUpdate) Exec(ctx context.Context) error {
|
|
_, err := _u.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_u *UserUpdate) 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 *UserUpdate) check() error {
|
|
if v, ok := _u.mutation.MixedEnum(); ok {
|
|
if err := user.MixedEnumValidator(v); err != nil {
|
|
return &ValidationError{Name: "mixed_enum", err: fmt.Errorf(`entv2: validator failed for field "User.mixed_enum": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.Nickname(); ok {
|
|
if err := user.NicknameValidator(v); err != nil {
|
|
return &ValidationError{Name: "nickname", err: fmt.Errorf(`entv2: validator failed for field "User.nickname": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.Blob(); ok {
|
|
if err := user.BlobValidator(v); err != nil {
|
|
return &ValidationError{Name: "blob", err: fmt.Errorf(`entv2: validator failed for field "User.blob": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.State(); ok {
|
|
if err := user.StateValidator(v); err != nil {
|
|
return &ValidationError{Name: "state", err: fmt.Errorf(`entv2: validator failed for field "User.state": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.Status(); ok {
|
|
if err := user.StatusValidator(v); err != nil {
|
|
return &ValidationError{Name: "status", err: fmt.Errorf(`entv2: validator failed for field "User.status": %w`, err)}
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (_u *UserUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
|
if err := _u.check(); err != nil {
|
|
return _node, err
|
|
}
|
|
_spec := sqlgraph.NewUpdateSpec(user.Table, user.Columns, sqlgraph.NewFieldSpec(user.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.MixedString(); ok {
|
|
_spec.SetField(user.FieldMixedString, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.MixedEnum(); ok {
|
|
_spec.SetField(user.FieldMixedEnum, field.TypeEnum, value)
|
|
}
|
|
if value, ok := _u.mutation.Active(); ok {
|
|
_spec.SetField(user.FieldActive, field.TypeBool, value)
|
|
}
|
|
if value, ok := _u.mutation.Age(); ok {
|
|
_spec.SetField(user.FieldAge, field.TypeInt, value)
|
|
}
|
|
if value, ok := _u.mutation.AddedAge(); ok {
|
|
_spec.AddField(user.FieldAge, field.TypeInt, value)
|
|
}
|
|
if value, ok := _u.mutation.Name(); ok {
|
|
_spec.SetField(user.FieldName, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Description(); ok {
|
|
_spec.SetField(user.FieldDescription, field.TypeString, value)
|
|
}
|
|
if _u.mutation.DescriptionCleared() {
|
|
_spec.ClearField(user.FieldDescription, field.TypeString)
|
|
}
|
|
if value, ok := _u.mutation.Nickname(); ok {
|
|
_spec.SetField(user.FieldNickname, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Phone(); ok {
|
|
_spec.SetField(user.FieldPhone, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Buffer(); ok {
|
|
_spec.SetField(user.FieldBuffer, field.TypeBytes, value)
|
|
}
|
|
if _u.mutation.BufferCleared() {
|
|
_spec.ClearField(user.FieldBuffer, field.TypeBytes)
|
|
}
|
|
if value, ok := _u.mutation.Title(); ok {
|
|
_spec.SetField(user.FieldTitle, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.NewName(); ok {
|
|
_spec.SetField(user.FieldNewName, field.TypeString, value)
|
|
}
|
|
if _u.mutation.NewNameCleared() {
|
|
_spec.ClearField(user.FieldNewName, field.TypeString)
|
|
}
|
|
if value, ok := _u.mutation.NewToken(); ok {
|
|
_spec.SetField(user.FieldNewToken, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Blob(); ok {
|
|
_spec.SetField(user.FieldBlob, field.TypeBytes, value)
|
|
}
|
|
if _u.mutation.BlobCleared() {
|
|
_spec.ClearField(user.FieldBlob, field.TypeBytes)
|
|
}
|
|
if value, ok := _u.mutation.State(); ok {
|
|
_spec.SetField(user.FieldState, field.TypeEnum, value)
|
|
}
|
|
if _u.mutation.StateCleared() {
|
|
_spec.ClearField(user.FieldState, field.TypeEnum)
|
|
}
|
|
if value, ok := _u.mutation.Status(); ok {
|
|
_spec.SetField(user.FieldStatus, field.TypeEnum, value)
|
|
}
|
|
if _u.mutation.StatusCleared() {
|
|
_spec.ClearField(user.FieldStatus, field.TypeEnum)
|
|
}
|
|
if value, ok := _u.mutation.Workplace(); ok {
|
|
_spec.SetField(user.FieldWorkplace, field.TypeString, value)
|
|
}
|
|
if _u.mutation.WorkplaceCleared() {
|
|
_spec.ClearField(user.FieldWorkplace, field.TypeString)
|
|
}
|
|
if value, ok := _u.mutation.Roles(); ok {
|
|
_spec.SetField(user.FieldRoles, field.TypeJSON, value)
|
|
}
|
|
if value, ok := _u.mutation.AppendedRoles(); ok {
|
|
_spec.AddModifier(func(u *sql.UpdateBuilder) {
|
|
sqljson.Append(u, user.FieldRoles, value)
|
|
})
|
|
}
|
|
if _u.mutation.RolesCleared() {
|
|
_spec.ClearField(user.FieldRoles, field.TypeJSON)
|
|
}
|
|
if value, ok := _u.mutation.DefaultExpr(); ok {
|
|
_spec.SetField(user.FieldDefaultExpr, field.TypeString, value)
|
|
}
|
|
if _u.mutation.DefaultExprCleared() {
|
|
_spec.ClearField(user.FieldDefaultExpr, field.TypeString)
|
|
}
|
|
if value, ok := _u.mutation.DefaultExprs(); ok {
|
|
_spec.SetField(user.FieldDefaultExprs, field.TypeString, value)
|
|
}
|
|
if _u.mutation.DefaultExprsCleared() {
|
|
_spec.ClearField(user.FieldDefaultExprs, field.TypeString)
|
|
}
|
|
if value, ok := _u.mutation.CreatedAt(); ok {
|
|
_spec.SetField(user.FieldCreatedAt, field.TypeTime, value)
|
|
}
|
|
if value, ok := _u.mutation.DropOptional(); ok {
|
|
_spec.SetField(user.FieldDropOptional, field.TypeString, value)
|
|
}
|
|
if _u.mutation.CarCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: user.CarTable,
|
|
Columns: []string{user.CarColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(car.FieldID, field.TypeInt),
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := _u.mutation.RemovedCarIDs(); len(nodes) > 0 && !_u.mutation.CarCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: user.CarTable,
|
|
Columns: []string{user.CarColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(car.FieldID, field.TypeInt),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := _u.mutation.CarIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: user.CarTable,
|
|
Columns: []string{user.CarColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(car.FieldID, field.TypeInt),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
|
}
|
|
if _u.mutation.PetsCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2O,
|
|
Inverse: false,
|
|
Table: user.PetsTable,
|
|
Columns: []string{user.PetsColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(pet.FieldID, field.TypeInt),
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := _u.mutation.PetsIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2O,
|
|
Inverse: false,
|
|
Table: user.PetsTable,
|
|
Columns: []string{user.PetsColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(pet.FieldID, field.TypeInt),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
|
}
|
|
if _u.mutation.FriendsCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2M,
|
|
Inverse: false,
|
|
Table: user.FriendsTable,
|
|
Columns: user.FriendsPrimaryKey,
|
|
Bidi: true,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := _u.mutation.RemovedFriendsIDs(); len(nodes) > 0 && !_u.mutation.FriendsCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2M,
|
|
Inverse: false,
|
|
Table: user.FriendsTable,
|
|
Columns: user.FriendsPrimaryKey,
|
|
Bidi: true,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := _u.mutation.FriendsIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2M,
|
|
Inverse: false,
|
|
Table: user.FriendsTable,
|
|
Columns: user.FriendsPrimaryKey,
|
|
Bidi: true,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
|
}
|
|
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
|
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
|
err = &NotFoundError{user.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return 0, err
|
|
}
|
|
_u.mutation.done = true
|
|
return _node, nil
|
|
}
|
|
|
|
// UserUpdateOne is the builder for updating a single User entity.
|
|
type UserUpdateOne struct {
|
|
config
|
|
fields []string
|
|
hooks []Hook
|
|
mutation *UserMutation
|
|
}
|
|
|
|
// SetMixedString sets the "mixed_string" field.
|
|
func (_u *UserUpdateOne) SetMixedString(v string) *UserUpdateOne {
|
|
_u.mutation.SetMixedString(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableMixedString sets the "mixed_string" field if the given value is not nil.
|
|
func (_u *UserUpdateOne) SetNillableMixedString(v *string) *UserUpdateOne {
|
|
if v != nil {
|
|
_u.SetMixedString(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetMixedEnum sets the "mixed_enum" field.
|
|
func (_u *UserUpdateOne) SetMixedEnum(v user.MixedEnum) *UserUpdateOne {
|
|
_u.mutation.SetMixedEnum(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableMixedEnum sets the "mixed_enum" field if the given value is not nil.
|
|
func (_u *UserUpdateOne) SetNillableMixedEnum(v *user.MixedEnum) *UserUpdateOne {
|
|
if v != nil {
|
|
_u.SetMixedEnum(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetActive sets the "active" field.
|
|
func (_u *UserUpdateOne) SetActive(v bool) *UserUpdateOne {
|
|
_u.mutation.SetActive(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableActive sets the "active" field if the given value is not nil.
|
|
func (_u *UserUpdateOne) SetNillableActive(v *bool) *UserUpdateOne {
|
|
if v != nil {
|
|
_u.SetActive(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetAge sets the "age" field.
|
|
func (_u *UserUpdateOne) SetAge(v int) *UserUpdateOne {
|
|
_u.mutation.ResetAge()
|
|
_u.mutation.SetAge(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableAge sets the "age" field if the given value is not nil.
|
|
func (_u *UserUpdateOne) SetNillableAge(v *int) *UserUpdateOne {
|
|
if v != nil {
|
|
_u.SetAge(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// AddAge adds value to the "age" field.
|
|
func (_u *UserUpdateOne) AddAge(v int) *UserUpdateOne {
|
|
_u.mutation.AddAge(v)
|
|
return _u
|
|
}
|
|
|
|
// SetName sets the "name" field.
|
|
func (_u *UserUpdateOne) SetName(v string) *UserUpdateOne {
|
|
_u.mutation.SetName(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableName sets the "name" field if the given value is not nil.
|
|
func (_u *UserUpdateOne) SetNillableName(v *string) *UserUpdateOne {
|
|
if v != nil {
|
|
_u.SetName(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetDescription sets the "description" field.
|
|
func (_u *UserUpdateOne) SetDescription(v string) *UserUpdateOne {
|
|
_u.mutation.SetDescription(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableDescription sets the "description" field if the given value is not nil.
|
|
func (_u *UserUpdateOne) SetNillableDescription(v *string) *UserUpdateOne {
|
|
if v != nil {
|
|
_u.SetDescription(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearDescription clears the value of the "description" field.
|
|
func (_u *UserUpdateOne) ClearDescription() *UserUpdateOne {
|
|
_u.mutation.ClearDescription()
|
|
return _u
|
|
}
|
|
|
|
// SetNickname sets the "nickname" field.
|
|
func (_u *UserUpdateOne) SetNickname(v string) *UserUpdateOne {
|
|
_u.mutation.SetNickname(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableNickname sets the "nickname" field if the given value is not nil.
|
|
func (_u *UserUpdateOne) SetNillableNickname(v *string) *UserUpdateOne {
|
|
if v != nil {
|
|
_u.SetNickname(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetPhone sets the "phone" field.
|
|
func (_u *UserUpdateOne) SetPhone(v string) *UserUpdateOne {
|
|
_u.mutation.SetPhone(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillablePhone sets the "phone" field if the given value is not nil.
|
|
func (_u *UserUpdateOne) SetNillablePhone(v *string) *UserUpdateOne {
|
|
if v != nil {
|
|
_u.SetPhone(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetBuffer sets the "buffer" field.
|
|
func (_u *UserUpdateOne) SetBuffer(v []byte) *UserUpdateOne {
|
|
_u.mutation.SetBuffer(v)
|
|
return _u
|
|
}
|
|
|
|
// ClearBuffer clears the value of the "buffer" field.
|
|
func (_u *UserUpdateOne) ClearBuffer() *UserUpdateOne {
|
|
_u.mutation.ClearBuffer()
|
|
return _u
|
|
}
|
|
|
|
// SetTitle sets the "title" field.
|
|
func (_u *UserUpdateOne) SetTitle(v string) *UserUpdateOne {
|
|
_u.mutation.SetTitle(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableTitle sets the "title" field if the given value is not nil.
|
|
func (_u *UserUpdateOne) SetNillableTitle(v *string) *UserUpdateOne {
|
|
if v != nil {
|
|
_u.SetTitle(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetNewName sets the "new_name" field.
|
|
func (_u *UserUpdateOne) SetNewName(v string) *UserUpdateOne {
|
|
_u.mutation.SetNewName(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableNewName sets the "new_name" field if the given value is not nil.
|
|
func (_u *UserUpdateOne) SetNillableNewName(v *string) *UserUpdateOne {
|
|
if v != nil {
|
|
_u.SetNewName(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearNewName clears the value of the "new_name" field.
|
|
func (_u *UserUpdateOne) ClearNewName() *UserUpdateOne {
|
|
_u.mutation.ClearNewName()
|
|
return _u
|
|
}
|
|
|
|
// SetNewToken sets the "new_token" field.
|
|
func (_u *UserUpdateOne) SetNewToken(v string) *UserUpdateOne {
|
|
_u.mutation.SetNewToken(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableNewToken sets the "new_token" field if the given value is not nil.
|
|
func (_u *UserUpdateOne) SetNillableNewToken(v *string) *UserUpdateOne {
|
|
if v != nil {
|
|
_u.SetNewToken(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetBlob sets the "blob" field.
|
|
func (_u *UserUpdateOne) SetBlob(v []byte) *UserUpdateOne {
|
|
_u.mutation.SetBlob(v)
|
|
return _u
|
|
}
|
|
|
|
// ClearBlob clears the value of the "blob" field.
|
|
func (_u *UserUpdateOne) ClearBlob() *UserUpdateOne {
|
|
_u.mutation.ClearBlob()
|
|
return _u
|
|
}
|
|
|
|
// SetState sets the "state" field.
|
|
func (_u *UserUpdateOne) SetState(v user.State) *UserUpdateOne {
|
|
_u.mutation.SetState(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableState sets the "state" field if the given value is not nil.
|
|
func (_u *UserUpdateOne) SetNillableState(v *user.State) *UserUpdateOne {
|
|
if v != nil {
|
|
_u.SetState(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearState clears the value of the "state" field.
|
|
func (_u *UserUpdateOne) ClearState() *UserUpdateOne {
|
|
_u.mutation.ClearState()
|
|
return _u
|
|
}
|
|
|
|
// SetStatus sets the "status" field.
|
|
func (_u *UserUpdateOne) SetStatus(v user.Status) *UserUpdateOne {
|
|
_u.mutation.SetStatus(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableStatus sets the "status" field if the given value is not nil.
|
|
func (_u *UserUpdateOne) SetNillableStatus(v *user.Status) *UserUpdateOne {
|
|
if v != nil {
|
|
_u.SetStatus(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearStatus clears the value of the "status" field.
|
|
func (_u *UserUpdateOne) ClearStatus() *UserUpdateOne {
|
|
_u.mutation.ClearStatus()
|
|
return _u
|
|
}
|
|
|
|
// SetWorkplace sets the "workplace" field.
|
|
func (_u *UserUpdateOne) SetWorkplace(v string) *UserUpdateOne {
|
|
_u.mutation.SetWorkplace(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableWorkplace sets the "workplace" field if the given value is not nil.
|
|
func (_u *UserUpdateOne) SetNillableWorkplace(v *string) *UserUpdateOne {
|
|
if v != nil {
|
|
_u.SetWorkplace(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearWorkplace clears the value of the "workplace" field.
|
|
func (_u *UserUpdateOne) ClearWorkplace() *UserUpdateOne {
|
|
_u.mutation.ClearWorkplace()
|
|
return _u
|
|
}
|
|
|
|
// SetRoles sets the "roles" field.
|
|
func (_u *UserUpdateOne) SetRoles(v []string) *UserUpdateOne {
|
|
_u.mutation.SetRoles(v)
|
|
return _u
|
|
}
|
|
|
|
// AppendRoles appends value to the "roles" field.
|
|
func (_u *UserUpdateOne) AppendRoles(v []string) *UserUpdateOne {
|
|
_u.mutation.AppendRoles(v)
|
|
return _u
|
|
}
|
|
|
|
// ClearRoles clears the value of the "roles" field.
|
|
func (_u *UserUpdateOne) ClearRoles() *UserUpdateOne {
|
|
_u.mutation.ClearRoles()
|
|
return _u
|
|
}
|
|
|
|
// SetDefaultExpr sets the "default_expr" field.
|
|
func (_u *UserUpdateOne) SetDefaultExpr(v string) *UserUpdateOne {
|
|
_u.mutation.SetDefaultExpr(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableDefaultExpr sets the "default_expr" field if the given value is not nil.
|
|
func (_u *UserUpdateOne) SetNillableDefaultExpr(v *string) *UserUpdateOne {
|
|
if v != nil {
|
|
_u.SetDefaultExpr(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearDefaultExpr clears the value of the "default_expr" field.
|
|
func (_u *UserUpdateOne) ClearDefaultExpr() *UserUpdateOne {
|
|
_u.mutation.ClearDefaultExpr()
|
|
return _u
|
|
}
|
|
|
|
// SetDefaultExprs sets the "default_exprs" field.
|
|
func (_u *UserUpdateOne) SetDefaultExprs(v string) *UserUpdateOne {
|
|
_u.mutation.SetDefaultExprs(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableDefaultExprs sets the "default_exprs" field if the given value is not nil.
|
|
func (_u *UserUpdateOne) SetNillableDefaultExprs(v *string) *UserUpdateOne {
|
|
if v != nil {
|
|
_u.SetDefaultExprs(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearDefaultExprs clears the value of the "default_exprs" field.
|
|
func (_u *UserUpdateOne) ClearDefaultExprs() *UserUpdateOne {
|
|
_u.mutation.ClearDefaultExprs()
|
|
return _u
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (_u *UserUpdateOne) SetCreatedAt(v time.Time) *UserUpdateOne {
|
|
_u.mutation.SetCreatedAt(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
|
func (_u *UserUpdateOne) SetNillableCreatedAt(v *time.Time) *UserUpdateOne {
|
|
if v != nil {
|
|
_u.SetCreatedAt(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetDropOptional sets the "drop_optional" field.
|
|
func (_u *UserUpdateOne) SetDropOptional(v string) *UserUpdateOne {
|
|
_u.mutation.SetDropOptional(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableDropOptional sets the "drop_optional" field if the given value is not nil.
|
|
func (_u *UserUpdateOne) SetNillableDropOptional(v *string) *UserUpdateOne {
|
|
if v != nil {
|
|
_u.SetDropOptional(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// AddCarIDs adds the "car" edge to the Car entity by IDs.
|
|
func (_u *UserUpdateOne) AddCarIDs(ids ...int) *UserUpdateOne {
|
|
_u.mutation.AddCarIDs(ids...)
|
|
return _u
|
|
}
|
|
|
|
// AddCar adds the "car" edges to the Car entity.
|
|
func (_u *UserUpdateOne) AddCar(v ...*Car) *UserUpdateOne {
|
|
ids := make([]int, len(v))
|
|
for i := range v {
|
|
ids[i] = v[i].ID
|
|
}
|
|
return _u.AddCarIDs(ids...)
|
|
}
|
|
|
|
// SetPetsID sets the "pets" edge to the Pet entity by ID.
|
|
func (_u *UserUpdateOne) SetPetsID(id int) *UserUpdateOne {
|
|
_u.mutation.SetPetsID(id)
|
|
return _u
|
|
}
|
|
|
|
// SetNillablePetsID sets the "pets" edge to the Pet entity by ID if the given value is not nil.
|
|
func (_u *UserUpdateOne) SetNillablePetsID(id *int) *UserUpdateOne {
|
|
if id != nil {
|
|
_u = _u.SetPetsID(*id)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetPets sets the "pets" edge to the Pet entity.
|
|
func (_u *UserUpdateOne) SetPets(v *Pet) *UserUpdateOne {
|
|
return _u.SetPetsID(v.ID)
|
|
}
|
|
|
|
// AddFriendIDs adds the "friends" edge to the User entity by IDs.
|
|
func (_u *UserUpdateOne) AddFriendIDs(ids ...int) *UserUpdateOne {
|
|
_u.mutation.AddFriendIDs(ids...)
|
|
return _u
|
|
}
|
|
|
|
// AddFriends adds the "friends" edges to the User entity.
|
|
func (_u *UserUpdateOne) AddFriends(v ...*User) *UserUpdateOne {
|
|
ids := make([]int, len(v))
|
|
for i := range v {
|
|
ids[i] = v[i].ID
|
|
}
|
|
return _u.AddFriendIDs(ids...)
|
|
}
|
|
|
|
// Mutation returns the UserMutation object of the builder.
|
|
func (_u *UserUpdateOne) Mutation() *UserMutation {
|
|
return _u.mutation
|
|
}
|
|
|
|
// ClearCar clears all "car" edges to the Car entity.
|
|
func (_u *UserUpdateOne) ClearCar() *UserUpdateOne {
|
|
_u.mutation.ClearCar()
|
|
return _u
|
|
}
|
|
|
|
// RemoveCarIDs removes the "car" edge to Car entities by IDs.
|
|
func (_u *UserUpdateOne) RemoveCarIDs(ids ...int) *UserUpdateOne {
|
|
_u.mutation.RemoveCarIDs(ids...)
|
|
return _u
|
|
}
|
|
|
|
// RemoveCar removes "car" edges to Car entities.
|
|
func (_u *UserUpdateOne) RemoveCar(v ...*Car) *UserUpdateOne {
|
|
ids := make([]int, len(v))
|
|
for i := range v {
|
|
ids[i] = v[i].ID
|
|
}
|
|
return _u.RemoveCarIDs(ids...)
|
|
}
|
|
|
|
// ClearPets clears the "pets" edge to the Pet entity.
|
|
func (_u *UserUpdateOne) ClearPets() *UserUpdateOne {
|
|
_u.mutation.ClearPets()
|
|
return _u
|
|
}
|
|
|
|
// ClearFriends clears all "friends" edges to the User entity.
|
|
func (_u *UserUpdateOne) ClearFriends() *UserUpdateOne {
|
|
_u.mutation.ClearFriends()
|
|
return _u
|
|
}
|
|
|
|
// RemoveFriendIDs removes the "friends" edge to User entities by IDs.
|
|
func (_u *UserUpdateOne) RemoveFriendIDs(ids ...int) *UserUpdateOne {
|
|
_u.mutation.RemoveFriendIDs(ids...)
|
|
return _u
|
|
}
|
|
|
|
// RemoveFriends removes "friends" edges to User entities.
|
|
func (_u *UserUpdateOne) RemoveFriends(v ...*User) *UserUpdateOne {
|
|
ids := make([]int, len(v))
|
|
for i := range v {
|
|
ids[i] = v[i].ID
|
|
}
|
|
return _u.RemoveFriendIDs(ids...)
|
|
}
|
|
|
|
// Where appends a list predicates to the UserUpdate builder.
|
|
func (_u *UserUpdateOne) Where(ps ...predicate.User) *UserUpdateOne {
|
|
_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 *UserUpdateOne) Select(field string, fields ...string) *UserUpdateOne {
|
|
_u.fields = append([]string{field}, fields...)
|
|
return _u
|
|
}
|
|
|
|
// Save executes the query and returns the updated User entity.
|
|
func (_u *UserUpdateOne) Save(ctx context.Context) (*User, error) {
|
|
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (_u *UserUpdateOne) SaveX(ctx context.Context) *User {
|
|
node, err := _u.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return node
|
|
}
|
|
|
|
// Exec executes the query on the entity.
|
|
func (_u *UserUpdateOne) Exec(ctx context.Context) error {
|
|
_, err := _u.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_u *UserUpdateOne) 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 *UserUpdateOne) check() error {
|
|
if v, ok := _u.mutation.MixedEnum(); ok {
|
|
if err := user.MixedEnumValidator(v); err != nil {
|
|
return &ValidationError{Name: "mixed_enum", err: fmt.Errorf(`entv2: validator failed for field "User.mixed_enum": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.Nickname(); ok {
|
|
if err := user.NicknameValidator(v); err != nil {
|
|
return &ValidationError{Name: "nickname", err: fmt.Errorf(`entv2: validator failed for field "User.nickname": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.Blob(); ok {
|
|
if err := user.BlobValidator(v); err != nil {
|
|
return &ValidationError{Name: "blob", err: fmt.Errorf(`entv2: validator failed for field "User.blob": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.State(); ok {
|
|
if err := user.StateValidator(v); err != nil {
|
|
return &ValidationError{Name: "state", err: fmt.Errorf(`entv2: validator failed for field "User.state": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.Status(); ok {
|
|
if err := user.StatusValidator(v); err != nil {
|
|
return &ValidationError{Name: "status", err: fmt.Errorf(`entv2: validator failed for field "User.status": %w`, err)}
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (_u *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error) {
|
|
if err := _u.check(); err != nil {
|
|
return _node, err
|
|
}
|
|
_spec := sqlgraph.NewUpdateSpec(user.Table, user.Columns, sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt))
|
|
id, ok := _u.mutation.ID()
|
|
if !ok {
|
|
return nil, &ValidationError{Name: "id", err: errors.New(`entv2: missing "User.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, user.FieldID)
|
|
for _, f := range fields {
|
|
if !user.ValidColumn(f) {
|
|
return nil, &ValidationError{Name: f, err: fmt.Errorf("entv2: invalid field %q for query", f)}
|
|
}
|
|
if f != user.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.MixedString(); ok {
|
|
_spec.SetField(user.FieldMixedString, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.MixedEnum(); ok {
|
|
_spec.SetField(user.FieldMixedEnum, field.TypeEnum, value)
|
|
}
|
|
if value, ok := _u.mutation.Active(); ok {
|
|
_spec.SetField(user.FieldActive, field.TypeBool, value)
|
|
}
|
|
if value, ok := _u.mutation.Age(); ok {
|
|
_spec.SetField(user.FieldAge, field.TypeInt, value)
|
|
}
|
|
if value, ok := _u.mutation.AddedAge(); ok {
|
|
_spec.AddField(user.FieldAge, field.TypeInt, value)
|
|
}
|
|
if value, ok := _u.mutation.Name(); ok {
|
|
_spec.SetField(user.FieldName, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Description(); ok {
|
|
_spec.SetField(user.FieldDescription, field.TypeString, value)
|
|
}
|
|
if _u.mutation.DescriptionCleared() {
|
|
_spec.ClearField(user.FieldDescription, field.TypeString)
|
|
}
|
|
if value, ok := _u.mutation.Nickname(); ok {
|
|
_spec.SetField(user.FieldNickname, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Phone(); ok {
|
|
_spec.SetField(user.FieldPhone, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Buffer(); ok {
|
|
_spec.SetField(user.FieldBuffer, field.TypeBytes, value)
|
|
}
|
|
if _u.mutation.BufferCleared() {
|
|
_spec.ClearField(user.FieldBuffer, field.TypeBytes)
|
|
}
|
|
if value, ok := _u.mutation.Title(); ok {
|
|
_spec.SetField(user.FieldTitle, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.NewName(); ok {
|
|
_spec.SetField(user.FieldNewName, field.TypeString, value)
|
|
}
|
|
if _u.mutation.NewNameCleared() {
|
|
_spec.ClearField(user.FieldNewName, field.TypeString)
|
|
}
|
|
if value, ok := _u.mutation.NewToken(); ok {
|
|
_spec.SetField(user.FieldNewToken, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Blob(); ok {
|
|
_spec.SetField(user.FieldBlob, field.TypeBytes, value)
|
|
}
|
|
if _u.mutation.BlobCleared() {
|
|
_spec.ClearField(user.FieldBlob, field.TypeBytes)
|
|
}
|
|
if value, ok := _u.mutation.State(); ok {
|
|
_spec.SetField(user.FieldState, field.TypeEnum, value)
|
|
}
|
|
if _u.mutation.StateCleared() {
|
|
_spec.ClearField(user.FieldState, field.TypeEnum)
|
|
}
|
|
if value, ok := _u.mutation.Status(); ok {
|
|
_spec.SetField(user.FieldStatus, field.TypeEnum, value)
|
|
}
|
|
if _u.mutation.StatusCleared() {
|
|
_spec.ClearField(user.FieldStatus, field.TypeEnum)
|
|
}
|
|
if value, ok := _u.mutation.Workplace(); ok {
|
|
_spec.SetField(user.FieldWorkplace, field.TypeString, value)
|
|
}
|
|
if _u.mutation.WorkplaceCleared() {
|
|
_spec.ClearField(user.FieldWorkplace, field.TypeString)
|
|
}
|
|
if value, ok := _u.mutation.Roles(); ok {
|
|
_spec.SetField(user.FieldRoles, field.TypeJSON, value)
|
|
}
|
|
if value, ok := _u.mutation.AppendedRoles(); ok {
|
|
_spec.AddModifier(func(u *sql.UpdateBuilder) {
|
|
sqljson.Append(u, user.FieldRoles, value)
|
|
})
|
|
}
|
|
if _u.mutation.RolesCleared() {
|
|
_spec.ClearField(user.FieldRoles, field.TypeJSON)
|
|
}
|
|
if value, ok := _u.mutation.DefaultExpr(); ok {
|
|
_spec.SetField(user.FieldDefaultExpr, field.TypeString, value)
|
|
}
|
|
if _u.mutation.DefaultExprCleared() {
|
|
_spec.ClearField(user.FieldDefaultExpr, field.TypeString)
|
|
}
|
|
if value, ok := _u.mutation.DefaultExprs(); ok {
|
|
_spec.SetField(user.FieldDefaultExprs, field.TypeString, value)
|
|
}
|
|
if _u.mutation.DefaultExprsCleared() {
|
|
_spec.ClearField(user.FieldDefaultExprs, field.TypeString)
|
|
}
|
|
if value, ok := _u.mutation.CreatedAt(); ok {
|
|
_spec.SetField(user.FieldCreatedAt, field.TypeTime, value)
|
|
}
|
|
if value, ok := _u.mutation.DropOptional(); ok {
|
|
_spec.SetField(user.FieldDropOptional, field.TypeString, value)
|
|
}
|
|
if _u.mutation.CarCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: user.CarTable,
|
|
Columns: []string{user.CarColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(car.FieldID, field.TypeInt),
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := _u.mutation.RemovedCarIDs(); len(nodes) > 0 && !_u.mutation.CarCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: user.CarTable,
|
|
Columns: []string{user.CarColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(car.FieldID, field.TypeInt),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := _u.mutation.CarIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: user.CarTable,
|
|
Columns: []string{user.CarColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(car.FieldID, field.TypeInt),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
|
}
|
|
if _u.mutation.PetsCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2O,
|
|
Inverse: false,
|
|
Table: user.PetsTable,
|
|
Columns: []string{user.PetsColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(pet.FieldID, field.TypeInt),
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := _u.mutation.PetsIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2O,
|
|
Inverse: false,
|
|
Table: user.PetsTable,
|
|
Columns: []string{user.PetsColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(pet.FieldID, field.TypeInt),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
|
}
|
|
if _u.mutation.FriendsCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2M,
|
|
Inverse: false,
|
|
Table: user.FriendsTable,
|
|
Columns: user.FriendsPrimaryKey,
|
|
Bidi: true,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := _u.mutation.RemovedFriendsIDs(); len(nodes) > 0 && !_u.mutation.FriendsCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2M,
|
|
Inverse: false,
|
|
Table: user.FriendsTable,
|
|
Columns: user.FriendsPrimaryKey,
|
|
Bidi: true,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := _u.mutation.FriendsIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2M,
|
|
Inverse: false,
|
|
Table: user.FriendsTable,
|
|
Columns: user.FriendsPrimaryKey,
|
|
Bidi: true,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
|
}
|
|
_node = &User{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{user.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return nil, err
|
|
}
|
|
_u.mutation.done = true
|
|
return _node, nil
|
|
}
|