Skip to content
/ mysql-go Public archive
forked from rocketlaunchr/mysql-go

Make mysql cancelation a breeze

License

Notifications You must be signed in to change notification settings

dati-mipt/mysql-go

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Canceling MySQL in Go

A MySQL-Driver for Go's database/sql package which properly implement context cancelation for MySQL.

See Article for details of the behind-the-scenes magic.



Features

  • Wrapper over standard Go MySQL Driver
  • Automatic killing queries on context cancellation
  • Automatic connection pooling (by database/sql package)

Requirements

The same as for imported version of Go MySQL Driver


Installation

Simple install the package to your $GOPATH with the go tool from shell:

$ go get -u github.com/dati-mipt/mysql-go

Make sure Git is installed on your machine and in your system's PATH.

Usage

This is implementation of Go's database/sql/driver interface. You only need to import the driver and can use the full database/sql API then.

Use mysqlc as driverName and a valid DSN as dataSourceName:

import (
	"database/sql"
	"time"

	_ "github.com/dati-mipt/mysql-go"
)

// ...

db, err := sql.Open("mysqlc", "user:password@/dbname")
if err != nil {
	panic(err)
}
// See "Important settings" section.
db.SetConnMaxLifetime(time.Minute * 3)
db.SetMaxOpenConns(10)
db.SetMaxIdleConns(10)

Examples are available in Wiki of standard mysql driver.

DSN (Data Source Name)

The Data Source Name has a common format, like e.g. PEAR DB uses it, but without type-prefix (optional parts marked by squared brackets):

[username[:password]@][protocol[(address)]]/dbname[?param1=value1&...&paramN=valueN]

Parameters

Parameters are case-sensitive!

In addition to Go MySQL Driver parameters, this wrapper introduces some new params:

killPoolSize
Type:          decimal number
Default:       1

Size of connection pool for killing queries.

killTimeout
Type:           duration
Default:        5s

Timeout of kill operation.

Cancel Query

Cancel the context. This will send a KILL signal to MySQL automatically.

License

The license is a modified MIT license. Refer to LICENSE file for more details.

© 2018-19 PJ Engineering and Business Solutions Pty. Ltd.

Final Notes

Feel free to enhance features by issuing pull-requests.

About

Make mysql cancelation a breeze

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 100.0%