ccabd
Explore posts from serversDTDrizzle Team
•Created by ccabd on 8/9/2023 in #help
How to specify type using sql template
I'm using this piece of code
to create a query like this
There is a few problems with it, I guess because this is a parameterized query and parameters are used as literals (need confirmation on this)?
1. I have to cast
temp.id
to integer in each subquery, otherwise I get PostgresError: operator does not exist: integer = text
. I don't know how that affects performance, but it feels dirty.
2. The query results are of type string
, which I then have to cast again.
3. Also, since the whole query is of type SQL<unknown>
, when parsing the result I need to force the wrong/unwanted type string
onto the typescript compiler first, just to be able to cast the value, like this result.map( v => +(v.id as string) )
Is this really the most optimal way of doing things here, or am I missing something? I found a param
method in drizzle but no docs and no idea how to use it or if it could be useful anyhow. Please enlighten me.5 replies
DTDrizzle Team
•Created by ccabd on 8/8/2023 in #help
Find IDs from a list which do not exist in table
As the title says, i'm trying to filter a list of given IDs (could be hundreds) into a list of IDs that do not exist in a table (could have multiple thousands of rows).
My research suggests that I should be doing something like this:
Would you agree and more importantly, can I do this using ORM syntax?
Thanks for any tips or insights you can provide.
4 replies