Appendix A. Using Korma – a Clojure DSL for SQL

In this book, we exclusively made use of YeSQL, a library that generates Clojure functions from native SQL. For an example application as small and simple as hipstr, YeSQL might be a tad overkill – its real beauty and elegance comes to light in larger projects that make use of large queries or lots of underlying database functionality. Furthermore, YeSQL does a decent job of abstracting away the underlying data model from the Clojure code.

That being said, there are many people who prefer using a domain specific language to interact with the database. This appendix will introduce you to Korma, a pure-Clojure DSL for SQL. This appendix will not cover Korma in its entirety (it's pretty full-fledged). Instead, this appendix will cover the following:

  • How to tie object models back to database tables
  • A light overview of selecting and inserting data using Korma
  • Port the connection, album-model, and user-model namespaces from YeSQL to Korma

Getting Korma

Add the following code to the Leiningen :dependencies in the hipstr project file:

[korma "0.4.0"]

At the time of writing this book, Version 0.4.0 is the most recent stable build of Korma, and it was released around late August of 2014. You may want to check if there's a newer version at https://github.com/korma/Korma/.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.221.249.198