533 lines
15 KiB
Go
533 lines
15 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"
|
|
"errors"
|
|
"fmt"
|
|
|
|
"entgo.io/ent/dialect/sql"
|
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
|
"entgo.io/ent/entc/integration/ent/comment"
|
|
"entgo.io/ent/entc/integration/ent/predicate"
|
|
schemadir "entgo.io/ent/entc/integration/ent/schema/dir"
|
|
"entgo.io/ent/schema/field"
|
|
)
|
|
|
|
// CommentUpdate is the builder for updating Comment entities.
|
|
type CommentUpdate struct {
|
|
config
|
|
hooks []Hook
|
|
mutation *CommentMutation
|
|
modifiers []func(*sql.UpdateBuilder)
|
|
}
|
|
|
|
// Where appends a list predicates to the CommentUpdate builder.
|
|
func (_u *CommentUpdate) Where(ps ...predicate.Comment) *CommentUpdate {
|
|
_u.mutation.Where(ps...)
|
|
return _u
|
|
}
|
|
|
|
// SetUniqueInt sets the "unique_int" field.
|
|
func (_u *CommentUpdate) SetUniqueInt(v int) *CommentUpdate {
|
|
_u.mutation.ResetUniqueInt()
|
|
_u.mutation.SetUniqueInt(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableUniqueInt sets the "unique_int" field if the given value is not nil.
|
|
func (_u *CommentUpdate) SetNillableUniqueInt(v *int) *CommentUpdate {
|
|
if v != nil {
|
|
_u.SetUniqueInt(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// AddUniqueInt adds value to the "unique_int" field.
|
|
func (_u *CommentUpdate) AddUniqueInt(v int) *CommentUpdate {
|
|
_u.mutation.AddUniqueInt(v)
|
|
return _u
|
|
}
|
|
|
|
// SetUniqueFloat sets the "unique_float" field.
|
|
func (_u *CommentUpdate) SetUniqueFloat(v float64) *CommentUpdate {
|
|
_u.mutation.ResetUniqueFloat()
|
|
_u.mutation.SetUniqueFloat(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableUniqueFloat sets the "unique_float" field if the given value is not nil.
|
|
func (_u *CommentUpdate) SetNillableUniqueFloat(v *float64) *CommentUpdate {
|
|
if v != nil {
|
|
_u.SetUniqueFloat(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// AddUniqueFloat adds value to the "unique_float" field.
|
|
func (_u *CommentUpdate) AddUniqueFloat(v float64) *CommentUpdate {
|
|
_u.mutation.AddUniqueFloat(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableInt sets the "nillable_int" field.
|
|
func (_u *CommentUpdate) SetNillableInt(v int) *CommentUpdate {
|
|
_u.mutation.ResetNillableInt()
|
|
_u.mutation.SetNillableInt(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableNillableInt sets the "nillable_int" field if the given value is not nil.
|
|
func (_u *CommentUpdate) SetNillableNillableInt(v *int) *CommentUpdate {
|
|
if v != nil {
|
|
_u.SetNillableInt(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// AddNillableInt adds value to the "nillable_int" field.
|
|
func (_u *CommentUpdate) AddNillableInt(v int) *CommentUpdate {
|
|
_u.mutation.AddNillableInt(v)
|
|
return _u
|
|
}
|
|
|
|
// ClearNillableInt clears the value of the "nillable_int" field.
|
|
func (_u *CommentUpdate) ClearNillableInt() *CommentUpdate {
|
|
_u.mutation.ClearNillableInt()
|
|
return _u
|
|
}
|
|
|
|
// SetTable sets the "table" field.
|
|
func (_u *CommentUpdate) SetTable(v string) *CommentUpdate {
|
|
_u.mutation.SetTable(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableTable sets the "table" field if the given value is not nil.
|
|
func (_u *CommentUpdate) SetNillableTable(v *string) *CommentUpdate {
|
|
if v != nil {
|
|
_u.SetTable(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearTable clears the value of the "table" field.
|
|
func (_u *CommentUpdate) ClearTable() *CommentUpdate {
|
|
_u.mutation.ClearTable()
|
|
return _u
|
|
}
|
|
|
|
// SetDir sets the "dir" field.
|
|
func (_u *CommentUpdate) SetDir(v schemadir.Dir) *CommentUpdate {
|
|
_u.mutation.SetDir(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableDir sets the "dir" field if the given value is not nil.
|
|
func (_u *CommentUpdate) SetNillableDir(v *schemadir.Dir) *CommentUpdate {
|
|
if v != nil {
|
|
_u.SetDir(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearDir clears the value of the "dir" field.
|
|
func (_u *CommentUpdate) ClearDir() *CommentUpdate {
|
|
_u.mutation.ClearDir()
|
|
return _u
|
|
}
|
|
|
|
// SetClient sets the "client" field.
|
|
func (_u *CommentUpdate) SetClient(v string) *CommentUpdate {
|
|
_u.mutation.SetClient(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableClient sets the "client" field if the given value is not nil.
|
|
func (_u *CommentUpdate) SetNillableClient(v *string) *CommentUpdate {
|
|
if v != nil {
|
|
_u.SetClient(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearClient clears the value of the "client" field.
|
|
func (_u *CommentUpdate) ClearClient() *CommentUpdate {
|
|
_u.mutation.ClearClient()
|
|
return _u
|
|
}
|
|
|
|
// Mutation returns the CommentMutation object of the builder.
|
|
func (_u *CommentUpdate) Mutation() *CommentMutation {
|
|
return _u.mutation
|
|
}
|
|
|
|
// Save executes the query and returns the number of nodes affected by the update operation.
|
|
func (_u *CommentUpdate) 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 *CommentUpdate) SaveX(ctx context.Context) int {
|
|
affected, err := _u.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return affected
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_u *CommentUpdate) Exec(ctx context.Context) error {
|
|
_, err := _u.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_u *CommentUpdate) ExecX(ctx context.Context) {
|
|
if err := _u.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
|
|
func (_u *CommentUpdate) Modify(modifiers ...func(u *sql.UpdateBuilder)) *CommentUpdate {
|
|
_u.modifiers = append(_u.modifiers, modifiers...)
|
|
return _u
|
|
}
|
|
|
|
func (_u *CommentUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
|
_spec := sqlgraph.NewUpdateSpec(comment.Table, comment.Columns, sqlgraph.NewFieldSpec(comment.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.UniqueInt(); ok {
|
|
_spec.SetField(comment.FieldUniqueInt, field.TypeInt, value)
|
|
}
|
|
if value, ok := _u.mutation.AddedUniqueInt(); ok {
|
|
_spec.AddField(comment.FieldUniqueInt, field.TypeInt, value)
|
|
}
|
|
if value, ok := _u.mutation.UniqueFloat(); ok {
|
|
_spec.SetField(comment.FieldUniqueFloat, field.TypeFloat64, value)
|
|
}
|
|
if value, ok := _u.mutation.AddedUniqueFloat(); ok {
|
|
_spec.AddField(comment.FieldUniqueFloat, field.TypeFloat64, value)
|
|
}
|
|
if value, ok := _u.mutation.NillableInt(); ok {
|
|
_spec.SetField(comment.FieldNillableInt, field.TypeInt, value)
|
|
}
|
|
if value, ok := _u.mutation.AddedNillableInt(); ok {
|
|
_spec.AddField(comment.FieldNillableInt, field.TypeInt, value)
|
|
}
|
|
if _u.mutation.NillableIntCleared() {
|
|
_spec.ClearField(comment.FieldNillableInt, field.TypeInt)
|
|
}
|
|
if value, ok := _u.mutation.Table(); ok {
|
|
_spec.SetField(comment.FieldTable, field.TypeString, value)
|
|
}
|
|
if _u.mutation.TableCleared() {
|
|
_spec.ClearField(comment.FieldTable, field.TypeString)
|
|
}
|
|
if value, ok := _u.mutation.Dir(); ok {
|
|
_spec.SetField(comment.FieldDir, field.TypeJSON, value)
|
|
}
|
|
if _u.mutation.DirCleared() {
|
|
_spec.ClearField(comment.FieldDir, field.TypeJSON)
|
|
}
|
|
if value, ok := _u.mutation.GetClient(); ok {
|
|
_spec.SetField(comment.FieldClient, field.TypeString, value)
|
|
}
|
|
if _u.mutation.ClientCleared() {
|
|
_spec.ClearField(comment.FieldClient, field.TypeString)
|
|
}
|
|
_spec.AddModifiers(_u.modifiers...)
|
|
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
|
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
|
err = &NotFoundError{comment.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return 0, err
|
|
}
|
|
_u.mutation.done = true
|
|
return _node, nil
|
|
}
|
|
|
|
// CommentUpdateOne is the builder for updating a single Comment entity.
|
|
type CommentUpdateOne struct {
|
|
config
|
|
fields []string
|
|
hooks []Hook
|
|
mutation *CommentMutation
|
|
modifiers []func(*sql.UpdateBuilder)
|
|
}
|
|
|
|
// SetUniqueInt sets the "unique_int" field.
|
|
func (_u *CommentUpdateOne) SetUniqueInt(v int) *CommentUpdateOne {
|
|
_u.mutation.ResetUniqueInt()
|
|
_u.mutation.SetUniqueInt(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableUniqueInt sets the "unique_int" field if the given value is not nil.
|
|
func (_u *CommentUpdateOne) SetNillableUniqueInt(v *int) *CommentUpdateOne {
|
|
if v != nil {
|
|
_u.SetUniqueInt(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// AddUniqueInt adds value to the "unique_int" field.
|
|
func (_u *CommentUpdateOne) AddUniqueInt(v int) *CommentUpdateOne {
|
|
_u.mutation.AddUniqueInt(v)
|
|
return _u
|
|
}
|
|
|
|
// SetUniqueFloat sets the "unique_float" field.
|
|
func (_u *CommentUpdateOne) SetUniqueFloat(v float64) *CommentUpdateOne {
|
|
_u.mutation.ResetUniqueFloat()
|
|
_u.mutation.SetUniqueFloat(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableUniqueFloat sets the "unique_float" field if the given value is not nil.
|
|
func (_u *CommentUpdateOne) SetNillableUniqueFloat(v *float64) *CommentUpdateOne {
|
|
if v != nil {
|
|
_u.SetUniqueFloat(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// AddUniqueFloat adds value to the "unique_float" field.
|
|
func (_u *CommentUpdateOne) AddUniqueFloat(v float64) *CommentUpdateOne {
|
|
_u.mutation.AddUniqueFloat(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableInt sets the "nillable_int" field.
|
|
func (_u *CommentUpdateOne) SetNillableInt(v int) *CommentUpdateOne {
|
|
_u.mutation.ResetNillableInt()
|
|
_u.mutation.SetNillableInt(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableNillableInt sets the "nillable_int" field if the given value is not nil.
|
|
func (_u *CommentUpdateOne) SetNillableNillableInt(v *int) *CommentUpdateOne {
|
|
if v != nil {
|
|
_u.SetNillableInt(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// AddNillableInt adds value to the "nillable_int" field.
|
|
func (_u *CommentUpdateOne) AddNillableInt(v int) *CommentUpdateOne {
|
|
_u.mutation.AddNillableInt(v)
|
|
return _u
|
|
}
|
|
|
|
// ClearNillableInt clears the value of the "nillable_int" field.
|
|
func (_u *CommentUpdateOne) ClearNillableInt() *CommentUpdateOne {
|
|
_u.mutation.ClearNillableInt()
|
|
return _u
|
|
}
|
|
|
|
// SetTable sets the "table" field.
|
|
func (_u *CommentUpdateOne) SetTable(v string) *CommentUpdateOne {
|
|
_u.mutation.SetTable(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableTable sets the "table" field if the given value is not nil.
|
|
func (_u *CommentUpdateOne) SetNillableTable(v *string) *CommentUpdateOne {
|
|
if v != nil {
|
|
_u.SetTable(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearTable clears the value of the "table" field.
|
|
func (_u *CommentUpdateOne) ClearTable() *CommentUpdateOne {
|
|
_u.mutation.ClearTable()
|
|
return _u
|
|
}
|
|
|
|
// SetDir sets the "dir" field.
|
|
func (_u *CommentUpdateOne) SetDir(v schemadir.Dir) *CommentUpdateOne {
|
|
_u.mutation.SetDir(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableDir sets the "dir" field if the given value is not nil.
|
|
func (_u *CommentUpdateOne) SetNillableDir(v *schemadir.Dir) *CommentUpdateOne {
|
|
if v != nil {
|
|
_u.SetDir(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearDir clears the value of the "dir" field.
|
|
func (_u *CommentUpdateOne) ClearDir() *CommentUpdateOne {
|
|
_u.mutation.ClearDir()
|
|
return _u
|
|
}
|
|
|
|
// SetClient sets the "client" field.
|
|
func (_u *CommentUpdateOne) SetClient(v string) *CommentUpdateOne {
|
|
_u.mutation.SetClient(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableClient sets the "client" field if the given value is not nil.
|
|
func (_u *CommentUpdateOne) SetNillableClient(v *string) *CommentUpdateOne {
|
|
if v != nil {
|
|
_u.SetClient(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearClient clears the value of the "client" field.
|
|
func (_u *CommentUpdateOne) ClearClient() *CommentUpdateOne {
|
|
_u.mutation.ClearClient()
|
|
return _u
|
|
}
|
|
|
|
// Mutation returns the CommentMutation object of the builder.
|
|
func (_u *CommentUpdateOne) Mutation() *CommentMutation {
|
|
return _u.mutation
|
|
}
|
|
|
|
// Where appends a list predicates to the CommentUpdate builder.
|
|
func (_u *CommentUpdateOne) Where(ps ...predicate.Comment) *CommentUpdateOne {
|
|
_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 *CommentUpdateOne) Select(field string, fields ...string) *CommentUpdateOne {
|
|
_u.fields = append([]string{field}, fields...)
|
|
return _u
|
|
}
|
|
|
|
// Save executes the query and returns the updated Comment entity.
|
|
func (_u *CommentUpdateOne) Save(ctx context.Context) (*Comment, error) {
|
|
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (_u *CommentUpdateOne) SaveX(ctx context.Context) *Comment {
|
|
node, err := _u.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return node
|
|
}
|
|
|
|
// Exec executes the query on the entity.
|
|
func (_u *CommentUpdateOne) Exec(ctx context.Context) error {
|
|
_, err := _u.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_u *CommentUpdateOne) ExecX(ctx context.Context) {
|
|
if err := _u.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
|
|
func (_u *CommentUpdateOne) Modify(modifiers ...func(u *sql.UpdateBuilder)) *CommentUpdateOne {
|
|
_u.modifiers = append(_u.modifiers, modifiers...)
|
|
return _u
|
|
}
|
|
|
|
func (_u *CommentUpdateOne) sqlSave(ctx context.Context) (_node *Comment, err error) {
|
|
_spec := sqlgraph.NewUpdateSpec(comment.Table, comment.Columns, sqlgraph.NewFieldSpec(comment.FieldID, field.TypeInt))
|
|
id, ok := _u.mutation.ID()
|
|
if !ok {
|
|
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Comment.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, comment.FieldID)
|
|
for _, f := range fields {
|
|
if !comment.ValidColumn(f) {
|
|
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
|
}
|
|
if f != comment.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.UniqueInt(); ok {
|
|
_spec.SetField(comment.FieldUniqueInt, field.TypeInt, value)
|
|
}
|
|
if value, ok := _u.mutation.AddedUniqueInt(); ok {
|
|
_spec.AddField(comment.FieldUniqueInt, field.TypeInt, value)
|
|
}
|
|
if value, ok := _u.mutation.UniqueFloat(); ok {
|
|
_spec.SetField(comment.FieldUniqueFloat, field.TypeFloat64, value)
|
|
}
|
|
if value, ok := _u.mutation.AddedUniqueFloat(); ok {
|
|
_spec.AddField(comment.FieldUniqueFloat, field.TypeFloat64, value)
|
|
}
|
|
if value, ok := _u.mutation.NillableInt(); ok {
|
|
_spec.SetField(comment.FieldNillableInt, field.TypeInt, value)
|
|
}
|
|
if value, ok := _u.mutation.AddedNillableInt(); ok {
|
|
_spec.AddField(comment.FieldNillableInt, field.TypeInt, value)
|
|
}
|
|
if _u.mutation.NillableIntCleared() {
|
|
_spec.ClearField(comment.FieldNillableInt, field.TypeInt)
|
|
}
|
|
if value, ok := _u.mutation.Table(); ok {
|
|
_spec.SetField(comment.FieldTable, field.TypeString, value)
|
|
}
|
|
if _u.mutation.TableCleared() {
|
|
_spec.ClearField(comment.FieldTable, field.TypeString)
|
|
}
|
|
if value, ok := _u.mutation.Dir(); ok {
|
|
_spec.SetField(comment.FieldDir, field.TypeJSON, value)
|
|
}
|
|
if _u.mutation.DirCleared() {
|
|
_spec.ClearField(comment.FieldDir, field.TypeJSON)
|
|
}
|
|
if value, ok := _u.mutation.GetClient(); ok {
|
|
_spec.SetField(comment.FieldClient, field.TypeString, value)
|
|
}
|
|
if _u.mutation.ClientCleared() {
|
|
_spec.ClearField(comment.FieldClient, field.TypeString)
|
|
}
|
|
_spec.AddModifiers(_u.modifiers...)
|
|
_node = &Comment{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{comment.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return nil, err
|
|
}
|
|
_u.mutation.done = true
|
|
return _node, nil
|
|
}
|