Created
February 21, 2011 16:29
-
-
Save ejackson/837299 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn pluralize | |
"Turn a string to plural" | |
[x] | |
(if (= (last (name x)) \y) | |
(apply str (concat (drop-last (name x)) [\i \e \s])) | |
(str (name x) "s"))) | |
(defn table [t] | |
(cql/table db (pluralize t))) | |
(defn col [t c] | |
(keyword (str (pluralize (name t)) "." (name c)))) | |
(defn fk [t] | |
(str (name t) "_id")) | |
(defn pk [t] | |
"id") | |
(defn refer-fk [t1 t2] | |
(col t1 (fk t2))) | |
(defn only-of | |
"Pass singular keywords for now." | |
[t1 t2] | |
(cql/join (table t1) | |
(table t2) | |
(cql/where (= (refer-fk t2 t1) | |
(col t1 (pk t1)))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment