Verifying inserts on the db: Database Functions or Edge Functions?
edge functions🟢SQL
Im building a booking app where a user can book a range of time on a certain place. The validations required are the following: - The range of time must not be smaller than MIN_BOOKING_TIME; - The range of time must not be greater than MAX_BOOKING_TIME; - The range of time must not overlap with any other existing booking in that same place.
All this validations are already done in the frontend, but I need to run this same validations right before the user tries to insert the booking in the bookings table.
I was wondering which of the two available options (Database Functions or Edge Functions) would be more appropriate.
If I go with Database Functions, I was thinking of building two function, one to validate max and min time, and the other to validate overlapping bookings. This last function is the more complex one since to check overlapping bookings what I'm doing is to 1) Check the open and close time of the place where the booking is being made, and 2) With al the existing bookings of that place I build an "availability ranges array" which consists of an array compose with objects with start and end time properties which represent available intervals. It looks something like this:
Supabase gives you the tools, documentation, and community that makes managing databases, authentication, and backend infrastructure a lot less overwhelming.