课程: Supabase Essential Training

免费学习该课程!

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

Writing functions

Writing functions

- Supabase functions are in the same name space as your tables. So the naming of parameters, variables and the function itself is important. Let's create a function that makes a purchase using a gift card balance. First, I'm going to go to the table editor and point out a gift cards table that I've added. And you'll see we have an ID I created at timestamp, a user_id and the balance in cents. I'm going to copy this user_id to keep it handy because we're going to use it again in a moment. And let's just select that balance from here. All right, so we've got the balance here again. I'm going to comment out this query for the moment. And next I'm going to paste in a function that I created ahead of time. And this is our purchase_from_gift_card function. This function starts with create or replace. This makes sure that we don't run into any conflicts, and it also allows us to continue building the function as we go. So you can run this over and over again and it will replace the function…

内容