mysql

package
v0.0.0-...-0871eb3 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ColumnForSQL

func ColumnForSQL(s interface{}) string

ColumnForSQL is to scan struct data for get column tag

func New

func New(host, dbname, user, pass string, port uint16) error

New is to create instance

Types

type MS

type MS struct {
	DB         *sql.DB
	Rows       *sql.Rows
	Err        error
	ServerInfo //embeded
}

MS is struct for MySQL

func GetDB

func GetDB() *MS

GetDB is to get instance. singleton architecture

func NewInstance

func NewInstance(host, dbname, user, pass string, port uint16) (*MS, error)

NewInstance makes a new instance

func (*MS) Close

func (ms *MS) Close()

Close is to close connection

func (*MS) Connection

func (ms *MS) Connection() (*sql.DB, error)

Connection is to connect MySQL server Be careful, sql.Open() doesn't return err. Use db.Ping() to check DB condition.

func (*MS) Exec

func (ms *MS) Exec(sql string, args ...interface{}) (int64, error)

Exec is for update and delete

func (*MS) Exec2

func (ms *MS) Exec2(sql string, args ...interface{}) error

Exec2 is for update and delete more simpler than Exec

func (*MS) Insert

func (ms *MS) Insert(sql string, args ...interface{}) (int64, error)

Insert is to insert record

func (*MS) Scan

func (ms *MS) Scan(x interface{}) bool

Scan is to set all extracted data into parameter variable

func (*MS) ScanOne

func (ms *MS) ScanOne(x interface{}) bool

ScanOne is to set a extracted data into parameter variable

func (*MS) Select

func (ms *MS) Select(selectSQL string, args ...interface{}) ([]map[string]interface{}, []string, error)

Select is to get all field you set

func (*MS) SelectCount

func (ms *MS) SelectCount(countSQL string, args ...interface{}) (int, error)

SelectCount is to get number of rows

func (*MS) SelectIns

func (ms *MS) SelectIns(selectSQL string, args ...interface{}) *MS

SelectIns is to get rows and return db instance

func (*MS) SetMaxIdleConns

func (ms *MS) SetMaxIdleConns(n int)

SetMaxIdleConns is to set the maximum number of connections in the idle connection pool.

func (*MS) SetMaxOpenConns

func (ms *MS) SetMaxOpenConns(n int)

SetMaxOpenConns is to set the maximum number of open connections to the database.

type ServerInfo

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

ServerInfo is struct of server information

Jump to

Keyboard shortcuts

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