gormPool

package
v2.2.6 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Pagination

func Pagination(db *gorm.DB, page, size int) *gorm.DB

Pagination 分页

Types

type Common

type Common struct {
	Driver string `yaml:"driver"`
}

type DbSetting

type DbSetting struct {
	Common    *Common           `yaml:"common"`
	MySql     *MySqlSetting     `yaml:"mysql"`
	Postgres  *PostgresSetting  `yaml:"postgres"`
	SqlServer *SqlServerSetting `yaml:"sqlServer"`
}
var DbSet DbSetting

func (DbSetting) New

func (DbSetting) New(path string) *DbSetting

New 初始化:数据库配置

type Dsn

type Dsn struct {
	Name    string
	Content string
}

type MySqlConnection

type MySqlConnection struct {
	Username  string `yaml:"username"`
	Password  string `yaml:"password"`
	Host      string `yaml:"host"`
	Port      uint16 `yaml:"port"`
	Database  string `yaml:"database"`
	Charset   string `yaml:"charset"`
	Collation string `yaml:"collation"`
}

type MySqlPool

type MySqlPool struct {
	// contains filtered or unexported fields
}
var (
	MySqlDsnFormat = "%s:%s@tcp(%s:%d)/%s?charset=%s&parseTime=True&loc=Local"
	MysqlPoolApp   MySqlPool
)

func (*MySqlPool) Close

func (r *MySqlPool) Close() error

Close 关闭数据库链接

func (*MySqlPool) GetConn

func (r *MySqlPool) GetConn() *gorm.DB

GetConn 获取主数据库链接

func (MySqlPool) New

func (MySqlPool) New(dbSetting *DbSetting) *MySqlPool

New 实例化:mysql链接池

type MySqlSetting

type MySqlSetting struct {
	MaxOpenConns int                         `yaml:"maxOpenConns"`
	MaxIdleConns int                         `yaml:"maxIdleConns"`
	MaxLifetime  int                         `yaml:"maxLifetime"`
	MaxIdleTime  int                         `yaml:"maxIdleTime"`
	Rws          bool                        `yaml:"rws"`
	Main         *MySqlConnection            `yaml:"main"`
	Sources      map[string]*MySqlConnection `yaml:"sources"`
	Replicas     map[string]*MySqlConnection `yaml:"replicas"`
}

type PostgresConnection

type PostgresConnection struct {
	Username string `yaml:"username"`
	Password string `yaml:"password"`
	Host     string `yaml:"host"`
	Port     uint16 `yaml:"port"`
	Database string `yaml:"database"`
	TimeZone string `yaml:"timezone"`
	SslMode  string `yaml:"sslmode"`
}

type PostgresPool

type PostgresPool struct {
	// contains filtered or unexported fields
}
var (
	PostgresDsnFormat = "host=%s user=%s password=%s dbname=%s port=%d sslmode=%s TimeZone=%s"
	PostgresPoolApp   PostgresPool
)

func (*PostgresPool) Close

func (r *PostgresPool) Close() error

Close 关闭数据库链接

func (*PostgresPool) GetConn

func (r *PostgresPool) GetConn() *gorm.DB

GetMain 获取主数据库链接

func (PostgresPool) New

func (PostgresPool) New(dbSetting *DbSetting) *PostgresPool

New 实例化:postgres链接池

type PostgresSetting

type PostgresSetting struct {
	MaxOpenConnections int                 `yaml:"maxOpenConns"`
	MaxIdleConnections int                 `yaml:"maxIdleConns"`
	MaxLifetime        int                 `yaml:"maxLifetime"`
	MaxIdleTime        int                 `yaml:"maxIdleTime"`
	Main               *PostgresConnection `yaml:"main"`
}

type SqlServerConnection

type SqlServerConnection struct {
	Username string `yaml:"username"`
	Password string `yaml:"password"`
	Host     string `yaml:"host"`
	Port     uint16 `yaml:"port"`
	Database string `yaml:"database"`
}

type SqlServerPool

type SqlServerPool struct {
	// contains filtered or unexported fields
}
var (
	SqlServerDsnFormat = "sqlserver://%s:%s@%s:?%d?database=%s"
	SqlServerPoolApp   SqlServerPool
)

func (*SqlServerPool) Close

func (r *SqlServerPool) Close() error

Close 关闭数据库链接

func (*SqlServerPool) GetConn

func (r *SqlServerPool) GetConn() *gorm.DB

GetMain 获取主数据库链接

func (SqlServerPool) New

func (SqlServerPool) New(dbSetting *DbSetting) *SqlServerPool

New 实例化:sql server连接池

type SqlServerSetting

type SqlServerSetting struct {
	MaxOpenConnections int                  `yaml:"maxOpenConns"`
	MaxIdleConnections int                  `yaml:"maxIdleConns"`
	MaxLifetime        int                  `yaml:"maxLifetime"`
	MaxIdleTime        int                  `yaml:"maxIdleTime"`
	Main               *SqlServerConnection `yaml:"main"`
}

Jump to

Keyboard shortcuts

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