[postmodern-devel] Quoted lists with QUERY or SQL
Hello, I'm working on a Postmodern backend for weblocks. To conform to their Store API<http://bitbucket.org/S11001001/weblocks-dev/src/f14b59da2238/src/store/store-api.lisp> I need to implement a count-persistent-objects method. I would like to be able to write something like: (defmethod count-persistent-objects ((store list) class-name &key where &allow-other-keys) (let ((sql-expr `(:select (:count '*) :from ,class-name ,@(when where (list :where where))))) (with-connection store (query sql-expr :single)))) However a simple test of this results in a type error: The value of CL-POSTGRES::QUERY is (:SELECT (:COUNT '*) :FROM QUOTES), which is not of type STRING. Is there a reason that query doesn't support evaluated lists? If so, how would you recommend this be done? Regards, Brit Butler
Is there a reason that query doesn't support evaluated lists?
Yes. These macros also accept string input, and assume that everything that's not a list starting with a keyword will evaluate to a string.
If so, how would you recommend this be done?
You can either add an sql-compile around your sql-expr, which does a run-time compilation of an s-sql expression (normally they happen at compile time), or do something like this: (defmethod count-persistent-objects ((store list) class-name &key (where t) &allow-other-keys) (with-connection store (sql (:select (:count '*) :from class-name :where (:raw (if (stringp where) where (sql-compile where))))))) Best, Marijn
sql-compile is exactly what I was looking for. Thanks Marijn. And thank you for Postmodern! Regards, Brit On Tue, Nov 30, 2010 at 3:36 AM, Marijn Haverbeke <marijnh@gmail.com> wrote:
Is there a reason that query doesn't support evaluated lists?
Yes. These macros also accept string input, and assume that everything that's not a list starting with a keyword will evaluate to a string.
If so, how would you recommend this be done?
You can either add an sql-compile around your sql-expr, which does a run-time compilation of an s-sql expression (normally they happen at compile time), or do something like this:
(defmethod count-persistent-objects ((store list) class-name &key (where t) &allow-other-keys) (with-connection store (sql (:select (:count '*) :from class-name :where (:raw (if (stringp where) where (sql-compile where)))))))
Best, Marijn
_______________________________________________ postmodern-devel mailing list postmodern-devel@common-lisp.net http://common-lisp.net/cgi-bin/mailman/listinfo/postmodern-devel
participants (2)
-
Brit Butler
-
Marijn Haverbeke