database

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsMySQL

func IsMySQL(db *DB) bool

IsMySQL @Description 判断当前连接是否为 MySQL @Param db *DB @Return bool

func IsSQLite

func IsSQLite(db *DB) bool

IsSQLite @Description 判断当前连接是否为 SQLite @Param db *DB @Return bool

Types

type Config

type Config struct {
	Driver          string // mysql, sqlite
	Host            string
	Port            int
	User            string
	Password        string
	DBName          string
	DSN             string // 自定义 DSN,优先级最高
	Charset         string
	MaxOpenConns    int
	MaxIdleConns    int
	ConnMaxLifetime int // 秒
}

Config @Description 数据库连接配置

type DB

type DB struct {
	Gorm   *gorm.DB
	Driver string
}

DB @Description 数据库连接实例,以 GORM 为主入口

func Connect

func Connect(cfg Config) (*DB, error)

Connect @Description 根据配置创建数据库连接 @Param cfg Config 数据库配置 @Return *DB @Return error

func (*DB) SQL

func (db *DB) SQL() *sql.DB

SQL 返回底层 *sql.DB,用于原始 SQL 操作(migration 等)

Jump to

Keyboard shortcuts

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