orm

package
v0.0.0-...-a8c716a Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Migrate = &Migration{
	version: make(map[int]func(db *gorm.DB, version string) error),
}

Functions

func GetFilename

func GetFilename(s string) int

GetFilename 获取迁移文件里名前的版本号

func GetGormConfig

func GetGormConfig() *gorm.Config

Types

type Client

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

func NewOrm

func NewOrm(conn *MysqlConfig, orm *gorm.Config) (*Client, error)

NewOrm 创建数据库连接对象

func (*Client) Conn

func (cli *Client) Conn() *sql.DB

Conn 获取通用数据库对象 sql.DB

func (*Client) DB

func (cli *Client) DB() *gorm.DB

func (*Client) Ping

func (cli *Client) Ping() error

func (*Client) Stats

func (cli *Client) Stats() sql.DBStats

Stats 返回数据库统计信息

type Migration

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

Migration 定义数据库迁移对象

func (*Migration) GetDb

func (e *Migration) GetDb() *gorm.DB

GetDb 获取需要迁移的数据库连接

func (*Migration) Migrate

func (e *Migration) Migrate()

Migrate 执行迁移文件

func (*Migration) SetVersion

func (e *Migration) SetVersion(k int, f func(db *gorm.DB, version string) error)

SetVersion 设置需要迁移的文件

type MigrationVersion

type MigrationVersion struct {
	Version   string    `gorm:"primaryKey"`
	ApplyTime time.Time `gorm:"autoCreateTime"`
}

MigrationVersion 数据前一版本表 nolint

func (MigrationVersion) TableName

func (MigrationVersion) TableName() string

type MysqlConfig

type MysqlConfig struct {
	Host     string        `json:"host"` // ip:port
	Username string        `json:"username"`
	Passwd   string        `json:"passwd"`
	DB       string        `json:"db"`
	Timeout  time.Duration `json:"timeout"` // 设置了连接可复用的最大时间
	MaxIdle  int           `json:"maxIdle"` // 设置空闲连接池中连接的最大数量
	MaxOpen  int           `json:"MaxOpen"` // 设置打开数据库连接的最大数量
	IsDebug  bool          `json:"isDebug"`
}

MysqlConfig 定义数据库连接配置

Jump to

Keyboard shortcuts

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