LauJensen / clojureql

ClojureQL is superior SQL integration for Clojure
https://clojureql.sabrecms.com
Eclipse Public License 1.0
285 stars 39 forks source link

transform and changing pick! to pick #71

Closed ninjudd closed 12 years ago

ninjudd commented 13 years ago

Hey Lau,

I'm submitting this as a pull request even though I could commit it directly because I want you to take a look and sign off first.

I added a transform method to RTable that lets you specify a transform function to be executed after deref. I also implmented pick using it based on the conversation we had in #clojureql. The transform function will also be really useful for other data transformations that have to be done in Clojure. i.e:

;; i just want a list of emails for all users
@(transform users #(map :email %))

;; several fields are json, and i need to parse them when records are loaded
@(transform records #(map parse-json %))

Transforms are also composable:

;; only parse and return the first record
@(-> records (transform #(map parse-json %)) (transform first))

I'm pretty excited about this feature as it is going to clean up a lot of our code and make ClojureQL even easier for our engineers to use.

Let me know if you have any questions.

Cheers, :justin

bendlas commented 12 years ago

Committed as 7584a38787f70324ef4b03e2629fa9ad1924c83e