summaryrefslogtreecommitdiff
path: root/src/clojure_sql/dsl.clj
diff options
context:
space:
mode:
Diffstat (limited to 'src/clojure_sql/dsl.clj')
-rw-r--r--src/clojure_sql/dsl.clj49
1 files changed, 14 insertions, 35 deletions
diff --git a/src/clojure_sql/dsl.clj b/src/clojure_sql/dsl.clj
index 006e637..996b55c 100644
--- a/src/clojure_sql/dsl.clj
+++ b/src/clojure_sql/dsl.clj
@@ -37,17 +37,24 @@
{:field field
:query query})))
+(defn ^:private resolve-field [table aliases field]
+ (let [field-alias-lookup (u/flip-map aliases)]
+ (or (field-alias-lookup field)
+ (if table
+ [table field]
+ (ambiguous-error field)))))
+
+(defn ^:private resolve-fields [table aliases expression]
+ (cond (list? expression) (map (partial table aliases) expression)
+ (vector? expression) (mapv (partial table aliases) expression)
+ (keyword? expression) (resolve-field table aliases expression)
+ :else expression))
+
(defn project [query fields]
(let [table (if-not (:joins query)
(-> query :table first val))
alias-lookup (u/flip-map (:fields query))
- original-name (fn [field]
- (if (vector? field)
- field
- (or (get alias-lookup field nil)
- (if table
- [table field]
- (ambiguous-error field query)))))]
+ original-name #(resolve-fields table (:fields query) %)]
(assoc query
:fields (->> (for [[key val] (if (map? fields)
fields
@@ -77,20 +84,6 @@
[(original-name key) val])
(into %)))))
-(defn ^:private resolve-field [table aliases field]
- (let [field-alias-lookup (u/flip-map aliases)]
- (or (field-alias-lookup field)
- (if table
- [table field]
- (ambiguous-error field)))))
-
-(defn ^:private resolve-fields [table aliases expression]
- (clojure.walk/postwalk (fn [expr]
- (cond
- (keyword? expr) (resolve-field table aliases expr)
- :else expr))
- expression))
-
(defn ^:private combine-wheres [& wheres]
(reduce (fn [acc where]
(cond (nil? acc) where
@@ -153,17 +146,3 @@
(if (vector? field)
(resolve-field table-name (:fields query) field)
[(resolve-field table-name (:fields query) field) :asc])))))
-
-
-(defn insert! [query & records]
- {:pre [(empty? (:joins query))]}
- ;; some code here
- )
-
-(defn update! [query & partial-records]
- ;; some code here
- )
-
-(defn delete! [query]
- ;; some code here
- )