• Stars
    star
    14
  • Rank 1,438,076 (Top 29 %)
  • Language
    Clojure
  • License
    Eclipse Public Li...
  • Created over 5 years ago
  • Updated about 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Connection pools for JDBC databases. Simple wrapper around C3P0.

Downloads Dependencies Status Circle CI License cljdoc badge

Clojars Project

Creating a Connection Pool

From a clojure.java.jdbc spec

You can create a C3P0 connection pool with any clojure.java.jdbc connection spec map with :subname and :subprotocol keys. connection-pool-spec will return a clojure.java.jdbc connection spec you can use directly:

(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).

From a JDBC URL String:

You can create a pooled DataSource (e.g., for use with next-jdbc) by calling pooled-data-source-from-url:

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

(with-open [connection (jdbc/get-connection (connection-pool/pooled-data-source-from-url "jdbc:postgresql:localhost:3000/my_db"))]
  (reduce my-fn init-value (jdbc/plan connection ["SELECT *"])))

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! pool-spec)

Legal Stuff

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

More Repositories

1

metabase

The simplest, fastest way to get business intelligence and analytics to everyone in your company 😋
Clojure
36,663
star
2

toucan

A classy high-level Clojure library for defining application models and retrieving them from a DB
Clojure
566
star
3

embedding-reference-apps

Reference applications for common web frameworks showing how to embed Metabase charts
PHP
128
star
4

metabase-deploy

Metabase binary deployment
Shell
96
star
5

sso-examples

Single Sign-On (SSO) examples for Metabase integration
JavaScript
46
star
6

hawk

It watches your code like a hawk! You like tests, right? Then run them with our state-of-the-art Clojure test runner.
Clojure
35
star
7

metabase-buildpack

Buildpack for Heroku
Shell
23
star
8

throttle

Tools for throttling access to API endpoints or other code pathways 😋
Clojure
17
star
9

metabase-qa

Make Metabase More Awesome
Shell
13
star
10

mbql

Formal definition and utility functions lib for the MBQL language
Clojure
12
star
11

sparksql-deps

Metabase SparkSQL driver dependencies
Clojure
8
star
12

dev-scripts

Useful scripts for Metabase development
Clojure
8
star
13

mba

metabase assembler
Clojure
7
star
14

sudoku-driver

Sample Metabase driver that generates sudoku boards
Clojure
7
star
15

webchauffeur

A fancy wrapper around selenium-webdriver for Node.js
JavaScript
6
star
16

metabase-clojure-mode

Minor Mode for Writing Metabase Clojure Code for Emacs
Emacs Lisp
6
star
17

crate-driver

Metabase driver for CrateDB. Community-supported.
Clojure
6
star
18

docker-spark

Docker image for running SparkSQL Thrift server
Dockerfile
5
star
19

financial-modeling-package

A package for setting up a metrics store in Metabase.
Python
5
star
20

macaw

A Clojure wrapper for JSqlParser 🦜
Clojure
5
star
21

toucan.admin

Automatic admin interface built on top of Toucan. Like Django admin, but for Clojure!
Clojure
4
star
22

metabase-docker-ci

Docker Image for CI
Dockerfile
4
star
23

metabase-nodejs-express-interactive-embedding-sample

Metabase Interactive Embedding Sample for Node.js
JavaScript
4
star
24

schema-util

Helpful prismatic/schema utility functions and schemas.
Clojure
3
star
25

CQL

Clojure Query Language
Clojure
3
star
26

metabook

Clerk Notebooks + Metabase
Clojure
3
star
27

common

Things shared across several Metabase projects, such as i18n & the canonical classloader
Clojure
3
star
28

sample-driver

A sample Metabase driver that connects to a database
Clojure
3
star
29

edumation-embedding-demo

Edumation - Metabase interactive embedding demo
TypeScript
3
star
30

jar-compression

EXPERIMENTAL Clojure library for programmatically compressing/decompressing JARs, stripping files and directories, and packing with pack200. Not actively supported
Clojure
3
star
31

uefa-euro-2024-data

A repo that is used to source data from the sportmonks API. The result is used for a EURO 2024 Metabase Dashboard.
Python
3
star
32

cla-bot

AWS Lambda Clojure GitHub app to check whether PR authors have signed CLA.
Clojure
2
star
33

second-date

Helpful java.time utility functions for Clojure
Clojure
2
star
34

interview-fe-boilerplate

JavaScript
2
star
35

honeysql-util

Helpful utility functions for HoneySQL
Clojure
2
star
36

driver

Interface and shared implementation functions for Metabase drivers [WIP]
Clojure
1
star
37

metabase-heroku

Shell
1
star
38

util

Experimental: Spin off metabase.util namespaces into separate lib
Clojure
1
star
39

lein-compress-jar

Leiningen plugin to compress/pack/strip blacklisted files from JARs
Clojure
1
star
40

druid-docker

Docker image to run simple Druid DB cluster for test purposes
Shell
1
star
41

docker-ci-build-image

Dockerfile for doing Metabase builds in CircleCI (no longer used)
Dockerfile
1
star