kysely
kysely copied to clipboard
Implement `JOIN ... USING` query
Fixes #730
The latest updates on your projects. Learn more about Vercel for Git ↗︎
Name | Status | Preview | Comments | Updated (UTC) |
---|---|---|---|---|
kysely | ✅ Ready (Inspect) | Visit Preview | 💬 Add feedback | Apr 21, 2024 9:11am |
To implement JOIN ... USING
, I added a new type argument to JoinBuilder
, C extends string
, representing the column names which are common to both tables being joined.
I see that JoinBuilder
is also used for the MERGE
query. Consequently this PR allows for a MERGE
syntax which is not valid in Postgres and probably not valid on any DBMS:
// merge into person using pet using (id)
db.mergeInto('person').using('pet', (join) => join.using(['id']))
There are a couple ways to solve that (if maintainers here think it's worth solving):
- Create a
SelectJoinBuilder
which extendsJoinBuilder
and adds theusing
function. UseSelectJoinBuilder
forSELECT
queries and useJoinBuilder
forMERGE
queries -
MERGE
queries could assignC = never
as the type param toJoinBuilder
Hi! This is very useful feature for me and I would love to see it in kysely, so thank you @dwickern!
Also are there any improvements needed to be done by the community to move this PR forward to be merged?
To implement
JOIN ... USING
, I added a new type argument toJoinBuilder
,C extends string
, representing the column names which are common to both tables being joined.
Sounds like it's not crucial and could've been placed on the method/s. We're usually quite conservative when it comes to adding more generic parameters to existing builders. There has to be a good reason.. e.g. proving TypeScript compile performance is much better this way.
I see that
JoinBuilder
is also used for theMERGE
query. Consequently this PR allows for aMERGE
syntax which is not valid in Postgres and probably not valid on any DBMS:// merge into person using pet using (id) db.mergeInto('person').using('pet', (join) => join.using(['id']))
There are a couple ways to solve that (if maintainers here think it's worth solving):
- Create a
SelectJoinBuilder
which extendsJoinBuilder
and adds theusing
function. UseSelectJoinBuilder
forSELECT
queries and useJoinBuilder
forMERGE
queriesMERGE
queries could assignC = never
as the type param toJoinBuilder
That's fine for now, not worth the extra builder/s IMHO. BYOSK (bring your own SQL knowledge).
@dwickern Hope you have time to finish the pull request and insure that it gets merged. Since it is a very nice feature and very nice work.
Seems to be abandoned.