orm

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2024 License: Apache-2.0 Imports: 22 Imported by: 0

README

数据库orm调用基础库

配置示例

[[dbConfig]]
uName = "irentOnlyRead" #必须唯一 方便索引数据库
mark = "正式库只读"
host = "rm-bp1t8o27rta4z4895go.mysql.rds.aliyuncs.com"
user = "read_only"
pass = "r!Gd$8vehqg7Z"
port = "3306"
name = "irent"
# ssh tunnel配置
tunnelSSHHost = "47.108.200.228"
tunnelSSHPort = "22"
tunnelSSHUser = "root"
tunnelSSHPassword = ""
# 秘钥验证 RSA PRIVATE KEY
tunnelSSHKey = "test.pem"
# 秘钥生成时的密码 一般都没有
tunnelSSHPassphrase = ""
# 自定义协议名称
tunnelSSHNetName = "mysql-ssh-tunnel"

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetDb

func GetDb(dbUName string) (*gorm.DB, error)

func ShowSql

func ShowSql(db *gorm.DB)

ShowSql 为数据库连接实例开启sql日志

func TableToStruct

func TableToStruct(dbUName string, tableName string)

TableToStruct 将数据库表 转换为struct结构输出

Types

type DbConf

type DbConf struct {
	DBType    string `yaml:"dbType"`    //数据库类型 默认mysql
	UName     string `yaml:"uName"`     //唯一名称标识
	Mark      string `yaml:"mark"`      //备注
	Host      string `yaml:"host"`      //域名或ip
	User      string `yaml:"user"`      //用户
	Pass      string `yaml:"pass"`      //密码
	Port      string `yaml:"port"`      //端口
	Name      string `yaml:"name"`      //数据库名称
	LogLevel  string `yaml:"logLevel"`  //日志级别 [silent error warn info]
	SlowTime  int    `yaml:"slowTime"`  //慢日志记录时间 单位毫秒
	LogPrefix string `yaml:"logPrefix"` //日志前缀 默认前缀为 "[dbType]-"

	//ssh tunnel加密配置
	TunnelSSHHost string `yaml:"tunnelSSHHost"`
	TunnelSSHPort string `yaml:"tunnelSSHPort"`
	TunnelSSHUser string `yaml:"tunnelSSHUser"`
	//ssh 密码验证
	TunnelSSHPassword string `yaml:"tunnelSSHPassword"`
	// 秘钥验证 RSA PRIVATE KEY
	TunnelSSHKey string `yaml:"tunnelSSHKey"`
	// 秘钥生成时的密码 一般都没有
	TunnelSSHPassphrase string `yaml:"tunnelSSHPassphrase"`
	//自定义连接名名称
	TunnelSSHNetName string `yaml:"tunnelSSHNetName"`
}

DbConf 数据库配置格式

type DbConfigParse

type DbConfigParse struct {
	Dbs []DbConf `yaml:"dbConfig"`
}

type ViaSshDialer

type ViaSshDialer struct {
	// contains filtered or unexported fields
}

func (*ViaSshDialer) Dial

func (v *ViaSshDialer) Dial(ctx context.Context, addr string) (net.Conn, error)

Jump to

Keyboard shortcuts

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