Skip to content

Access PostgreSQL connection parameters via Clojure

License

Notifications You must be signed in to change notification settings

grzm/pique.alpha

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pique

Pique (pēk) is a Clojure library to read the system environment for PostgreSQL parameters in the same manner as libpq.

NOTE: This is alpha. The little API it has is not stable.

Releases and Dependency Information

Releases are on Clojars.

Clojure CLI/deps.edn coordinates:

{com.grzm/pique.alpha {:mvn/version "0.1.6"}}

Leiningen/Boot dependency information:

[com.grzm/pique.alpha "0.1.6"]

Maven dependency information:

<dependency>
  <groupId>com.grzm</groupId>
  <artifactId>pique.alpha</artifactId>
  <version>0.1.6</version>
</dependency>

Usage

Easily use your PostgreSQL environment variables, service files, and .pgpass with clojure.java.jdbc:

(require
  '[clojure.java.jdbc :as jdbc]
  '[com.grzm.pique.jdbc :as env])

;; PGDATABASE, PGUSER set in environment

(env/spec)
;; => {:port 5496, :dbname "pique", :user "grzm", :dbtype "postgresql"}

(jdbc/query (env/spec) "SELECT 'Oh, so pleasant!' AS life_with_pique")
;; => ({:life_with_pique "Oh, so pleasant!!"})

clojure.java.jdbc doesn't use all of the parameters that are utilized by libpq (and renames some of the canonical libpq parameter names, and aren't exposed by jdbc/spec. You can access all libpq parameters that have been defined in the environment as well:

(require '[com.grzm.pique.env :as env])

(env/params)
;; => {:database "pique", :port 5496, :user "grzm"}

Details

Pique reads the same environment variables and connection service and password files used by libpq. This includes common enviroment variables such as PGDATABASE and PGUSER, and also PGSERVICEFILE and PGPASSFILE. Connection service files (e.g., ~/.pg_service.conf) and password files (e.g., ~/.pgpass) are also read, just like libpq clients such as psql.

Not all libpq connection parameters make sense for JDBC, but those that do are used to create the connection spec.

License

© 2017 Michael Glaesemann

Released under the MIT License. See LICENSE for details.

About

Access PostgreSQL connection parameters via Clojure

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published