enttenant

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package enttenant adapts GoTenancy data filters to Ent SQL selectors.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNilQuery reports that a nil Ent query was passed to the tenant filter.
	ErrNilQuery = errors.New("gotenancy/ent: nil query")

	// ErrNilMutation reports that a nil Ent mutation was passed to the tenant filter.
	ErrNilMutation = errors.New("gotenancy/ent: nil mutation")

	// ErrUnsupportedMutation reports that an Ent mutation does not expose storage predicates.
	ErrUnsupportedMutation = errors.New("gotenancy/ent: unsupported mutation")

	// ErrTenantFieldNotFound reports that the configured tenant field does not exist on the mutation.
	ErrTenantFieldNotFound = errors.New("gotenancy/ent: tenant field not found")
)

Functions

func Apply

func Apply(ctx context.Context, selector *sql.Selector, config Config) error

Apply adds the current tenant predicate directly to selector.

func FilterMutation

func FilterMutation(ctx context.Context, mutation Mutation, config Config) error

FilterMutation applies tenant isolation to mutation using config.

func FilterQuery

func FilterQuery(ctx context.Context, query Query, config Config) error

FilterQuery applies tenant isolation to query using config.

func Hook

func Hook(config Config) ent.Hook

Hook returns an Ent mutation hook that enforces tenant isolation before mutation execution.

Types

type Config

type Config struct {
	TenantField        string
	SoftDeleteField    string
	IncludeSoftDeleted bool
}

Config controls Ent tenant predicate generation.

type Mutation

type Mutation interface {
	Op() ent.Op
	WhereP(...SelectorPredicate)
	Field(string) (ent.Value, bool)
	SetField(string, ent.Value) error
}

Mutation is the storage-level predicate surface generated by Ent mutations.

type MutationFilter

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

MutationFilter applies tenant guards to Ent mutations.

func NewMutationFilter

func NewMutationFilter(config Config) MutationFilter

NewMutationFilter creates a reusable Ent mutation tenant filter.

func (MutationFilter) Apply

func (filter MutationFilter) Apply(ctx context.Context, mutation Mutation) error

Apply guards create mutations and appends tenant predicates to update/delete mutations.

type Query

type Query interface {
	WhereP(...SelectorPredicate)
}

Query is the storage-level predicate surface generated by Ent query builders.

type QueryFilter

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

QueryFilter applies tenant predicates to Ent query builders.

func NewQueryFilter

func NewQueryFilter(config Config) QueryFilter

NewQueryFilter creates a reusable Ent query tenant filter.

func (QueryFilter) Apply

func (filter QueryFilter) Apply(ctx context.Context, query Query) error

Apply appends the current tenant predicate to query. Host contexts are left unchanged.

type SelectorPredicate

type SelectorPredicate = func(*sql.Selector)

SelectorPredicate is an Ent custom predicate that mutates a SQL selector.

func Predicate

func Predicate(ctx context.Context, config Config) (SelectorPredicate, error)

Predicate builds an Ent custom predicate from the tenant context.

func TenantPredicate

func TenantPredicate(ctx context.Context) (SelectorPredicate, error)

TenantPredicate builds an Ent custom predicate with default configuration.

Jump to

Keyboard shortcuts

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