db

package
v0.0.0-...-479da69 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2022 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DriverNameMysql      = "mysql"      //数据库类型标识:mysql
	DriverNamePostgres   = "postgres"   //数据库类型标识:postgres sql
	DriverNameSqlite     = "sqlite"     //数据库类型标识:sqlite
	DriverNameSqlserver  = "sqlserver"  //数据库类型标识:sqlserver
	DriverNameClickhouse = "clickhouse" //数据库类型标识:clickhouse

)

数据库类型标识

Variables

This section is empty.

Functions

func ExampleUsage

func ExampleUsage()

ExampleUsage 使用示例

func GetInstance

func GetInstance() *gorm.DB

GetInstance 获取数据库实例

func InitDB

func InitDB(conf Conf)

InitDB 初始化数据库连接

Types

type ClickhouseConf

type ClickhouseConf struct {
	Host         string `yaml:"host" toml:"host" json:"host" default:"localhost"`                     //主机地址
	Port         int    `yaml:"port" toml:"port" json:"port" default:"9000"`                          //端口
	Username     string `yaml:"username" toml:"username" json:"username"`                             //用户名
	Password     string `yaml:"password" toml:"password" json:"password"`                             //密码
	Database     string `yaml:"database" toml:"database" json:"database"`                             //数据库名
	ReadTimeout  int    `yaml:"read_timeout" toml:"read_timeout" json:"read_timeout" default:"20"`    //读取超时时间
	WriteTimeout int    `yaml:"write_timeout" toml:"write_timeout" json:"write_timeout" default:"20"` //写入超时时间
}

ClickhouseConf clickhouse配置

type Conf

type Conf struct {
	DriverName string         `yaml:"diver_name" toml:"diver_name" json:"diver_name" default:"mysql"` //数据库类型
	Mysql      MysqlConf      `yaml:"mysql" toml:"mysql" json:"mysql"`                                //mysql配置
	Postgres   PostgresConf   `yaml:"postgres" toml:"postgres" json:"postgres"`                       //postgres配置
	Sqlserver  SqlserverConf  `yaml:"sqlserver" toml:"sqlserver" json:"sqlserver"`                    //sqlserver配置
	Sqlite     SqliteConf     `yaml:"sqlite" toml:"sqlite" json:"sqlite"`                             //sqlite配置
	Clickhouse ClickhouseConf `yaml:"clickhouse" toml:"clickhouse" json:"clickhouse"`                 //clickhouse配置
}

Conf 配置信息

func (Conf) GenDialector

func (conf Conf) GenDialector() gorm.Dialector

GenDialector 生成数据库连接方言(驱动)

type MysqlConf

type MysqlConf struct {
	Host      string `yaml:"host" toml:"host" json:"host" default:"localhost"`           //主机地址
	Port      int    `yaml:"port" toml:"port" json:"port" default:"3306"`                //端口
	Username  string `yaml:"username" toml:"username" json:"username"`                   //用户名
	Password  string `yaml:"password" toml:"password" json:"password"`                   //密码
	Database  string `yaml:"database" toml:"database" json:"database"`                   //数据库名
	Charset   string `yaml:"charset" toml:"charset" json:"charset"`                      //字符集
	ParseTime bool   `yaml:"parseTime" toml:"parseTime" json:"parseTime" default:"true"` //是否解析时间
	Loc       string `yaml:"loc" toml:"loc" json:"loc" default:"Local"`                  //位置
}

MysqlConf mysql配置

type PostgresConf

type PostgresConf struct {
	Host     string `yaml:"host" toml:"host" json:"host" default:"localhost"`                 //主机地址
	Port     int    `yaml:"port" toml:"port" json:"port" default:"9920"`                      //端口
	Username string `yaml:"username" toml:"username" json:"username"`                         //用户名
	Password string `yaml:"password" toml:"password" json:"password"`                         //密码
	Database string `yaml:"database" toml:"database" json:"database"`                         //数据库名
	SSLMode  string `yaml:"ssl_mode" toml:"ssl_mode" json:"ssl_mode"`                         //ssl模式 enable|disable
	TimeZone string `yaml:"timezone" toml:"timezone" json:"timezone" default:"Asia/Shanghai"` //时区
}

PostgresConf postgres配置

type SqliteConf

type SqliteConf struct {
	File string `yaml:"file" toml:"file" json:"file" default:"sqlite.db"` //数据库文件
}

SqliteConf sqlite配置

type SqlserverConf

type SqlserverConf struct {
	Host     string `yaml:"host" toml:"host" json:"host" default:"localhost"` //主机地址
	Port     int    `yaml:"port" toml:"port" json:"port" default:"9930"`      //端口
	Username string `yaml:"username" toml:"username" json:"username"`         //用户名
	Password string `yaml:"password" toml:"password" json:"password"`         //密码
	Database string `yaml:"database" toml:"database" json:"database"`         //数据库名
}

SqlserverConf sqlserver配置

Jump to

Keyboard shortcuts

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