db

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2020 License: MIT, MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DBConfigFile = "db.conf"

	DBTypeMongo    = "mongo"
	DBTypeMySQL    = "mysql"
	DBTypePostgres = "postgres"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type DBConfig

type DBConfig struct {
	Type          DBType `yaml:"type" json:"type"`                   // 类型:mongo, mysql, postgres ...
	IsInitialized bool   `yaml:"isInitialized" json:"isInitialized"` // 是否初始化
}

数据库配置

func SharedDBConfig

func SharedDBConfig() *DBConfig

取得共享的配置

func (*DBConfig) Save

func (this *DBConfig) Save() error

保存

func (*DBConfig) TypeName

func (this *DBConfig) TypeName() string

数据库名称

type DBType

type DBType = string

数据库配置

type MongoAccessLogConfig

type MongoAccessLogConfig struct {
	CleanHour int `yaml:"cleanHour" json:"cleanHour"` // 清理时间,0-23
	KeepDays  int `yaml:"keepDays" json:"keepDays"`   // 保留挺熟
}

访问日志配置

type MongoConfig

type MongoConfig struct {
	TeaVersion string `yaml:"teaVersion" json:"teaVersion"`

	URI string `yaml:"uri" json:"uri"`

	Scheme                  string             `yaml:"scheme" json:"scheme"`
	Username                string             `yaml:"username" json:"username"`
	Password                string             `yaml:"password" json:"password"`
	Addr                    string             `yaml:"addr" json:"addr"`
	AuthEnabled             bool               `yaml:"authEnabled" json:"authEnabled"`
	AuthMechanism           string             `yaml:"authMechanism" json:"authMechanism"`
	AuthMechanismProperties []*shared.Variable `yaml:"authMechanismProperties" json:"authMechanismProperties"`
	RequestURI              string             `yaml:"requestURI" json:"requestURI"` // @TODO 未来版本需要实现
	DBName                  string             `yaml:"dbName" json:"dbName"`

	PoolSize int `yaml:"poolSize" json:"poolSize"` // 连接池大小
	Timeout  int `yaml:"timeout" json:"timeout"`   // 超时时间(秒)

	// 日志访问配置
	AccessLog *MongoAccessLogConfig `yaml:"accessLog" json:"accessLog"`
}

MongoDB配置

func DefaultMongoConfig

func DefaultMongoConfig() *MongoConfig

默认的MongoDB配置

func LoadMongoConfig

func LoadMongoConfig() (*MongoConfig, error)

加载MongoDB配置

func NewMongoConfig

func NewMongoConfig() *MongoConfig

获取新对象

func (*MongoConfig) AuthMechanismPropertiesMap

func (this *MongoConfig) AuthMechanismPropertiesMap() map[string]string

取得Map形式的认证属性

func (*MongoConfig) AuthMechanismPropertiesString

func (this *MongoConfig) AuthMechanismPropertiesString() string

将认证参数转化为字符串

func (*MongoConfig) ComposeURI

func (this *MongoConfig) ComposeURI() string

组合后的URI

func (*MongoConfig) ComposeURIMask

func (this *MongoConfig) ComposeURIMask(mask bool) string

组合后的URI

func (*MongoConfig) Host

func (this *MongoConfig) Host() string

获取Host

func (*MongoConfig) LoadAuthMechanismProperties

func (this *MongoConfig) LoadAuthMechanismProperties(properties string)

分析认证参数

func (*MongoConfig) ParseFromURI

func (this *MongoConfig) ParseFromURI(uri string) error

从URI中分析配置

func (*MongoConfig) Port

func (this *MongoConfig) Port() int

获取Port

func (*MongoConfig) Save

func (this *MongoConfig) Save() error

保存

func (*MongoConfig) SetAddr

func (this *MongoConfig) SetAddr(host string, port uint)

设置地址

type MySQLAccessLogConfig

type MySQLAccessLogConfig struct {
	CleanHour int `yaml:"cleanHour" json:"cleanHour"` // 清理时间,0-23
	KeepDays  int `yaml:"keepDays" json:"keepDays"`   // 保留挺熟
}

访问日志配置

type MySQLConfig

type MySQLConfig struct {
	DSN string `yaml:"dsn" json:"dsn"`

	Addr     string `yaml:"addr" json:"addr"`
	Username string `yaml:"username" json:"username"`
	Password string `yaml:"password" json:"password"`
	DBName   string `yaml:"dbName" json:"dbName"`

	PoolSize int `yaml:"poolSize" json:"poolSize"`

	// 日志访问配置
	AccessLog *MySQLAccessLogConfig `yaml:"accessLog" json:"accessLog"`
}

MySQL配置

func DefaultMySQLConfig

func DefaultMySQLConfig() *MySQLConfig

默认的MySQL配置

func LoadMySQLConfig

func LoadMySQLConfig() (*MySQLConfig, error)

加载MySQL配置

func NewMySQLConfig

func NewMySQLConfig() *MySQLConfig

获取新MySQL配置对象

func (*MySQLConfig) ComposeDSN

func (this *MySQLConfig) ComposeDSN() string

组合DSN

func (*MySQLConfig) Save

func (this *MySQLConfig) Save() error

保存

type PostgresAccessLogConfig

type PostgresAccessLogConfig struct {
	CleanHour int `yaml:"cleanHour" json:"cleanHour"` // 清理时间,0-23
	KeepDays  int `yaml:"keepDays" json:"keepDays"`   // 保留挺熟
}

访问日志配置

type PostgresConfig

type PostgresConfig struct {
	DSN string `yaml:"dsn" json:"dsn"`

	Addr     string `yaml:"addr" json:"addr"`
	Username string `yaml:"username" json:"username"`
	Password string `yaml:"password" json:"password"`
	DBName   string `yaml:"dbName" json:"dbName"`

	PoolSize int `yaml:"poolSize" json:"poolSize"`

	// 日志访问配置
	AccessLog *PostgresAccessLogConfig `yaml:"accessLog" json:"accessLog"`
}

PostgreSQL配置

func DefaultPostgresConfig

func DefaultPostgresConfig() *PostgresConfig

默认的PostgreSQL配置

func LoadPostgresConfig

func LoadPostgresConfig() (*PostgresConfig, error)

加载PostgreSQL配置

func NewPostgresConfig

func NewPostgresConfig() *PostgresConfig

获取新对象

func (*PostgresConfig) ComposeDSN

func (this *PostgresConfig) ComposeDSN() string

组合DSN

func (*PostgresConfig) Save

func (this *PostgresConfig) Save() error

保存

Jump to

Keyboard shortcuts

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