database

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var MetadataLoader metadataLoader = metadataLoader{}

Functions

func GetConnection

func GetConnection() *gorm.DB

获取数据库连接

func NewNullTime

func NewNullTime(t time.Time) sql.NullTime

func Transaction

func Transaction(f func(tx *gorm.DB) error) error

事务处理,中途发生异常,进行数据回滚

Types

type BaseModel

type BaseModel struct {
	ID        int          `json:"id" gorm:"column:id;primarykey;"` // 开启了自增长,第一个为“1”
	CreatedAt sql.NullTime `json:"createdAt" gorm:"column:created_at;comment:创建时间"`
	UpdatedAt sql.NullTime `json:"updatedAt" gorm:"column:updated_at;comment:更新时间"`
	DeletedAt sql.NullTime `json:"deletedAt" gorm:"column:deleted_at;index;comment:更新时间"`
}

自定义公共模型参数

type Connect

type Connect interface {
	GenConnect(gormConf *gorm.Config) (*gorm.DB, *sql.DB, error)
}

type DatabaseConfig

type DatabaseConfig struct {
	Enable               bool   `mapstructure:"enable" json:"enable" yaml:"enable"`                                                 // 是否开启
	EnableAutoMigrate    bool   `mapstructure:"enable-auto-migrate" json:"enableAutoMigrate" yaml:"enable-auto-migrate"`            // 是否开启自动生成数据库表
	EnableAutoImportData bool   `mapstructure:"enable-auto-import-data" json:"enableAutoImportData" yaml:"enable-auto-import-data"` // 是否开启自动导入数据
	LogMode              string `mapstructure:"log-mode" json:"logMode" yaml:"log-mode"`                                            // 日志模式

	DBConfig Connect `mapstructure:"-" json:"-" yaml:"-"` // 数据库配置
}

func (DatabaseConfig) Load

func (dbc DatabaseConfig) Load()

Directories

Path Synopsis
connect

Jump to

Keyboard shortcuts

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