Browse Source

fixes for db access

Yogthos 10 years ago
parent
commit
018329f894

+ 1 - 1
frameworks/Clojure/luminus/hello/project.clj

@@ -19,7 +19,7 @@
                  [bouncer "0.3.2"]
                  [prone "0.8.1"]
                  [org.clojure/tools.nrepl "0.2.8"]
-                 [yesql "0.5.0-rc1"]
+                 [yesql "0.5.0-rc2"]
                  [mysql/mysql-connector-java "5.1.6"]
                  [c3p0/c3p0 "0.9.1.2"]
                  [http-kit "2.1.19"]

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

@@ -16,3 +16,11 @@ WHERE id = :id
 --name: get-all-fortunes
 -- query all fortune records
 SELECT id, message FROM fortune
+
+--name: insert-world<!
+-- create a world record
+INSERT into world
+(id, randomNumber)
+values (:id, :randomNumber)
+
+

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

@@ -3,13 +3,21 @@
     [yesql.core :refer [defqueries]])
   (:import com.mchange.v2.c3p0.ComboPooledDataSource))
 
-(def db-spec
+#_(def db-spec
   {:classname "com.mysql.jdbc.Driver"
    :subprotocol "mysql"
    :subname "//localhost:3306/hello_world?jdbcCompliantTruncation=false&elideSetAutoCommits=true&useLocalSessionState=true&cachePrepStmts=true&cacheCallableStmts=true&alwaysSendSetIsolation=false&prepStmtCacheSize=4096&cacheServerConfiguration=true&prepStmtCacheSqlLimit=2048&zeroDateTimeBehavior=convertToNull&traceProtocol=false&useUnbufferedInput=false&useReadAheadInput=false&maintainTimeStats=false&useServerPrepStmts&cacheRSMetadata=true"
    :user "benchmarkdbuser"
    :password "benchmarkdbpass"})
 
+(def db-spec
+  {:classname "com.mysql.jdbc.Driver"
+   :subprotocol "mysql"
+   :subname "//localhost:3306/hello_world?jdbcCompliantTruncation=false&elideSetAutoCommits=true&useLocalSessionState=true&cachePrepStmts=true&cacheCallableStmts=true&alwaysSendSetIsolation=false&prepStmtCacheSize=4096&cacheServerConfiguration=true&prepStmtCacheSqlLimit=2048&zeroDateTimeBehavior=convertToNull&traceProtocol=false&useUnbufferedInput=false&useReadAheadInput=false&maintainTimeStats=false&useServerPrepStmts&cacheRSMetadata=true"
+   :user "root"
+   :password "root"
+   })
+
 (defn pool
   [spec]
   {:datasource
@@ -54,11 +62,16 @@
   message text, and then return the results."
   (sort-by
    :message
-   (conj (get-all-fortunes) {:id 0 :message "Additional fortune added at request time."})))
+   (conj (get-all-fortunes {} {:connection @db})
+         {:id 0 :message "Additional fortune added at request time."})))
 
 (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 (-> queries get-query-count run-queries)]
-    (update-world<! (assoc world :randomNumber (inc (rand-int 9999))) {:connection @db})))
+    (let [updated-world (assoc world :randomNumber (inc (rand-int 9999)))]
+      (update-world<! updated-world {:connection @db})
+      updated-world)))
+
+