K
Kysely•2mo ago
oof2win2

Implementing D1 batching (getting typed queries as input and returning typed InferResult)

Hi. I've wanted to get D1 batching to work, so I've tried doing as below. Functionally the code works, however I would like to get the proper type safety for this. Essentially I extend Kysely to add the executeBatch method and I want to infer the results for each of the individual queries. Is this possible?
6 Replies
oof2win2
oof2win2OP•2mo ago
https://pastecord.com/fazekabave.ts the executeBatch method gets the compiled queries and the intention it returns an array of queryresponses like is this possible like the easiest way from a type perspective is probably getting compiledquery inputs and not returning anything (not ideal tho) per se i think i'm really asking for a way to represent an array of queries with type safety, since i can get the result type with InferResult<Query>
Igal (mobile)
Igal (mobile)•2mo ago
Hey 👋 There's an existing issue for this. How many queries do you run per batch btw?
oof2win2
oof2win2OP•2mo ago
like 10-20 on average maybe? i have instances where i also run say ~3k queries at once. defo could be optimized into say inserting more values (one case) but then sqlite limit of 1k variables throttles it quite a bit, and then update queries can't really be grouped (besides adding a CTE or a temp table or something)
Igal
Igal•2mo ago
That's too much for the compiler. iirc, we aimed at 5-6 type-safe, and beyond not as type-safe. Honestly I'd go for a "staging table" and do big upserts to "main table".
iirc, we aimed at 5-6 type-safe, and beyond not as type-safe.
but if it's all inserts/updates/deletes without returning, getting correct return types is pointless at this point.
oof2win2
oof2win2OP•5w ago
hmm so i can probably just have a type that accepts any query and executes it with no result because no return types would work for those three
Igal
Igal•5w ago
Yeah, something like that.
Want results from more Discord servers?
Add your server