Files
upstream-ent/entc/integration/gremlin/ent/groupinfo_update.go
upstream-mirror 4b3ad0b611
Some checks failed
Atlas CI Public / lint (push) Failing after 13s
Atlas CI Public / sync (push) Has been skipped
snapshot of https://github.com/ent/ent.git (master, 2026-09-15; blobs > 131072B omitted)
2026-09-15 22:12:36 +05:00

400 lines
11 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"
"entgo.io/ent/dialect/gremlin"
"entgo.io/ent/dialect/gremlin/graph/dsl"
"entgo.io/ent/dialect/gremlin/graph/dsl/__"
"entgo.io/ent/dialect/gremlin/graph/dsl/g"
"entgo.io/ent/dialect/gremlin/graph/dsl/p"
"entgo.io/ent/entc/integration/gremlin/ent/group"
"entgo.io/ent/entc/integration/gremlin/ent/groupinfo"
"entgo.io/ent/entc/integration/gremlin/ent/predicate"
)
// GroupInfoUpdate is the builder for updating GroupInfo entities.
type GroupInfoUpdate struct {
config
hooks []Hook
mutation *GroupInfoMutation
}
// 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 ...string) *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([]string, 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 ...string) *GroupInfoUpdate {
_u.mutation.RemoveGroupIDs(ids...)
return _u
}
// RemoveGroups removes "groups" edges to Group entities.
func (_u *GroupInfoUpdate) RemoveGroups(v ...*Group) *GroupInfoUpdate {
ids := make([]string, 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.gremlinSave, _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)
}
}
func (_u *GroupInfoUpdate) gremlinSave(ctx context.Context) (int, error) {
res := &gremlin.Response{}
query, bindings := _u.gremlin().Query()
if err := _u.driver.Exec(ctx, query, bindings, res); err != nil {
return 0, err
}
if err, ok := isConstantError(res); ok {
return 0, err
}
_u.mutation.done = true
return res.ReadInt()
}
func (_u *GroupInfoUpdate) gremlin() *dsl.Traversal {
type constraint struct {
pred *dsl.Traversal // constraint predicate.
test *dsl.Traversal // test matches and its constant.
}
constraints := make([]*constraint, 0, 1)
v := g.V().HasLabel(groupinfo.Label)
for _, p := range _u.mutation.Predicates() {
p(v)
}
var (
rv = v.Clone()
_ = rv
trs []*dsl.Traversal
)
if value, ok := _u.mutation.Desc(); ok {
v.Property(dsl.Single, groupinfo.FieldDesc, value)
}
if value, ok := _u.mutation.MaxUsers(); ok {
v.Property(dsl.Single, groupinfo.FieldMaxUsers, value)
}
if value, ok := _u.mutation.AddedMaxUsers(); ok {
v.Property(dsl.Single, groupinfo.FieldMaxUsers, __.Union(__.Values(groupinfo.FieldMaxUsers), __.Constant(value)).Sum())
}
for _, id := range _u.mutation.RemovedGroupsIDs() {
tr := rv.Clone().InE(group.InfoLabel).Where(__.OtherV().HasID(id)).Drop().Iterate()
trs = append(trs, tr)
}
for _, id := range _u.mutation.GroupsIDs() {
v.AddE(group.InfoLabel).From(g.V(id)).InV()
constraints = append(constraints, &constraint{
pred: g.E().HasLabel(group.InfoLabel).OutV().HasID(id).Count(),
test: __.Is(p.NEQ(0)).Constant(NewErrUniqueEdge(groupinfo.Label, group.InfoLabel, id)),
})
}
v.Count()
if len(constraints) > 0 {
constraints = append(constraints, &constraint{
pred: rv.Count(),
test: __.Is(p.GT(1)).Constant(&ConstraintError{msg: "update traversal contains more than one vertex"}),
})
v = constraints[0].pred.Coalesce(constraints[0].test, v)
for _, cr := range constraints[1:] {
v = cr.pred.Coalesce(cr.test, v)
}
}
trs = append(trs, v)
return dsl.Join(trs...)
}
// GroupInfoUpdateOne is the builder for updating a single GroupInfo entity.
type GroupInfoUpdateOne struct {
config
fields []string
hooks []Hook
mutation *GroupInfoMutation
}
// 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 ...string) *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([]string, 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 ...string) *GroupInfoUpdateOne {
_u.mutation.RemoveGroupIDs(ids...)
return _u
}
// RemoveGroups removes "groups" edges to Group entities.
func (_u *GroupInfoUpdateOne) RemoveGroups(v ...*Group) *GroupInfoUpdateOne {
ids := make([]string, 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.gremlinSave, _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)
}
}
func (_u *GroupInfoUpdateOne) gremlinSave(ctx context.Context) (*GroupInfo, error) {
res := &gremlin.Response{}
id, ok := _u.mutation.ID()
if !ok {
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "GroupInfo.id" for update`)}
}
query, bindings := _u.gremlin(id).Query()
if err := _u.driver.Exec(ctx, query, bindings, res); err != nil {
return nil, err
}
if err, ok := isConstantError(res); ok {
return nil, err
}
_u.mutation.done = true
_m := &GroupInfo{config: _u.config}
if err := _m.FromResponse(res); err != nil {
return nil, err
}
return _m, nil
}
func (_u *GroupInfoUpdateOne) gremlin(id string) *dsl.Traversal {
type constraint struct {
pred *dsl.Traversal // constraint predicate.
test *dsl.Traversal // test matches and its constant.
}
constraints := make([]*constraint, 0, 1)
v := g.V(id)
var (
rv = v.Clone()
_ = rv
trs []*dsl.Traversal
)
if value, ok := _u.mutation.Desc(); ok {
v.Property(dsl.Single, groupinfo.FieldDesc, value)
}
if value, ok := _u.mutation.MaxUsers(); ok {
v.Property(dsl.Single, groupinfo.FieldMaxUsers, value)
}
if value, ok := _u.mutation.AddedMaxUsers(); ok {
v.Property(dsl.Single, groupinfo.FieldMaxUsers, __.Union(__.Values(groupinfo.FieldMaxUsers), __.Constant(value)).Sum())
}
for _, id := range _u.mutation.RemovedGroupsIDs() {
tr := rv.Clone().InE(group.InfoLabel).Where(__.OtherV().HasID(id)).Drop().Iterate()
trs = append(trs, tr)
}
for _, id := range _u.mutation.GroupsIDs() {
v.AddE(group.InfoLabel).From(g.V(id)).InV()
constraints = append(constraints, &constraint{
pred: g.E().HasLabel(group.InfoLabel).OutV().HasID(id).Count(),
test: __.Is(p.NEQ(0)).Constant(NewErrUniqueEdge(groupinfo.Label, group.InfoLabel, id)),
})
}
if len(_u.fields) > 0 {
fields := make([]any, 0, len(_u.fields)+1)
fields = append(fields, true)
for _, f := range _u.fields {
fields = append(fields, f)
}
v.ValueMap(fields...)
} else {
v.ValueMap(true)
}
if len(constraints) > 0 {
v = constraints[0].pred.Coalesce(constraints[0].test, v)
for _, cr := range constraints[1:] {
v = cr.pred.Coalesce(cr.test, v)
}
}
trs = append(trs, v)
return dsl.Join(trs...)
}