Skip to content
Hypha Stack

postgres-eio

A native Postgres driver for OCaml 5 and Eio.

Source on GitHubLatest: 0.5.0

About

Protocol 3.0 and 3.2 over TCP, Unix sockets and TLS, with multi-host failover and load balancing; SCRAM-SHA-256 with channel binding; statement caching, pipelining, COPY and LISTEN/NOTIFY.

A connection pool lends every connection in a clean state. Every failure is a value, and its errors and logs never contain parameters, passwords or message bytes.

Data and persistence

Install

From Hypha's opam repository, on OCaml 5.5 or later:

opam repo add hypha https://github.com/hyphatech/opam-repository.git
opam install postgres-eio

Then in your dune file:

(libraries postgres-eio eio_main)

In code

  1. A query, its rows folded as they arrive and never buffered.

    let names =
      Postgres_eio.query conn
        "select name from customers where country = $1"
        ~params:[ Some "GB" ] ~init:[]
        ~row:(fun names row ->
          match row with [| Some name |] -> name :: names | _ -> names)
  2. Both libpq forms of connection string; with none given, a connection that crosses a network is encrypted.

    postgres://user:pass@host:5432/db?sslmode=require
    host=db user=app sslmode=require

Ontology

Build with Hypha.