gftenant

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: MIT Imports: 9 Imported by: 0

README

GFTENANT 是一个针对Goframe框架的多租户引擎

项目介绍:

  • 目前引擎相对功能封装可能不太完善,后续会持续完善。
  • 支持 column模式和db模式

注意事项:

  • 全项目禁止使用 g.DB()

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	FlagKey    = "TenantFlag"
	ModeNone   = "none"   //关闭
	ModeColumn = "column" //列模式
	ModeDB     = "db"     //数据源模式
)

Functions

func GetColumnName

func GetColumnName() string

func GetTenant

func GetTenant(ctx context.Context) string

GetTenant 获取当前上下文贴牌ID

func Init

func Init(ctx context.Context) gdb.DB

func SetFlag

func SetFlag(ctx context.Context) context.Context

func SetHandle

func SetHandle(i Handle)

func SetTenant

func SetTenant(ctx context.Context, id string) context.Context

SetTenant 设置当前上下文贴牌ID

Types

type Config

type Config struct {
	Mode       string `json:"mode" dc:"none"`            //none 不启用  column 列模式  db 数据库模式
	ColumnName string `json:"columnName" dc:"tenant_id"` //column模式的列名 默认 tenant_id

}

type Handle

type Handle func(tenantId string) (Model, error)

type Model

type Model struct {
	DbName    string `json:"dbName"`    // 数据库名称
	DbAddr    string `json:"dbAddr"`    // 数据库地址
	DbPort    string `json:"dbPort"`    // 数据库端口
	DbAccount string `json:"dbAccount"` // 数据库账号
	DbPass    string `json:"dbPass"`    // 数据库密码
}

type MysqlDriver

type MysqlDriver struct {
	*mysql.Driver
}

func (*MysqlDriver) DoFilter

func (d *MysqlDriver) DoFilter(ctx context.Context, link gdb.Link, sql string, args []interface{}) (newSql string, newArgs []interface{}, err error)

DoFilter is a hook function, which filters the sql and its arguments before it's committed to underlying driver. The parameter `link` specifies the current database connection operation object. You can modify the sql string `sql` and its arguments `args` as you wish before they're committed to driver.

func (*MysqlDriver) New

func (d *MysqlDriver) New(core *gdb.Core, node *gdb.ConfigNode) (gdb.DB, error)

New creates and returns a database object for mysql. It implements the interface of gdb.Driver for extra database driver installation.

Directories

Path Synopsis
internal/dao/internal
========================================================================== Code generated by GoFrame CLI tool.
========================================================================== Code generated by GoFrame CLI tool.

Jump to

Keyboard shortcuts

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