Chapter 12 — Tri-dialect + cross-cutting
3 live tests against a docker MySQL 8.0 container, exercising the
same cookbook model that PG tests use through the dialect-agnostic
Pool + save_pool / fetch_pool ORM API. Run with:
docker run -d --name rustango-mysql \
-e MYSQL_ROOT_PASSWORD=rustango -e MYSQL_DATABASE=cookbook_blog_my \
-e MYSQL_USER=rustango -e MYSQL_PASSWORD=rustango \
-p 3406:3306 mysql:8.0
MYSQL_TEST_URL=mysql://rustango:[email protected]:3406/cookbook_blog_my \
cargo test --test cookbook_chapter12_bidialect
The same model code that runs on Postgres round-trips on MySQL:
$ MYSQL_TEST_URL=mysql://…/cookbook_blog_my \
cargo test --test cookbook_chapter12_bidialect
running 3 tests
test cookbook_rating_round_trips_against_mysql ... ok
test mysql_multi_auto_inserts_then_refetches_for_remaining_fields ... ok
test mysql_decodes_multi_row_select ... ok
test result: ok. 3 passed; 0 failed; 0 ignored
- §12.140 / §12.141 —
Ratingmodel save + fetch + multi-row decode viaPool::Mysqlandsave_pool/fetch_pool. Exercises AUTO_INCREMENT forAuto<i64>, BIGINT round-trip, and per-backend trait dispatch. →cookbook_rating_round_trips_against_mysql,mysql_decodes_multi_row_select
Dialect note — multi-Auto models on MySQL: the cookbook's
Author has two Auto<T> columns (id: Auto<i64> PK + joined_at: Auto<DateTime> from auto_now_add). Postgres fills both in one
INSERT ... RETURNING; MySQL has only single-column
LAST_INSERT_ID(), so save_pool fills the PK and leaves the other
Auto fields Unset. Re-fetch the row by PK to materialize the
DB-defaulted timestamp — the same pattern as a Django app calling
.refresh_from_db() after save when it needs a server-set value.
(This used to error hard; it now succeeds on both backends.)