mirror of
https://github.com/ent/ent.git
synced 2026-05-24 09:31:56 +03:00
484 lines
11 KiB
Go
484 lines
11 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 ent
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"net/http"
|
|
"net/url"
|
|
|
|
"github.com/facebookincubator/ent/dialect/sql"
|
|
"github.com/facebookincubator/ent/dialect/sql/sqlgraph"
|
|
"github.com/facebookincubator/ent/entc/integration/json/ent/predicate"
|
|
"github.com/facebookincubator/ent/entc/integration/json/ent/user"
|
|
"github.com/facebookincubator/ent/schema/field"
|
|
)
|
|
|
|
// UserUpdate is the builder for updating User entities.
|
|
type UserUpdate struct {
|
|
config
|
|
url **url.URL
|
|
clearurl bool
|
|
raw *json.RawMessage
|
|
clearraw bool
|
|
dirs *[]http.Dir
|
|
cleardirs bool
|
|
ints *[]int
|
|
clearints bool
|
|
floats *[]float64
|
|
clearfloats bool
|
|
strings *[]string
|
|
clearstrings 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
|
|
}
|
|
|
|
// SetURL sets the url field.
|
|
func (uu *UserUpdate) SetURL(u *url.URL) *UserUpdate {
|
|
uu.url = &u
|
|
return uu
|
|
}
|
|
|
|
// ClearURL clears the value of url.
|
|
func (uu *UserUpdate) ClearURL() *UserUpdate {
|
|
uu.url = nil
|
|
uu.clearurl = true
|
|
return uu
|
|
}
|
|
|
|
// SetRaw sets the raw field.
|
|
func (uu *UserUpdate) SetRaw(jm json.RawMessage) *UserUpdate {
|
|
uu.raw = &jm
|
|
return uu
|
|
}
|
|
|
|
// ClearRaw clears the value of raw.
|
|
func (uu *UserUpdate) ClearRaw() *UserUpdate {
|
|
uu.raw = nil
|
|
uu.clearraw = true
|
|
return uu
|
|
}
|
|
|
|
// SetDirs sets the dirs field.
|
|
func (uu *UserUpdate) SetDirs(h []http.Dir) *UserUpdate {
|
|
uu.dirs = &h
|
|
return uu
|
|
}
|
|
|
|
// ClearDirs clears the value of dirs.
|
|
func (uu *UserUpdate) ClearDirs() *UserUpdate {
|
|
uu.dirs = nil
|
|
uu.cleardirs = true
|
|
return uu
|
|
}
|
|
|
|
// SetInts sets the ints field.
|
|
func (uu *UserUpdate) SetInts(i []int) *UserUpdate {
|
|
uu.ints = &i
|
|
return uu
|
|
}
|
|
|
|
// ClearInts clears the value of ints.
|
|
func (uu *UserUpdate) ClearInts() *UserUpdate {
|
|
uu.ints = nil
|
|
uu.clearints = true
|
|
return uu
|
|
}
|
|
|
|
// SetFloats sets the floats field.
|
|
func (uu *UserUpdate) SetFloats(f []float64) *UserUpdate {
|
|
uu.floats = &f
|
|
return uu
|
|
}
|
|
|
|
// ClearFloats clears the value of floats.
|
|
func (uu *UserUpdate) ClearFloats() *UserUpdate {
|
|
uu.floats = nil
|
|
uu.clearfloats = true
|
|
return uu
|
|
}
|
|
|
|
// SetStrings sets the strings field.
|
|
func (uu *UserUpdate) SetStrings(s []string) *UserUpdate {
|
|
uu.strings = &s
|
|
return uu
|
|
}
|
|
|
|
// ClearStrings clears the value of strings.
|
|
func (uu *UserUpdate) ClearStrings() *UserUpdate {
|
|
uu.strings = nil
|
|
uu.clearstrings = 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) {
|
|
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.url; value != nil {
|
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
|
Type: field.TypeJSON,
|
|
Value: *value,
|
|
Column: user.FieldURL,
|
|
})
|
|
}
|
|
if uu.clearurl {
|
|
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
|
|
Type: field.TypeJSON,
|
|
Column: user.FieldURL,
|
|
})
|
|
}
|
|
if value := uu.raw; value != nil {
|
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
|
Type: field.TypeJSON,
|
|
Value: *value,
|
|
Column: user.FieldRaw,
|
|
})
|
|
}
|
|
if uu.clearraw {
|
|
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
|
|
Type: field.TypeJSON,
|
|
Column: user.FieldRaw,
|
|
})
|
|
}
|
|
if value := uu.dirs; value != nil {
|
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
|
Type: field.TypeJSON,
|
|
Value: *value,
|
|
Column: user.FieldDirs,
|
|
})
|
|
}
|
|
if uu.cleardirs {
|
|
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
|
|
Type: field.TypeJSON,
|
|
Column: user.FieldDirs,
|
|
})
|
|
}
|
|
if value := uu.ints; value != nil {
|
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
|
Type: field.TypeJSON,
|
|
Value: *value,
|
|
Column: user.FieldInts,
|
|
})
|
|
}
|
|
if uu.clearints {
|
|
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
|
|
Type: field.TypeJSON,
|
|
Column: user.FieldInts,
|
|
})
|
|
}
|
|
if value := uu.floats; value != nil {
|
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
|
Type: field.TypeJSON,
|
|
Value: *value,
|
|
Column: user.FieldFloats,
|
|
})
|
|
}
|
|
if uu.clearfloats {
|
|
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
|
|
Type: field.TypeJSON,
|
|
Column: user.FieldFloats,
|
|
})
|
|
}
|
|
if value := uu.strings; value != nil {
|
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
|
Type: field.TypeJSON,
|
|
Value: *value,
|
|
Column: user.FieldStrings,
|
|
})
|
|
}
|
|
if uu.clearstrings {
|
|
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
|
|
Type: field.TypeJSON,
|
|
Column: user.FieldStrings,
|
|
})
|
|
}
|
|
if n, err = sqlgraph.UpdateNodes(ctx, uu.driver, _spec); err != nil {
|
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
|
err = &NotFoundError{user.Label}
|
|
} else 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
|
|
url **url.URL
|
|
clearurl bool
|
|
raw *json.RawMessage
|
|
clearraw bool
|
|
dirs *[]http.Dir
|
|
cleardirs bool
|
|
ints *[]int
|
|
clearints bool
|
|
floats *[]float64
|
|
clearfloats bool
|
|
strings *[]string
|
|
clearstrings bool
|
|
}
|
|
|
|
// SetURL sets the url field.
|
|
func (uuo *UserUpdateOne) SetURL(u *url.URL) *UserUpdateOne {
|
|
uuo.url = &u
|
|
return uuo
|
|
}
|
|
|
|
// ClearURL clears the value of url.
|
|
func (uuo *UserUpdateOne) ClearURL() *UserUpdateOne {
|
|
uuo.url = nil
|
|
uuo.clearurl = true
|
|
return uuo
|
|
}
|
|
|
|
// SetRaw sets the raw field.
|
|
func (uuo *UserUpdateOne) SetRaw(jm json.RawMessage) *UserUpdateOne {
|
|
uuo.raw = &jm
|
|
return uuo
|
|
}
|
|
|
|
// ClearRaw clears the value of raw.
|
|
func (uuo *UserUpdateOne) ClearRaw() *UserUpdateOne {
|
|
uuo.raw = nil
|
|
uuo.clearraw = true
|
|
return uuo
|
|
}
|
|
|
|
// SetDirs sets the dirs field.
|
|
func (uuo *UserUpdateOne) SetDirs(h []http.Dir) *UserUpdateOne {
|
|
uuo.dirs = &h
|
|
return uuo
|
|
}
|
|
|
|
// ClearDirs clears the value of dirs.
|
|
func (uuo *UserUpdateOne) ClearDirs() *UserUpdateOne {
|
|
uuo.dirs = nil
|
|
uuo.cleardirs = true
|
|
return uuo
|
|
}
|
|
|
|
// SetInts sets the ints field.
|
|
func (uuo *UserUpdateOne) SetInts(i []int) *UserUpdateOne {
|
|
uuo.ints = &i
|
|
return uuo
|
|
}
|
|
|
|
// ClearInts clears the value of ints.
|
|
func (uuo *UserUpdateOne) ClearInts() *UserUpdateOne {
|
|
uuo.ints = nil
|
|
uuo.clearints = true
|
|
return uuo
|
|
}
|
|
|
|
// SetFloats sets the floats field.
|
|
func (uuo *UserUpdateOne) SetFloats(f []float64) *UserUpdateOne {
|
|
uuo.floats = &f
|
|
return uuo
|
|
}
|
|
|
|
// ClearFloats clears the value of floats.
|
|
func (uuo *UserUpdateOne) ClearFloats() *UserUpdateOne {
|
|
uuo.floats = nil
|
|
uuo.clearfloats = true
|
|
return uuo
|
|
}
|
|
|
|
// SetStrings sets the strings field.
|
|
func (uuo *UserUpdateOne) SetStrings(s []string) *UserUpdateOne {
|
|
uuo.strings = &s
|
|
return uuo
|
|
}
|
|
|
|
// ClearStrings clears the value of strings.
|
|
func (uuo *UserUpdateOne) ClearStrings() *UserUpdateOne {
|
|
uuo.strings = nil
|
|
uuo.clearstrings = true
|
|
return uuo
|
|
}
|
|
|
|
// Save executes the query and returns the updated entity.
|
|
func (uuo *UserUpdateOne) Save(ctx context.Context) (*User, error) {
|
|
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.url; value != nil {
|
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
|
Type: field.TypeJSON,
|
|
Value: *value,
|
|
Column: user.FieldURL,
|
|
})
|
|
}
|
|
if uuo.clearurl {
|
|
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
|
|
Type: field.TypeJSON,
|
|
Column: user.FieldURL,
|
|
})
|
|
}
|
|
if value := uuo.raw; value != nil {
|
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
|
Type: field.TypeJSON,
|
|
Value: *value,
|
|
Column: user.FieldRaw,
|
|
})
|
|
}
|
|
if uuo.clearraw {
|
|
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
|
|
Type: field.TypeJSON,
|
|
Column: user.FieldRaw,
|
|
})
|
|
}
|
|
if value := uuo.dirs; value != nil {
|
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
|
Type: field.TypeJSON,
|
|
Value: *value,
|
|
Column: user.FieldDirs,
|
|
})
|
|
}
|
|
if uuo.cleardirs {
|
|
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
|
|
Type: field.TypeJSON,
|
|
Column: user.FieldDirs,
|
|
})
|
|
}
|
|
if value := uuo.ints; value != nil {
|
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
|
Type: field.TypeJSON,
|
|
Value: *value,
|
|
Column: user.FieldInts,
|
|
})
|
|
}
|
|
if uuo.clearints {
|
|
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
|
|
Type: field.TypeJSON,
|
|
Column: user.FieldInts,
|
|
})
|
|
}
|
|
if value := uuo.floats; value != nil {
|
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
|
Type: field.TypeJSON,
|
|
Value: *value,
|
|
Column: user.FieldFloats,
|
|
})
|
|
}
|
|
if uuo.clearfloats {
|
|
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
|
|
Type: field.TypeJSON,
|
|
Column: user.FieldFloats,
|
|
})
|
|
}
|
|
if value := uuo.strings; value != nil {
|
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
|
Type: field.TypeJSON,
|
|
Value: *value,
|
|
Column: user.FieldStrings,
|
|
})
|
|
}
|
|
if uuo.clearstrings {
|
|
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
|
|
Type: field.TypeJSON,
|
|
Column: user.FieldStrings,
|
|
})
|
|
}
|
|
u = &User{config: uuo.config}
|
|
_spec.Assign = u.assignValues
|
|
_spec.ScanValues = u.scanValues()
|
|
if err = sqlgraph.UpdateNode(ctx, uuo.driver, _spec); err != nil {
|
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
|
err = &NotFoundError{user.Label}
|
|
} else if cerr, ok := isSQLConstraintError(err); ok {
|
|
err = cerr
|
|
}
|
|
return nil, err
|
|
}
|
|
return u, nil
|
|
}
|