Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/diogok/pg-next
PostgreSQL with next.jdbc, supporting JSONB and Timestamp using Java8 Instant
https://github.com/diogok/pg-next
java-time jsonb pool postgresql timestamp
Last synced: about 2 months ago
JSON representation
PostgreSQL with next.jdbc, supporting JSONB and Timestamp using Java8 Instant
- Host: GitHub
- URL: https://github.com/diogok/pg-next
- Owner: diogok
- Created: 2020-01-13T21:44:31.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2023-01-29T00:28:15.000Z (almost 2 years ago)
- Last Synced: 2023-04-13T15:11:48.325Z (over 1 year ago)
- Topics: java-time, jsonb, pool, postgresql, timestamp
- Language: Clojure
- Size: 7.81 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 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](https://img.shields.io/clojars/v/org.clojars.diogok/pg-next.svg)](https://clojars.org/org.clojars.diogok/pg-next)
It will pull `next.jdbc`, `postgres jdbc` driver, `hikari cp` and all other deps for you.
Require the lib:
```clojure
(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.
```clojure
(def db-spec
{:host "localhost"
:port "5432"
:username "postgres"
:password "postgres"
:dbname "postgres"})(def pool (make-pool db-spec))
```Use the pool with `next.jdbc`:
```clojure
(require '[next.jdbc :as jdbc])
(require '[next.jdbc.sql :as sql])
(require '[java.time :refer [instant]])(jdbc/execute-one! pool
["CREATE TABLE IF NOT EXISTS my_table (
id varchar primary key,
my_timestamp TIMESTAMP WITH TIME ZONE,
my_object JSONB
)"])(sql/insert! pool :my_table {:id "m1" :my_timestamp (instant) :my_object {:foo "bar"}})
(sql/get-by-id pool :my_table "m1")
#=>:my_table{:id "m1" :my_timestamp #java.time.Instant :my_object {:foo "bar"}}
```## License
MIT