课程: Supabase Essential Training

免费学习该课程!

今天就开通帐号,24,700 门业界名师课程任您挑!

Calling functions through RPC

Calling functions through RPC

- [Instructor] In Supabase, custom PostgreSQL functions can be used as remote procedure calls. Every function added to the public schema becomes a potential RPC endpoint. Let's take a look at an existing database function in the public schema and call it via RPC. So the existing function that we're going to look at is purchased from gift card. We just go over here to edit function, and it brings that function up. We have two arguments for this function, one for the user ID and one for the amount of the purchase. And then we have the function itself. This starts with variable declaration. I just have one variable here for the new balance. So that gets declared up here. And then this is the body of the function. So in this function, we are updating the gift cards table. This gift cards table has a balance cents column, and we're going to set that to the value that it was before, only removing the amount that we are using for the purchase. Then we are limiting this query to just the user…

内容