Convert URIs into the ones you can use for JDBC.
Clojure
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.idea Full Cursive project to help people get started quickly developing. Dec 22, 2015
doc Created project: lein new to-jdbc-uri Jul 15, 2015
src/to_jdbc_uri
test/to_jdbc_uri Add support for URL params Dec 16, 2015
.gitignore
.travis.yml Add .travis.yml to use continuous build. Jul 19, 2015
LICENSE Created project: lein new to-jdbc-uri Jul 15, 2015
README.md Changelog for 0.5.0. Dec 22, 2015
project.clj lein-release plugin: bumped version from 0.5.0 to 0.6.0-SNAPSHOT for … Dec 22, 2015
to-jdbc-uri.iml Non-semantic: IntelliJ file. Dec 18, 2015

README.md

to-jdbc-uri

Code at GitHub Clojars Build Status Join the chat at https://gitter.im/carouselapps/to-jdbc-uri

Many libraries starting with clojure.java.jdbc and libraries that use clojure.java.jdbc internally expect a JDBC URI to connect to the database, but your environment might be giving you the database specs in a different format. to-jdbc-uri is designed to take the database credentials in any format and, as long as it's possible, generate a valid JDBC URI. Currently supported:

  • PostgreSQL (Heroku, RedHat OpenShift and others)
  • MySQL

Support for other formats, databases, environments is welcome.

The code in this library is actually trivial but if you need to perform this task and search for solutions you'll find lots of different snippets of code, some which work in some environments and not others. Even if you end up not using this library but copying and pasting the code it is better to have a canonical place for this code to exist.

Usage

In your project.clj include the dependency:

Clojars Project

and then call it like this:

(to-jdbc-uri.core/to-jdbc-uri your-non-jdbc-url)

for example:

(to-jdbc-uri "postgres://username:password@hostname/dbname")

which will output:

"jdbc:postgresql://hostname/dbname?user=username&password=password"

It is safe to feed JDBC URIs to this library, they'll be left untouched. For more examples, you might want to look into the tests, which are very simple.

Note: to-jdbc-uri up to version 0.3.0 was not in the com.carouselapps group, from 0.4.0 it'll be in the com.carouselapps groups. If you are using this jar, you can and should switch from [to-jdbc-uri "0.3.0"] to [com.carouselapps/to-jdbc-uri "0.4.1"] or the latest version.

Contributing

To contribute:

  1. fork the project.
  2. Add support for your favorite database/environment/format/feature.
  3. Add tests for the new code you wrote.
  4. Make sure all tests pass, new and all.
  5. Push, commit and send a pull request. Note how urgently you need a new release.

Change log

v0.5.0 - 2015-12-22

v0.4.1 - 2015-11-03

  • Corrected syntax for case when selected for PostgreSQL.

v0.4.0 - 2015-11-03

v0.3.0 - 2015-08-24

v0.2.0 - 2015-06-20

  • Raise an exception when the URI is empty or blank.
  • Started using Travis CI for continuous integration.

v0.1.0 - 2015-06-15

  • Initial version supporting PostgreSQL (at least on Heroku).

License

Copyright © 2015 Carousel Apps, Ltd. All rights reserved.

Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.