pqx

package
v0.15.1 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2024 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

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

func JsonbValue(v interface{}) (driver.Value, error)

JsonbValue helps models to implement driver.Valuer

func SkipTenancyCheck added in v0.15.0

func SkipTenancyCheck() func(*gorm.DB) *gorm.DB

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

type Duration utils.Duration

Duration is also an alias of time.Duration

func (Duration) MarshalText

func (d Duration) MarshalText() (text []byte, err error)

MarshalText implements encoding.TextMarshaler

func (*Duration) Scan

func (d *Duration) Scan(src interface{}) error

Scan implements sql.Scanner

func (*Duration) UnmarshalText

func (d *Duration) UnmarshalText(text []byte) error

UnmarshalText implements encoding.TextUnmarshaler

func (Duration) Value

func (d Duration) Value() (driver.Value, error)

Value implements driver.Valuer

type JsonbMap

type JsonbMap map[string]interface{}

func (*JsonbMap) Scan

func (m *JsonbMap) Scan(src interface{}) error

func (JsonbMap) Value

func (m JsonbMap) Value() (driver.Value, error)

type JsonbStringMap

type JsonbStringMap map[string]string

func (*JsonbStringMap) Scan

func (m *JsonbStringMap) Scan(src interface{}) error

func (JsonbStringMap) Value

func (m JsonbStringMap) Value() (driver.Value, 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) BeforeCreate added in v0.15.0

func (t *Tenancy) BeforeCreate(tx *gorm.DB) error

func (*Tenancy) BeforeUpdate added in v0.15.0

func (t *Tenancy) BeforeUpdate(tx *gorm.DB) error

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

func (Tenancy) SkipTenancyCheck(tx *gorm.DB)

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,

func (TenantPath) Value added in v0.15.0

func (t TenantPath) Value() (driver.Value, error)

Value implements driver.Valuer

type TimeArray

type TimeArray []time.Time

TimeArray register driver.Valuer & sql.Scanner

func (*TimeArray) Scan

func (a *TimeArray) Scan(src interface{}) error

Scan implements sql.Scanner

func (TimeArray) Value

func (a TimeArray) Value() (driver.Value, error)

Value implements driver.Valuer

type UUIDArray

type UUIDArray []uuid.UUID

func (*UUIDArray) Scan

func (a *UUIDArray) Scan(src interface{}) error

Scan implements sql.Scanner

func (UUIDArray) Strings

func (a UUIDArray) Strings() []string

func (UUIDArray) Value

func (a UUIDArray) Value() (driver.Value, error)

Value implements driver.Valuer

Jump to

Keyboard shortcuts

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