RawBuilder is not "Compilable"
How one should execute RawBuilders coming from (for example)
sql
customsql
.execute({ getExecutor: () => executor })
```
since I have a custom executor, but why is that? Is there another way?20 Replies
Hey 👋
RawBuilder is not compilable because we don't parse raw sql strings.
this thing is valid ts/kysely code and it's working fine right now for executing sql
custom sql
queries
under the hood, the rawBuilder .execute
method compile itself and execute itself with the executor and the same queryId (given by its private properties)
those methods are private as of now
I'd like to transform a rawbuilder to a CompiledQuery at least. I'm doing:
We could potentially make these public, need to look into it.
yeah I'm asking cause maybe there's a more than valid reason to hide them
don't know 🙂
GitHub
add
RawBuilder.compile
. by igalklebanov · Pull Request #365 · kos...This PR allows consumers to compile RawBuilders and pass around their CompiledQuerys around when splitting build, compile and execute code.
So is that going to be compatible with Compilable interface?
not really, RawBuilder and sql template tag are "floaters" that require an external executor to compile/execute, while Compilable was created for query builders
but since you're passing the return type to the sql template tag, it'll return a CompiledQuery with that type
Yeah got it
Is there a reason why there was a private #queryId used twice, once for the compilation and once for the execution inside RawBuilders?
query id is passed around mainly for the plugin system which consists of 2 steps:
pre-query transformQuery
post-query transformResult
the id allows to communicate between the steps using WeakMaps
https://github.com/koskimas/kysely/pull/176 this PR could help with split of build, compile and execute vs. plugins
GitHub
add
queryId
to CompiledQuery
to allow async communication betwe...does what #173 tried to achieve, but in a simpler way as suggested by @koskimas.
Might have to revisit it
Cause I got it working with my custom executor by self passing the executor to RawBuilder.execute. Now that I’m using toOperationNode I took care of using the same queryId for both compiling and executing, just to be sure and follow the private internal behavior of RawBuilders
So if RawBuilder get its own public compile then we should take care of using the same queryId then? Not sure how “secure” that would be
Why wouldnt it be secure? same query, same parameters should have same qid when compiled.
I mean, during execution you pass a queryId to the executor execute method
What if that’s different from the one used during compiling? Since compiling is managed inside the raw builder
You don't have to anymore (pending release)
but yeah, query id should be part of the compiled query
Igal vs igalk is confusing as hell 😂 sorry I thought to be speaking to the same person so far
Same person, different devices
This is my crazy side 🤪
🤯
We've released this btw.