createQueryId

KNKristian Notari3/7/2023
Is this function supposed to be exported and used in users code? I'm handling query execution with a custom executor and the executeQuery method asks me for a QueryId. Am I supposed to use kysely internal implementation or am I free to use a custom one? It's just a random string I see, but does it involve something else internally?

I'm asking cause the default import is set to: import { createQueryId } from "kysely/dist/cjs/util/query-id"
Kkoskimas3/7/2023
Having a custom executor is not something I thought people could do and it's not officially supported. That's the reason why createQueryId is not public.
Kkoskimas3/7/2023
I didn't think people would ever need to create their own query ids
KNKristian Notari3/7/2023
Ok so thatโ€™s not thought of being public. Itโ€™s ok, it was just to double check I was doing everything fine (or wrong ๐Ÿ˜…)
KNKristian Notari3/7/2023
My use case, if that could help, is using kysely with https://github.com/Effect-TS/effect effect system. So I need to separate query building from query execution, to better compose functions (effects)
KNKristian Notari3/7/2023
Basically Iโ€™m separating the kysely instance from the kysely query executor you get from retrieving getExecutor and then I use the first for build Compilable queries and I use the separated query executor to execute those. So I need a queryId
KNKristian Notari3/7/2023
Are there some technical reasons to choose a specific implementation for the createQueryId or I can just use whatever random string I want?
IIgal3/13/2023
Hey ๐Ÿ‘‹

Sounds like you're trying to pull off things done in this [recipe](https://github.com/koskimas/kysely/blob/master/recipes/splitting-build-compile-and-execute-code.md)

You should be able to pass a uuid
KNKristian Notari3/13/2023
Thanks! I'm doing something similar, just wanted to be sure I could use whatever queryId I wanted as long as it's unique (I guess) as when using UUIDs
KNKristian Notari3/13/2023
On top of such recipe, there's no way to "omit" the execution bit from the query builder right? So for example if I'm mistaken and use the dummy kysely instance to do an execute and not just compile I get a runtime error without prior warning, right?
IIgal3/16/2023
On top of such recipe, there's no way to "omit" the execution bit from the query builder right? So for example if I'm mistaken and use the dummy kysely instance to do an execute and not just compile I get a runtime error without prior warning, right?

According to the recipe:

Trying to execute queries using "cold" kysely instances will return empty results without communicating with a database.
KNKristian Notari3/17/2023
Yes, but that doesn't prevent me or someone else from using kysely to generate promises which will never get correctly executed at runtime, while being correct at compile-time.

My use case is the one where I create a kysely instance, get the executor from it and wrap it with a function "execute" so that it run the promise with a Compilable, catch the result and return a Result | Error basically, so that it never "crash/throw".

I then proceed to use the kysely instance as a query builder. It would be nice to evict all the "execution" capabilities from it in order to make it typed as it was only a query builder.
KNKristian Notari3/17/2023
so that I'm forced to use my execute function which has the kysely executor inside, everytime I need to execute something created by the kysely query builder
UUUnknown User3/17/2023
2 Messages Not Public
Sign In & Join Server To View
KNKristian Notari3/17/2023
I was asking if it was feasible at all to completely separate the query building capabilities from the exection features. I guess that's dialect agnostic too (it would be more, nonetheless)
UUUnknown User3/17/2023
Message Not Public
Sign In & Join Server To View
KNKristian Notari3/17/2023
It's a type thing at the end, removing .execute methods from query builders
KNKristian Notari3/17/2023
I assume it's not so easy now with a lot of types ๐Ÿ˜„
UUUnknown User3/17/2023
Message Not Public
Sign In & Join Server To View