Git Product home page Git Product logo

mpg's Introduction

mpg - more modern postgres to the gallon

Eases interoperability between clojure/java datatypes and postgres datatypes. No more boilerplate!

Handles the following:

  • DATE <-> java.time.LocalDate
  • TIMESTAMP/TIMESTAMPTZ <-> java.time.ZonedDateTime
  • JSON/JSONB <-> clojure map/vector
  • ARRAY (e.g. int[])<-> clojure vector
  • HSTORE <-> clojure map (limited support - jdbc stringifies all contents)

Build Status

Note: this library was once called jdbc-pg-sanity, mpg is the new version.

Installation

Add mpg as a leiningen dependency:

[mpg "1.1.0"]

Clojars Project

Usage

Just require the mpg.core namespace and call patch

(ns whatever.db
    (require [clojure.java.jdbc :as j]
             [mpg.core :as mpg]]))
(mpg/patch) ;; take the default settings
(mpg/patch {:default-map :hstore}) ;; custom settings are merged with the defaults
;; valid settings:
    :data        - boolean, default true. auto-map maps and vectors?
    :datetime    - boolean, default true. auto-map java.time.{LocalDate, ZonedDateTime} ?
    :default-map - keyword. one of :json, :hstore. Default :json

Limitations

The current clojure.java.jdbc interface imposes some limitations on us.

  1. You only get the autoconversion when using clojure.java.jdbc or something built on it
  2. When using unbound statements, we cannot save a vector as an array type (we therefore use json)
  3. When using unbound statements, you must choose between storing maps as json or hstore (default: json)
  4. All applications that have written to the database are assumed to have correctly saved timestamps in UTC. If you only use this library, you won't have to worry about that. Most applications can be configured with the TZ environment variable

Contributing

Contributions and improvements welcome, just open an issue! :)

If this library should do something, and it doesn't currently do it, please fork and open a pull request. All reasonable contributions will be accepted.

Acknowledgements

This library was originally extracted from luminus boilerplate which hails from code floating around the internet generally. James Laver then contributed a new API and java.time support.

License

Copyright © 2016 Shane Kilkelly

Distributed under the MIT license.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.