Documentation
¶
Index ¶
- Constants
- Variables
- func Asc(fields ...string) func(*sql.Selector)
- func DeleteBatchNodes(ctx context.Context, db *Client, ids []uuid.UUID) (int, error)
- func DeleteNode(ctx context.Context, db *Client, id uuid.UUID) error
- func Desc(fields ...string) func(*sql.Selector)
- func IsConstraintError(err error) bool
- func IsNotFound(err error) bool
- func IsNotLoaded(err error) bool
- func IsNotSingular(err error) bool
- func IsValidationError(err error) bool
- func ListNodes(ctx context.Context, db *Client, f *NodeFilter, r entapi.ListRequest) (*entapi.Page[NodeResponse], error)
- func MaskNotFound(err error) error
- func NewContext(parent context.Context, c *Client) context.Context
- func NewTxContext(parent context.Context, tx *Tx) context.Context
- func NodeCreateRequestTags() []string
- func NodeOrder(r entapi.ListRequest) ([]node.OrderOption, error)
- func NodePatchRequestTags() []string
- type APIHandler
- func (h *APIHandler) CreateNodeEndpoint() entapi.Endpoint
- func (h *APIHandler) DeleteNodeEndpoint() entapi.Endpoint
- func (h *APIHandler) Endpoints() []entapi.Endpoint
- func (h *APIHandler) GetNodeEndpoint() entapi.Endpoint
- func (h *APIHandler) ListNodesEndpoint() entapi.Endpoint
- func (h *APIHandler) Mount(mux *http.ServeMux)
- func (h *APIHandler) OpenAPIEndpoint() entapi.Endpoint
- func (h *APIHandler) PatchNodeEndpoint() entapi.Endpoint
- func (h *APIHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (h *APIHandler) With(opts ...APIOption) *APIHandler
- type APIOption
- type AggregateFunc
- type Client
- func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error)
- func (c *Client) Close() error
- func (c *Client) Debug() *Client
- func (c *Client) Intercept(interceptors ...Interceptor)
- func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error)
- func (c *Client) Tx(ctx context.Context) (*Tx, error)
- func (c *Client) Use(hooks ...Hook)
- type CommitFunc
- type CommitHook
- type Committer
- type ConstraintError
- type CreateNodeFn
- type DeleteNodeFn
- type GetNodeFn
- type Hook
- type InterceptFunc
- type Interceptor
- type ListNodesFn
- type MutateFunc
- type Mutation
- type Mutator
- type Node
- type NodeClient
- func (c *NodeClient) Create() *NodeCreate
- func (c *NodeClient) CreateBulk(builders ...*NodeCreate) *NodeCreateBulk
- func (c *NodeClient) Delete() *NodeDelete
- func (c *NodeClient) DeleteOne(n *Node) *NodeDeleteOne
- func (c *NodeClient) DeleteOneID(id uuid.UUID) *NodeDeleteOne
- func (c *NodeClient) Get(ctx context.Context, id uuid.UUID) (*Node, error)
- func (c *NodeClient) GetX(ctx context.Context, id uuid.UUID) *Node
- func (c *NodeClient) Hooks() []Hook
- func (c *NodeClient) Intercept(interceptors ...Interceptor)
- func (c *NodeClient) Interceptors() []Interceptor
- func (c *NodeClient) MapCreateBulk(slice any, setFunc func(*NodeCreate, int)) *NodeCreateBulk
- func (c *NodeClient) Query() *NodeQuery
- func (c *NodeClient) QueryChildren(n *Node) *NodeQuery
- func (c *NodeClient) QueryParent(n *Node) *NodeQuery
- func (c *NodeClient) Update() *NodeUpdate
- func (c *NodeClient) UpdateOne(n *Node) *NodeUpdateOne
- func (c *NodeClient) UpdateOneID(id uuid.UUID) *NodeUpdateOne
- func (c *NodeClient) Use(hooks ...Hook)
- type NodeCreate
- func (nc *NodeCreate) AddChildIDs(ids ...uuid.UUID) *NodeCreate
- func (nc *NodeCreate) AddChildren(n ...*Node) *NodeCreate
- func (nc *NodeCreate) Exec(ctx context.Context) error
- func (nc *NodeCreate) ExecX(ctx context.Context)
- func (nc *NodeCreate) Mutation() *NodeMutation
- func (nc *NodeCreate) Save(ctx context.Context) (*Node, error)
- func (nc *NodeCreate) SaveX(ctx context.Context) *Node
- func (nc *NodeCreate) SetID(u uuid.UUID) *NodeCreate
- func (nc *NodeCreate) SetLabel(s string) *NodeCreate
- func (nc *NodeCreate) SetNillableID(u *uuid.UUID) *NodeCreate
- func (nc *NodeCreate) SetNillableParentID(u *uuid.UUID) *NodeCreate
- func (nc *NodeCreate) SetParent(n *Node) *NodeCreate
- func (nc *NodeCreate) SetParentID(u uuid.UUID) *NodeCreate
- type NodeCreateBulk
- type NodeCreateRequest
- type NodeDelete
- type NodeDeleteOne
- type NodeEdges
- type NodeFilter
- type NodeGroupBy
- func (ngb *NodeGroupBy) Aggregate(fns ...AggregateFunc) *NodeGroupBy
- func (s *NodeGroupBy) Bool(ctx context.Context) (_ bool, err error)
- func (s *NodeGroupBy) BoolX(ctx context.Context) bool
- func (s *NodeGroupBy) Bools(ctx context.Context) ([]bool, error)
- func (s *NodeGroupBy) BoolsX(ctx context.Context) []bool
- func (s *NodeGroupBy) Float64(ctx context.Context) (_ float64, err error)
- func (s *NodeGroupBy) Float64X(ctx context.Context) float64
- func (s *NodeGroupBy) Float64s(ctx context.Context) ([]float64, error)
- func (s *NodeGroupBy) Float64sX(ctx context.Context) []float64
- func (s *NodeGroupBy) Int(ctx context.Context) (_ int, err error)
- func (s *NodeGroupBy) IntX(ctx context.Context) int
- func (s *NodeGroupBy) Ints(ctx context.Context) ([]int, error)
- func (s *NodeGroupBy) IntsX(ctx context.Context) []int
- func (ngb *NodeGroupBy) Scan(ctx context.Context, v any) error
- func (s *NodeGroupBy) ScanX(ctx context.Context, v any)
- func (s *NodeGroupBy) String(ctx context.Context) (_ string, err error)
- func (s *NodeGroupBy) StringX(ctx context.Context) string
- func (s *NodeGroupBy) Strings(ctx context.Context) ([]string, error)
- func (s *NodeGroupBy) StringsX(ctx context.Context) []string
- type NodeListResponse
- type NodeMutation
- func (m *NodeMutation) AddChildIDs(ids ...uuid.UUID)
- func (m *NodeMutation) AddField(name string, value ent.Value) error
- func (m *NodeMutation) AddedEdges() []string
- func (m *NodeMutation) AddedField(name string) (ent.Value, bool)
- func (m *NodeMutation) AddedFields() []string
- func (m *NodeMutation) AddedIDs(name string) []ent.Value
- func (m *NodeMutation) ChildrenCleared() bool
- func (m *NodeMutation) ChildrenIDs() (ids []uuid.UUID)
- func (m *NodeMutation) ClearChildren()
- func (m *NodeMutation) ClearEdge(name string) error
- func (m *NodeMutation) ClearField(name string) error
- func (m *NodeMutation) ClearParent()
- func (m *NodeMutation) ClearParentID()
- func (m *NodeMutation) ClearedEdges() []string
- func (m *NodeMutation) ClearedFields() []string
- func (m NodeMutation) Client() *Client
- func (m *NodeMutation) EdgeCleared(name string) bool
- func (m *NodeMutation) Field(name string) (ent.Value, bool)
- func (m *NodeMutation) FieldCleared(name string) bool
- func (m *NodeMutation) Fields() []string
- func (m *NodeMutation) ID() (id uuid.UUID, exists bool)
- func (m *NodeMutation) IDs(ctx context.Context) ([]uuid.UUID, error)
- func (m *NodeMutation) Label() (r string, exists bool)
- func (m *NodeMutation) OldField(ctx context.Context, name string) (ent.Value, error)
- func (m *NodeMutation) OldLabel(ctx context.Context) (v string, err error)
- func (m *NodeMutation) OldParentID(ctx context.Context) (v uuid.UUID, err error)
- func (m *NodeMutation) Op() Op
- func (m *NodeMutation) ParentCleared() bool
- func (m *NodeMutation) ParentID() (r uuid.UUID, exists bool)
- func (m *NodeMutation) ParentIDCleared() bool
- func (m *NodeMutation) ParentIDs() (ids []uuid.UUID)
- func (m *NodeMutation) RemoveChildIDs(ids ...uuid.UUID)
- func (m *NodeMutation) RemovedChildrenIDs() (ids []uuid.UUID)
- func (m *NodeMutation) RemovedEdges() []string
- func (m *NodeMutation) RemovedIDs(name string) []ent.Value
- func (m *NodeMutation) ResetChildren()
- func (m *NodeMutation) ResetEdge(name string) error
- func (m *NodeMutation) ResetField(name string) error
- func (m *NodeMutation) ResetLabel()
- func (m *NodeMutation) ResetParent()
- func (m *NodeMutation) ResetParentID()
- func (m *NodeMutation) SetField(name string, value ent.Value) error
- func (m *NodeMutation) SetID(id uuid.UUID)
- func (m *NodeMutation) SetLabel(s string)
- func (m *NodeMutation) SetOp(op Op)
- func (m *NodeMutation) SetParentID(u uuid.UUID)
- func (m NodeMutation) Tx() (*Tx, error)
- func (m *NodeMutation) Type() string
- func (m *NodeMutation) Where(ps ...predicate.Node)
- func (m *NodeMutation) WhereP(ps ...func(*sql.Selector))
- type NodePatchRequest
- type NodeQuery
- func (nq *NodeQuery) Aggregate(fns ...AggregateFunc) *NodeSelect
- func (nq *NodeQuery) All(ctx context.Context) ([]*Node, error)
- func (nq *NodeQuery) AllX(ctx context.Context) []*Node
- func (nq *NodeQuery) Clone() *NodeQuery
- func (nq *NodeQuery) Count(ctx context.Context) (int, error)
- func (nq *NodeQuery) CountX(ctx context.Context) int
- func (nq *NodeQuery) Exist(ctx context.Context) (bool, error)
- func (nq *NodeQuery) ExistX(ctx context.Context) bool
- func (nq *NodeQuery) First(ctx context.Context) (*Node, error)
- func (nq *NodeQuery) FirstID(ctx context.Context) (id uuid.UUID, err error)
- func (nq *NodeQuery) FirstIDX(ctx context.Context) uuid.UUID
- func (nq *NodeQuery) FirstX(ctx context.Context) *Node
- func (nq *NodeQuery) GroupBy(field string, fields ...string) *NodeGroupBy
- func (nq *NodeQuery) IDs(ctx context.Context) (ids []uuid.UUID, err error)
- func (nq *NodeQuery) IDsX(ctx context.Context) []uuid.UUID
- func (nq *NodeQuery) Limit(limit int) *NodeQuery
- func (nq *NodeQuery) Offset(offset int) *NodeQuery
- func (nq *NodeQuery) Only(ctx context.Context) (*Node, error)
- func (nq *NodeQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error)
- func (nq *NodeQuery) OnlyIDX(ctx context.Context) uuid.UUID
- func (nq *NodeQuery) OnlyX(ctx context.Context) *Node
- func (nq *NodeQuery) Order(o ...node.OrderOption) *NodeQuery
- func (nq *NodeQuery) QueryChildren() *NodeQuery
- func (nq *NodeQuery) QueryParent() *NodeQuery
- func (nq *NodeQuery) Select(fields ...string) *NodeSelect
- func (nq *NodeQuery) Unique(unique bool) *NodeQuery
- func (nq *NodeQuery) Where(ps ...predicate.Node) *NodeQuery
- func (nq *NodeQuery) WithChildren(opts ...func(*NodeQuery)) *NodeQuery
- func (nq *NodeQuery) WithParent(opts ...func(*NodeQuery)) *NodeQuery
- type NodeResponse
- func CreateNode(ctx context.Context, db *Client, v *ValidNodeCreateRequest) (*NodeResponse, error)
- func GetNode(ctx context.Context, db *Client, id uuid.UUID) (*NodeResponse, error)
- func NewNodeResponse(e *Node) (*NodeResponse, error)
- func PatchNode(ctx context.Context, db *Client, id uuid.UUID, v *ValidNodePatchRequest) (*NodeResponse, error)
- type NodeSelect
- func (ns *NodeSelect) Aggregate(fns ...AggregateFunc) *NodeSelect
- func (s *NodeSelect) Bool(ctx context.Context) (_ bool, err error)
- func (s *NodeSelect) BoolX(ctx context.Context) bool
- func (s *NodeSelect) Bools(ctx context.Context) ([]bool, error)
- func (s *NodeSelect) BoolsX(ctx context.Context) []bool
- func (s *NodeSelect) Float64(ctx context.Context) (_ float64, err error)
- func (s *NodeSelect) Float64X(ctx context.Context) float64
- func (s *NodeSelect) Float64s(ctx context.Context) ([]float64, error)
- func (s *NodeSelect) Float64sX(ctx context.Context) []float64
- func (s *NodeSelect) Int(ctx context.Context) (_ int, err error)
- func (s *NodeSelect) IntX(ctx context.Context) int
- func (s *NodeSelect) Ints(ctx context.Context) ([]int, error)
- func (s *NodeSelect) IntsX(ctx context.Context) []int
- func (ns *NodeSelect) Scan(ctx context.Context, v any) error
- func (s *NodeSelect) ScanX(ctx context.Context, v any)
- func (s *NodeSelect) String(ctx context.Context) (_ string, err error)
- func (s *NodeSelect) StringX(ctx context.Context) string
- func (s *NodeSelect) Strings(ctx context.Context) ([]string, error)
- func (s *NodeSelect) StringsX(ctx context.Context) []string
- type NodeSummary
- type NodeUpdate
- func (nu *NodeUpdate) AddChildIDs(ids ...uuid.UUID) *NodeUpdate
- func (nu *NodeUpdate) AddChildren(n ...*Node) *NodeUpdate
- func (nu *NodeUpdate) ClearChildren() *NodeUpdate
- func (nu *NodeUpdate) ClearParent() *NodeUpdate
- func (nu *NodeUpdate) ClearParentID() *NodeUpdate
- func (nu *NodeUpdate) Exec(ctx context.Context) error
- func (nu *NodeUpdate) ExecX(ctx context.Context)
- func (nu *NodeUpdate) Mutation() *NodeMutation
- func (nu *NodeUpdate) RemoveChildIDs(ids ...uuid.UUID) *NodeUpdate
- func (nu *NodeUpdate) RemoveChildren(n ...*Node) *NodeUpdate
- func (nu *NodeUpdate) Save(ctx context.Context) (int, error)
- func (nu *NodeUpdate) SaveX(ctx context.Context) int
- func (nu *NodeUpdate) SetLabel(s string) *NodeUpdate
- func (nu *NodeUpdate) SetNillableLabel(s *string) *NodeUpdate
- func (nu *NodeUpdate) SetNillableParentID(u *uuid.UUID) *NodeUpdate
- func (nu *NodeUpdate) SetParent(n *Node) *NodeUpdate
- func (nu *NodeUpdate) SetParentID(u uuid.UUID) *NodeUpdate
- func (nu *NodeUpdate) Where(ps ...predicate.Node) *NodeUpdate
- type NodeUpdateOne
- func (nuo *NodeUpdateOne) AddChildIDs(ids ...uuid.UUID) *NodeUpdateOne
- func (nuo *NodeUpdateOne) AddChildren(n ...*Node) *NodeUpdateOne
- func (nuo *NodeUpdateOne) ClearChildren() *NodeUpdateOne
- func (nuo *NodeUpdateOne) ClearParent() *NodeUpdateOne
- func (nuo *NodeUpdateOne) ClearParentID() *NodeUpdateOne
- func (nuo *NodeUpdateOne) Exec(ctx context.Context) error
- func (nuo *NodeUpdateOne) ExecX(ctx context.Context)
- func (nuo *NodeUpdateOne) Mutation() *NodeMutation
- func (nuo *NodeUpdateOne) RemoveChildIDs(ids ...uuid.UUID) *NodeUpdateOne
- func (nuo *NodeUpdateOne) RemoveChildren(n ...*Node) *NodeUpdateOne
- func (nuo *NodeUpdateOne) Save(ctx context.Context) (*Node, error)
- func (nuo *NodeUpdateOne) SaveX(ctx context.Context) *Node
- func (nuo *NodeUpdateOne) Select(field string, fields ...string) *NodeUpdateOne
- func (nuo *NodeUpdateOne) SetLabel(s string) *NodeUpdateOne
- func (nuo *NodeUpdateOne) SetNillableLabel(s *string) *NodeUpdateOne
- func (nuo *NodeUpdateOne) SetNillableParentID(u *uuid.UUID) *NodeUpdateOne
- func (nuo *NodeUpdateOne) SetParent(n *Node) *NodeUpdateOne
- func (nuo *NodeUpdateOne) SetParentID(u uuid.UUID) *NodeUpdateOne
- func (nuo *NodeUpdateOne) Where(ps ...predicate.Node) *NodeUpdateOne
- type Nodes
- type NotFoundError
- type NotLoadedError
- type NotSingularError
- type Op
- type Option
- type OrderFunc
- type PatchNodeFn
- type Policy
- type Querier
- type QuerierFunc
- type Query
- type QueryContext
- type RollbackFunc
- type RollbackHook
- type Rollbacker
- type TraverseFunc
- type Traverser
- type Tx
- type ValidNodeCreateRequest
- type ValidNodePatchRequest
- type ValidationError
- type Value
Constants ¶
const ( // Operation types. OpCreate = ent.OpCreate OpDelete = ent.OpDelete OpDeleteOne = ent.OpDeleteOne OpUpdate = ent.OpUpdate OpUpdateOne = ent.OpUpdateOne // Node types. TypeNode = "Node" )
Variables ¶
var ErrTxStarted = errors.New("selfrefpartialent: cannot start a transaction within a transaction")
ErrTxStarted is returned when trying to start a new transaction from a transactional client.
var ErrorMap = entapi.NewErrorMapper(IsNotFound, IsConstraintError). WithValidation(IsValidationError, func(err error) (string, bool) { var ve *ValidationError if errors.As(err, &ve) { return ve.Name, true } return "", false })
ErrorMap is the classifier every generated wiring function passes its error through before returning it.
One variable for the whole package, rather than a parameter on each operation. That is what makes entapi.IsNotFound answer the same way whichever function produced the error: a mapper threaded through as an argument would hold that property only for as long as every call site kept passing the same one, and there is no way to check that from here.
IsNotFound, IsConstraintError and IsValidationError are ent's own, generated into THIS package. The framework does not export them and cannot: ent generates NotFoundError and ConstraintError per project. That is why the runtime takes its classification as function values and never names an ent type — see entapi.ErrorMapper.
ValidationError is generated in this package too. The extractor keeps that type out of the stdlib-only runtime while preserving its field name for an RFC 9457 response.
API installs the runtime determination for the client's dialect unless the consumer already supplied one. ErrorMap is an ordinary package-level variable and carries no synchronisation of its own; configure overrides while building the client, before serving requests.
var NodeSortKeys = []string{
"id",
}
NodeSortKeys is the complete sort allow-list. The primary key is naturally Sortable; every other key requires api.Sortable().
Functions ¶
func DeleteBatchNodes ¶
DeleteBatchNodes removes several Nodes in one statement and returns how many rows it deleted.
The count is returned rather than discarded because ent computes it and the caller cannot recover it afterwards: a batch delete reports no error for an id that matched nothing, so "how many of the ids existed" is answerable here and nowhere else.
An empty list deletes nothing. That is ent's own reading of IDIn with no arguments, not a guard written here — a guard would be a second place for the rule to live, and the failure it protects against is unrecoverable.
An id that matched nothing is not an error here, so this operation never produces a not-found — but it can still fail a foreign-key check, which is exactly the case the mapping must NOT report as already-exists.
func DeleteNode ¶
DeleteNode removes one Node.
No runtime routine is involved: ent's own builder is already the single line, and there is nothing to convert. What "delete" means for an entity with a soft-delete column is decided by an ent interceptor or mixin, not by a filename convention read out of the schema.
func IsConstraintError ¶
IsConstraintError returns a boolean indicating whether the error is a constraint failure.
func IsNotFound ¶
IsNotFound returns a boolean indicating whether the error is a not found error.
func IsNotLoaded ¶
IsNotLoaded returns a boolean indicating whether the error is a not loaded error.
func IsNotSingular ¶
IsNotSingular returns a boolean indicating whether the error is a not singular error.
func IsValidationError ¶
IsValidationError returns a boolean indicating whether the error is a validation error.
func ListNodes ¶
func ListNodes(ctx context.Context, db *Client, f *NodeFilter, r entapi.ListRequest) (*entapi.Page[NodeResponse], error)
ListNodes runs a filtered, ordered, paginated query.
This is the one operation whose body is not a single call, and the reason is worth stating rather than hiding: NodeOrder can fail, because a sort key outside NodeSortKeys has no correct answer and serving a differently-ordered page instead is worse than refusing. entapi.ListPage takes resolved order options, not a fallible producer of them, so the check happens here.
A nil filter contributes no predicates, so a caller with nothing to filter by does not need a branch of its own.
The sort-key failure returns before the mapping. It is already an entapi.ErrValidation and never reached the database, so there is nothing for a persistence-layer classifier to say about it.
func NewContext ¶
NewContext returns a new context with the given Client attached.
func NewTxContext ¶
NewTxContext returns a new context with the given Tx attached.
func NodeCreateRequestTags ¶
func NodeCreateRequestTags() []string
NodeCreateRequestTags returns the canonical JSON key of every field on NodeCreateRequest, in declaration order. Generated handlers compare raw request keys against this data to reject unknown keys.
Like Endpoints(), it returns a fresh copy on every call: slices are mutable, so exporting the variable would let any consumer mutate validation data that every generated handler in the process reads. The unexported variable remains the source of truth; this accessor is for consumers that decline the generated handler and write their own bind step.
func NodeOrder ¶
func NodeOrder(r entapi.ListRequest) ([]node.OrderOption, error)
NodeOrder is the single sort allow-list seam.
func NodePatchRequestTags ¶
func NodePatchRequestTags() []string
NodePatchRequestTags returns the canonical JSON key of every field on NodePatchRequest, in declaration order. Generated handlers compare raw request keys against this data to reject unknown keys.
Like Endpoints(), it returns a fresh copy on every call: slices are mutable, so exporting the variable would let any consumer mutate validation data that every generated handler in the process reads. The unexported variable remains the source of truth; this accessor is for consumers that decline the generated handler and write their own bind step.
Types ¶
type APIHandler ¶
type APIHandler struct {
// contains filtered or unexported fields
}
APIHandler is the generated CRUD HTTP surface.
func API ¶
func API(client *Client) *APIHandler
API builds the generated CRUD HTTP surface for client.
func (*APIHandler) CreateNodeEndpoint ¶
func (h *APIHandler) CreateNodeEndpoint() entapi.Endpoint
CreateNodeEndpoint returns the generated POST /nodes endpoint.
func (*APIHandler) DeleteNodeEndpoint ¶
func (h *APIHandler) DeleteNodeEndpoint() entapi.Endpoint
DeleteNodeEndpoint returns the generated DELETE /nodes/{id} endpoint.
func (*APIHandler) Endpoints ¶
func (h *APIHandler) Endpoints() []entapi.Endpoint
Endpoints returns the generated endpoint manifest in deterministic registration order. It is data to compose into a router of your choosing; ServeHTTP and Mount are the convenience built from the same manifest.
It is the batch half of the composition surface. The per-operation accessors below are the take-one-by-name half: this slice is built by calling them, so the two cannot describe different endpoints, and every handler reads the current implementation through h, so a With after the call still takes effect. Endpoint values are not comparable; to skip or deduplicate rows, key on Method plus Path, or on Op. Except removes the method along with the endpoint, so naming an operation that is not exposed is a compile error.
func (*APIHandler) GetNodeEndpoint ¶
func (h *APIHandler) GetNodeEndpoint() entapi.Endpoint
GetNodeEndpoint returns the generated GET /nodes/{id} endpoint.
func (*APIHandler) ListNodesEndpoint ¶
func (h *APIHandler) ListNodesEndpoint() entapi.Endpoint
ListNodesEndpoint returns the generated GET /nodes endpoint.
func (*APIHandler) Mount ¶
func (h *APIHandler) Mount(mux *http.ServeMux)
Mount registers every generated endpoint on mux.
func (*APIHandler) OpenAPIEndpoint ¶
func (h *APIHandler) OpenAPIEndpoint() entapi.Endpoint
OpenAPIEndpoint returns the generated GET /openapi.yaml endpoint serving the generated document. It is the manifest's one entry with no Entity and no Op: it describes the resource surface rather than belonging to it.
func (*APIHandler) PatchNodeEndpoint ¶
func (h *APIHandler) PatchNodeEndpoint() entapi.Endpoint
PatchNodeEndpoint returns the generated PATCH /nodes/{id} endpoint.
func (*APIHandler) ServeHTTP ¶
func (h *APIHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP serves every generated endpoint through the internal mux.
func (*APIHandler) With ¶
func (h *APIHandler) With(opts ...APIOption) *APIHandler
With replaces generated operation implementations before serving begins.
type APIOption ¶
type APIOption interface {
// contains filtered or unexported methods
}
APIOption replaces one generated operation implementation.
type AggregateFunc ¶
AggregateFunc applies an aggregation step on the group-by traversal/selector.
func As ¶
func As(fn AggregateFunc, end string) AggregateFunc
As is a pseudo aggregation function for renaming another other functions with custom names. For example:
GroupBy(field1, field2). Aggregate(selfrefpartialent.As(selfrefpartialent.Sum(field1), "sum_field1"), (selfrefpartialent.As(selfrefpartialent.Sum(field2), "sum_field2")). Scan(ctx, &v)
func Count ¶
func Count() AggregateFunc
Count applies the "count" aggregation function on each group.
func Max ¶
func Max(field string) AggregateFunc
Max applies the "max" aggregation function on the given field of each group.
func Mean ¶
func Mean(field string) AggregateFunc
Mean applies the "mean" aggregation function on the given field of each group.
func Min ¶
func Min(field string) AggregateFunc
Min applies the "min" aggregation function on the given field of each group.
func Sum ¶
func Sum(field string) AggregateFunc
Sum applies the "sum" aggregation function on the given field of each group.
type Client ¶
type Client struct {
// Schema is the client for creating, migrating and dropping schema.
Schema *migrate.Schema
// Node is the client for interacting with the Node builders.
Node *NodeClient
// contains filtered or unexported fields
}
Client is the client that holds all ent builders.
func FromContext ¶
FromContext returns a Client stored inside a context, or nil if there isn't one.
func Open ¶
Open opens a database/sql.DB specified by the driver name and the data source name, and returns a new client attached to it. Optional parameters can be added for configuring the client.
func (*Client) Debug ¶
Debug returns a new debug-client. It's used to get verbose logging on specific operations.
client.Debug(). Node. Query(). Count(ctx)
func (*Client) Intercept ¶
func (c *Client) Intercept(interceptors ...Interceptor)
Intercept adds the query interceptors to all the entity clients. In order to add interceptors to a specific client, call: `client.Node.Intercept(...)`.
type CommitFunc ¶
The CommitFunc type is an adapter to allow the use of ordinary function as a Committer. If f is a function with the appropriate signature, CommitFunc(f) is a Committer that calls f.
type CommitHook ¶
CommitHook defines the "commit middleware". A function that gets a Committer and returns a Committer. For example:
hook := func(next ent.Committer) ent.Committer {
return ent.CommitFunc(func(ctx context.Context, tx *ent.Tx) error {
// Do some stuff before.
if err := next.Commit(ctx, tx); err != nil {
return err
}
// Do some stuff after.
return nil
})
}
type ConstraintError ¶
type ConstraintError struct {
// contains filtered or unexported fields
}
ConstraintError returns when trying to create/update one or more entities and one or more of their constraints failed. For example, violation of edge or field uniqueness.
func (ConstraintError) Error ¶
func (e ConstraintError) Error() string
Error implements the error interface.
func (*ConstraintError) Unwrap ¶
func (e *ConstraintError) Unwrap() error
Unwrap implements the errors.Wrapper interface.
type CreateNodeFn ¶
type CreateNodeFn func(context.Context, *Client, *ValidNodeCreateRequest) (*NodeResponse, error)
CreateNodeFn is byte-identical to CreateNode.
type DeleteNodeFn ¶
DeleteNodeFn is byte-identical to DeleteNode.
type InterceptFunc ¶
type InterceptFunc = ent.InterceptFunc
ent aliases to avoid import conflicts in user's code.
type Interceptor ¶
type Interceptor = ent.Interceptor
ent aliases to avoid import conflicts in user's code.
type ListNodesFn ¶
type ListNodesFn func(context.Context, *Client, *NodeFilter, entapi.ListRequest) (*entapi.Page[NodeResponse], error)
ListNodesFn is byte-identical to ListNodes.
type MutateFunc ¶
type MutateFunc = ent.MutateFunc
ent aliases to avoid import conflicts in user's code.
type Node ¶
type Node struct {
// ID of the ent.
ID uuid.UUID `json:"id,omitempty"`
// Label holds the value of the "label" field.
Label string `json:"label,omitempty"`
// ParentID holds the value of the "parent_id" field.
ParentID uuid.UUID `json:"parent_id,omitempty"`
// Edges holds the relations/edges for other nodes in the graph.
// The values are being populated by the NodeQuery when eager-loading is set.
Edges NodeEdges `json:"edges"`
// contains filtered or unexported fields
}
Node is the model entity for the Node schema.
func (*Node) QueryChildren ¶
QueryChildren queries the "children" edge of the Node entity.
func (*Node) QueryParent ¶
QueryParent queries the "parent" edge of the Node entity.
func (*Node) Unwrap ¶
Unwrap unwraps the Node entity that was returned from a transaction after it was closed, so that all future queries will be executed through the driver which created the transaction.
func (*Node) Update ¶
func (n *Node) Update() *NodeUpdateOne
Update returns a builder for updating this Node. Note that you need to call Node.Unwrap() before calling this method if this Node was returned from a transaction, and the transaction was committed or rolled back.
type NodeClient ¶
type NodeClient struct {
// contains filtered or unexported fields
}
NodeClient is a client for the Node schema.
func NewNodeClient ¶
func NewNodeClient(c config) *NodeClient
NewNodeClient returns a client for the Node from the given config.
func (*NodeClient) Create ¶
func (c *NodeClient) Create() *NodeCreate
Create returns a builder for creating a Node entity.
func (*NodeClient) CreateBulk ¶
func (c *NodeClient) CreateBulk(builders ...*NodeCreate) *NodeCreateBulk
CreateBulk returns a builder for creating a bulk of Node entities.
func (*NodeClient) Delete ¶
func (c *NodeClient) Delete() *NodeDelete
Delete returns a delete builder for Node.
func (*NodeClient) DeleteOne ¶
func (c *NodeClient) DeleteOne(n *Node) *NodeDeleteOne
DeleteOne returns a builder for deleting the given entity.
func (*NodeClient) DeleteOneID ¶
func (c *NodeClient) DeleteOneID(id uuid.UUID) *NodeDeleteOne
DeleteOneID returns a builder for deleting the given entity by its id.
func (*NodeClient) Intercept ¶
func (c *NodeClient) Intercept(interceptors ...Interceptor)
Intercept adds a list of query interceptors to the interceptors stack. A call to `Intercept(f, g, h)` equals to `node.Intercept(f(g(h())))`.
func (*NodeClient) Interceptors ¶
func (c *NodeClient) Interceptors() []Interceptor
Interceptors returns the client interceptors.
func (*NodeClient) MapCreateBulk ¶
func (c *NodeClient) MapCreateBulk(slice any, setFunc func(*NodeCreate, int)) *NodeCreateBulk
MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates a builder and applies setFunc on it.
func (*NodeClient) Query ¶
func (c *NodeClient) Query() *NodeQuery
Query returns a query builder for Node.
func (*NodeClient) QueryChildren ¶
func (c *NodeClient) QueryChildren(n *Node) *NodeQuery
QueryChildren queries the children edge of a Node.
func (*NodeClient) QueryParent ¶
func (c *NodeClient) QueryParent(n *Node) *NodeQuery
QueryParent queries the parent edge of a Node.
func (*NodeClient) Update ¶
func (c *NodeClient) Update() *NodeUpdate
Update returns an update builder for Node.
func (*NodeClient) UpdateOne ¶
func (c *NodeClient) UpdateOne(n *Node) *NodeUpdateOne
UpdateOne returns an update builder for the given entity.
func (*NodeClient) UpdateOneID ¶
func (c *NodeClient) UpdateOneID(id uuid.UUID) *NodeUpdateOne
UpdateOneID returns an update builder for the given id.
func (*NodeClient) Use ¶
func (c *NodeClient) Use(hooks ...Hook)
Use adds a list of mutation hooks to the hooks stack. A call to `Use(f, g, h)` equals to `node.Hooks(f(g(h())))`.
type NodeCreate ¶
type NodeCreate struct {
// contains filtered or unexported fields
}
NodeCreate is the builder for creating a Node entity.
func (*NodeCreate) AddChildIDs ¶
func (nc *NodeCreate) AddChildIDs(ids ...uuid.UUID) *NodeCreate
AddChildIDs adds the "children" edge to the Node entity by IDs.
func (*NodeCreate) AddChildren ¶
func (nc *NodeCreate) AddChildren(n ...*Node) *NodeCreate
AddChildren adds the "children" edges to the Node entity.
func (*NodeCreate) Exec ¶
func (nc *NodeCreate) Exec(ctx context.Context) error
Exec executes the query.
func (*NodeCreate) ExecX ¶
func (nc *NodeCreate) ExecX(ctx context.Context)
ExecX is like Exec, but panics if an error occurs.
func (*NodeCreate) Mutation ¶
func (nc *NodeCreate) Mutation() *NodeMutation
Mutation returns the NodeMutation object of the builder.
func (*NodeCreate) Save ¶
func (nc *NodeCreate) Save(ctx context.Context) (*Node, error)
Save creates the Node in the database.
func (*NodeCreate) SaveX ¶
func (nc *NodeCreate) SaveX(ctx context.Context) *Node
SaveX calls Save and panics if Save returns an error.
func (*NodeCreate) SetID ¶
func (nc *NodeCreate) SetID(u uuid.UUID) *NodeCreate
SetID sets the "id" field.
func (*NodeCreate) SetLabel ¶
func (nc *NodeCreate) SetLabel(s string) *NodeCreate
SetLabel sets the "label" field.
func (*NodeCreate) SetNillableID ¶
func (nc *NodeCreate) SetNillableID(u *uuid.UUID) *NodeCreate
SetNillableID sets the "id" field if the given value is not nil.
func (*NodeCreate) SetNillableParentID ¶
func (nc *NodeCreate) SetNillableParentID(u *uuid.UUID) *NodeCreate
SetNillableParentID sets the "parent_id" field if the given value is not nil.
func (*NodeCreate) SetParent ¶
func (nc *NodeCreate) SetParent(n *Node) *NodeCreate
SetParent sets the "parent" edge to the Node entity.
func (*NodeCreate) SetParentID ¶
func (nc *NodeCreate) SetParentID(u uuid.UUID) *NodeCreate
SetParentID sets the "parent_id" field.
type NodeCreateBulk ¶
type NodeCreateBulk struct {
// contains filtered or unexported fields
}
NodeCreateBulk is the builder for creating many Node entities in bulk.
func (*NodeCreateBulk) Exec ¶
func (ncb *NodeCreateBulk) Exec(ctx context.Context) error
Exec executes the query.
func (*NodeCreateBulk) ExecX ¶
func (ncb *NodeCreateBulk) ExecX(ctx context.Context)
ExecX is like Exec, but panics if an error occurs.
type NodeCreateRequest ¶
type NodeCreateRequest struct {
Label string `json:"label"`
ParentID *uuid.UUID `json:"parent_id,omitempty"`
// contains filtered or unexported fields
}
NodeCreateRequest is the create request for Node.
Field shape follows ent's schema rather than a parallel set of booleans. A field ent can fill by itself — Optional, or carrying a Default() — is a pointer here and is written to the builder only when the caller supplied a value, so an omitted key leaves the schema's default in effect. A field ent requires and cannot default is a value type and is always written.
func (*NodeCreateRequest) HasLabel ¶
func (r *NodeCreateRequest) HasLabel() bool
HasLabel reports whether the payload carried "label".
func (*NodeCreateRequest) HasParentID ¶
func (r *NodeCreateRequest) HasParentID() bool
HasParentID reports whether the payload carried "parent_id".
func (*NodeCreateRequest) UnmarshalJSON ¶
func (r *NodeCreateRequest) UnmarshalJSON(b []byte) error
UnmarshalJSON records presence, then decodes normally.
The wire format is unchanged: every exported field keeps its ordinary type and tag, so marshalling, form binders, validators and spec generators all see the struct they saw before. That is the property a generic Optional[T] wrapper could not keep.
A key that case-folds to a canonical tag without matching it exactly is rejected (#58, ADR-0001): encoding/json would fill the field from it while presence — recorded by raw key — would not, so the value decoded and then went unwritten. The check runs after raw decodes and BEFORE the alias decode, so a rejected request leaves the receiver untouched. A key that folds to no tag keeps its old behaviour and is ignored; refusing those is DisallowUnknownFields, which stays the consumer handler's decision.
func (*NodeCreateRequest) Validate ¶
func (r *NodeCreateRequest) Validate() (*ValidNodeCreateRequest, error)
Validate checks the request and returns the only type Apply accepts.
type NodeDelete ¶
type NodeDelete struct {
// contains filtered or unexported fields
}
NodeDelete is the builder for deleting a Node entity.
func (*NodeDelete) Exec ¶
func (nd *NodeDelete) Exec(ctx context.Context) (int, error)
Exec executes the deletion query and returns how many vertices were deleted.
func (*NodeDelete) ExecX ¶
func (nd *NodeDelete) ExecX(ctx context.Context) int
ExecX is like Exec, but panics if an error occurs.
func (*NodeDelete) Where ¶
func (nd *NodeDelete) Where(ps ...predicate.Node) *NodeDelete
Where appends a list predicates to the NodeDelete builder.
type NodeDeleteOne ¶
type NodeDeleteOne struct {
// contains filtered or unexported fields
}
NodeDeleteOne is the builder for deleting a single Node entity.
func (*NodeDeleteOne) Exec ¶
func (ndo *NodeDeleteOne) Exec(ctx context.Context) error
Exec executes the deletion query.
func (*NodeDeleteOne) ExecX ¶
func (ndo *NodeDeleteOne) ExecX(ctx context.Context)
ExecX is like Exec, but panics if an error occurs.
func (*NodeDeleteOne) Where ¶
func (ndo *NodeDeleteOne) Where(ps ...predicate.Node) *NodeDeleteOne
Where appends a list predicates to the NodeDelete builder.
type NodeEdges ¶
type NodeEdges struct {
// Children holds the value of the children edge.
Children []*Node `json:"children,omitempty"`
// Parent holds the value of the parent edge.
Parent *Node `json:"parent,omitempty"`
// contains filtered or unexported fields
}
NodeEdges holds the relations/edges for other nodes in the graph.
func (NodeEdges) ChildrenOrErr ¶
ChildrenOrErr returns the Children value or an error if the edge was not loaded in eager-loading.
func (NodeEdges) ParentOrErr ¶
ParentOrErr returns the Parent value or an error if the edge was not loaded in eager-loading, or loaded but was not found.
type NodeFilter ¶
type NodeFilter struct {
// id: uuid.UUID
ID []uuid.UUID `json:"id,omitempty"`
IDNEQ []uuid.UUID `json:"id_neq,omitempty"`
IDIn [][]uuid.UUID `json:"id_in,omitempty"`
IDNotIn [][]uuid.UUID `json:"id_not_in,omitempty"`
IDGT []uuid.UUID `json:"id_gt,omitempty"`
IDGTE []uuid.UUID `json:"id_gte,omitempty"`
IDLT []uuid.UUID `json:"id_lt,omitempty"`
IDLTE []uuid.UUID `json:"id_lte,omitempty"`
}
NodeFilter is the typed query representation for Node. Repeated URL parameters occupy repeated slots and Predicates ANDs them.
func ParseNodeQuery ¶
func ParseNodeQuery(q url.Values) (*NodeFilter, entapi.ListRequest, error)
ParseNodeQuery parses the complete URL query contract in sorted-key order. Runtime code owns lexical grammar; the generated operator tables own the field-local operator set, conversion and predicate slots.
func (*NodeFilter) Predicates ¶
func (f *NodeFilter) Predicates() []predicate.Node
Predicates converts the typed filter into conjunctive ent predicates.
type NodeGroupBy ¶
type NodeGroupBy struct {
// contains filtered or unexported fields
}
NodeGroupBy is the group-by builder for Node entities.
func (*NodeGroupBy) Aggregate ¶
func (ngb *NodeGroupBy) Aggregate(fns ...AggregateFunc) *NodeGroupBy
Aggregate adds the given aggregation functions to the group-by query.
func (*NodeGroupBy) Bool ¶
Bool returns a single bool from a selector. It is only allowed when selecting one field.
func (*NodeGroupBy) Bools ¶
Bools returns list of bools from a selector. It is only allowed when selecting one field.
func (*NodeGroupBy) Float64 ¶
Float64 returns a single float64 from a selector. It is only allowed when selecting one field.
func (*NodeGroupBy) Float64s ¶
Float64s returns list of float64s from a selector. It is only allowed when selecting one field.
func (*NodeGroupBy) Int ¶
Int returns a single int from a selector. It is only allowed when selecting one field.
func (*NodeGroupBy) Ints ¶
Ints returns list of ints from a selector. It is only allowed when selecting one field.
func (*NodeGroupBy) Scan ¶
func (ngb *NodeGroupBy) Scan(ctx context.Context, v any) error
Scan applies the selector query and scans the result into the given value.
func (*NodeGroupBy) String ¶
String returns a single string from a selector. It is only allowed when selecting one field.
type NodeListResponse ¶
type NodeListResponse struct {
Data []*NodeResponse `json:"data"`
Total int `json:"total"`
Page int `json:"page"`
Size int `json:"size"`
}
NodeListResponse is the NAMED, non-generic shape of one list page — for OpenAPI/swaggo-class annotation tooling, which cannot express the generic entapi.Page[NodeResponse] that ListNodes returns. Convert at the handler boundary with NewNodeListResponse. (A fifth field, PageInfo, carried cursor metadata until #6 removed it.)
func NewNodeListResponse ¶
func NewNodeListResponse(p *entapi.Page[NodeResponse]) *NodeListResponse
NewNodeListResponse converts the page ListNodes returns into the named list shape. The conversion expression is the shape contract: if NodeListResponse and entapi.Page ever diverge in field set, type or order, this line stops compiling in every generated package. JSON tags are outside what a conversion checks; the wire-format golden test in the basic fixture guards those.
type NodeMutation ¶
type NodeMutation struct {
// contains filtered or unexported fields
}
NodeMutation represents an operation that mutates the Node nodes in the graph.
func (*NodeMutation) AddChildIDs ¶
func (m *NodeMutation) AddChildIDs(ids ...uuid.UUID)
AddChildIDs adds the "children" edge to the Node entity by ids.
func (*NodeMutation) AddField ¶
func (m *NodeMutation) AddField(name string, value ent.Value) error
AddField adds the value to the field with the given name. It returns an error if the field is not defined in the schema, or if the type mismatched the field type.
func (*NodeMutation) AddedEdges ¶
func (m *NodeMutation) AddedEdges() []string
AddedEdges returns all edge names that were set/added in this mutation.
func (*NodeMutation) AddedField ¶
func (m *NodeMutation) AddedField(name string) (ent.Value, bool)
AddedField returns the numeric value that was incremented/decremented on a field with the given name. The second boolean return value indicates that this field was not set, or was not defined in the schema.
func (*NodeMutation) AddedFields ¶
func (m *NodeMutation) AddedFields() []string
AddedFields returns all numeric fields that were incremented/decremented during this mutation.
func (*NodeMutation) AddedIDs ¶
func (m *NodeMutation) AddedIDs(name string) []ent.Value
AddedIDs returns all IDs (to other nodes) that were added for the given edge name in this mutation.
func (*NodeMutation) ChildrenCleared ¶
func (m *NodeMutation) ChildrenCleared() bool
ChildrenCleared reports if the "children" edge to the Node entity was cleared.
func (*NodeMutation) ChildrenIDs ¶
func (m *NodeMutation) ChildrenIDs() (ids []uuid.UUID)
ChildrenIDs returns the "children" edge IDs in the mutation.
func (*NodeMutation) ClearChildren ¶
func (m *NodeMutation) ClearChildren()
ClearChildren clears the "children" edge to the Node entity.
func (*NodeMutation) ClearEdge ¶
func (m *NodeMutation) ClearEdge(name string) error
ClearEdge clears the value of the edge with the given name. It returns an error if that edge is not defined in the schema.
func (*NodeMutation) ClearField ¶
func (m *NodeMutation) ClearField(name string) error
ClearField clears the value of the field with the given name. It returns an error if the field is not defined in the schema.
func (*NodeMutation) ClearParent ¶
func (m *NodeMutation) ClearParent()
ClearParent clears the "parent" edge to the Node entity.
func (*NodeMutation) ClearParentID ¶
func (m *NodeMutation) ClearParentID()
ClearParentID clears the value of the "parent_id" field.
func (*NodeMutation) ClearedEdges ¶
func (m *NodeMutation) ClearedEdges() []string
ClearedEdges returns all edge names that were cleared in this mutation.
func (*NodeMutation) ClearedFields ¶
func (m *NodeMutation) ClearedFields() []string
ClearedFields returns all nullable fields that were cleared during this mutation.
func (NodeMutation) Client ¶
func (m NodeMutation) Client() *Client
Client returns a new `ent.Client` from the mutation. If the mutation was executed in a transaction (ent.Tx), a transactional client is returned.
func (*NodeMutation) EdgeCleared ¶
func (m *NodeMutation) EdgeCleared(name string) bool
EdgeCleared returns a boolean which indicates if the edge with the given name was cleared in this mutation.
func (*NodeMutation) Field ¶
func (m *NodeMutation) Field(name string) (ent.Value, bool)
Field returns the value of a field with the given name. The second boolean return value indicates that this field was not set, or was not defined in the schema.
func (*NodeMutation) FieldCleared ¶
func (m *NodeMutation) FieldCleared(name string) bool
FieldCleared returns a boolean indicating if a field with the given name was cleared in this mutation.
func (*NodeMutation) Fields ¶
func (m *NodeMutation) Fields() []string
Fields returns all fields that were changed during this mutation. Note that in order to get all numeric fields that were incremented/decremented, call AddedFields().
func (*NodeMutation) ID ¶
func (m *NodeMutation) ID() (id uuid.UUID, exists bool)
ID returns the ID value in the mutation. Note that the ID is only available if it was provided to the builder or after it was returned from the database.
func (*NodeMutation) IDs ¶
IDs queries the database and returns the entity ids that match the mutation's predicate. That means, if the mutation is applied within a transaction with an isolation level such as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated or updated by the mutation.
func (*NodeMutation) Label ¶
func (m *NodeMutation) Label() (r string, exists bool)
Label returns the value of the "label" field in the mutation.
func (*NodeMutation) OldField ¶
OldField returns the old value of the field from the database. An error is returned if the mutation operation is not UpdateOne, or the query to the database failed.
func (*NodeMutation) OldLabel ¶
func (m *NodeMutation) OldLabel(ctx context.Context) (v string, err error)
OldLabel returns the old "label" field's value of the Node entity. If the Node object wasn't provided to the builder, the object is fetched from the database. An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (*NodeMutation) OldParentID ¶
OldParentID returns the old "parent_id" field's value of the Node entity. If the Node object wasn't provided to the builder, the object is fetched from the database. An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (*NodeMutation) ParentCleared ¶
func (m *NodeMutation) ParentCleared() bool
ParentCleared reports if the "parent" edge to the Node entity was cleared.
func (*NodeMutation) ParentID ¶
func (m *NodeMutation) ParentID() (r uuid.UUID, exists bool)
ParentID returns the value of the "parent_id" field in the mutation.
func (*NodeMutation) ParentIDCleared ¶
func (m *NodeMutation) ParentIDCleared() bool
ParentIDCleared returns if the "parent_id" field was cleared in this mutation.
func (*NodeMutation) ParentIDs ¶
func (m *NodeMutation) ParentIDs() (ids []uuid.UUID)
ParentIDs returns the "parent" edge IDs in the mutation. Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use ParentID instead. It exists only for internal usage by the builders.
func (*NodeMutation) RemoveChildIDs ¶
func (m *NodeMutation) RemoveChildIDs(ids ...uuid.UUID)
RemoveChildIDs removes the "children" edge to the Node entity by IDs.
func (*NodeMutation) RemovedChildrenIDs ¶
func (m *NodeMutation) RemovedChildrenIDs() (ids []uuid.UUID)
RemovedChildren returns the removed IDs of the "children" edge to the Node entity.
func (*NodeMutation) RemovedEdges ¶
func (m *NodeMutation) RemovedEdges() []string
RemovedEdges returns all edge names that were removed in this mutation.
func (*NodeMutation) RemovedIDs ¶
func (m *NodeMutation) RemovedIDs(name string) []ent.Value
RemovedIDs returns all IDs (to other nodes) that were removed for the edge with the given name in this mutation.
func (*NodeMutation) ResetChildren ¶
func (m *NodeMutation) ResetChildren()
ResetChildren resets all changes to the "children" edge.
func (*NodeMutation) ResetEdge ¶
func (m *NodeMutation) ResetEdge(name string) error
ResetEdge resets all changes to the edge with the given name in this mutation. It returns an error if the edge is not defined in the schema.
func (*NodeMutation) ResetField ¶
func (m *NodeMutation) ResetField(name string) error
ResetField resets all changes in the mutation for the field with the given name. It returns an error if the field is not defined in the schema.
func (*NodeMutation) ResetLabel ¶
func (m *NodeMutation) ResetLabel()
ResetLabel resets all changes to the "label" field.
func (*NodeMutation) ResetParent ¶
func (m *NodeMutation) ResetParent()
ResetParent resets all changes to the "parent" edge.
func (*NodeMutation) ResetParentID ¶
func (m *NodeMutation) ResetParentID()
ResetParentID resets all changes to the "parent_id" field.
func (*NodeMutation) SetField ¶
func (m *NodeMutation) SetField(name string, value ent.Value) error
SetField sets the value of a field with the given name. It returns an error if the field is not defined in the schema, or if the type mismatched the field type.
func (*NodeMutation) SetID ¶
func (m *NodeMutation) SetID(id uuid.UUID)
SetID sets the value of the id field. Note that this operation is only accepted on creation of Node entities.
func (*NodeMutation) SetLabel ¶
func (m *NodeMutation) SetLabel(s string)
SetLabel sets the "label" field.
func (*NodeMutation) SetOp ¶
func (m *NodeMutation) SetOp(op Op)
SetOp allows setting the mutation operation.
func (*NodeMutation) SetParentID ¶
func (m *NodeMutation) SetParentID(u uuid.UUID)
SetParentID sets the "parent_id" field.
func (NodeMutation) Tx ¶
func (m NodeMutation) Tx() (*Tx, error)
Tx returns an `ent.Tx` for mutations that were executed in transactions; it returns an error otherwise.
func (*NodeMutation) Type ¶
func (m *NodeMutation) Type() string
Type returns the node type of this mutation (Node).
func (*NodeMutation) Where ¶
func (m *NodeMutation) Where(ps ...predicate.Node)
Where appends a list predicates to the NodeMutation builder.
func (*NodeMutation) WhereP ¶
func (m *NodeMutation) WhereP(ps ...func(*sql.Selector))
WhereP appends storage-level predicates to the NodeMutation builder. Using this method, users can use type-assertion to append predicates that do not depend on any generated package.
type NodePatchRequest ¶
type NodePatchRequest struct {
Label *string `json:"label,omitempty"`
ParentID *uuid.UUID `json:"parent_id,omitempty"`
// contains filtered or unexported fields
}
NodePatchRequest is the partial-update request for Node.
Every field is a pointer and presence is recorded separately, which is what separates the three states a PATCH has to express: absent means "leave it alone", an explicit null means "clear it", and a value means "set it". With bare pointers the first two are the same value, and clearing a field cannot be expressed at all.
A field the ent schema marks Immutable() is absent from this struct, because ent's update builders iterate MutableFields and generate no setter for one. encoding/json discards the key before any validator can see it, so a caller who sends it gets silence — rejecting that needs DisallowUnknownFields, which belongs to the consumer's handler.
func (*NodePatchRequest) HasLabel ¶
func (r *NodePatchRequest) HasLabel() bool
HasLabel reports whether the payload carried "label".
func (*NodePatchRequest) HasParentID ¶
func (r *NodePatchRequest) HasParentID() bool
HasParentID reports whether the payload carried "parent_id".
func (*NodePatchRequest) UnmarshalJSON ¶
func (r *NodePatchRequest) UnmarshalJSON(b []byte) error
UnmarshalJSON records which keys the payload carried, including the ones whose value was null — that is the whole point here, and the difference from the create request, where a null has nothing to clear.
A key that case-folds to a canonical tag without matching it exactly is rejected (#58, ADR-0001). The patch side is where that mattered most: a case-variant key decoded into the field while Has<Field>() stayed false, so Apply wrote nothing and the update reported success having changed no row — and a payload carrying BOTH spellings could clear a field the exact key had just set. The check runs after raw decodes and BEFORE the alias decode, so a rejected request leaves the receiver untouched.
func (*NodePatchRequest) Validate ¶
func (r *NodePatchRequest) Validate() (*ValidNodePatchRequest, error)
Validate rejects an explicit null on a field that cannot be cleared.
ent emits Clear<Field>() for Optional fields and for no others, so a null on anything else has no correct translation: the column is NOT NULL and there is no method to call. The field is named in the error, because "invalid request" tells the caller nothing about which key to fix.
type NodeQuery ¶
type NodeQuery struct {
// contains filtered or unexported fields
}
NodeQuery is the builder for querying Node entities.
func NodeQueryWithResponseEdges ¶
NodeQueryWithResponseEdges applies the eager-load plan for NodeResponse.
The plan is generated from the response type's own edge set, so no individual edge can be omitted from it. Generated wiring always routes through this function.
For a hand-written query, using this function is a convention the type system does not enforce. An entity loaded without this plan makes NewNodeResponse return a not-loaded-edge error at run time. It fails loudly; it never silently narrows the response.
NodeClient.Get loads no edges and therefore cannot serve this response type. Wiring for Node must go through Query with this plan applied.
func (*NodeQuery) Aggregate ¶
func (nq *NodeQuery) Aggregate(fns ...AggregateFunc) *NodeSelect
Aggregate returns a NodeSelect configured with the given aggregations.
func (*NodeQuery) Clone ¶
Clone returns a duplicate of the NodeQuery builder, including all associated steps. It can be used to prepare common query builders and use them differently after the clone is made.
func (*NodeQuery) First ¶
First returns the first Node entity from the query. Returns a *NotFoundError when no Node was found.
func (*NodeQuery) FirstID ¶
FirstID returns the first Node ID from the query. Returns a *NotFoundError when no Node ID was found.
func (*NodeQuery) GroupBy ¶
func (nq *NodeQuery) GroupBy(field string, fields ...string) *NodeGroupBy
GroupBy is used to group vertices by one or more fields/columns. It is often used with aggregate functions, like: count, max, mean, min, sum.
Example:
var v []struct {
Label string `json:"label,omitempty"`
Count int `json:"count,omitempty"`
}
client.Node.Query().
GroupBy(node.FieldLabel).
Aggregate(selfrefpartialent.Count()).
Scan(ctx, &v)
func (*NodeQuery) Only ¶
Only returns a single Node entity found by the query, ensuring it only returns one. Returns a *NotSingularError when more than one Node entity is found. Returns a *NotFoundError when no Node entities are found.
func (*NodeQuery) OnlyID ¶
OnlyID is like Only, but returns the only Node ID in the query. Returns a *NotSingularError when more than one Node ID is found. Returns a *NotFoundError when no entities are found.
func (*NodeQuery) Order ¶
func (nq *NodeQuery) Order(o ...node.OrderOption) *NodeQuery
Order specifies how the records should be ordered.
func (*NodeQuery) QueryChildren ¶
QueryChildren chains the current query on the "children" edge.
func (*NodeQuery) QueryParent ¶
QueryParent chains the current query on the "parent" edge.
func (*NodeQuery) Select ¶
func (nq *NodeQuery) Select(fields ...string) *NodeSelect
Select allows the selection one or more fields/columns for the given query, instead of selecting all fields in the entity.
Example:
var v []struct {
Label string `json:"label,omitempty"`
}
client.Node.Query().
Select(node.FieldLabel).
Scan(ctx, &v)
func (*NodeQuery) Unique ¶
Unique configures the query builder to filter duplicate records on query. By default, unique is set to true, and can be disabled using this method.
func (*NodeQuery) WithChildren ¶
WithChildren tells the query-builder to eager-load the nodes that are connected to the "children" edge. The optional arguments are used to configure the query builder of the edge.
func (*NodeQuery) WithParent ¶
WithParent tells the query-builder to eager-load the nodes that are connected to the "parent" edge. The optional arguments are used to configure the query builder of the edge.
type NodeResponse ¶
type NodeResponse struct {
// ID field is always included in responses
ID uuid.UUID `json:"id"`
Label string `json:"label"`
ParentID *uuid.UUID `json:"parent_id,omitempty"`
Parent *NodeSummary `json:"parent"`
}
NodeResponse represents the response for Node.
It is emitted unconditionally: an entity whose every scalar field is Sensitive still has a meaningful response carrying its ID, and NodeListResponse below refers to this type either way.
No edge field is omitempty. A loaded edge with no related row has to reach the client as an explicit null: omitting the key would make it indistinguishable from an edge nobody asked to load.
func CreateNode ¶
func CreateNode(ctx context.Context, db *Client, v *ValidNodeCreateRequest) (*NodeResponse, error)
CreateNode inserts one Node and returns its response.
It takes the VALIDATED request. Apply is defined on that type and nowhere else, so validation is a compile-time requirement here rather than a step this function could forget on the caller's behalf.
func NewNodeResponse ¶
func NewNodeResponse(e *Node) (*NodeResponse, error)
NewNodeResponse converts an entity to its response DTO.
Edge state is read through <Edge>OrErr(), never through a nil check: the flag separating "not loaded" from "loaded and absent" is unexported, so a nil pointer cannot tell them apart. Loaded-and-absent becomes an explicit null; a not-loaded edge is returned as an error rather than shipping a response that reads as "this node has none".
That error is cheap because NodeQueryWithResponseEdges below is generated from this type's own edge set, so generated wiring cannot forget an edge and the error only ever catches a hand-rolled query.
func PatchNode ¶
func PatchNode(ctx context.Context, db *Client, id uuid.UUID, v *ValidNodePatchRequest) (*NodeResponse, error)
PatchNode applies a validated patch to one Node.
Fields the patch did not carry are not written at all, so a partial update stays partial — that property belongs to Apply, and this function does not re-decide it.
type NodeSelect ¶
type NodeSelect struct {
*NodeQuery
// contains filtered or unexported fields
}
NodeSelect is the builder for selecting fields of Node entities.
func (*NodeSelect) Aggregate ¶
func (ns *NodeSelect) Aggregate(fns ...AggregateFunc) *NodeSelect
Aggregate adds the given aggregation functions to the selector query.
func (*NodeSelect) Bool ¶
Bool returns a single bool from a selector. It is only allowed when selecting one field.
func (*NodeSelect) Bools ¶
Bools returns list of bools from a selector. It is only allowed when selecting one field.
func (*NodeSelect) Float64 ¶
Float64 returns a single float64 from a selector. It is only allowed when selecting one field.
func (*NodeSelect) Float64s ¶
Float64s returns list of float64s from a selector. It is only allowed when selecting one field.
func (*NodeSelect) Int ¶
Int returns a single int from a selector. It is only allowed when selecting one field.
func (*NodeSelect) Ints ¶
Ints returns list of ints from a selector. It is only allowed when selecting one field.
func (*NodeSelect) Scan ¶
func (ns *NodeSelect) Scan(ctx context.Context, v any) error
Scan applies the selector query and scans the result into the given value.
func (*NodeSelect) String ¶
String returns a single string from a selector. It is only allowed when selecting one field.
type NodeSummary ¶
type NodeSummary struct {
// ID field is always included in summaries
ID uuid.UUID `json:"id"`
Label string `json:"label"`
ParentID *uuid.UUID `json:"parent_id,omitempty"`
}
NodeSummary is the shape Node takes on another entity's response.
It carries the same scalar fields as NodeResponse and no edges at all. That is what bounds expansion: NewNodeResponse calls summary constructors, and a summary constructor calls nothing, so there is no second level for a cycle to close through and no runtime depth counter is needed.
The cost is real rather than hidden: a three-level tree comes back one level deep, and a deeper one needs another round trip per level.
func NewNodeSummary ¶
func NewNodeSummary(e *Node) *NodeSummary
NewNodeSummary converts an entity to its summary DTO. It cannot fail: a summary reads no edges.
type NodeUpdate ¶
type NodeUpdate struct {
// contains filtered or unexported fields
}
NodeUpdate is the builder for updating Node entities.
func (*NodeUpdate) AddChildIDs ¶
func (nu *NodeUpdate) AddChildIDs(ids ...uuid.UUID) *NodeUpdate
AddChildIDs adds the "children" edge to the Node entity by IDs.
func (*NodeUpdate) AddChildren ¶
func (nu *NodeUpdate) AddChildren(n ...*Node) *NodeUpdate
AddChildren adds the "children" edges to the Node entity.
func (*NodeUpdate) ClearChildren ¶
func (nu *NodeUpdate) ClearChildren() *NodeUpdate
ClearChildren clears all "children" edges to the Node entity.
func (*NodeUpdate) ClearParent ¶
func (nu *NodeUpdate) ClearParent() *NodeUpdate
ClearParent clears the "parent" edge to the Node entity.
func (*NodeUpdate) ClearParentID ¶
func (nu *NodeUpdate) ClearParentID() *NodeUpdate
ClearParentID clears the value of the "parent_id" field.
func (*NodeUpdate) Exec ¶
func (nu *NodeUpdate) Exec(ctx context.Context) error
Exec executes the query.
func (*NodeUpdate) ExecX ¶
func (nu *NodeUpdate) ExecX(ctx context.Context)
ExecX is like Exec, but panics if an error occurs.
func (*NodeUpdate) Mutation ¶
func (nu *NodeUpdate) Mutation() *NodeMutation
Mutation returns the NodeMutation object of the builder.
func (*NodeUpdate) RemoveChildIDs ¶
func (nu *NodeUpdate) RemoveChildIDs(ids ...uuid.UUID) *NodeUpdate
RemoveChildIDs removes the "children" edge to Node entities by IDs.
func (*NodeUpdate) RemoveChildren ¶
func (nu *NodeUpdate) RemoveChildren(n ...*Node) *NodeUpdate
RemoveChildren removes "children" edges to Node entities.
func (*NodeUpdate) Save ¶
func (nu *NodeUpdate) Save(ctx context.Context) (int, error)
Save executes the query and returns the number of nodes affected by the update operation.
func (*NodeUpdate) SaveX ¶
func (nu *NodeUpdate) SaveX(ctx context.Context) int
SaveX is like Save, but panics if an error occurs.
func (*NodeUpdate) SetLabel ¶
func (nu *NodeUpdate) SetLabel(s string) *NodeUpdate
SetLabel sets the "label" field.
func (*NodeUpdate) SetNillableLabel ¶
func (nu *NodeUpdate) SetNillableLabel(s *string) *NodeUpdate
SetNillableLabel sets the "label" field if the given value is not nil.
func (*NodeUpdate) SetNillableParentID ¶
func (nu *NodeUpdate) SetNillableParentID(u *uuid.UUID) *NodeUpdate
SetNillableParentID sets the "parent_id" field if the given value is not nil.
func (*NodeUpdate) SetParent ¶
func (nu *NodeUpdate) SetParent(n *Node) *NodeUpdate
SetParent sets the "parent" edge to the Node entity.
func (*NodeUpdate) SetParentID ¶
func (nu *NodeUpdate) SetParentID(u uuid.UUID) *NodeUpdate
SetParentID sets the "parent_id" field.
func (*NodeUpdate) Where ¶
func (nu *NodeUpdate) Where(ps ...predicate.Node) *NodeUpdate
Where appends a list predicates to the NodeUpdate builder.
type NodeUpdateOne ¶
type NodeUpdateOne struct {
// contains filtered or unexported fields
}
NodeUpdateOne is the builder for updating a single Node entity.
func (*NodeUpdateOne) AddChildIDs ¶
func (nuo *NodeUpdateOne) AddChildIDs(ids ...uuid.UUID) *NodeUpdateOne
AddChildIDs adds the "children" edge to the Node entity by IDs.
func (*NodeUpdateOne) AddChildren ¶
func (nuo *NodeUpdateOne) AddChildren(n ...*Node) *NodeUpdateOne
AddChildren adds the "children" edges to the Node entity.
func (*NodeUpdateOne) ClearChildren ¶
func (nuo *NodeUpdateOne) ClearChildren() *NodeUpdateOne
ClearChildren clears all "children" edges to the Node entity.
func (*NodeUpdateOne) ClearParent ¶
func (nuo *NodeUpdateOne) ClearParent() *NodeUpdateOne
ClearParent clears the "parent" edge to the Node entity.
func (*NodeUpdateOne) ClearParentID ¶
func (nuo *NodeUpdateOne) ClearParentID() *NodeUpdateOne
ClearParentID clears the value of the "parent_id" field.
func (*NodeUpdateOne) Exec ¶
func (nuo *NodeUpdateOne) Exec(ctx context.Context) error
Exec executes the query on the entity.
func (*NodeUpdateOne) ExecX ¶
func (nuo *NodeUpdateOne) ExecX(ctx context.Context)
ExecX is like Exec, but panics if an error occurs.
func (*NodeUpdateOne) Mutation ¶
func (nuo *NodeUpdateOne) Mutation() *NodeMutation
Mutation returns the NodeMutation object of the builder.
func (*NodeUpdateOne) RemoveChildIDs ¶
func (nuo *NodeUpdateOne) RemoveChildIDs(ids ...uuid.UUID) *NodeUpdateOne
RemoveChildIDs removes the "children" edge to Node entities by IDs.
func (*NodeUpdateOne) RemoveChildren ¶
func (nuo *NodeUpdateOne) RemoveChildren(n ...*Node) *NodeUpdateOne
RemoveChildren removes "children" edges to Node entities.
func (*NodeUpdateOne) Save ¶
func (nuo *NodeUpdateOne) Save(ctx context.Context) (*Node, error)
Save executes the query and returns the updated Node entity.
func (*NodeUpdateOne) SaveX ¶
func (nuo *NodeUpdateOne) SaveX(ctx context.Context) *Node
SaveX is like Save, but panics if an error occurs.
func (*NodeUpdateOne) Select ¶
func (nuo *NodeUpdateOne) Select(field string, fields ...string) *NodeUpdateOne
Select allows selecting one or more fields (columns) of the returned entity. The default is selecting all fields defined in the entity schema.
func (*NodeUpdateOne) SetLabel ¶
func (nuo *NodeUpdateOne) SetLabel(s string) *NodeUpdateOne
SetLabel sets the "label" field.
func (*NodeUpdateOne) SetNillableLabel ¶
func (nuo *NodeUpdateOne) SetNillableLabel(s *string) *NodeUpdateOne
SetNillableLabel sets the "label" field if the given value is not nil.
func (*NodeUpdateOne) SetNillableParentID ¶
func (nuo *NodeUpdateOne) SetNillableParentID(u *uuid.UUID) *NodeUpdateOne
SetNillableParentID sets the "parent_id" field if the given value is not nil.
func (*NodeUpdateOne) SetParent ¶
func (nuo *NodeUpdateOne) SetParent(n *Node) *NodeUpdateOne
SetParent sets the "parent" edge to the Node entity.
func (*NodeUpdateOne) SetParentID ¶
func (nuo *NodeUpdateOne) SetParentID(u uuid.UUID) *NodeUpdateOne
SetParentID sets the "parent_id" field.
func (*NodeUpdateOne) Where ¶
func (nuo *NodeUpdateOne) Where(ps ...predicate.Node) *NodeUpdateOne
Where appends a list predicates to the NodeUpdate builder.
type NotFoundError ¶
type NotFoundError struct {
// contains filtered or unexported fields
}
NotFoundError returns when trying to fetch a specific entity and it was not found in the database.
func (*NotFoundError) Error ¶
func (e *NotFoundError) Error() string
Error implements the error interface.
type NotLoadedError ¶
type NotLoadedError struct {
// contains filtered or unexported fields
}
NotLoadedError returns when trying to get a node that was not loaded by the query.
func (*NotLoadedError) Error ¶
func (e *NotLoadedError) Error() string
Error implements the error interface.
type NotSingularError ¶
type NotSingularError struct {
// contains filtered or unexported fields
}
NotSingularError returns when trying to fetch a singular entity and more then one was found in the database.
func (*NotSingularError) Error ¶
func (e *NotSingularError) Error() string
Error implements the error interface.
type OrderFunc ¶
OrderFunc applies an ordering on the sql selector. Deprecated: Use Asc/Desc functions or the package builders instead.
type PatchNodeFn ¶
type PatchNodeFn func(context.Context, *Client, uuid.UUID, *ValidNodePatchRequest) (*NodeResponse, error)
PatchNodeFn is byte-identical to PatchNode.
type QuerierFunc ¶
type QuerierFunc = ent.QuerierFunc
ent aliases to avoid import conflicts in user's code.
type QueryContext ¶
type QueryContext = ent.QueryContext
ent aliases to avoid import conflicts in user's code.
type RollbackFunc ¶
The RollbackFunc type is an adapter to allow the use of ordinary function as a Rollbacker. If f is a function with the appropriate signature, RollbackFunc(f) is a Rollbacker that calls f.
type RollbackHook ¶
type RollbackHook func(Rollbacker) Rollbacker
RollbackHook defines the "rollback middleware". A function that gets a Rollbacker and returns a Rollbacker. For example:
hook := func(next ent.Rollbacker) ent.Rollbacker {
return ent.RollbackFunc(func(ctx context.Context, tx *ent.Tx) error {
// Do some stuff before.
if err := next.Rollback(ctx, tx); err != nil {
return err
}
// Do some stuff after.
return nil
})
}
type Rollbacker ¶
Rollbacker is the interface that wraps the Rollback method.
type TraverseFunc ¶
type TraverseFunc = ent.TraverseFunc
ent aliases to avoid import conflicts in user's code.
type Tx ¶
type Tx struct {
// Node is the client for interacting with the Node builders.
Node *NodeClient
// contains filtered or unexported fields
}
Tx is a transactional client that is created by calling Client.Tx().
func TxFromContext ¶
TxFromContext returns a Tx stored inside a context, or nil if there isn't one.
func (*Tx) OnRollback ¶
func (tx *Tx) OnRollback(f RollbackHook)
OnRollback adds a hook to call on rollback.
type ValidNodeCreateRequest ¶
type ValidNodeCreateRequest struct {
// contains filtered or unexported fields
}
ValidNodeCreateRequest wraps a NodeCreateRequest that has passed Validate. Apply is defined on this type and nowhere else, so a caller who skips validation has no method to call — a compile error rather than a validator that runs only when someone remembers it.
func (*ValidNodeCreateRequest) Apply ¶
func (v *ValidNodeCreateRequest) Apply(b *NodeCreate) *NodeCreate
Apply writes the request onto a create builder.
A field the caller omitted is not written at all, so the schema's Default() still applies. Writing the zero value unconditionally is what silently defeated every schema default.
func (*ValidNodeCreateRequest) HasLabel ¶
func (v *ValidNodeCreateRequest) HasLabel() bool
HasLabel reports whether the payload carried "label".
func (*ValidNodeCreateRequest) HasParentID ¶
func (v *ValidNodeCreateRequest) HasParentID() bool
HasParentID reports whether the payload carried "parent_id".
type ValidNodePatchRequest ¶
type ValidNodePatchRequest struct {
// contains filtered or unexported fields
}
ValidNodePatchRequest wraps a NodePatchRequest that has passed Validate. It is the only type Apply is defined on.
func (*ValidNodePatchRequest) Apply ¶
func (v *ValidNodePatchRequest) Apply(b *NodeUpdateOne) *NodeUpdateOne
Apply writes the request onto an update builder. Absent fields are not touched; the rest are set, or cleared when the caller sent an explicit null.
func (*ValidNodePatchRequest) HasLabel ¶
func (v *ValidNodePatchRequest) HasLabel() bool
HasLabel reports whether the payload carried "label".
A custom implementation receives only the validated type, so without this forwarder the patch's presence — the one thing that distinguishes "clear it" from "leave it alone" — is unreachable from the customization point that is supposed to act on it.
func (*ValidNodePatchRequest) HasParentID ¶
func (v *ValidNodePatchRequest) HasParentID() bool
HasParentID reports whether the payload carried "parent_id".
A custom implementation receives only the validated type, so without this forwarder the patch's presence — the one thing that distinguishes "clear it" from "leave it alone" — is unreachable from the customization point that is supposed to act on it.
func (*ValidNodePatchRequest) Label ¶
func (v *ValidNodePatchRequest) Label() (string, bool)
Label reports the value the payload carried for "label", and whether Apply will Set it.
Presence is two of the three states a PATCH field has; this reads the third. Paired with HasLabel(), which is "present" below:
ok the payload carried a value; Apply will Set it
!ok, present the payload carried an explicit null; Apply will
Clear it. Reachable only for a clearable field —
Validate refuses a null on anything else
!ok, absent the key was not in the payload; Apply writes nothing
Without it a cross-field rule cannot tell "clear this" from "set this", and the customization point is forced to allocate an update builder it never executes, Apply the request to it and read back Mutation() (#113).
func (*ValidNodePatchRequest) ParentID ¶
func (v *ValidNodePatchRequest) ParentID() (uuid.UUID, bool)
ParentID reports the value the payload carried for "parent_id", and whether Apply will Set it.
Presence is two of the three states a PATCH field has; this reads the third. Paired with HasParentID(), which is "present" below:
ok the payload carried a value; Apply will Set it
!ok, present the payload carried an explicit null; Apply will
Clear it. Reachable only for a clearable field —
Validate refuses a null on anything else
!ok, absent the key was not in the payload; Apply writes nothing
Without it a cross-field rule cannot tell "clear this" from "set this", and the customization point is forced to allocate an update builder it never executes, Apply the request to it and read back Mutation() (#113).
type ValidationError ¶
type ValidationError struct {
Name string // Field or edge name.
// contains filtered or unexported fields
}
ValidationError returns when validating a field or edge fails.
func (*ValidationError) Error ¶
func (e *ValidationError) Error() string
Error implements the error interface.
func (*ValidationError) Unwrap ¶
func (e *ValidationError) Unwrap() error
Unwrap implements the errors.Wrapper interface.