O'Reilly logo

Web Development with Clojure by Dmitri Sotnikov

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Task D: Displaying Pictures

We now have all the pieces in place to start displaying the pictures in our gallery. We simply have to load all the thumbnails associated with the user and show them on the page. When clicked, a thumbnail will display the full-size picture.

Since we store references to uploaded images in the database, we can easily write a function to query all images with the given user ID in our db namespace.

picture-gallery-d/src/picture_gallery/models/db.clj
 
(​defn​ images-by-user [userid]
 
(with-db
 
sql/with-query-results
 
res [​"select * from images where userid = ?"​ userid] (​doall​ res)))

Let’s test that the function does what we intended by running it against a user we registered earlier and see if we get a list of ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required