gormx

package
v1.2.5 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Mysql      = "mysql"
	Postgres   = "postgres"
	ClickHouse = "clickhouse"
	SqlServer  = "sqlserver"
)

数据库类型

Variables

This section is empty.

Functions

func GetGormDB

func GetGormDB(dsn, dialect string) (gormDb *gorm.DB, err error)

根据dsn生成gormDB

func InitGormCTL added in v1.2.0

func InitGormCTL()

初始化Gorm控制器

Types

type Config

type Config struct {
	Dialect   string `json:"dialect" yaml:"dialect" nacos:"database.dialect"`       // 数据库类型
	Host      string `json:"host" yaml:"host" nacos:"database.host"`                // 数据库Host
	Port      string `json:"port" yaml:"port" nacos:"database.port"`                // 数据库端口
	DbName    string `json:"dbName" yaml:"dbName" nacos:"database.dbName"`          // 数据库名
	UserName  string `json:"userName" yaml:"userName" nacos:"database.userName"`    // 用户名
	Password  string `json:"password" yaml:"password" nacos:"database.password"`    // 密码
	Debug     bool   `json:"debug" yaml:"debug" nacos:"database.debug"`             // 是否开启debug
	InitTable bool   `json:"initTable" yaml:"initTable" nacos:"database.initTable"` // 是否初始化表结构
}

数据源配置

var CONFIG *Config

func (*Config) Format

func (conf *Config) Format() string

配置信息格式化

func (*Config) GetDSN added in v1.2.0

func (conf *Config) GetDSN() (dsn string)

获取数据库连接DSN

func (*Config) NewGormCTL added in v1.2.0

func (conf *Config) NewGormCTL() (ctl *Control, err error)

创建数据库连接

func (*Config) NewGormDB added in v1.2.0

func (conf *Config) NewGormDB() (gormDB *gorm.DB, err error)

创建数据库连接

type Control added in v1.2.4

type Control struct {
	Config *Config
	DB     *gorm.DB
}

Gorm控制器

var CTL *Control

func (*Control) InitTable added in v1.2.4

func (ctl *Control) InitTable(dst interface{}) error

初始化表结构

Jump to

Keyboard shortcuts

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