clj-record is an API inspired by Rails’ ActiveRecord but implemented in the Clojure programming language and intended to use its idioms.
This is a learning exercise and (at least for now) not intended for real-world use. Contributions to harden it are welcome, but I’m even more interested in recommendations for how to make it more idiomatically lisp-ey.
To define a model, you do something like this.
(ns com.example.user) (clj-record.core/init-model)
To define associations, you add something like this.
(ns com.example.user) (clj-record.core/init-model (belongs-to account) (has-many subscriptions))
Then you can do things like this.
(let [mikey (user/find-record 2) subs (user/find-subscriptions mikey)] (doseq [subscription subs] (println (format "%s subscribed to %s" (:name mikey) (:name sub)))) (user/destroy-subscriptions mikey) (println "But not any more."))
…is awful. Recommendations are welcome.
Copyright 2008 John D. Hume and released under an MIT license.