Clojure.contrib.sql: How do I retrieve the results of a select statement into a vector that can be accessed anytime? -
for example, in query:
(clojure.contrib.sql/with-query-results rows ["select count(*) tablename"] (doseq [record rows] (println (vals record))))
it seems record , rows don't exist outside scope want exist anytime me access.
update: tried next lines of code
(def asdf []) (sql/with-connection db (sql/with-query-results rows ["select * tablename"] (doseq [record rows] (def asdf (conj asdf record))))) (println asdf)
why print statement of asdf above homecoming empty when added rows in sql statement?
you seem lack basic understanding of clojure's underlying principles, in particular immutable info structures. conj
phone call doesn't modify var asdf
-- var not variable. next (untested)
(def asdf (sql/with-connection db (doall (sql/with-query-results rows ["select * tablename"]))))
to store result straight value of asdf
, not want. familiar clojure's take on functional programming instead.
sql clojure
No comments:
Post a Comment