Browse Source

fixed lowercased names in update

Yogthos 9 years ago
parent
commit
09688d61cb

+ 11 - 0
frameworks/Clojure/luminus/hello/resources/sql/queries.sql

@@ -7,3 +7,14 @@ WHERE id = :id
 -- select all records from the fortune table
 SELECT * FROM fortune
 
+-- :name update-world<! :<! :1
+-- update an existing world record
+UPDATE world
+SET "randomNumber" = :randomnumber
+WHERE id = :id
+RETURNING id
+
+-- :name insert-world<! :<!
+INSERT INTO world (id, "randomNumber")
+VALUES (:id, :randomNumber)
+RETURNING id

+ 3 - 9
frameworks/Clojure/luminus/hello/src/clj/hello/db/core.clj

@@ -106,17 +106,11 @@
    (conj (get-all-fortunes)
          {:id 0 :message "Additional fortune added at request time."})))
 
-(defn update-world<! [{:keys [randomNumber id]}]
-  (jdbc/update!
-    *db*
-    :world
-    {"\"randomNumber\"" randomNumber}
-    ["id = ?" id]))
-
 (defn update-and-persist
   "Changes the :randomNumber of a number of world entities.
   Persists the changes to sql then returns the updated entities"
   [queries]
   (for [world (run-queries queries)]
-    (let [updated-world (assoc world :randomNumber (inc (rand-int 9999)))]
-      (assoc updated-world :id (update-world<! updated-world)))))
+    (let [number (inc (rand-int 9999))]
+      {:randomNumber number
+       :id (:id (update-world<! (assoc world :randommumber number)))})))