Browse Source

Merge pull request #2026 from k-r-g/compojure-httpkit-update-fix

Fix updates test implementation to actually update the database
Mike Smith 9 years ago
parent
commit
66fa3d6c8a

+ 12 - 11
frameworks/Clojure/compojure/hello/src/hello/handler.clj

@@ -143,23 +143,24 @@
   "Using Korma: Changes the :randomNumber of a number of world entities.
   "Using Korma: Changes the :randomNumber of a number of world entities.
   Persists the changes to sql then returns the updated entities"
   Persists the changes to sql then returns the updated entities"
   [queries]
   [queries]
-(let [results (run-queries queries)]
-    (for [w results]
-      (update-in w [:randomNumber (inc (rand-int 9999))]
-        (update world
-                (set-fields {:randomNumber (:randomNumber w)})
-                (where {:id [:id w]}))))
+  (let [results (map #(assoc % :randomNumber (inc (rand-int 9999))) (run-queries queries))]
+    (doseq [{:keys [id randomNumber]} results]
+      (update world
+              (set-fields {:randomNumber randomNumber})
+              (where {:id id})))
     results))
     results))
 
 
 (defn update-and-persist-raw
 (defn update-and-persist-raw
   "Using JDBC: Changes the :randomNumber of a number of world entities.
   "Using JDBC: Changes the :randomNumber of a number of world entities.
   Persists the changes to sql then returns the updated entities"
   Persists the changes to sql then returns the updated entities"
   [queries]
   [queries]
-(let [results (run-queries queries)]
-    (for [w results]
-      (update-in w [:randomNumber (inc (rand-int 9999))]
-        (jdbc/update! (db-mysql-raw) :world {:randomNumber (:randomNumber w)} ["id = ?" (:id w)])))
-    results))
+  (let [world (map #(assoc % :randomnumber (inc (rand-int 9999))) (run-queries-raw queries))]
+    (doseq [{:keys [id randomnumber]} world]
+      (jdbc/update!
+       (db-mysql-raw)
+       :world {:randomnumber randomnumber}
+       ["id = ?" id]))
+    world))
 
 
 (defn json-serialization
 (defn json-serialization
   "Test 1: JSON serialization"
   "Test 1: JSON serialization"

+ 11 - 10
frameworks/Clojure/http-kit/hello/src/hello/handler.clj

@@ -145,23 +145,24 @@
   "Using Korma: Changes the :randomNumber of a number of world entities.
   "Using Korma: Changes the :randomNumber of a number of world entities.
   Persists the changes to sql then returns the updated entities"
   Persists the changes to sql then returns the updated entities"
   [queries]
   [queries]
-(let [results (run-queries queries)]
-    (for [w results]
-      (update-in w [:randomNumber (inc (rand-int 9999))]
+  (let [results (map #(assoc % :randomNumber (inc (rand-int 9999))) (run-queries queries))]
+    (doseq [{:keys [id randomNumber]} results]
         (update world
         (update world
-                (set-fields {:randomNumber (:randomNumber w)})
-                (where {:id [:id w]}))))
+              (set-fields {:randomNumber randomNumber})
+              (where {:id id})))
     results))
     results))
 
 
 (defn update-and-persist-raw
 (defn update-and-persist-raw
   "Using JDBC: Changes the :randomNumber of a number of world entities.
   "Using JDBC: Changes the :randomNumber of a number of world entities.
   Persists the changes to sql then returns the updated entities"
   Persists the changes to sql then returns the updated entities"
   [queries]
   [queries]
-(let [results (run-queries queries)]
-    (for [w results]
-      (update-in w [:randomNumber (inc (rand-int 9999))]
-        (jdbc/update! (db-mysql-raw) :world {:randomNumber (:randomNumber w)} ["id = ?" (:id w)])))
-    results))
+  (let [world (map #(assoc % :randomnumber (inc (rand-int 9999))) (run-queries-raw queries))]
+    (doseq [{:keys [id randomnumber]} world]
+      (jdbc/update!
+       (db-mysql-raw)
+       :world {:randomnumber randomnumber}
+       ["id = ?" id]))
+    world))
 
 
 (defn json-serialization
 (defn json-serialization
   "Test 1: JSON serialization"
   "Test 1: JSON serialization"