kurierjs / kurier

TypeScript framework to create JSON:API compliant APIs
https://kurier.readthedocs.io/en/latest/
MIT License
61 stars 9 forks source link

Ability to replace Knex with Prisma #276

Open isBatak opened 3 years ago

isBatak commented 3 years ago

This is just an idea, but it would be cool to support Prisma and implement PrismaProcessor. https://www.prisma.io/

joelalejandro commented 3 years ago

Looks very interesting @isBatak, it seems that it supports pretty much everything covered by Knex. However, instead of replacing, I'd like to keep support for Knex, since it's already there.

On the long run, if we add more support for packages like Knex or Prisma, we'd need to create a DatabaseProcessor with the generic features and then both KnexProcessor and PrismaProcessor can implement from there. However, this feels a bit cumbersome at present, given that we need to explore more APIs to come up with an adequate abstraction.

Have you used Prisma before? I'm not entirely familiar with it.

isBatak commented 3 years ago

Yeah, wrong title... it should be more like "Ability to replace Knex with Prisma".

I like the DatabaseProcessor idea, it could be an abstract class or interface. Kinda a side-thought, can TS compiler do a Dead Code Elimination (three-shaking) of abstract class methods 🤔 . I'm primarily a Front-end developer so I always think about bundle size.

To be honest I don't have a real experience with Prisma but it seems like a great solution for serverless architecture. I'm experimenting with a combination of Kurier, Next.js, Datx here https://github.com/isBatak/next-js-json-api-starter. Next.js/Vercel is built with serverless in mind on top of AWS Lambda@Edge, and to use any database we need to have some kind of connection pool. I read that Knex has some solution but it's unreliable and should be handled on the DB side (like PgBouncer https://www.pgbouncer.org/). So it seems to me that Prisma is a much simpler solution and it works OTB with Next.js.

I agree that this is a long shot for now...

joelalejandro commented 3 years ago

Interesting. You might want to take a look at #282 then, since we're starting to include features to make Kurier compatible with serverless environments as well. The fact that Prisma works out-of-the-box with Next.js also makes me want to explore more how an integration would look like.

isBatak commented 3 years ago

I saw #282 and I'm really excited and can't wait to test it... is it included in 1.2.0-alpha1 version?

joelalejandro commented 3 years ago

Yes, you can try it out in 1.2.0-alpha1, beware of the unforseen ~dragons~ bugs though :P