Первый прототип с основными возможностями
This commit is contained in:
339
ent/user_update.go
Normal file
339
ent/user_update.go
Normal file
@@ -0,0 +1,339 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"code.gurenya.net/carlsmei/muninn-aio/ent/link"
|
||||
"code.gurenya.net/carlsmei/muninn-aio/ent/predicate"
|
||||
"code.gurenya.net/carlsmei/muninn-aio/ent/user"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
// AddLinkIDs adds the "links" edge to the Link entity by IDs.
|
||||
func (uu *UserUpdate) AddLinkIDs(ids ...uuid.UUID) *UserUpdate {
|
||||
uu.mutation.AddLinkIDs(ids...)
|
||||
return uu
|
||||
}
|
||||
|
||||
// AddLinks adds the "links" edges to the Link entity.
|
||||
func (uu *UserUpdate) AddLinks(l ...*Link) *UserUpdate {
|
||||
ids := make([]uuid.UUID, len(l))
|
||||
for i := range l {
|
||||
ids[i] = l[i].ID
|
||||
}
|
||||
return uu.AddLinkIDs(ids...)
|
||||
}
|
||||
|
||||
// Mutation returns the UserMutation object of the builder.
|
||||
func (uu *UserUpdate) Mutation() *UserMutation {
|
||||
return uu.mutation
|
||||
}
|
||||
|
||||
// ClearLinks clears all "links" edges to the Link entity.
|
||||
func (uu *UserUpdate) ClearLinks() *UserUpdate {
|
||||
uu.mutation.ClearLinks()
|
||||
return uu
|
||||
}
|
||||
|
||||
// RemoveLinkIDs removes the "links" edge to Link entities by IDs.
|
||||
func (uu *UserUpdate) RemoveLinkIDs(ids ...uuid.UUID) *UserUpdate {
|
||||
uu.mutation.RemoveLinkIDs(ids...)
|
||||
return uu
|
||||
}
|
||||
|
||||
// RemoveLinks removes "links" edges to Link entities.
|
||||
func (uu *UserUpdate) RemoveLinks(l ...*Link) *UserUpdate {
|
||||
ids := make([]uuid.UUID, len(l))
|
||||
for i := range l {
|
||||
ids[i] = l[i].ID
|
||||
}
|
||||
return uu.RemoveLinkIDs(ids...)
|
||||
}
|
||||
|
||||
// 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.sqlSave, 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)
|
||||
}
|
||||
}
|
||||
|
||||
func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
_spec := sqlgraph.NewUpdateSpec(user.Table, user.Columns, sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID))
|
||||
if ps := uu.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if uu.mutation.LinksCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2M,
|
||||
Inverse: false,
|
||||
Table: user.LinksTable,
|
||||
Columns: user.LinksPrimaryKey,
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(link.FieldID, field.TypeUUID),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := uu.mutation.RemovedLinksIDs(); len(nodes) > 0 && !uu.mutation.LinksCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2M,
|
||||
Inverse: false,
|
||||
Table: user.LinksTable,
|
||||
Columns: user.LinksPrimaryKey,
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(link.FieldID, field.TypeUUID),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := uu.mutation.LinksIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2M,
|
||||
Inverse: false,
|
||||
Table: user.LinksTable,
|
||||
Columns: user.LinksPrimaryKey,
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(link.FieldID, field.TypeUUID),
|
||||
},
|
||||
}
|
||||
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{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
uu.mutation.done = true
|
||||
return n, nil
|
||||
}
|
||||
|
||||
// UserUpdateOne is the builder for updating a single User entity.
|
||||
type UserUpdateOne struct {
|
||||
config
|
||||
fields []string
|
||||
hooks []Hook
|
||||
mutation *UserMutation
|
||||
}
|
||||
|
||||
// AddLinkIDs adds the "links" edge to the Link entity by IDs.
|
||||
func (uuo *UserUpdateOne) AddLinkIDs(ids ...uuid.UUID) *UserUpdateOne {
|
||||
uuo.mutation.AddLinkIDs(ids...)
|
||||
return uuo
|
||||
}
|
||||
|
||||
// AddLinks adds the "links" edges to the Link entity.
|
||||
func (uuo *UserUpdateOne) AddLinks(l ...*Link) *UserUpdateOne {
|
||||
ids := make([]uuid.UUID, len(l))
|
||||
for i := range l {
|
||||
ids[i] = l[i].ID
|
||||
}
|
||||
return uuo.AddLinkIDs(ids...)
|
||||
}
|
||||
|
||||
// Mutation returns the UserMutation object of the builder.
|
||||
func (uuo *UserUpdateOne) Mutation() *UserMutation {
|
||||
return uuo.mutation
|
||||
}
|
||||
|
||||
// ClearLinks clears all "links" edges to the Link entity.
|
||||
func (uuo *UserUpdateOne) ClearLinks() *UserUpdateOne {
|
||||
uuo.mutation.ClearLinks()
|
||||
return uuo
|
||||
}
|
||||
|
||||
// RemoveLinkIDs removes the "links" edge to Link entities by IDs.
|
||||
func (uuo *UserUpdateOne) RemoveLinkIDs(ids ...uuid.UUID) *UserUpdateOne {
|
||||
uuo.mutation.RemoveLinkIDs(ids...)
|
||||
return uuo
|
||||
}
|
||||
|
||||
// RemoveLinks removes "links" edges to Link entities.
|
||||
func (uuo *UserUpdateOne) RemoveLinks(l ...*Link) *UserUpdateOne {
|
||||
ids := make([]uuid.UUID, len(l))
|
||||
for i := range l {
|
||||
ids[i] = l[i].ID
|
||||
}
|
||||
return uuo.RemoveLinkIDs(ids...)
|
||||
}
|
||||
|
||||
// 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.sqlSave, 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)
|
||||
}
|
||||
}
|
||||
|
||||
func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error) {
|
||||
_spec := sqlgraph.NewUpdateSpec(user.Table, user.Columns, sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID))
|
||||
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 uuo.mutation.LinksCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2M,
|
||||
Inverse: false,
|
||||
Table: user.LinksTable,
|
||||
Columns: user.LinksPrimaryKey,
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(link.FieldID, field.TypeUUID),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := uuo.mutation.RemovedLinksIDs(); len(nodes) > 0 && !uuo.mutation.LinksCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2M,
|
||||
Inverse: false,
|
||||
Table: user.LinksTable,
|
||||
Columns: user.LinksPrimaryKey,
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(link.FieldID, field.TypeUUID),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := uuo.mutation.LinksIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2M,
|
||||
Inverse: false,
|
||||
Table: user.LinksTable,
|
||||
Columns: user.LinksPrimaryKey,
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(link.FieldID, field.TypeUUID),
|
||||
},
|
||||
}
|
||||
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{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
uuo.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
Reference in New Issue
Block a user