sea-orm
sea-orm copied to clipboard
Query streams that subscribe to relevant changes in database
Motivation
The use case in which the lack of this feature has become a blocker is GraphQL subscription integration.
In GraphQL, subscription requests can be used to enable users to continuously receive up-to-date data via WebSocket. However, the existing implementation of SeaORM does not provide a way to continuously send updated data.
Full Disclosure: I am not experienced with async data pipelines, streams, WebSocket, or anything in this area, so pardon me if anything here does not make sense.
For example, one use case could be:
- User asks for a subscribed stream of Bakery (id: 1).
- SeaORM returns a stream with the model of the desired Bakery.
- User continues to listen via WebSocket.
- If there is a change in relevant data resulting in a change in the model (e.g. the name of Bakery (id: 1) is changed), SeaORM returns the updated version of it.
- The subscription terminates upon receiving User's explicit signal or after a certain amount of time, etc.
Proposed Solutions
I am thinking of introducing an observer system around certain operations (mutations) in SeaORM. When the user calls a special query executor (subscribe()
?), they get a stream of Model
like the stream()
executor, but under the hood this stream is subscribed to relevant mutation operations. When the relevant operations are performed, their subscriptions are triggered.
Additional Information
Streaming exists in SeaORM but it is currently only for memory efficiency. It only prepares the query result once after it is done one time, no subscription or updating is performed.