testcontainer_formulas/mysql

MySQL formula. Defaults to mysql:8.4 with app credentials.

use db <- testcontainer.with_formula(
  mysql.new()
  |> mysql.with_database("app_test")
  |> mysql.with_username("app")
  |> mysql.with_password("secret")
  |> mysql.formula(),
)

// db.connection_url, db.host, db.port, db.database, db.username

Types

MySQL-specific configuration. Build with new/0 + with_*.

pub opaque type MysqlConfig

Typed output handed to the body of testcontainer.with_formula/2.

pub type MysqlContainer {
  MysqlContainer(
    container: container.Container,
    connection_url: String,
    host: String,
    port: Int,
    database: String,
    username: String,
  )
}

Constructors

  • MysqlContainer(
      container: container.Container,
      connection_url: String,
      host: String,
      port: Int,
      database: String,
      username: String,
    )

Values

pub fn formula(c: MysqlConfig) -> formula.Formula(MysqlContainer)

Builds the Formula(MysqlContainer) ready to pass to testcontainer.with_formula/2.

pub fn new() -> MysqlConfig

Sensible defaults: mysql:8.4 / app / app / root.

pub fn on_network(
  c: MysqlConfig,
  net: network.Network,
) -> MysqlConfig
pub fn on_network_name(
  c: MysqlConfig,
  net: String,
) -> MysqlConfig

Same as on_network/2 when you already have the Docker network name.

pub fn with_database(c: MysqlConfig, db: String) -> MysqlConfig
pub fn with_extra_wait(
  c: MysqlConfig,
  s: wait.WaitStrategy,
) -> MysqlConfig

Adds an extra wait strategy on top of the default log_times("MY-010931", 2). MY-010931 is the mysqld “Server ready” message id, emitted once by the temporary bootstrap server and again by the final TCP server — matching the second occurrence guarantees MYSQL_USER exists and the server is reachable on port 3306.

pub fn with_image(c: MysqlConfig, image: String) -> MysqlConfig

Replaces the image entirely.

pub fn with_name(c: MysqlConfig, n: String) -> MysqlConfig
pub fn with_password(c: MysqlConfig, pass: String) -> MysqlConfig
pub fn with_root_password(
  c: MysqlConfig,
  pass: String,
) -> MysqlConfig

Root password used by the MySQL image bootstrap.

pub fn with_secret_password(
  c: MysqlConfig,
  pass: cowl.Secret(String),
) -> MysqlConfig
pub fn with_secret_root_password(
  c: MysqlConfig,
  pass: cowl.Secret(String),
) -> MysqlConfig

Same as with_root_password/2 when the value is already a cowl.Secret.

pub fn with_username(c: MysqlConfig, user: String) -> MysqlConfig
pub fn with_version(
  c: MysqlConfig,
  version: String,
) -> MysqlConfig

Shorthand: keep mysql: prefix, override only the tag.

Search Document