Skip to content

Instantly share code, notes, and snippets.

Created June 4, 2010 00:03
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 anonymous/424699 to your computer and use it in GitHub Desktop.
Save anonymous/424699 to your computer and use it in GitHub Desktop.
; want to convert:
;
; struct returned by contrib.sql:
; {:user_id 5
; :login "a@b.com"
; :created "1234567890"
; :k1 "v1"
; :k2 "v2"
; :k3 "v3"}
;
; to a cleaned up, modified map:
; {:type "user"
; :id 5
; :login "a@b.com"
; :created "1234567890"}
(defn convert-struct-to-map
[row]
(assoc (select-keys (rename-keys (into {} row) {:user_id :id}) [:id :login :created]) :type "user"))
; cleaned up
(defn convert-user-row-to-neo-struct
[row]
(-> (into {} row)
(rename-keys {:user_id :id})
(select-keys [:id :login])
(assoc :type "user"))
; with a filter
(defn convert-user-row-to-neo-struct
[row]
(->
(->>
(-> (into {} row)
(rename-keys {:user_id :id})
(select-keys [:id :login]))
(filter :required_param))
(assoc :type "user"))
; with a filter with lets
(defn convert-user-row-to-neo-struct
[row]
(let [1st (-> (into {} row) (rename-keys {:user_id :id}) (select-keys [:id :login]))]
(let [2nd (->> 1st (filter :required_param))]
(-> 2nd (assoc :type "user"))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment