electric-sql / electric-sql/electric

Feature request: Dependent Data Hydration ("Graph Sync") for Sliding Window Patterns

Open
#3,651 2 comments 0 reactions 0 assignees View on GitHub
feature request triage
Dominant language
TypeScript
Stars
10.4k
Forks
375
Avg merge
3d 1h
Merged PRs (30d)
18

Description

**Is your feature request related to a problem? Please describe.**
I am building a local-first mobile application (React Native) involving high-frequency data (messaging) where we need to sync a "sliding window" of recent activity (e.g., messages WHERE created_at > 30 days ago).

The problem is **Data Hydration** (orphaned Foreign Keys). When we sync the last 30 days of messages, we also need the `Conversation` and `Customer` rows associated with those messages to render the UI. However:
1. The `Conversation` might be 2 years old (outside the sync window).
2. Syncing all `Conversations` is not feasible (dataset too large).
3. We cannot easily identify which old conversations to fetch without first fetching the messages.
This leaves us with orphaned foreign keys on the client and a broken UI.

**Describe the solution you'd like**
I would like a mechanism to define **Dependent Shapes** or **Include Trees** where the presence of a child row in a shape forces the sync of its parent row, regardless of the parent's timestamp.

Ideal Syntax (Conceptual):
```
const { data } = useShape({
table: 'messages',
where: `created_at >= now() - interval '30 days'`,
include: {
// Automatically fetch the specific Conversation row referenced by messages.conversation_id
conversation: {
include: {
// And the Customer referenced by that conversation
customer: true
}
}
}
})
```
I understand `include` was removed in v1.0, but the use case for "Graph Sync" remains critical for partial replication.

**Additional context**
- **Stack:** Postgres -> ElectricSQL -> SQLite

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.