Closed anthonyalayo closed 1 year ago
You should take a look at Drizzle. It's closer to what you're looking for.
Your suggestion has its own drawbacks and is a completely different design. You get better type safety and much better autocompletion with Kysely's API.
We obviously won't make a complete rewrite.
you flow through your IDE's autocomplete as you continue to add clauses until you are ready to end your statement.
Your definition of flow is having to stop yourself to import something? 🙅
Your definition of flow is having to stop yourself to import something? 🙅
Not at all. Please don't misrepresent what I wrote and jump to a different conclusion. The fact that other popular libraries have this design is a good indicator of its value.
You should take a look at Drizzle. It's closer to what you're looking for.
Thanks for the pointer! I'll take a look.
Your definition of flow is having to stop yourself to import something? 🙅
Not at all. Please don't misrepresent what I wrote and jump to a different conclusion. The fact that other popular libraries have this design is a good indicator of its value.
Other languages have their own historical constraints and flavors. That doesn't mean that's good or bad.
A good API optimizes for readability - something that we do a lot more often than writing. Your examples, especially the first one, are verbose, overly complex and distant from SQL. Class & fluent interface overkill.
If anyone stumbles upon this issue, here's how you can write these in Kysely v0.24.2:
First example:
db
.selectFrom('actor')
.innerJoin('film_actor', 'actor.actor_id', 'film_actor.actor_id')
.innerJoin('film', 'film.film_id', 'film_actor.film_id')
.innerJoin('language', 'language.language_id', 'film.language_id')
.innerJoin('film_category', 'film_category.film_id', 'film.film_id')
.innerJoin(
'category',
'category.category_id',
'film_category.category_id',
)
.where('language.name', '=', 'English')
.where('category.name', '<>', 'Action')
.where('film.length', '>', 180)
.select([
'actor.actor_id',
'actor.first_name',
'actor.last_name',
'actor.last_update',
'language.language_id',
'language.name',
])
.selectAll(['film', 'category'])
.orderBy('actor.actor_id')
.orderBy('film.film_id')
https://wirekang.github.io/kysely-playground/?p=f&i=-NSrEdU2eJOeCAcIqKow
Second example:
db
.selectFrom('book')
.where('book.author_id', '=', 1)
.where('book.title', '=', '1984')
.selectAll()
https://wirekang.github.io/kysely-playground/?p=f&i=-NSrF7UUu2OG4znrGwfh
In both of these, could also make a single .where
invocation and use eb.and([...])
if wanted to be more explicit.
Hey there,
A year ago I browsed the internet looking for the closest thing to JOOQ / JET in TypeScript. After a year, I can definitely say that Kysely is almost there :-).
I started using it again, and the biggest DX issue I have is how filters (ie. where clauses) are designed. Even with my IDE auto-completing fields, there's significant friction to type out a comma separated list of fields.
Here is an example from Jet (in Go):
And an example from JOOQ (in Java):
The benefits you get from the builder syntax is clear -- you flow through your IDE's autocomplete as you continue to add clauses until you are ready to end your statement.
Would Kysely be interested in an API like this?