I'm writing a Compojure TODO app and with MySQL as the primary data store. I'm using clojure.contrib.sql to interface with MySQL as follows:
(def db {:classname "com.mysql.jdbc.Driver"
:subprotocol "mysql"
:subname "//localhost:3306/todo"
:user "<user>"
:password ""})
The queries I'm using seem to work, however the results appear to be cached. For example, after running
(with-connection db
(insert-values :todos
[:name] [name]))
the value is successfully inserted into the database. However,
(defn sql-query [query]
(with-connection db
(with-query-results rows [query]
(into [] rows))))
returns the same value, regardless of how many items are inserted. Of course, if I restart the web app, the results are updated, but this doesn't seem very production-friendly :).
Any idea why this would be happening? Thanks in advance.
As requested, here is the top-level form for the SELECT query:
(def home-view
(render
(base {:title "Clojure Todo"
:content (apply str
(map #(% :name)
(sql-query "select * from todos")))})))