From ebaec499fd55af519d81e3499fbff41245ebc3ac Mon Sep 17 00:00:00 2001 From: "Alexander K. Hudek" Date: Tue, 13 Jan 2015 15:49:48 -0500 Subject: [PATCH] Ignore raw sql in table extraction. --- project.clj | 2 +- src/views/db/honeysql.clj | 11 +++++++---- test/views/db/honeysql_test.clj | 7 ++++++- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/project.clj b/project.clj index ac37a04..defedc6 100644 --- a/project.clj +++ b/project.clj @@ -1,4 +1,4 @@ -(defproject views "0.5.1" +(defproject views "0.5.2" :description "You underestimate the power of the SQL side" :url "https://github.com/diligenceengine/views" diff --git a/src/views/db/honeysql.clj b/src/views/db/honeysql.clj index bf2619c..121a97e 100644 --- a/src/views/db/honeysql.clj +++ b/src/views/db/honeysql.clj @@ -65,10 +65,13 @@ (mapcat isolate-tables (every-second (k query)))) (defn collect-maps - [coll] - (let[maps (filterv map? coll) - colls (filter #(and (coll? %) (not (map? %))) coll)] - (into maps (mapcat collect-maps colls)))) + [wc] + (cond + (coll? wc) (let [maps (filterv map? wc) + colls (filter #(and (coll? %) (not (map? %))) wc)] + (into maps (mapcat collect-maps colls))) + (map? wc) [wc] + :else [])) (defn where-tables "This search for subqueries in the where clause." diff --git a/test/views/db/honeysql_test.clj b/test/views/db/honeysql_test.clj index 95d4596..a053ec2 100644 --- a/test/views/db/honeysql_test.clj +++ b/test/views/db/honeysql_test.clj @@ -2,6 +2,7 @@ (:require [clojure.test :refer [deftest is run-tests]] [views.db.honeysql :as vh] + [honeysql.core :as hsql] [honeysql.helpers :as hh])) (def simple-test @@ -47,6 +48,9 @@ (def nested-where-subselect-test {:select [:*] :from [:foo] :where [:and [:in :a {:select [:*] :from [:bar]}] [:in :a {:select [:*] :from [:baz]}]]}) +(def sql-raw-test + {:select [:*] :from [:foo] :where (hsql/raw "bar=1")}) + (deftest extracts-tables-from-full-refresh-specs (is (= (vh/query-tables simple-test) #{:foo})) (is (= (vh/query-tables insert-test) #{:foo})) @@ -56,7 +60,8 @@ (is (= (vh/query-tables cte-test) #{:foo :bar})) (is (= (vh/query-tables from-subselect-test) #{:foo})) (is (= (vh/query-tables where-subselect-test) #{:foo :bar})) - (is (= (vh/query-tables nested-where-subselect-test) #{:foo :bar :baz}))) + (is (= (vh/query-tables nested-where-subselect-test) #{:foo :bar :baz})) + (is (= (vh/query-tables sql-raw-test) #{:foo}))) ;; Do we really need to test the new version? (deftest merges-where-clauses