lukas.slezevicius
Advice for debugging timeout/connection issues with Kysely
Hi everyone,
We've been using Kysely with pg in prod in our startup for over a year now and everything has been mostly stable, however, we started encountering these random errors with no seemingly obvious reason.
I am 99.9% sure that this is not a Kysely specific issue, but I'd be grateful if someone could advice us on how to debug these issues, as we don't have much experience in this. Googling revealed some stack overflow threads were timeout configs were discussed, but that didn't help us too much.
The error is:
connect ETIMEDOUT 20.208.39.81:5432
.
The weird thing is that all the DB metrics are stable - memory, cpu, connections, etc.
Raising timeout values, or even making them indefinite does not seem to help.
We don't have too much data (2gb) and we rarely have queries that take more than a second to complete.
We set up our client like this:
Once again, we'd appreciate any pointers!1 replies
Typing reusable functions for filtering rows
Hi all, we're using Kysely at our company and loving it! We recently encountered some issues when trying to type reusable functions.
One example of our current attempt:
This works when our initial query is basic like this:
However, it stops working when we add some joins (which shouldn't break the original filtering function anyway):
If we update the SelectQueryBuilder middle type to be
"conversations" | "contactConversations"
, it works with neither the simpler, nor the more "complex" query.
I'd be thankful for any pointers and general tips on how to type reusable functions!6 replies
Syntax error when empty array is passed to a WHERE filter (request for more readable errors)
In a query like
someQuery.where("x", "in", xs)
, if xs
is empty, then the error will be something like error: syntax error at or near ")"
. Given that in complex queries there can be multiple places that could cause such an issue, debugging it is sometimes painful.
I understand that it's SQL that is throwing the error and empty arrays are not possible, but would it be feasible to do a runtime check by the lib and throw a more readable error in case that happens? Or would this be against the philsophy of Kysely or too much overhead?
Also, I think a fallback of 1=0
might make even more sense, since that should be the logical output of the query with an empty array.2 replies
Derived tables for Postgres
Hi, I am trying to do a bulk update like this:
I found that UpdateQueryBuilder supports update joins with
from
method, but I couldn't find how to create derived tables like in the pure SQL shown above.
Thanks!2 replies
How to add table/column comments when creating tables?
Hey, we're approaching close to 100 tables in our project. New people will be joining our founding team and we thought documenting the tables using the Postgres table/column commenting feature would make it easier to understand the DB schema.
After searching the docs, discord, and google, I couldn't find any info on how to do this in Kysely. Should we resort to raw SQL? Thanks!
6 replies
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!7 replies