data

package
v0.1.4 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: 7 Imported by: 0

Documentation

Overview

Package data contains ORM-independent tenant filtering contracts.

Index

Constants

View Source
const (
	// DefaultTenantField is the default database field used for tenant isolation.
	DefaultTenantField = "tenant_id"
)

Variables

View Source
var (
	// ErrNoTenant reports that a tenant-scoped filter was requested without tenant context.
	ErrNoTenant = gotenancy.ErrNoTenant

	// ErrInvalidFieldName reports an unsafe field name in filter options.
	ErrInvalidFieldName = errors.New("gotenancy/data: invalid field name")
)

Functions

This section is empty.

Types

type Condition

type Condition struct {
	Expression string
	Args       []any
}

Condition is an ORM-independent parameterized filter expression.

func (Condition) Empty

func (condition Condition) Empty() bool

Empty reports whether the condition has no expression.

type DataFilter

type DataFilter interface {
	Condition() Condition
	TenantID() (types.TenantID, bool)
	IsHost() bool
}

DataFilter provides an ORM-independent tenant filter.

type Filter

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

Filter is the default DataFilter implementation.

func NewFilter

func NewFilter(ctx context.Context, opts ...FilterOption) (*Filter, error)

NewFilter creates a tenant filter from context.

func (*Filter) Condition

func (filter *Filter) Condition() Condition

Condition returns the parameterized tenant condition.

func (*Filter) IsHost

func (filter *Filter) IsHost() bool

IsHost reports whether this filter represents explicit host-side access.

func (*Filter) TenantID

func (filter *Filter) TenantID() (types.TenantID, bool)

TenantID returns the scoped tenant ID when the filter is tenant-scoped.

type FilterOption

type FilterOption func(*filterOptions) error

FilterOption configures a Filter.

func WithIncludeSoftDeleted

func WithIncludeSoftDeleted(include bool) FilterOption

WithIncludeSoftDeleted disables the soft-delete IS NULL condition.

func WithSoftDeleteField

func WithSoftDeleteField(field string) FilterOption

WithSoftDeleteField adds an IS NULL condition for soft-deleted records.

func WithTenantField

func WithTenantField(field string) FilterOption

WithTenantField overrides the tenant field name.

Directories

Path Synopsis
Package enttenant adapts GoTenancy data filters to Ent SQL selectors.
Package enttenant adapts GoTenancy data filters to Ent SQL selectors.
Package gormtenant adds tenant-aware query, mutation, preload, raw SQL, and delete guardrails to GORM.
Package gormtenant adds tenant-aware query, mutation, preload, raw SQL, and delete guardrails to GORM.
Package sqlxtenant provides tenant-filtered helpers for simple sqlx-style SELECT, UPDATE, and DELETE statements.
Package sqlxtenant provides tenant-filtered helpers for simple sqlx-style SELECT, UPDATE, and DELETE statements.

Jump to

Keyboard shortcuts

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