503 lines
14 KiB
Go
503 lines
14 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/customid/ent/note"
|
|
"entgo.io/ent/entc/integration/customid/ent/predicate"
|
|
"entgo.io/ent/entc/integration/customid/ent/schema"
|
|
"entgo.io/ent/schema/field"
|
|
)
|
|
|
|
// NoteUpdate is the builder for updating Note entities.
|
|
type NoteUpdate struct {
|
|
config
|
|
hooks []Hook
|
|
mutation *NoteMutation
|
|
}
|
|
|
|
// Where appends a list predicates to the NoteUpdate builder.
|
|
func (_u *NoteUpdate) Where(ps ...predicate.Note) *NoteUpdate {
|
|
_u.mutation.Where(ps...)
|
|
return _u
|
|
}
|
|
|
|
// SetText sets the "text" field.
|
|
func (_u *NoteUpdate) SetText(v string) *NoteUpdate {
|
|
_u.mutation.SetText(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableText sets the "text" field if the given value is not nil.
|
|
func (_u *NoteUpdate) SetNillableText(v *string) *NoteUpdate {
|
|
if v != nil {
|
|
_u.SetText(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearText clears the value of the "text" field.
|
|
func (_u *NoteUpdate) ClearText() *NoteUpdate {
|
|
_u.mutation.ClearText()
|
|
return _u
|
|
}
|
|
|
|
// SetParentID sets the "parent" edge to the Note entity by ID.
|
|
func (_u *NoteUpdate) SetParentID(id schema.NoteID) *NoteUpdate {
|
|
_u.mutation.SetParentID(id)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableParentID sets the "parent" edge to the Note entity by ID if the given value is not nil.
|
|
func (_u *NoteUpdate) SetNillableParentID(id *schema.NoteID) *NoteUpdate {
|
|
if id != nil {
|
|
_u = _u.SetParentID(*id)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetParent sets the "parent" edge to the Note entity.
|
|
func (_u *NoteUpdate) SetParent(v *Note) *NoteUpdate {
|
|
return _u.SetParentID(v.ID)
|
|
}
|
|
|
|
// AddChildIDs adds the "children" edge to the Note entity by IDs.
|
|
func (_u *NoteUpdate) AddChildIDs(ids ...schema.NoteID) *NoteUpdate {
|
|
_u.mutation.AddChildIDs(ids...)
|
|
return _u
|
|
}
|
|
|
|
// AddChildren adds the "children" edges to the Note entity.
|
|
func (_u *NoteUpdate) AddChildren(v ...*Note) *NoteUpdate {
|
|
ids := make([]schema.NoteID, len(v))
|
|
for i := range v {
|
|
ids[i] = v[i].ID
|
|
}
|
|
return _u.AddChildIDs(ids...)
|
|
}
|
|
|
|
// Mutation returns the NoteMutation object of the builder.
|
|
func (_u *NoteUpdate) Mutation() *NoteMutation {
|
|
return _u.mutation
|
|
}
|
|
|
|
// ClearParent clears the "parent" edge to the Note entity.
|
|
func (_u *NoteUpdate) ClearParent() *NoteUpdate {
|
|
_u.mutation.ClearParent()
|
|
return _u
|
|
}
|
|
|
|
// ClearChildren clears all "children" edges to the Note entity.
|
|
func (_u *NoteUpdate) ClearChildren() *NoteUpdate {
|
|
_u.mutation.ClearChildren()
|
|
return _u
|
|
}
|
|
|
|
// RemoveChildIDs removes the "children" edge to Note entities by IDs.
|
|
func (_u *NoteUpdate) RemoveChildIDs(ids ...schema.NoteID) *NoteUpdate {
|
|
_u.mutation.RemoveChildIDs(ids...)
|
|
return _u
|
|
}
|
|
|
|
// RemoveChildren removes "children" edges to Note entities.
|
|
func (_u *NoteUpdate) RemoveChildren(v ...*Note) *NoteUpdate {
|
|
ids := make([]schema.NoteID, len(v))
|
|
for i := range v {
|
|
ids[i] = v[i].ID
|
|
}
|
|
return _u.RemoveChildIDs(ids...)
|
|
}
|
|
|
|
// Save executes the query and returns the number of nodes affected by the update operation.
|
|
func (_u *NoteUpdate) 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 *NoteUpdate) SaveX(ctx context.Context) int {
|
|
affected, err := _u.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return affected
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_u *NoteUpdate) Exec(ctx context.Context) error {
|
|
_, err := _u.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_u *NoteUpdate) ExecX(ctx context.Context) {
|
|
if err := _u.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
func (_u *NoteUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
|
_spec := sqlgraph.NewUpdateSpec(note.Table, note.Columns, sqlgraph.NewFieldSpec(note.FieldID, field.TypeString))
|
|
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.Text(); ok {
|
|
_spec.SetField(note.FieldText, field.TypeString, value)
|
|
}
|
|
if _u.mutation.TextCleared() {
|
|
_spec.ClearField(note.FieldText, field.TypeString)
|
|
}
|
|
if _u.mutation.ParentCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: note.ParentTable,
|
|
Columns: []string{note.ParentColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(note.FieldID, field.TypeString),
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := _u.mutation.ParentIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: note.ParentTable,
|
|
Columns: []string{note.ParentColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(note.FieldID, field.TypeString),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
|
}
|
|
if _u.mutation.ChildrenCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: note.ChildrenTable,
|
|
Columns: []string{note.ChildrenColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(note.FieldID, field.TypeString),
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := _u.mutation.RemovedChildrenIDs(); len(nodes) > 0 && !_u.mutation.ChildrenCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: note.ChildrenTable,
|
|
Columns: []string{note.ChildrenColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(note.FieldID, field.TypeString),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := _u.mutation.ChildrenIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: note.ChildrenTable,
|
|
Columns: []string{note.ChildrenColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(note.FieldID, field.TypeString),
|
|
},
|
|
}
|
|
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{note.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return 0, err
|
|
}
|
|
_u.mutation.done = true
|
|
return _node, nil
|
|
}
|
|
|
|
// NoteUpdateOne is the builder for updating a single Note entity.
|
|
type NoteUpdateOne struct {
|
|
config
|
|
fields []string
|
|
hooks []Hook
|
|
mutation *NoteMutation
|
|
}
|
|
|
|
// SetText sets the "text" field.
|
|
func (_u *NoteUpdateOne) SetText(v string) *NoteUpdateOne {
|
|
_u.mutation.SetText(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableText sets the "text" field if the given value is not nil.
|
|
func (_u *NoteUpdateOne) SetNillableText(v *string) *NoteUpdateOne {
|
|
if v != nil {
|
|
_u.SetText(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearText clears the value of the "text" field.
|
|
func (_u *NoteUpdateOne) ClearText() *NoteUpdateOne {
|
|
_u.mutation.ClearText()
|
|
return _u
|
|
}
|
|
|
|
// SetParentID sets the "parent" edge to the Note entity by ID.
|
|
func (_u *NoteUpdateOne) SetParentID(id schema.NoteID) *NoteUpdateOne {
|
|
_u.mutation.SetParentID(id)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableParentID sets the "parent" edge to the Note entity by ID if the given value is not nil.
|
|
func (_u *NoteUpdateOne) SetNillableParentID(id *schema.NoteID) *NoteUpdateOne {
|
|
if id != nil {
|
|
_u = _u.SetParentID(*id)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetParent sets the "parent" edge to the Note entity.
|
|
func (_u *NoteUpdateOne) SetParent(v *Note) *NoteUpdateOne {
|
|
return _u.SetParentID(v.ID)
|
|
}
|
|
|
|
// AddChildIDs adds the "children" edge to the Note entity by IDs.
|
|
func (_u *NoteUpdateOne) AddChildIDs(ids ...schema.NoteID) *NoteUpdateOne {
|
|
_u.mutation.AddChildIDs(ids...)
|
|
return _u
|
|
}
|
|
|
|
// AddChildren adds the "children" edges to the Note entity.
|
|
func (_u *NoteUpdateOne) AddChildren(v ...*Note) *NoteUpdateOne {
|
|
ids := make([]schema.NoteID, len(v))
|
|
for i := range v {
|
|
ids[i] = v[i].ID
|
|
}
|
|
return _u.AddChildIDs(ids...)
|
|
}
|
|
|
|
// Mutation returns the NoteMutation object of the builder.
|
|
func (_u *NoteUpdateOne) Mutation() *NoteMutation {
|
|
return _u.mutation
|
|
}
|
|
|
|
// ClearParent clears the "parent" edge to the Note entity.
|
|
func (_u *NoteUpdateOne) ClearParent() *NoteUpdateOne {
|
|
_u.mutation.ClearParent()
|
|
return _u
|
|
}
|
|
|
|
// ClearChildren clears all "children" edges to the Note entity.
|
|
func (_u *NoteUpdateOne) ClearChildren() *NoteUpdateOne {
|
|
_u.mutation.ClearChildren()
|
|
return _u
|
|
}
|
|
|
|
// RemoveChildIDs removes the "children" edge to Note entities by IDs.
|
|
func (_u *NoteUpdateOne) RemoveChildIDs(ids ...schema.NoteID) *NoteUpdateOne {
|
|
_u.mutation.RemoveChildIDs(ids...)
|
|
return _u
|
|
}
|
|
|
|
// RemoveChildren removes "children" edges to Note entities.
|
|
func (_u *NoteUpdateOne) RemoveChildren(v ...*Note) *NoteUpdateOne {
|
|
ids := make([]schema.NoteID, len(v))
|
|
for i := range v {
|
|
ids[i] = v[i].ID
|
|
}
|
|
return _u.RemoveChildIDs(ids...)
|
|
}
|
|
|
|
// Where appends a list predicates to the NoteUpdate builder.
|
|
func (_u *NoteUpdateOne) Where(ps ...predicate.Note) *NoteUpdateOne {
|
|
_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 *NoteUpdateOne) Select(field string, fields ...string) *NoteUpdateOne {
|
|
_u.fields = append([]string{field}, fields...)
|
|
return _u
|
|
}
|
|
|
|
// Save executes the query and returns the updated Note entity.
|
|
func (_u *NoteUpdateOne) Save(ctx context.Context) (*Note, error) {
|
|
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (_u *NoteUpdateOne) SaveX(ctx context.Context) *Note {
|
|
node, err := _u.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return node
|
|
}
|
|
|
|
// Exec executes the query on the entity.
|
|
func (_u *NoteUpdateOne) Exec(ctx context.Context) error {
|
|
_, err := _u.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_u *NoteUpdateOne) ExecX(ctx context.Context) {
|
|
if err := _u.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
func (_u *NoteUpdateOne) sqlSave(ctx context.Context) (_node *Note, err error) {
|
|
_spec := sqlgraph.NewUpdateSpec(note.Table, note.Columns, sqlgraph.NewFieldSpec(note.FieldID, field.TypeString))
|
|
id, ok := _u.mutation.ID()
|
|
if !ok {
|
|
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Note.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, note.FieldID)
|
|
for _, f := range fields {
|
|
if !note.ValidColumn(f) {
|
|
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
|
}
|
|
if f != note.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.Text(); ok {
|
|
_spec.SetField(note.FieldText, field.TypeString, value)
|
|
}
|
|
if _u.mutation.TextCleared() {
|
|
_spec.ClearField(note.FieldText, field.TypeString)
|
|
}
|
|
if _u.mutation.ParentCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: note.ParentTable,
|
|
Columns: []string{note.ParentColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(note.FieldID, field.TypeString),
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := _u.mutation.ParentIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: note.ParentTable,
|
|
Columns: []string{note.ParentColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(note.FieldID, field.TypeString),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
|
}
|
|
if _u.mutation.ChildrenCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: note.ChildrenTable,
|
|
Columns: []string{note.ChildrenColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(note.FieldID, field.TypeString),
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := _u.mutation.RemovedChildrenIDs(); len(nodes) > 0 && !_u.mutation.ChildrenCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: note.ChildrenTable,
|
|
Columns: []string{note.ChildrenColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(note.FieldID, field.TypeString),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := _u.mutation.ChildrenIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: note.ChildrenTable,
|
|
Columns: []string{note.ChildrenColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(note.FieldID, field.TypeString),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
|
}
|
|
_node = &Note{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{note.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return nil, err
|
|
}
|
|
_u.mutation.done = true
|
|
return _node, nil
|
|
}
|