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.
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 |
| -- :doc adds a new user |
| INSERT INTO users |
| (id, pass) |
| VALUES (:id, :pass) |
HugSQL uses specially formatted SQL ...
Get Web Development with Clojure, 3rd Edition 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.