Skip to content

githubink/connection-pool

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Downloads Dependencies Status Circle CI License cljdoc badge

Clojars Project

Creating a Connection Pool

You can create a C3P0 connection pool with any clojure.java.jdbc connection spec map. (Currently, only maps with :subname and :subprotocol are supported.) connection-pool-spec will return a clojure.java.jdbc connection spec you can use directly with JDBC:

(require '[clojure.java.jdbc :as jdbc]
         '[metabase.connection-pool :as connection-pool])

;;; Create a C3P0 connection pool

(let [pool-spec (connection-pool/connection-pool-spec my-jdbc-spec)]
  (jdbc/query pool-spec ["SELECT *"]))

(You will almost certainly want to store your pool somewhere, such as in an atom).

Configuring the connection pool

You can set connection pool options such as size in a c3p0.properties file, or by passing them as a map to connection-pool-spec:

(def ^:private connection-pool-properties
  {"maxIdleTime"     (* 3 60 60)
   "minPoolSize"     1
   "initialPoolSize" 1
   "maxPoolSize"     15})
   
(def my-pool-spec 
  (connection-pool/connection-pool-spec my-jdbc-spec connection-pool-properties))

See https://www.mchange.com/projects/c3p0/#configuration_properties for a list of all options.

Destroying connection pools

destroy-connection-pool! will destroy the connection pool you created:

(connection-pool/destroy-connection-pool! (:datasource pool-spec))

Note that due to me making bad decisions that I haven't fixed yet you currently have to pull the DataSource out of the pool spec yourself. (I plan to fix this in the future)

Legal Stuff

Copyright © 2019 Metabase, Inc. This project is licensed under the Eclipse Public License, same as Clojure.

About

Connection pools for JDBC databases. Simple wrapper around C3P0.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Clojure 89.6%
  • Emacs Lisp 10.4%