rusticx
Database Guides

MySQL / MariaDB

Setting up and using rusticx with MySQL or MariaDB and the mysql feature flag.

Setup

[dependencies]
rusticx = { version = "0.1", features = ["mysql"] }
tokio = { version = "1", features = ["full"] }
serde = { version = "1", features = ["derive"] }
uuid = { version = "1", features = ["v4", "serde"] }

Connection String

mysql://username:password@host:port/database
# Local development
mysql://root:@localhost:3306/mydb

# With credentials
mysql://alice:secret@localhost:3306/production

Creating a Repo

use rusticx::prelude::*;

let repo = MySqlRepo::<User>::new("mysql://root:@localhost:3306/mydb").await?;
repo.migrate().await?;

MySQL-Specific Notes

UUID Storage

MySQL does not have a native UUID type. rusticx stores UUIDs as CHAR(36) in MySQL:

-- Generated by repo.migrate() for a Uuid primary key
id CHAR(36) PRIMARY KEY

Raw SQL Placeholders

MySQL uses ? placeholders (not $1 like PostgreSQL):

let rows = repo
    .adapter()
    .query_raw("SELECT id, name FROM users WHERE role = ? AND score > ?", &[&"admin", &100])
    .await?;

Running MySQL Locally

docker run --name rusticx-mysql \
  -e MYSQL_ROOT_PASSWORD=secret \
  -e MYSQL_DATABASE=rusticxdb \
  -p 3306:3306 \
  -d mysql:8
export DATABASE_URL="mysql://root:secret@localhost:3306/rusticxdb"

MariaDB Compatibility

rusticx's MySQL adapter is fully compatible with MariaDB 10.5+. Use the same mysql:// connection string format:

export DATABASE_URL="mysql://root:secret@localhost:3306/rusticxdb"

On this page