Hi all, new to clojure and polylith. I saw the polylith example and I have a question, https://github.com/furkan3ayraktar/clojure-polylith-realworld-example-app/blob/master/components/user/src/clojure/realworld/user/store.clj, here the user component is using the jdbc, make it hard to switch the database implemtation, what's the best way to structure the database component so I can easily switch to another implementation, say a in-memory atom for testing? do I put the model operations in the database component like this python example did https://github.com/DavidVujic/python-polylith-example/blob/main/components/example/database/message/crud.py?
You can use H2 in-memory with JDBC. The Polylith variant of my usermanager example app uses H2 for tests (file-based, but could easily switch to in-memory): https://github.com/seancorfield/usermanager-example/blob/polylith/components/schema-fixture/src/usermanager/schema_fixture/core.clj while the regular app uses SQLite https://github.com/seancorfield/usermanager-example/blob/polylith/components/schema/src/usermanager/schema/core.clj
Using Component is a nice way of being able to both support a start/stop stateful resource and also being able to easily swap implementations for testing.
oh didn't know I can do H2
Just for excerise, what If I really want to switch to atom hh, does it mean I need to implement something like a user_repository protocol?
Even with PostgreSQL, there's a full in-memory implementation you can use for testing. See how next.jdbc handles that for an example of the test dependencies you need etc.
I don't think it's worth the overhead of trying to switch to a repository pattern just to use an atom when there are JDBC-based in-memory and local file options available.
In OO-land, you kind of have to do that pattern-based swap, but no reason to do it in Clojure, IMO.
got it, I guess I'm still the mind shift period 😅. Thanks for the answer. Also your example repo is more up to date, I'll use it more often for reference
Even in the XTDB variant of the usermanager app (non-Polylith), I use an in-memory version for testing, and a regular version (Docker or cloud-based) for "production-like" behavior.
We have a pretty massive Polylith repo at work -- 200+ components, 20+ bases -- and I maintain next.jdbc, HoneySQL, and three variants of the usermanager example app 🙂
cool, yeah I think I read the story at your work and I decide to give Polylith a try hh
Cool. And welcome to Clojurians! 🙂
(I'm also one of the Admin team here)
Thank you so much
Happy to see one more Polylith user! polylith