Use HugSQL

The major advantage of using HugSQL is that it allows us to write the SQL queries in separate files instead of having to embed strings in our code. This has a number of advantages, such as allowing us to use SQL tools to edit the queries. We already got a preview of HugSQL when we developed our guestbook application in Chapter 1, Getting Your Feet Wet.

Getting Things Done with HugSQL

HugSQL provides a flexible DSL for generating the functions for running SQL queries. We’ll start by seeing how we can define a single query in a file and then create a function from it using the def-db-fns macro. Let’s place the query in the resources/find_user.sql file in our project.

 -- :name add-user! :! :n
 

Get Web Development with Clojure, 2nd Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.