|
@@ -0,0 +1,1519 @@
|
|
|
+
|
|
|
+
|
|
|
+package ent
|
|
|
+
|
|
|
+import (
|
|
|
+ "context"
|
|
|
+ "errors"
|
|
|
+ "fmt"
|
|
|
+
|
|
|
+ "code.osinet.fr/fgm/go__ent_demo/ent/car"
|
|
|
+ "code.osinet.fr/fgm/go__ent_demo/ent/group"
|
|
|
+ "code.osinet.fr/fgm/go__ent_demo/ent/predicate"
|
|
|
+ "code.osinet.fr/fgm/go__ent_demo/ent/user"
|
|
|
+ "entgo.io/ent/dialect/sql"
|
|
|
+ "entgo.io/ent/dialect/sql/sqlgraph"
|
|
|
+ "entgo.io/ent/schema/field"
|
|
|
+)
|
|
|
+
|
|
|
+
|
|
|
+type UserUpdate struct {
|
|
|
+ config
|
|
|
+ hooks []Hook
|
|
|
+ mutation *UserMutation
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (uu *UserUpdate) Where(ps ...predicate.User) *UserUpdate {
|
|
|
+ uu.mutation.Where(ps...)
|
|
|
+ return uu
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (uu *UserUpdate) SetAge(i int) *UserUpdate {
|
|
|
+ uu.mutation.ResetAge()
|
|
|
+ uu.mutation.SetAge(i)
|
|
|
+ return uu
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (uu *UserUpdate) AddAge(i int) *UserUpdate {
|
|
|
+ uu.mutation.AddAge(i)
|
|
|
+ return uu
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (uu *UserUpdate) SetName(s string) *UserUpdate {
|
|
|
+ uu.mutation.SetName(s)
|
|
|
+ return uu
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (uu *UserUpdate) SetNillableName(s *string) *UserUpdate {
|
|
|
+ if s != nil {
|
|
|
+ uu.SetName(*s)
|
|
|
+ }
|
|
|
+ return uu
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (uu *UserUpdate) SetPassword(s string) *UserUpdate {
|
|
|
+ uu.mutation.SetPassword(s)
|
|
|
+ return uu
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (uu *UserUpdate) SetNillablePassword(s *string) *UserUpdate {
|
|
|
+ if s != nil {
|
|
|
+ uu.SetPassword(*s)
|
|
|
+ }
|
|
|
+ return uu
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (uu *UserUpdate) ClearPassword() *UserUpdate {
|
|
|
+ uu.mutation.ClearPassword()
|
|
|
+ return uu
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (uu *UserUpdate) SetSize(u user.Size) *UserUpdate {
|
|
|
+ uu.mutation.SetSize(u)
|
|
|
+ return uu
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (uu *UserUpdate) SetNillableSize(u *user.Size) *UserUpdate {
|
|
|
+ if u != nil {
|
|
|
+ uu.SetSize(*u)
|
|
|
+ }
|
|
|
+ return uu
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (uu *UserUpdate) SetSpouseID(i int) *UserUpdate {
|
|
|
+ uu.mutation.SetSpouseID(i)
|
|
|
+ return uu
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (uu *UserUpdate) SetNillableSpouseID(i *int) *UserUpdate {
|
|
|
+ if i != nil {
|
|
|
+ uu.SetSpouseID(*i)
|
|
|
+ }
|
|
|
+ return uu
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (uu *UserUpdate) ClearSpouseID() *UserUpdate {
|
|
|
+ uu.mutation.ClearSpouseID()
|
|
|
+ return uu
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (uu *UserUpdate) AddCarIDs(ids ...int) *UserUpdate {
|
|
|
+ uu.mutation.AddCarIDs(ids...)
|
|
|
+ return uu
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (uu *UserUpdate) AddCars(c ...*Car) *UserUpdate {
|
|
|
+ ids := make([]int, len(c))
|
|
|
+ for i := range c {
|
|
|
+ ids[i] = c[i].ID
|
|
|
+ }
|
|
|
+ return uu.AddCarIDs(ids...)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (uu *UserUpdate) AddGroupIDs(ids ...int) *UserUpdate {
|
|
|
+ uu.mutation.AddGroupIDs(ids...)
|
|
|
+ return uu
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (uu *UserUpdate) AddGroups(g ...*Group) *UserUpdate {
|
|
|
+ ids := make([]int, len(g))
|
|
|
+ for i := range g {
|
|
|
+ ids[i] = g[i].ID
|
|
|
+ }
|
|
|
+ return uu.AddGroupIDs(ids...)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (uu *UserUpdate) SetSpouse(u *User) *UserUpdate {
|
|
|
+ return uu.SetSpouseID(u.ID)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (uu *UserUpdate) AddFollowerIDs(ids ...int) *UserUpdate {
|
|
|
+ uu.mutation.AddFollowerIDs(ids...)
|
|
|
+ return uu
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (uu *UserUpdate) AddFollowers(u ...*User) *UserUpdate {
|
|
|
+ ids := make([]int, len(u))
|
|
|
+ for i := range u {
|
|
|
+ ids[i] = u[i].ID
|
|
|
+ }
|
|
|
+ return uu.AddFollowerIDs(ids...)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (uu *UserUpdate) AddFollowingIDs(ids ...int) *UserUpdate {
|
|
|
+ uu.mutation.AddFollowingIDs(ids...)
|
|
|
+ return uu
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (uu *UserUpdate) AddFollowing(u ...*User) *UserUpdate {
|
|
|
+ ids := make([]int, len(u))
|
|
|
+ for i := range u {
|
|
|
+ ids[i] = u[i].ID
|
|
|
+ }
|
|
|
+ return uu.AddFollowingIDs(ids...)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (uu *UserUpdate) AddFriendIDs(ids ...int) *UserUpdate {
|
|
|
+ uu.mutation.AddFriendIDs(ids...)
|
|
|
+ return uu
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (uu *UserUpdate) AddFriends(u ...*User) *UserUpdate {
|
|
|
+ ids := make([]int, len(u))
|
|
|
+ for i := range u {
|
|
|
+ ids[i] = u[i].ID
|
|
|
+ }
|
|
|
+ return uu.AddFriendIDs(ids...)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (uu *UserUpdate) Mutation() *UserMutation {
|
|
|
+ return uu.mutation
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (uu *UserUpdate) ClearCars() *UserUpdate {
|
|
|
+ uu.mutation.ClearCars()
|
|
|
+ return uu
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (uu *UserUpdate) RemoveCarIDs(ids ...int) *UserUpdate {
|
|
|
+ uu.mutation.RemoveCarIDs(ids...)
|
|
|
+ return uu
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (uu *UserUpdate) RemoveCars(c ...*Car) *UserUpdate {
|
|
|
+ ids := make([]int, len(c))
|
|
|
+ for i := range c {
|
|
|
+ ids[i] = c[i].ID
|
|
|
+ }
|
|
|
+ return uu.RemoveCarIDs(ids...)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (uu *UserUpdate) ClearGroups() *UserUpdate {
|
|
|
+ uu.mutation.ClearGroups()
|
|
|
+ return uu
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (uu *UserUpdate) RemoveGroupIDs(ids ...int) *UserUpdate {
|
|
|
+ uu.mutation.RemoveGroupIDs(ids...)
|
|
|
+ return uu
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (uu *UserUpdate) RemoveGroups(g ...*Group) *UserUpdate {
|
|
|
+ ids := make([]int, len(g))
|
|
|
+ for i := range g {
|
|
|
+ ids[i] = g[i].ID
|
|
|
+ }
|
|
|
+ return uu.RemoveGroupIDs(ids...)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (uu *UserUpdate) ClearSpouse() *UserUpdate {
|
|
|
+ uu.mutation.ClearSpouse()
|
|
|
+ return uu
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (uu *UserUpdate) ClearFollowers() *UserUpdate {
|
|
|
+ uu.mutation.ClearFollowers()
|
|
|
+ return uu
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (uu *UserUpdate) RemoveFollowerIDs(ids ...int) *UserUpdate {
|
|
|
+ uu.mutation.RemoveFollowerIDs(ids...)
|
|
|
+ return uu
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (uu *UserUpdate) RemoveFollowers(u ...*User) *UserUpdate {
|
|
|
+ ids := make([]int, len(u))
|
|
|
+ for i := range u {
|
|
|
+ ids[i] = u[i].ID
|
|
|
+ }
|
|
|
+ return uu.RemoveFollowerIDs(ids...)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (uu *UserUpdate) ClearFollowing() *UserUpdate {
|
|
|
+ uu.mutation.ClearFollowing()
|
|
|
+ return uu
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (uu *UserUpdate) RemoveFollowingIDs(ids ...int) *UserUpdate {
|
|
|
+ uu.mutation.RemoveFollowingIDs(ids...)
|
|
|
+ return uu
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (uu *UserUpdate) RemoveFollowing(u ...*User) *UserUpdate {
|
|
|
+ ids := make([]int, len(u))
|
|
|
+ for i := range u {
|
|
|
+ ids[i] = u[i].ID
|
|
|
+ }
|
|
|
+ return uu.RemoveFollowingIDs(ids...)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (uu *UserUpdate) ClearFriends() *UserUpdate {
|
|
|
+ uu.mutation.ClearFriends()
|
|
|
+ return uu
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (uu *UserUpdate) RemoveFriendIDs(ids ...int) *UserUpdate {
|
|
|
+ uu.mutation.RemoveFriendIDs(ids...)
|
|
|
+ return uu
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (uu *UserUpdate) RemoveFriends(u ...*User) *UserUpdate {
|
|
|
+ ids := make([]int, len(u))
|
|
|
+ for i := range u {
|
|
|
+ ids[i] = u[i].ID
|
|
|
+ }
|
|
|
+ return uu.RemoveFriendIDs(ids...)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (uu *UserUpdate) Save(ctx context.Context) (int, error) {
|
|
|
+ var (
|
|
|
+ err error
|
|
|
+ affected int
|
|
|
+ )
|
|
|
+ if len(uu.hooks) == 0 {
|
|
|
+ if err = uu.check(); err != nil {
|
|
|
+ return 0, err
|
|
|
+ }
|
|
|
+ affected, err = uu.sqlSave(ctx)
|
|
|
+ } else {
|
|
|
+ var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
|
|
+ mutation, ok := m.(*UserMutation)
|
|
|
+ if !ok {
|
|
|
+ return nil, fmt.Errorf("unexpected mutation type %T", m)
|
|
|
+ }
|
|
|
+ if err = uu.check(); err != nil {
|
|
|
+ return 0, err
|
|
|
+ }
|
|
|
+ uu.mutation = mutation
|
|
|
+ affected, err = uu.sqlSave(ctx)
|
|
|
+ mutation.done = true
|
|
|
+ return affected, err
|
|
|
+ })
|
|
|
+ for i := len(uu.hooks) - 1; i >= 0; i-- {
|
|
|
+ if uu.hooks[i] == nil {
|
|
|
+ return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
|
|
|
+ }
|
|
|
+ mut = uu.hooks[i](mut)
|
|
|
+ }
|
|
|
+ if _, err := mut.Mutate(ctx, uu.mutation); err != nil {
|
|
|
+ return 0, err
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return affected, err
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (uu *UserUpdate) SaveX(ctx context.Context) int {
|
|
|
+ affected, err := uu.Save(ctx)
|
|
|
+ if err != nil {
|
|
|
+ panic(err)
|
|
|
+ }
|
|
|
+ return affected
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (uu *UserUpdate) Exec(ctx context.Context) error {
|
|
|
+ _, err := uu.Save(ctx)
|
|
|
+ return err
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (uu *UserUpdate) ExecX(ctx context.Context) {
|
|
|
+ if err := uu.Exec(ctx); err != nil {
|
|
|
+ panic(err)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (uu *UserUpdate) check() error {
|
|
|
+ if v, ok := uu.mutation.Age(); ok {
|
|
|
+ if err := user.AgeValidator(v); err != nil {
|
|
|
+ return &ValidationError{Name: "age", err: fmt.Errorf(`ent: validator failed for field "User.age": %w`, err)}
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if v, ok := uu.mutation.Size(); ok {
|
|
|
+ if err := user.SizeValidator(v); err != nil {
|
|
|
+ return &ValidationError{Name: "size", err: fmt.Errorf(`ent: validator failed for field "User.size": %w`, err)}
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return nil
|
|
|
+}
|
|
|
+
|
|
|
+func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
|
|
+ _spec := &sqlgraph.UpdateSpec{
|
|
|
+ Node: &sqlgraph.NodeSpec{
|
|
|
+ Table: user.Table,
|
|
|
+ Columns: user.Columns,
|
|
|
+ ID: &sqlgraph.FieldSpec{
|
|
|
+ Type: field.TypeInt,
|
|
|
+ Column: user.FieldID,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ }
|
|
|
+ if ps := uu.mutation.predicates; len(ps) > 0 {
|
|
|
+ _spec.Predicate = func(selector *sql.Selector) {
|
|
|
+ for i := range ps {
|
|
|
+ ps[i](selector)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if value, ok := uu.mutation.Age(); ok {
|
|
|
+ _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
|
|
+ Type: field.TypeInt,
|
|
|
+ Value: value,
|
|
|
+ Column: user.FieldAge,
|
|
|
+ })
|
|
|
+ }
|
|
|
+ if value, ok := uu.mutation.AddedAge(); ok {
|
|
|
+ _spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
|
|
|
+ Type: field.TypeInt,
|
|
|
+ Value: value,
|
|
|
+ Column: user.FieldAge,
|
|
|
+ })
|
|
|
+ }
|
|
|
+ if value, ok := uu.mutation.Name(); ok {
|
|
|
+ _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
|
|
+ Type: field.TypeString,
|
|
|
+ Value: value,
|
|
|
+ Column: user.FieldName,
|
|
|
+ })
|
|
|
+ }
|
|
|
+ if value, ok := uu.mutation.Password(); ok {
|
|
|
+ _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
|
|
+ Type: field.TypeString,
|
|
|
+ Value: value,
|
|
|
+ Column: user.FieldPassword,
|
|
|
+ })
|
|
|
+ }
|
|
|
+ if uu.mutation.PasswordCleared() {
|
|
|
+ _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
|
|
|
+ Type: field.TypeString,
|
|
|
+ Column: user.FieldPassword,
|
|
|
+ })
|
|
|
+ }
|
|
|
+ if value, ok := uu.mutation.Size(); ok {
|
|
|
+ _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
|
|
+ Type: field.TypeEnum,
|
|
|
+ Value: value,
|
|
|
+ Column: user.FieldSize,
|
|
|
+ })
|
|
|
+ }
|
|
|
+ if uu.mutation.CarsCleared() {
|
|
|
+ edge := &sqlgraph.EdgeSpec{
|
|
|
+ Rel: sqlgraph.O2M,
|
|
|
+ Inverse: false,
|
|
|
+ Table: user.CarsTable,
|
|
|
+ Columns: []string{user.CarsColumn},
|
|
|
+ Bidi: false,
|
|
|
+ Target: &sqlgraph.EdgeTarget{
|
|
|
+ IDSpec: &sqlgraph.FieldSpec{
|
|
|
+ Type: field.TypeInt,
|
|
|
+ Column: car.FieldID,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ }
|
|
|
+ _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
|
+ }
|
|
|
+ if nodes := uu.mutation.RemovedCarsIDs(); len(nodes) > 0 && !uu.mutation.CarsCleared() {
|
|
|
+ edge := &sqlgraph.EdgeSpec{
|
|
|
+ Rel: sqlgraph.O2M,
|
|
|
+ Inverse: false,
|
|
|
+ Table: user.CarsTable,
|
|
|
+ Columns: []string{user.CarsColumn},
|
|
|
+ Bidi: false,
|
|
|
+ Target: &sqlgraph.EdgeTarget{
|
|
|
+ IDSpec: &sqlgraph.FieldSpec{
|
|
|
+ Type: field.TypeInt,
|
|
|
+ Column: car.FieldID,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ }
|
|
|
+ for _, k := range nodes {
|
|
|
+ edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
|
+ }
|
|
|
+ _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
|
+ }
|
|
|
+ if nodes := uu.mutation.CarsIDs(); len(nodes) > 0 {
|
|
|
+ edge := &sqlgraph.EdgeSpec{
|
|
|
+ Rel: sqlgraph.O2M,
|
|
|
+ Inverse: false,
|
|
|
+ Table: user.CarsTable,
|
|
|
+ Columns: []string{user.CarsColumn},
|
|
|
+ Bidi: false,
|
|
|
+ Target: &sqlgraph.EdgeTarget{
|
|
|
+ IDSpec: &sqlgraph.FieldSpec{
|
|
|
+ Type: field.TypeInt,
|
|
|
+ Column: car.FieldID,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ }
|
|
|
+ for _, k := range nodes {
|
|
|
+ edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
|
+ }
|
|
|
+ _spec.Edges.Add = append(_spec.Edges.Add, edge)
|
|
|
+ }
|
|
|
+ if uu.mutation.GroupsCleared() {
|
|
|
+ edge := &sqlgraph.EdgeSpec{
|
|
|
+ Rel: sqlgraph.M2M,
|
|
|
+ Inverse: true,
|
|
|
+ Table: user.GroupsTable,
|
|
|
+ Columns: user.GroupsPrimaryKey,
|
|
|
+ Bidi: false,
|
|
|
+ Target: &sqlgraph.EdgeTarget{
|
|
|
+ IDSpec: &sqlgraph.FieldSpec{
|
|
|
+ Type: field.TypeInt,
|
|
|
+ Column: group.FieldID,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ }
|
|
|
+ _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
|
+ }
|
|
|
+ if nodes := uu.mutation.RemovedGroupsIDs(); len(nodes) > 0 && !uu.mutation.GroupsCleared() {
|
|
|
+ edge := &sqlgraph.EdgeSpec{
|
|
|
+ Rel: sqlgraph.M2M,
|
|
|
+ Inverse: true,
|
|
|
+ Table: user.GroupsTable,
|
|
|
+ Columns: user.GroupsPrimaryKey,
|
|
|
+ Bidi: false,
|
|
|
+ Target: &sqlgraph.EdgeTarget{
|
|
|
+ IDSpec: &sqlgraph.FieldSpec{
|
|
|
+ Type: field.TypeInt,
|
|
|
+ Column: group.FieldID,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ }
|
|
|
+ for _, k := range nodes {
|
|
|
+ edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
|
+ }
|
|
|
+ _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
|
+ }
|
|
|
+ if nodes := uu.mutation.GroupsIDs(); len(nodes) > 0 {
|
|
|
+ edge := &sqlgraph.EdgeSpec{
|
|
|
+ Rel: sqlgraph.M2M,
|
|
|
+ Inverse: true,
|
|
|
+ Table: user.GroupsTable,
|
|
|
+ Columns: user.GroupsPrimaryKey,
|
|
|
+ Bidi: false,
|
|
|
+ Target: &sqlgraph.EdgeTarget{
|
|
|
+ IDSpec: &sqlgraph.FieldSpec{
|
|
|
+ Type: field.TypeInt,
|
|
|
+ Column: group.FieldID,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ }
|
|
|
+ for _, k := range nodes {
|
|
|
+ edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
|
+ }
|
|
|
+ _spec.Edges.Add = append(_spec.Edges.Add, edge)
|
|
|
+ }
|
|
|
+ if uu.mutation.SpouseCleared() {
|
|
|
+ edge := &sqlgraph.EdgeSpec{
|
|
|
+ Rel: sqlgraph.O2O,
|
|
|
+ Inverse: false,
|
|
|
+ Table: user.SpouseTable,
|
|
|
+ Columns: []string{user.SpouseColumn},
|
|
|
+ Bidi: true,
|
|
|
+ Target: &sqlgraph.EdgeTarget{
|
|
|
+ IDSpec: &sqlgraph.FieldSpec{
|
|
|
+ Type: field.TypeInt,
|
|
|
+ Column: user.FieldID,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ }
|
|
|
+ _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
|
+ }
|
|
|
+ if nodes := uu.mutation.SpouseIDs(); len(nodes) > 0 {
|
|
|
+ edge := &sqlgraph.EdgeSpec{
|
|
|
+ Rel: sqlgraph.O2O,
|
|
|
+ Inverse: false,
|
|
|
+ Table: user.SpouseTable,
|
|
|
+ Columns: []string{user.SpouseColumn},
|
|
|
+ Bidi: true,
|
|
|
+ Target: &sqlgraph.EdgeTarget{
|
|
|
+ IDSpec: &sqlgraph.FieldSpec{
|
|
|
+ Type: field.TypeInt,
|
|
|
+ Column: user.FieldID,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ }
|
|
|
+ for _, k := range nodes {
|
|
|
+ edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
|
+ }
|
|
|
+ _spec.Edges.Add = append(_spec.Edges.Add, edge)
|
|
|
+ }
|
|
|
+ if uu.mutation.FollowersCleared() {
|
|
|
+ edge := &sqlgraph.EdgeSpec{
|
|
|
+ Rel: sqlgraph.M2M,
|
|
|
+ Inverse: true,
|
|
|
+ Table: user.FollowersTable,
|
|
|
+ Columns: user.FollowersPrimaryKey,
|
|
|
+ Bidi: false,
|
|
|
+ Target: &sqlgraph.EdgeTarget{
|
|
|
+ IDSpec: &sqlgraph.FieldSpec{
|
|
|
+ Type: field.TypeInt,
|
|
|
+ Column: user.FieldID,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ }
|
|
|
+ _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
|
+ }
|
|
|
+ if nodes := uu.mutation.RemovedFollowersIDs(); len(nodes) > 0 && !uu.mutation.FollowersCleared() {
|
|
|
+ edge := &sqlgraph.EdgeSpec{
|
|
|
+ Rel: sqlgraph.M2M,
|
|
|
+ Inverse: true,
|
|
|
+ Table: user.FollowersTable,
|
|
|
+ Columns: user.FollowersPrimaryKey,
|
|
|
+ Bidi: false,
|
|
|
+ Target: &sqlgraph.EdgeTarget{
|
|
|
+ IDSpec: &sqlgraph.FieldSpec{
|
|
|
+ Type: field.TypeInt,
|
|
|
+ Column: user.FieldID,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ }
|
|
|
+ for _, k := range nodes {
|
|
|
+ edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
|
+ }
|
|
|
+ _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
|
+ }
|
|
|
+ if nodes := uu.mutation.FollowersIDs(); len(nodes) > 0 {
|
|
|
+ edge := &sqlgraph.EdgeSpec{
|
|
|
+ Rel: sqlgraph.M2M,
|
|
|
+ Inverse: true,
|
|
|
+ Table: user.FollowersTable,
|
|
|
+ Columns: user.FollowersPrimaryKey,
|
|
|
+ Bidi: false,
|
|
|
+ Target: &sqlgraph.EdgeTarget{
|
|
|
+ IDSpec: &sqlgraph.FieldSpec{
|
|
|
+ Type: field.TypeInt,
|
|
|
+ Column: user.FieldID,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ }
|
|
|
+ for _, k := range nodes {
|
|
|
+ edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
|
+ }
|
|
|
+ _spec.Edges.Add = append(_spec.Edges.Add, edge)
|
|
|
+ }
|
|
|
+ if uu.mutation.FollowingCleared() {
|
|
|
+ edge := &sqlgraph.EdgeSpec{
|
|
|
+ Rel: sqlgraph.M2M,
|
|
|
+ Inverse: false,
|
|
|
+ Table: user.FollowingTable,
|
|
|
+ Columns: user.FollowingPrimaryKey,
|
|
|
+ Bidi: false,
|
|
|
+ Target: &sqlgraph.EdgeTarget{
|
|
|
+ IDSpec: &sqlgraph.FieldSpec{
|
|
|
+ Type: field.TypeInt,
|
|
|
+ Column: user.FieldID,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ }
|
|
|
+ _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
|
+ }
|
|
|
+ if nodes := uu.mutation.RemovedFollowingIDs(); len(nodes) > 0 && !uu.mutation.FollowingCleared() {
|
|
|
+ edge := &sqlgraph.EdgeSpec{
|
|
|
+ Rel: sqlgraph.M2M,
|
|
|
+ Inverse: false,
|
|
|
+ Table: user.FollowingTable,
|
|
|
+ Columns: user.FollowingPrimaryKey,
|
|
|
+ Bidi: false,
|
|
|
+ Target: &sqlgraph.EdgeTarget{
|
|
|
+ IDSpec: &sqlgraph.FieldSpec{
|
|
|
+ Type: field.TypeInt,
|
|
|
+ Column: user.FieldID,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ }
|
|
|
+ for _, k := range nodes {
|
|
|
+ edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
|
+ }
|
|
|
+ _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
|
+ }
|
|
|
+ if nodes := uu.mutation.FollowingIDs(); len(nodes) > 0 {
|
|
|
+ edge := &sqlgraph.EdgeSpec{
|
|
|
+ Rel: sqlgraph.M2M,
|
|
|
+ Inverse: false,
|
|
|
+ Table: user.FollowingTable,
|
|
|
+ Columns: user.FollowingPrimaryKey,
|
|
|
+ Bidi: false,
|
|
|
+ Target: &sqlgraph.EdgeTarget{
|
|
|
+ IDSpec: &sqlgraph.FieldSpec{
|
|
|
+ Type: field.TypeInt,
|
|
|
+ Column: user.FieldID,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ }
|
|
|
+ for _, k := range nodes {
|
|
|
+ edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
|
+ }
|
|
|
+ _spec.Edges.Add = append(_spec.Edges.Add, edge)
|
|
|
+ }
|
|
|
+ if uu.mutation.FriendsCleared() {
|
|
|
+ edge := &sqlgraph.EdgeSpec{
|
|
|
+ Rel: sqlgraph.M2M,
|
|
|
+ Inverse: false,
|
|
|
+ Table: user.FriendsTable,
|
|
|
+ Columns: user.FriendsPrimaryKey,
|
|
|
+ Bidi: true,
|
|
|
+ Target: &sqlgraph.EdgeTarget{
|
|
|
+ IDSpec: &sqlgraph.FieldSpec{
|
|
|
+ Type: field.TypeInt,
|
|
|
+ Column: user.FieldID,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ }
|
|
|
+ _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
|
+ }
|
|
|
+ if nodes := uu.mutation.RemovedFriendsIDs(); len(nodes) > 0 && !uu.mutation.FriendsCleared() {
|
|
|
+ edge := &sqlgraph.EdgeSpec{
|
|
|
+ Rel: sqlgraph.M2M,
|
|
|
+ Inverse: false,
|
|
|
+ Table: user.FriendsTable,
|
|
|
+ Columns: user.FriendsPrimaryKey,
|
|
|
+ Bidi: true,
|
|
|
+ Target: &sqlgraph.EdgeTarget{
|
|
|
+ IDSpec: &sqlgraph.FieldSpec{
|
|
|
+ Type: field.TypeInt,
|
|
|
+ Column: user.FieldID,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ }
|
|
|
+ for _, k := range nodes {
|
|
|
+ edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
|
+ }
|
|
|
+ _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
|
+ }
|
|
|
+ if nodes := uu.mutation.FriendsIDs(); len(nodes) > 0 {
|
|
|
+ edge := &sqlgraph.EdgeSpec{
|
|
|
+ Rel: sqlgraph.M2M,
|
|
|
+ Inverse: false,
|
|
|
+ Table: user.FriendsTable,
|
|
|
+ Columns: user.FriendsPrimaryKey,
|
|
|
+ Bidi: true,
|
|
|
+ Target: &sqlgraph.EdgeTarget{
|
|
|
+ IDSpec: &sqlgraph.FieldSpec{
|
|
|
+ Type: field.TypeInt,
|
|
|
+ Column: user.FieldID,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ }
|
|
|
+ for _, k := range nodes {
|
|
|
+ edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
|
+ }
|
|
|
+ _spec.Edges.Add = append(_spec.Edges.Add, edge)
|
|
|
+ }
|
|
|
+ if n, err = sqlgraph.UpdateNodes(ctx, uu.driver, _spec); err != nil {
|
|
|
+ if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
|
|
+ err = &NotFoundError{user.Label}
|
|
|
+ } else if sqlgraph.IsConstraintError(err) {
|
|
|
+ err = &ConstraintError{err.Error(), err}
|
|
|
+ }
|
|
|
+ return 0, err
|
|
|
+ }
|
|
|
+ return n, nil
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+type UserUpdateOne struct {
|
|
|
+ config
|
|
|
+ fields []string
|
|
|
+ hooks []Hook
|
|
|
+ mutation *UserMutation
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (uuo *UserUpdateOne) SetAge(i int) *UserUpdateOne {
|
|
|
+ uuo.mutation.ResetAge()
|
|
|
+ uuo.mutation.SetAge(i)
|
|
|
+ return uuo
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (uuo *UserUpdateOne) AddAge(i int) *UserUpdateOne {
|
|
|
+ uuo.mutation.AddAge(i)
|
|
|
+ return uuo
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (uuo *UserUpdateOne) SetName(s string) *UserUpdateOne {
|
|
|
+ uuo.mutation.SetName(s)
|
|
|
+ return uuo
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (uuo *UserUpdateOne) SetNillableName(s *string) *UserUpdateOne {
|
|
|
+ if s != nil {
|
|
|
+ uuo.SetName(*s)
|
|
|
+ }
|
|
|
+ return uuo
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (uuo *UserUpdateOne) SetPassword(s string) *UserUpdateOne {
|
|
|
+ uuo.mutation.SetPassword(s)
|
|
|
+ return uuo
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (uuo *UserUpdateOne) SetNillablePassword(s *string) *UserUpdateOne {
|
|
|
+ if s != nil {
|
|
|
+ uuo.SetPassword(*s)
|
|
|
+ }
|
|
|
+ return uuo
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (uuo *UserUpdateOne) ClearPassword() *UserUpdateOne {
|
|
|
+ uuo.mutation.ClearPassword()
|
|
|
+ return uuo
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (uuo *UserUpdateOne) SetSize(u user.Size) *UserUpdateOne {
|
|
|
+ uuo.mutation.SetSize(u)
|
|
|
+ return uuo
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (uuo *UserUpdateOne) SetNillableSize(u *user.Size) *UserUpdateOne {
|
|
|
+ if u != nil {
|
|
|
+ uuo.SetSize(*u)
|
|
|
+ }
|
|
|
+ return uuo
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (uuo *UserUpdateOne) SetSpouseID(i int) *UserUpdateOne {
|
|
|
+ uuo.mutation.SetSpouseID(i)
|
|
|
+ return uuo
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (uuo *UserUpdateOne) SetNillableSpouseID(i *int) *UserUpdateOne {
|
|
|
+ if i != nil {
|
|
|
+ uuo.SetSpouseID(*i)
|
|
|
+ }
|
|
|
+ return uuo
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (uuo *UserUpdateOne) ClearSpouseID() *UserUpdateOne {
|
|
|
+ uuo.mutation.ClearSpouseID()
|
|
|
+ return uuo
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (uuo *UserUpdateOne) AddCarIDs(ids ...int) *UserUpdateOne {
|
|
|
+ uuo.mutation.AddCarIDs(ids...)
|
|
|
+ return uuo
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (uuo *UserUpdateOne) AddCars(c ...*Car) *UserUpdateOne {
|
|
|
+ ids := make([]int, len(c))
|
|
|
+ for i := range c {
|
|
|
+ ids[i] = c[i].ID
|
|
|
+ }
|
|
|
+ return uuo.AddCarIDs(ids...)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (uuo *UserUpdateOne) AddGroupIDs(ids ...int) *UserUpdateOne {
|
|
|
+ uuo.mutation.AddGroupIDs(ids...)
|
|
|
+ return uuo
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (uuo *UserUpdateOne) AddGroups(g ...*Group) *UserUpdateOne {
|
|
|
+ ids := make([]int, len(g))
|
|
|
+ for i := range g {
|
|
|
+ ids[i] = g[i].ID
|
|
|
+ }
|
|
|
+ return uuo.AddGroupIDs(ids...)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (uuo *UserUpdateOne) SetSpouse(u *User) *UserUpdateOne {
|
|
|
+ return uuo.SetSpouseID(u.ID)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (uuo *UserUpdateOne) AddFollowerIDs(ids ...int) *UserUpdateOne {
|
|
|
+ uuo.mutation.AddFollowerIDs(ids...)
|
|
|
+ return uuo
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (uuo *UserUpdateOne) AddFollowers(u ...*User) *UserUpdateOne {
|
|
|
+ ids := make([]int, len(u))
|
|
|
+ for i := range u {
|
|
|
+ ids[i] = u[i].ID
|
|
|
+ }
|
|
|
+ return uuo.AddFollowerIDs(ids...)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (uuo *UserUpdateOne) AddFollowingIDs(ids ...int) *UserUpdateOne {
|
|
|
+ uuo.mutation.AddFollowingIDs(ids...)
|
|
|
+ return uuo
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (uuo *UserUpdateOne) AddFollowing(u ...*User) *UserUpdateOne {
|
|
|
+ ids := make([]int, len(u))
|
|
|
+ for i := range u {
|
|
|
+ ids[i] = u[i].ID
|
|
|
+ }
|
|
|
+ return uuo.AddFollowingIDs(ids...)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (uuo *UserUpdateOne) AddFriendIDs(ids ...int) *UserUpdateOne {
|
|
|
+ uuo.mutation.AddFriendIDs(ids...)
|
|
|
+ return uuo
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (uuo *UserUpdateOne) AddFriends(u ...*User) *UserUpdateOne {
|
|
|
+ ids := make([]int, len(u))
|
|
|
+ for i := range u {
|
|
|
+ ids[i] = u[i].ID
|
|
|
+ }
|
|
|
+ return uuo.AddFriendIDs(ids...)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (uuo *UserUpdateOne) Mutation() *UserMutation {
|
|
|
+ return uuo.mutation
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (uuo *UserUpdateOne) ClearCars() *UserUpdateOne {
|
|
|
+ uuo.mutation.ClearCars()
|
|
|
+ return uuo
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (uuo *UserUpdateOne) RemoveCarIDs(ids ...int) *UserUpdateOne {
|
|
|
+ uuo.mutation.RemoveCarIDs(ids...)
|
|
|
+ return uuo
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (uuo *UserUpdateOne) RemoveCars(c ...*Car) *UserUpdateOne {
|
|
|
+ ids := make([]int, len(c))
|
|
|
+ for i := range c {
|
|
|
+ ids[i] = c[i].ID
|
|
|
+ }
|
|
|
+ return uuo.RemoveCarIDs(ids...)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (uuo *UserUpdateOne) ClearGroups() *UserUpdateOne {
|
|
|
+ uuo.mutation.ClearGroups()
|
|
|
+ return uuo
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (uuo *UserUpdateOne) RemoveGroupIDs(ids ...int) *UserUpdateOne {
|
|
|
+ uuo.mutation.RemoveGroupIDs(ids...)
|
|
|
+ return uuo
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (uuo *UserUpdateOne) RemoveGroups(g ...*Group) *UserUpdateOne {
|
|
|
+ ids := make([]int, len(g))
|
|
|
+ for i := range g {
|
|
|
+ ids[i] = g[i].ID
|
|
|
+ }
|
|
|
+ return uuo.RemoveGroupIDs(ids...)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (uuo *UserUpdateOne) ClearSpouse() *UserUpdateOne {
|
|
|
+ uuo.mutation.ClearSpouse()
|
|
|
+ return uuo
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (uuo *UserUpdateOne) ClearFollowers() *UserUpdateOne {
|
|
|
+ uuo.mutation.ClearFollowers()
|
|
|
+ return uuo
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (uuo *UserUpdateOne) RemoveFollowerIDs(ids ...int) *UserUpdateOne {
|
|
|
+ uuo.mutation.RemoveFollowerIDs(ids...)
|
|
|
+ return uuo
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (uuo *UserUpdateOne) RemoveFollowers(u ...*User) *UserUpdateOne {
|
|
|
+ ids := make([]int, len(u))
|
|
|
+ for i := range u {
|
|
|
+ ids[i] = u[i].ID
|
|
|
+ }
|
|
|
+ return uuo.RemoveFollowerIDs(ids...)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (uuo *UserUpdateOne) ClearFollowing() *UserUpdateOne {
|
|
|
+ uuo.mutation.ClearFollowing()
|
|
|
+ return uuo
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (uuo *UserUpdateOne) RemoveFollowingIDs(ids ...int) *UserUpdateOne {
|
|
|
+ uuo.mutation.RemoveFollowingIDs(ids...)
|
|
|
+ return uuo
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (uuo *UserUpdateOne) RemoveFollowing(u ...*User) *UserUpdateOne {
|
|
|
+ ids := make([]int, len(u))
|
|
|
+ for i := range u {
|
|
|
+ ids[i] = u[i].ID
|
|
|
+ }
|
|
|
+ return uuo.RemoveFollowingIDs(ids...)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (uuo *UserUpdateOne) ClearFriends() *UserUpdateOne {
|
|
|
+ uuo.mutation.ClearFriends()
|
|
|
+ return uuo
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (uuo *UserUpdateOne) RemoveFriendIDs(ids ...int) *UserUpdateOne {
|
|
|
+ uuo.mutation.RemoveFriendIDs(ids...)
|
|
|
+ return uuo
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (uuo *UserUpdateOne) RemoveFriends(u ...*User) *UserUpdateOne {
|
|
|
+ ids := make([]int, len(u))
|
|
|
+ for i := range u {
|
|
|
+ ids[i] = u[i].ID
|
|
|
+ }
|
|
|
+ return uuo.RemoveFriendIDs(ids...)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+func (uuo *UserUpdateOne) Select(field string, fields ...string) *UserUpdateOne {
|
|
|
+ uuo.fields = append([]string{field}, fields...)
|
|
|
+ return uuo
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (uuo *UserUpdateOne) Save(ctx context.Context) (*User, error) {
|
|
|
+ var (
|
|
|
+ err error
|
|
|
+ node *User
|
|
|
+ )
|
|
|
+ if len(uuo.hooks) == 0 {
|
|
|
+ if err = uuo.check(); err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+ node, err = uuo.sqlSave(ctx)
|
|
|
+ } else {
|
|
|
+ var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
|
|
+ mutation, ok := m.(*UserMutation)
|
|
|
+ if !ok {
|
|
|
+ return nil, fmt.Errorf("unexpected mutation type %T", m)
|
|
|
+ }
|
|
|
+ if err = uuo.check(); err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+ uuo.mutation = mutation
|
|
|
+ node, err = uuo.sqlSave(ctx)
|
|
|
+ mutation.done = true
|
|
|
+ return node, err
|
|
|
+ })
|
|
|
+ for i := len(uuo.hooks) - 1; i >= 0; i-- {
|
|
|
+ if uuo.hooks[i] == nil {
|
|
|
+ return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
|
|
|
+ }
|
|
|
+ mut = uuo.hooks[i](mut)
|
|
|
+ }
|
|
|
+ if _, err := mut.Mutate(ctx, uuo.mutation); err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return node, err
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (uuo *UserUpdateOne) SaveX(ctx context.Context) *User {
|
|
|
+ node, err := uuo.Save(ctx)
|
|
|
+ if err != nil {
|
|
|
+ panic(err)
|
|
|
+ }
|
|
|
+ return node
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (uuo *UserUpdateOne) Exec(ctx context.Context) error {
|
|
|
+ _, err := uuo.Save(ctx)
|
|
|
+ return err
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (uuo *UserUpdateOne) ExecX(ctx context.Context) {
|
|
|
+ if err := uuo.Exec(ctx); err != nil {
|
|
|
+ panic(err)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (uuo *UserUpdateOne) check() error {
|
|
|
+ if v, ok := uuo.mutation.Age(); ok {
|
|
|
+ if err := user.AgeValidator(v); err != nil {
|
|
|
+ return &ValidationError{Name: "age", err: fmt.Errorf(`ent: validator failed for field "User.age": %w`, err)}
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if v, ok := uuo.mutation.Size(); ok {
|
|
|
+ if err := user.SizeValidator(v); err != nil {
|
|
|
+ return &ValidationError{Name: "size", err: fmt.Errorf(`ent: validator failed for field "User.size": %w`, err)}
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return nil
|
|
|
+}
|
|
|
+
|
|
|
+func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error) {
|
|
|
+ _spec := &sqlgraph.UpdateSpec{
|
|
|
+ Node: &sqlgraph.NodeSpec{
|
|
|
+ Table: user.Table,
|
|
|
+ Columns: user.Columns,
|
|
|
+ ID: &sqlgraph.FieldSpec{
|
|
|
+ Type: field.TypeInt,
|
|
|
+ Column: user.FieldID,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ }
|
|
|
+ id, ok := uuo.mutation.ID()
|
|
|
+ if !ok {
|
|
|
+ return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "User.id" for update`)}
|
|
|
+ }
|
|
|
+ _spec.Node.ID.Value = id
|
|
|
+ if fields := uuo.fields; len(fields) > 0 {
|
|
|
+ _spec.Node.Columns = make([]string, 0, len(fields))
|
|
|
+ _spec.Node.Columns = append(_spec.Node.Columns, user.FieldID)
|
|
|
+ for _, f := range fields {
|
|
|
+ if !user.ValidColumn(f) {
|
|
|
+ return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
|
|
+ }
|
|
|
+ if f != user.FieldID {
|
|
|
+ _spec.Node.Columns = append(_spec.Node.Columns, f)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if ps := uuo.mutation.predicates; len(ps) > 0 {
|
|
|
+ _spec.Predicate = func(selector *sql.Selector) {
|
|
|
+ for i := range ps {
|
|
|
+ ps[i](selector)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if value, ok := uuo.mutation.Age(); ok {
|
|
|
+ _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
|
|
+ Type: field.TypeInt,
|
|
|
+ Value: value,
|
|
|
+ Column: user.FieldAge,
|
|
|
+ })
|
|
|
+ }
|
|
|
+ if value, ok := uuo.mutation.AddedAge(); ok {
|
|
|
+ _spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
|
|
|
+ Type: field.TypeInt,
|
|
|
+ Value: value,
|
|
|
+ Column: user.FieldAge,
|
|
|
+ })
|
|
|
+ }
|
|
|
+ if value, ok := uuo.mutation.Name(); ok {
|
|
|
+ _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
|
|
+ Type: field.TypeString,
|
|
|
+ Value: value,
|
|
|
+ Column: user.FieldName,
|
|
|
+ })
|
|
|
+ }
|
|
|
+ if value, ok := uuo.mutation.Password(); ok {
|
|
|
+ _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
|
|
+ Type: field.TypeString,
|
|
|
+ Value: value,
|
|
|
+ Column: user.FieldPassword,
|
|
|
+ })
|
|
|
+ }
|
|
|
+ if uuo.mutation.PasswordCleared() {
|
|
|
+ _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
|
|
|
+ Type: field.TypeString,
|
|
|
+ Column: user.FieldPassword,
|
|
|
+ })
|
|
|
+ }
|
|
|
+ if value, ok := uuo.mutation.Size(); ok {
|
|
|
+ _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
|
|
+ Type: field.TypeEnum,
|
|
|
+ Value: value,
|
|
|
+ Column: user.FieldSize,
|
|
|
+ })
|
|
|
+ }
|
|
|
+ if uuo.mutation.CarsCleared() {
|
|
|
+ edge := &sqlgraph.EdgeSpec{
|
|
|
+ Rel: sqlgraph.O2M,
|
|
|
+ Inverse: false,
|
|
|
+ Table: user.CarsTable,
|
|
|
+ Columns: []string{user.CarsColumn},
|
|
|
+ Bidi: false,
|
|
|
+ Target: &sqlgraph.EdgeTarget{
|
|
|
+ IDSpec: &sqlgraph.FieldSpec{
|
|
|
+ Type: field.TypeInt,
|
|
|
+ Column: car.FieldID,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ }
|
|
|
+ _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
|
+ }
|
|
|
+ if nodes := uuo.mutation.RemovedCarsIDs(); len(nodes) > 0 && !uuo.mutation.CarsCleared() {
|
|
|
+ edge := &sqlgraph.EdgeSpec{
|
|
|
+ Rel: sqlgraph.O2M,
|
|
|
+ Inverse: false,
|
|
|
+ Table: user.CarsTable,
|
|
|
+ Columns: []string{user.CarsColumn},
|
|
|
+ Bidi: false,
|
|
|
+ Target: &sqlgraph.EdgeTarget{
|
|
|
+ IDSpec: &sqlgraph.FieldSpec{
|
|
|
+ Type: field.TypeInt,
|
|
|
+ Column: car.FieldID,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ }
|
|
|
+ for _, k := range nodes {
|
|
|
+ edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
|
+ }
|
|
|
+ _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
|
+ }
|
|
|
+ if nodes := uuo.mutation.CarsIDs(); len(nodes) > 0 {
|
|
|
+ edge := &sqlgraph.EdgeSpec{
|
|
|
+ Rel: sqlgraph.O2M,
|
|
|
+ Inverse: false,
|
|
|
+ Table: user.CarsTable,
|
|
|
+ Columns: []string{user.CarsColumn},
|
|
|
+ Bidi: false,
|
|
|
+ Target: &sqlgraph.EdgeTarget{
|
|
|
+ IDSpec: &sqlgraph.FieldSpec{
|
|
|
+ Type: field.TypeInt,
|
|
|
+ Column: car.FieldID,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ }
|
|
|
+ for _, k := range nodes {
|
|
|
+ edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
|
+ }
|
|
|
+ _spec.Edges.Add = append(_spec.Edges.Add, edge)
|
|
|
+ }
|
|
|
+ if uuo.mutation.GroupsCleared() {
|
|
|
+ edge := &sqlgraph.EdgeSpec{
|
|
|
+ Rel: sqlgraph.M2M,
|
|
|
+ Inverse: true,
|
|
|
+ Table: user.GroupsTable,
|
|
|
+ Columns: user.GroupsPrimaryKey,
|
|
|
+ Bidi: false,
|
|
|
+ Target: &sqlgraph.EdgeTarget{
|
|
|
+ IDSpec: &sqlgraph.FieldSpec{
|
|
|
+ Type: field.TypeInt,
|
|
|
+ Column: group.FieldID,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ }
|
|
|
+ _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
|
+ }
|
|
|
+ if nodes := uuo.mutation.RemovedGroupsIDs(); len(nodes) > 0 && !uuo.mutation.GroupsCleared() {
|
|
|
+ edge := &sqlgraph.EdgeSpec{
|
|
|
+ Rel: sqlgraph.M2M,
|
|
|
+ Inverse: true,
|
|
|
+ Table: user.GroupsTable,
|
|
|
+ Columns: user.GroupsPrimaryKey,
|
|
|
+ Bidi: false,
|
|
|
+ Target: &sqlgraph.EdgeTarget{
|
|
|
+ IDSpec: &sqlgraph.FieldSpec{
|
|
|
+ Type: field.TypeInt,
|
|
|
+ Column: group.FieldID,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ }
|
|
|
+ for _, k := range nodes {
|
|
|
+ edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
|
+ }
|
|
|
+ _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
|
+ }
|
|
|
+ if nodes := uuo.mutation.GroupsIDs(); len(nodes) > 0 {
|
|
|
+ edge := &sqlgraph.EdgeSpec{
|
|
|
+ Rel: sqlgraph.M2M,
|
|
|
+ Inverse: true,
|
|
|
+ Table: user.GroupsTable,
|
|
|
+ Columns: user.GroupsPrimaryKey,
|
|
|
+ Bidi: false,
|
|
|
+ Target: &sqlgraph.EdgeTarget{
|
|
|
+ IDSpec: &sqlgraph.FieldSpec{
|
|
|
+ Type: field.TypeInt,
|
|
|
+ Column: group.FieldID,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ }
|
|
|
+ for _, k := range nodes {
|
|
|
+ edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
|
+ }
|
|
|
+ _spec.Edges.Add = append(_spec.Edges.Add, edge)
|
|
|
+ }
|
|
|
+ if uuo.mutation.SpouseCleared() {
|
|
|
+ edge := &sqlgraph.EdgeSpec{
|
|
|
+ Rel: sqlgraph.O2O,
|
|
|
+ Inverse: false,
|
|
|
+ Table: user.SpouseTable,
|
|
|
+ Columns: []string{user.SpouseColumn},
|
|
|
+ Bidi: true,
|
|
|
+ Target: &sqlgraph.EdgeTarget{
|
|
|
+ IDSpec: &sqlgraph.FieldSpec{
|
|
|
+ Type: field.TypeInt,
|
|
|
+ Column: user.FieldID,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ }
|
|
|
+ _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
|
+ }
|
|
|
+ if nodes := uuo.mutation.SpouseIDs(); len(nodes) > 0 {
|
|
|
+ edge := &sqlgraph.EdgeSpec{
|
|
|
+ Rel: sqlgraph.O2O,
|
|
|
+ Inverse: false,
|
|
|
+ Table: user.SpouseTable,
|
|
|
+ Columns: []string{user.SpouseColumn},
|
|
|
+ Bidi: true,
|
|
|
+ Target: &sqlgraph.EdgeTarget{
|
|
|
+ IDSpec: &sqlgraph.FieldSpec{
|
|
|
+ Type: field.TypeInt,
|
|
|
+ Column: user.FieldID,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ }
|
|
|
+ for _, k := range nodes {
|
|
|
+ edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
|
+ }
|
|
|
+ _spec.Edges.Add = append(_spec.Edges.Add, edge)
|
|
|
+ }
|
|
|
+ if uuo.mutation.FollowersCleared() {
|
|
|
+ edge := &sqlgraph.EdgeSpec{
|
|
|
+ Rel: sqlgraph.M2M,
|
|
|
+ Inverse: true,
|
|
|
+ Table: user.FollowersTable,
|
|
|
+ Columns: user.FollowersPrimaryKey,
|
|
|
+ Bidi: false,
|
|
|
+ Target: &sqlgraph.EdgeTarget{
|
|
|
+ IDSpec: &sqlgraph.FieldSpec{
|
|
|
+ Type: field.TypeInt,
|
|
|
+ Column: user.FieldID,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ }
|
|
|
+ _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
|
+ }
|
|
|
+ if nodes := uuo.mutation.RemovedFollowersIDs(); len(nodes) > 0 && !uuo.mutation.FollowersCleared() {
|
|
|
+ edge := &sqlgraph.EdgeSpec{
|
|
|
+ Rel: sqlgraph.M2M,
|
|
|
+ Inverse: true,
|
|
|
+ Table: user.FollowersTable,
|
|
|
+ Columns: user.FollowersPrimaryKey,
|
|
|
+ Bidi: false,
|
|
|
+ Target: &sqlgraph.EdgeTarget{
|
|
|
+ IDSpec: &sqlgraph.FieldSpec{
|
|
|
+ Type: field.TypeInt,
|
|
|
+ Column: user.FieldID,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ }
|
|
|
+ for _, k := range nodes {
|
|
|
+ edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
|
+ }
|
|
|
+ _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
|
+ }
|
|
|
+ if nodes := uuo.mutation.FollowersIDs(); len(nodes) > 0 {
|
|
|
+ edge := &sqlgraph.EdgeSpec{
|
|
|
+ Rel: sqlgraph.M2M,
|
|
|
+ Inverse: true,
|
|
|
+ Table: user.FollowersTable,
|
|
|
+ Columns: user.FollowersPrimaryKey,
|
|
|
+ Bidi: false,
|
|
|
+ Target: &sqlgraph.EdgeTarget{
|
|
|
+ IDSpec: &sqlgraph.FieldSpec{
|
|
|
+ Type: field.TypeInt,
|
|
|
+ Column: user.FieldID,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ }
|
|
|
+ for _, k := range nodes {
|
|
|
+ edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
|
+ }
|
|
|
+ _spec.Edges.Add = append(_spec.Edges.Add, edge)
|
|
|
+ }
|
|
|
+ if uuo.mutation.FollowingCleared() {
|
|
|
+ edge := &sqlgraph.EdgeSpec{
|
|
|
+ Rel: sqlgraph.M2M,
|
|
|
+ Inverse: false,
|
|
|
+ Table: user.FollowingTable,
|
|
|
+ Columns: user.FollowingPrimaryKey,
|
|
|
+ Bidi: false,
|
|
|
+ Target: &sqlgraph.EdgeTarget{
|
|
|
+ IDSpec: &sqlgraph.FieldSpec{
|
|
|
+ Type: field.TypeInt,
|
|
|
+ Column: user.FieldID,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ }
|
|
|
+ _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
|
+ }
|
|
|
+ if nodes := uuo.mutation.RemovedFollowingIDs(); len(nodes) > 0 && !uuo.mutation.FollowingCleared() {
|
|
|
+ edge := &sqlgraph.EdgeSpec{
|
|
|
+ Rel: sqlgraph.M2M,
|
|
|
+ Inverse: false,
|
|
|
+ Table: user.FollowingTable,
|
|
|
+ Columns: user.FollowingPrimaryKey,
|
|
|
+ Bidi: false,
|
|
|
+ Target: &sqlgraph.EdgeTarget{
|
|
|
+ IDSpec: &sqlgraph.FieldSpec{
|
|
|
+ Type: field.TypeInt,
|
|
|
+ Column: user.FieldID,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ }
|
|
|
+ for _, k := range nodes {
|
|
|
+ edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
|
+ }
|
|
|
+ _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
|
+ }
|
|
|
+ if nodes := uuo.mutation.FollowingIDs(); len(nodes) > 0 {
|
|
|
+ edge := &sqlgraph.EdgeSpec{
|
|
|
+ Rel: sqlgraph.M2M,
|
|
|
+ Inverse: false,
|
|
|
+ Table: user.FollowingTable,
|
|
|
+ Columns: user.FollowingPrimaryKey,
|
|
|
+ Bidi: false,
|
|
|
+ Target: &sqlgraph.EdgeTarget{
|
|
|
+ IDSpec: &sqlgraph.FieldSpec{
|
|
|
+ Type: field.TypeInt,
|
|
|
+ Column: user.FieldID,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ }
|
|
|
+ for _, k := range nodes {
|
|
|
+ edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
|
+ }
|
|
|
+ _spec.Edges.Add = append(_spec.Edges.Add, edge)
|
|
|
+ }
|
|
|
+ if uuo.mutation.FriendsCleared() {
|
|
|
+ edge := &sqlgraph.EdgeSpec{
|
|
|
+ Rel: sqlgraph.M2M,
|
|
|
+ Inverse: false,
|
|
|
+ Table: user.FriendsTable,
|
|
|
+ Columns: user.FriendsPrimaryKey,
|
|
|
+ Bidi: true,
|
|
|
+ Target: &sqlgraph.EdgeTarget{
|
|
|
+ IDSpec: &sqlgraph.FieldSpec{
|
|
|
+ Type: field.TypeInt,
|
|
|
+ Column: user.FieldID,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ }
|
|
|
+ _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
|
+ }
|
|
|
+ if nodes := uuo.mutation.RemovedFriendsIDs(); len(nodes) > 0 && !uuo.mutation.FriendsCleared() {
|
|
|
+ edge := &sqlgraph.EdgeSpec{
|
|
|
+ Rel: sqlgraph.M2M,
|
|
|
+ Inverse: false,
|
|
|
+ Table: user.FriendsTable,
|
|
|
+ Columns: user.FriendsPrimaryKey,
|
|
|
+ Bidi: true,
|
|
|
+ Target: &sqlgraph.EdgeTarget{
|
|
|
+ IDSpec: &sqlgraph.FieldSpec{
|
|
|
+ Type: field.TypeInt,
|
|
|
+ Column: user.FieldID,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ }
|
|
|
+ for _, k := range nodes {
|
|
|
+ edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
|
+ }
|
|
|
+ _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
|
+ }
|
|
|
+ if nodes := uuo.mutation.FriendsIDs(); len(nodes) > 0 {
|
|
|
+ edge := &sqlgraph.EdgeSpec{
|
|
|
+ Rel: sqlgraph.M2M,
|
|
|
+ Inverse: false,
|
|
|
+ Table: user.FriendsTable,
|
|
|
+ Columns: user.FriendsPrimaryKey,
|
|
|
+ Bidi: true,
|
|
|
+ Target: &sqlgraph.EdgeTarget{
|
|
|
+ IDSpec: &sqlgraph.FieldSpec{
|
|
|
+ Type: field.TypeInt,
|
|
|
+ Column: user.FieldID,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ }
|
|
|
+ for _, k := range nodes {
|
|
|
+ edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
|
+ }
|
|
|
+ _spec.Edges.Add = append(_spec.Edges.Add, edge)
|
|
|
+ }
|
|
|
+ _node = &User{config: uuo.config}
|
|
|
+ _spec.Assign = _node.assignValues
|
|
|
+ _spec.ScanValues = _node.scanValues
|
|
|
+ if err = sqlgraph.UpdateNode(ctx, uuo.driver, _spec); err != nil {
|
|
|
+ if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
|
|
+ err = &NotFoundError{user.Label}
|
|
|
+ } else if sqlgraph.IsConstraintError(err) {
|
|
|
+ err = &ConstraintError{err.Error(), err}
|
|
|
+ }
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+ return _node, nil
|
|
|
+}
|