mysql

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package mysql adapts a MySQL database to the core interfaces. The Adapter (store.DB/Tx) is also reused by the oceanbase provider, since OceanBase speaks the MySQL wire protocol.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewIntrospector

func NewIntrospector(db *sql.DB) introspect.Introspector

NewIntrospector returns an introspect.Introspector backed by db.

Types

type Adapter

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

Adapter wraps *sql.DB for the MySQL protocol, satisfying store.DB and store.TxBeginner. Shared with the oceanbase provider.

func NewAdapter

func NewAdapter(dsn string) (*Adapter, error)

NewAdapter opens a MySQL-compatible database and pings it (fail-fast). It injects sql_safe_updates=1 as a DB-native backstop against full-table UPDATE/DELETE (defense in depth alongside the cost gate's WriteGuard); a DSN that sets sql_safe_updates explicitly is respected.

func NewAdapterWithTimeout

func NewAdapterWithTimeout(dsn string, timeout time.Duration, oceanBaseVariable string) (*Adapter, error)

NewAdapterWithTimeout opens a MySQL-compatible database with a DB-native statement timeout. oceanBaseVariable may be "ob_query_timeout".

func (*Adapter) BeginTx

func (a *Adapter) BeginTx(ctx context.Context, opts *store.TxOptions) (store.Tx, error)

BeginTx implements store.TxBeginner.

func (*Adapter) Close

func (a *Adapter) Close() error

Close closes the pool.

func (*Adapter) DB

func (a *Adapter) DB() *sql.DB

DB exposes the underlying pool (for providers that need it).

func (*Adapter) ExecContext

func (a *Adapter) ExecContext(ctx context.Context, query string, args ...any) (store.Result, error)

ExecContext implements store.DB.

func (*Adapter) PrepareContext

func (a *Adapter) PrepareContext(ctx context.Context, query string) (store.Prepared, error)

PrepareContext implements store.Preparer for MySQL and OceanBase.

func (*Adapter) QueryContext

func (a *Adapter) QueryContext(ctx context.Context, query string, args ...any) (store.Rows, error)

QueryContext implements store.DB.

type Dialect

type Dialect struct{}

Dialect is the MySQL dialect. EXPLAIN estimates are less reliable than PostgreSQL's, so the gate weakens the Estimate layer and leans on EnforceCap + max_execution_time + sql_safe_updates.

func (Dialect) Capabilities

func (Dialect) Capabilities() dialect.Capabilities

func (Dialect) ExplainSQL

func (Dialect) ExplainSQL(q string) string

func (Dialect) Name

func (Dialect) Name() string

func (Dialect) Placeholder

func (Dialect) Placeholder(_ int) string

func (Dialect) QuoteIdent

func (Dialect) QuoteIdent(name string) string

type Introspector

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

Introspector discovers entities from information_schema. Exported so the oceanbase provider can reuse it (OceanBase is MySQL-protocol compatible).

func (Introspector) Discover

func (i Introspector) Discover(ctx context.Context, sources []string) ([]entity.Entity, error)

Discover implements introspect.Introspector. It lists base tables (filtered to the requested schemas in memory) with their columns and primary keys.

type Provider

type Provider struct {
	*Adapter
	// contains filtered or unexported fields
}

Provider adapts a MySQL database to the core interfaces.

func New

func New(dsn string) (*Provider, error)

New opens a MySQL database and assembles the core adapters.

func NewWithTimeout

func NewWithTimeout(dsn string, timeout time.Duration) (*Provider, error)

NewWithTimeout opens MySQL with a DB-native SELECT timeout.

func (*Provider) Dialect

func (p *Provider) Dialect() dialect.Dialect

Dialect returns the MySQL dialect.

func (*Provider) Explainer

func (p *Provider) Explainer() cost.Explainer

Explainer returns the EXPLAIN-based plan estimator.

func (*Provider) Introspector

func (p *Provider) Introspector() introspect.Introspector

Introspector returns the schema introspector.

Jump to

Keyboard shortcuts

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