Add a table alias function to Source, allowing us to mock alias generation.

This commit is contained in:
Richard Newman 2016-07-26 10:50:40 -07:00
parent 5e1648b05f
commit a5556637e8

View file

@ -36,20 +36,27 @@
attribute-transform attribute-transform
constant-transform constant-transform
;; `table-alias` is a function from table to alias, e.g., :datoms => :datoms1234.
table-alias
;; Not currently used. ;; Not currently used.
make-constraints ; ?fn [source alias] => [where-clauses] make-constraints ; ?fn [source alias] => [where-clauses]
]) ])
(defn gensym-table-alias [table]
(gensym (name table)))
(defn datoms-source [db] (defn datoms-source [db]
(->Source :datoms (->Source :datoms
[:e :a :v :tx :added] [:e :a :v :tx :added]
transforms/attribute-transform-string transforms/attribute-transform-string
transforms/constant-transform-default transforms/constant-transform-default
gensym-table-alias
nil)) nil))
(defn source->from [source] (defn source->from [source]
(let [table (:table source)] (let [table (:table source)]
[table (gensym (name table))])) [table ((:table-alias source) table)]))
(defn source->constraints [source alias] (defn source->constraints [source alias]
(when-let [f (:make-constraints source)] (when-let [f (:make-constraints source)]