RawBuilder is not "Compilable"

How one should execute RawBuilders coming from (for example)
```
since they're not "Compilable" things? I know you can pass from
```
since they're not "Compilable" things? I know you can pass from
sqlcustomsql.execute({ getExecutor: () => executor }) ``` since I have a custom executor, but why is that? Is there another way?
20 Replies
Igal (mobile)
Igal (mobile)2y ago
Hey 👋 RawBuilder is not compilable because we don't parse raw sql strings.
Kristian Notari
Kristian NotariOP2y ago
sql`customsql`.execute({ getExecutor: () => executor })
sql`customsql`.execute({ getExecutor: () => executor })
this thing is valid ts/kysely code and it's working fine right now for executing sqlcustom 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:
queryExecutor.compileQuery(rawBuilder.toOperationNode(), queryId)
queryExecutor.compileQuery(rawBuilder.toOperationNode(), queryId)
Igal (mobile)
Igal (mobile)2y ago
We could potentially make these public, need to look into it.
Kristian Notari
Kristian NotariOP2y ago
yeah I'm asking cause maybe there's a more than valid reason to hide them don't know 🙂
Igal
Igal2y ago
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.
Kristian Notari
Kristian NotariOP2y ago
So is that going to be compatible with Compilable interface?
Igal
Igal2y ago
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
Kristian Notari
Kristian NotariOP2y ago
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?
Igal
Igal2y ago
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
Igal
Igal2y ago
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.
Igal
Igal2y ago
Might have to revisit it
Kristian Notari
Kristian NotariOP2y ago
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
Igal (mobile)
Igal (mobile)2y ago
Why wouldnt it be secure? same query, same parameters should have same qid when compiled.
Kristian Notari
Kristian NotariOP2y ago
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
Igal
Igal2y ago
You don't have to anymore (pending release) but yeah, query id should be part of the compiled query
Kristian Notari
Kristian NotariOP2y ago
Igal vs igalk is confusing as hell 😂 sorry I thought to be speaking to the same person so far
Igal
Igal2y ago
Same person, different devices
Igal (mobile)
Igal (mobile)2y ago
This is my crazy side 🤪
Kristian Notari
Kristian NotariOP2y ago
🤯
Igal
Igal2y ago
We've released this btw.
Want results from more Discord servers?
Add your server