S
Supabase8mo ago
Gabe

SvelteKit + Supabase - Reusing DB calls, wrappers, error handling +

Hope it's fine to post something very SvelteKit related! Me and a buddy have created a project together for about two years, and we've learnt most of Supabase and SvelteKit while doing so. This has lead to us doing things many different ways when fetching data from Supabase. Our database is not particularly complex, but trying to create a pretty normalised relational database has made some queries more annoying than others. As a result, we want to reuse most of the more complex DB calls, and perhaps create wrappers for handling errors and similar. I have a couple of questions/ideas for what I want to achieve, and mostly I'm just wondering if people have insight or thoughts as to best practices. Some of the questions might be more SvelteKit heavy than Supabase heavy, but I'm posting both in this and the SvelteKit Discord in hopes of getting insight :) 1. What do people think about creating views for databases that are not particularly complex? My friend argues for them, while I think they clutter what could be done through better queries and JavaScript 2. I would like to avoid writing a new SELECT query every time I do a DB call in my page.server.ts files, and instead defining these beforehand. But I don't know how to best create reusable queries, while also hopefully avoiding adding the Supabase client as a parameter to a function 3. I would love to be able to create a wrapper around all queries to handle errors and only return data or throw 500 or 404 codes. What's the best way to acheive this? 4. I also need a definitive way of considering data sent from page.server.ts mandatory vs. "can wait with a skeleton loader" 5. What's the best way of dealing with default values for less "bad" errors? Should all DB calls return empty lists for all list values when errors are present?
0 Replies
No replies yetBe the first to reply to this messageJoin

Did you find this page helpful?