bombillazo
Explore posts from serversKysely client usage and pooling question
Hello,
We have a long running server that at the moment creates a single Kysely instance. It is setup to use pg pooling. We have a util function called getKysely which returns this instance and is used throught our backend , like on every request handler that calls the DB. So in theory multiple concurrent requests call this function to get the Kysely client and make queries.
We are noticing that even within the same API endpoint handler, executing queries with a fetched client seems to be running on different connections. We think this because we sometimes execute raw sql queries which change the role of the connection, but later on using the same client we execute a query to check the current role and it is not the one set up previously.
I am curious about how Kysely internally uses pooling, does it fetch a connection from the pool on every query? I know we are using a singleton, but how can I make sure that Kysely uses a single connection throughout the scope of a single request?
7 replies
Kysely setup in monolith API
Hello, we have a basic http server with a basic router and a PostgreSQL database. We're wondering what is the proper setup to use the Kysely client in our routes to make calls to the database. Should there be a singleton client that is used across routes, or do we need to instantiate a kysely client on every request ?
10 replies
Omit/filter out columns from query
Hey, is there an easy or convenient way with Kysely to filter out data from a query? Lets say I have columns 1,2,3,4,..., 10 and I want to omit column 9, do I have to really list all my columns like this:
?
11 replies
How to create a typed array of columns for select?
Hello, I am trying to create some helpers that contain the list of columns used by multiple queries, and I want to have them typed to the table they belong to to have it suggest errors if a table changes or someone uses a non-valid column. How is this achievable with the kysely helper types? The array may also include expression builder or the
jsonObjectFrom
helpers since they are valid Select options3 replies
Ad hoc custom column type
Hello, we have a table that on the database level, the column is a string type, but on the typescript level, the type is a Type literal union.
Is there any way we can ad hoc type a column to a type we know during select queries and insert statements?
9 replies
Any way to docutype a Column as `@deprecated`?
Hello, We'd like to have columns we specify in out types with the
@deprecated
type identifier in the Table type definition comments to be used in queries, is there a way to make it work with Kysely?4 replies
Use JSON key as text
Hello, I am using the following syntax to fetch data in a JSONB column:
This returns
my_val
as a json value which is equivalent to using ->
, how can I retrieve the data using the Postgres ->>
operation that returns the data as TEXT?4 replies
Query building optimization question
Hello, Id like some input from Kysely advanced users about my approach to using the
eb
. If I have a conditional select query, is this efficiently using the eb
object for my query? Is it ok to use multiple levels of eb
s ?
6 replies
Relational table join question
Hey, just out of curiosity, does Kysely have any helpers for joining tables across a relational table? For example, if I have tables
user
and account
joined via the user_account
relational tables, if I use jsonArrayFrom
from a query on the user
table to get accounts, do I always need to do a join with the intermediary table or does Kysely provide any type of shortcut for this?6 replies
Deno usage
Hey, has anyone by any chance trie using Kysely with deno using the
postgresjs
library? https://github.com/porsager/postgres4 replies