Help us shape the future of Go! Take the 2026 Go Developer Survey

ent

package module
v0.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 19, 2026 License: Apache-2.0 Imports: 18 Imported by: 125

README

ent - An Entity Framework For Go

Simple, yet powerful entity framework for Go, that makes it easy to build and maintain applications with large data-models.

  • Schema As Code - model any database schema as Go objects.
  • Easily Traverse Any Graph - run queries, aggregations and traverse any graph structure easily.
  • Statically Typed And Explicit API - 100% statically typed and explicit API using code generation.
  • PostgreSQL and SQLite - focused support for PostgreSQL and SQLite.
  • Extendable - simple to extend and customize using Go templates.

Installation

go get github.com/neko-sc/ent

About

Fork of entgo.io/ent at 69d5d4d.

License

ent is licensed under Apache 2.0 as found in the LICENSE file.

Documentation

Overview

Package ent is the interface between end-user schemas and entc (ent codegen).

Index

Constants

View Source
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

View Source
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

func IsConstraintError(err error) bool

IsConstraintError reports whether err wraps a driver's constraint violation.

func IsNotFound added in v0.3.0

func IsNotFound(err error) bool

IsNotFound reports whether err wraps a NotFoundError.

func IsNotSingular added in v0.3.0

func IsNotSingular(err error) bool

IsNotSingular reports whether err wraps a NotSingularError.

func IsValidationError added in v0.3.0

func IsValidationError(err error) bool

IsValidationError reports whether err wraps a ValidationError.

func SelectColumns added in v0.3.0

func SelectColumns(selector *sql.Selector, selections ...Selection)

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

type ArrayColumn[E, T any] struct{ Column[E, T] }

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]) Alias added in v0.3.0

func (c Column[E, T]) Alias() string

Alias returns the unaliased column's name.

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

func (c Column[E, T]) EQ(value T) Predicate[E]

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

func (c Column[E, T]) EQExpr(expression Expr[T]) Predicate[E]

EQExpr compares the column to an expression with the same value type.

func (Column[E, T]) Expr added in v0.3.0

func (c Column[E, T]) Expr() Expr[T]

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

func (c Column[E, T]) In(values ...T) Predicate[E]

In tests membership in a set of values. An empty set matches nothing.

func (Column[E, T]) IsNull added in v0.3.0

func (c Column[E, T]) IsNull() Predicate[E]

IsNull tests for SQL NULL.

func (Column[E, T]) NEQ added in v0.3.0

func (c Column[E, T]) NEQ(value T) Predicate[E]

NEQ tests inequality to a stored value.

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

func (c Column[E, T]) NEQExpr(expression Expr[T]) Predicate[E]

NEQExpr compares the column to an expression for inequality.

func (Column[E, T]) NotIn added in v0.3.0

func (c Column[E, T]) NotIn(values ...T) Predicate[E]

NotIn excludes a set of values. An empty set excludes nothing.

func (Column[E, T]) NotNull added in v0.3.0

func (c Column[E, T]) NotNull() Predicate[E]

NotNull excludes SQL NULL.

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]) Ref added in v0.3.0

func (c Column[E, T]) Ref() ColumnRef

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

type ColumnOf[E, T any] interface {
	Ref() ColumnRef
	// contains filtered or unexported methods
}

ColumnOf accepts every column kind with the same entity and value types.

type ColumnRef added in v0.3.0

type ColumnRef struct {
	Table string
	Name  string
}

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

type EntityColumn[E any] interface {
	Selection
	// contains filtered or unexported methods
}

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 Add added in v0.3.0

func Add[T Number](left, right Expr[T]) Expr[T]

func Coalesce added in v0.3.0

func Coalesce[T any](expressions ...Expr[T]) Expr[T]

Coalesce returns the first non-null expression. At least one is required.

func Excluded added in v0.3.0

func Excluded[E, T any](column ColumnOf[E, T]) Expr[T]

Excluded refers to the proposed value of a column in an upsert.

func ExprFunc added in v0.3.0

func ExprFunc[T any](render func(*sql.Builder)) Expr[T]

ExprFunc wraps a SQL renderer. Bind external values with Builder.Arg.

func Literal added in v0.3.0

func Literal[T any](value T) Expr[T]

Literal renders a value as a bound SQL argument.

func Mul added in v0.3.0

func Mul[T Number](left, right Expr[T]) Expr[T]

func Sub added in v0.3.0

func Sub[T Number](left, right Expr[T]) Expr[T]

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.

func (Expr[T]) Render added in v0.3.0

func (e Expr[T]) Render(builder *sql.Builder)

Render appends the expression to a builder. Columns without an explicit table render unqualified outside a selector predicate.

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

type JSONColumn[E, T any] struct{ Column[E, T] }

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.

func (JSONPath[E]) EQ added in v0.3.0

func (p JSONPath[E]) EQ(value any) Predicate[E]

EQ compares the JSON path's value to a scalar.

func (JSONPath[E]) IsNull added in v0.3.0

func (p JSONPath[E]) IsNull() Predicate[E]

IsNull tests a JSON null literal, not a missing path or SQL NULL document.

func (JSONPath[E]) NEQ added in v0.3.0

func (p JSONPath[E]) NEQ(value any) Predicate[E]

NEQ compares the JSON path's value to a scalar for inequality.

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 Mutation

type Mutation interface {
	Op() Op
	Type() string
}

Mutation identifies an operation on an entity type.

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.

const (
	OpCreate    Op = 1 << iota // node creation.
	OpUpdate                   // update nodes by predicate (if any).
	OpUpdateOne                // update one node.
	OpDelete                   // delete nodes by predicate (if any).
	OpDeleteOne                // delete one node.
)

