In the Wild

Maps are the Swiss Army knives of Clojure programming: any time you need to bundle together some related data items into a unified whole, one of your first thoughts should be, Hey, I’ll use a map. You can see this thinking at work in the clojure.java.jdbc library, which provides an easy-to-use Clojure interface to a wide variety of relational databases. The functions supplied by clojure.java.jdbc need several pieces of configuration information to find your database, which you supply with a map:

 (require ​'clojure.java.jdbc​)
 
 (​def​ db {:dbtype ​"derby"​ :dbname ​"books"​})
 
 (clojure.java.jdbc/query db [​"select * from books"​])

In the example, the map bound to db contains the database connection information. Don’t worry about ...

Get Getting Clojure now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.