gormx

package
v2.0.56 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	MulitDB map[string]*gorm.DB
)

MulitDB 多数据库源

Functions

func AutoMigrate

func AutoMigrate(db *gorm.DB, dbType string) error

AutoMigrate 自动映射数据表

func Check

func Check(db *gorm.DB) (bool, error)

Check 检查数据是否存在

func FindOne

func FindOne(db *gorm.DB, out interface{}) (bool, error)

FindOne 查询单条数据

func FindPage

func FindPage(db *gorm.DB, pp pagination.Param, out interface{}) (int64, error)

FindPage 查询分页数据

func GetAssignDB

func GetAssignDB(dbName string) (*gorm.DB, bool)

GetAssignDB 获取指定数据库连接

func NewDB

func NewDB(c *Config) (*gorm.DB, func(), error)

NewDB 创建DB实例

func NewMulitDB

func NewMulitDB(cs map[string]*Config) (func(), []error)

NewMulitDB 创建多数据源DB实例

func WrapPageQuery

func WrapPageQuery(db *gorm.DB, pp pagination.Param, out interface{}) (int64, error)

WrapPageQuery 包装带有分页的查询

Types

type Config

type Config struct {
	Debug             bool
	DBType            string
	DBName            string
	DSN               string
	MaxLifetime       int
	MaxOpenConns      int
	MaxIdleConns      int
	TablePrefix       string
	EnableAutoMigrate bool
}

Config 数据库配置

type Model added in v2.0.31

type Model struct {
	CreatedAt time.Time  `gorm:"type:timestamp;default:CURRENT_TIMESTAMP;comment:创建时间;" json:"createdAt"`                             // 创建时间
	UpdatedAt time.Time  `gorm:"type:timestamp;default:CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP;comment:更新时间;" json:"updatedAt"` // 更新时间
	DeletedAt *time.Time `gorm:"type:timestamp;index;comment:删除时间;" json:"deletedAt"`                                                 // 删除时间
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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