我有两个相互引用的表.举个例子,假设它们是帖子和 comments :
Posts
-----
id bigint
title text
body text
Comments
--------
id bigint
post_id bigint references Posts
body text
在我的应用程序中,没有至少一条 comments 的帖子是没有意义的.因此,如果用户创建了某个内容,则必须从一个帖子和与该帖子相关的 comments 开始(稍后,他们可以向该帖子添加其他 comments ).
在Supabase中,有没有办法同时创建一个新的帖子和一个引用这个新帖子的新 comments ?
supabase
.from("posts")
.insert({title: 'new post', body: 'body of new post'})
.select({ id })
.then()
.from("comments")
.insert({post_id: id, body: 'comment body'})
在Rails中,我相信有一些类似于
transaction do
# ...
end
这几乎就是我在suabase js客户端中要寻找的东西.如果不存在,有没有办法在PostgreSQL中这样做(然后用Supabase.rpc()运行它)?