 
   (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

     (loop [[x & more] xs ctx ctx]
       (when x
         (recur more (cond
                      (vector? x) (do (println "vector")
                                      (insert-vector x session ctx ))
                      (seq? x) (do (println "seq:" (::prior ctx))
                                   (doseq [y x]
                                     (insert (merge (::prior ctx)
                                                    y)
                                             session
                                             ctx)))
                      (map? x) (do (println "map")
                                   (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)]
    (clojure.pprint/pprint data)
    (insert-vector data session)))

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

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

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

(defmethod insert :error-no-table [x _ _ ]
  nil)

(defmethod insert :programmes [x session ctx]
  (let [id (str (generators/uuid))]
    (insert* session (merge
                      {:id id}
                      x))
    (assoc ctx :programme_id id)))

(defmethod insert :projects [x session ctx]
  (let [id (str (generators/uuid))]
    (insert* session (merge  {:id id}
                            (select-keys ctx [:programme_id])
                            x))
   (assoc ctx :project_id id)))

(defmethod insert :entities [x session ctx]
  (let [id (str (generators/uuid))]
    (insert* session (merge  {:id id}
                             (select-keys ctx [:project_id])
                             x))
    (assoc ctx :entity_id id)))

(defmethod insert :properties [x session ctx]
  (let [m (select-keys ctx [:programme_id])
        id (str (generators/uuid))]
   (insert* session (merge  {:id id}
                            (select-keys ctx [:programme_id])
                            x))
   (assoc ctx :entity_id id)))

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