#End-to-end type safety, from PostgreSQL to React using Kanel and tRPC (Question)

14 messages · Page 1 of 1 (latest)

frozen gazelle
#

I have a lecture later today called End-to-end type safety, from PostgreSQL to React
It will look at how the TypeScript open source tools Kanel and tRPC.

It seems to be saying that they will discuss the trade-offs there are by not using a traditional Object/Relations Mapper (ORM) but instead letting the database be the source-of-truth for models in both backend and frontend. And they will look at how tRPC can be used to maintain this type safety in our API.

Am I understanding the description correctly: Kanel and tRPC are tools that allow you to directly connect PostgreSQL with React without the use of Prisma, Sequelize, TypeORM,Drizzle ORM etc?

Also: Not to sound too noobish, but how does Zod play into all of this? Would Zod still be useful for Kanel and tRPC? Or is Zod used for something totally else?

cursive rapids
#

tRPC manages routing, data validation/serialization, and a few other things for your HTTP API. it doesn't have anything to do with databases

Zod is a data validation library that can be used to validate incoming request data with tRPC, or elsewhere in your program for other things

i haven't used Kanel but here's the first sentence of the blog post that introduces it:

I’ve created a tool that extracts the schema of a Postgres database and generates Typescript types out of it.
it doesn't seem like Kanel is used to interact with your database at runtime at all. you'd still use another library (they suggest Knex) for that part. if you use a library like Prisma/TypeORM/Drizzle what Kanel does isn't useful to you since you're probably already defining your database schemas in code and have typescript types which line up with them (though note that Drizzle at least also has a tool to generate a typescript representation of existing database schemas, like what Kanel is doing. wouldn't surprise me if those other packages do too)

frozen gazelle
cursive rapids
#

i don't think that ORMs necessarily invert control like that. e.g. with drizzle you can go in either direction (others may be the same)

frozen gazelle
#

oh

#

now I see what you mean

#

Drizzle can also go the other way by generating typescript representation of existing databases

cursive rapids
#

it's nice to manage database schema changes in code, because it can be committed along with your application code. for that reason alone it's nice to invert control

frozen gazelle
cursive rapids
#

the latter. databases (at least those i know about) don't actually keep a record of exactly how you set up your tables, just their current schemas