我在 supabase 数据库上有一些表。
有一个 post 表,它包含 profiles 表中的 user_id。
user_id
与配置文件表的id相关的字段。 @supabase
节点模块从 supabase 中提取数据。 await supabase
.from('posts')
.select(`user_id,
profiles(
first_name
)
`);
我该如何解决这个问题?
要使用 Supabase 在单个查询中从多个表中获取数据,您可以在查询中使用 JOIN 子句。在您的情况下,您想使用
posts
字段将 profiles
表与 user_id
表连接起来。
await supabase
.from('posts')
.select('posts.title, posts.content, profiles.first_name')
.innerJoin('profiles', 'posts.user_id', 'profiles.id');
您还可以使用其他类型的联接,例如
leftOuterJoin
或rightOuterJoin
,具体取决于您的需要。此外,您可以使用 where
、order
和 limit
等方法将各种过滤和排序选项应用于查询。