I am writing a Compojure TODO and MySQL application as the main data warehouse. I use clojure.contrib.sql to interact with MySQL as follows:
(def db {:classname "com.mysql.jdbc.Driver" :subprotocol "mysql" :subname "//localhost:3306/todo" :user "<user>" :password ""})
The queries I use seem to work, however the results seem to be cached. For example, after starting
(with-connection db (insert-values :todos [:name] [name]))
The value was successfully inserted into the database. Nonetheless,
(defn sql-query [query] (with-connection db (with-query-results rows [query] (into [] rows))))
returns the same value no matter how many elements are inserted. Of course, if I restart the web application, the results will be updated, but this is not very convenient for production :).
Any idea why this will happen? 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")))})))
source share