Hi,

I'm writing an RSS-reader using compojure and clojure.contrib.sql. As
this is my first project in a functional language, I'm not sure about
how to design the application. The concrete question I'm having right
now, is how to encapsulate database queries in functions. For my
RSS-reader, a basic operations is to display lists of feeds that I
retrieve with the following code:

(sql/with-connection db
  (sql/with-query-results
    feeds
    ["select id, title from feeds order by title"]

As this happens at a few places in the code, I would like to
encapsulate it somehow. I see several approaches to this, but I'm
uncertain which of them is the most idiomatic way to do this in
Clojure.

(1) The straightforward approach seems to be a function that returns
the feeds. However, I would have to call (doall feeds) to get the data
out of the internals of contrib.sql/JDBC and into my application. So I
guess this would not be the most efficient way.

(2) Another idea is to create a function or macro with-feeds that
wraps the query and creates a binding to be used inside the body.

(3) Or I could have a function that takes another function as a
parameter which gets called inside with-query-results and gets feeds
as parameter.

Which of these variants -- or another one that I did not think of --
would you recommend?

Janico

--~--~---------~--~----~------------~-------~--~----~
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
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to