Documentation
¶
Index ¶
- Constants
- Variables
- func GetAccount(username, password string) string
- func GetAddr(host string, port uint16) string
- type ConnConfig
- type Dialect
- type FlashDB
- func (d FlashDB) BuildDSN() string
- func (d FlashDB) BuildFullDSN(username, password string) string
- func (FlashDB) ChangeDb(database string) (bool, error)
- func (FlashDB) ImporterPath() string
- func (FlashDB) IsXormDriver() bool
- func (FlashDB) Name() string
- func (FlashDB) QuoteIdent(ident string) string
- type Mysql
- type Postgres
- func (d Postgres) BuildDSN() string
- func (d Postgres) BuildFullDSN(username, password string) string
- func (d *Postgres) ChangeDb(database string) (bool, error)
- func (Postgres) ImporterPath() string
- func (Postgres) IsXormDriver() bool
- func (Postgres) Name() string
- func (Postgres) QuoteIdent(ident string) string
- type Redis
- type RepeatConfig
- type Sqlite
- func (d Sqlite) BuildDSN() string
- func (d Sqlite) BuildFullDSN(username, password string) string
- func (Sqlite) ChangeDb(database string) (bool, error)
- func (Sqlite) ImporterPath() string
- func (d Sqlite) IsMemory() bool
- func (Sqlite) IsXormDriver() bool
- func (Sqlite) Name() string
- func (Sqlite) QuoteIdent(ident string) string
Constants ¶
View Source
const DIALECT_DEFAULT_HOST = "127.0.0.1"
View Source
const FLASHDB_DEFAULT_PORT uint16 = 8000
View Source
const MYSQL_DEFAULT_PORT uint16 = 3306
View Source
const PGSQL_DEFAULT_PORT uint16 = 5432
View Source
const REDIS_DEFAULT_PORT uint16 = 6379
Variables ¶
View Source
var ( ConcatWith = utils.ConcatWith WrapWith = utils.WrapWith Escape = url.QueryEscape )
Functions ¶
Types ¶
type ConnConfig ¶
type ConnConfig struct {
Type string `hcl:"type,label" json:"type"` // 数据库类型
Key string `hcl:"key,label" json:"key"` // 数据库连接名
LogFile string `hcl:"log_file,optional" json:"log_file,omitempty"`
Username string `hcl:"username,optional" json:"username,omitempty"`
Password string `hcl:"password,optional" json:"password,omitempty"`
DSN string `hcl:"dsn,optional" json:"dsn,omitempty"`
Options url.Values `hcl:"options,optional" json:"options,omitempty"`
Remain hcl.Body `hcl:",remain"`
Dialect Dialect
}
ConnConfig 连接配置
func RepeatConns ¶
func RepeatConns(reps []RepeatConfig, conns []ConnConfig) (adds []ConnConfig)
RepeatConns 复制配置
func (ConnConfig) CopyIt ¶
func (c ConnConfig) CopyIt(key string) ConnConfig
CopyIt 复制一份完整配置,但修改它的连接名
func (ConnConfig) QuickConnect ¶
func (c ConnConfig) QuickConnect(logsql, verbose bool) *xorm.Engine
QuickConnect 连接数据库,需要先导入对应驱动
type Dialect ¶
type Dialect interface {
Name() string // 驱动名
ImporterPath() string // 驱动支持库
IsXormDriver() bool // 是否Xorm支持的驱动
QuoteIdent(ident string) string // 字段或表名脱敏
ChangeDb(database string) (bool, error) // 切换数据库
BuildDSN() string // 生成DSN连接串
BuildFullDSN(username, password string) string // 生成带账号的完整DSN
}
Dialect 不同数据库的驱动配置
func CreateDialectByName ¶
CreateDialectByName 根据名称创建驱动配置
type FlashDB ¶
type FlashDB struct {
Path string `hcl:"path,optional" json:"path,omitempty"`
EvictionInterval int `hcl:"eviction_interval,optional" json:"eviction_interval,omitempty"`
}
FlashDB 一个golang写的类似redis的缓存
func (FlashDB) BuildFullDSN ¶
BuildFullDSN 生成带账号的完整DSN
type Mysql ¶
type Mysql struct {
Host string `hcl:"host" json:"host"`
Port uint16 `hcl:"port,optional" json:"port,omitempty"`
Database string `hcl:"database,optional" json:"database,omitempty"`
}
MySQL或MariaDB数据库
func (Mysql) BuildFullDSN ¶
BuildFullDSN 生成带账号的完整DSN
type Postgres ¶
type Postgres struct {
Host string `hcl:"host" json:"host"`
Port uint16 `hcl:"port,optional" json:"port,omitempty"`
Database string `hcl:"database,optional" json:"database,omitempty"`
Sslmode string `hcl:"sslmode,optional" json:"sslmode,omitempty"` // 例如 disable
}
PostgreSQL数据库
func (Postgres) BuildFullDSN ¶
BuildFullDSN 生成带账号的完整DSN
type Redis ¶
type Redis struct {
Host string `hcl:"host" json:"host"`
Port uint16 `hcl:"port,optional" json:"port,omitempty"`
Database int `hcl:"database,optional" json:"database,omitempty"`
}
Redis缓存
func (Redis) BuildFullDSN ¶
BuildFullDSN 生成带账号的完整DSN
type RepeatConfig ¶
type RepeatConfig struct {
Type string `hcl:"type,label" json:"type"`
Key string `hcl:"key" json:"key"`
DbPrefix string `hcl:"db_prefix,optional" json:"db_prefix,omitempty"`
DbNames []string `hcl:"db_names,optional" json:"db_names,omitempty"`
}
RepeatConfig 复制连接参数,只有数据库不同,目前只支持Mysql/Postgres/Redis
type Sqlite ¶
type Sqlite struct {
Path string `hcl:"path,optional" json:"path"`
}
SQLite3数据库
func (Sqlite) BuildFullDSN ¶
BuildFullDSN 生成带账号的完整DSN
Click to show internal directories.
Click to hide internal directories.