Mutation operations.

func (Op) Is

func (i Op) Is(o Op) bool

Is reports whether o is match the given operation.

func (Op) String

func (i Op) String() string

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 FromPtr added in v0.3.0

func FromPtr[T any](pointer *T) Option[T]

FromPtr copies a pointed-to value; nil means unset.

func Null added in v0.3.0

func Null[T any]() Option[T]

func NullIfNil added in v0.3.0

func NullIfNil[T any](pointer *T) Option[T]

NullIfNil copies a pointed-to value; nil means explicit null.

func Some added in v0.3.0

func Some[T any](value T) Option[T]

Some wraps a present value, including the zero value of T.

func Unset added in v0.3.0

func Unset[T any]() Option[T]

func (Option[T]) Get added in v0.3.0

func (o Option[T]) Get() (T, bool)

Get returns the value and whether it is present and non-null.

func (Option[T]) IsNull added in v0.3.0

func (o Option[T]) IsNull() bool

IsNull reports whether the option is explicitly null.

func (Option[T]) IsSet added in v0.3.0

func (o Option[T]) IsSet() bool

IsSet reports whether the option contains a value or explicit null.

func (Option[T]) IsUnset added in v0.3.0

func (o Option[T]) IsUnset() bool

IsUnset reports whether the option was omitted.

func (Option[T]) IsZero added in v0.3.0

func (o Option[T]) IsZero() bool

IsZero permits encoding/json to omit only unset options with omitzero.

func (Option[T]) MarshalJSON added in v0.3.0

func (o Option[T]) MarshalJSON() ([]byte, error)

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]) String added in v0.3.0

func (o Option[T]) String() string

String formats an option's state and value for debugging.

func (*Option[T]) UnmarshalJSON added in v0.3.0

func (o *Option[T]) UnmarshalJSON(data []byte) error

UnmarshalJSON records null or a present value. An absent struct field is untouched.

type OrderOption added in v0.3.0

type OrderOption[E any] func(*sql.Selector)

OrderOption orders a selector for entity E.

type OrderedColumn added in v0.3.0

type OrderedColumn[E, T any] struct{ Column[E, T] }

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

type Predicate[E any] func(*sql.Selector)

Predicate restricts a selector for entity E.

func And added in v0.3.0

func And[E any](predicates ...Predicate[E]) Predicate[E]

And joins predicates with AND without absorbing existing selector predicates.

func Not added in v0.3.0

func Not[E any](predicate Predicate[E]) Predicate[E]

Not negates a predicate without negating existing selector predicates.

func Or added in v0.3.0

func Or[E any](predicates ...Predicate[E]) Predicate[E]

Or joins predicates with OR without absorbing existing selector predicates.

func (Predicate[E]) And added in v0.3.0

func (p Predicate[E]) And(others ...Predicate[E]) Predicate[E]

And joins this predicate and others with AND.

func (Predicate[E]) Not added in v0.3.0

func (p Predicate[E]) Not() Predicate[E]

Not negates this predicate.

func (Predicate[E]) Or added in v0.3.0

func (p Predicate[E]) Or(others ...Predicate[E]) Predicate[E]

Or joins this predicate and others with OR.

type PredicateFunc added in v0.3.0

type PredicateFunc = func(*sql.Selector)

PredicateFunc is an expression predicate without an entity type restriction. It can be passed directly to a function accepting Predicate[E].

type Query

type Query any

Query represents an entity query builder.

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

func NewRelation[E, N, K any](name string, step func() *sqlgraph.Step) Relation[E, N, K]

NewRelation creates a non-unique edge descriptor.

func (Relation[E, N, K]) Has added in v0.3.0

func (e Relation[E, N, K]) Has() Predicate[E]

Has tests whether the edge has any neighbors.

func (Relation[E, N, K]) HasWith added in v0.3.0

func (e Relation[E, N, K]) HasWith(predicates ...Predicate[N]) Predicate[E]

HasWith tests whether any neighbor matches all predicates.

func (Relation[E, N, K]) OrderBy added in v0.3.0

func (e Relation[E, N, K]) OrderBy(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption[E]

OrderBy orders by neighbor terms.

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

func (e RelationRef) CountQuery(selector *sql.Selector, ids ...any) *sql.Selector

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.

func NewRow added in v0.3.0

func NewRow(selections []Selection) (*Row, []any)

NewRow allocates a row and destinations to pass to the driver's scan operation. It panics for duplicate output aliases; use As to disambiguate joined columns.

type RowsQuerier added in v0.3.0

type RowsQuerier interface {
	Rows(context.Context) ([]*Row, error)
}

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.

func (Schema) Config

func (Schema) Config() Config

Config of the schema.

func (Schema) Edges

func (Schema) Edges() []Edge

Edges of the schema.

func (Schema) Fields

func (Schema) Fields() []Field

Fields of the schema.

func (Schema) Indexes

func (Schema) Indexes() []Index

Indexes of the schema.

func (Schema) Mixin

func (Schema) Mixin() []Mixin

Mixin 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 Count added in v0.3.0

func Count() SelectionOf[int]

Count selects the number of rows.

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.

func Sum added in v0.3.0

func Sum[E any, T Number](column ColumnOf[E, T]) SelectionOf[T]

Sum selects the sum of non-null column values.

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

type ValidationError struct {
	Name string
	Err  error
}

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

type View

type View struct {
	Schema
}

A View only schema describes an entity that all its operations are limited to read-only. For example, a database view.

Users that wants to define a view schema should embed the View struct in their schema as follows:

type V struct {
	ent.View
}

type Viewer

type Viewer interface {
	// contains filtered or unexported methods
}

Viewer is an interface that wraps the view method. Implemented by the View struct.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL