Skip to content

Instantly share code, notes, and snippets.

@mediocregopher
Created April 25, 2013 04:39
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 mediocregopher/5457543 to your computer and use it in GitHub Desktop.
Save mediocregopher/5457543 to your computer and use it in GitHub Desktop.
Given either a numeric id or name, returns all the children of that reference from sql. If the numeric id is given a normal select is done, if the name is given a subselect to get the id is done.
(defn get-reference-children
[fn-id] ;fullname-or-id
(-> (select* reference)
(fields :id :fullname :isDir )
(#(if-not (string? fn-id)
(where %1 {:parent_id fn-id})
(where %1 {:parent_id (subselect reference
(fields :id)
(limit 1)
(where {:fullname fn-id}))} )))
(exec)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment