dialect

package
v1.7.5 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2024 License: LGPL-3.0 Imports: 9 Imported by: 2

Documentation

Index

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

func GetAccount

func GetAccount(username, password string) string

GetAccount 获得账号密码,用于DSN连接串

func GetAddr

func GetAddr(host string, port uint16) string

GetAddr 获得数据库的连接地址和端口,用于TCP协议的数据库连接

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) GetDSN

func (c ConnConfig) GetDSN(full bool) string

GetDSN 获取DSN连接串,可选是否带账号密码

func (*ConnConfig) LoadDialect

func (c *ConnConfig) LoadDialect() Dialect

LoadDialect 加载数据库驱动配置

func (ConnConfig) Name

func (c ConnConfig) Name() string

Name 数据库驱动名

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

func CreateDialectByName(name string) Dialect

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) BuildDSN

func (d FlashDB) BuildDSN() string

BuildDSN 生成DSN连接串

func (FlashDB) BuildFullDSN

func (d FlashDB) BuildFullDSN(username, password string) string

BuildFullDSN 生成带账号的完整DSN

func (FlashDB) ChangeDb

func (FlashDB) ChangeDb(database string) (bool, error)

ChangeDb 切换数据库

func (FlashDB) ImporterPath

func (FlashDB) ImporterPath() string

ImporterPath 驱动支持库

func (FlashDB) IsXormDriver

func (FlashDB) IsXormDriver() bool

IsXormDriver 是否Xorm支持的驱动

func (FlashDB) Name

func (FlashDB) Name() string

Name 驱动名

func (FlashDB) QuoteIdent

func (FlashDB) QuoteIdent(ident string) string

QuoteIdent 字段或表名脱敏

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) BuildDSN

func (d Mysql) BuildDSN() string

BuildDSN 生成DSN连接串

func (Mysql) BuildFullDSN

func (d Mysql) BuildFullDSN(username, password string) string

BuildFullDSN 生成带账号的完整DSN

func (*Mysql) ChangeDb

func (d *Mysql) ChangeDb(database string) (bool, error)

ChangeDb 切换数据库

func (Mysql) ImporterPath

func (Mysql) ImporterPath() string

ImporterPath 驱动支持库

func (Mysql) IsXormDriver

func (Mysql) IsXormDriver() bool

IsXormDriver 是否Xorm支持的驱动

func (Mysql) Name

func (Mysql) Name() string

Name 驱动名

func (Mysql) QuoteIdent

func (Mysql) QuoteIdent(ident string) string

QuoteIdent 字段或表名脱敏

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"`
}

PostgreSQL数据库

func (Postgres) BuildDSN

func (d Postgres) BuildDSN() string

BuildDSN 生成DSN连接串

func (Postgres) BuildFullDSN

func (d Postgres) BuildFullDSN(username, password string) string

BuildFullDSN 生成带账号的完整DSN

func (*Postgres) ChangeDb

func (d *Postgres) ChangeDb(database string) (bool, error)

ChangeDb 切换数据库

func (Postgres) ImporterPath

func (Postgres) ImporterPath() string

ImporterPath 驱动支持库

func (Postgres) IsXormDriver

func (Postgres) IsXormDriver() bool

IsXormDriver 是否Xorm支持的驱动

func (Postgres) Name

func (Postgres) Name() string

Name 驱动名

func (Postgres) QuoteIdent

func (Postgres) QuoteIdent(ident string) string

QuoteIdent 字段或表名脱敏

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) BuildDSN

func (d Redis) BuildDSN() string

BuildDSN 生成DSN连接串

func (Redis) BuildFullDSN

func (d Redis) BuildFullDSN(username, password string) string

BuildFullDSN 生成带账号的完整DSN

func (*Redis) ChangeDb

func (d *Redis) ChangeDb(database string) (bool, error)

ChangeDb 切换数据库

func (Redis) ImporterPath

func (Redis) ImporterPath() string

ImporterPath 驱动支持库

func (Redis) IsXormDriver

func (Redis) IsXormDriver() bool

IsXormDriver 是否Xorm支持的驱动

func (Redis) Name

func (Redis) Name() string

Name 驱动名

func (Redis) QuoteIdent

func (Redis) QuoteIdent(ident string) string

QuoteIdent 字段或表名脱敏

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) BuildDSN

func (d Sqlite) BuildDSN() string

BuildDSN 生成DSN连接串

func (Sqlite) BuildFullDSN

func (d Sqlite) BuildFullDSN(username, password string) string

BuildFullDSN 生成带账号的完整DSN

func (Sqlite) ChangeDb

func (Sqlite) ChangeDb(database string) (bool, error)

ChangeDb 切换数据库

func (Sqlite) ImporterPath

func (Sqlite) ImporterPath() string

ImporterPath 驱动支持库

func (Sqlite) IsMemory added in v1.6.0

func (d Sqlite) IsMemory() bool

IsMemory 是否内存数据库

func (Sqlite) IsXormDriver

func (Sqlite) IsXormDriver() bool

IsXormDriver 是否Xorm支持的驱动

func (Sqlite) Name

func (Sqlite) Name() string

Name 驱动名

func (Sqlite) QuoteIdent

func (Sqlite) QuoteIdent(ident string) string

QuoteIdent 字段或表名脱敏

Jump to

Keyboard shortcuts

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