Ignore raw sql in table extraction.

This commit is contained in:
Alexander K. Hudek 2015-01-13 15:49:48 -05:00
parent e89800e099
commit ebaec499fd
3 changed files with 14 additions and 6 deletions

View file

@ -1,4 +1,4 @@
(defproject views "0.5.1" (defproject views "0.5.2"
:description "You underestimate the power of the SQL side" :description "You underestimate the power of the SQL side"
:url "https://github.com/diligenceengine/views" :url "https://github.com/diligenceengine/views"

View file

@ -65,10 +65,13 @@
(mapcat isolate-tables (every-second (k query)))) (mapcat isolate-tables (every-second (k query))))
(defn collect-maps (defn collect-maps
[coll] [wc]
(let[maps (filterv map? coll) (cond
colls (filter #(and (coll? %) (not (map? %))) coll)] (coll? wc) (let [maps (filterv map? wc)
(into maps (mapcat collect-maps colls)))) colls (filter #(and (coll? %) (not (map? %))) wc)]
(into maps (mapcat collect-maps colls)))
(map? wc) [wc]
:else []))
(defn where-tables (defn where-tables
"This search for subqueries in the where clause." "This search for subqueries in the where clause."

View file

@ -2,6 +2,7 @@
(:require (:require
[clojure.test :refer [deftest is run-tests]] [clojure.test :refer [deftest is run-tests]]
[views.db.honeysql :as vh] [views.db.honeysql :as vh]
[honeysql.core :as hsql]
[honeysql.helpers :as hh])) [honeysql.helpers :as hh]))
(def simple-test (def simple-test
@ -47,6 +48,9 @@
(def nested-where-subselect-test (def nested-where-subselect-test
{:select [:*] :from [:foo] :where [:and [:in :a {:select [:*] :from [:bar]}] [:in :a {:select [:*] :from [:baz]}]]}) {: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 (deftest extracts-tables-from-full-refresh-specs
(is (= (vh/query-tables simple-test) #{:foo})) (is (= (vh/query-tables simple-test) #{:foo}))
(is (= (vh/query-tables insert-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 cte-test) #{:foo :bar}))
(is (= (vh/query-tables from-subselect-test) #{:foo})) (is (= (vh/query-tables from-subselect-test) #{:foo}))
(is (= (vh/query-tables where-subselect-test) #{:foo :bar})) (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? ;; Do we really need to test the new version?
(deftest merges-where-clauses (deftest merges-where-clauses