Hi :
I would try to make a macro to simplify the database methods as
follows, but it doesn't work,
is there any way to fix it, or any easier solution? Thanks..
(defmacro with-db [& body]
`(with-connection *db* ~...@body))
(defmacro with-transaction [& body]
`(with-db (transaction ~...@body)))
;
; basic table operations - drop, insert, update, select(by id)
;
(defmacro create-database-methods [db]
(let [db# db]
`(do
(defn (var (str "drop-" db#)) []
(try
(drop-table (keyword ~db#))
(catch Exception _))
(defn (var (str "insert-" db#)) [body]
(insert-values (keyword ~db#)
(keys body)
(vals body)))
(defn (var (str "update-" db#)) [id attribute-map]
(update-values (keyword ~db#)
["id=?" id] attribute-map))
(defmacro select-userentry [id & body]
`(with-transaction
with-query-results rs [~~(str "select * from " ~~db# "
where id=?") id]
~...@body))))))
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en