Help us shape the future of Go! Take the 2026 Go Developer Survey

mysql

package
v2.17.1 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: AGPL-3.0 Imports: 17 Imported by: 0

Documentation

Overview

Package mysql provides an interface for writing to a MySQL instance.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterDatabaseClient

func RegisterDatabaseClient(i do.Injector)

RegisterDatabaseClient registers a database.Client with the injector. Prerequisite: database.ClientConfig must be registered (e.g. via databasecfg.RegisterClientConfig).

Types

type Client

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

Client is the primary database querying client.

func NewDatabaseClient

func NewDatabaseClient(ctx context.Context, cfg database.ClientConfig, opts ...Option) (*Client, error)

NewDatabaseClient provides a new DataManager client. If a metrics provider is supplied via WithMetricsProvider, the DB driver will use it so SQL latency and other db.sql.* metrics are emitted (e.g. db_sql_latency_milliseconds_bucket in Prometheus).

func (*Client) Close

func (q *Client) Close() error

Close closes the database connection.

func (*Client) CurrentTime

func (q *Client) CurrentTime() time.Time

CurrentTime reads the clock this client was built with.

func (*Client) Dialect

func (*Client) Dialect() dialect.Dialect

Dialect reports the SQL dialect this client speaks, which is always dialect.MySQL.

func (*Client) IsReady

func (q *Client) IsReady(ctx context.Context) bool

IsReady returns whether the database is ready for the querier.

func (*Client) ReadDB

func (q *Client) ReadDB() *sql.DB

ReadDB provides the database object.

func (*Client) Reader

func (q *Client) Reader() database.SQLQueryExecutor

Reader returns a non-transactional executor for the read database.

func (*Client) RollbackTransaction

func (q *Client) RollbackTransaction(ctx context.Context, tx database.SQLQueryExecutorAndTransactionManager)

RollbackTransaction rolls tx back, recording a failure on a span rather than returning it.

func (*Client) WithTransaction

func (q *Client) WithTransaction(ctx context.Context, fn func(tx database.Tx) error) error

WithTransaction runs fn inside a transaction on the write database, committing on a nil return and rolling back on error or panic. See database.RunInTransaction.

func (*Client) WithTransactionOptions added in v2.9.0

func (q *Client) WithTransactionOptions(ctx context.Context, fn func(tx database.Tx) error, opts ...database.TxOption) error

WithTransactionOptions is WithTransaction configured by opts, which satisfies database.TxOptionsAccess. Callers reach it through database.WithTransaction.

func (*Client) WriteDB

func (q *Client) WriteDB() *sql.DB

WriteDB provides the database object. It satisfies database.RawAccess; prefer Writer and WithTransaction on the Client interface.

func (*Client) Writer

func (q *Client) Writer() database.SQLQueryExecutor

Writer returns a non-transactional executor for the write database.

type Option

type Option func(*options)

Option configures the database client this package constructs. The zero configuration works: an absent logger logs nowhere, an absent tracer provider traces nowhere, and an absent metrics provider emits no metrics.

func WithLogger

func WithLogger(logger logging.Logger) Option

WithLogger attaches a logger.

func WithMetricsProvider

func WithMetricsProvider(metricsProvider metrics.Provider) Option

WithMetricsProvider attaches a metrics provider; the DB driver uses it to emit SQL latency and other db.sql.* metrics.

func WithTracerProvider

func WithTracerProvider(tracerProvider tracing.Provider) Option

WithTracerProvider attaches a tracer provider, enabling spans on every database operation.

Directories

Path Synopsis
Package tableaccess is the MySQL database.Manager: the administrative surface that creates users and databases and grants table privileges, as distinct from the query path a database.Client serves.
Package tableaccess is the MySQL database.Manager: the administrative surface that creates users and databases and grants table privileges, as distinct from the query path a database.Client serves.

Jump to

Keyboard shortcuts

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