如何对 PostgREST 数据库建模以实现类似社交网络的行为

How to model PostgREST database to achieve social-network-like behaviour

这个问题可能有一个非常简单的答案,但由于我是 PostgreSQL/PostgREST 的新手,我不确定如何实现它。

我想要创建的是一个 schema/REST 端点,它允许我查询关注用户发布的帖子。

目前,架构如下所示:

用户

- first_name
, last_name
, id

帖子

- id
, text
, author_id --foreign key to a user

连接数

- id
, follower --foreign key to a user
, followed --foreign key to a user

我希望能够查询给定用户关注的用户发布的帖子,但我不确定如何使用 postgREST 实现此目的。

posts posted by users which given user follows,

试一试:

GET /posts?select=*,users!inner(connections!inner!followed(*))&users.connections.follower=eq.<your_user_id>

有了它,您将获得您想要的 posts,但还有一些额外的数据。