Documentation ¶
Index ¶
- func JsonbScan(src interface{}, v interface{}) error
- func JsonbValue(v interface{}) (driver.Value, error)
- func SkipTenancyCheck() func(*gorm.DB) *gorm.DB
- func TenancyCheck(flags ...TenancyCheckFlag) func(*gorm.DB) *gorm.DB
- type Duration
- type JsonbMap
- type JsonbStringMap
- type Tenancy
- type TenancyCheckFlag
- type TenantPath
- func (t TenantPath) DeleteClauses(f *schema.Field) []clause.Interface
- func (t TenantPath) GormDataType() string
- func (t TenantPath) QueryClauses(f *schema.Field) []clause.Interface
- func (t *TenantPath) Scan(src interface{}) error
- func (t TenantPath) UpdateClauses(f *schema.Field) []clause.Interface
- func (t TenantPath) Value() (driver.Value, error)
- type TimeArray
- type UUIDArray
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func JsonbScan ¶
func JsonbScan(src interface{}, v interface{}) error
JsonbScan helps models to implement sql.Scanner
func JsonbValue ¶
JsonbValue helps models to implement driver.Valuer
func SkipTenancyCheck ¶ added in v0.15.0
SkipTenancyCheck is used as a scope for gorm.DB to skip tenancy check e.g. db.WithContext(ctx).Scopes(SkipTenancyCheck()).Find(...) Note using this scope without context would panic
func TenancyCheck ¶ added in v0.15.0
func TenancyCheck(flags ...TenancyCheckFlag) func(*gorm.DB) *gorm.DB
TenancyCheck is used as a scope for gorm.DB to override tenancy check e.g. db.WithContext(ctx).Scopes(TenancyCheck()).Find(...) Note using this scope without context would panic
Types ¶
type Duration ¶
Duration is also an alias of time.Duration
func (Duration) MarshalText ¶
MarshalText implements encoding.TextMarshaler
func (*Duration) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler
type JsonbStringMap ¶
func (*JsonbStringMap) Scan ¶
func (m *JsonbStringMap) Scan(src interface{}) error
type Tenancy ¶ added in v0.15.0
type Tenancy struct { TenantID uuid.UUID `gorm:"type:KeyID;not null"` TenantPath TenantPath `gorm:"type:uuid[];index:,type:gin;not null" json:"-"` }
Tenancy is an embedded type for data model. It's responsible for populating TenantPath and check for Tenancy related data when crating/updating. Tenancy implements - callbacks.BeforeCreateInterface - callbacks.BeforeUpdateInterface When used as an embedded type, tag `filter` can be used to override default tenancy check behavior:
- `filter:"w"`: create/update/delete are enforced (Default mode)
- `filter:"rw"`: CRUD operations are all enforced, this mode filters result of any Select/Update/Delete query based on current security context
- `filter:"-"`: filtering is disabled. Note: setting TenantID to in-accessible tenant is still enforced. to disable TenantID value check, use SkipTenancyCheck
e.g. <code>
type TenancyModel struct { ID uuid.UUID `gorm:"primaryKey;type:uuid;default:gen_random_uuid();"` Tenancy `filter:"rw"` }
</code>
func (*Tenancy) BeforeUpdate ¶ added in v0.15.0
BeforeUpdate Check if user is allowed to update this item's tenancy to the target tenant. (i.e. if user has access to the target tenant) We don't check the original tenancy because we don't have that information in this hook. That check has to be done in application code.
func (Tenancy) SkipTenancyCheck ¶ added in v0.15.0
SkipTenancyCheck is used for embedding models to override tenancy check behavior. It should be called within model's hooks. this function would panic if context is not set yet
type TenancyCheckFlag ¶ added in v0.15.0
type TenancyCheckFlag uint
TenancyCheckFlag bitwise Flag of tenancy flag mode
const ( TenancyCheckFlagWriteValueCheck TenancyCheckFlag = 1 << iota TenancyCheckFlagWriteFiltering TenancyCheckFlagReadFiltering )
type TenantPath ¶ added in v0.15.0
type TenantPath UUIDArray
TenantPath implements - schema.GormDataTypeInterface - schema.QueryClausesInterface - schema.UpdateClausesInterface - schema.DeleteClausesInterface this data type adds "WHERE" clause for tenancy filtering
func (TenantPath) DeleteClauses ¶ added in v0.15.0
func (t TenantPath) DeleteClauses(f *schema.Field) []clause.Interface
DeleteClauses implements schema.DeleteClausesInterface,
func (TenantPath) GormDataType ¶ added in v0.15.0
func (t TenantPath) GormDataType() string
func (TenantPath) QueryClauses ¶ added in v0.15.0
func (t TenantPath) QueryClauses(f *schema.Field) []clause.Interface
QueryClauses implements schema.QueryClausesInterface,
func (*TenantPath) Scan ¶ added in v0.15.0
func (t *TenantPath) Scan(src interface{}) error
Scan implements sql.Scanner
func (TenantPath) UpdateClauses ¶ added in v0.15.0
func (t TenantPath) UpdateClauses(f *schema.Field) []clause.Interface
UpdateClauses implements schema.UpdateClausesInterface,
type TimeArray ¶
TimeArray register driver.Valuer & sql.Scanner