gormx

package
v1.0.9 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DatabaseDsnMap = map[DBType]string{
	DBTypeSQLite:    "%s",
	DBTypeOracle:    "%s/%s@%s:%d/%s",
	DBTypeMySQL:     "%s:%s@tcp(%s:%d)/%s?parseTime=True&loc=Local&timeout=30s",
	DBTypePostgres:  "user=%s password=%s host=%s port=%d dbname=%s sslmode=disable TimeZone=Asia/Shanghai",
	DBTypeSqlserver: "user id=%s;password=%s;server=%s;port=%d;database=%s;encrypt=disable",
	DBTypeGreenplum: "user=%s password=%s host=%s port=%d dbname=%s sslmode=disable TimeZone=Asia/Shanghai",
}

DatabaseDsnMap 关系型数据库类型 username、password、address、port、dbname

View Source
var JDBCUrlMap = map[DBType]string{
	DBTypeOracle:    "jdbc:oracle:thin:@%s:%d/%s",
	DBTypeMySQL:     "jdbc:mysql://%s:%d/%s?charset=utf8mb4&parseTime=True&loc=Local&timeout=30s",
	DBTypePostgres:  "jdbc:postgresql://%s:%d/%s",
	DBTypeSqlserver: "jdbc:sqlserver://%s:%d;DatabaseName=%s;encrypt=disable",
	DBTypeGreenplum: "jdbc:postgresql://%s:%d/%s",
}

JDBCUrlMap 关系型数据库类型 username、password、address、port、dbname

Functions

func Close

func Close(dbName string) error

func GetDB

func GetDB(name string) (*gorm.DB, error)

func InitConfig

func InitConfig(config *Config) error

func LoadDBInstance

func LoadDBInstance(config *Config) (*gorm.DB, error)

func Ping

func Ping(dbName string) error

Types

type Config

type Config struct {
	DBName          string        `json:"db_name"`  // 数据库名称(要求唯一)
	JDBCUrl         string        `json:"jdbc_url"` // jdbc_url
	DSN             string        `json:"dsn"`      // 数据库连接串
	DBType          DBType        `json:"db_type"`
	Host            string        `json:"host"`
	Port            int           `json:"port"`
	User            string        `json:"user"`
	Password        string        `json:"password"`
	Database        string        `json:"database"`
	MaxOpenConn     int           `json:"max_open_conn"`      // 最大连接数
	MaxIdleConn     int           `json:"max_idle_conn"`      // 最大空闲连接数
	ConnMaxLifeTime time.Duration `json:"conn_max_life_time"` // 连接最大存活时间
	SSLMode         string        `json:"ssl_mode"`
	TimeZone        string        `json:"time_zone"`
	Charset         string        `json:"charset"`
}

Config Database configuration

func GetDBConfig

func GetDBConfig(name string) (*Config, error)

func (*Config) GenDSN

func (c *Config) GenDSN() (dsn string)

func (*Config) GenJDBCUrl

func (c *Config) GenJDBCUrl() (jdbcUrl string)

type DBType

type DBType string
const (
	DBTypeOracle    DBType = "oracle"
	DBTypePostgres  DBType = "postgres"
	DBTypeMySQL     DBType = "mysql"
	DBTypeSqlserver DBType = "sqlserver"
	DBTypeGreenplum DBType = "greenplum"
	DBTypeSQLite    DBType = "sqlite"
)

type DBWrapper

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

type LogMode

type LogMode string

Jump to

Keyboard shortcuts

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