You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a load of simple queries to define, each returning one or many models which I have Typescript types for. At present I’m doing something like:
findById: async(id)=>{const[user]=awaitsql<User[]>` SELECT * FROM users WHERE id = ${id} `returnuser??null},
I would like to clean up the call sites to make the queries a bit more readable by creating a couple of helpers that do the whole thing inline — something like the following:
findById: async(id)=>awaitone` SELECT * FROM users WHERE id = ${id} `,findMany: async(type)=>awaitmany` SELECT * FROM users WHERE type = ${type} `,
But figuring out what types the wrapper tag functions need to have is a bit beyond me after looking through the Sql type’s definition.
All I really want to do is for many, pass through the result and cast it to the caller’s desired type, and for one, unwrap the first result and cast that to the caller’s desired type, which would be T | null.
Has anyone wrapped the sql tag function before and has the types handy, or knows how to do this?
The text was updated successfully, but these errors were encountered:
I have a load of simple queries to define, each returning one or many models which I have Typescript types for. At present I’m doing something like:
I would like to clean up the call sites to make the queries a bit more readable by creating a couple of helpers that do the whole thing inline — something like the following:
But figuring out what types the wrapper tag functions need to have is a bit beyond me after looking through the
Sql
type’s definition.All I really want to do is for
many
, pass through the result and cast it to the caller’s desired type, and forone
, unwrap the first result and cast that to the caller’s desired type, which would beT | null
.Has anyone wrapped the
sql
tag function before and has the types handy, or knows how to do this?The text was updated successfully, but these errors were encountered: