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

View file

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