blefnk / relivator

Next.js 15 eCommerce Template ▲ i18n Stripe Shadcn Tailwind Drizzle Zod tRPC TypeScript Clerk Authjs Radix UI, Responsive React 19 Server Components, MySQL Postgres Neon TS ORM, Intl App Router Docs User Actions Kit, SaaS Commerce Shop Pricing Payments, Dark Mode, Full Stack Free ▲ more stars → more featur
https://relivator.reliverse.org
MIT License
961 stars 203 forks source link

✅ Drizzle: Fix Typesafety & Autocompletion #32

Open blefnk opened 4 months ago

blefnk commented 4 months ago

It's not an issue anymore, it's a story. Over several versions of Relivator and many months, I put a lot of effort into combining Postgres and MySQL as well as the providers of these services (Neon/Planetscale/Vercel/etc.) as best I could. This was necessary to have opportunity to change the provider only with the help of an .env file, means on-the-fly. I have to admit, it turned into hell.

So, typesafety was lost, and I spent a long time trying to provide the correct types, starting with importing Drizzle's own types with even trying to create my own types. But it always came down to the fact that Postgress and MySQL types were combined into one, which is why TypeScript could not cross them correctly, because there were some parameters somewhere and not others, I was have even trying to narrow down these types (and, yes, I learned TypeScript quite well thanks to this challenge). It was months, I'm a psycho I know, don't make the same mistakes, haha.

Working on the 1.2.6 update, I fixed typesafety and autocompletion. Now it's just a matter of uncommenting out a single needed line in the two index.ts files. And starting from 1.3.0, the project will have only Postgres (since Planetscale is now only paid, I think MySQL will lose a lot of popularity in the JS community). But don't worry, thanks to the Reliverse CLI, you can always bootstrap your own version of Relivator with MySQL, and even with Prisma 😉, if you need to.

I will leave this issue open here for a while longer so more people can see it. If anyone has any thoughts on this, please feel free to comment.

blefnk commented 4 months ago

As mentioned in PR #29, I'm working on adding better-sqlite3 to the project. This will be delivered in Relivator 1.2.6 or 1.3.0. And also, the project will now have support for private/local Postgres and MySQL thanks to the mentioned PR. SQLite will be the standard provider once it is fully delivered, because it doesn't require any additional setup unlike local Postgres and MySQL. upd. As an option, SQLite will be default, but it will be possible to switch to Postgres manually by commenting out specific lines.