mysql

package
v0.1.13 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2026 License: MIT Imports: 20 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 NewAdapter

func NewAdapter(dsn string, opts providerregistry.Options, oceanBaseVariable string) (*sqladapter.Pool, 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) and a DB-native statement timeout: max_execution_time, or the named OceanBase variable when oceanBaseVariable is set. DSN values set explicitly are respected. Behind a transaction-mode pooler arguments are interpolated by the driver instead of server-side prepared statements, which a pooler may not keep. The adapter is shared with the oceanbase provider.

func NewIntrospector

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

NewIntrospector returns an introspect.Introspector backed by db.

func ParseExplain added in v0.1.12

func ParseExplain(b []byte) (cost.Plan, error)

ParseExplain parses MySQL EXPLAIN FORMAT=JSON output (OceanBase may mirror it), degrading on surprise. The tables a query reads may sit under grouping, ordering or join steps, so the plan is as risky as the worst access among them, and estimates the most rows any table is scanned for or a join produces; a sort or temporary table at any step counts.

Types

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) 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 and views of the requested schemas (by default the current database, where unqualified names resolve) with their columns, keys, foreign keys and write effects.

func (Introspector) Physical added in v0.1.11

func (i Introspector) Physical(ctx context.Context) (introspect.Physical, error)

Physical implements introspect.PhysicalNamer: the server UUID (unknown when the server does not report one, as OceanBase may not) and whether table names compare case-insensitively.

func (Introspector) ProcedurePrivilege added in v0.1.11

func (i Introspector) ProcedurePrivilege(ctx context.Context, schema, _ string) (introspect.Privilege, error)

ProcedurePrivilege implements introspect.PrivilegeInspector. A grant on one routine is not listed in information_schema, so without a global or database-level EXECUTE the answer is unknown.

func (Introspector) ReadOnly added in v0.1.11

func (i Introspector) ReadOnly(ctx context.Context) (bool, error)

ReadOnly implements introspect.PrivilegeInspector: read_only or super_read_only (a replica), which refuse every write of an ordinary account.

func (Introspector) Schemas added in v0.1.11

func (i Introspector) Schemas(ctx context.Context) ([]string, string, error)

Schemas implements introspect.SchemaLister: every database except the system ones, and the connection's current database.

func (Introspector) TablePrivileges added in v0.1.11

func (i Introspector) TablePrivileges(
	ctx context.Context, schema string, tables []string,
) (map[string]introspect.TablePrivileges, error)

TablePrivileges implements introspect.PrivilegeInspector.

type Provider

type Provider struct{ sqladapter.Base }

Provider adapts a MySQL database to the core interfaces.

func NewWithTimeout

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

NewWithTimeout opens MySQL with a DB-native SELECT timeout.

func Open added in v0.1.11

func Open(dsn string, opts providerregistry.Options) (*Provider, error)

Open opens MySQL with opts (see NewAdapter).

Jump to

Keyboard shortcuts

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