database

package
v0.0.0-...-04efeb6 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DB *gorm.DB

DB 用于存储全局数据库连接实例

Functions

func ChooseDB

func ChooseDB(cfg *config.DatabaseConfig) (*gorm.DB, error)

ChooseDB 根据配置选择数据库

func CloseDB

func CloseDB(db *gorm.DB) error

CloseDB 关闭数据库连接

func GetDB

func GetDB() *gorm.DB

GetDB 返回数据库连接实例

func InitDB

func InitDB(cfg *config.DatabaseConfig)

InitDB 初始化数据库连接

func SetDBConns

func SetDBConns(cfg *config.DatabaseConfig, db *gorm.DB)

SetDBConns 设置数据库连接池参数

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

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)

Jump to

Keyboard shortcuts

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