Hey folks, if I wish to add some complex business ...
# off-topic
s
Hey folks, if I wish to add some complex business logic that I don't want to expose on the client; then is there any provision supabase to handle that logic on the platform or I need to create my own server and use supabase sdk functions there? Example: I want to calculate result by a secret formula (that I cannot show on client) I take data and perform some operations and update on the Table. To do this, how shall I proceed? Would appreciate help. Thanks
s
This depends on how much computation power you think this complex business logic will require and what language it is being written in.
s
It won't need a lot of computation. We are comfortable to write in JS/TS but we are cool with writing in SQL/PostgreSQL too. Idea to get flexibility and know approaches.
I have compiled a little bit approaches: Approach 1 Client Side: /services updateUserRewardWithSomeComplexOperation(){ // fetch all data via Supabase SDK // call api to get the response with updated data based on business logic computation // update the data via Supabase SDK } Server Side APIs can be written in Next.js Server of a particular app APIs can be written in a separate Express Server (shared with all the apps) Approach 2 Use Postgres Functions to compute business logic directly in the DB Refer: https://supabase.com/docs/guides/database/functions https://supabase.com/docs/reference/javascript/rpc Need to write functions directly in Postgres inside the SQL section of Supabase Dashboard Support for Function Hooks (call a function automatically when a particular row/col changes) Need to write logic in SQL and not JS Can execute directly on client side via JS SDK Please let me know your views upon this.
s
Yes both approaches are good but just a bit more about Approach 2, you can write the business logic in other languages too besides SQL, you can use plpgsql which is quite powerful, you can also use JavaScript, Python and Perl too.
s
Thanks for this! In case if you have some good resources for learning plpgsql or plv8 languages, I would love to have a look. Also, would be happiest guy on earth if Jon Mayers makes an in-depth tutorial vid about this haha 🙂 Again, thanks ❤️