Add explicit fts-table to source.

This commit is contained in:
Richard Newman 2016-08-04 18:50:34 -07:00
parent 3058c43c70
commit 5f04a48c2a
2 changed files with 16 additions and 2 deletions

View file

@ -35,6 +35,9 @@
(defprotocol Source (defprotocol Source
(source->from [source attribute] (source->from [source attribute]
"Returns a pair, `[table alias]` for a pattern with the provided attribute.") "Returns a pair, `[table alias]` for a pattern with the provided attribute.")
(source->non-fts-from [source])
(source->fts-from [source]
"Returns a pair, `[table alias]` for querying the source's fulltext index.")
(source->constraints [source alias]) (source->constraints [source alias])
(attribute-in-source [source attribute]) (attribute-in-source [source attribute])
(constant-in-source [source constant])) (constant-in-source [source constant]))
@ -42,6 +45,7 @@
(defrecord (defrecord
DatomsSource DatomsSource
[table ; Typically :datoms. [table ; Typically :datoms.
fts-table ; Typically :fulltext_values
fts-view ; Typically :fulltext_datoms. fts-view ; Typically :fulltext_datoms.
columns ; e.g., [:e :a :v :tx] columns ; e.g., [:e :a :v :tx]
@ -51,7 +55,7 @@
;; turn, e.g., the literal 'true' into 1. ;; turn, e.g., the literal 'true' into 1.
attribute-transform attribute-transform
constant-transform constant-transform
;; `table-alias` is a function from table to alias, e.g., :datoms => :datoms1234. ;; `table-alias` is a function from table to alias, e.g., :datoms => :datoms1234.
table-alias table-alias
@ -61,7 +65,7 @@
Source Source
(source->from [source attribute] (source->from [source attribute]
(let [table (let [table
(if (and (instance? Constant attribute) (if (and (instance? Constant attribute)
;; TODO: look in the DB schema to see if `attribute` is known to not be ;; TODO: look in the DB schema to see if `attribute` is known to not be
;; a fulltext attribute. ;; a fulltext attribute.
@ -72,6 +76,14 @@
(:fts-view source))] (:fts-view source))]
[table ((:table-alias source) table)])) [table ((:table-alias source) table)]))
(source->non-fts-from [source]
(let [table (:table source)]
[table ((:table-alias source) table)]))
(source->fts-from [source]
(let [table (:fts-table source)]
[table ((:table-alias source) table)]))
(source->constraints [source alias] (source->constraints [source alias]
(when-let [f (:make-constraints source)] (when-let [f (:make-constraints source)]
(f alias))) (f alias)))
@ -85,6 +97,7 @@
(defn datoms-source [db] (defn datoms-source [db]
(map->DatomsSource (map->DatomsSource
{:table :datoms {:table :datoms
:fts-table :fulltext_values
:fts-view :fulltext_datoms :fts-view :fulltext_datoms
:columns [:e :a :v :tx :added] :columns [:e :a :v :tx :added]
:attribute-transform transforms/attribute-transform-string :attribute-transform transforms/attribute-transform-string

View file

@ -28,6 +28,7 @@
(defn mock-source [db] (defn mock-source [db]
(source/map->DatomsSource (source/map->DatomsSource
{:table :datoms {:table :datoms
:fts-table :fulltext_values
:fts-view :fulltext_datoms :fts-view :fulltext_datoms
:columns [:e :a :v :tx :added] :columns [:e :a :v :tx :added]
:attribute-transform transforms/attribute-transform-string :attribute-transform transforms/attribute-transform-string