schemax

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2024 License: Apache-2.0 Imports: 20 Imported by: 8

Documentation

Index

Constants

View Source
const (
	FieldTenantID = "tenant_id"
)

Variables

View Source
var (
	AnnotationName = "Knockout"
)

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 {
	mixin.Schema
}

IntID helps to generate an int type id. It is used for the primary key of the table.

func (IntID) Fields

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

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 {
	mixin.Schema
}

SnowFlakeID helps to generate a snowflake type id.

func (SnowFlakeID) Fields

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

func (SnowFlakeID) SchemaType

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

SchemaType override the ent.Schema. The SchemaType of SnowFlakeID is a map of database dialects to the SQL type.

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 (World) Fields() []ent.Field {
			return []ent.Field{
				field.Int(schemax.FieldTenantID).Immutable(),
			}
  }

func NewTenantMixin

func NewTenantMixin[T Query, Q Mutator](app string, newQuery func(ent.Query) (T, error), opts ...TenantMixinOption[T, Q]) 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. Knockout Tenant field uses go Int type as the field type, it is a snowflake id by default.

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 TenantMixin.

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:expression`. The expression is a list of field and value pairs separated by `/`, and the field and value are separated by `:`. It means multiple and conditions that only support the equal operation.

type TenantMixinOption

type TenantMixinOption[T Query, Q Mutator] func(*TenantMixin[T, Q])

func WithTenantMixinStorageKey

func WithTenantMixinStorageKey[T Query, Q Mutator](storageKey string) TenantMixinOption[T, Q]

WithTenantMixinStorageKey sets the tenant field for ent StorageKey if you custom the field name which is not `tenant_id`.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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