Browse Source

removed returning, since it's not necessary

Yogthos 9 years ago
parent
commit
e1b3e6f6df

+ 1 - 7
frameworks/Clojure/luminus/hello/resources/sql/queries.sql

@@ -7,14 +7,8 @@ WHERE id = :id
 -- select all records from the fortune table
 SELECT * FROM fortune
 
--- :name update-world<! :<! :1
+-- :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

+ 4 - 6
frameworks/Clojure/luminus/hello/src/clj/hello/db/core.clj

@@ -95,8 +95,7 @@
 (defn run-queries
   "Run the specified number of queries, return the results"
   [queries]
-  (let [num-queries (get-query-count queries)]
-    (flatten (repeatedly num-queries get-world-random))))
+  (flatten (repeatedly (get-query-count queries) get-world-random)))
 
 (defn get-fortunes []
    "Fetch the full list of Fortunes from the database, sort them by the fortune
@@ -110,7 +109,6 @@
   "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 [number (inc (rand-int 9999))]
-      {:randomNumber number
-       :id (:id (update-world<! (assoc world :randommumber number)))})))
+  (let [world (map #(assoc % :randomNumber (inc (rand-int 9999))) (run-queries queries))]
+    (doseq [w world] (update-world! w))
+    world))