项目作者: diogok

项目描述 :
PostgreSQL with next.jdbc, supporting JSONB and Timestamp using Java8 Instant
高级语言: Clojure
项目地址: git://github.com/diogok/pg-next.git
创建时间: 2020-01-13T21:44:31Z
项目社区:https://github.com/diogok/pg-next

开源协议:

下载


pg-next

A simple lib with what is needed to connect with jdbc.next to postgresql.

Already including types for jsonb using cheshire and timestamp with timezone using instant from clojure.java-time.

Usage

Import from clojars:

Clojars Project

It will pull next.jdbc, postgres jdbc driver, hikari cp and all other deps for you.

Require the lib:

  1. (require '[pg-next.core :refer [make-pool]])

Create a connection pool. These are the default values, you only need to supply what you want to override.

  1. (def db-spec
  2. {:host "localhost"
  3. :port "5432"
  4. :username "postgres"
  5. :password "postgres"
  6. :dbname "postgres"})
  7. (def pool (make-pool db-spec))

Use the pool with next.jdbc:

  1. (require '[next.jdbc :as jdbc])
  2. (require '[next.jdbc.sql :as sql])
  3. (require '[java.time :refer [instant]])
  4. (jdbc/execute-one! pool
  5. ["CREATE TABLE IF NOT EXISTS my_table (
  6. id varchar primary key,
  7. my_timestamp TIMESTAMP WITH TIME ZONE,
  8. my_object JSONB
  9. )"])
  10. (sql/insert! pool :my_table {:id "m1" :my_timestamp (instant) :my_object {:foo "bar"}})
  11. (sql/get-by-id pool :my_table "m1")
  12. #=>:my_table{:id "m1" :my_timestamp #java.time.Instant :my_object {:foo "bar"}}

License

MIT