snapshot of https://github.com/ent/ent.git (master, 2026-09-15; blobs > 131072B omitted)
This commit is contained in:
446
entc/integration/ent/groupinfo_update.go
Normal file
446
entc/integration/ent/groupinfo_update.go
Normal file
@@ -0,0 +1,446 @@
|
||||
// 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/group"
|
||||
"entgo.io/ent/entc/integration/ent/groupinfo"
|
||||
"entgo.io/ent/entc/integration/ent/predicate"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// GroupInfoUpdate is the builder for updating GroupInfo entities.
|
||||
type GroupInfoUpdate struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *GroupInfoMutation
|
||||
modifiers []func(*sql.UpdateBuilder)
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the GroupInfoUpdate builder.
|
||||
func (_u *GroupInfoUpdate) Where(ps ...predicate.GroupInfo) *GroupInfoUpdate {
|
||||
_u.mutation.Where(ps...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetDesc sets the "desc" field.
|
||||
func (_u *GroupInfoUpdate) SetDesc(v string) *GroupInfoUpdate {
|
||||
_u.mutation.SetDesc(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableDesc sets the "desc" field if the given value is not nil.
|
||||
func (_u *GroupInfoUpdate) SetNillableDesc(v *string) *GroupInfoUpdate {
|
||||
if v != nil {
|
||||
_u.SetDesc(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetMaxUsers sets the "max_users" field.
|
||||
func (_u *GroupInfoUpdate) SetMaxUsers(v int) *GroupInfoUpdate {
|
||||
_u.mutation.ResetMaxUsers()
|
||||
_u.mutation.SetMaxUsers(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableMaxUsers sets the "max_users" field if the given value is not nil.
|
||||
func (_u *GroupInfoUpdate) SetNillableMaxUsers(v *int) *GroupInfoUpdate {
|
||||
if v != nil {
|
||||
_u.SetMaxUsers(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddMaxUsers adds value to the "max_users" field.
|
||||
func (_u *GroupInfoUpdate) AddMaxUsers(v int) *GroupInfoUpdate {
|
||||
_u.mutation.AddMaxUsers(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddGroupIDs adds the "groups" edge to the Group entity by IDs.
|
||||
func (_u *GroupInfoUpdate) AddGroupIDs(ids ...int) *GroupInfoUpdate {
|
||||
_u.mutation.AddGroupIDs(ids...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddGroups adds the "groups" edges to the Group entity.
|
||||
func (_u *GroupInfoUpdate) AddGroups(v ...*Group) *GroupInfoUpdate {
|
||||
ids := make([]int, len(v))
|
||||
for i := range v {
|
||||
ids[i] = v[i].ID
|
||||
}
|
||||
return _u.AddGroupIDs(ids...)
|
||||
}
|
||||
|
||||
// Mutation returns the GroupInfoMutation object of the builder.
|
||||
func (_u *GroupInfoUpdate) Mutation() *GroupInfoMutation {
|
||||
return _u.mutation
|
||||
}
|
||||
|
||||
// ClearGroups clears all "groups" edges to the Group entity.
|
||||
func (_u *GroupInfoUpdate) ClearGroups() *GroupInfoUpdate {
|
||||
_u.mutation.ClearGroups()
|
||||
return _u
|
||||
}
|
||||
|
||||
// RemoveGroupIDs removes the "groups" edge to Group entities by IDs.
|
||||
func (_u *GroupInfoUpdate) RemoveGroupIDs(ids ...int) *GroupInfoUpdate {
|
||||
_u.mutation.RemoveGroupIDs(ids...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// RemoveGroups removes "groups" edges to Group entities.
|
||||
func (_u *GroupInfoUpdate) RemoveGroups(v ...*Group) *GroupInfoUpdate {
|
||||
ids := make([]int, len(v))
|
||||
for i := range v {
|
||||
ids[i] = v[i].ID
|
||||
}
|
||||
return _u.RemoveGroupIDs(ids...)
|
||||
}
|
||||
|
||||
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||
func (_u *GroupInfoUpdate) 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 *GroupInfoUpdate) SaveX(ctx context.Context) int {
|
||||
affected, err := _u.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return affected
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_u *GroupInfoUpdate) Exec(ctx context.Context) error {
|
||||
_, err := _u.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_u *GroupInfoUpdate) 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 *GroupInfoUpdate) Modify(modifiers ...func(u *sql.UpdateBuilder)) *GroupInfoUpdate {
|
||||
_u.modifiers = append(_u.modifiers, modifiers...)
|
||||
return _u
|
||||
}
|
||||
|
||||
func (_u *GroupInfoUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
||||
_spec := sqlgraph.NewUpdateSpec(groupinfo.Table, groupinfo.Columns, sqlgraph.NewFieldSpec(groupinfo.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.Desc(); ok {
|
||||
_spec.SetField(groupinfo.FieldDesc, field.TypeString, value)
|
||||
}
|
||||
if value, ok := _u.mutation.MaxUsers(); ok {
|
||||
_spec.SetField(groupinfo.FieldMaxUsers, field.TypeInt, value)
|
||||
}
|
||||
if value, ok := _u.mutation.AddedMaxUsers(); ok {
|
||||
_spec.AddField(groupinfo.FieldMaxUsers, field.TypeInt, value)
|
||||
}
|
||||
if _u.mutation.GroupsCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: true,
|
||||
Table: groupinfo.GroupsTable,
|
||||
Columns: []string{groupinfo.GroupsColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := _u.mutation.RemovedGroupsIDs(); len(nodes) > 0 && !_u.mutation.GroupsCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: true,
|
||||
Table: groupinfo.GroupsTable,
|
||||
Columns: []string{groupinfo.GroupsColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := _u.mutation.GroupsIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: true,
|
||||
Table: groupinfo.GroupsTable,
|
||||
Columns: []string{groupinfo.GroupsColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
_spec.AddModifiers(_u.modifiers...)
|
||||
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{groupinfo.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
_u.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
|
||||
// GroupInfoUpdateOne is the builder for updating a single GroupInfo entity.
|
||||
type GroupInfoUpdateOne struct {
|
||||
config
|
||||
fields []string
|
||||
hooks []Hook
|
||||
mutation *GroupInfoMutation
|
||||
modifiers []func(*sql.UpdateBuilder)
|
||||
}
|
||||
|
||||
// SetDesc sets the "desc" field.
|
||||
func (_u *GroupInfoUpdateOne) SetDesc(v string) *GroupInfoUpdateOne {
|
||||
_u.mutation.SetDesc(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableDesc sets the "desc" field if the given value is not nil.
|
||||
func (_u *GroupInfoUpdateOne) SetNillableDesc(v *string) *GroupInfoUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetDesc(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetMaxUsers sets the "max_users" field.
|
||||
func (_u *GroupInfoUpdateOne) SetMaxUsers(v int) *GroupInfoUpdateOne {
|
||||
_u.mutation.ResetMaxUsers()
|
||||
_u.mutation.SetMaxUsers(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableMaxUsers sets the "max_users" field if the given value is not nil.
|
||||
func (_u *GroupInfoUpdateOne) SetNillableMaxUsers(v *int) *GroupInfoUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetMaxUsers(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddMaxUsers adds value to the "max_users" field.
|
||||
func (_u *GroupInfoUpdateOne) AddMaxUsers(v int) *GroupInfoUpdateOne {
|
||||
_u.mutation.AddMaxUsers(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddGroupIDs adds the "groups" edge to the Group entity by IDs.
|
||||
func (_u *GroupInfoUpdateOne) AddGroupIDs(ids ...int) *GroupInfoUpdateOne {
|
||||
_u.mutation.AddGroupIDs(ids...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddGroups adds the "groups" edges to the Group entity.
|
||||
func (_u *GroupInfoUpdateOne) AddGroups(v ...*Group) *GroupInfoUpdateOne {
|
||||
ids := make([]int, len(v))
|
||||
for i := range v {
|
||||
ids[i] = v[i].ID
|
||||
}
|
||||
return _u.AddGroupIDs(ids...)
|
||||
}
|
||||
|
||||
// Mutation returns the GroupInfoMutation object of the builder.
|
||||
func (_u *GroupInfoUpdateOne) Mutation() *GroupInfoMutation {
|
||||
return _u.mutation
|
||||
}
|
||||
|
||||
// ClearGroups clears all "groups" edges to the Group entity.
|
||||
func (_u *GroupInfoUpdateOne) ClearGroups() *GroupInfoUpdateOne {
|
||||
_u.mutation.ClearGroups()
|
||||
return _u
|
||||
}
|
||||
|
||||
// RemoveGroupIDs removes the "groups" edge to Group entities by IDs.
|
||||
func (_u *GroupInfoUpdateOne) RemoveGroupIDs(ids ...int) *GroupInfoUpdateOne {
|
||||
_u.mutation.RemoveGroupIDs(ids...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// RemoveGroups removes "groups" edges to Group entities.
|
||||
func (_u *GroupInfoUpdateOne) RemoveGroups(v ...*Group) *GroupInfoUpdateOne {
|
||||
ids := make([]int, len(v))
|
||||
for i := range v {
|
||||
ids[i] = v[i].ID
|
||||
}
|
||||
return _u.RemoveGroupIDs(ids...)
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the GroupInfoUpdate builder.
|
||||
func (_u *GroupInfoUpdateOne) Where(ps ...predicate.GroupInfo) *GroupInfoUpdateOne {
|
||||
_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 *GroupInfoUpdateOne) Select(field string, fields ...string) *GroupInfoUpdateOne {
|
||||
_u.fields = append([]string{field}, fields...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// Save executes the query and returns the updated GroupInfo entity.
|
||||
func (_u *GroupInfoUpdateOne) Save(ctx context.Context) (*GroupInfo, error) {
|
||||
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (_u *GroupInfoUpdateOne) SaveX(ctx context.Context) *GroupInfo {
|
||||
node, err := _u.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// Exec executes the query on the entity.
|
||||
func (_u *GroupInfoUpdateOne) Exec(ctx context.Context) error {
|
||||
_, err := _u.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_u *GroupInfoUpdateOne) 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 *GroupInfoUpdateOne) Modify(modifiers ...func(u *sql.UpdateBuilder)) *GroupInfoUpdateOne {
|
||||
_u.modifiers = append(_u.modifiers, modifiers...)
|
||||
return _u
|
||||
}
|
||||
|
||||
func (_u *GroupInfoUpdateOne) sqlSave(ctx context.Context) (_node *GroupInfo, err error) {
|
||||
_spec := sqlgraph.NewUpdateSpec(groupinfo.Table, groupinfo.Columns, sqlgraph.NewFieldSpec(groupinfo.FieldID, field.TypeInt))
|
||||
id, ok := _u.mutation.ID()
|
||||
if !ok {
|
||||
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "GroupInfo.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, groupinfo.FieldID)
|
||||
for _, f := range fields {
|
||||
if !groupinfo.ValidColumn(f) {
|
||||
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||
}
|
||||
if f != groupinfo.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.Desc(); ok {
|
||||
_spec.SetField(groupinfo.FieldDesc, field.TypeString, value)
|
||||
}
|
||||
if value, ok := _u.mutation.MaxUsers(); ok {
|
||||
_spec.SetField(groupinfo.FieldMaxUsers, field.TypeInt, value)
|
||||
}
|
||||
if value, ok := _u.mutation.AddedMaxUsers(); ok {
|
||||
_spec.AddField(groupinfo.FieldMaxUsers, field.TypeInt, value)
|
||||
}
|
||||
if _u.mutation.GroupsCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: true,
|
||||
Table: groupinfo.GroupsTable,
|
||||
Columns: []string{groupinfo.GroupsColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := _u.mutation.RemovedGroupsIDs(); len(nodes) > 0 && !_u.mutation.GroupsCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: true,
|
||||
Table: groupinfo.GroupsTable,
|
||||
Columns: []string{groupinfo.GroupsColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := _u.mutation.GroupsIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: true,
|
||||
Table: groupinfo.GroupsTable,
|
||||
Columns: []string{groupinfo.GroupsColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
_spec.AddModifiers(_u.modifiers...)
|
||||
_node = &GroupInfo{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{groupinfo.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
_u.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
Reference in New Issue
Block a user