Skip to content

215#221

Merged
RAprogramm merged 1 commit into
mainfrom
215
Jul 5, 2026
Merged

215#221
RAprogramm merged 1 commit into
mainfrom
215

Conversation

@RAprogramm

Copy link
Copy Markdown
Owner

Closes #215.

New repeatable #[join(table as alias, on = local = foreign, fields(col as alias: Type, ...))] attribute generating a joined read model:

  • {Entity}View — flat struct with every entity column plus the declared joined columns (sqlx::FromRow + serde::Serialize)
  • {Entity}View::SELECT — canonical SELECT ... FROM ... JOIN ... fragment (no WHERE) so bespoke filters reuse the one column list
  • {Entity}View::find_by_id(pool, id) / {Entity}View::list(pool, limit, offset)

Joins are INNER JOINs; base columns are qualified with the table name; a join column that does not match an entity field fails the build. Joined column types are part of the declaration — the macro cannot see the foreign table's schema.

Validated against a real consumer: three production read models (two-way airport joins over tickets and parcels, plus two matching queries composed on SELECT) replaced ~120 lines of hand-written SQL and three Raw row structs; the consumer's full integration suite passes against live Postgres.

Wiki (Attributes-en) documents the attribute.

@codecov

codecov Bot commented Jul 5, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.26316% with 9 lines in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
...derive-impl/src/entity/parse/entity/constructor.rs 50.00% 5 Missing ⚠️
...entity-derive-impl/src/entity/parse/entity/join.rs 95.83% 4 Missing ⚠️

📢 Thoughts on this report? Let us know!

@RAprogramm
RAprogramm merged commit 90fecd5 into main Jul 5, 2026
17 checks passed
@RAprogramm
RAprogramm deleted the 215 branch July 5, 2026 04:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(sql): declarative joined read models (views)

1 participant