Documentation
¶
Index ¶
- Variables
- func ChooseDB(cfg *config.DatabaseConfig) (*gorm.DB, error)
- func CloseDB(db *gorm.DB) error
- func GetDB() *gorm.DB
- func InitDB(cfg *config.DatabaseConfig)
- func SetDBConns(cfg *config.DatabaseConfig, db *gorm.DB)
- type DatabaseConnection
- type MySQLConnection
- type PostgreSQLConnection
- type SQLiteConnection
Constants ¶
This section is empty.
Variables ¶
View Source
var DB *gorm.DB
DB 用于存储全局数据库连接实例
Functions ¶
Types ¶
type DatabaseConnection ¶
type DatabaseConnection interface {
Open(cfg *config.DatabaseConfig) (*gorm.DB, error)
ConfigureConnection(db *gorm.DB, cfg *config.DatabaseConfig)
}
DatabaseConnection 接口定义数据库连接的基本方法
type MySQLConnection ¶
type MySQLConnection struct{}
MySQLConnection 用于 MySQL 数据库的连接
func (*MySQLConnection) ConfigureConnection ¶
func (m *MySQLConnection) ConfigureConnection(db *gorm.DB, cfg *config.DatabaseConfig)
func (*MySQLConnection) Open ¶
func (m *MySQLConnection) Open(cfg *config.DatabaseConfig) (*gorm.DB, error)
type PostgreSQLConnection ¶
type PostgreSQLConnection struct{}
PostgreSQLConnection 用于 PostgreSQL 数据库的连接
func (*PostgreSQLConnection) ConfigureConnection ¶
func (p *PostgreSQLConnection) ConfigureConnection(db *gorm.DB, cfg *config.DatabaseConfig)
func (*PostgreSQLConnection) Open ¶
func (p *PostgreSQLConnection) Open(cfg *config.DatabaseConfig) (*gorm.DB, error)
type SQLiteConnection ¶
type SQLiteConnection struct{}
SQLiteConnection 用于 SQLite 数据库的连接
func (*SQLiteConnection) ConfigureConnection ¶
func (s *SQLiteConnection) ConfigureConnection(db *gorm.DB, cfg *config.DatabaseConfig)
func (*SQLiteConnection) Open ¶
func (s *SQLiteConnection) Open(cfg *config.DatabaseConfig) (*gorm.DB, error)
Click to show internal directories.
Click to hide internal directories.