schemax

package
v0.0.0-...-5a6b2d2 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2023 License: Apache-2.0 Imports: 19 Imported by: 7

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	AnnotationName = "Knockout"
)
View Source
var (
	FieldTenantID = "tenant_id"
)

Functions

func AuditHook

func AuditHook(next ent.Mutator) ent.Mutator

func SkipSoftDelete

func SkipSoftDelete(parent context.Context) context.Context

SkipSoftDelete returns a new context that skips the soft-delete interceptor/mutators.

func SkipTenantPrivacy

func SkipTenantPrivacy(parent context.Context) context.Context

SkipTenantPrivacy returns a new context that skips the TenantRule interceptor/mutators.

Types

type Annotation

type Annotation struct {
	// Resources is the list of resources that this annotation is applied to.
	// each resource name use field name
	Resources []string `json:"Resources,omitempty"`
	// TenantField is the name of the tenant field.if you want to use a name except tenant_id
	TenantField string `json:"TenantField,omitempty"`
}

Annotation is a schema annotation for Knockout projects.

func Resources

func Resources(fields []string) Annotation

Resources returns a new annotation with the given resources.

func TenantField

func TenantField(field string) Annotation

TenantField returns a new annotation with the given tenant field.

func (Annotation) Merge

func (a Annotation) Merge(other schema.Annotation) schema.Annotation

func (Annotation) Name

func (Annotation) Name() string

type AuditMixin

type AuditMixin struct {
	mixin.Schema
}

func (AuditMixin) Fields

func (e AuditMixin) Fields() []ent.Field

func (AuditMixin) Hooks

func (AuditMixin) Hooks() []ent.Hook

type IntID

type IntID struct {
	// ID is the unique identifier of the user in the database.
	mixin.Schema
}

IntID helps to generate an int type id.

func (IntID) Fields

func (id IntID) Fields() []ent.Field

func (IntID) SchemaType

func (IntID) SchemaType() map[string]string

type Mutator

type Mutator interface {
	Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error)
}

The Query interface represents an operation that queries with WhereP.

type NotifyMixin

type NotifyMixin struct {
	mixin.Schema
}

NotifyMixin helps to notify when data changed.

func (NotifyMixin) Hooks

func (NotifyMixin) Hooks() []ent.Hook

type Query

type Query interface {
	WhereP(...func(*sql.Selector))
}

The Query interface represents an operation that queries with WhereP.

type SnowFlakeID

type SnowFlakeID struct {
	// ID is the unique identifier of the user in the database.
	mixin.Schema
}

SnowFlakeID 是采用雪花算法生成的ID.

func (SnowFlakeID) Fields

func (id SnowFlakeID) Fields() []ent.Field

func (SnowFlakeID) SchemaType

func (SnowFlakeID) SchemaType() map[string]string

type SoftDeleteMixin

type SoftDeleteMixin[T Query, Q Mutator] struct {
	mixin.Schema
	QueryFunc func(ent.Query) (T, error)
}

SoftDeleteMixin implements the soft delete pattern for schemas.

func NewSoftDeleteMixin

func NewSoftDeleteMixin[T Query, Q Mutator](qf func(ent.Query) (T, error)) SoftDeleteMixin[T, Q]

func (SoftDeleteMixin[T, Q]) Fields

func (SoftDeleteMixin[T, Q]) Fields() []ent.Field

Fields of the SoftDeleteMixin.

func (SoftDeleteMixin[T, Q]) Hooks

func (d SoftDeleteMixin[T, Q]) Hooks() []ent.Hook

Hooks of the SoftDeleteMixin.

func (SoftDeleteMixin[T, Q]) Interceptors

func (d SoftDeleteMixin[T, Q]) Interceptors() []ent.Interceptor

Interceptors of the SoftDeleteMixin.

func (SoftDeleteMixin[T, Q]) P

func (d SoftDeleteMixin[T, Q]) P(w Query)

P adds a storage-level predicate to the queries and mutations.

type TenantMixin

type TenantMixin[T Query, Q Mutator] struct {
	mixin.Schema
	// contains filtered or unexported fields
}

TenantMixin helps to generate a tenant_id field and inject resource query.

 type World struct {
	    ent.Schema
 }

 func (World) Mixin() []ent.Mixin {
	    return []ent.Mixin{
	    	schemax.NewTenantMixin[intercept.Query, *gen.Client](intercept.NewQuery),
	    }
 }

func NewTenantMixin

func NewTenantMixin[T Query, Q Mutator](app string, newQuery func(ent.Query) (T, error)) TenantMixin[T, Q]

NewTenantMixin returns a mixin that adds a tenant_id field and inject resource query.

app is the application code, the same as the one defined in knockout backend.

func (TenantMixin[T, Q]) Fields

func (TenantMixin[T, Q]) Fields() []ent.Field

func (TenantMixin[T, Q]) Hooks

func (d TenantMixin[T, Q]) Hooks() []ent.Hook

Hooks of the SoftDeleteMixin.

func (TenantMixin[T, Q]) Interceptors

func (d TenantMixin[T, Q]) Interceptors() []ent.Interceptor

Interceptors of the SoftDeleteMixin.

func (TenantMixin[T, Q]) P

func (d TenantMixin[T, Q]) P(w Query, tid int)

P adds a storage-level predicate to the queries and mutations.

func (TenantMixin[T, Q]) QueryRulesP

func (d TenantMixin[T, Q]) QueryRulesP(ctx context.Context, w Query) error

QueryRulesP adds a storage-level predicate to the queries.

When call Authorizer.Prepare, pass appcode, tenant id, and resource type those as resource prefix, the prefix format is `appcode:tenant_id:resource_type:`.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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