Skip to content
Snippets Groups Projects
Commit 3bb1fa4e authored by Cam Saül's avatar Cam Saül
Browse files

"nested fields" not "subfields"

parent 1c5f1a4d
No related branches found
No related tags found
No related merge requests found
......@@ -70,10 +70,10 @@
* dest-column-name"))
(defprotocol ISyncDriverFieldSubFields
(defprotocol ISyncDriverFieldNestedFields
"Optional protocol that should provide information about the subfields of a FIELD when applicable.
Drivers that declare support for `:nested-fields` should implement this protocol."
(active-subfield-names->type [this field]
(active-nested-field-name->type [this field]
"Return a map of string names of active child `Fields` of FIELD -> `Field.base_type`."))
......
......@@ -97,8 +97,8 @@
(mq/with-collection conn (:name table)
(mq/fields [(:name field)])))))))
ISyncDriverFieldSubFields
(active-subfield-names->type [this field]
ISyncDriverFieldNestedFields
(active-nested-field-name->type [this field]
;; Build a map of nested-field-key -> type -> count
;; TODO - using an atom isn't the *fastest* thing in the world (but is the easiest); consider alternate implementation
(let [field->type->count (atom {})]
......@@ -150,7 +150,7 @@
(datasets/with-dataset :mongo
(data/with-temp-db [db (data/dataset-loader) defs/geographical-tips]
(with-mongo-connection [_ db]
(active-subfield-names->type driver &tips.venue)))))
(active-nested-field-name->type driver &tips.venue)))))
;; TODO
;; 1. Sync
......
......@@ -24,7 +24,7 @@
sync-table-active-fields-and-pks!
sync-table-fks!
sync-table-fields-metadata!
sync-field-subfields!
sync-field-nested-fields!
update-table-row-count!)
;; ## sync-database! and sync-table!
......@@ -252,7 +252,7 @@
mark-category-field!
(mark-no-preview-display-field! driver)
auto-assign-field-special-type-by-name!
(sync-field-subfields! driver)))
(sync-field-nested-fields! driver)))
;; Each field-syncing function below should return FIELD with any updates that we made, or nil.
......@@ -429,9 +429,12 @@
(assoc field :special_type special-type))))
(defn- sync-field-subfields! [driver field]
(defn- sync-field-nested-fields! [driver field]
(when (and (= (:base_type field) :DictionaryField)
(supports? driver :nested-fields) ; if one of these is true
(satisfies? ISyncDriverFieldSubFields driver)) ; the other should be :wink:
(let [subfield-name->type (active-subfield-names->type driver field)]
(log/info (u/format-color 'green "Syncing subfields for '%s.%s': %s" (:name @(:table field)) (:name field) (keys subfield-name->type))))))
(satisfies? ISyncDriverFieldNestedFields driver)) ; the other should be :wink:
(let [nested-field-name->type (active-nested-field-name->type driver field)]
(log/info (u/format-color 'green "Syncing subfields for '%s.%s': %s" (:name @(:table field)) (:name field) (keys nested-field-name->type)))
;; fetch those existing nested fields
)))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment