feat(showcase): blog app — JSON CRUD (Phase 2)#522
Merged
Conversation
Adds the first sub-app under examples/showcase/. Exercises:
- #[derive(Model)] schema with Auto<i64> PK, max_length, default, and
auto_now_add via the canonical macro surface.
- manage makemigrations — `cargo run -- makemigrations blog` produced
migrations/0002_blog.json via the framework's diff machinery.
- Tri-dialect QuerySet pipeline:
Post::objects().order_by(\&[(...)]).filter_op(col, op, val)
.fetch_pool(\&pool)
- Macro-emitted Post::insert_pool(&Pool) round-trip with auto_now_add
populated by the DB.
## Routes
GET /blog/posts — list, sorted by id ASC
GET /blog/posts/{id} — retrieve, 404 on miss
POST /blog/posts — create from {title, body?, published?}
## Backend abstraction
The framework's non-tenancy runserver attaches different Extension
types per build (PgPool when feature=postgres, Pool otherwise).
`AttachedPool` + `into_pool()` hide the cfg fork so the handler
body works the same against every backend.
## Playwright
e2e/tests/blog/crud.spec.ts — 5 tests covering empty list, create +
retrieve round-trip, ordering, 404 on unknown id, null body +
default published. 7/7 tests pass locally (5 blog + 2 smoke from
phase 1).
The macro-emitted insert_pool populates Auto<T> PK on every backend but auto_now_add fields only on dialects with INSERT ... RETURNING (PG + SQLite). MySQL leaves created_at as Auto::Unset, which serialized as an empty string and made the playwright assertion on the RFC-3339 shape fail. Re-fetch by PK after insert so the API contract is uniform across the matrix.
3 tasks
Closed
4 tasks
6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Phase 2 of the E2E showcase plan. Adds the first sub-app: `blog`, a JSON CRUD surface over a single `Post` model. Exercises end-to-end:
Routes
Playwright
`e2e/tests/blog/crud.spec.ts` — 5 tests covering empty list, create + retrieve round-trip, ordering, 404 on unknown id, null body + default published. 7/7 tests pass locally (5 new + 2 smoke from phase 1).
Verified locally
```
$ npx playwright test
✓ blog API › list is initially empty (smoke against fresh DB) (9ms)
✓ blog API › POST creates a post + GET retrieves it by id (7ms)
✓ blog API › list reflects newly created posts (order_by id asc) (6ms)
✓ blog API › GET unknown id returns 404 (2ms)
✓ blog API › body is nullable (22ms)
✓ phase 1 smoke › info endpoint serves framework metadata (2ms)
✓ phase 1 smoke › backend matches the SHOWCASE_BACKEND env if set (1ms)
7 passed (4.2s)
```
CI matrix runs the same suite against postgres / mysql / sqlite.