entx

package module
v0.0.0-...-c646443 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2025 License: MIT Imports: 8 Imported by: 0

README ΒΆ

entx - Extension for entgo.io

entx is a modular extension toolkit for ent, the powerful ORM for Go. It eliminates repetitive logic that most projects end up rewriting β€” such as advanced querying, input validation, pagination handling, or mutation helpers.

Instead of re-implementing the same patterns in every service, entx generates them directly from your Ent schema and provides flexible client-side adapters tailored to your application’s needs.

In short: entx automates all the boilerplate that Ent enables β€” but doesn’t generate by default.


πŸš€ Why entx?

ent is powerful, but its internal graph representation (based on schema definitions) is not directly accessible or reusable.

entx builds its own generic and structured graph, based on your schema, and uses it to generate ready-to-use features like search engines.

Less code to write. Zero logic to repeat.


🧩 Modular by Design

entx is composed of focused modules. Each one solves a common problem that can be automated based on your Ent schema.

Module Description
πŸ” search Powerful search engine with filters, sorting, pagination, includes, aggregations…
🧬 mutate (coming soon) Automated create/update/upsert/attach/detach operations, integration of customized business logic.

Each module integrates with Ent through the entc.Extension system.

πŸ” search (ready to use)

A declarative, type-safe, and extensible search engine for Ent. Includes:

  • Dynamic filtering (with AND, OR, nesting)
  • Multi-field sorting
  • Offset and cursor pagination
  • Relational includes
  • Grouping and aggregation
  • Parallelism and transactions

β†’ See full search documentation


πŸ“¦ Installation

For the moment, generation is done via the search module extension. The future idea is to offer an entx extension by specifying the desired modules.

In your entc.go:

import search "github.com/brice-74/entx/search/extension"

func main() {
   opts := []entc.Option{
      entc.Extensions(
         search.New(), // enable search module
      ),
   }

   if err := entc.Generate("./schema", opts...); err != nil {
      log.Fatalf("entc: %v", err)
   }
}

Documentation ΒΆ

Index ΒΆ

Constants ΒΆ

This section is empty.

Variables ΒΆ

This section is empty.

Functions ΒΆ

func AsTypedEntities ΒΆ

func AsTypedEntities[T Entity](in []Entity) []T

Transforms a slice of Entity into a slice of T (where T implements Entity) ⚠️ This conversion often requires a safe type assertion or verification

func CombinePredicates ΒΆ

func CombinePredicates[T ~func(*sql.Selector)](preds ...T) T

func NormalizeAggregateValue ΒΆ

func NormalizeAggregateValue(v any) any

func ToInterceptor ΒΆ

func ToInterceptor[T Entity](handlers ...EntityHandler) ent.Interceptor

Types ΒΆ

type BaseBridge ΒΆ

type BaseBridge struct {
	RelationInfos
	// contains filtered or unexported fields
}

func NewBaseBridge ΒΆ

func NewBaseBridge(
	parent Node,
	child Node,
	inverse Bridge,
	relInfos RelationInfos,
) BaseBridge

func (*BaseBridge) Child ΒΆ

func (b *BaseBridge) Child() Node

func (*BaseBridge) Inverse ΒΆ

func (b *BaseBridge) Inverse() Bridge

func (*BaseBridge) Join ΒΆ

func (b *BaseBridge) Join(s *sql.Selector, outer ...*sql.SelectTable) (tables []*sql.SelectTable)

func (*BaseBridge) JoinPivot ΒΆ

func (b *BaseBridge) JoinPivot(s *sql.Selector, outer ...*sql.SelectTable) *sql.SelectTable

func (*BaseBridge) Parent ΒΆ

func (b *BaseBridge) Parent() Node

func (*BaseBridge) RelInfos ΒΆ

func (b *BaseBridge) RelInfos() *RelationInfos

func (*BaseBridge) SetInverse ΒΆ

func (b *BaseBridge) SetInverse(bridge Bridge)

type BaseNode ΒΆ

type BaseNode struct {
	// contains filtered or unexported fields
}

func NewBaseNode ΒΆ

func NewBaseNode(
	name string,
	tableName string,
	bridges map[string]Bridge,
	fields map[string]*Field,
	pks []*Field,
) BaseNode

func (*BaseNode) Bridge ΒΆ

func (n *BaseNode) Bridge(s string) Bridge

func (*BaseNode) FieldByName ΒΆ

func (n *BaseNode) FieldByName(s string) *Field

func (*BaseNode) Name ΒΆ

func (n *BaseNode) Name() string

func (*BaseNode) PKs ΒΆ

func (n *BaseNode) PKs() []*Field

func (*BaseNode) SetBridge ΒΆ

func (n *BaseNode) SetBridge(key string, bridge Bridge)

func (*BaseNode) Table ΒΆ

func (n *BaseNode) Table() string

type Bridge ΒΆ

type Bridge interface {
	RelInfos() *RelationInfos
	JoinPivot(*sql.Selector, ...*sql.SelectTable) *sql.SelectTable
	Join(*sql.Selector, ...*sql.SelectTable) []*sql.SelectTable
	Include(parentQuery Query, childQuery func(Query), handlers ...EntityHandler) Query
	FilterWith(...func(*sql.Selector)) func(*sql.Selector)
	Filter() func(*sql.Selector)
	Inverse() Bridge
	Child() Node
	Parent() Node
}

type Client ΒΆ

type Client interface {
	Debug() Client
	GetEntityClient(Node) (EntityClient, error)
	MustGetEntityClient(Node) EntityClient
	QueryContext(ctx context.Context, query string, args ...any) (*stdsql.Rows, error)
	Tx(ctx context.Context, opts *stdsql.TxOptions) (Transaction, Client, error)
}

type Entity ΒΆ

type Entity interface {
	Metadatas() *EntityMeta
	// native ent method to retrieve additionnal query values
	Value(name string) (ent.Value, error)
}

func AsEntities ΒΆ

func AsEntities[T Entity](in []T) []Entity

TODO: create slice pool to avoid re allocation ?

type EntityClient ΒΆ

type EntityClient interface {
	Query() Query
}

type EntityHandler ΒΆ

type EntityHandler func(entities []Entity) error

func AddAggregatesFromValues ΒΆ

func AddAggregatesFromValues(fields ...string) EntityHandler

type EntityMeta ΒΆ

type EntityMeta struct {
	Aggregates map[string]any `json:"aggregates,omitempty"`
}

type Field ΒΆ

type Field struct {
	Name        string
	StorageName string
}

type Graph ΒΆ

type Graph = map[string]Node

type Node ΒΆ

type Node interface {
	PKs() []*Field
	Name() string
	Table() string
	Policy() ent.Policy
	NewQuery(Client) Query
	FieldByName(s string) *Field
	Bridge(string) Bridge
}

type Query ΒΆ

type Query interface {
	Predicate(...func(s *sql.Selector)) Query
	Select(columns ...string) Query
	All(ctx context.Context) ([]Entity, error)
}

type RelationInfos ΒΆ

type RelationInfos struct {
	RelType sqlgraph.Rel
	// used by O2O, O2M, M2O and M2M relations
	FinalLeftField  string
	FinalRightField string
	// used only by M2M relation
	PivotTable      string
	PivotLeftField  string
	PivotRightField string
}

type Transaction ΒΆ

type Transaction interface {
	Rollback() error
	Commit() error
}

Directories ΒΆ

Path Synopsis
dsl

Jump to

Keyboard shortcuts

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