sqlmore

package module
v0.0.0-...-1a6eb04 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2020 License: MIT Imports: 13 Imported by: 0

README

sqlmore

more about golang db sql

  1. 数据库连接池增强

    • MaxOpenConns:10
    • MaxIdleConns:0
    • ConnMaxLifetime:10s
  2. MySQL增强

    • 自动增强连接属性: charset=utf8mb4&parseTime=true&loc=Local&timeout=10s&writeTimeout=10s&readTimeout=10s
    • 增强GormDB建表选项: db.Set("gorm:table_options", "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4")
    • MySQLDump
  3. ExecSQL

  4. SplitSqls

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CompatibleMySQLDs

func CompatibleMySQLDs(s string) string

CompatibleMySQLDs make mysql datasource be compatible with raw, mysql or gossh host format.

func ContainsIgnoreCase

func ContainsIgnoreCase(a, b string) bool

ContainsIgnoreCase tell if a contains b in case-insensitively

func IfElse

func IfElse(ifCondition bool, ifValue, elseValue string) string

IfElse if else ...

func IsQuerySQL

func IsQuerySQL(sql string) (string, bool)

IsQuerySQL tests a sql is a query or not

func MySQLDump

func MySQLDump(db *sql.DB, writer io.Writer) error

MySQLDump creates a MYSQL Dump based on the options supplied through the dumper.

func SetConnectionPool

func SetConnectionPool(db *sql.DB) *sql.DB

SetConnectionPool 设置连接池常见属性

func SplitSqls

func SplitSqls(sqls string, separate rune) []string

SplitSqls splits sqls by separate

Types

type ExecResult

type ExecResult struct {
	Error        error
	CostTime     time.Duration
	Headers      []string
	Rows         [][]string
	RowsAffected int64
	LastInsertID int64
	IsQuerySQL   bool
	FirstKey     string
}

ExecResult defines the result structure of sql execution.

func ExecSQL

func ExecSQL(db SQLExec, sqlStr string, maxRows int, nullReplace string) ExecResult

ExecSQL executes a SQL

type More

type More interface {
	// Matches 是否匹配当前实现
	Matches() bool
	// EnhanceURI 增强URI
	EnhanceURI(dbURI string) string
	// EnhanceGormDB 增强GormDB
	EnhanceGormDB(db *gorm.DB) *gorm.DB
}

More 为各个数据库增强的接口

type MySQLMore

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

MySQLMore MySQL增强器

func NewMySQLMore

func NewMySQLMore(dbDriver string) *MySQLMore

NewMySQLMore 新建MySQL增强器

func (*MySQLMore) EnhanceGormDB

func (m *MySQLMore) EnhanceGormDB(db *gorm.DB) *gorm.DB

EnhanceGormDB 增强GormDB

func (*MySQLMore) EnhanceURI

func (m *MySQLMore) EnhanceURI(dbURI string) string

EnhanceURI 增强URI

func (*MySQLMore) Matches

func (m *MySQLMore) Matches() bool

Matches 是否匹配当前实现

type SQLExec

type SQLExec interface {
	// Exec execute query.
	Exec(query string, args ...interface{}) (sql.Result, error)
	Query(query string, args ...interface{}) (*sql.Rows, error)
}

SQLExec wraps Exec method.

type SQLMore

type SQLMore struct {

	// DbDriver 原始驱动名称
	DbDriver string
	// EnhancedDbURI 增强后的URI
	EnhancedDbURI string
	// contains filtered or unexported fields
}

SQLMore SQL增强结构体

func NewSQLMore

func NewSQLMore(dbDriver, dbURI string) *SQLMore

NewSQLMore 创建SQL增强器

func (*SQLMore) GormOpen

func (s *SQLMore) GormOpen() (*gorm.DB, error)

GormOpen 打开新的Gorm数据库连接池对象

func (*SQLMore) MustGormOpen

func (s *SQLMore) MustGormOpen() *gorm.DB

MustGormOpen 确保打开新的Gorm数据库连接池对象

func (*SQLMore) MustOpen

func (s *SQLMore) MustOpen() *sql.DB

MustOpen 确保打开新的数据库连接池对象

func (*SQLMore) Open

func (s *SQLMore) Open() (*sql.DB, error)

Open 打开新的数据库连接池对象

Jump to

Keyboard shortcuts

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