Categorygithub.com/rocketlaunchr/mysql-go
modulepackage
1.1.3
Repository: https://github.com/rocketlaunchr/mysql-go.git
Documentation: pkg.go.dev

# README

Canceling MySQL in Go GoDoc Go Report Card

This package will properly implement context cancelation for MySQL. Without this package, context cancelation does not actually cancel a MySQL query.

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

The API is designed to resemble the standard library. It is fully compatible with the dbq package which allows for zero boilerplate database operations in Go.

the project to show your appreciation.

Dependencies

Installation

go get -u github.com/rocketlaunchr/mysql-go

QuickStart


import (
   sql "github.com/rocketlaunchr/mysql-go"
)

pool, _ := sql.Open("user:password@tcp(localhost:3306)/db")

Read Query


// Obtain an exclusive connection
conn, err := pool.Conn(ctx)
defer conn.Close() // Return the connection back to the pool

// Perform your read operation.
rows, err := conn.QueryContext(ctx, stmt)
if err != nil {
   return err
}

Write Query


// Obtain an exclusive connection
conn, err := pool.Conn(ctx)
defer conn.Close() // Return the connection back to the pool

// Perform the write operation
tx, err := conn.BeginTx(ctx, nil)

_, err = tx.ExecContext(ctx, stmt)
if err != nil {
   return tx.Rollback()
}

tx.Commit()

Cancel Query

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

It is highly recommended you set a KillerPool when you instantiate the DB object.

The KillerPool is used to call the KILL signal.

Reverse Proxy Support

Checkout the proxy-protection branch if your database is behind a reverse proxy in order to better guarantee that you are killing the correct query.

Other useful packages

  • dataframe-go - Statistics and data manipulation
  • dbq - Zero boilerplate database operations for Go
  • igo - A Go transpiler with cool new syntax such as fordefer (defer for for-loops)
  • react - Build front end applications using Go
  • remember-go - Cache slow database queries

Legal Information

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.

# Functions

Open opens a database specified by its connection information.
OpenDB opens a database using a Connector, allowing drivers to bypass a string based data source name.

# Structs

Conn represents a single database connection rather than a pool of database connections.
DB is a database handle representing a pool of zero or more underlying connections.
Row is the result of calling QueryRow to select a single row.
Rows is the result of a query.
Stmt is a prepared statement.
Tx is an in-progress database transaction.

# Interfaces

SQLBasic is the interface that allows Conn and Stmt to be used.
SQLConn is the interface that allows Conn and Stmt to be used.
SQLTx is the interface that allows Tx to be used.
StdSQLCommon is the interface that allows query and exec interactions with a database.
StdSQLDB is the interface that allows a transaction to be created.
StdSQLDBExtra is the interface that directly maps to a *stdSql.DB.
StdSQLLegacy will potentially be removed in Go 2.
StdSQLTx is the interface that allows a transaction to be committed or rolledback.