Just a small snippet of code for this week. Had a situation where needed to insert a Date value with Korma for one of my databases. Some minor troubleshooting led me to this code snippet that made life a lot easier. Note: the parameter date was a list of strings: (Date, Month, Year).
(defn make-sql-date [date]
(java.util.GregorianCalendar. (Integer. (last date))
(Integer. (second date))
(Integer. (first date))))))
Let’s discuss SQL in Clojure. Specifically we’re going to take a look at two libraries and use their power to connect to databases, make SQL queries in an ‘Clojure-like’ manner, and be able to create, delete, and modify databases and tables. The two libraries we’re looking at today are Lobos and Korma. Lobos primarily handles create, alter, and drop commands, whereas Korma focuses on queries to the database (although does handle inserting new data, updating old data, and deleting data). With that let’s delve right into the world of SQL in Clojure!