Skip to content

[PIP] Event stream #1123

@tyt2y3

Description

@tyt2y3

No pun intended, PIP stands for "Proposal & Implementation Plan".

Motivation

To generate a high level event stream of changes to Entities, and serve as a foundation to change capture and other event-based system paradigm.

Architecture

When this flag is enabled, DatabaseConnection will maintain a broadcast channel (is there non-tokio equivalent?) internally, and users will be able to subscribe to this channel (via subscribe(&self) -> Receiver<Event>.

If execution succeeded, Inserter, Updater & Deleter will extract some semantic information from the query and generate an Event, and push to the channel.

Information we can extract and represent:

  1. New Model: the newly inserted ID and content of the new Model
  2. Update Model: ID of the model, which fields are changed and the updated values
  3. Delete Model: ID of the deleted model, and perhaps content of the deleted Model

Notes 1: We should not buffer events. When no one is subscribing, we will discard all events.
Notes 2: I imagine a subscriber can persist these event, may be even saving to the same database. To prevent infinite echo, we should have an option to ignore certain tables.

Breaking changes

It seems that we need to convert DatabaseConnection from a enum to a struct.

Open questions

  1. How to allow custom SQL execution to generate events
  2. How to allow custom processors to handle InsertStatement and UpdateStatement

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions