Created
December 9, 2017 18:53
-
-
Save carcigenicate/f1fbfd7c0a866f3153595c2ef398be22 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns bits.sql-syntax) | |
(def test-db [{:id 1, :name "A"}, | |
{:id 0, :name "B"}, | |
{:id 3, :name "C"}, | |
{:id 2, :name "D"}, | |
{:id 4, :name "E"}]) | |
(defn where [arg-vec] | |
(let [[k f comp-arg] arg-vec] | |
(fn [elem] (f (k elem) comp-arg)))) | |
(defn select [selection & args] | |
(let [arg-map (into {} (map vec (partition 2 args))) | |
{from :from, where-vec :where, order-key :order-by} arg-map] | |
(if from | |
(let [filt-ordered | |
(cond->> from | |
where-vec (filter (where where-vec)) | |
order-key (sort-by order-key))] | |
(mapcat #(map % filt-ordered) selection))))) | |
(select [:name] :from test-db :where [:id < 2] :order-by :id) | |
; Prints ("B" "A") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You shouldn't be unquoting
func
. This runs without error, although I haven't tested if it actually works: