gocloud.dev: gocloud.dev/mysql Index | Examples | Files | Directories

package mysql

import "gocloud.dev/mysql"

Package mysql provides functions to open MySQL databases with OpenCensus instrumentation.



Package Files



const Scheme = "mysql"

Scheme is the URL scheme this package registers its URLOpener under on DefaultMux.

func ConfigFromURL Uses

func ConfigFromURL(u *url.URL) (cfg *mysql.Config, err error)

ConfigFromURL creates a mysql.Config from URL.

func Open Uses

func Open(ctx context.Context, urlstr string) (*sql.DB, error)

Open opens the bucket identified by the URL given. URL openers must be registered in the DefaultURLMux, which is typically done in driver packages' initialization.

See the URLOpener documentation in driver subpackages for more details on supported scheme(s) and URL parameter(s).


// PRAGMA: This example is used on gocloud.dev; PRAGMA comments adjust how it is shown and can be ignored.
// PRAGMA: On gocloud.dev, hide lines until the next blank line.
ctx := context.Background()

// Replace this with your actual settings.
db, err := mysql.Open(ctx, "mysql://user:password@localhost/testdb")
if err != nil {
defer db.Close()

// Use database in your program.
db.Exec("CREATE TABLE foo (bar INT);")

type MySQLURLOpener Uses

type MySQLURLOpener interface {
    OpenMySQLURL(ctx context.Context, u *url.URL) (*sql.DB, error)

A type that implements MySQLURLOpener can open connection based on a URL. The opener must not modify the URL argument. OpenMySQLURL must be safe to call from multiple goroutines.

This interface is generally implemented by types in driver packages.

type URLMux Uses

type URLMux struct {
    // contains filtered or unexported fields

URLMux is a URL opener multiplexer. It matches the scheme of the URLs against a set of registered schemes and calls the opener that matches the URL's scheme.

The zero value is a multiplexer with no registered schemes.

func DefaultURLMux Uses

func DefaultURLMux() *URLMux

DefaultURLMux returns the URLMux used by OpenMySql.

Driver packages can use this to register their MySQLURLOpener on the mux.

func (*URLMux) OpenMySQL Uses

func (mux *URLMux) OpenMySQL(ctx context.Context, urlstr string) (*sql.DB, error)

OpenMySQL calls OpenMySQLURL with the URL parsed from urlstr. OpenMySQL is safe to call from multiple goroutines.

func (*URLMux) OpenMySQLURL Uses

func (mux *URLMux) OpenMySQLURL(ctx context.Context, u *url.URL) (*sql.DB, error)

OpenMySQLURL dispatches the URL to the opener that is registered with the URL's scheme. OpenMySQLURL is safe to call from multiple goroutines.

func (*URLMux) RegisterMySQL Uses

func (mux *URLMux) RegisterMySQL(scheme string, opener MySQLURLOpener)

RegisterMySQL registers the opener with the given scheme. If an opener already exists for the scheme, RegisterMySQL panics.

type URLOpener Uses

type URLOpener struct {
    TraceOpts []ocsql.TraceOption

URLOpener opens URLs like "mysql://" by using the underlying MySQL driver. See https://godoc.org/github.com/lib/pq#hdr-Connection_String_Parameters for details.

func (*URLOpener) OpenMySQLURL Uses

func (uo *URLOpener) OpenMySQLURL(_ context.Context, u *url.URL) (*sql.DB, error)

OpenMySQLURL opens a new database connection wrapped with OpenCensus instrumentation.


awsmysqlPackage awsmysql provides connections to AWS RDS MySQL instances.
azuremysqlPackage azuremysql provides connections to Azure Database for MySQL.
gcpmysqlPackage gcpmysql provides connections to managed MySQL Cloud SQL instances.

Package mysql imports 9 packages (graph) and is imported by 3 packages. Updated 2020-09-12. Refresh now. Tools for package owners.