dbmgr

package
v0.0.0-...-1770afa Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2022 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

dbmgr.go

option.go

util.go

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Rows2Map

func Rows2Map(rows *sql.Rows) ([]map[string]interface{}, error)

Rows2Map convers rows to []map[string]interface{} caller call the function rows.Close()

func Sql2Map

func Sql2Map(db *sql.DB, strSql string, args ...interface{}) ([]map[string]interface{}, error)

Sql2Map convers query to []map[string]interface{}

That's a specialty of MySQL: you have to use prepared statements to get the native types. MySQL has two protocols, one transmits everything as text, the other as the "real" type. And that binary protocol is only used when you use prepared statements. The driver is pretty much powerless to enforce a protocol and the text protocol takes less resources on the server.

This may help you:

stmt, err := db.Prepare(sqlString) if err != nil { ...... } defer stmt.Close() rows, err := stmt.Query()

Types

type DB

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

DB database info

func (*DB) Close

func (db *DB) Close() error

func (*DB) DBConn

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

func (*DB) Open

func (db *DB) Open(options ...DBOptionFn) (*sql.DB, error)

type DBMgr

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

func GetDBMgr

func GetDBMgr() *DBMgr

func (*DBMgr) Add

func (dm *DBMgr) Add(dbAlias, driver, dsn string) (*DB, error)

func (*DBMgr) Del

func (dm *DBMgr) Del(dbAlias string)

func (*DBMgr) GetConn

func (dm *DBMgr) GetConn(dbAlias string) (*sql.DB, error)

func (*DBMgr) GetDB

func (dm *DBMgr) GetDB(dbAlias string) (*DB, error)

type DBOptionFn

type DBOptionFn func(*DB)

func WithConnMaxIdleTime

func WithConnMaxIdleTime(d time.Duration) DBOptionFn

func WithConnMaxLifetime

func WithConnMaxLifetime(d time.Duration) DBOptionFn

func WithMaxIdleConns

func WithMaxIdleConns(n int) DBOptionFn

func WithMaxOpenConns

func WithMaxOpenConns(n int) DBOptionFn

Jump to

Keyboard shortcuts

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