 
 (defn- all-fields-constructor [attributes]
   (if (empty? attributes) (constantly nil) (apply juxt (map #(fn [col] (get col %)) attributes))))
-
-(defn- geo-column [geo-group]
-   (str "_geometry_" (name geo-group)))
 
 (defn gs-insert-sql [schema table columns]
   (str "INSERT INTO " (pg/quoted schema) "." (pg/quoted table)


(defn- gs-create-collection [{:keys [db dataset]} ndims srid collection]
  "Create table with default fields"
  (let [table collection
        geometries [:_geometry_point :_geometry_line :_geometry_polygon]]

    (pg/create-table db dataset table
                     [:gid "serial" :primary :key]
                     [:_id "text"]
                     [:_parent_id "text"]
                     [:_version "uuid"]
                     [:_geo_group "text"])

    (pg/create-index db dataset table "_id")
    (doseq [geometry geometries]
      (#(pg/create-column db dataset table %1 pg/geometry-type ndims srid) geometry)
      ((partial pg/create-geo-index db dataset table) geometry))))

(defn- gs-collection-attributes [{:keys [db dataset]} collection]
  (let [table collection

  (pg/create-column db dataset collection attribute-name (pg/clj-to-pg-type attribute-value) ndims srid))

(defn- feature-to-sparse-record [proj-fn feature all-fields-constructor import-nil-geometry?]
  (let [id (:id feature)
        parent-id (:parent-id feature)
        version (:version feature)
        sparse-attributes (all-fields-constructor (:attributes feature))]
    (concat [id
                parent-id
                version]
               sparse-attributes
               [id])))

(defn- feature-keys [feature]
  (let [attributes (:attributes feature)]
     (cond-> (transient [])
             (seq attributes) (conj!-coll (keys attributes))
             true (persistent!))))

 (defn- feature-to-update-record [proj-fn feature]
   (let [attributes (:attributes feature)]
     (cond-> (transient [(:version feature)])
             (seq attributes) (conj!-coll (vals attributes))
             true (conj! (:id feature))
             true (conj! (:current-version feature))
