Shape support for include trees #1608
Replies: 2 comments 4 replies
-
Hey check out the auth example to see how to do this. https://github.com/electric-sql/electric/tree/main/examples/auth The auth doc page covers similar territory We only support single table shapes atm so you'll need to sync each table and do joins client-side. |
Beta Was this translation helpful? Give feedback.
-
I've updated the title and set to a feature request because I think this question is really asking if Shapes support include trees. As per the previous shape docs/implementation for old Electric Shapes were designed and envisaged as having a:
With a code snippet example looking like: await db.projects.sync({
where: {
id: 'abcd'
},
include: {
issues: {
include: {
comments: {
include: {
author: true
}
}
}
}
}
}) This was modelled on Prisma relation queries and more generally on ORM queries with an association tree, such as Ecto preloads: Repo.all from p in Project,
join: t in assoc(p, :tasks),
join: i in assoc(t, :issues),
join: c in assoc(i, :comments),
preload: [tasks: {t, issues: {i, comments: {c, }}] A shape with an include tree allows you to do things like sync a project with all its nested tasks, issues and comments. This is exactly what the question above is asking how to achieve. |
Beta Was this translation helpful? Give feedback.
-
Hi! Your project is really interesting!
I have a question. Let's take a schema like this:
Table projects_users for m2m link:
Now user has a lot of accessible comments through: project -> tasks -> issues
In a regular SQL we can retrieve comments from DB like this:
How can we limit electric's shapes of
comments
to be only accessible to user from auth-token when we call/v1/shape/comments?offset=-1
? In this example, we shouldn't get all diffs, only diffs for comments linked to one project.I would like to see an advanced example of usage in your docs. Maybe you can extend your example with projects-issues-comments?
Beta Was this translation helpful? Give feedback.
All reactions