-
-
Notifications
You must be signed in to change notification settings - Fork 536
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[PIP] Event stream #1123
Comments
Question: since broadcast channel is generic, what will be the type? It could be |
I think async-channel would be a good alternative. |
Would this be for all updates occurring in the database or per table? |
I think a downstream component would be responsible for filtering and forwarding messages to interested receivers so here the design should focus on the source of truth. |
Will it work with delete events caused by "cascade delete"? So if I delete an entity and related entities are deleted automatically by sea orm, can I get the deleted related entities? |
I think not. This is a feature inside the database, and if you used it, it is meant to be transparent to the application. |
There is a fundamental design choice we have to make. How can the event subscriber be able to decode the event? For example, this CRUD event belongs to which entity and what has been changed? I think we need a trimmed struct ModelEvent {
table_name: DynIden,
action_type: ModelEventType,
model: Box<dyn BasicModelTrait>,
}
enum ModelEventType {
Insert,
Update,
Delete,
}
trait BasicModelTrait {
/// Get the value of a column.
///
/// Here the `col` is not bounded by `<Self::Entity as EntityTrait>::Column`
fn get(&self, col: DynIden) -> Value;
} The original #[async_trait]
pub trait ModelTrait: Clone + Send + Debug + BasicModelTrait { // All `ModelTrait` should implements `BasicModelTrait`
// Need to provide generic / concrete type for this associated type
type Entity: EntityTrait;
// ...
} |
Will it be possible to implement a generic |
Okay. This won't work... the data transported via broadcast channel has to be // Has to be `Clone`
trait BasicModelTrait: Clone { ... }
struct ModelEvent {
table_name: DynIden,
action_type: ModelEventType,
model: Box<dyn BasicModelTrait>, // Violation of object safety!
} |
Yes, it could! |
Maybe this crate can be used? |
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 (viasubscribe(&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:
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
InsertStatement
andUpdateStatement
The text was updated successfully, but these errors were encountered: