Browse Source

switched to using Postgres

Yogthos 9 years ago
parent
commit
808b34a09c

+ 1 - 1
frameworks/Clojure/luminus/benchmark_config.json

@@ -12,7 +12,7 @@
       "port": 3000,
       "approach": "Realistic",
       "classification": "Platform",
-      "database": "MySQL",
+      "database": "Postgres",
       "framework": "luminus",
       "language": "Clojure",
       "orm": "Raw",

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

@@ -24,7 +24,7 @@
                  [luminus-nrepl "0.1.2"]
                  [migratus "0.8.8"]
                  [conman "0.2.9"]
-                 [mysql/mysql-connector-java "5.1.34"]
+                 [org.postgresql/postgresql "9.4-1206-jdbc4"]
                  [org.webjars/webjars-locator-jboss-vfs "0.1.0"]
                  [luminus-immutant "0.1.0"]]
 
@@ -50,8 +50,8 @@
                                  [ring/ring-devel "1.4.0"]
                                  [pjstadig/humane-test-output "0.7.1"]
                                  [mvxcvi/puget "1.0.0"]]
-                  
-                  
+
+
                   :source-paths ["env/dev/clj"]
                   :repl-options {:init-ns hello.core}
                   :injections [(require 'pjstadig.humane-test-output)

+ 40 - 8
frameworks/Clojure/luminus/hello/src/hello/db/core.clj

@@ -1,18 +1,24 @@
 (ns hello.db.core
   (:require
+    [cheshire.core :refer [generate-string parse-string]]
     [clojure.java.jdbc :as jdbc]
     [conman.core :as conman]
     [environ.core :refer [env]]
     [mount.core :refer [defstate]])
-  (:import [java.sql
+  (:import org.postgresql.util.PGobject
+           org.postgresql.jdbc4.Jdbc4Array
+           clojure.lang.IPersistentMap
+           clojure.lang.IPersistentVector
+           [java.sql
             BatchUpdateException
+            Date
+            Timestamp
             PreparedStatement]))
 
 (def pool-spec
-  {:jdbc-uri   "//127.0.0.1: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"
-   :datasource-classname "com.mysql.jdbc.jdbc2.optional.MysqlDataSource"
-   :username   "benchmarkdbuser"
+  {:username   "benchmarkdbuser"
    :password   "benchmarkdbpass"
+   :jdbc-url   "jdbc:postgresql://127.0.0.1:5432/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"
    :init-size  1
    :min-idle   1
    :max-idle   4
@@ -36,16 +42,42 @@
   (-> sql-date (.getTime) (java.util.Date.)))
 
 (extend-protocol jdbc/IResultSetReadColumn
-  java.sql.Date
+  Date
   (result-set-read-column [v _ _] (to-date v))
 
-  java.sql.Timestamp
-  (result-set-read-column [v _ _] (to-date v)))
+  Timestamp
+  (result-set-read-column [v _ _] (to-date v))
+
+  Jdbc4Array
+  (result-set-read-column [v _ _] (vec (.getArray v)))
+
+  PGobject
+  (result-set-read-column [pgobj _metadata _index]
+    (let [type  (.getType pgobj)
+          value (.getValue pgobj)]
+      (case type
+        "json" (parse-string value true)
+        "jsonb" (parse-string value true)
+        "citext" (str value)
+        value))))
 
 (extend-type java.util.Date
   jdbc/ISQLParameter
   (set-parameter [v ^PreparedStatement stmt idx]
-    (.setTimestamp stmt idx (java.sql.Timestamp. (.getTime v)))))
+    (.setTimestamp stmt idx (Timestamp. (.getTime v)))))
+
+(defn to-pg-json [value]
+  (doto (PGobject.)
+    (.setType "jsonb")
+    (.setValue (generate-string value))))
+
+(extend-protocol jdbc/ISQLValue
+  IPersistentMap
+  (sql-value [value] (to-pg-json value))
+  IPersistentVector
+  (sql-value [value] (to-pg-json value)))
+
+;; queries
 
 (defn get-world-random
   "Query a random World record between 1 and 10,000 from the database"

+ 1 - 1
frameworks/Clojure/luminus/setup.sh

@@ -3,7 +3,7 @@
 fw_depends java7 resin leiningen
 
 # Update db host in the source file
-sed -i 's|:subname "//.*:3306|:subname "//'"${DBHOST}"':3306|g' hello/src/hello/db/core.clj
+sed -i 's|:jdbc-uri   "jdbc:postgresql://.*/hello_world|:jdbc-uri   "jdbc:postgresql://'"${DBHOST}"':5432/hello_world|g' hello/src/hello/db/core.clj
 
 cd hello
 lein clean