Ai
1 Star 0 Fork 0

DaMeng/Ent

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
user_update.go 51.38 KB
一键复制 编辑 原始数据 按行查看 历史
DaMeng 提交于 2024-10-24 16:04 +08:00 . :tada:fork ent
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795
// 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"
"gitee.com/damengde/ent/dialect/gremlin"
"gitee.com/damengde/ent/dialect/gremlin/graph/dsl"
"gitee.com/damengde/ent/dialect/gremlin/graph/dsl/__"
"gitee.com/damengde/ent/dialect/gremlin/graph/dsl/g"
"gitee.com/damengde/ent/dialect/gremlin/graph/dsl/p"
"gitee.com/damengde/ent/entc/integration/gremlin/ent/predicate"
"gitee.com/damengde/ent/entc/integration/gremlin/ent/user"
)
// UserUpdate is the builder for updating User entities.
type UserUpdate struct {
config
hooks []Hook
mutation *UserMutation
}
// Where appends a list predicates to the UserUpdate builder.
func (uu *UserUpdate) Where(ps ...predicate.User) *UserUpdate {
uu.mutation.Where(ps...)
return uu
}
// SetOptionalInt sets the "optional_int" field.
func (uu *UserUpdate) SetOptionalInt(i int) *UserUpdate {
uu.mutation.ResetOptionalInt()
uu.mutation.SetOptionalInt(i)
return uu
}
// SetNillableOptionalInt sets the "optional_int" field if the given value is not nil.
func (uu *UserUpdate) SetNillableOptionalInt(i *int) *UserUpdate {
if i != nil {
uu.SetOptionalInt(*i)
}
return uu
}
// AddOptionalInt adds i to the "optional_int" field.
func (uu *UserUpdate) AddOptionalInt(i int) *UserUpdate {
uu.mutation.AddOptionalInt(i)
return uu
}
// ClearOptionalInt clears the value of the "optional_int" field.
func (uu *UserUpdate) ClearOptionalInt() *UserUpdate {
uu.mutation.ClearOptionalInt()
return uu
}
// SetAge sets the "age" field.
func (uu *UserUpdate) SetAge(i int) *UserUpdate {
uu.mutation.ResetAge()
uu.mutation.SetAge(i)
return uu
}
// SetNillableAge sets the "age" field if the given value is not nil.
func (uu *UserUpdate) SetNillableAge(i *int) *UserUpdate {
if i != nil {
uu.SetAge(*i)
}
return uu
}
// AddAge adds i to the "age" field.
func (uu *UserUpdate) AddAge(i int) *UserUpdate {
uu.mutation.AddAge(i)
return uu
}
// SetName sets the "name" field.
func (uu *UserUpdate) SetName(s string) *UserUpdate {
uu.mutation.SetName(s)
return uu
}
// SetNillableName sets the "name" field if the given value is not nil.
func (uu *UserUpdate) SetNillableName(s *string) *UserUpdate {
if s != nil {
uu.SetName(*s)
}
return uu
}
// SetLast sets the "last" field.
func (uu *UserUpdate) SetLast(s string) *UserUpdate {
uu.mutation.SetLast(s)
return uu
}
// SetNillableLast sets the "last" field if the given value is not nil.
func (uu *UserUpdate) SetNillableLast(s *string) *UserUpdate {
if s != nil {
uu.SetLast(*s)
}
return uu
}
// SetNickname sets the "nickname" field.
func (uu *UserUpdate) SetNickname(s string) *UserUpdate {
uu.mutation.SetNickname(s)
return uu
}
// SetNillableNickname sets the "nickname" field if the given value is not nil.
func (uu *UserUpdate) SetNillableNickname(s *string) *UserUpdate {
if s != nil {
uu.SetNickname(*s)
}
return uu
}
// ClearNickname clears the value of the "nickname" field.
func (uu *UserUpdate) ClearNickname() *UserUpdate {
uu.mutation.ClearNickname()
return uu
}
// SetAddress sets the "address" field.
func (uu *UserUpdate) SetAddress(s string) *UserUpdate {
uu.mutation.SetAddress(s)
return uu
}
// SetNillableAddress sets the "address" field if the given value is not nil.
func (uu *UserUpdate) SetNillableAddress(s *string) *UserUpdate {
if s != nil {
uu.SetAddress(*s)
}
return uu
}
// ClearAddress clears the value of the "address" field.
func (uu *UserUpdate) ClearAddress() *UserUpdate {
uu.mutation.ClearAddress()
return uu
}
// SetPhone sets the "phone" field.
func (uu *UserUpdate) SetPhone(s string) *UserUpdate {
uu.mutation.SetPhone(s)
return uu
}
// SetNillablePhone sets the "phone" field if the given value is not nil.
func (uu *UserUpdate) SetNillablePhone(s *string) *UserUpdate {
if s != nil {
uu.SetPhone(*s)
}
return uu
}
// ClearPhone clears the value of the "phone" field.
func (uu *UserUpdate) ClearPhone() *UserUpdate {
uu.mutation.ClearPhone()
return uu
}
// SetPassword sets the "password" field.
func (uu *UserUpdate) SetPassword(s string) *UserUpdate {
uu.mutation.SetPassword(s)
return uu
}
// SetNillablePassword sets the "password" field if the given value is not nil.
func (uu *UserUpdate) SetNillablePassword(s *string) *UserUpdate {
if s != nil {
uu.SetPassword(*s)
}
return uu
}
// ClearPassword clears the value of the "password" field.
func (uu *UserUpdate) ClearPassword() *UserUpdate {
uu.mutation.ClearPassword()
return uu
}
// SetRole sets the "role" field.
func (uu *UserUpdate) SetRole(u user.Role) *UserUpdate {
uu.mutation.SetRole(u)
return uu
}
// SetNillableRole sets the "role" field if the given value is not nil.
func (uu *UserUpdate) SetNillableRole(u *user.Role) *UserUpdate {
if u != nil {
uu.SetRole(*u)
}
return uu
}
// SetEmployment sets the "employment" field.
func (uu *UserUpdate) SetEmployment(u user.Employment) *UserUpdate {
uu.mutation.SetEmployment(u)
return uu
}
// SetNillableEmployment sets the "employment" field if the given value is not nil.
func (uu *UserUpdate) SetNillableEmployment(u *user.Employment) *UserUpdate {
if u != nil {
uu.SetEmployment(*u)
}
return uu
}
// SetSSOCert sets the "SSOCert" field.
func (uu *UserUpdate) SetSSOCert(s string) *UserUpdate {
uu.mutation.SetSSOCert(s)
return uu
}
// SetNillableSSOCert sets the "SSOCert" field if the given value is not nil.
func (uu *UserUpdate) SetNillableSSOCert(s *string) *UserUpdate {
if s != nil {
uu.SetSSOCert(*s)
}
return uu
}
// ClearSSOCert clears the value of the "SSOCert" field.
func (uu *UserUpdate) ClearSSOCert() *UserUpdate {
uu.mutation.ClearSSOCert()
return uu
}
// SetFilesCount sets the "files_count" field.
func (uu *UserUpdate) SetFilesCount(i int) *UserUpdate {
uu.mutation.ResetFilesCount()
uu.mutation.SetFilesCount(i)
return uu
}
// SetNillableFilesCount sets the "files_count" field if the given value is not nil.
func (uu *UserUpdate) SetNillableFilesCount(i *int) *UserUpdate {
if i != nil {
uu.SetFilesCount(*i)
}
return uu
}
// AddFilesCount adds i to the "files_count" field.
func (uu *UserUpdate) AddFilesCount(i int) *UserUpdate {
uu.mutation.AddFilesCount(i)
return uu
}
// ClearFilesCount clears the value of the "files_count" field.
func (uu *UserUpdate) ClearFilesCount() *UserUpdate {
uu.mutation.ClearFilesCount()
return uu
}
// SetCardID sets the "card" edge to the Card entity by ID.
func (uu *UserUpdate) SetCardID(id string) *UserUpdate {
uu.mutation.SetCardID(id)
return uu
}
// SetNillableCardID sets the "card" edge to the Card entity by ID if the given value is not nil.
func (uu *UserUpdate) SetNillableCardID(id *string) *UserUpdate {
if id != nil {
uu = uu.SetCardID(*id)
}
return uu
}
// SetCard sets the "card" edge to the Card entity.
func (uu *UserUpdate) SetCard(c *Card) *UserUpdate {
return uu.SetCardID(c.ID)
}
// AddPetIDs adds the "pets" edge to the Pet entity by IDs.
func (uu *UserUpdate) AddPetIDs(ids ...string) *UserUpdate {
uu.mutation.AddPetIDs(ids...)
return uu
}
// AddPets adds the "pets" edges to the Pet entity.
func (uu *UserUpdate) AddPets(p ...*Pet) *UserUpdate {
ids := make([]string, len(p))
for i := range p {
ids[i] = p[i].ID
}
return uu.AddPetIDs(ids...)
}
// AddFileIDs adds the "files" edge to the File entity by IDs.
func (uu *UserUpdate) AddFileIDs(ids ...string) *UserUpdate {
uu.mutation.AddFileIDs(ids...)
return uu
}
// AddFiles adds the "files" edges to the File entity.
func (uu *UserUpdate) AddFiles(f ...*File) *UserUpdate {
ids := make([]string, len(f))
for i := range f {
ids[i] = f[i].ID
}
return uu.AddFileIDs(ids...)
}
// AddGroupIDs adds the "groups" edge to the Group entity by IDs.
func (uu *UserUpdate) AddGroupIDs(ids ...string) *UserUpdate {
uu.mutation.AddGroupIDs(ids...)
return uu
}
// AddGroups adds the "groups" edges to the Group entity.
func (uu *UserUpdate) AddGroups(g ...*Group) *UserUpdate {
ids := make([]string, len(g))
for i := range g {
ids[i] = g[i].ID
}
return uu.AddGroupIDs(ids...)
}
// AddFriendIDs adds the "friends" edge to the User entity by IDs.
func (uu *UserUpdate) AddFriendIDs(ids ...string) *UserUpdate {
uu.mutation.AddFriendIDs(ids...)
return uu
}
// AddFriends adds the "friends" edges to the User entity.
func (uu *UserUpdate) AddFriends(u ...*User) *UserUpdate {
ids := make([]string, len(u))
for i := range u {
ids[i] = u[i].ID
}
return uu.AddFriendIDs(ids...)
}
// AddFollowerIDs adds the "followers" edge to the User entity by IDs.
func (uu *UserUpdate) AddFollowerIDs(ids ...string) *UserUpdate {
uu.mutation.AddFollowerIDs(ids...)
return uu
}
// AddFollowers adds the "followers" edges to the User entity.
func (uu *UserUpdate) AddFollowers(u ...*User) *UserUpdate {
ids := make([]string, len(u))
for i := range u {
ids[i] = u[i].ID
}
return uu.AddFollowerIDs(ids...)
}
// AddFollowingIDs adds the "following" edge to the User entity by IDs.
func (uu *UserUpdate) AddFollowingIDs(ids ...string) *UserUpdate {
uu.mutation.AddFollowingIDs(ids...)
return uu
}
// AddFollowing adds the "following" edges to the User entity.
func (uu *UserUpdate) AddFollowing(u ...*User) *UserUpdate {
ids := make([]string, len(u))
for i := range u {
ids[i] = u[i].ID
}
return uu.AddFollowingIDs(ids...)
}
// SetTeamID sets the "team" edge to the Pet entity by ID.
func (uu *UserUpdate) SetTeamID(id string) *UserUpdate {
uu.mutation.SetTeamID(id)
return uu
}
// SetNillableTeamID sets the "team" edge to the Pet entity by ID if the given value is not nil.
func (uu *UserUpdate) SetNillableTeamID(id *string) *UserUpdate {
if id != nil {
uu = uu.SetTeamID(*id)
}
return uu
}
// SetTeam sets the "team" edge to the Pet entity.
func (uu *UserUpdate) SetTeam(p *Pet) *UserUpdate {
return uu.SetTeamID(p.ID)
}
// SetSpouseID sets the "spouse" edge to the User entity by ID.
func (uu *UserUpdate) SetSpouseID(id string) *UserUpdate {
uu.mutation.SetSpouseID(id)
return uu
}
// SetNillableSpouseID sets the "spouse" edge to the User entity by ID if the given value is not nil.
func (uu *UserUpdate) SetNillableSpouseID(id *string) *UserUpdate {
if id != nil {
uu = uu.SetSpouseID(*id)
}
return uu
}
// SetSpouse sets the "spouse" edge to the User entity.
func (uu *UserUpdate) SetSpouse(u *User) *UserUpdate {
return uu.SetSpouseID(u.ID)
}
// AddChildIDs adds the "children" edge to the User entity by IDs.
func (uu *UserUpdate) AddChildIDs(ids ...string) *UserUpdate {
uu.mutation.AddChildIDs(ids...)
return uu
}
// AddChildren adds the "children" edges to the User entity.
func (uu *UserUpdate) AddChildren(u ...*User) *UserUpdate {
ids := make([]string, len(u))
for i := range u {
ids[i] = u[i].ID
}
return uu.AddChildIDs(ids...)
}
// SetParentID sets the "parent" edge to the User entity by ID.
func (uu *UserUpdate) SetParentID(id string) *UserUpdate {
uu.mutation.SetParentID(id)
return uu
}
// SetNillableParentID sets the "parent" edge to the User entity by ID if the given value is not nil.
func (uu *UserUpdate) SetNillableParentID(id *string) *UserUpdate {
if id != nil {
uu = uu.SetParentID(*id)
}
return uu
}
// SetParent sets the "parent" edge to the User entity.
func (uu *UserUpdate) SetParent(u *User) *UserUpdate {
return uu.SetParentID(u.ID)
}
// Mutation returns the UserMutation object of the builder.
func (uu *UserUpdate) Mutation() *UserMutation {
return uu.mutation
}
// ClearCard clears the "card" edge to the Card entity.
func (uu *UserUpdate) ClearCard() *UserUpdate {
uu.mutation.ClearCard()
return uu
}
// ClearPets clears all "pets" edges to the Pet entity.
func (uu *UserUpdate) ClearPets() *UserUpdate {
uu.mutation.ClearPets()
return uu
}
// RemovePetIDs removes the "pets" edge to Pet entities by IDs.
func (uu *UserUpdate) RemovePetIDs(ids ...string) *UserUpdate {
uu.mutation.RemovePetIDs(ids...)
return uu
}
// RemovePets removes "pets" edges to Pet entities.
func (uu *UserUpdate) RemovePets(p ...*Pet) *UserUpdate {
ids := make([]string, len(p))
for i := range p {
ids[i] = p[i].ID
}
return uu.RemovePetIDs(ids...)
}
// ClearFiles clears all "files" edges to the File entity.
func (uu *UserUpdate) ClearFiles() *UserUpdate {
uu.mutation.ClearFiles()
return uu
}
// RemoveFileIDs removes the "files" edge to File entities by IDs.
func (uu *UserUpdate) RemoveFileIDs(ids ...string) *UserUpdate {
uu.mutation.RemoveFileIDs(ids...)
return uu
}
// RemoveFiles removes "files" edges to File entities.
func (uu *UserUpdate) RemoveFiles(f ...*File) *UserUpdate {
ids := make([]string, len(f))
for i := range f {
ids[i] = f[i].ID
}
return uu.RemoveFileIDs(ids...)
}
// ClearGroups clears all "groups" edges to the Group entity.
func (uu *UserUpdate) ClearGroups() *UserUpdate {
uu.mutation.ClearGroups()
return uu
}
// RemoveGroupIDs removes the "groups" edge to Group entities by IDs.
func (uu *UserUpdate) RemoveGroupIDs(ids ...string) *UserUpdate {
uu.mutation.RemoveGroupIDs(ids...)
return uu
}
// RemoveGroups removes "groups" edges to Group entities.
func (uu *UserUpdate) RemoveGroups(g ...*Group) *UserUpdate {
ids := make([]string, len(g))
for i := range g {
ids[i] = g[i].ID
}
return uu.RemoveGroupIDs(ids...)
}
// ClearFriends clears all "friends" edges to the User entity.
func (uu *UserUpdate) ClearFriends() *UserUpdate {
uu.mutation.ClearFriends()
return uu
}
// RemoveFriendIDs removes the "friends" edge to User entities by IDs.
func (uu *UserUpdate) RemoveFriendIDs(ids ...string) *UserUpdate {
uu.mutation.RemoveFriendIDs(ids...)
return uu
}
// RemoveFriends removes "friends" edges to User entities.
func (uu *UserUpdate) RemoveFriends(u ...*User) *UserUpdate {
ids := make([]string, len(u))
for i := range u {
ids[i] = u[i].ID
}
return uu.RemoveFriendIDs(ids...)
}
// ClearFollowers clears all "followers" edges to the User entity.
func (uu *UserUpdate) ClearFollowers() *UserUpdate {
uu.mutation.ClearFollowers()
return uu
}
// RemoveFollowerIDs removes the "followers" edge to User entities by IDs.
func (uu *UserUpdate) RemoveFollowerIDs(ids ...string) *UserUpdate {
uu.mutation.RemoveFollowerIDs(ids...)
return uu
}
// RemoveFollowers removes "followers" edges to User entities.
func (uu *UserUpdate) RemoveFollowers(u ...*User) *UserUpdate {
ids := make([]string, len(u))
for i := range u {
ids[i] = u[i].ID
}
return uu.RemoveFollowerIDs(ids...)
}
// ClearFollowing clears all "following" edges to the User entity.
func (uu *UserUpdate) ClearFollowing() *UserUpdate {
uu.mutation.ClearFollowing()
return uu
}
// RemoveFollowingIDs removes the "following" edge to User entities by IDs.
func (uu *UserUpdate) RemoveFollowingIDs(ids ...string) *UserUpdate {
uu.mutation.RemoveFollowingIDs(ids...)
return uu
}
// RemoveFollowing removes "following" edges to User entities.
func (uu *UserUpdate) RemoveFollowing(u ...*User) *UserUpdate {
ids := make([]string, len(u))
for i := range u {
ids[i] = u[i].ID
}
return uu.RemoveFollowingIDs(ids...)
}
// ClearTeam clears the "team" edge to the Pet entity.
func (uu *UserUpdate) ClearTeam() *UserUpdate {
uu.mutation.ClearTeam()
return uu
}
// ClearSpouse clears the "spouse" edge to the User entity.
func (uu *UserUpdate) ClearSpouse() *UserUpdate {
uu.mutation.ClearSpouse()
return uu
}
// ClearChildren clears all "children" edges to the User entity.
func (uu *UserUpdate) ClearChildren() *UserUpdate {
uu.mutation.ClearChildren()
return uu
}
// RemoveChildIDs removes the "children" edge to User entities by IDs.
func (uu *UserUpdate) RemoveChildIDs(ids ...string) *UserUpdate {
uu.mutation.RemoveChildIDs(ids...)
return uu
}
// RemoveChildren removes "children" edges to User entities.
func (uu *UserUpdate) RemoveChildren(u ...*User) *UserUpdate {
ids := make([]string, len(u))
for i := range u {
ids[i] = u[i].ID
}
return uu.RemoveChildIDs(ids...)
}
// ClearParent clears the "parent" edge to the User entity.
func (uu *UserUpdate) ClearParent() *UserUpdate {
uu.mutation.ClearParent()
return uu
}
// Save executes the query and returns the number of nodes affected by the update operation.
func (uu *UserUpdate) Save(ctx context.Context) (int, error) {
return withHooks(ctx, uu.gremlinSave, uu.mutation, uu.hooks)
}
// 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)
}
}
// check runs all checks and user-defined validators on the builder.
func (uu *UserUpdate) check() error {
if v, ok := uu.mutation.OptionalInt(); ok {
if err := user.OptionalIntValidator(v); err != nil {
return &ValidationError{Name: "optional_int", err: fmt.Errorf(`ent: validator failed for field "User.optional_int": %w`, err)}
}
}
if v, ok := uu.mutation.Role(); ok {
if err := user.RoleValidator(v); err != nil {
return &ValidationError{Name: "role", err: fmt.Errorf(`ent: validator failed for field "User.role": %w`, err)}
}
}
if v, ok := uu.mutation.Employment(); ok {
if err := user.EmploymentValidator(v); err != nil {
return &ValidationError{Name: "employment", err: fmt.Errorf(`ent: validator failed for field "User.employment": %w`, err)}
}
}
return nil
}
func (uu *UserUpdate) gremlinSave(ctx context.Context) (int, error) {
if err := uu.check(); err != nil {
return 0, err
}
res := &gremlin.Response{}
query, bindings := uu.gremlin().Query()
if err := uu.driver.Exec(ctx, query, bindings, res); err != nil {
return 0, err
}
if err, ok := isConstantError(res); ok {
return 0, err
}
uu.mutation.done = true
return res.ReadInt()
}
func (uu *UserUpdate) gremlin() *dsl.Traversal {
type constraint struct {
pred *dsl.Traversal // constraint predicate.
test *dsl.Traversal // test matches and its constant.
}
constraints := make([]*constraint, 0, 8)
v := g.V().HasLabel(user.Label)
for _, p := range uu.mutation.predicates {
p(v)
}
var (
rv = v.Clone()
_ = rv
trs []*dsl.Traversal
)
if value, ok := uu.mutation.OptionalInt(); ok {
v.Property(dsl.Single, user.FieldOptionalInt, value)
}
if value, ok := uu.mutation.AddedOptionalInt(); ok {
v.Property(dsl.Single, user.FieldOptionalInt, __.Union(__.Values(user.FieldOptionalInt), __.Constant(value)).Sum())
}
if value, ok := uu.mutation.Age(); ok {
v.Property(dsl.Single, user.FieldAge, value)
}
if value, ok := uu.mutation.AddedAge(); ok {
v.Property(dsl.Single, user.FieldAge, __.Union(__.Values(user.FieldAge), __.Constant(value)).Sum())
}
if value, ok := uu.mutation.Name(); ok {
v.Property(dsl.Single, user.FieldName, value)
}
if value, ok := uu.mutation.Last(); ok {
v.Property(dsl.Single, user.FieldLast, value)
}
if value, ok := uu.mutation.Nickname(); ok {
constraints = append(constraints, &constraint{
pred: g.V().Has(user.Label, user.FieldNickname, value).Count(),
test: __.Is(p.NEQ(0)).Constant(NewErrUniqueField(user.Label, user.FieldNickname, value)),
})
v.Property(dsl.Single, user.FieldNickname, value)
}
if value, ok := uu.mutation.Address(); ok {
v.Property(dsl.Single, user.FieldAddress, value)
}
if value, ok := uu.mutation.Phone(); ok {
constraints = append(constraints, &constraint{
pred: g.V().Has(user.Label, user.FieldPhone, value).Count(),
test: __.Is(p.NEQ(0)).Constant(NewErrUniqueField(user.Label, user.FieldPhone, value)),
})
v.Property(dsl.Single, user.FieldPhone, value)
}
if value, ok := uu.mutation.Password(); ok {
v.Property(dsl.Single, user.FieldPassword, value)
}
if value, ok := uu.mutation.Role(); ok {
v.Property(dsl.Single, user.FieldRole, value)
}
if value, ok := uu.mutation.Employment(); ok {
v.Property(dsl.Single, user.FieldEmployment, value)
}
if value, ok := uu.mutation.SSOCert(); ok {
v.Property(dsl.Single, user.FieldSSOCert, value)
}
if value, ok := uu.mutation.FilesCount(); ok {
v.Property(dsl.Single, user.FieldFilesCount, value)
}
if value, ok := uu.mutation.AddedFilesCount(); ok {
v.Property(dsl.Single, user.FieldFilesCount, __.Union(__.Values(user.FieldFilesCount), __.Constant(value)).Sum())
}
var properties []any
if uu.mutation.OptionalIntCleared() {
properties = append(properties, user.FieldOptionalInt)
}
if uu.mutation.NicknameCleared() {
properties = append(properties, user.FieldNickname)
}
if uu.mutation.AddressCleared() {
properties = append(properties, user.FieldAddress)
}
if uu.mutation.PhoneCleared() {
properties = append(properties, user.FieldPhone)
}
if uu.mutation.PasswordCleared() {
properties = append(properties, user.FieldPassword)
}
if uu.mutation.SSOCertCleared() {
properties = append(properties, user.FieldSSOCert)
}
if uu.mutation.FilesCountCleared() {
properties = append(properties, user.FieldFilesCount)
}
if len(properties) > 0 {
v.SideEffect(__.Properties(properties...).Drop())
}
if uu.mutation.CardCleared() {
tr := rv.Clone().OutE(user.CardLabel).Drop().Iterate()
trs = append(trs, tr)
}
for _, id := range uu.mutation.CardIDs() {
v.AddE(user.CardLabel).To(g.V(id)).OutV()
constraints = append(constraints, &constraint{
pred: g.E().HasLabel(user.CardLabel).InV().HasID(id).Count(),
test: __.Is(p.NEQ(0)).Constant(NewErrUniqueEdge(user.Label, user.CardLabel, id)),
})
}
for _, id := range uu.mutation.RemovedPetsIDs() {
tr := rv.Clone().OutE(user.PetsLabel).Where(__.OtherV().HasID(id)).Drop().Iterate()
trs = append(trs, tr)
}
for _, id := range uu.mutation.PetsIDs() {
v.AddE(user.PetsLabel).To(g.V(id)).OutV()
constraints = append(constraints, &constraint{
pred: g.E().HasLabel(user.PetsLabel).InV().HasID(id).Count(),
test: __.Is(p.NEQ(0)).Constant(NewErrUniqueEdge(user.Label, user.PetsLabel, id)),
})
}
for _, id := range uu.mutation.RemovedFilesIDs() {
tr := rv.Clone().OutE(user.FilesLabel).Where(__.OtherV().HasID(id)).Drop().Iterate()
trs = append(trs, tr)
}
for _, id := range uu.mutation.FilesIDs() {
v.AddE(user.FilesLabel).To(g.V(id)).OutV()
constraints = append(constraints, &constraint{
pred: g.E().HasLabel(user.FilesLabel).InV().HasID(id).Count(),
test: __.Is(p.NEQ(0)).Constant(NewErrUniqueEdge(user.Label, user.FilesLabel, id)),
})
}
for _, id := range uu.mutation.RemovedGroupsIDs() {
tr := rv.Clone().OutE(user.GroupsLabel).Where(__.OtherV().HasID(id)).Drop().Iterate()
trs = append(trs, tr)
}
for _, id := range uu.mutation.GroupsIDs() {
v.AddE(user.GroupsLabel).To(g.V(id)).OutV()
}
for _, id := range uu.mutation.RemovedFriendsIDs() {
tr := rv.Clone().BothE(user.FriendsLabel).Where(__.Or(__.InV().HasID(id), __.OutV().HasID(id))).Drop().Iterate()
trs = append(trs, tr)
}
for _, id := range uu.mutation.FriendsIDs() {
v.AddE(user.FriendsLabel).To(g.V(id)).OutV()
}
for _, id := range uu.mutation.RemovedFollowersIDs() {
tr := rv.Clone().InE(user.FollowingLabel).Where(__.OtherV().HasID(id)).Drop().Iterate()
trs = append(trs, tr)
}
for _, id := range uu.mutation.FollowersIDs() {
v.AddE(user.FollowingLabel).From(g.V(id)).InV()
}
for _, id := range uu.mutation.RemovedFollowingIDs() {
tr := rv.Clone().OutE(user.FollowingLabel).Where(__.OtherV().HasID(id)).Drop().Iterate()
trs = append(trs, tr)
}
for _, id := range uu.mutation.FollowingIDs() {
v.AddE(user.FollowingLabel).To(g.V(id)).OutV()
}
if uu.mutation.TeamCleared() {
tr := rv.Clone().OutE(user.TeamLabel).Drop().Iterate()
trs = append(trs, tr)
}
for _, id := range uu.mutation.TeamIDs() {
v.AddE(user.TeamLabel).To(g.V(id)).OutV()
constraints = append(constraints, &constraint{
pred: g.E().HasLabel(user.TeamLabel).InV().HasID(id).Count(),
test: __.Is(p.NEQ(0)).Constant(NewErrUniqueEdge(user.Label, user.TeamLabel, id)),
})
}
if uu.mutation.SpouseCleared() {
tr := rv.Clone().BothE(user.SpouseLabel).Drop().Iterate()
trs = append(trs, tr)
}
for _, id := range uu.mutation.SpouseIDs() {
v.AddE(user.SpouseLabel).To(g.V(id)).OutV()
constraints = append(constraints, &constraint{
pred: rv.Clone().Both(user.SpouseLabel).Count(),
test: __.Is(p.NEQ(0)).Constant(NewErrUniqueEdge(user.Label, user.SpouseLabel, id)),
})
constraints = append(constraints, &constraint{
pred: g.E().HasLabel(user.SpouseLabel).Where(__.Or(__.InV().HasID(id), __.OutV().HasID(id))).Count(),
test: __.Is(p.NEQ(0)).Constant(NewErrUniqueEdge(user.Label, user.SpouseLabel, id)),
})
}
for _, id := range uu.mutation.RemovedChildrenIDs() {
tr := rv.Clone().InE(user.ParentLabel).Where(__.OtherV().HasID(id)).Drop().Iterate()
trs = append(trs, tr)
}
for _, id := range uu.mutation.ChildrenIDs() {
v.AddE(user.ParentLabel).From(g.V(id)).InV()
constraints = append(constraints, &constraint{
pred: g.E().HasLabel(user.ParentLabel).OutV().HasID(id).Count(),
test: __.Is(p.NEQ(0)).Constant(NewErrUniqueEdge(user.Label, user.ParentLabel, id)),
})
}
if uu.mutation.ParentCleared() {
tr := rv.Clone().OutE(user.ParentLabel).Drop().Iterate()
trs = append(trs, tr)
}
for _, id := range uu.mutation.ParentIDs() {
v.AddE(user.ParentLabel).To(g.V(id)).OutV()
}
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...)
}
// UserUpdateOne is the builder for updating a single User entity.
type UserUpdateOne struct {
config
fields []string
hooks []Hook
mutation *UserMutation
}
// SetOptionalInt sets the "optional_int" field.
func (uuo *UserUpdateOne) SetOptionalInt(i int) *UserUpdateOne {
uuo.mutation.ResetOptionalInt()
uuo.mutation.SetOptionalInt(i)
return uuo
}
// SetNillableOptionalInt sets the "optional_int" field if the given value is not nil.
func (uuo *UserUpdateOne) SetNillableOptionalInt(i *int) *UserUpdateOne {
if i != nil {
uuo.SetOptionalInt(*i)
}
return uuo
}
// AddOptionalInt adds i to the "optional_int" field.
func (uuo *UserUpdateOne) AddOptionalInt(i int) *UserUpdateOne {
uuo.mutation.AddOptionalInt(i)
return uuo
}
// ClearOptionalInt clears the value of the "optional_int" field.
func (uuo *UserUpdateOne) ClearOptionalInt() *UserUpdateOne {
uuo.mutation.ClearOptionalInt()
return uuo
}
// SetAge sets the "age" field.
func (uuo *UserUpdateOne) SetAge(i int) *UserUpdateOne {
uuo.mutation.ResetAge()
uuo.mutation.SetAge(i)
return uuo
}
// SetNillableAge sets the "age" field if the given value is not nil.
func (uuo *UserUpdateOne) SetNillableAge(i *int) *UserUpdateOne {
if i != nil {
uuo.SetAge(*i)
}
return uuo
}
// AddAge adds i to the "age" field.
func (uuo *UserUpdateOne) AddAge(i int) *UserUpdateOne {
uuo.mutation.AddAge(i)
return uuo
}
// SetName sets the "name" field.
func (uuo *UserUpdateOne) SetName(s string) *UserUpdateOne {
uuo.mutation.SetName(s)
return uuo
}
// SetNillableName sets the "name" field if the given value is not nil.
func (uuo *UserUpdateOne) SetNillableName(s *string) *UserUpdateOne {
if s != nil {
uuo.SetName(*s)
}
return uuo
}
// SetLast sets the "last" field.
func (uuo *UserUpdateOne) SetLast(s string) *UserUpdateOne {
uuo.mutation.SetLast(s)
return uuo
}
// SetNillableLast sets the "last" field if the given value is not nil.
func (uuo *UserUpdateOne) SetNillableLast(s *string) *UserUpdateOne {
if s != nil {
uuo.SetLast(*s)
}
return uuo
}
// SetNickname sets the "nickname" field.
func (uuo *UserUpdateOne) SetNickname(s string) *UserUpdateOne {
uuo.mutation.SetNickname(s)
return uuo
}
// SetNillableNickname sets the "nickname" field if the given value is not nil.
func (uuo *UserUpdateOne) SetNillableNickname(s *string) *UserUpdateOne {
if s != nil {
uuo.SetNickname(*s)
}
return uuo
}
// ClearNickname clears the value of the "nickname" field.
func (uuo *UserUpdateOne) ClearNickname() *UserUpdateOne {
uuo.mutation.ClearNickname()
return uuo
}
// SetAddress sets the "address" field.
func (uuo *UserUpdateOne) SetAddress(s string) *UserUpdateOne {
uuo.mutation.SetAddress(s)
return uuo
}
// SetNillableAddress sets the "address" field if the given value is not nil.
func (uuo *UserUpdateOne) SetNillableAddress(s *string) *UserUpdateOne {
if s != nil {
uuo.SetAddress(*s)
}
return uuo
}
// ClearAddress clears the value of the "address" field.
func (uuo *UserUpdateOne) ClearAddress() *UserUpdateOne {
uuo.mutation.ClearAddress()
return uuo
}
// SetPhone sets the "phone" field.
func (uuo *UserUpdateOne) SetPhone(s string) *UserUpdateOne {
uuo.mutation.SetPhone(s)
return uuo
}
// SetNillablePhone sets the "phone" field if the given value is not nil.
func (uuo *UserUpdateOne) SetNillablePhone(s *string) *UserUpdateOne {
if s != nil {
uuo.SetPhone(*s)
}
return uuo
}
// ClearPhone clears the value of the "phone" field.
func (uuo *UserUpdateOne) ClearPhone() *UserUpdateOne {
uuo.mutation.ClearPhone()
return uuo
}
// SetPassword sets the "password" field.
func (uuo *UserUpdateOne) SetPassword(s string) *UserUpdateOne {
uuo.mutation.SetPassword(s)
return uuo
}
// SetNillablePassword sets the "password" field if the given value is not nil.
func (uuo *UserUpdateOne) SetNillablePassword(s *string) *UserUpdateOne {
if s != nil {
uuo.SetPassword(*s)
}
return uuo
}
// ClearPassword clears the value of the "password" field.
func (uuo *UserUpdateOne) ClearPassword() *UserUpdateOne {
uuo.mutation.ClearPassword()
return uuo
}
// SetRole sets the "role" field.
func (uuo *UserUpdateOne) SetRole(u user.Role) *UserUpdateOne {
uuo.mutation.SetRole(u)
return uuo
}
// SetNillableRole sets the "role" field if the given value is not nil.
func (uuo *UserUpdateOne) SetNillableRole(u *user.Role) *UserUpdateOne {
if u != nil {
uuo.SetRole(*u)
}
return uuo
}
// SetEmployment sets the "employment" field.
func (uuo *UserUpdateOne) SetEmployment(u user.Employment) *UserUpdateOne {
uuo.mutation.SetEmployment(u)
return uuo
}
// SetNillableEmployment sets the "employment" field if the given value is not nil.
func (uuo *UserUpdateOne) SetNillableEmployment(u *user.Employment) *UserUpdateOne {
if u != nil {
uuo.SetEmployment(*u)
}
return uuo
}
// SetSSOCert sets the "SSOCert" field.
func (uuo *UserUpdateOne) SetSSOCert(s string) *UserUpdateOne {
uuo.mutation.SetSSOCert(s)
return uuo
}
// SetNillableSSOCert sets the "SSOCert" field if the given value is not nil.
func (uuo *UserUpdateOne) SetNillableSSOCert(s *string) *UserUpdateOne {
if s != nil {
uuo.SetSSOCert(*s)
}
return uuo
}
// ClearSSOCert clears the value of the "SSOCert" field.
func (uuo *UserUpdateOne) ClearSSOCert() *UserUpdateOne {
uuo.mutation.ClearSSOCert()
return uuo
}
// SetFilesCount sets the "files_count" field.
func (uuo *UserUpdateOne) SetFilesCount(i int) *UserUpdateOne {
uuo.mutation.ResetFilesCount()
uuo.mutation.SetFilesCount(i)
return uuo
}
// SetNillableFilesCount sets the "files_count" field if the given value is not nil.
func (uuo *UserUpdateOne) SetNillableFilesCount(i *int) *UserUpdateOne {
if i != nil {
uuo.SetFilesCount(*i)
}
return uuo
}
// AddFilesCount adds i to the "files_count" field.
func (uuo *UserUpdateOne) AddFilesCount(i int) *UserUpdateOne {
uuo.mutation.AddFilesCount(i)
return uuo
}
// ClearFilesCount clears the value of the "files_count" field.
func (uuo *UserUpdateOne) ClearFilesCount() *UserUpdateOne {
uuo.mutation.ClearFilesCount()
return uuo
}
// SetCardID sets the "card" edge to the Card entity by ID.
func (uuo *UserUpdateOne) SetCardID(id string) *UserUpdateOne {
uuo.mutation.SetCardID(id)
return uuo
}
// SetNillableCardID sets the "card" edge to the Card entity by ID if the given value is not nil.
func (uuo *UserUpdateOne) SetNillableCardID(id *string) *UserUpdateOne {
if id != nil {
uuo = uuo.SetCardID(*id)
}
return uuo
}
// SetCard sets the "card" edge to the Card entity.
func (uuo *UserUpdateOne) SetCard(c *Card) *UserUpdateOne {
return uuo.SetCardID(c.ID)
}
// AddPetIDs adds the "pets" edge to the Pet entity by IDs.
func (uuo *UserUpdateOne) AddPetIDs(ids ...string) *UserUpdateOne {
uuo.mutation.AddPetIDs(ids...)
return uuo
}
// AddPets adds the "pets" edges to the Pet entity.
func (uuo *UserUpdateOne) AddPets(p ...*Pet) *UserUpdateOne {
ids := make([]string, len(p))
for i := range p {
ids[i] = p[i].ID
}
return uuo.AddPetIDs(ids...)
}
// AddFileIDs adds the "files" edge to the File entity by IDs.
func (uuo *UserUpdateOne) AddFileIDs(ids ...string) *UserUpdateOne {
uuo.mutation.AddFileIDs(ids...)
return uuo
}
// AddFiles adds the "files" edges to the File entity.
func (uuo *UserUpdateOne) AddFiles(f ...*File) *UserUpdateOne {
ids := make([]string, len(f))
for i := range f {
ids[i] = f[i].ID
}
return uuo.AddFileIDs(ids...)
}
// AddGroupIDs adds the "groups" edge to the Group entity by IDs.
func (uuo *UserUpdateOne) AddGroupIDs(ids ...string) *UserUpdateOne {
uuo.mutation.AddGroupIDs(ids...)
return uuo
}
// AddGroups adds the "groups" edges to the Group entity.
func (uuo *UserUpdateOne) AddGroups(g ...*Group) *UserUpdateOne {
ids := make([]string, len(g))
for i := range g {
ids[i] = g[i].ID
}
return uuo.AddGroupIDs(ids...)
}
// AddFriendIDs adds the "friends" edge to the User entity by IDs.
func (uuo *UserUpdateOne) AddFriendIDs(ids ...string) *UserUpdateOne {
uuo.mutation.AddFriendIDs(ids...)
return uuo
}
// AddFriends adds the "friends" edges to the User entity.
func (uuo *UserUpdateOne) AddFriends(u ...*User) *UserUpdateOne {
ids := make([]string, len(u))
for i := range u {
ids[i] = u[i].ID
}
return uuo.AddFriendIDs(ids...)
}
// AddFollowerIDs adds the "followers" edge to the User entity by IDs.
func (uuo *UserUpdateOne) AddFollowerIDs(ids ...string) *UserUpdateOne {
uuo.mutation.AddFollowerIDs(ids...)
return uuo
}
// AddFollowers adds the "followers" edges to the User entity.
func (uuo *UserUpdateOne) AddFollowers(u ...*User) *UserUpdateOne {
ids := make([]string, len(u))
for i := range u {
ids[i] = u[i].ID
}
return uuo.AddFollowerIDs(ids...)
}
// AddFollowingIDs adds the "following" edge to the User entity by IDs.
func (uuo *UserUpdateOne) AddFollowingIDs(ids ...string) *UserUpdateOne {
uuo.mutation.AddFollowingIDs(ids...)
return uuo
}
// AddFollowing adds the "following" edges to the User entity.
func (uuo *UserUpdateOne) AddFollowing(u ...*User) *UserUpdateOne {
ids := make([]string, len(u))
for i := range u {
ids[i] = u[i].ID
}
return uuo.AddFollowingIDs(ids...)
}
// SetTeamID sets the "team" edge to the Pet entity by ID.
func (uuo *UserUpdateOne) SetTeamID(id string) *UserUpdateOne {
uuo.mutation.SetTeamID(id)
return uuo
}
// SetNillableTeamID sets the "team" edge to the Pet entity by ID if the given value is not nil.
func (uuo *UserUpdateOne) SetNillableTeamID(id *string) *UserUpdateOne {
if id != nil {
uuo = uuo.SetTeamID(*id)
}
return uuo
}
// SetTeam sets the "team" edge to the Pet entity.
func (uuo *UserUpdateOne) SetTeam(p *Pet) *UserUpdateOne {
return uuo.SetTeamID(p.ID)
}
// SetSpouseID sets the "spouse" edge to the User entity by ID.
func (uuo *UserUpdateOne) SetSpouseID(id string) *UserUpdateOne {
uuo.mutation.SetSpouseID(id)
return uuo
}
// SetNillableSpouseID sets the "spouse" edge to the User entity by ID if the given value is not nil.
func (uuo *UserUpdateOne) SetNillableSpouseID(id *string) *UserUpdateOne {
if id != nil {
uuo = uuo.SetSpouseID(*id)
}
return uuo
}
// SetSpouse sets the "spouse" edge to the User entity.
func (uuo *UserUpdateOne) SetSpouse(u *User) *UserUpdateOne {
return uuo.SetSpouseID(u.ID)
}
// AddChildIDs adds the "children" edge to the User entity by IDs.
func (uuo *UserUpdateOne) AddChildIDs(ids ...string) *UserUpdateOne {
uuo.mutation.AddChildIDs(ids...)
return uuo
}
// AddChildren adds the "children" edges to the User entity.
func (uuo *UserUpdateOne) AddChildren(u ...*User) *UserUpdateOne {
ids := make([]string, len(u))
for i := range u {
ids[i] = u[i].ID
}
return uuo.AddChildIDs(ids...)
}
// SetParentID sets the "parent" edge to the User entity by ID.
func (uuo *UserUpdateOne) SetParentID(id string) *UserUpdateOne {
uuo.mutation.SetParentID(id)
return uuo
}
// SetNillableParentID sets the "parent" edge to the User entity by ID if the given value is not nil.
func (uuo *UserUpdateOne) SetNillableParentID(id *string) *UserUpdateOne {
if id != nil {
uuo = uuo.SetParentID(*id)
}
return uuo
}
// SetParent sets the "parent" edge to the User entity.
func (uuo *UserUpdateOne) SetParent(u *User) *UserUpdateOne {
return uuo.SetParentID(u.ID)
}
// Mutation returns the UserMutation object of the builder.
func (uuo *UserUpdateOne) Mutation() *UserMutation {
return uuo.mutation
}
// ClearCard clears the "card" edge to the Card entity.
func (uuo *UserUpdateOne) ClearCard() *UserUpdateOne {
uuo.mutation.ClearCard()
return uuo
}
// ClearPets clears all "pets" edges to the Pet entity.
func (uuo *UserUpdateOne) ClearPets() *UserUpdateOne {
uuo.mutation.ClearPets()
return uuo
}
// RemovePetIDs removes the "pets" edge to Pet entities by IDs.
func (uuo *UserUpdateOne) RemovePetIDs(ids ...string) *UserUpdateOne {
uuo.mutation.RemovePetIDs(ids...)
return uuo
}
// RemovePets removes "pets" edges to Pet entities.
func (uuo *UserUpdateOne) RemovePets(p ...*Pet) *UserUpdateOne {
ids := make([]string, len(p))
for i := range p {
ids[i] = p[i].ID
}
return uuo.RemovePetIDs(ids...)
}
// ClearFiles clears all "files" edges to the File entity.
func (uuo *UserUpdateOne) ClearFiles() *UserUpdateOne {
uuo.mutation.ClearFiles()
return uuo
}
// RemoveFileIDs removes the "files" edge to File entities by IDs.
func (uuo *UserUpdateOne) RemoveFileIDs(ids ...string) *UserUpdateOne {
uuo.mutation.RemoveFileIDs(ids...)
return uuo
}
// RemoveFiles removes "files" edges to File entities.
func (uuo *UserUpdateOne) RemoveFiles(f ...*File) *UserUpdateOne {
ids := make([]string, len(f))
for i := range f {
ids[i] = f[i].ID
}
return uuo.RemoveFileIDs(ids...)
}
// ClearGroups clears all "groups" edges to the Group entity.
func (uuo *UserUpdateOne) ClearGroups() *UserUpdateOne {
uuo.mutation.ClearGroups()
return uuo
}
// RemoveGroupIDs removes the "groups" edge to Group entities by IDs.
func (uuo *UserUpdateOne) RemoveGroupIDs(ids ...string) *UserUpdateOne {
uuo.mutation.RemoveGroupIDs(ids...)
return uuo
}
// RemoveGroups removes "groups" edges to Group entities.
func (uuo *UserUpdateOne) RemoveGroups(g ...*Group) *UserUpdateOne {
ids := make([]string, len(g))
for i := range g {
ids[i] = g[i].ID
}
return uuo.RemoveGroupIDs(ids...)
}
// ClearFriends clears all "friends" edges to the User entity.
func (uuo *UserUpdateOne) ClearFriends() *UserUpdateOne {
uuo.mutation.ClearFriends()
return uuo
}
// RemoveFriendIDs removes the "friends" edge to User entities by IDs.
func (uuo *UserUpdateOne) RemoveFriendIDs(ids ...string) *UserUpdateOne {
uuo.mutation.RemoveFriendIDs(ids...)
return uuo
}
// RemoveFriends removes "friends" edges to User entities.
func (uuo *UserUpdateOne) RemoveFriends(u ...*User) *UserUpdateOne {
ids := make([]string, len(u))
for i := range u {
ids[i] = u[i].ID
}
return uuo.RemoveFriendIDs(ids...)
}
// ClearFollowers clears all "followers" edges to the User entity.
func (uuo *UserUpdateOne) ClearFollowers() *UserUpdateOne {
uuo.mutation.ClearFollowers()
return uuo
}
// RemoveFollowerIDs removes the "followers" edge to User entities by IDs.
func (uuo *UserUpdateOne) RemoveFollowerIDs(ids ...string) *UserUpdateOne {
uuo.mutation.RemoveFollowerIDs(ids...)
return uuo
}
// RemoveFollowers removes "followers" edges to User entities.
func (uuo *UserUpdateOne) RemoveFollowers(u ...*User) *UserUpdateOne {
ids := make([]string, len(u))
for i := range u {
ids[i] = u[i].ID
}
return uuo.RemoveFollowerIDs(ids...)
}
// ClearFollowing clears all "following" edges to the User entity.
func (uuo *UserUpdateOne) ClearFollowing() *UserUpdateOne {
uuo.mutation.ClearFollowing()
return uuo
}
// RemoveFollowingIDs removes the "following" edge to User entities by IDs.
func (uuo *UserUpdateOne) RemoveFollowingIDs(ids ...string) *UserUpdateOne {
uuo.mutation.RemoveFollowingIDs(ids...)
return uuo
}
// RemoveFollowing removes "following" edges to User entities.
func (uuo *UserUpdateOne) RemoveFollowing(u ...*User) *UserUpdateOne {
ids := make([]string, len(u))
for i := range u {
ids[i] = u[i].ID
}
return uuo.RemoveFollowingIDs(ids...)
}
// ClearTeam clears the "team" edge to the Pet entity.
func (uuo *UserUpdateOne) ClearTeam() *UserUpdateOne {
uuo.mutation.ClearTeam()
return uuo
}
// ClearSpouse clears the "spouse" edge to the User entity.
func (uuo *UserUpdateOne) ClearSpouse() *UserUpdateOne {
uuo.mutation.ClearSpouse()
return uuo
}
// ClearChildren clears all "children" edges to the User entity.
func (uuo *UserUpdateOne) ClearChildren() *UserUpdateOne {
uuo.mutation.ClearChildren()
return uuo
}
// RemoveChildIDs removes the "children" edge to User entities by IDs.
func (uuo *UserUpdateOne) RemoveChildIDs(ids ...string) *UserUpdateOne {
uuo.mutation.RemoveChildIDs(ids...)
return uuo
}
// RemoveChildren removes "children" edges to User entities.
func (uuo *UserUpdateOne) RemoveChildren(u ...*User) *UserUpdateOne {
ids := make([]string, len(u))
for i := range u {
ids[i] = u[i].ID
}
return uuo.RemoveChildIDs(ids...)
}
// ClearParent clears the "parent" edge to the User entity.
func (uuo *UserUpdateOne) ClearParent() *UserUpdateOne {
uuo.mutation.ClearParent()
return uuo
}
// Where appends a list predicates to the UserUpdate builder.
func (uuo *UserUpdateOne) Where(ps ...predicate.User) *UserUpdateOne {
uuo.mutation.Where(ps...)
return uuo
}
// Select allows selecting one or more fields (columns) of the returned entity.
// The default is selecting all fields defined in the entity schema.
func (uuo *UserUpdateOne) Select(field string, fields ...string) *UserUpdateOne {
uuo.fields = append([]string{field}, fields...)
return uuo
}
// Save executes the query and returns the updated User entity.
func (uuo *UserUpdateOne) Save(ctx context.Context) (*User, error) {
return withHooks(ctx, uuo.gremlinSave, uuo.mutation, uuo.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (uuo *UserUpdateOne) SaveX(ctx context.Context) *User {
node, err := uuo.Save(ctx)
if err != nil {
panic(err)
}
return node
}
// 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)
}
}
// check runs all checks and user-defined validators on the builder.
func (uuo *UserUpdateOne) check() error {
if v, ok := uuo.mutation.OptionalInt(); ok {
if err := user.OptionalIntValidator(v); err != nil {
return &ValidationError{Name: "optional_int", err: fmt.Errorf(`ent: validator failed for field "User.optional_int": %w`, err)}
}
}
if v, ok := uuo.mutation.Role(); ok {
if err := user.RoleValidator(v); err != nil {
return &ValidationError{Name: "role", err: fmt.Errorf(`ent: validator failed for field "User.role": %w`, err)}
}
}
if v, ok := uuo.mutation.Employment(); ok {
if err := user.EmploymentValidator(v); err != nil {
return &ValidationError{Name: "employment", err: fmt.Errorf(`ent: validator failed for field "User.employment": %w`, err)}
}
}
return nil
}
func (uuo *UserUpdateOne) gremlinSave(ctx context.Context) (*User, error) {
if err := uuo.check(); err != nil {
return nil, err
}
res := &gremlin.Response{}
id, ok := uuo.mutation.ID()
if !ok {
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "User.id" for update`)}
}
query, bindings := uuo.gremlin(id).Query()
if err := uuo.driver.Exec(ctx, query, bindings, res); err != nil {
return nil, err
}
if err, ok := isConstantError(res); ok {
return nil, err
}
uuo.mutation.done = true
u := &User{config: uuo.config}
if err := u.FromResponse(res); err != nil {
return nil, err
}
return u, nil
}
func (uuo *UserUpdateOne) 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, 8)
v := g.V(id)
var (
rv = v.Clone()
_ = rv
trs []*dsl.Traversal
)
if value, ok := uuo.mutation.OptionalInt(); ok {
v.Property(dsl.Single, user.FieldOptionalInt, value)
}
if value, ok := uuo.mutation.AddedOptionalInt(); ok {
v.Property(dsl.Single, user.FieldOptionalInt, __.Union(__.Values(user.FieldOptionalInt), __.Constant(value)).Sum())
}
if value, ok := uuo.mutation.Age(); ok {
v.Property(dsl.Single, user.FieldAge, value)
}
if value, ok := uuo.mutation.AddedAge(); ok {
v.Property(dsl.Single, user.FieldAge, __.Union(__.Values(user.FieldAge), __.Constant(value)).Sum())
}
if value, ok := uuo.mutation.Name(); ok {
v.Property(dsl.Single, user.FieldName, value)
}
if value, ok := uuo.mutation.Last(); ok {
v.Property(dsl.Single, user.FieldLast, value)
}
if value, ok := uuo.mutation.Nickname(); ok {
constraints = append(constraints, &constraint{
pred: g.V().Has(user.Label, user.FieldNickname, value).Count(),
test: __.Is(p.NEQ(0)).Constant(NewErrUniqueField(user.Label, user.FieldNickname, value)),
})
v.Property(dsl.Single, user.FieldNickname, value)
}
if value, ok := uuo.mutation.Address(); ok {
v.Property(dsl.Single, user.FieldAddress, value)
}
if value, ok := uuo.mutation.Phone(); ok {
constraints = append(constraints, &constraint{
pred: g.V().Has(user.Label, user.FieldPhone, value).Count(),
test: __.Is(p.NEQ(0)).Constant(NewErrUniqueField(user.Label, user.FieldPhone, value)),
})
v.Property(dsl.Single, user.FieldPhone, value)
}
if value, ok := uuo.mutation.Password(); ok {
v.Property(dsl.Single, user.FieldPassword, value)
}
if value, ok := uuo.mutation.Role(); ok {
v.Property(dsl.Single, user.FieldRole, value)
}
if value, ok := uuo.mutation.Employment(); ok {
v.Property(dsl.Single, user.FieldEmployment, value)
}
if value, ok := uuo.mutation.SSOCert(); ok {
v.Property(dsl.Single, user.FieldSSOCert, value)
}
if value, ok := uuo.mutation.FilesCount(); ok {
v.Property(dsl.Single, user.FieldFilesCount, value)
}
if value, ok := uuo.mutation.AddedFilesCount(); ok {
v.Property(dsl.Single, user.FieldFilesCount, __.Union(__.Values(user.FieldFilesCount), __.Constant(value)).Sum())
}
var properties []any
if uuo.mutation.OptionalIntCleared() {
properties = append(properties, user.FieldOptionalInt)
}
if uuo.mutation.NicknameCleared() {
properties = append(properties, user.FieldNickname)
}
if uuo.mutation.AddressCleared() {
properties = append(properties, user.FieldAddress)
}
if uuo.mutation.PhoneCleared() {
properties = append(properties, user.FieldPhone)
}
if uuo.mutation.PasswordCleared() {
properties = append(properties, user.FieldPassword)
}
if uuo.mutation.SSOCertCleared() {
properties = append(properties, user.FieldSSOCert)
}
if uuo.mutation.FilesCountCleared() {
properties = append(properties, user.FieldFilesCount)
}
if len(properties) > 0 {
v.SideEffect(__.Properties(properties...).Drop())
}
if uuo.mutation.CardCleared() {
tr := rv.Clone().OutE(user.CardLabel).Drop().Iterate()
trs = append(trs, tr)
}
for _, id := range uuo.mutation.CardIDs() {
v.AddE(user.CardLabel).To(g.V(id)).OutV()
constraints = append(constraints, &constraint{
pred: g.E().HasLabel(user.CardLabel).InV().HasID(id).Count(),
test: __.Is(p.NEQ(0)).Constant(NewErrUniqueEdge(user.Label, user.CardLabel, id)),
})
}
for _, id := range uuo.mutation.RemovedPetsIDs() {
tr := rv.Clone().OutE(user.PetsLabel).Where(__.OtherV().HasID(id)).Drop().Iterate()
trs = append(trs, tr)
}
for _, id := range uuo.mutation.PetsIDs() {
v.AddE(user.PetsLabel).To(g.V(id)).OutV()
constraints = append(constraints, &constraint{
pred: g.E().HasLabel(user.PetsLabel).InV().HasID(id).Count(),
test: __.Is(p.NEQ(0)).Constant(NewErrUniqueEdge(user.Label, user.PetsLabel, id)),
})
}
for _, id := range uuo.mutation.RemovedFilesIDs() {
tr := rv.Clone().OutE(user.FilesLabel).Where(__.OtherV().HasID(id)).Drop().Iterate()
trs = append(trs, tr)
}
for _, id := range uuo.mutation.FilesIDs() {
v.AddE(user.FilesLabel).To(g.V(id)).OutV()
constraints = append(constraints, &constraint{
pred: g.E().HasLabel(user.FilesLabel).InV().HasID(id).Count(),
test: __.Is(p.NEQ(0)).Constant(NewErrUniqueEdge(user.Label, user.FilesLabel, id)),
})
}
for _, id := range uuo.mutation.RemovedGroupsIDs() {
tr := rv.Clone().OutE(user.GroupsLabel).Where(__.OtherV().HasID(id)).Drop().Iterate()
trs = append(trs, tr)
}
for _, id := range uuo.mutation.GroupsIDs() {
v.AddE(user.GroupsLabel).To(g.V(id)).OutV()
}
for _, id := range uuo.mutation.RemovedFriendsIDs() {
tr := rv.Clone().BothE(user.FriendsLabel).Where(__.Or(__.InV().HasID(id), __.OutV().HasID(id))).Drop().Iterate()
trs = append(trs, tr)
}
for _, id := range uuo.mutation.FriendsIDs() {
v.AddE(user.FriendsLabel).To(g.V(id)).OutV()
}
for _, id := range uuo.mutation.RemovedFollowersIDs() {
tr := rv.Clone().InE(user.FollowingLabel).Where(__.OtherV().HasID(id)).Drop().Iterate()
trs = append(trs, tr)
}
for _, id := range uuo.mutation.FollowersIDs() {
v.AddE(user.FollowingLabel).From(g.V(id)).InV()
}
for _, id := range uuo.mutation.RemovedFollowingIDs() {
tr := rv.Clone().OutE(user.FollowingLabel).Where(__.OtherV().HasID(id)).Drop().Iterate()
trs = append(trs, tr)
}
for _, id := range uuo.mutation.FollowingIDs() {
v.AddE(user.FollowingLabel).To(g.V(id)).OutV()
}
if uuo.mutation.TeamCleared() {
tr := rv.Clone().OutE(user.TeamLabel).Drop().Iterate()
trs = append(trs, tr)
}
for _, id := range uuo.mutation.TeamIDs() {
v.AddE(user.TeamLabel).To(g.V(id)).OutV()
constraints = append(constraints, &constraint{
pred: g.E().HasLabel(user.TeamLabel).InV().HasID(id).Count(),
test: __.Is(p.NEQ(0)).Constant(NewErrUniqueEdge(user.Label, user.TeamLabel, id)),
})
}
if uuo.mutation.SpouseCleared() {
tr := rv.Clone().BothE(user.SpouseLabel).Drop().Iterate()
trs = append(trs, tr)
}
for _, id := range uuo.mutation.SpouseIDs() {
v.AddE(user.SpouseLabel).To(g.V(id)).OutV()
constraints = append(constraints, &constraint{
pred: rv.Clone().Both(user.SpouseLabel).Count(),
test: __.Is(p.NEQ(0)).Constant(NewErrUniqueEdge(user.Label, user.SpouseLabel, id)),
})
constraints = append(constraints, &constraint{
pred: g.E().HasLabel(user.SpouseLabel).Where(__.Or(__.InV().HasID(id), __.OutV().HasID(id))).Count(),
test: __.Is(p.NEQ(0)).Constant(NewErrUniqueEdge(user.Label, user.SpouseLabel, id)),
})
}
for _, id := range uuo.mutation.RemovedChildrenIDs() {
tr := rv.Clone().InE(user.ParentLabel).Where(__.OtherV().HasID(id)).Drop().Iterate()
trs = append(trs, tr)
}
for _, id := range uuo.mutation.ChildrenIDs() {
v.AddE(user.ParentLabel).From(g.V(id)).InV()
constraints = append(constraints, &constraint{
pred: g.E().HasLabel(user.ParentLabel).OutV().HasID(id).Count(),
test: __.Is(p.NEQ(0)).Constant(NewErrUniqueEdge(user.Label, user.ParentLabel, id)),
})
}
if uuo.mutation.ParentCleared() {
tr := rv.Clone().OutE(user.ParentLabel).Drop().Iterate()
trs = append(trs, tr)
}
for _, id := range uuo.mutation.ParentIDs() {
v.AddE(user.ParentLabel).To(g.V(id)).OutV()
}
if len(uuo.fields) > 0 {
fields := make([]any, 0, len(uuo.fields)+1)
fields = append(fields, true)
for _, f := range uuo.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...)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/damengde/ent.git
git@gitee.com:damengde/ent.git
damengde
ent
Ent
90870c5ba095

搜索帮助