Skip to content

#220 feat: participant scopes over an OR group of columns#265

Merged
RAprogramm merged 1 commit into
mainfrom
220
Jul 26, 2026
Merged

#220 feat: participant scopes over an OR group of columns#265
RAprogramm merged 1 commit into
mainfrom
220

Conversation

@RAprogramm

Copy link
Copy Markdown
Owner

Closes #220

"Rows where this principal takes part in any role" is an OR over several columns of the same type, and it was the one query shape that forced raw SQL. It is now a declaration:

#[scope(involving: requester_id | subject_id)]
#[scope(handled: requester_id | subject_id, within = parcel_id)]
Generated SQL
list_involving(value, limit, offset) WHERE (requester_id = $1 OR subject_id = $1) ORDER BY id DESC LIMIT $2 OFFSET $3
list_handled(parcel_id, value, limit, offset) WHERE parcel_id = $1 AND (requester_id = $2 OR subject_id = $2) …

The value is bound once and referenced by every branch. within narrows the group to one parent before the OR. Soft-delete aware, ordered like list.

Checked while parsing: a scope needs at least two columns, every name must be a field of the entity, and the OR-ed columns must agree on their type — one value is bound against all of them, so a mismatch would otherwise surface as a decode error at run time. Two compile-fail cases cover the rejections.

A live-Postgres case proves both forms: both roles match the same principal, narrowing drops the row belonging to another parent, an uninvolved principal matches nothing, and pagination applies. README and the attribute page in all five wiki languages document it.

@codecov

codecov Bot commented Jul 26, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.32143% with 6 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 87.50% 5 Missing ⚠️
...tity-derive-impl/src/entity/sql/postgres/scopes.rs 98.36% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@RAprogramm
RAprogramm merged commit 4496cf8 into main Jul 26, 2026
22 checks passed
@RAprogramm
RAprogramm deleted the 220 branch July 26, 2026 11:52
@RAprogramm RAprogramm mentioned this pull request Jul 26, 2026
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): OR-group filters (find rows involving a principal)

1 participant