                       :metadata  {}}]
               (->> m2
                    (v/validate store-new)
-                   (hecuba/upsert! commander :measurement))
+                   (insert-measurement session))
 
               (update-bounds! t)
               (q/put-on-queue topic m2)))
-          (hecuba/upsert! commander :sensor_metadata {:device_id device_id
-                                                      :type type
-                                                      :lower_ts @lower
-                                                      :upper_ts @upper})
-
-          (hecuba/upsert! commander :sensor_metadata {:device_id device_id
-                                                      :type type
-                                                      :lower_ts @lower
-                                                      :upper_ts @upper})
+          (dbnew/execute session
+                         (hayt/insert :sensor_metadata 
+                                      (hayt/values {:device_id device_id
+                                                    :type type
+                                                    :lower_ts @lower
+                                                    :upper_ts @upper})))
+
+          (dbnew/execute session
+                         (hayt/insert :sensor_metadata
+                                      (hayt/values {:device_id device_id
+                                                    :type type
+                                                    :lower_ts @lower
+                                                    :upper_ts @upper})))
           {:response {:status 202 :body "Accepted"}})
         {:response {:status 400 :body "Provide valid device_id and type."}}))))
 
-(defn index-handle-ok [store store-new ctx]
-  (let [{:keys [querier]} store
-        request (:request ctx)
-        route-params (:route-params request)
-        device_id (:device_id route-params)
-        where [[= :device_id device_id]]
-        measurements (hecuba/items querier :measurement where)]
-    {:measurements (->> measurements
-                        (map #(-> %
-                                  util/parse-value
-                                  (update-in [:timestamp] util/db-to-iso)
-                                  (dissoc :metadata :device_id :month))))}))
+(defn index-handle-ok [store-new ctx]
+  (dbnew/with-session [session (:hecuba-session store-new)]
+    (let [request (:request ctx)
+          route-params (:route-params request)
+          device_id (:device_id route-params)
+          where [[= :device_id device_id]]
+          measurements (dbnew/execute session
+                                      (hayt/select :measurements
+                                                   (hayt/where where)))]
+      {:measurements (->> measurements
+                          (map #(-> %
+                                    util/parse-value
+                                    (update-in [:timestamp] util/db-to-iso)
+                                    (dissoc :metadata :device_id :month))))})))
 
 (defn index-handle-created [ctx]
   (ring-response (:response ctx)))
 
-(defn measurements-by-reading-handle-ok [store store-new ctx]
+(defn measurements-by-reading-handle-ok [store-new ctx]
   (let [{:keys [request]} ctx
         {:keys [route-params]} request
         {:keys [device_id sensor-type timestamp]} route-params
-        measurement (dbnew/with-session [session (:hecuba-session store)]
+        measurement (dbnew/with-session [session (:hecuba-session store-new)]
                       (dbnew/execute session
                                      (hayt/select :measurements
                                                   (hayt/where [[= :device_id device_id]

        decoded-params         (util/decode-query-params query-string)
        start-date             (util/to-db-format (string/replace (get decoded-params "startDate") "%20" " "))
        end-date               (util/to-db-format (string/replace (get decoded-params "endDate") "%20" " "))
        measurements           (retrieve-measurements querier start-date end-date device_id reading-type)]

    (format-measurements ctx measurements)))


                               (hayt/where [[= :device_id device_id]
                                            [= :type type]])))))

(defn- insert-measurement [session m]
  (dbnew/execute session (hayt/insert :measurements (hayt/values m))))

(defn index-post! [store-new queue ctx]
  (let [request       (:request ctx)
        route-params  (:route-params request)
        device_id     (:device_id route-params)
        topic         (get-in queue ["measurements"])
