911 lines
26 KiB
Go
911 lines
26 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 ent
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"errors"
|
|
"fmt"
|
|
"net/http"
|
|
"net/url"
|
|
|
|
"entgo.io/ent/dialect/sql"
|
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
|
"entgo.io/ent/dialect/sql/sqljson"
|
|
"entgo.io/ent/entc/integration/json/ent/predicate"
|
|
"entgo.io/ent/entc/integration/json/ent/schema"
|
|
"entgo.io/ent/entc/integration/json/ent/user"
|
|
"entgo.io/ent/schema/field"
|
|
)
|
|
|
|
// UserUpdate is the builder for updating User entities.
|
|
type UserUpdate struct {
|
|
config
|
|
hooks []Hook
|
|
mutation *UserMutation
|
|
modifiers []func(*sql.UpdateBuilder)
|
|
}
|
|
|
|
// Where appends a list predicates to the UserUpdate builder.
|
|
func (_u *UserUpdate) Where(ps ...predicate.User) *UserUpdate {
|
|
_u.mutation.Where(ps...)
|
|
return _u
|
|
}
|
|
|
|
// SetT sets the "t" field.
|
|
func (_u *UserUpdate) SetT(v *schema.T) *UserUpdate {
|
|
_u.mutation.SetT(v)
|
|
return _u
|
|
}
|
|
|
|
// ClearT clears the value of the "t" field.
|
|
func (_u *UserUpdate) ClearT() *UserUpdate {
|
|
_u.mutation.ClearT()
|
|
return _u
|
|
}
|
|
|
|
// SetURL sets the "url" field.
|
|
func (_u *UserUpdate) SetURL(v *url.URL) *UserUpdate {
|
|
_u.mutation.SetURL(v)
|
|
return _u
|
|
}
|
|
|
|
// ClearURL clears the value of the "url" field.
|
|
func (_u *UserUpdate) ClearURL() *UserUpdate {
|
|
_u.mutation.ClearURL()
|
|
return _u
|
|
}
|
|
|
|
// SetURLs sets the "URLs" field.
|
|
func (_u *UserUpdate) SetURLs(v []*url.URL) *UserUpdate {
|
|
_u.mutation.SetURLs(v)
|
|
return _u
|
|
}
|
|
|
|
// AppendURLs appends value to the "URLs" field.
|
|
func (_u *UserUpdate) AppendURLs(v []*url.URL) *UserUpdate {
|
|
_u.mutation.AppendURLs(v)
|
|
return _u
|
|
}
|
|
|
|
// ClearURLs clears the value of the "URLs" field.
|
|
func (_u *UserUpdate) ClearURLs() *UserUpdate {
|
|
_u.mutation.ClearURLs()
|
|
return _u
|
|
}
|
|
|
|
// SetRaw sets the "raw" field.
|
|
func (_u *UserUpdate) SetRaw(v json.RawMessage) *UserUpdate {
|
|
_u.mutation.SetRaw(v)
|
|
return _u
|
|
}
|
|
|
|
// AppendRaw appends value to the "raw" field.
|
|
func (_u *UserUpdate) AppendRaw(v json.RawMessage) *UserUpdate {
|
|
_u.mutation.AppendRaw(v)
|
|
return _u
|
|
}
|
|
|
|
// ClearRaw clears the value of the "raw" field.
|
|
func (_u *UserUpdate) ClearRaw() *UserUpdate {
|
|
_u.mutation.ClearRaw()
|
|
return _u
|
|
}
|
|
|
|
// SetDirs sets the "dirs" field.
|
|
func (_u *UserUpdate) SetDirs(v []http.Dir) *UserUpdate {
|
|
_u.mutation.SetDirs(v)
|
|
return _u
|
|
}
|
|
|
|
// AppendDirs appends value to the "dirs" field.
|
|
func (_u *UserUpdate) AppendDirs(v []http.Dir) *UserUpdate {
|
|
_u.mutation.AppendDirs(v)
|
|
return _u
|
|
}
|
|
|
|
// SetInts sets the "ints" field.
|
|
func (_u *UserUpdate) SetInts(v []int) *UserUpdate {
|
|
_u.mutation.SetInts(v)
|
|
return _u
|
|
}
|
|
|
|
// AppendInts appends value to the "ints" field.
|
|
func (_u *UserUpdate) AppendInts(v []int) *UserUpdate {
|
|
_u.mutation.AppendInts(v)
|
|
return _u
|
|
}
|
|
|
|
// ClearInts clears the value of the "ints" field.
|
|
func (_u *UserUpdate) ClearInts() *UserUpdate {
|
|
_u.mutation.ClearInts()
|
|
return _u
|
|
}
|
|
|
|
// SetFloats sets the "floats" field.
|
|
func (_u *UserUpdate) SetFloats(v []float64) *UserUpdate {
|
|
_u.mutation.SetFloats(v)
|
|
return _u
|
|
}
|
|
|
|
// AppendFloats appends value to the "floats" field.
|
|
func (_u *UserUpdate) AppendFloats(v []float64) *UserUpdate {
|
|
_u.mutation.AppendFloats(v)
|
|
return _u
|
|
}
|
|
|
|
// ClearFloats clears the value of the "floats" field.
|
|
func (_u *UserUpdate) ClearFloats() *UserUpdate {
|
|
_u.mutation.ClearFloats()
|
|
return _u
|
|
}
|
|
|
|
// SetStrings sets the "strings" field.
|
|
func (_u *UserUpdate) SetStrings(v []string) *UserUpdate {
|
|
_u.mutation.SetStrings(v)
|
|
return _u
|
|
}
|
|
|
|
// AppendStrings appends value to the "strings" field.
|
|
func (_u *UserUpdate) AppendStrings(v []string) *UserUpdate {
|
|
_u.mutation.AppendStrings(v)
|
|
return _u
|
|
}
|
|
|
|
// ClearStrings clears the value of the "strings" field.
|
|
func (_u *UserUpdate) ClearStrings() *UserUpdate {
|
|
_u.mutation.ClearStrings()
|
|
return _u
|
|
}
|
|
|
|
// SetIntsValidate sets the "ints_validate" field.
|
|
func (_u *UserUpdate) SetIntsValidate(v []int) *UserUpdate {
|
|
_u.mutation.SetIntsValidate(v)
|
|
return _u
|
|
}
|
|
|
|
// AppendIntsValidate appends value to the "ints_validate" field.
|
|
func (_u *UserUpdate) AppendIntsValidate(v []int) *UserUpdate {
|
|
_u.mutation.AppendIntsValidate(v)
|
|
return _u
|
|
}
|
|
|
|
// ClearIntsValidate clears the value of the "ints_validate" field.
|
|
func (_u *UserUpdate) ClearIntsValidate() *UserUpdate {
|
|
_u.mutation.ClearIntsValidate()
|
|
return _u
|
|
}
|
|
|
|
// SetFloatsValidate sets the "floats_validate" field.
|
|
func (_u *UserUpdate) SetFloatsValidate(v []float64) *UserUpdate {
|
|
_u.mutation.SetFloatsValidate(v)
|
|
return _u
|
|
}
|
|
|
|
// AppendFloatsValidate appends value to the "floats_validate" field.
|
|
func (_u *UserUpdate) AppendFloatsValidate(v []float64) *UserUpdate {
|
|
_u.mutation.AppendFloatsValidate(v)
|
|
return _u
|
|
}
|
|
|
|
// ClearFloatsValidate clears the value of the "floats_validate" field.
|
|
func (_u *UserUpdate) ClearFloatsValidate() *UserUpdate {
|
|
_u.mutation.ClearFloatsValidate()
|
|
return _u
|
|
}
|
|
|
|
// SetStringsValidate sets the "strings_validate" field.
|
|
func (_u *UserUpdate) SetStringsValidate(v []string) *UserUpdate {
|
|
_u.mutation.SetStringsValidate(v)
|
|
return _u
|
|
}
|
|
|
|
// AppendStringsValidate appends value to the "strings_validate" field.
|
|
func (_u *UserUpdate) AppendStringsValidate(v []string) *UserUpdate {
|
|
_u.mutation.AppendStringsValidate(v)
|
|
return _u
|
|
}
|
|
|
|
// ClearStringsValidate clears the value of the "strings_validate" field.
|
|
func (_u *UserUpdate) ClearStringsValidate() *UserUpdate {
|
|
_u.mutation.ClearStringsValidate()
|
|
return _u
|
|
}
|
|
|
|
// SetAddr sets the "addr" field.
|
|
func (_u *UserUpdate) SetAddr(v schema.Addr) *UserUpdate {
|
|
_u.mutation.SetAddr(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableAddr sets the "addr" field if the given value is not nil.
|
|
func (_u *UserUpdate) SetNillableAddr(v *schema.Addr) *UserUpdate {
|
|
if v != nil {
|
|
_u.SetAddr(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearAddr clears the value of the "addr" field.
|
|
func (_u *UserUpdate) ClearAddr() *UserUpdate {
|
|
_u.mutation.ClearAddr()
|
|
return _u
|
|
}
|
|
|
|
// SetUnknown sets the "unknown" field.
|
|
func (_u *UserUpdate) SetUnknown(v any) *UserUpdate {
|
|
_u.mutation.SetUnknown(v)
|
|
return _u
|
|
}
|
|
|
|
// ClearUnknown clears the value of the "unknown" field.
|
|
func (_u *UserUpdate) ClearUnknown() *UserUpdate {
|
|
_u.mutation.ClearUnknown()
|
|
return _u
|
|
}
|
|
|
|
// Mutation returns the UserMutation object of the builder.
|
|
func (_u *UserUpdate) Mutation() *UserMutation {
|
|
return _u.mutation
|
|
}
|
|
|
|
// 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.IntsValidate(); ok {
|
|
if err := user.IntsValidateValidator(v); err != nil {
|
|
return &ValidationError{Name: "ints_validate", err: fmt.Errorf(`ent: validator failed for field "User.ints_validate": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.FloatsValidate(); ok {
|
|
if err := user.FloatsValidateValidator(v); err != nil {
|
|
return &ValidationError{Name: "floats_validate", err: fmt.Errorf(`ent: validator failed for field "User.floats_validate": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.StringsValidate(); ok {
|
|
if err := user.StringsValidateValidator(v); err != nil {
|
|
return &ValidationError{Name: "strings_validate", err: fmt.Errorf(`ent: validator failed for field "User.strings_validate": %w`, err)}
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
|
|
func (_u *UserUpdate) Modify(modifiers ...func(u *sql.UpdateBuilder)) *UserUpdate {
|
|
_u.modifiers = append(_u.modifiers, modifiers...)
|
|
return _u
|
|
}
|
|
|
|
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.T(); ok {
|
|
_spec.SetField(user.FieldT, field.TypeJSON, value)
|
|
}
|
|
if _u.mutation.TCleared() {
|
|
_spec.ClearField(user.FieldT, field.TypeJSON)
|
|
}
|
|
if value, ok := _u.mutation.URL(); ok {
|
|
_spec.SetField(user.FieldURL, field.TypeJSON, value)
|
|
}
|
|
if _u.mutation.URLCleared() {
|
|
_spec.ClearField(user.FieldURL, field.TypeJSON)
|
|
}
|
|
if value, ok := _u.mutation.URLs(); ok {
|
|
_spec.SetField(user.FieldURLs, field.TypeJSON, value)
|
|
}
|
|
if value, ok := _u.mutation.AppendedURLs(); ok {
|
|
_spec.AddModifier(func(u *sql.UpdateBuilder) {
|
|
sqljson.Append(u, user.FieldURLs, value)
|
|
})
|
|
}
|
|
if _u.mutation.URLsCleared() {
|
|
_spec.ClearField(user.FieldURLs, field.TypeJSON)
|
|
}
|
|
if value, ok := _u.mutation.Raw(); ok {
|
|
_spec.SetField(user.FieldRaw, field.TypeJSON, value)
|
|
}
|
|
if value, ok := _u.mutation.AppendedRaw(); ok {
|
|
_spec.AddModifier(func(u *sql.UpdateBuilder) {
|
|
sqljson.Append(u, user.FieldRaw, value)
|
|
})
|
|
}
|
|
if _u.mutation.RawCleared() {
|
|
_spec.ClearField(user.FieldRaw, field.TypeJSON)
|
|
}
|
|
if value, ok := _u.mutation.Dirs(); ok {
|
|
_spec.SetField(user.FieldDirs, field.TypeJSON, value)
|
|
}
|
|
if value, ok := _u.mutation.AppendedDirs(); ok {
|
|
_spec.AddModifier(func(u *sql.UpdateBuilder) {
|
|
sqljson.Append(u, user.FieldDirs, value)
|
|
})
|
|
}
|
|
if value, ok := _u.mutation.Ints(); ok {
|
|
_spec.SetField(user.FieldInts, field.TypeJSON, value)
|
|
}
|
|
if value, ok := _u.mutation.AppendedInts(); ok {
|
|
_spec.AddModifier(func(u *sql.UpdateBuilder) {
|
|
sqljson.Append(u, user.FieldInts, value)
|
|
})
|
|
}
|
|
if _u.mutation.IntsCleared() {
|
|
_spec.ClearField(user.FieldInts, field.TypeJSON)
|
|
}
|
|
if value, ok := _u.mutation.Floats(); ok {
|
|
_spec.SetField(user.FieldFloats, field.TypeJSON, value)
|
|
}
|
|
if value, ok := _u.mutation.AppendedFloats(); ok {
|
|
_spec.AddModifier(func(u *sql.UpdateBuilder) {
|
|
sqljson.Append(u, user.FieldFloats, value)
|
|
})
|
|
}
|
|
if _u.mutation.FloatsCleared() {
|
|
_spec.ClearField(user.FieldFloats, field.TypeJSON)
|
|
}
|
|
if value, ok := _u.mutation.Strings(); ok {
|
|
_spec.SetField(user.FieldStrings, field.TypeJSON, value)
|
|
}
|
|
if value, ok := _u.mutation.AppendedStrings(); ok {
|
|
_spec.AddModifier(func(u *sql.UpdateBuilder) {
|
|
sqljson.Append(u, user.FieldStrings, value)
|
|
})
|
|
}
|
|
if _u.mutation.StringsCleared() {
|
|
_spec.ClearField(user.FieldStrings, field.TypeJSON)
|
|
}
|
|
if value, ok := _u.mutation.IntsValidate(); ok {
|
|
_spec.SetField(user.FieldIntsValidate, field.TypeJSON, value)
|
|
}
|
|
if value, ok := _u.mutation.AppendedIntsValidate(); ok {
|
|
_spec.AddModifier(func(u *sql.UpdateBuilder) {
|
|
sqljson.Append(u, user.FieldIntsValidate, value)
|
|
})
|
|
}
|
|
if _u.mutation.IntsValidateCleared() {
|
|
_spec.ClearField(user.FieldIntsValidate, field.TypeJSON)
|
|
}
|
|
if value, ok := _u.mutation.FloatsValidate(); ok {
|
|
_spec.SetField(user.FieldFloatsValidate, field.TypeJSON, value)
|
|
}
|
|
if value, ok := _u.mutation.AppendedFloatsValidate(); ok {
|
|
_spec.AddModifier(func(u *sql.UpdateBuilder) {
|
|
sqljson.Append(u, user.FieldFloatsValidate, value)
|
|
})
|
|
}
|
|
if _u.mutation.FloatsValidateCleared() {
|
|
_spec.ClearField(user.FieldFloatsValidate, field.TypeJSON)
|
|
}
|
|
if value, ok := _u.mutation.StringsValidate(); ok {
|
|
_spec.SetField(user.FieldStringsValidate, field.TypeJSON, value)
|
|
}
|
|
if value, ok := _u.mutation.AppendedStringsValidate(); ok {
|
|
_spec.AddModifier(func(u *sql.UpdateBuilder) {
|
|
sqljson.Append(u, user.FieldStringsValidate, value)
|
|
})
|
|
}
|
|
if _u.mutation.StringsValidateCleared() {
|
|
_spec.ClearField(user.FieldStringsValidate, field.TypeJSON)
|
|
}
|
|
if value, ok := _u.mutation.Addr(); ok {
|
|
_spec.SetField(user.FieldAddr, field.TypeJSON, value)
|
|
}
|
|
if _u.mutation.AddrCleared() {
|
|
_spec.ClearField(user.FieldAddr, field.TypeJSON)
|
|
}
|
|
if value, ok := _u.mutation.Unknown(); ok {
|
|
_spec.SetField(user.FieldUnknown, field.TypeJSON, value)
|
|
}
|
|
if _u.mutation.UnknownCleared() {
|
|
_spec.ClearField(user.FieldUnknown, field.TypeJSON)
|
|
}
|
|
_spec.AddModifiers(_u.modifiers...)
|
|
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
|
|
modifiers []func(*sql.UpdateBuilder)
|
|
}
|
|
|
|
// SetT sets the "t" field.
|
|
func (_u *UserUpdateOne) SetT(v *schema.T) *UserUpdateOne {
|
|
_u.mutation.SetT(v)
|
|
return _u
|
|
}
|
|
|
|
// ClearT clears the value of the "t" field.
|
|
func (_u *UserUpdateOne) ClearT() *UserUpdateOne {
|
|
_u.mutation.ClearT()
|
|
return _u
|
|
}
|
|
|
|
// SetURL sets the "url" field.
|
|
func (_u *UserUpdateOne) SetURL(v *url.URL) *UserUpdateOne {
|
|
_u.mutation.SetURL(v)
|
|
return _u
|
|
}
|
|
|
|
// ClearURL clears the value of the "url" field.
|
|
func (_u *UserUpdateOne) ClearURL() *UserUpdateOne {
|
|
_u.mutation.ClearURL()
|
|
return _u
|
|
}
|
|
|
|
// SetURLs sets the "URLs" field.
|
|
func (_u *UserUpdateOne) SetURLs(v []*url.URL) *UserUpdateOne {
|
|
_u.mutation.SetURLs(v)
|
|
return _u
|
|
}
|
|
|
|
// AppendURLs appends value to the "URLs" field.
|
|
func (_u *UserUpdateOne) AppendURLs(v []*url.URL) *UserUpdateOne {
|
|
_u.mutation.AppendURLs(v)
|
|
return _u
|
|
}
|
|
|
|
// ClearURLs clears the value of the "URLs" field.
|
|
func (_u *UserUpdateOne) ClearURLs() *UserUpdateOne {
|
|
_u.mutation.ClearURLs()
|
|
return _u
|
|
}
|
|
|
|
// SetRaw sets the "raw" field.
|
|
func (_u *UserUpdateOne) SetRaw(v json.RawMessage) *UserUpdateOne {
|
|
_u.mutation.SetRaw(v)
|
|
return _u
|
|
}
|
|
|
|
// AppendRaw appends value to the "raw" field.
|
|
func (_u *UserUpdateOne) AppendRaw(v json.RawMessage) *UserUpdateOne {
|
|
_u.mutation.AppendRaw(v)
|
|
return _u
|
|
}
|
|
|
|
// ClearRaw clears the value of the "raw" field.
|
|
func (_u *UserUpdateOne) ClearRaw() *UserUpdateOne {
|
|
_u.mutation.ClearRaw()
|
|
return _u
|
|
}
|
|
|
|
// SetDirs sets the "dirs" field.
|
|
func (_u *UserUpdateOne) SetDirs(v []http.Dir) *UserUpdateOne {
|
|
_u.mutation.SetDirs(v)
|
|
return _u
|
|
}
|
|
|
|
// AppendDirs appends value to the "dirs" field.
|
|
func (_u *UserUpdateOne) AppendDirs(v []http.Dir) *UserUpdateOne {
|
|
_u.mutation.AppendDirs(v)
|
|
return _u
|
|
}
|
|
|
|
// SetInts sets the "ints" field.
|
|
func (_u *UserUpdateOne) SetInts(v []int) *UserUpdateOne {
|
|
_u.mutation.SetInts(v)
|
|
return _u
|
|
}
|
|
|
|
// AppendInts appends value to the "ints" field.
|
|
func (_u *UserUpdateOne) AppendInts(v []int) *UserUpdateOne {
|
|
_u.mutation.AppendInts(v)
|
|
return _u
|
|
}
|
|
|
|
// ClearInts clears the value of the "ints" field.
|
|
func (_u *UserUpdateOne) ClearInts() *UserUpdateOne {
|
|
_u.mutation.ClearInts()
|
|
return _u
|
|
}
|
|
|
|
// SetFloats sets the "floats" field.
|
|
func (_u *UserUpdateOne) SetFloats(v []float64) *UserUpdateOne {
|
|
_u.mutation.SetFloats(v)
|
|
return _u
|
|
}
|
|
|
|
// AppendFloats appends value to the "floats" field.
|
|
func (_u *UserUpdateOne) AppendFloats(v []float64) *UserUpdateOne {
|
|
_u.mutation.AppendFloats(v)
|
|
return _u
|
|
}
|
|
|
|
// ClearFloats clears the value of the "floats" field.
|
|
func (_u *UserUpdateOne) ClearFloats() *UserUpdateOne {
|
|
_u.mutation.ClearFloats()
|
|
return _u
|
|
}
|
|
|
|
// SetStrings sets the "strings" field.
|
|
func (_u *UserUpdateOne) SetStrings(v []string) *UserUpdateOne {
|
|
_u.mutation.SetStrings(v)
|
|
return _u
|
|
}
|
|
|
|
// AppendStrings appends value to the "strings" field.
|
|
func (_u *UserUpdateOne) AppendStrings(v []string) *UserUpdateOne {
|
|
_u.mutation.AppendStrings(v)
|
|
return _u
|
|
}
|
|
|
|
// ClearStrings clears the value of the "strings" field.
|
|
func (_u *UserUpdateOne) ClearStrings() *UserUpdateOne {
|
|
_u.mutation.ClearStrings()
|
|
return _u
|
|
}
|
|
|
|
// SetIntsValidate sets the "ints_validate" field.
|
|
func (_u *UserUpdateOne) SetIntsValidate(v []int) *UserUpdateOne {
|
|
_u.mutation.SetIntsValidate(v)
|
|
return _u
|
|
}
|
|
|
|
// AppendIntsValidate appends value to the "ints_validate" field.
|
|
func (_u *UserUpdateOne) AppendIntsValidate(v []int) *UserUpdateOne {
|
|
_u.mutation.AppendIntsValidate(v)
|
|
return _u
|
|
}
|
|
|
|
// ClearIntsValidate clears the value of the "ints_validate" field.
|
|
func (_u *UserUpdateOne) ClearIntsValidate() *UserUpdateOne {
|
|
_u.mutation.ClearIntsValidate()
|
|
return _u
|
|
}
|
|
|
|
// SetFloatsValidate sets the "floats_validate" field.
|
|
func (_u *UserUpdateOne) SetFloatsValidate(v []float64) *UserUpdateOne {
|
|
_u.mutation.SetFloatsValidate(v)
|
|
return _u
|
|
}
|
|
|
|
// AppendFloatsValidate appends value to the "floats_validate" field.
|
|
func (_u *UserUpdateOne) AppendFloatsValidate(v []float64) *UserUpdateOne {
|
|
_u.mutation.AppendFloatsValidate(v)
|
|
return _u
|
|
}
|
|
|
|
// ClearFloatsValidate clears the value of the "floats_validate" field.
|
|
func (_u *UserUpdateOne) ClearFloatsValidate() *UserUpdateOne {
|
|
_u.mutation.ClearFloatsValidate()
|
|
return _u
|
|
}
|
|
|
|
// SetStringsValidate sets the "strings_validate" field.
|
|
func (_u *UserUpdateOne) SetStringsValidate(v []string) *UserUpdateOne {
|
|
_u.mutation.SetStringsValidate(v)
|
|
return _u
|
|
}
|
|
|
|
// AppendStringsValidate appends value to the "strings_validate" field.
|
|
func (_u *UserUpdateOne) AppendStringsValidate(v []string) *UserUpdateOne {
|
|
_u.mutation.AppendStringsValidate(v)
|
|
return _u
|
|
}
|
|
|
|
// ClearStringsValidate clears the value of the "strings_validate" field.
|
|
func (_u *UserUpdateOne) ClearStringsValidate() *UserUpdateOne {
|
|
_u.mutation.ClearStringsValidate()
|
|
return _u
|
|
}
|
|
|
|
// SetAddr sets the "addr" field.
|
|
func (_u *UserUpdateOne) SetAddr(v schema.Addr) *UserUpdateOne {
|
|
_u.mutation.SetAddr(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableAddr sets the "addr" field if the given value is not nil.
|
|
func (_u *UserUpdateOne) SetNillableAddr(v *schema.Addr) *UserUpdateOne {
|
|
if v != nil {
|
|
_u.SetAddr(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearAddr clears the value of the "addr" field.
|
|
func (_u *UserUpdateOne) ClearAddr() *UserUpdateOne {
|
|
_u.mutation.ClearAddr()
|
|
return _u
|
|
}
|
|
|
|
// SetUnknown sets the "unknown" field.
|
|
func (_u *UserUpdateOne) SetUnknown(v any) *UserUpdateOne {
|
|
_u.mutation.SetUnknown(v)
|
|
return _u
|
|
}
|
|
|
|
// ClearUnknown clears the value of the "unknown" field.
|
|
func (_u *UserUpdateOne) ClearUnknown() *UserUpdateOne {
|
|
_u.mutation.ClearUnknown()
|
|
return _u
|
|
}
|
|
|
|
// Mutation returns the UserMutation object of the builder.
|
|
func (_u *UserUpdateOne) Mutation() *UserMutation {
|
|
return _u.mutation
|
|
}
|
|
|
|
// 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.IntsValidate(); ok {
|
|
if err := user.IntsValidateValidator(v); err != nil {
|
|
return &ValidationError{Name: "ints_validate", err: fmt.Errorf(`ent: validator failed for field "User.ints_validate": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.FloatsValidate(); ok {
|
|
if err := user.FloatsValidateValidator(v); err != nil {
|
|
return &ValidationError{Name: "floats_validate", err: fmt.Errorf(`ent: validator failed for field "User.floats_validate": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.StringsValidate(); ok {
|
|
if err := user.StringsValidateValidator(v); err != nil {
|
|
return &ValidationError{Name: "strings_validate", err: fmt.Errorf(`ent: validator failed for field "User.strings_validate": %w`, err)}
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
|
|
func (_u *UserUpdateOne) Modify(modifiers ...func(u *sql.UpdateBuilder)) *UserUpdateOne {
|
|
_u.modifiers = append(_u.modifiers, modifiers...)
|
|
return _u
|
|
}
|
|
|
|
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(`ent: 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("ent: 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.T(); ok {
|
|
_spec.SetField(user.FieldT, field.TypeJSON, value)
|
|
}
|
|
if _u.mutation.TCleared() {
|
|
_spec.ClearField(user.FieldT, field.TypeJSON)
|
|
}
|
|
if value, ok := _u.mutation.URL(); ok {
|
|
_spec.SetField(user.FieldURL, field.TypeJSON, value)
|
|
}
|
|
if _u.mutation.URLCleared() {
|
|
_spec.ClearField(user.FieldURL, field.TypeJSON)
|
|
}
|
|
if value, ok := _u.mutation.URLs(); ok {
|
|
_spec.SetField(user.FieldURLs, field.TypeJSON, value)
|
|
}
|
|
if value, ok := _u.mutation.AppendedURLs(); ok {
|
|
_spec.AddModifier(func(u *sql.UpdateBuilder) {
|
|
sqljson.Append(u, user.FieldURLs, value)
|
|
})
|
|
}
|
|
if _u.mutation.URLsCleared() {
|
|
_spec.ClearField(user.FieldURLs, field.TypeJSON)
|
|
}
|
|
if value, ok := _u.mutation.Raw(); ok {
|
|
_spec.SetField(user.FieldRaw, field.TypeJSON, value)
|
|
}
|
|
if value, ok := _u.mutation.AppendedRaw(); ok {
|
|
_spec.AddModifier(func(u *sql.UpdateBuilder) {
|
|
sqljson.Append(u, user.FieldRaw, value)
|
|
})
|
|
}
|
|
if _u.mutation.RawCleared() {
|
|
_spec.ClearField(user.FieldRaw, field.TypeJSON)
|
|
}
|
|
if value, ok := _u.mutation.Dirs(); ok {
|
|
_spec.SetField(user.FieldDirs, field.TypeJSON, value)
|
|
}
|
|
if value, ok := _u.mutation.AppendedDirs(); ok {
|
|
_spec.AddModifier(func(u *sql.UpdateBuilder) {
|
|
sqljson.Append(u, user.FieldDirs, value)
|
|
})
|
|
}
|
|
if value, ok := _u.mutation.Ints(); ok {
|
|
_spec.SetField(user.FieldInts, field.TypeJSON, value)
|
|
}
|
|
if value, ok := _u.mutation.AppendedInts(); ok {
|
|
_spec.AddModifier(func(u *sql.UpdateBuilder) {
|
|
sqljson.Append(u, user.FieldInts, value)
|
|
})
|
|
}
|
|
if _u.mutation.IntsCleared() {
|
|
_spec.ClearField(user.FieldInts, field.TypeJSON)
|
|
}
|
|
if value, ok := _u.mutation.Floats(); ok {
|
|
_spec.SetField(user.FieldFloats, field.TypeJSON, value)
|
|
}
|
|
if value, ok := _u.mutation.AppendedFloats(); ok {
|
|
_spec.AddModifier(func(u *sql.UpdateBuilder) {
|
|
sqljson.Append(u, user.FieldFloats, value)
|
|
})
|
|
}
|
|
if _u.mutation.FloatsCleared() {
|
|
_spec.ClearField(user.FieldFloats, field.TypeJSON)
|
|
}
|
|
if value, ok := _u.mutation.Strings(); ok {
|
|
_spec.SetField(user.FieldStrings, field.TypeJSON, value)
|
|
}
|
|
if value, ok := _u.mutation.AppendedStrings(); ok {
|
|
_spec.AddModifier(func(u *sql.UpdateBuilder) {
|
|
sqljson.Append(u, user.FieldStrings, value)
|
|
})
|
|
}
|
|
if _u.mutation.StringsCleared() {
|
|
_spec.ClearField(user.FieldStrings, field.TypeJSON)
|
|
}
|
|
if value, ok := _u.mutation.IntsValidate(); ok {
|
|
_spec.SetField(user.FieldIntsValidate, field.TypeJSON, value)
|
|
}
|
|
if value, ok := _u.mutation.AppendedIntsValidate(); ok {
|
|
_spec.AddModifier(func(u *sql.UpdateBuilder) {
|
|
sqljson.Append(u, user.FieldIntsValidate, value)
|
|
})
|
|
}
|
|
if _u.mutation.IntsValidateCleared() {
|
|
_spec.ClearField(user.FieldIntsValidate, field.TypeJSON)
|
|
}
|
|
if value, ok := _u.mutation.FloatsValidate(); ok {
|
|
_spec.SetField(user.FieldFloatsValidate, field.TypeJSON, value)
|
|
}
|
|
if value, ok := _u.mutation.AppendedFloatsValidate(); ok {
|
|
_spec.AddModifier(func(u *sql.UpdateBuilder) {
|
|
sqljson.Append(u, user.FieldFloatsValidate, value)
|
|
})
|
|
}
|
|
if _u.mutation.FloatsValidateCleared() {
|
|
_spec.ClearField(user.FieldFloatsValidate, field.TypeJSON)
|
|
}
|
|
if value, ok := _u.mutation.StringsValidate(); ok {
|
|
_spec.SetField(user.FieldStringsValidate, field.TypeJSON, value)
|
|
}
|
|
if value, ok := _u.mutation.AppendedStringsValidate(); ok {
|
|
_spec.AddModifier(func(u *sql.UpdateBuilder) {
|
|
sqljson.Append(u, user.FieldStringsValidate, value)
|
|
})
|
|
}
|
|
if _u.mutation.StringsValidateCleared() {
|
|
_spec.ClearField(user.FieldStringsValidate, field.TypeJSON)
|
|
}
|
|
if value, ok := _u.mutation.Addr(); ok {
|
|
_spec.SetField(user.FieldAddr, field.TypeJSON, value)
|
|
}
|
|
if _u.mutation.AddrCleared() {
|
|
_spec.ClearField(user.FieldAddr, field.TypeJSON)
|
|
}
|
|
if value, ok := _u.mutation.Unknown(); ok {
|
|
_spec.SetField(user.FieldUnknown, field.TypeJSON, value)
|
|
}
|
|
if _u.mutation.UnknownCleared() {
|
|
_spec.ClearField(user.FieldUnknown, field.TypeJSON)
|
|
}
|
|
_spec.AddModifiers(_u.modifiers...)
|
|
_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
|
|
}
|