Thanks Daniel, and Sean for your answers. 

Daniel, the part that interests me the most is "converting resultset rows 
to collection (of objects)", and I think a lot of people do just what you 
said (own customized function). I was looking for, and will probably in the 
end implement an open source library that does exactly that in some 
standardized way. 

Sean, maybe my use case is specific to web applications. In REST API's it's 
common to respond with something like "Example Result" here: 
https://dev.twitter.com/rest/reference/get/statuses/mentions_timeline I 
completely agree with you about ORMs, but in case of REST API's one just 
needs to somehow map the queryset to a structure of hashes and arrays (not 
necessarily objects), and this task is much heavier than I thought in the 
beginning, from choosing between making many queries to fill in the hash of 
related objects vs making JOINs, to complexity of extracting data from a 
set of rows with potential repetitions, rows of null values (like Daniel 
said happens for instance in case of LEFT JOINS), and different kinds of 
relations (has-one, has-many, belongs-to). 

I just thought that maybe a tool for that (relational mapper - but not 
"object-" like it's common in Java, and Ruby, but just hashes and arrays) 
already exists, but if not, I'll implement it and open source it soonish. 
BTW, if there are here developers that would be interested in such tool, 
let me know what data format and a set of features would you find the most 
desirable. 



W dniu poniedziałek, 25 maja 2015 19:13:10 UTC+2 użytkownik Sean Corfield 
napisał:
>
> I just don’t consider it a problem. A query returns a flat result set — a 
> sequence of hash-maps. That’s it. That’s what SQL returns (essentially a 
> table) and it’s a perfectly reasonable data structure for Clojure to work 
> with.
>
> The JOINs in SQL just say how to link tables together to produce that 
> (flat) result set. Any structural grouping semantics you want to apply are 
> up to your application.
>
> FWIW, I find ORMs — which is where you’re going with this — to be far more 
> trouble than they’re worth and I just don’t see the benefit in Clojure 
> which is all about pure data structures. I worked with a lot of ORMs — and 
> written several of my own — over the last couple of decades and these days 
> I just avoid them.
>
> Sean
>
> On May 24, 2015, at 3:10 AM, Krzysiek Herod <krzysie...@gmail.com 
> <javascript:>> wrote:
>
> It seems to me that it's a problem that sooner or later appears in any 
> project using relational database (apart form easy cases, when there is no 
> many relations between tables). Am I missing something? How do you guys 
> work with database results of queries containing several tables referring 
> to each other? 
>
> W dniu czwartek, 21 maja 2015 21:57:03 UTC+2 użytkownik Krzysiek Herod 
> napisał:
>>
>> I've found the question appearing here, but a long time ago, so I thought 
>> that maybe the situation changed:
>>
>> Is there a relational mapper in clojure (or in java) that takes query 
>> result and generates an array of hashmaps?
>> I mean something that converts the result of this query:
>> "SELECT * FROM posts LEFT JOIN comments ON (comments.post_id = posts.id) 
>> LEFT JOIN users ON (posts.user_id = users.id)"
>> into (for example) the following structure:
>> [{:title "Post title" :user {:first_name "User 1"} :comments [{:title 
>> "Comment 1"} {:title "Comment 2"}]}]
>>
>> I've used kormadb for that, but it works like this only with has-many 
>> relation (belongs-to puts all of the fields from related tables into the 
>> same hash as if it was one table, and using "with" do not solve the problem 
>> neither).
>>
>> Is there any other clojure library that does that, or is any java library 
>> used instead?  
>>
>
>
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to