func (puo *PortalUpdateOne) SaveX(ctx context.Context) *Portal {
	node, err := puo.Save(ctx)
	if err != nil {
		panic(err)
	}
	return node
}
SaveX is like Save, but panics if an error occurs.
package ent
import (
	"context"
	"fmt"
	"entgo.io/contrib/entproto/internal/entprototest/ent/category"
	"entgo.io/contrib/entproto/internal/entprototest/ent/portal"
	"entgo.io/contrib/entproto/internal/entprototest/ent/predicate"
	"entgo.io/ent/dialect/sql"
	"entgo.io/ent/dialect/sql/sqlgraph"
	"entgo.io/ent/schema/field"
)
type PortalUpdate struct {
	config
	hooks    []Hook
	mutation *PortalMutation
}
func (pu *PortalUpdate) Where(ps ...predicate.Portal) *PortalUpdate {
	pu.mutation.Where(ps...)
	return pu
}
func (pu *PortalUpdate) SetName(s string) *PortalUpdate {
	pu.mutation.SetName(s)
	return pu
}
func (pu *PortalUpdate) SetDescription(s string) *PortalUpdate {
	pu.mutation.SetDescription(s)
	return pu
}
func (pu *PortalUpdate) SetCategoryID(id int) *PortalUpdate {
	pu.mutation.SetCategoryID(id)
	return pu
}
func (pu *PortalUpdate) SetNillableCategoryID(id *int) *PortalUpdate {
	if id != nil {
		pu = pu.SetCategoryID(*id)
	}
	return pu
}
func (pu *PortalUpdate) SetCategory(c *Category) *PortalUpdate {
	return pu.SetCategoryID(c.ID)
}
func (pu *PortalUpdate) Mutation() *PortalMutation {
	return pu.mutation
}
func (pu *PortalUpdate) ClearCategory() *PortalUpdate {
	pu.mutation.ClearCategory()
	return pu
}
func (pu *PortalUpdate) Save(ctx context.Context) (int, error) {
	var (
		err      error
		affected int
	)
	if len(pu.hooks) == 0 {
		affected, err = pu.sqlSave(ctx)
	} else {
		var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
			mutation, ok := m.(*PortalMutation)
			if !ok {
				return nil, fmt.Errorf("unexpected mutation type %T", m)
			}
			pu.mutation = mutation
			affected, err = pu.sqlSave(ctx)
			mutation.done = true
			return affected, err
		})
		for i := len(pu.hooks) - 1; i >= 0; i-- {
			if pu.hooks[i] == nil {
				return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
			}
			mut = pu.hooks[i](mut)
		}
		if _, err := mut.Mutate(ctx, pu.mutation); err != nil {
			return 0, err
		}
	}
	return affected, err
}
func (pu *PortalUpdate) SaveX(ctx context.Context) int {
	affected, err := pu.Save(ctx)
	if err != nil {
		panic(err)
	}
	return affected
}
func (pu *PortalUpdate) Exec(ctx context.Context) error {
	_, err := pu.Save(ctx)
	return err
}
func (pu *PortalUpdate) ExecX(ctx context.Context) {
	if err := pu.Exec(ctx); err != nil {
		panic(err)
	}
}
func (pu *PortalUpdate) sqlSave(ctx context.Context) (n int, err error) {
	_spec := &sqlgraph.UpdateSpec{
		Node: &sqlgraph.NodeSpec{
			Table:   portal.Table,
			Columns: portal.Columns,
			ID: &sqlgraph.FieldSpec{
				Type:   field.TypeInt,
				Column: portal.FieldID,
			},
		},
	}
	if ps := pu.mutation.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	if value, ok := pu.mutation.Name(); ok {
		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
			Type:   field.TypeString,
			Value:  value,
			Column: portal.FieldName,
		})
	}
	if value, ok := pu.mutation.Description(); ok {
		_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
			Type:   field.TypeString,
			Value:  value,
			Column: portal.FieldDescription,
		})
	}
	if pu.mutation.CategoryCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: false,
			Table:   portal.CategoryTable,
			Columns: []string{portal.CategoryColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: &sqlgraph.FieldSpec{
					Type:   field.TypeInt,
					Column: category.FieldID,
				},
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := pu.mutation.CategoryIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: false,
			Table:   portal.CategoryTable,
			Columns: []string{portal.CategoryColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: &sqlgraph.FieldSpec{
					Type:   field.TypeInt,
					Column: category.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, pu.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{portal.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{err.Error(), err}
		}
		return 0, err
	}
	return n, nil
}
type PortalUpdateOne struct {
	config
	fields   []string
	hooks    []Hook
	mutation *PortalMutation
}
func (puo *PortalUpdateOne) SetName(s string) *PortalUpdateOne {
	puo.mutation.SetName(s)
	return puo
}
func (puo *PortalUpdateOne) SetDescription(s string) *PortalUpdateOne {
	puo.mutation.SetDescription(s)
	return puo
}
func (puo *PortalUpdateOne) SetCategoryID(id int) *PortalUpdateOne {
	puo.mutation.SetCategoryID(id)
	return puo
}
func (puo *PortalUpdateOne) SetNillableCategoryID(id *int) *PortalUpdateOne {
	if id != nil {
		puo = puo.SetCategoryID(*id)
	}
	return puo
}
func (puo *PortalUpdateOne) SetCategory(c *Category) *PortalUpdateOne {
	return puo.SetCategoryID(c.ID)
}
func (puo *PortalUpdateOne) Mutation() *PortalMutation {
	return puo.mutation
}
func (puo *PortalUpdateOne) ClearCategory() *PortalUpdateOne {
	puo.mutation.ClearCategory()
	return puo
}
func (puo *PortalUpdateOne) Select(field string, fields ...string) *PortalUpdateOne {
	puo.fields = append([]string{field}, fields...)
	return puo
}
func (puo *PortalUpdateOne) Save(ctx context.Context) (*Portal, error) {
	var (
		err  error
		node *Portal
	)
	if len(puo.hooks) == 0 {
		node, err = puo.sqlSave(ctx)
	} else {
		var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
			mutation, ok := m.(*PortalMutation)
			if !ok {
				return nil, fmt.Errorf("unexpected mutation type %T", m)
			}
			puo.mutation = mutation
			node, err = puo.sqlSave(ctx)
			mutation.done = true
			return node, err
		})
		for i := len(puo.hooks) - 1; i >= 0; i-- {
			if puo.hooks[i] == nil {
				return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
			}
			mut = puo.hooks[i](mut)
		}
		if _, err := mut.Mutate(ctx, puo.mutation); err != nil {
			return nil, err
		}
	}
	return node, err
}