Documentation
¶
Overview ¶
Package ent is the interface between end-user schemas and entc (ent codegen).
Index ¶
- Constants
- Variables
- func Get[T any](row *Row, selection SelectionOf[T]) T
- func GetNullable[T any](row *Row, selection SelectionOf[T]) (T, bool)
- func IsConstraintError(err error) bool
- func IsNotFound(err error) bool
- func IsNotSingular(err error) bool
- func IsValidationError(err error) bool
- func SelectColumns(selector *sql.Selector, selections ...Selection)
- func Values[T any](ctx context.Context, query RowsQuerier, selection SelectionOf[T]) ([]T, error)
- func ValuesNullable[T any](ctx context.Context, query RowsQuerier, selection SelectionOf[T]) ([]*T, error)
- type ArrayColumn
- func (c ArrayColumn[E, T]) Contains(value any) Predicate[E]
- func (c ArrayColumn[E, T]) HasAll(values ...any) Predicate[E]
- func (c ArrayColumn[E, T]) HasAny(values ...any) Predicate[E]
- func (c ArrayColumn[E, T]) LenEQ(length int) Predicate[E]
- func (c ArrayColumn[E, T]) LenGT(length int) Predicate[E]
- func (c ArrayColumn[E, T]) LenGTE(length int) Predicate[E]
- func (c ArrayColumn[E, T]) LenLT(length int) Predicate[E]
- func (c ArrayColumn[E, T]) LenLTE(length int) Predicate[E]
- func (c ArrayColumn[E, T]) LenNEQ(length int) Predicate[E]
- type Column
- func (c Column[E, T]) Alias() string
- func (c Column[E, T]) As(alias string) SelectionOf[T]
- func (c Column[E, T]) Asc(options ...sql.OrderTermOption) OrderOption[E]
- func (c Column[E, T]) Desc(options ...sql.OrderTermOption) OrderOption[E]
- func (c Column[E, T]) EQ(value T) Predicate[E]
- func (c Column[E, T]) EQColumn(other SelectionOf[T]) Predicate[E]
- func (c Column[E, T]) EQExpr(expression Expr[T]) Predicate[E]
- func (c Column[E, T]) Expr() Expr[T]
- func (c Column[E, T]) In(values ...T) Predicate[E]
- func (c Column[E, T]) IsNull() Predicate[E]
- func (c Column[E, T]) NEQ(value T) Predicate[E]
- func (c Column[E, T]) NEQColumn(other SelectionOf[T]) Predicate[E]
- func (c Column[E, T]) NEQExpr(expression Expr[T]) Predicate[E]
- func (c Column[E, T]) NotIn(values ...T) Predicate[E]
- func (c Column[E, T]) NotNull() Predicate[E]
- func (c Column[E, T]) Nullable() SelectionOf[T]
- func (c Column[E, T]) Ref() ColumnRef
- func (c Column[E, T]) Term(options ...sql.OrderTermOption) *sql.OrderFieldTerm
- type ColumnOf
- type ColumnRef
- type Configdeprecated
- type Edge
- type EntityColumn
- type Expr
- func Add[T Number](left, right Expr[T]) Expr[T]
- func Coalesce[T any](expressions ...Expr[T]) Expr[T]
- func Excluded[E, T any](column ColumnOf[E, T]) Expr[T]
- func ExprFunc[T any](render func(*sql.Builder)) Expr[T]
- func Literal[T any](value T) Expr[T]
- func Mul[T Number](left, right Expr[T]) Expr[T]
- func Sub[T Number](left, right Expr[T]) Expr[T]
- func (e Expr[T]) EQ(value T) PredicateFunc
- func (e Expr[T]) GT(value T) PredicateFunc
- func (e Expr[T]) GTE(value T) PredicateFunc
- func (e Expr[T]) LT(value T) PredicateFunc
- func (e Expr[T]) LTE(value T) PredicateFunc
- func (e Expr[T]) NEQ(value T) PredicateFunc
- func (e Expr[T]) Render(builder *sql.Builder)
- type Field
- type Index
- type Interface
- type JSONColumn
- type JSONPath
- type Mixin
- type Mutation
- type NotFoundError
- type NotSingularError
- type Number
- type Op
- type Option
- func (o Option[T]) Get() (T, bool)
- func (o Option[T]) IsNull() bool
- func (o Option[T]) IsSet() bool
- func (o Option[T]) IsUnset() bool
- func (o Option[T]) IsZero() bool
- func (o Option[T]) MarshalJSON() ([]byte, error)
- func (o Option[T]) MustGet() T
- func (o Option[T]) Or(fallback T) T
- func (o Option[T]) Ptr() *T
- func (o Option[T]) String() string
- func (o *Option[T]) UnmarshalJSON(data []byte) error
- type OrderOption
- type OrderedColumn
- type Predicate
- type PredicateFunc
- type Query
- type QueryContext
- type Relation
- func (e Relation[E, N, K]) Has() Predicate[E]
- func (e Relation[E, N, K]) HasWith(predicates ...Predicate[N]) Predicate[E]
- func (e Relation[E, N, K]) OrderBy(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption[E]
- func (e Relation[E, N, K]) OrderByCount(options ...sql.OrderTermOption) OrderOption[E]
- type RelationOf
- type RelationPatch
- type RelationRef
- type Row
- type RowsQuerier
- type Schema
- type Selection
- type SelectionOf
- func Avg[E any, T Number](column ColumnOf[E, T]) SelectionOf[float64]
- func Count() SelectionOf[int]
- func CountColumn[E, T any](column ColumnOf[E, T]) SelectionOf[int]
- func ExprSelection[T any](expression Expr[T], alias string) SelectionOf[T]
- func Max[E, T any](column ColumnOf[E, T]) SelectionOf[T]
- func Min[E, T any](column ColumnOf[E, T]) SelectionOf[T]
- func Sum[E any, T Number](column ColumnOf[E, T]) SelectionOf[T]
- type StringColumn
- func (c StringColumn[E, T]) Contains(substring string) Predicate[E]
- func (c StringColumn[E, T]) ContainsFold(substring string) Predicate[E]
- func (c StringColumn[E, T]) EqualFold(value string) Predicate[E]
- func (c StringColumn[E, T]) HasPrefix(prefix string) Predicate[E]
- func (c StringColumn[E, T]) HasSuffix(suffix string) Predicate[E]
- type UniqueRelation
- type ValidationError
- type View
- type Viewer
Constants ¶
const ( OpQueryFirst = "First" OpQueryFirstID = "FirstID" OpQueryOnly = "Only" OpQueryOnlyID = "OnlyID" OpQueryAll = "All" OpQueryIDs = "IDs" OpQueryCount = "Count" OpQueryExist = "Exist" OpQueryGroupBy = "GroupBy" OpQuerySelect = "Select" )
List of query operations used by the codegen.
Variables ¶
var ErrConflict = errors.New("ent: conflict")
ErrConflict is returned when an upsert's DoNothing action encounters an existing row.
Functions ¶
func Get ¶ added in v0.3.0
func Get[T any](row *Row, selection SelectionOf[T]) T
Get returns a selected value. It panics if the selection is absent, has the wrong type, or holds SQL NULL. Use GetNullable for a potentially NULL selection.
func GetNullable ¶ added in v0.3.0
func GetNullable[T any](row *Row, selection SelectionOf[T]) (T, bool)
GetNullable returns a selected value and false for SQL NULL. Ordinary *T scan destinations always return true, even for zero values. Missing selections and incompatible value types panic rather than silently returning zero values.
func IsConstraintError ¶ added in v0.3.0
IsConstraintError reports whether err wraps a driver's constraint violation.
func IsNotFound ¶ added in v0.3.0
IsNotFound reports whether err wraps a NotFoundError.
func IsNotSingular ¶ added in v0.3.0
IsNotSingular reports whether err wraps a NotSingularError.
func IsValidationError ¶ added in v0.3.0
IsValidationError reports whether err wraps a ValidationError.
func SelectColumns ¶ added in v0.3.0
SelectColumns applies typed selections without losing bound expression arguments.
func Values ¶ added in v0.3.0
func Values[T any](ctx context.Context, query RowsQuerier, selection SelectionOf[T]) ([]T, error)
Values extracts a selection from every result row.
func ValuesNullable ¶ added in v0.3.0
func ValuesNullable[T any](ctx context.Context, query RowsQuerier, selection SelectionOf[T]) ([]*T, error)
ValuesNullable preserves SQL NULL as a nil pointer.
Types ¶
type ArrayColumn ¶ added in v0.3.0
ArrayColumn describes a native PostgreSQL array or a SQLite JSON array. T is the entire stored value (for example, []string), not its element type. Membership arguments are untyped because T does not constrain the element type.
func (ArrayColumn[E, T]) Contains ¶ added in v0.3.0
func (c ArrayColumn[E, T]) Contains(value any) Predicate[E]
Contains tests for an array element. NULL elements do not match.
func (ArrayColumn[E, T]) HasAll ¶ added in v0.3.0
func (c ArrayColumn[E, T]) HasAll(values ...any) Predicate[E]
HasAll tests array containment. An empty list matches every non-null array. Duplicates are ignored, matching PostgreSQL array containment semantics.
func (ArrayColumn[E, T]) HasAny ¶ added in v0.3.0
func (c ArrayColumn[E, T]) HasAny(values ...any) Predicate[E]
HasAny tests array overlap. An empty argument list matches no non-null arrays.
func (ArrayColumn[E, T]) LenEQ ¶ added in v0.3.0
func (c ArrayColumn[E, T]) LenEQ(length int) Predicate[E]
LenEQ tests equality to the array's element count.
func (ArrayColumn[E, T]) LenGT ¶ added in v0.3.0
func (c ArrayColumn[E, T]) LenGT(length int) Predicate[E]
LenGT tests whether the array has more than length elements.
func (ArrayColumn[E, T]) LenGTE ¶ added in v0.3.0
func (c ArrayColumn[E, T]) LenGTE(length int) Predicate[E]
LenGTE tests whether the array has at least length elements.
func (ArrayColumn[E, T]) LenLT ¶ added in v0.3.0
func (c ArrayColumn[E, T]) LenLT(length int) Predicate[E]
LenLT tests whether the array has fewer than length elements.
func (ArrayColumn[E, T]) LenLTE ¶ added in v0.3.0
func (c ArrayColumn[E, T]) LenLTE(length int) Predicate[E]
LenLTE tests whether the array has at most length elements.
func (ArrayColumn[E, T]) LenNEQ ¶ added in v0.3.0
func (c ArrayColumn[E, T]) LenNEQ(length int) Predicate[E]
LenNEQ tests inequality to the array's element count.
type Column ¶ added in v0.3.0
type Column[E, T any] struct { ColumnRef // Valuer converts a Go value to its database representation, when needed. Valuer func(T) (driver.Value, error) }
Column describes a column with entity type E and stored value type T.
func (Column[E, T]) As ¶ added in v0.3.0
func (c Column[E, T]) As(alias string) SelectionOf[T]
As gives a projected column a unique output alias while retaining its value type.
func (Column[E, T]) Asc ¶ added in v0.3.0
func (c Column[E, T]) Asc(options ...sql.OrderTermOption) OrderOption[E]
Asc orders ascending; options may request NULLS FIRST or NULLS LAST.
func (Column[E, T]) Desc ¶ added in v0.3.0
func (c Column[E, T]) Desc(options ...sql.OrderTermOption) OrderOption[E]
Desc orders descending; options may request NULLS FIRST or NULLS LAST.
func (Column[E, T]) EQ ¶ added in v0.3.0
EQ tests equality to a stored value, including when T is nillable. Use IsNull to test SQL NULL rather than equality to a nil value.
func (Column[E, T]) EQColumn ¶ added in v0.3.0
func (c Column[E, T]) EQColumn(other SelectionOf[T]) Predicate[E]
EQColumn compares columns with matching value types, including across tables.
func (Column[E, T]) EQExpr ¶ added in v0.3.0
EQExpr compares the column to an expression with the same value type.
func (Column[E, T]) Expr ¶ added in v0.3.0
Expr returns the column as a typed expression. Inside predicates, an empty Table resolves against the selector; standalone rendering leaves it unqualified.
func (Column[E, T]) In ¶ added in v0.3.0
In tests membership in a set of values. An empty set matches nothing.
func (Column[E, T]) NEQColumn ¶ added in v0.3.0
func (c Column[E, T]) NEQColumn(other SelectionOf[T]) Predicate[E]
NEQColumn compares columns for inequality.
func (Column[E, T]) NEQExpr ¶ added in v0.3.0
NEQExpr compares the column to an expression for inequality.
func (Column[E, T]) NotIn ¶ added in v0.3.0
NotIn excludes a set of values. An empty set excludes nothing.
func (Column[E, T]) Nullable ¶ added in v0.3.0
func (c Column[E, T]) Nullable() SelectionOf[T]
Nullable allocates **T for scanning a potentially NULL column, such as a left join. A nil *T represents SQL NULL; a non-nil pointer contains the stored T value.
func (Column[E, T]) Term ¶ added in v0.3.0
func (c Column[E, T]) Term(options ...sql.OrderTermOption) *sql.OrderFieldTerm
Term returns an ordering term for an edge's neighbor columns.
type ColumnOf ¶ added in v0.3.0
ColumnOf accepts every column kind with the same entity and value types.
type ColumnRef ¶ added in v0.3.0
ColumnRef is the dialect-independent identity of a column. An empty Table means the current selector's table.
type Config
deprecated
type Config struct {
// A Table is an optional table name defined for the schema.
Table string
}
A Config structure is used to configure an entity schema. The usage of this structure is as follows:
func (T) Config() ent.Config {
return ent.Config{
Table: "Name",
}
}
Deprecated: the Config object predates the schema.Annotation method and it is planned to be removed in future versions. New code should use Annotations instead.
func (T) Annotations() []schema.Annotation {
return []schema.Annotation{
entsql.Annotation{Table: "Name"},
}
}
type Edge ¶
type Edge interface {
Descriptor() *edge.Descriptor
}
A Edge interface returns an edge descriptor for vertex edges. The usage for the interface is as follows:
func (T) Edges() []ent.Edge {
return []ent.Edge{
edge.To("S", S.Type),
}
}
type EntityColumn ¶ added in v0.3.0
EntityColumn accepts every column kind belonging to entity E.
type Expr ¶ added in v0.3.0
type Expr[T any] struct { // contains filtered or unexported fields }
Expr is a SQL expression with a result type. Values should be constructed with ExprFunc, Literal, column methods, or the expression combinators.
func Coalesce ¶ added in v0.3.0
Coalesce returns the first non-null expression. At least one is required.
func ExprFunc ¶ added in v0.3.0
ExprFunc wraps a SQL renderer. Bind external values with Builder.Arg.
func (Expr[T]) EQ ¶ added in v0.3.0
func (e Expr[T]) EQ(value T) PredicateFunc
EQ compares an expression to a value for equality.
func (Expr[T]) GT ¶ added in v0.3.0
func (e Expr[T]) GT(value T) PredicateFunc
GT tests whether an expression is greater than a value.
func (Expr[T]) GTE ¶ added in v0.3.0
func (e Expr[T]) GTE(value T) PredicateFunc
GTE tests whether an expression is greater than or equal to a value.
func (Expr[T]) LT ¶ added in v0.3.0
func (e Expr[T]) LT(value T) PredicateFunc
LT tests whether an expression is less than a value.
func (Expr[T]) LTE ¶ added in v0.3.0
func (e Expr[T]) LTE(value T) PredicateFunc
LTE tests whether an expression is less than or equal to a value.
func (Expr[T]) NEQ ¶ added in v0.3.0
func (e Expr[T]) NEQ(value T) PredicateFunc
NEQ compares an expression to a value for inequality.
type Field ¶
type Field interface {
Descriptor() *field.Descriptor
}
A Field interface returns a field descriptor for vertex fields/properties. The usage for the interface is as follows:
func (T) Fields() []ent.Field {
return []ent.Field{
field.Int("int"),
}
}
type Index ¶
type Index interface {
Descriptor() *index.Descriptor
}
An Index interface returns an index descriptor for vertex indexes. The usage for the interface is as follows:
func (T) Indexes() []ent.Index {
return []ent.Index{
index.Fields("f1", "f2").
Unique(),
}
}
type Interface ¶
type Interface interface {
// Type is a dummy method, that is used in edge declaration.
//
// The Type method should be used as follows:
//
// type S struct { ent.Schema }
//
// type T struct { ent.Schema }
//
// func (T) Edges() []ent.Edge {
// return []ent.Edge{
// edge.To("S", S.Type),
// }
// }
//
Type()
// Fields returns the fields of the schema.
Fields() []Field
// Edges returns the edges of the schema.
Edges() []Edge
// Indexes returns the indexes of the schema.
Indexes() []Index
// Config returns an optional config for the schema.
//
// Deprecated: the Config method predates the Annotations method, and it
// is planned be removed in v0.5.0. New code should use Annotations instead.
//
// func (T) Annotations() []schema.Annotation {
// return []schema.Annotation{
// entsql.Annotation{Table: "Name"},
// }
// }
//
Config() Config
// Mixin returns an optional list of Mixin to extends
// the schema.
Mixin() []Mixin
// Annotations returns a list of schema annotations to be used by
// codegen extensions.
Annotations() []schema.Annotation
}
The Interface type describes the requirements for an exported type defined in the schema package. It functions as the interface between the user's schema types and codegen loader. Users should use the Schema type for embedding as follows:
type T struct {
ent.Schema
}
type JSONColumn ¶ added in v0.3.0
JSONColumn describes a JSON document and supports predicates on its paths.
func (JSONColumn[E, T]) Path ¶ added in v0.3.0
func (c JSONColumn[E, T]) Path(path ...string) JSONPath[E]
Path selects JSON object keys or array indexes as supported by sqljson.Path.
type JSONPath ¶ added in v0.3.0
type JSONPath[E any] struct { // contains filtered or unexported fields }
JSONPath identifies a path within an entity's JSON column.
type Mixin ¶
type Mixin interface {
// Fields returns a slice of fields to add to the schema.
Fields() []Field
// Edges returns a slice of edges to add to the schema.
Edges() []Edge
// Indexes returns a slice of indexes to add to the schema.
Indexes() []Index
// Annotations returns a list of schema annotations to add
// to the schema annotations.
Annotations() []schema.Annotation
}
The Mixin type describes a set of methods that can extend other methods in the schema without calling them directly.
type TimeMixin struct {}
func (TimeMixin) Fields() []ent.Field {
return []ent.Field{
field.Time("created_at").
Immutable().
Default(time.Now),
field.Time("updated_at").
Default(time.Now).
UpdateDefault(time.Now),
}
}
type T struct {
ent.Schema
}
func(T) Mixin() []ent.Mixin {
return []ent.Mixin{
TimeMixin{},
}
}
type NotFoundError ¶ added in v0.3.0
type NotFoundError struct{ Label string }
NotFoundError indicates that a query requiring an entity found no rows.
func (*NotFoundError) Error ¶ added in v0.3.0
func (e *NotFoundError) Error() string
type NotSingularError ¶ added in v0.3.0
type NotSingularError struct{ Label string }
NotSingularError indicates that a query requiring one entity found multiple rows.
func (*NotSingularError) Error ¶ added in v0.3.0
func (e *NotSingularError) Error() string
type Number ¶ added in v0.3.0
type Number interface {
~int | ~int8 | ~int16 | ~int32 | ~int64 |
~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr |
~float32 | ~float64
}
Number permits arithmetic on built-in and named numeric types.
type Op ¶
type Op uint
An Op represents a mutation operation.
type Option ¶ added in v0.3.0
type Option[T any] struct { // contains filtered or unexported fields }
Option distinguishes an omitted value, a present value, and an explicit NULL. Its zero value is unset. Use json:",omitzero" to omit unset struct fields.
func (Option[T]) Get ¶ added in v0.3.0
Get returns the value and whether it is present and non-null.
func (Option[T]) IsSet ¶ added in v0.3.0
IsSet reports whether the option contains a value or explicit null.
func (Option[T]) IsZero ¶ added in v0.3.0
IsZero permits encoding/json to omit only unset options with omitzero.
func (Option[T]) MarshalJSON ¶ added in v0.3.0
MarshalJSON encodes unset and null as null, and a present value as itself.
func (Option[T]) MustGet ¶ added in v0.3.0
func (o Option[T]) MustGet() T
MustGet returns the value or panics if the option is unset or null.
func (Option[T]) Or ¶ added in v0.3.0
func (o Option[T]) Or(fallback T) T
Or returns the value, or the fallback for unset and null.
func (Option[T]) Ptr ¶ added in v0.3.0
func (o Option[T]) Ptr() *T
Ptr returns a pointer to a copy of the value, or nil for unset and null.
func (*Option[T]) UnmarshalJSON ¶ added in v0.3.0
UnmarshalJSON records null or a present value. An absent struct field is untouched.
type OrderOption ¶ added in v0.3.0
OrderOption orders a selector for entity E.
type OrderedColumn ¶ added in v0.3.0
OrderedColumn adds ordering comparisons for numeric, time, and string values.
func (OrderedColumn[E, T]) Between ¶ added in v0.3.0
func (c OrderedColumn[E, T]) Between(lower, upper T) Predicate[E]
Between tests an inclusive range.
func (OrderedColumn[E, T]) GT ¶ added in v0.3.0
func (c OrderedColumn[E, T]) GT(value T) Predicate[E]
GT tests whether the column is greater than a value.
func (OrderedColumn[E, T]) GTE ¶ added in v0.3.0
func (c OrderedColumn[E, T]) GTE(value T) Predicate[E]
GTE tests whether the column is greater than or equal to a value.
func (OrderedColumn[E, T]) LT ¶ added in v0.3.0
func (c OrderedColumn[E, T]) LT(value T) Predicate[E]
LT tests whether the column is less than a value.
func (OrderedColumn[E, T]) LTE ¶ added in v0.3.0
func (c OrderedColumn[E, T]) LTE(value T) Predicate[E]
LTE tests whether the column is less than or equal to a value.
type Predicate ¶ added in v0.3.0
Predicate restricts a selector for entity E.
func And ¶ added in v0.3.0
And joins predicates with AND without absorbing existing selector predicates.
func Or ¶ added in v0.3.0
Or joins predicates with OR without absorbing existing selector predicates.
type PredicateFunc ¶ added in v0.3.0
PredicateFunc is an expression predicate without an entity type restriction. It can be passed directly to a function accepting Predicate[E].
type QueryContext ¶
type QueryContext struct {
// Op defines the operation name. e.g., First, All, Count, etc.
Op string
// Type defines the query type as defined in the generated code.
Type string
// Unique indicates if the Unique modifier was set on the query and
// its value. Calling Unique(false) sets the value of Unique to false.
Unique *bool
// Limit indicates if the Limit modifier was set on the query and
// its value. Calling Limit(10) sets the value of Limit to 10.
Limit *int
// Offset indicates if the Offset modifier was set on the query and
// its value. Calling Offset(10) sets the value of Offset to 10.
Offset *int
// Fields specifies the fields that were selected in the query.
Fields []string
}
QueryContext contains additional information about the context in which the query is executed.
func (*QueryContext) AppendFieldOnce ¶
func (q *QueryContext) AppendFieldOnce(f string) *QueryContext
AppendFieldOnce adds the given field to the spec if it is not already present.
func (*QueryContext) Clone ¶
func (q *QueryContext) Clone() *QueryContext
Clone returns a deep copy of the query context.
type Relation ¶ added in v0.3.0
type Relation[E, N, K any] struct{ RelationRef }
Relation describes a non-unique relation from entity E to neighbor N with key K.
func NewRelation ¶ added in v0.3.0
NewRelation creates a non-unique edge descriptor.
func (Relation[E, N, K]) HasWith ¶ added in v0.3.0
HasWith tests whether any neighbor matches all predicates.
func (Relation[E, N, K]) OrderByCount ¶ added in v0.3.0
func (e Relation[E, N, K]) OrderByCount(options ...sql.OrderTermOption) OrderOption[E]
OrderByCount orders by the number of neighbors.
type RelationOf ¶ added in v0.3.0
type RelationOf[E, N, K any] interface { Ref() RelationRef // contains filtered or unexported methods }
RelationOf accepts either edge kind with matching owner, neighbor and key types.
type RelationPatch ¶ added in v0.3.0
type RelationPatch[K comparable] struct { Add []K `json:"add,omitzero"` Remove []K `json:"remove,omitzero"` Clear bool `json:"clear,omitzero"` }
RelationPatch describes additions, removals, and clearing of a relation.
func (RelationPatch[K]) IsZero ¶ added in v0.3.0
func (p RelationPatch[K]) IsZero() bool
IsZero reports whether the relation is unchanged.
type RelationRef ¶ added in v0.3.0
type RelationRef struct {
Name string
Unique bool
// Configure applies selector-local schema configuration to a fresh step.
Configure func(*sql.Selector, *sqlgraph.Step)
// contains filtered or unexported fields
}
RelationRef is the dialect-independent identity of an edge.
func (RelationRef) CountQuery ¶ added in v0.3.0
CountQuery builds one grouped count query for the requested parent IDs.
func (RelationRef) Ref ¶ added in v0.3.0
func (e RelationRef) Ref() RelationRef
type Row ¶ added in v0.3.0
type Row struct {
// contains filtered or unexported fields
}
Row holds typed scan destinations for a projection. Output aliases must be unique.
type RowsQuerier ¶ added in v0.3.0
RowsQuerier executes a typed projection.
type Schema ¶
type Schema struct {
Interface
}
Schema is the default implementation for the schema Interface. It can be embedded in end-user schemas as follows:
type T struct {
ent.Schema
}
func (Schema) Annotations ¶
func (Schema) Annotations() []schema.Annotation
Annotations of the schema.
type Selection ¶ added in v0.3.0
type Selection interface {
Ref() ColumnRef
Alias() string
// contains filtered or unexported methods
}
Selection describes a projected column and allocates its typed scan destination. Columns select into *T; Nullable selections select into **T to preserve SQL NULL.
type SelectionOf ¶ added in v0.3.0
type SelectionOf[T any] interface { Selection As(string) SelectionOf[T] Nullable() SelectionOf[T] // contains filtered or unexported methods }
SelectionOf retains a selection's value type for Get and GetNullable inference.
func Avg ¶ added in v0.3.0
func Avg[E any, T Number](column ColumnOf[E, T]) SelectionOf[float64]
Avg selects the mean of non-null column values.
func CountColumn ¶ added in v0.3.0
func CountColumn[E, T any](column ColumnOf[E, T]) SelectionOf[int]
CountColumn selects the number of non-null column values.
func ExprSelection ¶ added in v0.3.0
func ExprSelection[T any](expression Expr[T], alias string) SelectionOf[T]
ExprSelection selects a typed expression under the given output alias.
func Max ¶ added in v0.3.0
func Max[E, T any](column ColumnOf[E, T]) SelectionOf[T]
Max selects the largest non-null column value.
func Min ¶ added in v0.3.0
func Min[E, T any](column ColumnOf[E, T]) SelectionOf[T]
Min selects the smallest non-null column value.
type StringColumn ¶ added in v0.3.0
type StringColumn[E, T any] struct{ OrderedColumn[E, T] }
StringColumn adds text matching predicates, including for named string types.
func (StringColumn[E, T]) Contains ¶ added in v0.3.0
func (c StringColumn[E, T]) Contains(substring string) Predicate[E]
Contains matches a literal substring, escaping SQL wildcard characters.
func (StringColumn[E, T]) ContainsFold ¶ added in v0.3.0
func (c StringColumn[E, T]) ContainsFold(substring string) Predicate[E]
ContainsFold matches a literal substring without case sensitivity.
func (StringColumn[E, T]) EqualFold ¶ added in v0.3.0
func (c StringColumn[E, T]) EqualFold(value string) Predicate[E]
EqualFold tests case-insensitive text equality.
func (StringColumn[E, T]) HasPrefix ¶ added in v0.3.0
func (c StringColumn[E, T]) HasPrefix(prefix string) Predicate[E]
HasPrefix matches a literal prefix.
func (StringColumn[E, T]) HasSuffix ¶ added in v0.3.0
func (c StringColumn[E, T]) HasSuffix(suffix string) Predicate[E]
HasSuffix matches a literal suffix.
type UniqueRelation ¶ added in v0.3.0
type UniqueRelation[E, N, K any] struct{ RelationRef }
UniqueRelation describes a unique relation from entity E to neighbor N with key K.
func NewUniqueRelation ¶ added in v0.3.0
func NewUniqueRelation[E, N, K any](name string, step func() *sqlgraph.Step) UniqueRelation[E, N, K]
NewUniqueRelation creates a unique edge descriptor.
func (UniqueRelation[E, N, K]) Has ¶ added in v0.3.0
func (e UniqueRelation[E, N, K]) Has() Predicate[E]
Has tests whether the edge has a neighbor.
func (UniqueRelation[E, N, K]) HasWith ¶ added in v0.3.0
func (e UniqueRelation[E, N, K]) HasWith(predicates ...Predicate[N]) Predicate[E]
HasWith tests whether the neighbor matches all predicates.
func (UniqueRelation[E, N, K]) OrderBy ¶ added in v0.3.0
func (e UniqueRelation[E, N, K]) OrderBy(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption[E]
OrderBy orders by neighbor terms.
type ValidationError ¶ added in v0.3.0
ValidationError associates a validation failure with a field name.
func (*ValidationError) Error ¶ added in v0.3.0
func (e *ValidationError) Error() string
func (*ValidationError) Unwrap ¶ added in v0.3.0
func (e *ValidationError) Unwrap() error
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
cache
module
|
|
|
cmd
|
|
|
ent
command
|
|
|
entc
command
|
|
|
internal/base
Package base defines shared basic pieces of the ent command.
|
Package base defines shared basic pieces of the ent command. |
|
pg
Package pg implements the driver boundary with native pgx codecs.
|
Package pg implements the driver boundary with native pgx codecs. |
|
sql
Package sql provides wrappers around the standard database/sql package to allow the generated code to interact with a statically-typed API.
|
Package sql provides wrappers around the standard database/sql package to allow the generated code to interact with a statically-typed API. |
|
sql/schema
Package schema contains all schema migration logic for SQL dialects.
|
Package schema contains all schema migration logic for SQL dialects. |
|
sql/sqlgraph
Package sqlgraph provides graph abstraction capabilities on top of sql-based databases for ent codegen.
|
Package sqlgraph provides graph abstraction capabilities on top of sql-based databases for ent codegen. |
|
sqlite
Package sqlite uses ncruces SQLite through database/sql.
|
Package sqlite uses ncruces SQLite through database/sql. |
|
Package entc provides an interface for interacting with entc (ent codegen) as a package rather than an executable.
|
Package entc provides an interface for interacting with entc (ent codegen) as a package rather than an executable. |
|
gen
Package gen is the interface for generating loaded schemas into a Go package.
|
Package gen is the interface for generating loaded schemas into a Go package. |
|
load
Package load is the interface for loading an ent/schema package into a Go program.
|
Package load is the interface for loading an ent/schema package into a Go program. |
|
integration
module
|
|
|
field/internal
command
gen is a codegen cmd for generating numeric build types from template.
|
gen is a codegen cmd for generating numeric build types from template. |