Live data from Hacker News

Show HN: Kysely, a type-safe SQL query builder for TypeScript

kysely.dev

51–60 of 65 posts

Re: Show HN: Kysely, a type-safe SQL query builder for TypeScript

#51
post #23

If you want to run SQL, write SQL. The majority of your SQL will not require building dynamic where clauses or (dog forbid) dynamic joins. Having your SQL as plain statements with simple placeholders (to create safe prepared statements) is the saner approach. Not only can you pluck them into your favorite SQL tools and analyzers, but you will not be surprised by terribly performing queries, because you created them d…

Any patterns you'd recommend? (pseudo code)

1) db.execute("select name, tel from person where id={?}",personId);

2) const sqlText="select name, tel from person where id={?}";

db.execute(sqlText, personId);

3) as 2), but put sqlText in another file,

Re: Show HN: Kysely, a type-safe SQL query builder for TypeScript

#52
post #8

How does it compare to zapatos? https://jawj.github.io/zapatos/

I'd suggest you try them both, and pick what you like better or what feels safer to bet on for your project.

I know some of our users use both, zapatos for codegen and kysely for querying.

Re: Show HN: Kysely, a type-safe SQL query builder for TypeScript

#53
Love Kysely, been rooting for it ever since it was first released. Paired with kysely-codegen, it's my favorite TS SQL interface. Does just enough, but not too much.

Had lots of good experiences working with Knex.js over the years, and Kysely is the TS-native spiritual successor to Knex.

Re: Show HN: Kysely, a type-safe SQL query builder for TypeScript

#54

Love Kysely, been rooting for it ever since it was first released. Paired with kysely-codegen, it's my favorite TS SQL interface. Does just enough, but not too much. Had lots of good experiences working with Knex.js over the years, and Kysely is the TS-native spiritual successor to Knex.

<3 from Kysely. kysely-codegen is dope!

Re: Show HN: Kysely, a type-safe SQL query builder for TypeScript

#56
Kysely looks interesting, although I really like being able to write the query directly so I'm able to test the raw query directly. PgTyped is an interesting library I've used in the past where queries can be written as regular template strings that gets checked and responses become types. https://pgtyped.dev/docs/ts-file

Re: Show HN: Kysely, a type-safe SQL query builder for TypeScript

#57
Have used it for a smaller project for a bit now and I really like it as well. Concise code and I can still map it to actual SQL in my brain.

What has been a bit non-intuitive for me though is the expression builder since the latest major version of kysely. When writing queries with `OR` conditions it always takes me a while to wrap my head around it again. It is also challening to make this easily readable with lots of dynamic `OR` conditions and I usually end up with a wrapper function which returns the array for the statements passed into the `or(` block. Could be improved in my opinion, otherwise a great tool

Re: Show HN: Kysely, a type-safe SQL query builder for TypeScript

#58
post #23

If you want to run SQL, write SQL. The majority of your SQL will not require building dynamic where clauses or (dog forbid) dynamic joins. Having your SQL as plain statements with simple placeholders (to create safe prepared statements) is the saner approach. Not only can you pluck them into your favorite SQL tools and analyzers, but you will not be surprised by terribly performing queries, because you created them d…

For me, Rusts SQLx has been a good option for this. Write plain SQL with a macro and have it verified against a dev database at build time, optionally to a typed anonymous struct to match your query results. The performance isn't incredible though.

I've been curious about sqlx for a while. About the non-incredible performance: Do you mean the performance of the verification in development, or the performance of sqlx execution in a live setting?

Re: Show HN: Kysely, a type-safe SQL query builder for TypeScript

#59
I am building squashql-js for a slightly different use case (database agnostic SQL-like Typescript query builder among others) but Kysely and pypika (for Python) have been a great source of inspiration.

https://github.com/squashql/squashql/blob/main/documentation...

Re: Show HN: Kysely, a type-safe SQL query builder for TypeScript

#60
post #57

Have used it for a smaller project for a bit now and I really like it as well. Concise code and I can still map it to actual SQL in my brain. What has been a bit non-intuitive for me though is the expression builder since the latest major version of kysely. When writing queries with `OR` conditions it always takes me a while to wrap my head around it again. It is also challening to make this easily readable with lots…

Would love to have a discussion about your use case in our discord. We're constantly thinking about improving that part of our API as it's at the heart of many things.
Post reply on HN