I was reading this site about the clojure web stack:
http://brehaut.net/blog/2011/ring_introduction
and it has this to say about ORM for clojure:
"There are no SQL/Relational DB ORMs for Clojure for obvious reasons."
The obvious reason I can see is that the mapping to object happens automatically when you do a clojure.contrib.sql or clojureql query. However it seems some extra work is needed to do one-to-many or many-to-many relations (although maybe not too much work).
I found this write up for one-to-many: http://briancarper.net/blog/493/
Which I'm not sure I agree with; it appears to be assuming that both tables are pulled from the database and then the joined table is filtered in memory. In practice I think the sql query would specify the where criteria.
So I'm left wondering, is there some fairly obvious way to automatically do one-to-many relations via clojureql or clojure.contrib.sql? The only thing I can think of is something like this (using the typical blog post/comment example):
(defn post [id] @(-> (table :posts) (select (where :id id)))) (defn comments [post_id] @(-> (table :comments) (select (where :post_id post_id)))) (defn post-and-comments [id] (assoc (post id) :comments (comments id)))
Is there any way to sort of automate this concept or is this as good as it gets?
I asked this question quite a while ago, but I ran across the following and decided to add it as an answer in case anyone is interested:
http://sqlkorma.com/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With