Code Monkey home page Code Monkey logo

pg-next's Introduction

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:

(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.

(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:

(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

pg-next's People

Contributors

dependabot[bot] avatar diogok avatar

Watchers

 avatar  avatar  avatar

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.