Browse Source

Merge pull request #1981 from yogthos/master

fix for the query test
ssmith-techempower 9 years ago
parent
commit
d1f2f432c4

+ 5 - 4
frameworks/Clojure/luminus/hello/resources/sql/queries.sql

@@ -1,7 +1,3 @@
--- :name get-worlds :? :*
-SELECT * FROM "World"
-WHERE id IN (:v*:ids)
-
 --:name get-all-fortunes :? :*
 --:name get-all-fortunes :? :*
 -- select all records from the fortune table
 -- select all records from the fortune table
 SELECT * FROM "Fortune"
 SELECT * FROM "Fortune"
@@ -11,3 +7,8 @@ SELECT * FROM "Fortune"
 UPDATE "World"
 UPDATE "World"
 SET "randomnumber" = :randomNumber
 SET "randomnumber" = :randomNumber
 WHERE id = :id
 WHERE id = :id
+
+-- :name get-world :? :1
+-- get world by id
+SELECT * FROM "World"
+WHERE id = :id

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

@@ -5,7 +5,7 @@
     [conman.core :as conman]
     [conman.core :as conman]
     [hello.config :refer [env]]
     [hello.config :refer [env]]
     [mount.core :refer [defstate]]
     [mount.core :refer [defstate]]
-    clojure.set)
+    [clojure.set :refer [rename-keys]])
   (:import org.postgresql.util.PGobject
   (:import org.postgresql.util.PGobject
            org.postgresql.jdbc4.Jdbc4Array
            org.postgresql.jdbc4.Jdbc4Array
            clojure.lang.IPersistentMap
            clojure.lang.IPersistentMap
@@ -39,22 +39,21 @@
       (> n 500) 500
       (> n 500) 500
       :else     n)))
       :else     n)))
 
 
-(defn rename-keys [results]
-  (map #(clojure.set/rename-keys % {:randomnumber :randomNumber}) results))
+(defn get-random-world []
+  (-> (get-world {:id (inc (rand-int 10000))})
+      (rename-keys {:randomnumber :randomNumber})))
 
 
 (defn run-queries
 (defn run-queries
   "Run the specified number of queries, return the results"
   "Run the specified number of queries, return the results"
   [queries]
   [queries]
-  (->> {:ids (repeatedly (get-query-count queries) #(inc (rand-int 9999)))}
-      get-worlds
-      rename-keys))
+  (repeatedly (get-query-count queries) get-random-world))
 
 
 (defn get-fortunes []
 (defn get-fortunes []
    "Fetch the full list of Fortunes from the database, sort them by the fortune
    "Fetch the full list of Fortunes from the database, sort them by the fortune
   message text, and then return the results."
   message text, and then return the results."
   (sort-by
   (sort-by
    :message
    :message
-   (conj (rename-keys (get-all-fortunes))
+   (conj (get-all-fortunes)
          {:id 0 :message "Additional fortune added at request time."})))
          {:id 0 :message "Additional fortune added at request time."})))
 
 
 (defn set-random-number!
 (defn set-random-number!