Building a Type-Safe Database Workflow With Kysely

https://hackernoon.imgix.net/images/GKMDC80avThn4WCIH2KxmeCMx9o1-cm82cwi.png

Talking to a database with Node usually goes one of two ways: you write raw SQL and trust that the strings in your code still match the columns in the database, while dealing with SQL injections and migrations by yourself, or you pull in a full ORM and inherit an entire opinionated world just to run simple queries. Both work fine until someone renames a column and you find out about it in production, or you want to do something slightly different and your ORM just won't let you. Fortunately, there's a middle ground where you can get the best of both worlds.

Writing queries with Kysely

Kyselyis a query builder, not an ORM. There's no entity layer, no lazy loading, no magic session flushing things behind your back. You describe your schema once as a TypeScript interface and from there every method on the builder narrows what you're...

Copyright of this story solely belongs to hackernoon.com. To see the full text click HERE

Read more