Liking cljdoc? Tell your friends :D


Tasty SQL for Clojure.

TravisCI Status

Build Status

Getting started

Simply add Korma as a dependency to your lein project:

[korma "0.4.3"]

Docs and Real Usage

To get rid of the ridiculously verbose logging, add the following into src/log4j.xml:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="">
  <logger name="com.mchange">
    <level value="WARN"/>

And include log4j in your project.clj:

[log4j "1.2.15" :exclusions [javax.mail/mail

Examples of generated queries:

(use 'korma.db)
(defdb db (postgres {:db "mydb"
                     :user "user"
                     :password "dbpass"}))

(use 'korma.core)
(defentity users)

(select users)
;; executes: SELECT * FROM users

(select users
  (fields :username :id))
;; executes: SELECT users.username, FROM users

(select users
  (where {:username "chris"}))
;; executes: SELECT * FROM users WHERE (users.username = 'chris')

(select users 
  (where {:active true})
  (order :created)
  (limit 5)
  (offset 3))
;; executes: SELECT * FROM users WHERE ( = TRUE) ORDER BY users.created DESC LIMIT 5 OFFSET 3

(select users
  (where (or (= :username "chris")
             (= :email ""))))
;; executes: SELECT * FROM users WHERE (users.username = 'chris' OR = '')

(select users
  (where {:username [like "chris"]
          :status "active"
          :location [not= nil]}))
;; executes SELECT * FROM users WHERE (users.username LIKE 'chris' AND users.status = 'active' AND users.location IS NOT NULL)

(select users
  (where (or {:username "chris"
              :first "chris"}
             {:email [like ""]})))
;; executes: SELECT * FROM users WHERE ((users.username = 'chris' AND users.first = 'chris') OR LIKE ''

(defentity address
 (entity-fields :street :city :zip))

(defentity users
 (has-one address))

(select users
 (with address))
;; SELECT address.street,, FROM users LEFT JOIN address ON = address.users_id


Copyright (C) 2011 Chris Granger

Distributed under the Eclipse Public License, the same as Clojure.

Can you improve this documentation? These fine people already did:
Chris Granger, Immo Heikkinen, Alex Baranosky, Josh Tilles, Dane Schneider, Kazunobu Raita, Chris Allen, Isaac Su, jihui, Mike Aldred, mynomoto & Dan Midwood
Edit on GitHub

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close