dbx

package
v0.1.18 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2022 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DBXContext   ContextKey = "dbx-context"
	SQLLiteType             = "sqllite"
	MysqlType               = "mysql"
	PostgresType            = "postgres"
	DB           *gorm.DB
)

Functions

func FromCtx

func FromCtx(ctx context.Context) *gorm.DB

func Init

func Init(c *Config)

func InjectCtx

func InjectCtx(ctx context.Context, db *gorm.DB) context.Context

func MysqlMigrate added in v0.1.14

func MysqlMigrate(ctx context.Context, tenants ...string) error

func PGMigrate added in v0.1.14

func PGMigrate(ctx context.Context, tenants ...string) error

func RegisterModel

func RegisterModel(m interface{}, initialValue ...interface{})

func SessionCtx

func SessionCtx(ctx context.Context) context.Context

func SessionHandler

func SessionHandler(next http.Handler) http.Handler

func WithPagenation added in v0.1.14

func WithPagenation(pageNum int, pageSize int) func(db *gorm.DB) *gorm.DB

WithPagenation build the gorm condition with page_num and page_size the page_num start from 1

func WithTenant

func WithTenant(tenant string, m interface{}) func(db *gorm.DB) *gorm.DB

Types

type Config

type Config struct {
	Type        string
	DSN         string
	TablePrefix string
	MaxIdleConn int
	MaxOpenConn int
	Logger      logrus.FieldLogger
}

type ContextKey

type ContextKey string

type Model

type Model struct {
	ID        int64 `gorm:"primarykey;autoIncrement:false" example:"1479429646645936128"`
	CreatedAt time.Time
	UpdatedAt time.Time
	DeletedAt *time.Time `gorm:"index"`
	Version   string     `gorm:"type:varchar(50);index"`
}

Jump to

Keyboard shortcuts

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