 
   (when (contains? x :value)
     (let [m (select-keys ctx [:device_id :type])]
-      (insert* session :measurements (->> (dissoc x ::table)
-                                          (merge
-                                           m)))
-      ))
+      (insert* session (merge
+                        x
+                        m))))
   ctx)
 
 (defn insert-vector

(defmethod compile-element clojure.lang.ISeq [xs]
  (for [x xs] (compile-element x)))

(defn- insert* [session table values]
  (dbnew/execute session
     (hayt/insert table (hayt/values values))))

(defn- insert-simple [x session]
    (let [id (str (generators/uuid))
        data (-> x
                 (assoc :id id)
                 (dissoc x ::table))]
      (insert* session (::table x) data)
      id))

(defmulti insert (fn [x _ _] (::table x)) :default :error-no-table)

(defmethod insert :error-no-table [x _ _ ]
  (throw (ex-info "ERROR - NO TABLE:" x)))

(defmethod insert :programmes [x session ctx]
  (assoc ctx :programme_id
         (insert-simple x session)))

(defmethod insert :projects [x session ctx]
  (assoc ctx :project_id
         (insert-simple x session)))

(defmethod insert :entities [x session ctx]
  (assoc ctx :entity_id
         (insert-simple x session)))

(defmethod insert :properties [x session ctx]
  (assoc ctx :property_id
         (insert-simple x session)))

(defmethod insert :devices [x session ctx]
  (let [m {:id (str (generators/uuid))

     (loop [[x & more] xs ctx ctx]
       (when x
         (recur more (cond
                      (vector? x) (insert-vector x session ctx )
                      (seq? x) (doseq [y x]
                                 (insert (merge (::prior ctx) y)
                                         session
                                         ctx))
                      (map? x) (insert x session (assoc ctx ::prior x))
                      :else (throw (ex-info (str "Invalid value " x) {}))))))))

(defn load-fixture [session fixture]
  (let [data (compile-element fixture)]
    (insert-vector data session)))
