MariaDB database engine

MariaDB engine for Piko's database service. Bundles the engine, driver name, and migration dialect into a single EngineConfig that drops into a database registration.

Overview

The package provides the engine half of a Piko database registration. The MariaDB engine is the MySQL engine with three dialect overrides. NewMariaDBEngine calls db_engine_mysql.NewMySQLEngine with WithDialectName("mariadb"), WithReturningSupport(true), and a function hook that adds the sys_guid built-in. Everything else, the recursive-descent DDL and DML parser, the type resolver, the type catalogue, and the migration dialect, is the shared MySQL implementation. MariaDB-specific SQL beyond those overrides parses as MySQL.

Two differences matter when you choose this engine over MySQL. First, the engine enables RETURNING, so typed INSERT, UPDATE, and DELETE queries that end with a RETURNING clause resolve and generate code against MariaDB. The Piko MySQL engine reports SupportsReturning as false and rejects those queries. Second, the sys_guid built-in resolves under MariaDB but not under MySQL. Both differences flow through to which typed queries the code generator accepts, so they are the concrete reason to pick this engine.

Reach for MariaDB when you target a MariaDB server and want RETURNING in generated typed queries. Reach for MySQL when you target MySQL, or when your hosting provider only offers MySQL. Reach for PostgreSQL when JSON-heavy or constraint-heavy schemas dominate.

MariaDB shares its migration dialect with MySQL. The dialect uses MySQL advisory locks (GET_LOCK() and RELEASE_LOCK()), question-mark placeholders, and statement splitting. The wire-level driver is github.com/go-sql-driver/mysql, so connection setup is identical to MySQL.

Configuration

MariaDB() returns a complete db.EngineConfig with the engine, the mysql driver name, and the shared MySQL migration dialect. The constructor takes no arguments, so you write no glue.

import (
    "piko.sh/piko/wdk/db/db_engine_mariadb"
)

engineConfig := db_engine_mariadb.MariaDB()

The returned value is a db.EngineConfig, the same shape every engine constructor produces, so it drops straight into a db.DatabaseRegistration.

Bootstrap

import (
    "database/sql"
    "os"

    _ "github.com/go-sql-driver/mysql" // MariaDB speaks the MySQL wire protocol

    "piko.sh/piko"
    "piko.sh/piko/wdk/db"
    "piko.sh/piko/wdk/db/db_engine_mariadb"
)

connection, err := sql.Open("mysql", os.Getenv("MARIADB_DSN"))
if err != nil {
    return err
}

ssr := piko.New(
    piko.WithDatabase("primary", &db.DatabaseRegistration{
        DB:           connection,
        EngineConfig: db_engine_mariadb.MariaDB(),
        MigrationFS:  migrationsFS,
    }),
)

See also

Other database engines:

  • MySQL, the shared base engine, without RETURNING or sys_guid.
  • PostgreSQL, richer SQL surface, stronger JSON, expression indexes.
  • SQLite, embedded, single-file, zero-config.
  • DuckDB, embedded analytical engine for online analytical processing (OLAP).
  • CockroachDB, Postgres-compatible distributed SQL.

Framework docs:

External: