Documentation ¶
Index ¶
- Constants
- Variables
- func AuditHook(next ent.Mutator) ent.Mutator
- func SkipSoftDelete(parent context.Context) context.Context
- func SkipTenantPrivacy(parent context.Context) context.Context
- type Annotation
- type AuditMixin
- type IntID
- type Mutator
- type NotifyMixin
- type Query
- type SnowFlakeID
- type SoftDeleteMixin
- type TenantMixin
- type TenantMixinOption
Constants ¶
const (
FieldTenantID = "tenant_id"
)
Variables ¶
var (
AnnotationName = "Knockout"
)
Functions ¶
func SkipSoftDelete ¶
SkipSoftDelete returns a new context that skips the soft-delete 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 ¶
func (AuditMixin) Fields ¶
func (e AuditMixin) Fields() []ent.Field
func (AuditMixin) Hooks ¶
func (AuditMixin) Hooks() []ent.Hook
type NotifyMixin ¶
NotifyMixin helps to notify when data changed.
func (NotifyMixin) Hooks ¶
func (NotifyMixin) Hooks() []ent.Hook
type SnowFlakeID ¶
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 (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`.