Creating a Generic Service for a Drizzle/Postgres Database in Effect Typescript
Hey, so I want to create an
When I say "loosely" here I mean that I want to pass a drizzle schema to the service and let the schema's type be reflected in the drizzle object the service returns.
I can't just pass the schema as an argument to some
This brought me into the rabbit hole of "generic services" and after digging through discord and learning that this is an anti pattern and best solved with a "service factory" I came up with the following code and am now looking for feedback if what I did is fine or not and if it could maybe be solved better. Here is the code:
Effect.Service which loosely abstracts over a drizzle/postgres database. When I say "loosely" here I mean that I want to pass a drizzle schema to the service and let the schema's type be reflected in the drizzle object the service returns.
I can't just pass the schema as an argument to some
Layer function as I do with the database connection details, because then the schema type will not be reflected in the service.This brought me into the rabbit hole of "generic services" and after digging through discord and learning that this is an anti pattern and best solved with a "service factory" I came up with the following code and am now looking for feedback if what I did is fine or not and if it could maybe be solved better. Here is the code:
