[postmodern-devel] Retrieving completely populated DAOs based on SQL string query

Marijn Haverbeke marijnh at gmail.com
Tue Oct 5 11:32:11 UTC 2010


> (select-dao 'foo-db-name (:in 'foo.id (:set (flatten (query "SELECT DISTINCT
> foo.id FROM foo_member INNER JOIN foo_show ON (foo_member.id =
> foo_show.member_id) INNER JOIN foo_series ON (foo_show.series_id =
> foo_series.id) WHERE foo_series.year = 2011))))

Ouch! You could express the IN test using a subquery to save a
round-trip, but beyond than that there's not much hope of making this
look sane. I think this should work (untested):

(select-dao 'foo-db-name (:in 'foo.id (:raw "(SELECT DISTINCT foo.id
FROM foo_member INNER JOIN foo_show ON (foo_member.id =
foo_show.member_id) INNER JOIN foo_series ON (foo_show.series_id =
foo_series.id) WHERE foo_series.year = 2011)")))

(Also, your flatten function is probably something like mapcar #'car,
which you can more easily do by passing the query macro a second
argument of :column)




More information about the postmodern-devel mailing list