Documentation
¶
Overview ¶
Package mysql provides the MySQL dialect, which also serves MariaDB.
Importing it registers the dialect under "mysql" and "mariadb":
import _ "github.com/gruberchris/rung/dialect/mysql"
MariaDB is served by this dialect because it speaks the same wire protocol and the same SQL. It is a fork rather than a version, though, so it is worth verifying separately in CI.
Index ¶
- type Dialect
- func (Dialect) DropTablesStatement(quoted []string) string
- func (Dialect) LedgerDDL() string
- func (Dialect) LedgerExistsQuery() string
- func (Dialect) ListTablesQuery() string
- func (Dialect) MigrationsDir() string
- func (Dialect) Name() string
- func (Dialect) OpenForMigrations(dsn string) (*sql.DB, error)
- func (Dialect) QuoteIdentifier(name string) string
- func (Dialect) Rebind(query string) string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Dialect ¶
type Dialect struct{}
Dialect implements rung.Dialect for MySQL 8.0+ and MariaDB 10.5+.
func (Dialect) DropTablesStatement ¶
DropTablesStatement drops every named table.
MySQL has no CASCADE, so foreign key checks are suspended for the duration rather than a safe drop order being computed. The statement relies on the multi-statement connection Dialect.OpenForMigrations returns.
func (Dialect) LedgerDDL ¶
LedgerDDL creates the migration ledger, mirroring the PostgreSQL one row for row.
DATETIME(6) rather than TIMESTAMP: MySQL's TIMESTAMP converts to and from the session time zone and tops out in 2038, and neither is wanted for a record of what has been applied to a schema.
func (Dialect) LedgerExistsQuery ¶
LedgerExistsQuery reports whether the ledger exists in the connected database.
The TABLE_SCHEMA = DATABASE() predicate is load-bearing: without it the query reports a _migrations table belonging to some other database on the same server.
func (Dialect) ListTablesQuery ¶
ListTablesQuery lists the tables in the connected database, for rung/reset.
func (Dialect) MigrationsDir ¶
MigrationsDir returns "mysql". MariaDB runs the same file set.
func (Dialect) OpenForMigrations ¶
OpenForMigrations opens a handle permitting several statements per Exec.
A migration file needs that and ordinary traffic must never have it: it is the difference between a driver that can reject an injected statement and one that cannot.
ParseTime and a UTC location are forced rather than left to the caller's DSN. Without ParseTime the driver returns DATETIME columns as []byte and every scan into a time.Time fails; without Loc it reads them in the server's local zone, silently shifting every timestamp by the deployment's UTC offset. Both are configuration mistakes that surface far from their cause.
func (Dialect) QuoteIdentifier ¶
QuoteIdentifier quotes a SQL identifier with backticks.