Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
korma.sql.utils]
:src-dir-uri "https://github.com/korma/Korma/blob/master/"
:src-linenum-anchor-prefix "L"}

:dependencies [[org.clojure/clojure "1.8.0"]
[com.mchange/c3p0 "0.9.5.2"]
[org.clojure/java.jdbc "0.6.1"]]
Expand All @@ -24,7 +23,8 @@
:plugins [[codox "0.8.12"]
[jonase/eastwood "0.2.1"]
[lein-localrepo "0.5.3"]]}
:test {:dependencies [[mysql/mysql-connector-java "5.1.35"]
:test {:plugins [[lein-cloverage "1.0.9"]]
:dependencies [[mysql/mysql-connector-java "5.1.35"]
[com.h2database/h2 "1.4.187"]
[criterium "0.4.3"]]}
:1.4 {:dependencies [[org.clojure/clojure "1.4.0"]]}
Expand Down
32 changes: 28 additions & 4 deletions src/korma/db.clj
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@
test-connection-query
idle-connection-test-period
test-connection-on-checkin
test-connection-on-checkout]
test-connection-on-checkout
acquire-retry-attempts
acquire-retry-delay
acquire-increment
checkout-timeout]
:or {excess-timeout (* 30 60)
idle-timeout (* 3 60 60)
initial-pool-size 3
Expand All @@ -68,7 +72,11 @@
test-connection-query nil
idle-connection-test-period 0
test-connection-on-checkin false
test-connection-on-checkout false}
test-connection-on-checkout false
acquire-retry-attempts 30
acquire-retry-delay 1000
acquire-increment 3
checkout-timeout 0}
:as spec}]
(when-not c3p0-enabled?
(throw (Exception. "com.mchange.v2.c3p0.ComboPooledDataSource not found in class path.")))
Expand All @@ -92,7 +100,11 @@
(.setIdleConnectionTestPeriod idle-connection-test-period)
(.setTestConnectionOnCheckin test-connection-on-checkin)
(.setTestConnectionOnCheckout test-connection-on-checkout)
(.setPreferredTestQuery test-connection-query))})
(.setPreferredTestQuery test-connection-query)
(.setAcquireRetryAttempts acquire-retry-attempts)
(.setAcquireRetryDelay acquire-retry-delay)
(.setAcquireIncrement acquire-increment)
(.setCheckoutTimeout checkout-timeout))})

(defn delay-pool
"Return a delay for creating a connection pool for the given spec."
Expand All @@ -118,7 +130,8 @@
"sqlserver" "com.microsoft.sqlserver.jdbc.SQLServerDriver"
"odbc" "sun.jdbc.odbc.JdbcOdbcDriver"
"sqlite" "org.sqlite.JDBC"
"h2" "org.h2.Driver"})
"h2" "org.h2.Driver"
"kylin" "org.apache.kylin.jdbc.Driver"})

(def ^:private subprotocol->options {"mysql" {:delimiters "`"}})

Expand Down Expand Up @@ -166,6 +179,17 @@
:encoding "UTF8"}
(dissoc opts :host :port :db)))

(defn kylin
"Create a database specification for a kylin database. Opts should include
keys for :db, :user, and :password. You can also optionally set host and
port."
[{:keys [host port db]
:or {host "localhost", port 5432, db ""}
:as opts}]
(merge {:subprotocol "kylin"
:subname (str "//" host ":" port "/" db)}
(dissoc opts :host :port :db)))

(defn postgres
"Create a database specification for a postgres database. Opts should include
keys for :db, :user, and :password. You can also optionally set host and
Expand Down
32 changes: 17 additions & 15 deletions src/korma/sql/engine.clj
Original file line number Diff line number Diff line change
Expand Up @@ -157,21 +157,23 @@
;;*****************************************************

(def predicates
(let [predicates-s {'like 'korma.sql.fns/pred-like
'ilike 'korma.sql.fns/pred-ilike
'and 'korma.sql.fns/pred-and
'or 'korma.sql.fns/pred-or
'not 'korma.sql.fns/pred-not
'in 'korma.sql.fns/pred-in
'exists 'korma.sql.fns/pred-exists
'not-in 'korma.sql.fns/pred-not-in
'between 'korma.sql.fns/pred-between
'> 'korma.sql.fns/pred->
'< 'korma.sql.fns/pred-<
'>= 'korma.sql.fns/pred->=
'<= 'korma.sql.fns/pred-<=
'not= 'korma.sql.fns/pred-not=
'= 'korma.sql.fns/pred-=}
(let [predicates-s {'like 'korma.sql.fns/pred-like
'ilike 'korma.sql.fns/pred-ilike
'and 'korma.sql.fns/pred-and
'or 'korma.sql.fns/pred-or
'not 'korma.sql.fns/pred-not
'in 'korma.sql.fns/pred-in
'exists 'korma.sql.fns/pred-exists
'not-in 'korma.sql.fns/pred-not-in
'between 'korma.sql.fns/pred-between
'> 'korma.sql.fns/pred->
'< 'korma.sql.fns/pred-<
'>= 'korma.sql.fns/pred->=
'<= 'korma.sql.fns/pred-<=
'not= 'korma.sql.fns/pred-not=
'= 'korma.sql.fns/pred-=
'not-between 'korma.sql.fns/pred-not-between
'similar-to 'korma.sql.fns/pred-similar-to}
predicates-k (into {} (map (fn [[k v]] {(keyword k) v}) predicates-s))]
(merge predicates-s predicates-k)))

Expand Down
20 changes: 12 additions & 8 deletions src/korma/sql/fns.clj
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,24 @@
(defn pred-or [& args] (group-with " OR " args))
(defn pred-not [v] (wrapper "NOT" v))

(defn pred-in [k v] (infix k "IN" v))
(defn pred-not-in [k v] (infix k "NOT IN" v))
(defn pred-> [k v] (infix k ">" v))
(defn pred-< [k v] (infix k "<" v))
(defn pred->= [k v] (infix k ">=" v))
(defn pred-<= [k v] (infix k "<=" v))
(defn pred-like [k v] (infix k "LIKE" v))
(defn pred-ilike [k v] (infix k "ILIKE" v))
(defn pred-in [k v] (infix k "IN" v))
(defn pred-not-in [k v] (infix k "NOT IN" v))
(defn pred-> [k v] (infix k ">" v))
(defn pred-< [k v] (infix k "<" v))
(defn pred->= [k v] (infix k ">=" v))
(defn pred-<= [k v] (infix k "<=" v))
(defn pred-like [k v] (infix k "LIKE" v))
(defn pred-ilike [k v] (infix k "ILIKE" v))
(defn pred-similar-to [k v] (infix k "SIMILAR TO" v))

(defn pred-exists [v] (wrapper "EXISTS" v))

(defn pred-between [k [v1 v2]]
(trinary k "BETWEEN" v1 "AND" v2))

(defn pred-not-between [k [v1 v2]]
(trinary k "NOT BETWEEN" v1 "AND" v2))

(def pred-= eng/pred-=)
(defn pred-not= [k v] (cond
(and k v) (infix k "<>" v)
Expand Down