Skip to content

Instantly share code, notes, and snippets.

@ejackson
Created February 21, 2011 16:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ejackson/837299 to your computer and use it in GitHub Desktop.
Save ejackson/837299 to your computer and use it in GitHub Desktop.
(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