gormPool

package
v2.21.10 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 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 CbitSqlConnection added in v2.8.0

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

type CbitSqlSetting added in v2.8.0

type CbitSqlSetting struct {
	Database string                        `yaml:"database"`
	Rws      bool                          `yaml:"rws"`
	Main     *MySqlConnection              `yaml:"main"`
	Sources  map[string]*CbitSqlConnection `yaml:"sources"`
	Replicas map[string]*CbitSqlConnection `yaml:"replicas"`
}

type Common

type Common struct {
	Driver             string `yaml:"driver"`
	MaxOpenConnections int    `yaml:"maxOpenConns"`
	MaxIdleConnections int    `yaml:"maxIdleConns"`
	MaxLifetime        int    `yaml:"maxLifetime"`
	MaxIdleTime        int    `yaml:"maxIdleTime"`
}

type DbSetting

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

func (DbSetting) ExampleYaml added in v2.11.2

func (DbSetting) ExampleYaml() string

func (DbSetting) New

func (DbSetting) New(path string) *DbSetting

New 初始化:数据库配置

type Dsn

type Dsn struct {
	Name    string
	Content string
}

type GormPool added in v2.9.0

type GormPool interface {
	GetConn() *gorm.DB

	Close() error
	// contains filtered or unexported methods
}

type MySqlConnection

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

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) Once added in v2.9.0

func (MySqlPool) Once(dbSetting *DbSetting) GormPool

Once 单例化:mysql链接池

type MySqlSetting

type MySqlSetting struct {
	Database  string                      `yaml:"database"`
	Charset   string                      `yaml:"charset"`
	Collation string                      `yaml:"collation"`
	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) Once added in v2.9.0

func (PostgresPool) Once(dbSetting *DbSetting) GormPool

Once 单例化:postgres链接池

type PostgresSetting

type PostgresSetting struct {
	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) Once added in v2.9.0

func (SqlServerPool) Once(dbSetting *DbSetting) GormPool

Once 单例化:sql server连接池

type SqlServerSetting

type SqlServerSetting struct {
	Main *SqlServerConnection `yaml:"main"`
}

Jump to

Keyboard shortcuts

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