ohmi
Figuring out where in codebase an exception originated from
Hi all,
This might be a stupid question, but what is the best way to figure out which
.execute()
call threw a SQL exception? I know ideally I should be doing error handling on each call, but I have a large codebase and I'm not sure where this error is coming from. Is there any easy way of figuring this out? Maybe a way to have a wrapper that prints out the query if malformed, or to print out the stack trace where the original call was executed?
30 replies
Using column aliases in `.where()`
This is a supported feature in MySQL, but having issues here:
https://kyse.link/?p=s&i=xxyMrfnfJ6CjbRlQZpMA
Do I need to do something special for it to recognize the alias?
7 replies
Querying two different tables with subset of common columns
I have two tables that have an intersection of common columns that I'm looking to query. For each of the tables, I have identical conditional logic (
.where
s) that I'd like to apply for both queries, and it's quite extensive so I'd prefer not to copy and paste. My query would only .select
the common columns.
Is there any Kysely-ic way of doing this?15 replies
.where('x', 'is not', null) and correspond type's nullability
Not sure if this even possible in typescript (although all of the work Kysely already makes it seem magical). But let's say we have a column 'x' that has type
string | null
. Is it possible to write a query that ends up resulting in a final type of string
after using .where('x', 'is not', null)
or any similar method?12 replies
Running database agnostic queries (MySQL)
As part of my test suite, I drop/create databases programmatically. Is it possible to have a Kysely connection that isn't attached to a specific database, so that I could run queries like
DROP DATABASE a
or CREATE DATABASE a
?
Other similar use cases include:
RESET QUERY CACHE
, SELECT 1
(for latency check), etc8 replies
Asserting type of .countAll() (MySQL)
I've noticed that the return type from the result of aggregation functions like
countAll()
and sum()
are string | number | bigint
.
I assume this is in-case the number returned is too large to be stored in a JS "number." In my case, it appears to be being returned as strings
. Is it possible to assert it as a number
so that I don't need to wrap every query in a parseInt(result as string, 10)
?7 replies
kysely-codegen for multiple databases
I have two MySQL 'databases' within the same instance. From the documentation, it doesn't look like the codegen has innate support for multiple databases with different schemas?
I could codegen with the two different connection strings with a different
--out-file
, rename the exported interfaces, then manually update index.d.ts
, but I was wondering if there's a better solution?14 replies
Using MySQL functions in SELECT statement
Hi!
Just trying to migrate over from Knex. Skimmed over the documentation but still unsure of how to replicate this query in Kysely, or might be looking in the wrong place? In Knex, I'd often have to use
selectRaw
for these
SELECT a, b, UPPER(c) FROM x;
6 replies