mirror of
https://github.com/ent/ent.git
synced 2026-05-24 09:31:56 +03:00
556 lines
13 KiB
Go
556 lines
13 KiB
Go
// Copyright (c) Facebook, Inc. and its affiliates. 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 entc, DO NOT EDIT.
|
|
|
|
package entv1
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/facebookincubator/ent/dialect/sql"
|
|
"github.com/facebookincubator/ent/dialect/sql/sqlgraph"
|
|
"github.com/facebookincubator/ent/entc/integration/migrate/entv1/predicate"
|
|
"github.com/facebookincubator/ent/entc/integration/migrate/entv1/user"
|
|
"github.com/facebookincubator/ent/schema/field"
|
|
)
|
|
|
|
// UserUpdate is the builder for updating User entities.
|
|
type UserUpdate struct {
|
|
config
|
|
age *int32
|
|
addage *int32
|
|
name *string
|
|
nickname *string
|
|
address *string
|
|
clearaddress bool
|
|
renamed *string
|
|
clearrenamed bool
|
|
blob *[]byte
|
|
clearblob bool
|
|
state *user.State
|
|
clearstate bool
|
|
predicates []predicate.User
|
|
}
|
|
|
|
// Where adds a new predicate for the builder.
|
|
func (uu *UserUpdate) Where(ps ...predicate.User) *UserUpdate {
|
|
uu.predicates = append(uu.predicates, ps...)
|
|
return uu
|
|
}
|
|
|
|
// SetAge sets the age field.
|
|
func (uu *UserUpdate) SetAge(i int32) *UserUpdate {
|
|
uu.age = &i
|
|
uu.addage = nil
|
|
return uu
|
|
}
|
|
|
|
// AddAge adds i to age.
|
|
func (uu *UserUpdate) AddAge(i int32) *UserUpdate {
|
|
if uu.addage == nil {
|
|
uu.addage = &i
|
|
} else {
|
|
*uu.addage += i
|
|
}
|
|
return uu
|
|
}
|
|
|
|
// SetName sets the name field.
|
|
func (uu *UserUpdate) SetName(s string) *UserUpdate {
|
|
uu.name = &s
|
|
return uu
|
|
}
|
|
|
|
// SetNickname sets the nickname field.
|
|
func (uu *UserUpdate) SetNickname(s string) *UserUpdate {
|
|
uu.nickname = &s
|
|
return uu
|
|
}
|
|
|
|
// SetAddress sets the address field.
|
|
func (uu *UserUpdate) SetAddress(s string) *UserUpdate {
|
|
uu.address = &s
|
|
return uu
|
|
}
|
|
|
|
// SetNillableAddress sets the address field if the given value is not nil.
|
|
func (uu *UserUpdate) SetNillableAddress(s *string) *UserUpdate {
|
|
if s != nil {
|
|
uu.SetAddress(*s)
|
|
}
|
|
return uu
|
|
}
|
|
|
|
// ClearAddress clears the value of address.
|
|
func (uu *UserUpdate) ClearAddress() *UserUpdate {
|
|
uu.address = nil
|
|
uu.clearaddress = true
|
|
return uu
|
|
}
|
|
|
|
// SetRenamed sets the renamed field.
|
|
func (uu *UserUpdate) SetRenamed(s string) *UserUpdate {
|
|
uu.renamed = &s
|
|
return uu
|
|
}
|
|
|
|
// SetNillableRenamed sets the renamed field if the given value is not nil.
|
|
func (uu *UserUpdate) SetNillableRenamed(s *string) *UserUpdate {
|
|
if s != nil {
|
|
uu.SetRenamed(*s)
|
|
}
|
|
return uu
|
|
}
|
|
|
|
// ClearRenamed clears the value of renamed.
|
|
func (uu *UserUpdate) ClearRenamed() *UserUpdate {
|
|
uu.renamed = nil
|
|
uu.clearrenamed = true
|
|
return uu
|
|
}
|
|
|
|
// SetBlob sets the blob field.
|
|
func (uu *UserUpdate) SetBlob(b []byte) *UserUpdate {
|
|
uu.blob = &b
|
|
return uu
|
|
}
|
|
|
|
// ClearBlob clears the value of blob.
|
|
func (uu *UserUpdate) ClearBlob() *UserUpdate {
|
|
uu.blob = nil
|
|
uu.clearblob = true
|
|
return uu
|
|
}
|
|
|
|
// SetState sets the state field.
|
|
func (uu *UserUpdate) SetState(u user.State) *UserUpdate {
|
|
uu.state = &u
|
|
return uu
|
|
}
|
|
|
|
// SetNillableState sets the state field if the given value is not nil.
|
|
func (uu *UserUpdate) SetNillableState(u *user.State) *UserUpdate {
|
|
if u != nil {
|
|
uu.SetState(*u)
|
|
}
|
|
return uu
|
|
}
|
|
|
|
// ClearState clears the value of state.
|
|
func (uu *UserUpdate) ClearState() *UserUpdate {
|
|
uu.state = nil
|
|
uu.clearstate = true
|
|
return uu
|
|
}
|
|
|
|
// Save executes the query and returns the number of rows/vertices matched by this operation.
|
|
func (uu *UserUpdate) Save(ctx context.Context) (int, error) {
|
|
if uu.name != nil {
|
|
if err := user.NameValidator(*uu.name); err != nil {
|
|
return 0, fmt.Errorf("entv1: validator failed for field \"name\": %v", err)
|
|
}
|
|
}
|
|
if uu.state != nil {
|
|
if err := user.StateValidator(*uu.state); err != nil {
|
|
return 0, fmt.Errorf("entv1: validator failed for field \"state\": %v", err)
|
|
}
|
|
}
|
|
return uu.sqlSave(ctx)
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (uu *UserUpdate) SaveX(ctx context.Context) int {
|
|
affected, err := uu.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return affected
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (uu *UserUpdate) Exec(ctx context.Context) error {
|
|
_, err := uu.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (uu *UserUpdate) ExecX(ctx context.Context) {
|
|
if err := uu.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
|
spec := &sqlgraph.UpdateSpec{
|
|
Node: &sqlgraph.NodeSpec{
|
|
Table: user.Table,
|
|
Columns: user.Columns,
|
|
ID: &sqlgraph.FieldSpec{
|
|
Type: field.TypeInt,
|
|
Column: user.FieldID,
|
|
},
|
|
},
|
|
}
|
|
if ps := uu.predicates; len(ps) > 0 {
|
|
spec.Predicate = func(selector *sql.Selector) {
|
|
for i := range ps {
|
|
ps[i](selector)
|
|
}
|
|
}
|
|
}
|
|
if value := uu.age; value != nil {
|
|
spec.Fields.Set = append(spec.Fields.Set, &sqlgraph.FieldSpec{
|
|
Type: field.TypeInt32,
|
|
Value: *value,
|
|
Column: user.FieldAge,
|
|
})
|
|
}
|
|
if value := uu.addage; value != nil {
|
|
spec.Fields.Add = append(spec.Fields.Add, &sqlgraph.FieldSpec{
|
|
Type: field.TypeInt32,
|
|
Value: *value,
|
|
Column: user.FieldAge,
|
|
})
|
|
}
|
|
if value := uu.name; value != nil {
|
|
spec.Fields.Set = append(spec.Fields.Set, &sqlgraph.FieldSpec{
|
|
Type: field.TypeString,
|
|
Value: *value,
|
|
Column: user.FieldName,
|
|
})
|
|
}
|
|
if value := uu.nickname; value != nil {
|
|
spec.Fields.Set = append(spec.Fields.Set, &sqlgraph.FieldSpec{
|
|
Type: field.TypeString,
|
|
Value: *value,
|
|
Column: user.FieldNickname,
|
|
})
|
|
}
|
|
if value := uu.address; value != nil {
|
|
spec.Fields.Set = append(spec.Fields.Set, &sqlgraph.FieldSpec{
|
|
Type: field.TypeString,
|
|
Value: *value,
|
|
Column: user.FieldAddress,
|
|
})
|
|
}
|
|
if uu.clearaddress {
|
|
spec.Fields.Clear = append(spec.Fields.Clear, &sqlgraph.FieldSpec{
|
|
Type: field.TypeString,
|
|
Column: user.FieldAddress,
|
|
})
|
|
}
|
|
if value := uu.renamed; value != nil {
|
|
spec.Fields.Set = append(spec.Fields.Set, &sqlgraph.FieldSpec{
|
|
Type: field.TypeString,
|
|
Value: *value,
|
|
Column: user.FieldRenamed,
|
|
})
|
|
}
|
|
if uu.clearrenamed {
|
|
spec.Fields.Clear = append(spec.Fields.Clear, &sqlgraph.FieldSpec{
|
|
Type: field.TypeString,
|
|
Column: user.FieldRenamed,
|
|
})
|
|
}
|
|
if value := uu.blob; value != nil {
|
|
spec.Fields.Set = append(spec.Fields.Set, &sqlgraph.FieldSpec{
|
|
Type: field.TypeBytes,
|
|
Value: *value,
|
|
Column: user.FieldBlob,
|
|
})
|
|
}
|
|
if uu.clearblob {
|
|
spec.Fields.Clear = append(spec.Fields.Clear, &sqlgraph.FieldSpec{
|
|
Type: field.TypeBytes,
|
|
Column: user.FieldBlob,
|
|
})
|
|
}
|
|
if value := uu.state; value != nil {
|
|
spec.Fields.Set = append(spec.Fields.Set, &sqlgraph.FieldSpec{
|
|
Type: field.TypeEnum,
|
|
Value: *value,
|
|
Column: user.FieldState,
|
|
})
|
|
}
|
|
if uu.clearstate {
|
|
spec.Fields.Clear = append(spec.Fields.Clear, &sqlgraph.FieldSpec{
|
|
Type: field.TypeEnum,
|
|
Column: user.FieldState,
|
|
})
|
|
}
|
|
if n, err = sqlgraph.UpdateNodes(ctx, uu.driver, spec); err != nil {
|
|
if cerr, ok := isSQLConstraintError(err); ok {
|
|
err = cerr
|
|
}
|
|
return 0, err
|
|
}
|
|
return n, nil
|
|
}
|
|
|
|
// UserUpdateOne is the builder for updating a single User entity.
|
|
type UserUpdateOne struct {
|
|
config
|
|
id int
|
|
age *int32
|
|
addage *int32
|
|
name *string
|
|
nickname *string
|
|
address *string
|
|
clearaddress bool
|
|
renamed *string
|
|
clearrenamed bool
|
|
blob *[]byte
|
|
clearblob bool
|
|
state *user.State
|
|
clearstate bool
|
|
}
|
|
|
|
// SetAge sets the age field.
|
|
func (uuo *UserUpdateOne) SetAge(i int32) *UserUpdateOne {
|
|
uuo.age = &i
|
|
uuo.addage = nil
|
|
return uuo
|
|
}
|
|
|
|
// AddAge adds i to age.
|
|
func (uuo *UserUpdateOne) AddAge(i int32) *UserUpdateOne {
|
|
if uuo.addage == nil {
|
|
uuo.addage = &i
|
|
} else {
|
|
*uuo.addage += i
|
|
}
|
|
return uuo
|
|
}
|
|
|
|
// SetName sets the name field.
|
|
func (uuo *UserUpdateOne) SetName(s string) *UserUpdateOne {
|
|
uuo.name = &s
|
|
return uuo
|
|
}
|
|
|
|
// SetNickname sets the nickname field.
|
|
func (uuo *UserUpdateOne) SetNickname(s string) *UserUpdateOne {
|
|
uuo.nickname = &s
|
|
return uuo
|
|
}
|
|
|
|
// SetAddress sets the address field.
|
|
func (uuo *UserUpdateOne) SetAddress(s string) *UserUpdateOne {
|
|
uuo.address = &s
|
|
return uuo
|
|
}
|
|
|
|
// SetNillableAddress sets the address field if the given value is not nil.
|
|
func (uuo *UserUpdateOne) SetNillableAddress(s *string) *UserUpdateOne {
|
|
if s != nil {
|
|
uuo.SetAddress(*s)
|
|
}
|
|
return uuo
|
|
}
|
|
|
|
// ClearAddress clears the value of address.
|
|
func (uuo *UserUpdateOne) ClearAddress() *UserUpdateOne {
|
|
uuo.address = nil
|
|
uuo.clearaddress = true
|
|
return uuo
|
|
}
|
|
|
|
// SetRenamed sets the renamed field.
|
|
func (uuo *UserUpdateOne) SetRenamed(s string) *UserUpdateOne {
|
|
uuo.renamed = &s
|
|
return uuo
|
|
}
|
|
|
|
// SetNillableRenamed sets the renamed field if the given value is not nil.
|
|
func (uuo *UserUpdateOne) SetNillableRenamed(s *string) *UserUpdateOne {
|
|
if s != nil {
|
|
uuo.SetRenamed(*s)
|
|
}
|
|
return uuo
|
|
}
|
|
|
|
// ClearRenamed clears the value of renamed.
|
|
func (uuo *UserUpdateOne) ClearRenamed() *UserUpdateOne {
|
|
uuo.renamed = nil
|
|
uuo.clearrenamed = true
|
|
return uuo
|
|
}
|
|
|
|
// SetBlob sets the blob field.
|
|
func (uuo *UserUpdateOne) SetBlob(b []byte) *UserUpdateOne {
|
|
uuo.blob = &b
|
|
return uuo
|
|
}
|
|
|
|
// ClearBlob clears the value of blob.
|
|
func (uuo *UserUpdateOne) ClearBlob() *UserUpdateOne {
|
|
uuo.blob = nil
|
|
uuo.clearblob = true
|
|
return uuo
|
|
}
|
|
|
|
// SetState sets the state field.
|
|
func (uuo *UserUpdateOne) SetState(u user.State) *UserUpdateOne {
|
|
uuo.state = &u
|
|
return uuo
|
|
}
|
|
|
|
// SetNillableState sets the state field if the given value is not nil.
|
|
func (uuo *UserUpdateOne) SetNillableState(u *user.State) *UserUpdateOne {
|
|
if u != nil {
|
|
uuo.SetState(*u)
|
|
}
|
|
return uuo
|
|
}
|
|
|
|
// ClearState clears the value of state.
|
|
func (uuo *UserUpdateOne) ClearState() *UserUpdateOne {
|
|
uuo.state = nil
|
|
uuo.clearstate = true
|
|
return uuo
|
|
}
|
|
|
|
// Save executes the query and returns the updated entity.
|
|
func (uuo *UserUpdateOne) Save(ctx context.Context) (*User, error) {
|
|
if uuo.name != nil {
|
|
if err := user.NameValidator(*uuo.name); err != nil {
|
|
return nil, fmt.Errorf("entv1: validator failed for field \"name\": %v", err)
|
|
}
|
|
}
|
|
if uuo.state != nil {
|
|
if err := user.StateValidator(*uuo.state); err != nil {
|
|
return nil, fmt.Errorf("entv1: validator failed for field \"state\": %v", err)
|
|
}
|
|
}
|
|
return uuo.sqlSave(ctx)
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (uuo *UserUpdateOne) SaveX(ctx context.Context) *User {
|
|
u, err := uuo.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return u
|
|
}
|
|
|
|
// Exec executes the query on the entity.
|
|
func (uuo *UserUpdateOne) Exec(ctx context.Context) error {
|
|
_, err := uuo.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (uuo *UserUpdateOne) ExecX(ctx context.Context) {
|
|
if err := uuo.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (u *User, err error) {
|
|
spec := &sqlgraph.UpdateSpec{
|
|
Node: &sqlgraph.NodeSpec{
|
|
Table: user.Table,
|
|
Columns: user.Columns,
|
|
ID: &sqlgraph.FieldSpec{
|
|
Value: uuo.id,
|
|
Type: field.TypeInt,
|
|
Column: user.FieldID,
|
|
},
|
|
},
|
|
}
|
|
if value := uuo.age; value != nil {
|
|
spec.Fields.Set = append(spec.Fields.Set, &sqlgraph.FieldSpec{
|
|
Type: field.TypeInt32,
|
|
Value: *value,
|
|
Column: user.FieldAge,
|
|
})
|
|
}
|
|
if value := uuo.addage; value != nil {
|
|
spec.Fields.Add = append(spec.Fields.Add, &sqlgraph.FieldSpec{
|
|
Type: field.TypeInt32,
|
|
Value: *value,
|
|
Column: user.FieldAge,
|
|
})
|
|
}
|
|
if value := uuo.name; value != nil {
|
|
spec.Fields.Set = append(spec.Fields.Set, &sqlgraph.FieldSpec{
|
|
Type: field.TypeString,
|
|
Value: *value,
|
|
Column: user.FieldName,
|
|
})
|
|
}
|
|
if value := uuo.nickname; value != nil {
|
|
spec.Fields.Set = append(spec.Fields.Set, &sqlgraph.FieldSpec{
|
|
Type: field.TypeString,
|
|
Value: *value,
|
|
Column: user.FieldNickname,
|
|
})
|
|
}
|
|
if value := uuo.address; value != nil {
|
|
spec.Fields.Set = append(spec.Fields.Set, &sqlgraph.FieldSpec{
|
|
Type: field.TypeString,
|
|
Value: *value,
|
|
Column: user.FieldAddress,
|
|
})
|
|
}
|
|
if uuo.clearaddress {
|
|
spec.Fields.Clear = append(spec.Fields.Clear, &sqlgraph.FieldSpec{
|
|
Type: field.TypeString,
|
|
Column: user.FieldAddress,
|
|
})
|
|
}
|
|
if value := uuo.renamed; value != nil {
|
|
spec.Fields.Set = append(spec.Fields.Set, &sqlgraph.FieldSpec{
|
|
Type: field.TypeString,
|
|
Value: *value,
|
|
Column: user.FieldRenamed,
|
|
})
|
|
}
|
|
if uuo.clearrenamed {
|
|
spec.Fields.Clear = append(spec.Fields.Clear, &sqlgraph.FieldSpec{
|
|
Type: field.TypeString,
|
|
Column: user.FieldRenamed,
|
|
})
|
|
}
|
|
if value := uuo.blob; value != nil {
|
|
spec.Fields.Set = append(spec.Fields.Set, &sqlgraph.FieldSpec{
|
|
Type: field.TypeBytes,
|
|
Value: *value,
|
|
Column: user.FieldBlob,
|
|
})
|
|
}
|
|
if uuo.clearblob {
|
|
spec.Fields.Clear = append(spec.Fields.Clear, &sqlgraph.FieldSpec{
|
|
Type: field.TypeBytes,
|
|
Column: user.FieldBlob,
|
|
})
|
|
}
|
|
if value := uuo.state; value != nil {
|
|
spec.Fields.Set = append(spec.Fields.Set, &sqlgraph.FieldSpec{
|
|
Type: field.TypeEnum,
|
|
Value: *value,
|
|
Column: user.FieldState,
|
|
})
|
|
}
|
|
if uuo.clearstate {
|
|
spec.Fields.Clear = append(spec.Fields.Clear, &sqlgraph.FieldSpec{
|
|
Type: field.TypeEnum,
|
|
Column: user.FieldState,
|
|
})
|
|
}
|
|
u = &User{config: uuo.config}
|
|
spec.Assign = u.assignValues
|
|
spec.ScanValues = u.scanValues()
|
|
if err = sqlgraph.UpdateNode(ctx, uuo.driver, spec); err != nil {
|
|
if cerr, ok := isSQLConstraintError(err); ok {
|
|
err = cerr
|
|
}
|
|
return nil, err
|
|
}
|
|
return u, nil
|
|
}
|