Reusable CTEs that depend on previous CTEs
I have 2 CTEs that I'd like to separate out into separate functions for readability.
These are the CTEs:
I know I can extract the first one like this:
But if I do the same for the second one, it won't be able to reference the
chatMessages
table . Is there a way to do that?
The most relevant docs I found were https://kysely.dev/docs/recipes/expressions, but it doesn't cover this usecase.
Thanks in advance!Solution:Jump to solution
If you meant
eligibleChats
instead of chatMessages
, then you can do it like this
...3 Replies
But if I do the same for the second one, it won't be able to reference the chatMessages table . Is there a way to do that?Why wouldn't it be? The first one is able to reference it, so why wouldn't the second one be?
Solution
If you meant
eligibleChats
instead of chatMessages
, then you can do it like this
Yes, I did mean
eligibleChats
. Apologies!
Thanks a lot! In hindsight, it's obvious that there's no other way for a reusable function to know about the existence of some entity (table?) without extending the DB type.