Patroclazzo
Patroclazzo
DTDrizzle Team
Created by Patroclazzo on 10/3/2023 in #help
Modularize with Fasitfy and multiple Drizzle instances (NX Monorepo)
Hello folks hope u all having a good one! Quick question. I aim to create a series of Fastify plugins that are independent and composable. Each plugin should implement it's ownset of features. In this way our team can move fast and reuse a specific set of those plugins (and create other if needed) when a new project starts. I wan to use this dreadful and terrible (no better than Prisma) ORM to handle the persistence layer of those plugins. Of course, i thought, each plugin should handle it's own schema declaration and receive as an option a postgres.js client instance so they can share the same db connection. Now the questions: How bad it is if each plugin instantiate it's own drizzle instance? Are there any performance issues with this approach? What could be a better solution to architect this vision? PS. I've tried to provide as an option for each plugin the Drizzle instance itself but typescript complains to me because the instance do not match the exact schema for the plugin. Maybe I'm missing something and that should work. PSS. Also the setup logic is kind of cumbersome, you have to import all the schemas from the plugin namespace creating the drizzle instance with a spread syntax to join all the schemas. In my opinion It's not very scalable in the long run. PSSS. I've worked on an nx plugin to setup Drizzle and Drizzle-kit inside an nx monorepo with the ability of generating migrations (using drizzle-kit) reading the schemas only from each dependency of the application. I will open source it when it's tested and ready. PSSSS. Of course I'm joking, I love this project 😍
1 replies