>>34883Learned the repo pattern from TypeORM. And dependency injection of repos from FastAPI. Where these patterns are nearly sacrosanct. As part of my efforts to not abandon negated pieces, ended up trying to emulate these with raw SQL — via pgtyped. Despite having run into issues with the translation layers of TypeORM and SQLAlchemy/SQLModel. A backport I guess?
In my most recent project anatta wanted to get the testing benefit of a functional core imperative shell — which are made much easier by the repo pattern and dependency injection. The repos just being mocked as simple functions, passed to another simple function for the tests.
On top of this I ended up using a unit-of-work pattern, and writing it as on-rails pattern wrapping all the repos all at once. The transaction doesn't need to be mocked in the test because of this, and the errors are uniformly handled, the same way as Zod errors for example — none of which reach the 500 handler in my app.
Of course protection against SQL injection was a requirement, and type safety a big added bonus. Anyway my experience has indicated that ORMs are upside down — that the full flexibility of SQL can be had with all the abstractions of your programming language of choice through something like hugsql (clojure), pugsql (python), or pgtyped (typescript).
Then again plain programming in strings is not good enough for what I've done. That would require tons of hand written boiler plate, and tools would not work on the queries.
https://gitlab.com/anatta/anatta/-/tree/main/database