Documentation
¶
Index ¶
- Constants
- Variables
- func Asc(fields ...string) func(*sql.Selector)
- func DeleteBatchWidgets(ctx context.Context, db *Client, ids []uuid.UUID) (int, error)
- func DeleteWidget(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 ListWidgets(ctx context.Context, db *Client, f *WidgetFilter, r entapi.ListRequest) (*entapi.Page[WidgetResponse], 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 WidgetCreateRequestTags() []string
- func WidgetOrder(r entapi.ListRequest) ([]widget.OrderOption, error)
- func WidgetPatchRequestTags() []string
- type APIHandler
- func (h *APIHandler) CreateWidgetEndpoint() entapi.Endpoint
- func (h *APIHandler) DeleteWidgetEndpoint() entapi.Endpoint
- func (h *APIHandler) Endpoints() []entapi.Endpoint
- func (h *APIHandler) GetWidgetEndpoint() entapi.Endpoint
- func (h *APIHandler) ListWidgetsEndpoint() entapi.Endpoint
- func (h *APIHandler) Mount(mux *http.ServeMux)
- func (h *APIHandler) OpenAPIEndpoint() entapi.Endpoint
- func (h *APIHandler) PatchWidgetEndpoint() 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 CreateWidgetFn
- type DeleteWidgetFn
- type GetWidgetFn
- type Hook
- type InterceptFunc
- type Interceptor
- type ListWidgetsFn
- type MutateFunc
- type Mutation
- type Mutator
- type NotFoundError
- type NotLoadedError
- type NotSingularError
- type Op
- type Option
- type OrderFunc
- type PatchWidgetFn
- type Policy
- type Querier
- type QuerierFunc
- type Query
- type QueryContext
- type RollbackFunc
- type RollbackHook
- type Rollbacker
- type TraverseFunc
- type Traverser
- type Tx
- type ValidWidgetCreateRequest
- type ValidWidgetPatchRequest
- func (v *ValidWidgetPatchRequest) Apply(b *WidgetUpdateOne) *WidgetUpdateOne
- func (v *ValidWidgetPatchRequest) Description() (string, bool)
- func (v *ValidWidgetPatchRequest) HasDescription() bool
- func (v *ValidWidgetPatchRequest) HasName() bool
- func (v *ValidWidgetPatchRequest) Name() (string, bool)
- type ValidationError
- type Value
- type Widget
- type WidgetClient
- func (c *WidgetClient) Create() *WidgetCreate
- func (c *WidgetClient) CreateBulk(builders ...*WidgetCreate) *WidgetCreateBulk
- func (c *WidgetClient) Delete() *WidgetDelete
- func (c *WidgetClient) DeleteOne(w *Widget) *WidgetDeleteOne
- func (c *WidgetClient) DeleteOneID(id uuid.UUID) *WidgetDeleteOne
- func (c *WidgetClient) Get(ctx context.Context, id uuid.UUID) (*Widget, error)
- func (c *WidgetClient) GetX(ctx context.Context, id uuid.UUID) *Widget
- func (c *WidgetClient) Hooks() []Hook
- func (c *WidgetClient) Intercept(interceptors ...Interceptor)
- func (c *WidgetClient) Interceptors() []Interceptor
- func (c *WidgetClient) MapCreateBulk(slice any, setFunc func(*WidgetCreate, int)) *WidgetCreateBulk
- func (c *WidgetClient) Query() *WidgetQuery
- func (c *WidgetClient) Update() *WidgetUpdate
- func (c *WidgetClient) UpdateOne(w *Widget) *WidgetUpdateOne
- func (c *WidgetClient) UpdateOneID(id uuid.UUID) *WidgetUpdateOne
- func (c *WidgetClient) Use(hooks ...Hook)
- type WidgetCreate
- func (wc *WidgetCreate) Exec(ctx context.Context) error
- func (wc *WidgetCreate) ExecX(ctx context.Context)
- func (wc *WidgetCreate) Mutation() *WidgetMutation
- func (wc *WidgetCreate) Save(ctx context.Context) (*Widget, error)
- func (wc *WidgetCreate) SaveX(ctx context.Context) *Widget
- func (wc *WidgetCreate) SetCreatedAt(t time.Time) *WidgetCreate
- func (wc *WidgetCreate) SetDescription(s string) *WidgetCreate
- func (wc *WidgetCreate) SetID(u uuid.UUID) *WidgetCreate
- func (wc *WidgetCreate) SetName(s string) *WidgetCreate
- func (wc *WidgetCreate) SetNillableCreatedAt(t *time.Time) *WidgetCreate
- func (wc *WidgetCreate) SetNillableDescription(s *string) *WidgetCreate
- func (wc *WidgetCreate) SetNillableID(u *uuid.UUID) *WidgetCreate
- type WidgetCreateBulk
- type WidgetCreateRequest
- type WidgetDelete
- type WidgetDeleteOne
- type WidgetFilter
- type WidgetGroupBy
- func (wgb *WidgetGroupBy) Aggregate(fns ...AggregateFunc) *WidgetGroupBy
- func (s *WidgetGroupBy) Bool(ctx context.Context) (_ bool, err error)
- func (s *WidgetGroupBy) BoolX(ctx context.Context) bool
- func (s *WidgetGroupBy) Bools(ctx context.Context) ([]bool, error)
- func (s *WidgetGroupBy) BoolsX(ctx context.Context) []bool
- func (s *WidgetGroupBy) Float64(ctx context.Context) (_ float64, err error)
- func (s *WidgetGroupBy) Float64X(ctx context.Context) float64
- func (s *WidgetGroupBy) Float64s(ctx context.Context) ([]float64, error)
- func (s *WidgetGroupBy) Float64sX(ctx context.Context) []float64
- func (s *WidgetGroupBy) Int(ctx context.Context) (_ int, err error)
- func (s *WidgetGroupBy) IntX(ctx context.Context) int
- func (s *WidgetGroupBy) Ints(ctx context.Context) ([]int, error)
- func (s *WidgetGroupBy) IntsX(ctx context.Context) []int
- func (wgb *WidgetGroupBy) Scan(ctx context.Context, v any) error
- func (s *WidgetGroupBy) ScanX(ctx context.Context, v any)
- func (s *WidgetGroupBy) String(ctx context.Context) (_ string, err error)
- func (s *WidgetGroupBy) StringX(ctx context.Context) string
- func (s *WidgetGroupBy) Strings(ctx context.Context) ([]string, error)
- func (s *WidgetGroupBy) StringsX(ctx context.Context) []string
- type WidgetListResponse
- type WidgetMutation
- func (m *WidgetMutation) AddField(name string, value ent.Value) error
- func (m *WidgetMutation) AddedEdges() []string
- func (m *WidgetMutation) AddedField(name string) (ent.Value, bool)
- func (m *WidgetMutation) AddedFields() []string
- func (m *WidgetMutation) AddedIDs(name string) []ent.Value
- func (m *WidgetMutation) ClearDescription()
- func (m *WidgetMutation) ClearEdge(name string) error
- func (m *WidgetMutation) ClearField(name string) error
- func (m *WidgetMutation) ClearedEdges() []string
- func (m *WidgetMutation) ClearedFields() []string
- func (m WidgetMutation) Client() *Client
- func (m *WidgetMutation) CreatedAt() (r time.Time, exists bool)
- func (m *WidgetMutation) Description() (r string, exists bool)
- func (m *WidgetMutation) DescriptionCleared() bool
- func (m *WidgetMutation) EdgeCleared(name string) bool
- func (m *WidgetMutation) Field(name string) (ent.Value, bool)
- func (m *WidgetMutation) FieldCleared(name string) bool
- func (m *WidgetMutation) Fields() []string
- func (m *WidgetMutation) ID() (id uuid.UUID, exists bool)
- func (m *WidgetMutation) IDs(ctx context.Context) ([]uuid.UUID, error)
- func (m *WidgetMutation) Name() (r string, exists bool)
- func (m *WidgetMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error)
- func (m *WidgetMutation) OldDescription(ctx context.Context) (v string, err error)
- func (m *WidgetMutation) OldField(ctx context.Context, name string) (ent.Value, error)
- func (m *WidgetMutation) OldName(ctx context.Context) (v string, err error)
- func (m *WidgetMutation) Op() Op
- func (m *WidgetMutation) RemovedEdges() []string
- func (m *WidgetMutation) RemovedIDs(name string) []ent.Value
- func (m *WidgetMutation) ResetCreatedAt()
- func (m *WidgetMutation) ResetDescription()
- func (m *WidgetMutation) ResetEdge(name string) error
- func (m *WidgetMutation) ResetField(name string) error
- func (m *WidgetMutation) ResetName()
- func (m *WidgetMutation) SetCreatedAt(t time.Time)
- func (m *WidgetMutation) SetDescription(s string)
- func (m *WidgetMutation) SetField(name string, value ent.Value) error
- func (m *WidgetMutation) SetID(id uuid.UUID)
- func (m *WidgetMutation) SetName(s string)
- func (m *WidgetMutation) SetOp(op Op)
- func (m WidgetMutation) Tx() (*Tx, error)
- func (m *WidgetMutation) Type() string
- func (m *WidgetMutation) Where(ps ...predicate.Widget)
- func (m *WidgetMutation) WhereP(ps ...func(*sql.Selector))
- type WidgetPatchRequest
- type WidgetQuery
- func (wq *WidgetQuery) Aggregate(fns ...AggregateFunc) *WidgetSelect
- func (wq *WidgetQuery) All(ctx context.Context) ([]*Widget, error)
- func (wq *WidgetQuery) AllX(ctx context.Context) []*Widget
- func (wq *WidgetQuery) Clone() *WidgetQuery
- func (wq *WidgetQuery) Count(ctx context.Context) (int, error)
- func (wq *WidgetQuery) CountX(ctx context.Context) int
- func (wq *WidgetQuery) Exist(ctx context.Context) (bool, error)
- func (wq *WidgetQuery) ExistX(ctx context.Context) bool
- func (wq *WidgetQuery) First(ctx context.Context) (*Widget, error)
- func (wq *WidgetQuery) FirstID(ctx context.Context) (id uuid.UUID, err error)
- func (wq *WidgetQuery) FirstIDX(ctx context.Context) uuid.UUID
- func (wq *WidgetQuery) FirstX(ctx context.Context) *Widget
- func (wq *WidgetQuery) GroupBy(field string, fields ...string) *WidgetGroupBy
- func (wq *WidgetQuery) IDs(ctx context.Context) (ids []uuid.UUID, err error)
- func (wq *WidgetQuery) IDsX(ctx context.Context) []uuid.UUID
- func (wq *WidgetQuery) Limit(limit int) *WidgetQuery
- func (wq *WidgetQuery) Offset(offset int) *WidgetQuery
- func (wq *WidgetQuery) Only(ctx context.Context) (*Widget, error)
- func (wq *WidgetQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error)
- func (wq *WidgetQuery) OnlyIDX(ctx context.Context) uuid.UUID
- func (wq *WidgetQuery) OnlyX(ctx context.Context) *Widget
- func (wq *WidgetQuery) Order(o ...widget.OrderOption) *WidgetQuery
- func (wq *WidgetQuery) Select(fields ...string) *WidgetSelect
- func (wq *WidgetQuery) Unique(unique bool) *WidgetQuery
- func (wq *WidgetQuery) Where(ps ...predicate.Widget) *WidgetQuery
- type WidgetResponse
- func CreateWidget(ctx context.Context, db *Client, v *ValidWidgetCreateRequest) (*WidgetResponse, error)
- func GetWidget(ctx context.Context, db *Client, id uuid.UUID) (*WidgetResponse, error)
- func NewWidgetResponse(e *Widget) (*WidgetResponse, error)
- func PatchWidget(ctx context.Context, db *Client, id uuid.UUID, v *ValidWidgetPatchRequest) (*WidgetResponse, error)
- type WidgetSelect
- func (ws *WidgetSelect) Aggregate(fns ...AggregateFunc) *WidgetSelect
- func (s *WidgetSelect) Bool(ctx context.Context) (_ bool, err error)
- func (s *WidgetSelect) BoolX(ctx context.Context) bool
- func (s *WidgetSelect) Bools(ctx context.Context) ([]bool, error)
- func (s *WidgetSelect) BoolsX(ctx context.Context) []bool
- func (s *WidgetSelect) Float64(ctx context.Context) (_ float64, err error)
- func (s *WidgetSelect) Float64X(ctx context.Context) float64
- func (s *WidgetSelect) Float64s(ctx context.Context) ([]float64, error)
- func (s *WidgetSelect) Float64sX(ctx context.Context) []float64
- func (s *WidgetSelect) Int(ctx context.Context) (_ int, err error)
- func (s *WidgetSelect) IntX(ctx context.Context) int
- func (s *WidgetSelect) Ints(ctx context.Context) ([]int, error)
- func (s *WidgetSelect) IntsX(ctx context.Context) []int
- func (ws *WidgetSelect) Scan(ctx context.Context, v any) error
- func (s *WidgetSelect) ScanX(ctx context.Context, v any)
- func (s *WidgetSelect) String(ctx context.Context) (_ string, err error)
- func (s *WidgetSelect) StringX(ctx context.Context) string
- func (s *WidgetSelect) Strings(ctx context.Context) ([]string, error)
- func (s *WidgetSelect) StringsX(ctx context.Context) []string
- type WidgetSummary
- type WidgetUpdate
- func (wu *WidgetUpdate) ClearDescription() *WidgetUpdate
- func (wu *WidgetUpdate) Exec(ctx context.Context) error
- func (wu *WidgetUpdate) ExecX(ctx context.Context)
- func (wu *WidgetUpdate) Mutation() *WidgetMutation
- func (wu *WidgetUpdate) Save(ctx context.Context) (int, error)
- func (wu *WidgetUpdate) SaveX(ctx context.Context) int
- func (wu *WidgetUpdate) SetDescription(s string) *WidgetUpdate
- func (wu *WidgetUpdate) SetName(s string) *WidgetUpdate
- func (wu *WidgetUpdate) SetNillableDescription(s *string) *WidgetUpdate
- func (wu *WidgetUpdate) SetNillableName(s *string) *WidgetUpdate
- func (wu *WidgetUpdate) Where(ps ...predicate.Widget) *WidgetUpdate
- type WidgetUpdateOne
- func (wuo *WidgetUpdateOne) ClearDescription() *WidgetUpdateOne
- func (wuo *WidgetUpdateOne) Exec(ctx context.Context) error
- func (wuo *WidgetUpdateOne) ExecX(ctx context.Context)
- func (wuo *WidgetUpdateOne) Mutation() *WidgetMutation
- func (wuo *WidgetUpdateOne) Save(ctx context.Context) (*Widget, error)
- func (wuo *WidgetUpdateOne) SaveX(ctx context.Context) *Widget
- func (wuo *WidgetUpdateOne) Select(field string, fields ...string) *WidgetUpdateOne
- func (wuo *WidgetUpdateOne) SetDescription(s string) *WidgetUpdateOne
- func (wuo *WidgetUpdateOne) SetName(s string) *WidgetUpdateOne
- func (wuo *WidgetUpdateOne) SetNillableDescription(s *string) *WidgetUpdateOne
- func (wuo *WidgetUpdateOne) SetNillableName(s *string) *WidgetUpdateOne
- func (wuo *WidgetUpdateOne) Where(ps ...predicate.Widget) *WidgetUpdateOne
- type Widgets
Constants ¶
const ( // Operation types. OpCreate = ent.OpCreate OpDelete = ent.OpDelete OpDeleteOne = ent.OpDeleteOne OpUpdate = ent.OpUpdate OpUpdateOne = ent.OpUpdateOne // Node types. TypeWidget = "Widget" )
Variables ¶
var ErrTxStarted = errors.New("basicent: 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 WidgetSortKeys = []string{
"id",
}
WidgetSortKeys is the complete sort allow-list. The primary key is naturally Sortable; every other key requires api.Sortable().
Functions ¶
func DeleteBatchWidgets ¶
DeleteBatchWidgets removes several Widgets 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 DeleteWidget ¶
DeleteWidget removes one Widget.
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 ListWidgets ¶
func ListWidgets(ctx context.Context, db *Client, f *WidgetFilter, r entapi.ListRequest) (*entapi.Page[WidgetResponse], error)
ListWidgets 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: WidgetOrder can fail, because a sort key outside WidgetSortKeys 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 WidgetCreateRequestTags ¶
func WidgetCreateRequestTags() []string
WidgetCreateRequestTags returns the canonical JSON key of every field on WidgetCreateRequest, 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 WidgetOrder ¶
func WidgetOrder(r entapi.ListRequest) ([]widget.OrderOption, error)
WidgetOrder is the single sort allow-list seam.
func WidgetPatchRequestTags ¶
func WidgetPatchRequestTags() []string
WidgetPatchRequestTags returns the canonical JSON key of every field on WidgetPatchRequest, 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) CreateWidgetEndpoint ¶
func (h *APIHandler) CreateWidgetEndpoint() entapi.Endpoint
CreateWidgetEndpoint returns the generated POST /widgets endpoint.
func (*APIHandler) DeleteWidgetEndpoint ¶
func (h *APIHandler) DeleteWidgetEndpoint() entapi.Endpoint
DeleteWidgetEndpoint returns the generated DELETE /widgets/{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) GetWidgetEndpoint ¶
func (h *APIHandler) GetWidgetEndpoint() entapi.Endpoint
GetWidgetEndpoint returns the generated GET /widgets/{id} endpoint.
func (*APIHandler) ListWidgetsEndpoint ¶
func (h *APIHandler) ListWidgetsEndpoint() entapi.Endpoint
ListWidgetsEndpoint returns the generated GET /widgets 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) PatchWidgetEndpoint ¶
func (h *APIHandler) PatchWidgetEndpoint() entapi.Endpoint
PatchWidgetEndpoint returns the generated PATCH /widgets/{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(basicent.As(basicent.Sum(field1), "sum_field1"), (basicent.As(basicent.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
// Widget is the client for interacting with the Widget builders.
Widget *WidgetClient
// 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(). Widget. 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 CreateWidgetFn ¶
type CreateWidgetFn func(context.Context, *Client, *ValidWidgetCreateRequest) (*WidgetResponse, error)
CreateWidgetFn is byte-identical to CreateWidget.
type DeleteWidgetFn ¶
DeleteWidgetFn is byte-identical to DeleteWidget.
type GetWidgetFn ¶
GetWidgetFn is byte-identical to GetWidget.
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 ListWidgetsFn ¶
type ListWidgetsFn func(context.Context, *Client, *WidgetFilter, entapi.ListRequest) (*entapi.Page[WidgetResponse], error)
ListWidgetsFn is byte-identical to ListWidgets.
type MutateFunc ¶
type MutateFunc = ent.MutateFunc
ent aliases to avoid import conflicts in user's code.
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 PatchWidgetFn ¶
type PatchWidgetFn func(context.Context, *Client, uuid.UUID, *ValidWidgetPatchRequest) (*WidgetResponse, error)
PatchWidgetFn is byte-identical to PatchWidget.
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 {
// Widget is the client for interacting with the Widget builders.
Widget *WidgetClient
// 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 ValidWidgetCreateRequest ¶
type ValidWidgetCreateRequest struct {
// contains filtered or unexported fields
}
ValidWidgetCreateRequest wraps a WidgetCreateRequest 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 (*ValidWidgetCreateRequest) Apply ¶
func (v *ValidWidgetCreateRequest) Apply(b *WidgetCreate) *WidgetCreate
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 (*ValidWidgetCreateRequest) HasDescription ¶
func (v *ValidWidgetCreateRequest) HasDescription() bool
HasDescription reports whether the payload carried "description".
func (*ValidWidgetCreateRequest) HasName ¶
func (v *ValidWidgetCreateRequest) HasName() bool
HasName reports whether the payload carried "name".
type ValidWidgetPatchRequest ¶
type ValidWidgetPatchRequest struct {
// contains filtered or unexported fields
}
ValidWidgetPatchRequest wraps a WidgetPatchRequest that has passed Validate. It is the only type Apply is defined on.
func (*ValidWidgetPatchRequest) Apply ¶
func (v *ValidWidgetPatchRequest) Apply(b *WidgetUpdateOne) *WidgetUpdateOne
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 (*ValidWidgetPatchRequest) Description ¶
func (v *ValidWidgetPatchRequest) Description() (string, bool)
Description reports the value the payload carried for "description", and whether Apply will Set it.
Presence is two of the three states a PATCH field has; this reads the third. Paired with HasDescription(), 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 (*ValidWidgetPatchRequest) HasDescription ¶
func (v *ValidWidgetPatchRequest) HasDescription() bool
HasDescription reports whether the payload carried "description".
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 (*ValidWidgetPatchRequest) HasName ¶
func (v *ValidWidgetPatchRequest) HasName() bool
HasName reports whether the payload carried "name".
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 (*ValidWidgetPatchRequest) Name ¶
func (v *ValidWidgetPatchRequest) Name() (string, bool)
Name reports the value the payload carried for "name", and whether Apply will Set it.
Presence is two of the three states a PATCH field has; this reads the third. Paired with HasName(), 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.
type Widget ¶
type Widget struct {
// ID of the ent.
ID uuid.UUID `json:"id,omitempty"`
// Name holds the value of the "name" field.
Name string `json:"name,omitempty"`
// Description holds the value of the "description" field.
Description string `json:"description,omitempty"`
// CreatedAt holds the value of the "created_at" field.
CreatedAt time.Time `json:"created_at,omitempty"`
// contains filtered or unexported fields
}
Widget is the model entity for the Widget schema.
func (*Widget) Unwrap ¶
Unwrap unwraps the Widget 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 (*Widget) Update ¶
func (w *Widget) Update() *WidgetUpdateOne
Update returns a builder for updating this Widget. Note that you need to call Widget.Unwrap() before calling this method if this Widget was returned from a transaction, and the transaction was committed or rolled back.
type WidgetClient ¶
type WidgetClient struct {
// contains filtered or unexported fields
}
WidgetClient is a client for the Widget schema.
func NewWidgetClient ¶
func NewWidgetClient(c config) *WidgetClient
NewWidgetClient returns a client for the Widget from the given config.
func (*WidgetClient) Create ¶
func (c *WidgetClient) Create() *WidgetCreate
Create returns a builder for creating a Widget entity.
func (*WidgetClient) CreateBulk ¶
func (c *WidgetClient) CreateBulk(builders ...*WidgetCreate) *WidgetCreateBulk
CreateBulk returns a builder for creating a bulk of Widget entities.
func (*WidgetClient) Delete ¶
func (c *WidgetClient) Delete() *WidgetDelete
Delete returns a delete builder for Widget.
func (*WidgetClient) DeleteOne ¶
func (c *WidgetClient) DeleteOne(w *Widget) *WidgetDeleteOne
DeleteOne returns a builder for deleting the given entity.
func (*WidgetClient) DeleteOneID ¶
func (c *WidgetClient) DeleteOneID(id uuid.UUID) *WidgetDeleteOne
DeleteOneID returns a builder for deleting the given entity by its id.
func (*WidgetClient) Intercept ¶
func (c *WidgetClient) Intercept(interceptors ...Interceptor)
Intercept adds a list of query interceptors to the interceptors stack. A call to `Intercept(f, g, h)` equals to `widget.Intercept(f(g(h())))`.
func (*WidgetClient) Interceptors ¶
func (c *WidgetClient) Interceptors() []Interceptor
Interceptors returns the client interceptors.
func (*WidgetClient) MapCreateBulk ¶
func (c *WidgetClient) MapCreateBulk(slice any, setFunc func(*WidgetCreate, int)) *WidgetCreateBulk
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 (*WidgetClient) Query ¶
func (c *WidgetClient) Query() *WidgetQuery
Query returns a query builder for Widget.
func (*WidgetClient) Update ¶
func (c *WidgetClient) Update() *WidgetUpdate
Update returns an update builder for Widget.
func (*WidgetClient) UpdateOne ¶
func (c *WidgetClient) UpdateOne(w *Widget) *WidgetUpdateOne
UpdateOne returns an update builder for the given entity.
func (*WidgetClient) UpdateOneID ¶
func (c *WidgetClient) UpdateOneID(id uuid.UUID) *WidgetUpdateOne
UpdateOneID returns an update builder for the given id.
func (*WidgetClient) Use ¶
func (c *WidgetClient) Use(hooks ...Hook)
Use adds a list of mutation hooks to the hooks stack. A call to `Use(f, g, h)` equals to `widget.Hooks(f(g(h())))`.
type WidgetCreate ¶
type WidgetCreate struct {
// contains filtered or unexported fields
}
WidgetCreate is the builder for creating a Widget entity.
func (*WidgetCreate) Exec ¶
func (wc *WidgetCreate) Exec(ctx context.Context) error
Exec executes the query.
func (*WidgetCreate) ExecX ¶
func (wc *WidgetCreate) ExecX(ctx context.Context)
ExecX is like Exec, but panics if an error occurs.
func (*WidgetCreate) Mutation ¶
func (wc *WidgetCreate) Mutation() *WidgetMutation
Mutation returns the WidgetMutation object of the builder.
func (*WidgetCreate) Save ¶
func (wc *WidgetCreate) Save(ctx context.Context) (*Widget, error)
Save creates the Widget in the database.
func (*WidgetCreate) SaveX ¶
func (wc *WidgetCreate) SaveX(ctx context.Context) *Widget
SaveX calls Save and panics if Save returns an error.
func (*WidgetCreate) SetCreatedAt ¶
func (wc *WidgetCreate) SetCreatedAt(t time.Time) *WidgetCreate
SetCreatedAt sets the "created_at" field.
func (*WidgetCreate) SetDescription ¶
func (wc *WidgetCreate) SetDescription(s string) *WidgetCreate
SetDescription sets the "description" field.
func (*WidgetCreate) SetID ¶
func (wc *WidgetCreate) SetID(u uuid.UUID) *WidgetCreate
SetID sets the "id" field.
func (*WidgetCreate) SetName ¶
func (wc *WidgetCreate) SetName(s string) *WidgetCreate
SetName sets the "name" field.
func (*WidgetCreate) SetNillableCreatedAt ¶
func (wc *WidgetCreate) SetNillableCreatedAt(t *time.Time) *WidgetCreate
SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
func (*WidgetCreate) SetNillableDescription ¶
func (wc *WidgetCreate) SetNillableDescription(s *string) *WidgetCreate
SetNillableDescription sets the "description" field if the given value is not nil.
func (*WidgetCreate) SetNillableID ¶
func (wc *WidgetCreate) SetNillableID(u *uuid.UUID) *WidgetCreate
SetNillableID sets the "id" field if the given value is not nil.
type WidgetCreateBulk ¶
type WidgetCreateBulk struct {
// contains filtered or unexported fields
}
WidgetCreateBulk is the builder for creating many Widget entities in bulk.
func (*WidgetCreateBulk) Exec ¶
func (wcb *WidgetCreateBulk) Exec(ctx context.Context) error
Exec executes the query.
func (*WidgetCreateBulk) ExecX ¶
func (wcb *WidgetCreateBulk) ExecX(ctx context.Context)
ExecX is like Exec, but panics if an error occurs.
type WidgetCreateRequest ¶
type WidgetCreateRequest struct {
Name string `json:"name"`
Description *string `json:"description,omitempty"`
// contains filtered or unexported fields
}
WidgetCreateRequest is the create request for Widget.
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 (*WidgetCreateRequest) HasDescription ¶
func (r *WidgetCreateRequest) HasDescription() bool
HasDescription reports whether the payload carried "description".
func (*WidgetCreateRequest) HasName ¶
func (r *WidgetCreateRequest) HasName() bool
HasName reports whether the payload carried "name".
func (*WidgetCreateRequest) UnmarshalJSON ¶
func (r *WidgetCreateRequest) 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 (*WidgetCreateRequest) Validate ¶
func (r *WidgetCreateRequest) Validate() (*ValidWidgetCreateRequest, error)
Validate checks the request and returns the only type Apply accepts.
type WidgetDelete ¶
type WidgetDelete struct {
// contains filtered or unexported fields
}
WidgetDelete is the builder for deleting a Widget entity.
func (*WidgetDelete) Exec ¶
func (wd *WidgetDelete) Exec(ctx context.Context) (int, error)
Exec executes the deletion query and returns how many vertices were deleted.
func (*WidgetDelete) ExecX ¶
func (wd *WidgetDelete) ExecX(ctx context.Context) int
ExecX is like Exec, but panics if an error occurs.
func (*WidgetDelete) Where ¶
func (wd *WidgetDelete) Where(ps ...predicate.Widget) *WidgetDelete
Where appends a list predicates to the WidgetDelete builder.
type WidgetDeleteOne ¶
type WidgetDeleteOne struct {
// contains filtered or unexported fields
}
WidgetDeleteOne is the builder for deleting a single Widget entity.
func (*WidgetDeleteOne) Exec ¶
func (wdo *WidgetDeleteOne) Exec(ctx context.Context) error
Exec executes the deletion query.
func (*WidgetDeleteOne) ExecX ¶
func (wdo *WidgetDeleteOne) ExecX(ctx context.Context)
ExecX is like Exec, but panics if an error occurs.
func (*WidgetDeleteOne) Where ¶
func (wdo *WidgetDeleteOne) Where(ps ...predicate.Widget) *WidgetDeleteOne
Where appends a list predicates to the WidgetDelete builder.
type WidgetFilter ¶
type WidgetFilter 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"`
}
WidgetFilter is the typed query representation for Widget. Repeated URL parameters occupy repeated slots and Predicates ANDs them.
func ParseWidgetQuery ¶
func ParseWidgetQuery(q url.Values) (*WidgetFilter, entapi.ListRequest, error)
ParseWidgetQuery 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 (*WidgetFilter) Predicates ¶
func (f *WidgetFilter) Predicates() []predicate.Widget
Predicates converts the typed filter into conjunctive ent predicates.
type WidgetGroupBy ¶
type WidgetGroupBy struct {
// contains filtered or unexported fields
}
WidgetGroupBy is the group-by builder for Widget entities.
func (*WidgetGroupBy) Aggregate ¶
func (wgb *WidgetGroupBy) Aggregate(fns ...AggregateFunc) *WidgetGroupBy
Aggregate adds the given aggregation functions to the group-by query.
func (*WidgetGroupBy) Bool ¶
Bool returns a single bool from a selector. It is only allowed when selecting one field.
func (*WidgetGroupBy) Bools ¶
Bools returns list of bools from a selector. It is only allowed when selecting one field.
func (*WidgetGroupBy) Float64 ¶
Float64 returns a single float64 from a selector. It is only allowed when selecting one field.
func (*WidgetGroupBy) Float64s ¶
Float64s returns list of float64s from a selector. It is only allowed when selecting one field.
func (*WidgetGroupBy) Int ¶
Int returns a single int from a selector. It is only allowed when selecting one field.
func (*WidgetGroupBy) Ints ¶
Ints returns list of ints from a selector. It is only allowed when selecting one field.
func (*WidgetGroupBy) Scan ¶
func (wgb *WidgetGroupBy) Scan(ctx context.Context, v any) error
Scan applies the selector query and scans the result into the given value.
func (*WidgetGroupBy) String ¶
String returns a single string from a selector. It is only allowed when selecting one field.
type WidgetListResponse ¶
type WidgetListResponse struct {
Data []*WidgetResponse `json:"data"`
Total int `json:"total"`
Page int `json:"page"`
Size int `json:"size"`
}
WidgetListResponse is the NAMED, non-generic shape of one list page — for OpenAPI/swaggo-class annotation tooling, which cannot express the generic entapi.Page[WidgetResponse] that ListWidgets returns. Convert at the handler boundary with NewWidgetListResponse. (A fifth field, PageInfo, carried cursor metadata until #6 removed it.)
func NewWidgetListResponse ¶
func NewWidgetListResponse(p *entapi.Page[WidgetResponse]) *WidgetListResponse
NewWidgetListResponse converts the page ListWidgets returns into the named list shape. The conversion expression is the shape contract: if WidgetListResponse 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 WidgetMutation ¶
type WidgetMutation struct {
// contains filtered or unexported fields
}
WidgetMutation represents an operation that mutates the Widget nodes in the graph.
func (*WidgetMutation) AddField ¶
func (m *WidgetMutation) 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 (*WidgetMutation) AddedEdges ¶
func (m *WidgetMutation) AddedEdges() []string
AddedEdges returns all edge names that were set/added in this mutation.
func (*WidgetMutation) AddedField ¶
func (m *WidgetMutation) 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 (*WidgetMutation) AddedFields ¶
func (m *WidgetMutation) AddedFields() []string
AddedFields returns all numeric fields that were incremented/decremented during this mutation.
func (*WidgetMutation) AddedIDs ¶
func (m *WidgetMutation) AddedIDs(name string) []ent.Value
AddedIDs returns all IDs (to other nodes) that were added for the given edge name in this mutation.
func (*WidgetMutation) ClearDescription ¶
func (m *WidgetMutation) ClearDescription()
ClearDescription clears the value of the "description" field.
func (*WidgetMutation) ClearEdge ¶
func (m *WidgetMutation) 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 (*WidgetMutation) ClearField ¶
func (m *WidgetMutation) 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 (*WidgetMutation) ClearedEdges ¶
func (m *WidgetMutation) ClearedEdges() []string
ClearedEdges returns all edge names that were cleared in this mutation.
func (*WidgetMutation) ClearedFields ¶
func (m *WidgetMutation) ClearedFields() []string
ClearedFields returns all nullable fields that were cleared during this mutation.
func (WidgetMutation) Client ¶
func (m WidgetMutation) 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 (*WidgetMutation) CreatedAt ¶
func (m *WidgetMutation) CreatedAt() (r time.Time, exists bool)
CreatedAt returns the value of the "created_at" field in the mutation.
func (*WidgetMutation) Description ¶
func (m *WidgetMutation) Description() (r string, exists bool)
Description returns the value of the "description" field in the mutation.
func (*WidgetMutation) DescriptionCleared ¶
func (m *WidgetMutation) DescriptionCleared() bool
DescriptionCleared returns if the "description" field was cleared in this mutation.
func (*WidgetMutation) EdgeCleared ¶
func (m *WidgetMutation) EdgeCleared(name string) bool
EdgeCleared returns a boolean which indicates if the edge with the given name was cleared in this mutation.
func (*WidgetMutation) Field ¶
func (m *WidgetMutation) 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 (*WidgetMutation) FieldCleared ¶
func (m *WidgetMutation) FieldCleared(name string) bool
FieldCleared returns a boolean indicating if a field with the given name was cleared in this mutation.
func (*WidgetMutation) Fields ¶
func (m *WidgetMutation) 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 (*WidgetMutation) ID ¶
func (m *WidgetMutation) 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 (*WidgetMutation) 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 (*WidgetMutation) Name ¶
func (m *WidgetMutation) Name() (r string, exists bool)
Name returns the value of the "name" field in the mutation.
func (*WidgetMutation) OldCreatedAt ¶
OldCreatedAt returns the old "created_at" field's value of the Widget entity. If the Widget 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 (*WidgetMutation) OldDescription ¶
func (m *WidgetMutation) OldDescription(ctx context.Context) (v string, err error)
OldDescription returns the old "description" field's value of the Widget entity. If the Widget 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 (*WidgetMutation) 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 (*WidgetMutation) OldName ¶
func (m *WidgetMutation) OldName(ctx context.Context) (v string, err error)
OldName returns the old "name" field's value of the Widget entity. If the Widget 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 (*WidgetMutation) RemovedEdges ¶
func (m *WidgetMutation) RemovedEdges() []string
RemovedEdges returns all edge names that were removed in this mutation.
func (*WidgetMutation) RemovedIDs ¶
func (m *WidgetMutation) 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 (*WidgetMutation) ResetCreatedAt ¶
func (m *WidgetMutation) ResetCreatedAt()
ResetCreatedAt resets all changes to the "created_at" field.
func (*WidgetMutation) ResetDescription ¶
func (m *WidgetMutation) ResetDescription()
ResetDescription resets all changes to the "description" field.
func (*WidgetMutation) ResetEdge ¶
func (m *WidgetMutation) 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 (*WidgetMutation) ResetField ¶
func (m *WidgetMutation) 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 (*WidgetMutation) ResetName ¶
func (m *WidgetMutation) ResetName()
ResetName resets all changes to the "name" field.
func (*WidgetMutation) SetCreatedAt ¶
func (m *WidgetMutation) SetCreatedAt(t time.Time)
SetCreatedAt sets the "created_at" field.
func (*WidgetMutation) SetDescription ¶
func (m *WidgetMutation) SetDescription(s string)
SetDescription sets the "description" field.
func (*WidgetMutation) SetField ¶
func (m *WidgetMutation) 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 (*WidgetMutation) SetID ¶
func (m *WidgetMutation) SetID(id uuid.UUID)
SetID sets the value of the id field. Note that this operation is only accepted on creation of Widget entities.
func (*WidgetMutation) SetName ¶
func (m *WidgetMutation) SetName(s string)
SetName sets the "name" field.
func (*WidgetMutation) SetOp ¶
func (m *WidgetMutation) SetOp(op Op)
SetOp allows setting the mutation operation.
func (WidgetMutation) Tx ¶
func (m WidgetMutation) Tx() (*Tx, error)
Tx returns an `ent.Tx` for mutations that were executed in transactions; it returns an error otherwise.
func (*WidgetMutation) Type ¶
func (m *WidgetMutation) Type() string
Type returns the node type of this mutation (Widget).
func (*WidgetMutation) Where ¶
func (m *WidgetMutation) Where(ps ...predicate.Widget)
Where appends a list predicates to the WidgetMutation builder.
func (*WidgetMutation) WhereP ¶
func (m *WidgetMutation) WhereP(ps ...func(*sql.Selector))
WhereP appends storage-level predicates to the WidgetMutation builder. Using this method, users can use type-assertion to append predicates that do not depend on any generated package.
type WidgetPatchRequest ¶
type WidgetPatchRequest struct {
Name *string `json:"name,omitempty"`
Description *string `json:"description,omitempty"`
// contains filtered or unexported fields
}
WidgetPatchRequest is the partial-update request for Widget.
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 (*WidgetPatchRequest) HasDescription ¶
func (r *WidgetPatchRequest) HasDescription() bool
HasDescription reports whether the payload carried "description".
func (*WidgetPatchRequest) HasName ¶
func (r *WidgetPatchRequest) HasName() bool
HasName reports whether the payload carried "name".
func (*WidgetPatchRequest) UnmarshalJSON ¶
func (r *WidgetPatchRequest) 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 (*WidgetPatchRequest) Validate ¶
func (r *WidgetPatchRequest) Validate() (*ValidWidgetPatchRequest, 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 WidgetQuery ¶
type WidgetQuery struct {
// contains filtered or unexported fields
}
WidgetQuery is the builder for querying Widget entities.
func WidgetQueryWithResponseEdges ¶
func WidgetQueryWithResponseEdges(q *WidgetQuery) *WidgetQuery
WidgetQueryWithResponseEdges applies the eager-load plan for WidgetResponse.
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 NewWidgetResponse return a not-loaded-edge error at run time. It fails loudly; it never silently narrows the response.
With no expanded edges, this function is the identity function. It exists so every entity has the same call shape.
func (*WidgetQuery) Aggregate ¶
func (wq *WidgetQuery) Aggregate(fns ...AggregateFunc) *WidgetSelect
Aggregate returns a WidgetSelect configured with the given aggregations.
func (*WidgetQuery) All ¶
func (wq *WidgetQuery) All(ctx context.Context) ([]*Widget, error)
All executes the query and returns a list of Widgets.
func (*WidgetQuery) AllX ¶
func (wq *WidgetQuery) AllX(ctx context.Context) []*Widget
AllX is like All, but panics if an error occurs.
func (*WidgetQuery) Clone ¶
func (wq *WidgetQuery) Clone() *WidgetQuery
Clone returns a duplicate of the WidgetQuery builder, including all associated steps. It can be used to prepare common query builders and use them differently after the clone is made.
func (*WidgetQuery) Count ¶
func (wq *WidgetQuery) Count(ctx context.Context) (int, error)
Count returns the count of the given query.
func (*WidgetQuery) CountX ¶
func (wq *WidgetQuery) CountX(ctx context.Context) int
CountX is like Count, but panics if an error occurs.
func (*WidgetQuery) Exist ¶
func (wq *WidgetQuery) Exist(ctx context.Context) (bool, error)
Exist returns true if the query has elements in the graph.
func (*WidgetQuery) ExistX ¶
func (wq *WidgetQuery) ExistX(ctx context.Context) bool
ExistX is like Exist, but panics if an error occurs.
func (*WidgetQuery) First ¶
func (wq *WidgetQuery) First(ctx context.Context) (*Widget, error)
First returns the first Widget entity from the query. Returns a *NotFoundError when no Widget was found.
func (*WidgetQuery) FirstID ¶
FirstID returns the first Widget ID from the query. Returns a *NotFoundError when no Widget ID was found.
func (*WidgetQuery) FirstIDX ¶
func (wq *WidgetQuery) FirstIDX(ctx context.Context) uuid.UUID
FirstIDX is like FirstID, but panics if an error occurs.
func (*WidgetQuery) FirstX ¶
func (wq *WidgetQuery) FirstX(ctx context.Context) *Widget
FirstX is like First, but panics if an error occurs.
func (*WidgetQuery) GroupBy ¶
func (wq *WidgetQuery) GroupBy(field string, fields ...string) *WidgetGroupBy
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 {
Name string `json:"name,omitempty"`
Count int `json:"count,omitempty"`
}
client.Widget.Query().
GroupBy(widget.FieldName).
Aggregate(basicent.Count()).
Scan(ctx, &v)
func (*WidgetQuery) IDsX ¶
func (wq *WidgetQuery) IDsX(ctx context.Context) []uuid.UUID
IDsX is like IDs, but panics if an error occurs.
func (*WidgetQuery) Limit ¶
func (wq *WidgetQuery) Limit(limit int) *WidgetQuery
Limit the number of records to be returned by this query.
func (*WidgetQuery) Offset ¶
func (wq *WidgetQuery) Offset(offset int) *WidgetQuery
Offset to start from.
func (*WidgetQuery) Only ¶
func (wq *WidgetQuery) Only(ctx context.Context) (*Widget, error)
Only returns a single Widget entity found by the query, ensuring it only returns one. Returns a *NotSingularError when more than one Widget entity is found. Returns a *NotFoundError when no Widget entities are found.
func (*WidgetQuery) OnlyID ¶
OnlyID is like Only, but returns the only Widget ID in the query. Returns a *NotSingularError when more than one Widget ID is found. Returns a *NotFoundError when no entities are found.
func (*WidgetQuery) OnlyIDX ¶
func (wq *WidgetQuery) OnlyIDX(ctx context.Context) uuid.UUID
OnlyIDX is like OnlyID, but panics if an error occurs.
func (*WidgetQuery) OnlyX ¶
func (wq *WidgetQuery) OnlyX(ctx context.Context) *Widget
OnlyX is like Only, but panics if an error occurs.
func (*WidgetQuery) Order ¶
func (wq *WidgetQuery) Order(o ...widget.OrderOption) *WidgetQuery
Order specifies how the records should be ordered.
func (*WidgetQuery) Select ¶
func (wq *WidgetQuery) Select(fields ...string) *WidgetSelect
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 {
Name string `json:"name,omitempty"`
}
client.Widget.Query().
Select(widget.FieldName).
Scan(ctx, &v)
func (*WidgetQuery) Unique ¶
func (wq *WidgetQuery) Unique(unique bool) *WidgetQuery
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 (*WidgetQuery) Where ¶
func (wq *WidgetQuery) Where(ps ...predicate.Widget) *WidgetQuery
Where adds a new predicate for the WidgetQuery builder.
type WidgetResponse ¶
type WidgetResponse struct {
// ID field is always included in responses
ID uuid.UUID `json:"id"`
Name string `json:"name"`
Description *string `json:"description,omitempty"`
CreatedAt time.Time `json:"created_at"`
}
WidgetResponse represents the response for Widget.
It is emitted unconditionally: an entity whose every scalar field is Sensitive still has a meaningful response carrying its ID, and WidgetListResponse below refers to this type either way.
func CreateWidget ¶
func CreateWidget(ctx context.Context, db *Client, v *ValidWidgetCreateRequest) (*WidgetResponse, error)
CreateWidget inserts one Widget 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 NewWidgetResponse ¶
func NewWidgetResponse(e *Widget) (*WidgetResponse, error)
NewWidgetResponse converts an entity to its response DTO.
This entity declares no response edges, so the error is always nil. The signature is kept uniform so callers do not need two shapes.
func PatchWidget ¶
func PatchWidget(ctx context.Context, db *Client, id uuid.UUID, v *ValidWidgetPatchRequest) (*WidgetResponse, error)
PatchWidget applies a validated patch to one Widget.
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 WidgetSelect ¶
type WidgetSelect struct {
*WidgetQuery
// contains filtered or unexported fields
}
WidgetSelect is the builder for selecting fields of Widget entities.
func (*WidgetSelect) Aggregate ¶
func (ws *WidgetSelect) Aggregate(fns ...AggregateFunc) *WidgetSelect
Aggregate adds the given aggregation functions to the selector query.
func (*WidgetSelect) Bool ¶
Bool returns a single bool from a selector. It is only allowed when selecting one field.
func (*WidgetSelect) Bools ¶
Bools returns list of bools from a selector. It is only allowed when selecting one field.
func (*WidgetSelect) Float64 ¶
Float64 returns a single float64 from a selector. It is only allowed when selecting one field.
func (*WidgetSelect) Float64s ¶
Float64s returns list of float64s from a selector. It is only allowed when selecting one field.
func (*WidgetSelect) Int ¶
Int returns a single int from a selector. It is only allowed when selecting one field.
func (*WidgetSelect) Ints ¶
Ints returns list of ints from a selector. It is only allowed when selecting one field.
func (*WidgetSelect) Scan ¶
func (ws *WidgetSelect) Scan(ctx context.Context, v any) error
Scan applies the selector query and scans the result into the given value.
func (*WidgetSelect) String ¶
String returns a single string from a selector. It is only allowed when selecting one field.
type WidgetSummary ¶
type WidgetSummary struct {
// ID field is always included in summaries
ID uuid.UUID `json:"id"`
Name string `json:"name"`
Description *string `json:"description,omitempty"`
CreatedAt time.Time `json:"created_at"`
}
WidgetSummary is the shape Widget takes on another entity's response.
It carries the same scalar fields as WidgetResponse and no edges at all. That is what bounds expansion: NewWidgetResponse 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 NewWidgetSummary ¶
func NewWidgetSummary(e *Widget) *WidgetSummary
NewWidgetSummary converts an entity to its summary DTO. It cannot fail: a summary reads no edges.
type WidgetUpdate ¶
type WidgetUpdate struct {
// contains filtered or unexported fields
}
WidgetUpdate is the builder for updating Widget entities.
func (*WidgetUpdate) ClearDescription ¶
func (wu *WidgetUpdate) ClearDescription() *WidgetUpdate
ClearDescription clears the value of the "description" field.
func (*WidgetUpdate) Exec ¶
func (wu *WidgetUpdate) Exec(ctx context.Context) error
Exec executes the query.
func (*WidgetUpdate) ExecX ¶
func (wu *WidgetUpdate) ExecX(ctx context.Context)
ExecX is like Exec, but panics if an error occurs.
func (*WidgetUpdate) Mutation ¶
func (wu *WidgetUpdate) Mutation() *WidgetMutation
Mutation returns the WidgetMutation object of the builder.
func (*WidgetUpdate) Save ¶
func (wu *WidgetUpdate) Save(ctx context.Context) (int, error)
Save executes the query and returns the number of nodes affected by the update operation.
func (*WidgetUpdate) SaveX ¶
func (wu *WidgetUpdate) SaveX(ctx context.Context) int
SaveX is like Save, but panics if an error occurs.
func (*WidgetUpdate) SetDescription ¶
func (wu *WidgetUpdate) SetDescription(s string) *WidgetUpdate
SetDescription sets the "description" field.
func (*WidgetUpdate) SetName ¶
func (wu *WidgetUpdate) SetName(s string) *WidgetUpdate
SetName sets the "name" field.
func (*WidgetUpdate) SetNillableDescription ¶
func (wu *WidgetUpdate) SetNillableDescription(s *string) *WidgetUpdate
SetNillableDescription sets the "description" field if the given value is not nil.
func (*WidgetUpdate) SetNillableName ¶
func (wu *WidgetUpdate) SetNillableName(s *string) *WidgetUpdate
SetNillableName sets the "name" field if the given value is not nil.
func (*WidgetUpdate) Where ¶
func (wu *WidgetUpdate) Where(ps ...predicate.Widget) *WidgetUpdate
Where appends a list predicates to the WidgetUpdate builder.
type WidgetUpdateOne ¶
type WidgetUpdateOne struct {
// contains filtered or unexported fields
}
WidgetUpdateOne is the builder for updating a single Widget entity.
func (*WidgetUpdateOne) ClearDescription ¶
func (wuo *WidgetUpdateOne) ClearDescription() *WidgetUpdateOne
ClearDescription clears the value of the "description" field.
func (*WidgetUpdateOne) Exec ¶
func (wuo *WidgetUpdateOne) Exec(ctx context.Context) error
Exec executes the query on the entity.
func (*WidgetUpdateOne) ExecX ¶
func (wuo *WidgetUpdateOne) ExecX(ctx context.Context)
ExecX is like Exec, but panics if an error occurs.
func (*WidgetUpdateOne) Mutation ¶
func (wuo *WidgetUpdateOne) Mutation() *WidgetMutation
Mutation returns the WidgetMutation object of the builder.
func (*WidgetUpdateOne) Save ¶
func (wuo *WidgetUpdateOne) Save(ctx context.Context) (*Widget, error)
Save executes the query and returns the updated Widget entity.
func (*WidgetUpdateOne) SaveX ¶
func (wuo *WidgetUpdateOne) SaveX(ctx context.Context) *Widget
SaveX is like Save, but panics if an error occurs.
func (*WidgetUpdateOne) Select ¶
func (wuo *WidgetUpdateOne) Select(field string, fields ...string) *WidgetUpdateOne
Select allows selecting one or more fields (columns) of the returned entity. The default is selecting all fields defined in the entity schema.
func (*WidgetUpdateOne) SetDescription ¶
func (wuo *WidgetUpdateOne) SetDescription(s string) *WidgetUpdateOne
SetDescription sets the "description" field.
func (*WidgetUpdateOne) SetName ¶
func (wuo *WidgetUpdateOne) SetName(s string) *WidgetUpdateOne
SetName sets the "name" field.
func (*WidgetUpdateOne) SetNillableDescription ¶
func (wuo *WidgetUpdateOne) SetNillableDescription(s *string) *WidgetUpdateOne
SetNillableDescription sets the "description" field if the given value is not nil.
func (*WidgetUpdateOne) SetNillableName ¶
func (wuo *WidgetUpdateOne) SetNillableName(s *string) *WidgetUpdateOne
SetNillableName sets the "name" field if the given value is not nil.
func (*WidgetUpdateOne) Where ¶
func (wuo *WidgetUpdateOne) Where(ps ...predicate.Widget) *WidgetUpdateOne
Where appends a list predicates to the WidgetUpdate builder.