diff options
| author | ojacobson <ojacobson@noreply.codeberg.org> | 2025-08-27 06:10:29 +0200 |
|---|---|---|
| committer | ojacobson <ojacobson@noreply.codeberg.org> | 2025-08-27 06:10:29 +0200 |
| commit | 8712c3a19c279d664ce75e8e90d6dde1bda56cb4 (patch) | |
| tree | 93c95548126eea048cd8962345b720b883d391c1 /src/event/sequence.rs | |
| parent | 7b131e35fdea1a68aaf9230d157bafb200557ef8 (diff) | |
| parent | f839449d5505b5352bd0da931b980a7a0305234f (diff) | |
Implement storage of synchronized entities in terms of events, not state.
Conversations, users, messages, and all other "synchronized" entities now have an in-memory implementation of their lifecycle, rather than a database-backed one. These operations take a history, apply one lifecycle change to that history, and emit a new history. Storage is then implemented by applying the events in this new history to the database.
The storage methods in repo types, which process these events by emitting SQL statements, make necessary assumptions that the events being passed to them are coherent with the data already in storage. For example, the code to handle a conversation's delete event is allowed to assume that the database already contains a row for that conversation, inserted in response to a prior conversation creation event.
Data retrieval is not modified in this commit, and probably never will be without a more thorough storage rewrite. The whole intention of the data modelling approach I've been using is that a single row per entity represents its entire history, in turn so that the data in the database should be legible to people approaching it using normal SQL tools.
Developed as an aesthetic response to increasing unease with the lack of an ORM versus the boring-ness of our actual queries.
Merges event-based-storage into main.
Diffstat (limited to 'src/event/sequence.rs')
| -rw-r--r-- | src/event/sequence.rs | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/src/event/sequence.rs b/src/event/sequence.rs index 77281c2..9a0ea5d 100644 --- a/src/event/sequence.rs +++ b/src/event/sequence.rs @@ -50,24 +50,30 @@ impl fmt::Display for Sequence { } impl Sequence { - pub fn up_to<E>(resume_point: Sequence) -> impl for<'e> Fn(&'e E) -> bool + pub fn up_to<P, E>(resume_point: P) -> impl for<'e> Fn(&'e E) -> bool + Clone where + P: Into<Self>, E: Sequenced, { + let resume_point = resume_point.into(); move |event| event.sequence() <= resume_point } - pub fn after<E>(resume_point: Sequence) -> impl for<'e> Fn(&'e E) -> bool + pub fn after<P, E>(resume_point: P) -> impl for<'e> Fn(&'e E) -> bool + Clone where + P: Into<Self>, E: Sequenced, { + let resume_point = resume_point.into(); move |event| resume_point < event.sequence() } - pub fn start_from<E>(resume_point: Self) -> impl for<'e> Fn(&'e E) -> bool + pub fn start_from<P, E>(resume_point: P) -> impl for<'e> Fn(&'e E) -> bool + Clone where + P: Into<Self>, E: Sequenced, { + let resume_point = resume_point.into(); move |event| resume_point <= event.sequence() } |
