Hi! Short question: Is there any way to get more t...
# help
m
Hi! Short question: Is there any way to get more typesafe results from the supabase service? I'm trying to build an application in angular and right now I need to check in my components if all the fields from a row are present, i.e.
n
Hello ! This thread has been automatically created from your message in a ``few seconds ago``. Pinging @User so that they see this as well! Want to unsubscribe from this thread? Right-click the thread in Discord (or use the ... menu) and select Leave Thread to unsubscribe from future updates. Want to change the title? Use the
/title
command! We have solved your problem? Click the button below to archive it.
m
I have code like this:
Copy code
ts
getQuestion(id : string) : Observable<any> {
    return from(this.supabase.from('question').select('*').eq('id', id).single())
  }
in my supabase-service.ts But this is annoying as the result returned is some weird Observable/postgres-result-like object. What i'd much rather have, would be for the function to either return the complete, typesafe data from the request, for example by using an interface or object definition and instantiating it, or throw errors if the request failed.
Is there any way to make supabase do this automatically (return fully assembled objects from a request or throw error) or would i need to have to implement this myself?
should i just switch to prisma if i want more type-safety?
s
https://supabase.com/docs/reference/javascript/generating-types - It's possible to generate types for your DB
n
Milou (2022-03-26)
s
You can then do
supabase.from<definitions['question']>('question').select('*').eq('id', id).single()
m
neat, thank you! btw, super cool that youre using the openapi spec for this. ive been trying to convince people that you can use it for so much more other than documentation and thats a great example, not only for generating code from such a spec, but also achieving looser coupling (by not having to use an ORM such as prisma)