multi_tenants

package
v1.2.50 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2025 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const SessionCfg = "session_config"

Variables

View Source
var ErrDeleteTenantAllNotAllowed = errors.New("delete tenant all rows or global update is not allowed")
View Source
var ErrUpdateTenantAllNotAllowed = errors.New("update tenant all rows or global update is not allowed")

Functions

func IsFieldDupError

func IsFieldDupError(err error) bool

Types

type Cfg added in v1.2.49

type Cfg struct {
	// contains filtered or unexported fields
}

func (*Cfg) Ok added in v1.2.49

func (c *Cfg) Ok(tx *gorm.DB) bool

func (*Cfg) Set added in v1.2.49

func (c *Cfg) Set(tx *gorm.DB) *gorm.DB

func (*Cfg) Val added in v1.2.49

func (c *Cfg) Val(tx *gorm.DB) any

type Config

type Config struct {
	PluginName   string // no default value, "" will be error, plugin will not be effect
	TagKey       string // default: mt
	TagTenantKey string // default: tenant
	TagUniqueKey string // default: unique
	TxTenantKey  string // default: tenant_id
	TxTenantsKey string // default: tenant_ids
	TxSkipKey    string // default: skip_tenant

	GlobalCfg *SessionConfig // can be overSensed by SessionCfg

	UseTableParseSchema bool
	// contains filtered or unexported fields
}

func (*Config) AfterCreate

func (cfg *Config) AfterCreate(tx *gorm.DB)

func (*Config) AfterDelete

func (cfg *Config) AfterDelete(tx *gorm.DB)

func (*Config) AfterQuery

func (cfg *Config) AfterQuery(tx *gorm.DB)

func (*Config) AfterUpdate

func (cfg *Config) AfterUpdate(tx *gorm.DB)

func (*Config) BeforeCreate

func (cfg *Config) BeforeCreate(tx *gorm.DB)

func (*Config) BeforeDelete

func (cfg *Config) BeforeDelete(tx *gorm.DB)

func (*Config) BeforeQuery

func (cfg *Config) BeforeQuery(tx *gorm.DB)

func (*Config) BeforeUpdate

func (cfg *Config) BeforeUpdate(tx *gorm.DB)

func (*Config) FieldDupCheck

func (cfg *Config) FieldDupCheck(tx *gorm.DB, forUpdate bool)

func (*Config) FieldDupInfo

func (cfg *Config) FieldDupInfo(tx *gorm.DB) *FieldDup

FieldDupInfo Create(&Struct), Create(&[]Struct), Create(&[N]Struct) Create(&map[string]any{}), Create(&[]map[string]any{}) Create map[string]any ~ Map[K]V, K(string) is FieldName, V(any) is FieldValue Updates(&Struct) Updates(&map[string]any{}) Updates map[string]any ~ Map[K]V, K(string) is ColumnName, V(any) is FieldValue

func (*Config) GraspSchema added in v1.2.49

func (cfg *Config) GraspSchema(tx *gorm.DB, zeroList ...any)

func (*Config) Initialize

func (cfg *Config) Initialize(tx *gorm.DB) error

func (*Config) Name

func (cfg *Config) Name() string

func (*Config) ParseSchema

func (cfg *Config) ParseSchema(tx *gorm.DB)

func (*Config) TenantInfo

func (cfg *Config) TenantInfo(tx *gorm.DB) *Tenant

type Field

type Field struct {
	Name    string
	DBTable string
	DBName  string
	Value   any
	Values  []any
}

func DeletedAt deprecated

func DeletedAt(schema *gormschema.Schema) *Field

Deprecated: use clause.Interface instead

func FieldFromSchema

func FieldFromSchema(field *gormschema.Field) Field

func (Field) Clause

func (f Field) Clause() clause.Expression

func (Field) ClauseEq

func (f Field) ClauseEq() clause.Eq

func (Field) ClauseIn

func (f Field) ClauseIn() clause.IN

type FieldDup

type FieldDup struct {
	Tenant      *Tenant
	Clauses     []clause.Interface
	DBTable     string
	FieldColumn map[string]string
	ColumnField map[string]string
	Groups      map[string][]string // Groups[key] -> FieldGroup
}

func (*FieldDup) Create

func (d *FieldDup) Create(tx *gorm.DB)

func (*FieldDup) Update

func (d *FieldDup) Update(tx *gorm.DB)

type FieldDupError

type FieldDupError interface {
	error
	DBTable() string
	TenantDBName() string
	TenantValue() any
	DupDBName() []string
}

type SessionConfig

type SessionConfig struct {
	DisableFieldDup          bool // effect on create and update
	ComplexFieldDup          bool // effect on create
	DeleteAllowTenantAll     bool // effect on delete, only tenant and soft_delete, no other where clause
	BeforeDeleteDoQuery      bool // effect on delete
	UpdateAllowTenantAll     bool // effect on update, only tenant and soft_delete, no other where clause
	UpdateOmitMapZeroElemKey bool // effect on update
	AfterCreateShowTenant    bool // effect on create
	AfterQueryShowTenant     bool // effect on query
	BeforeQueryOmitField     bool // effect on query
}

func GetSessionConfig

func GetSessionConfig(cfg *Config, tx *gorm.DB) SessionConfig

type Tenant

type Tenant struct {
	Field Field
}

func (*Tenant) AddClause added in v1.2.49

func (t *Tenant) AddClause(tx *gorm.DB)

func (*Tenant) Build added in v1.2.49

func (t *Tenant) Build(_ clause.Builder)

func (*Tenant) MergeClause added in v1.2.49

func (t *Tenant) MergeClause(_ *clause.Clause)

func (*Tenant) ModifyStatement added in v1.2.49

func (t *Tenant) ModifyStatement(stmt *gorm.Statement)

func (*Tenant) Name added in v1.2.49

func (t *Tenant) Name() string

Jump to

Keyboard shortcuts

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