From 148f752b5f48707dc3d7fe448d1faf33d5cd0228 Mon Sep 17 00:00:00 2001 From: Carlo Zancanaro Date: Thu, 13 Jun 2013 18:24:05 +1000 Subject: Starting a re-write of the DSL, to be followed by the compiler. Flip around field/table aliases, do joins a bit differently. They're my main aims at the moment! I'll also add a preprocessor for the compiler to massage it into a nicer form there. I discovered that joins can be done with a pretty sweet syntax in SQL: (tableA LEFT JOIN tableB) RIGHT JOIN tableC This is pretty much perfect for my purposes. Flipping alias maps just makes more sense and removes a whole bunch of `flip-map` calls that would be unnecessary if the aliases were the other way around. The user-facing side of the DSL will be left unchanged, though. The user provides an `{old-name new-name}` map and internally we convert that into `{new-name old-name}`. Like magic. I'm also adding a bunch more tests. Hopefully that will make things more likely to work for long periods of time. Peace out! --- src/clojure_sql/util.clj | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'src/clojure_sql/util.clj') diff --git a/src/clojure_sql/util.clj b/src/clojure_sql/util.clj index cd8e8b6..f2edf30 100644 --- a/src/clojure_sql/util.clj +++ b/src/clojure_sql/util.clj @@ -1,4 +1,5 @@ -(ns clojure-sql.util) +(ns clojure-sql.util + (:require [clojure.set :as set])) (defn funcall [f & args] (apply f args)) @@ -11,3 +12,15 @@ (->> m (map (comp vec reverse)) (into {}))) + +(defn map-kv [f & maps] + (let [all-keys (into #{} (mapcat keys maps))] + (->> all-keys + (map (fn [key] + (apply f key (map #(get % key) maps)))) + (into {})))) + +(defn map-vals [f & maps] + (apply map-kv (fn [k & vs] + [k (apply f vs)]) + maps)) -- cgit v1.2.3