About
Feature-complete: TLS with SCRAM and client certificates, a connection pool, failover and load balancing across hosts, streamed COPY, and LISTEN/NOTIFY that reconnects by itself. Errors and logs never contain your parameters or passwords.
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-eioThen in your dune file:
(libraries postgres-eio eio_main)In code
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)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
Under load
Queries
- libpq
- 4,090
- postgres-eio
- 3,510
- postgres_async
- 2,040
Rows read
- postgres-eio
- 7.2M
- postgres_async
- 6.9M
- libpq
- 5.6M
Inserts
- postgres-eio (pipelined)
- 396,900
- libpq
- 3,970
- postgres_async
- 1,840
Operations per second on one connection, Postgres 18.6 in Docker on an Apple M4 Pro, postgres-eio 0.5.1, median of three runs. A query is one round trip, rows are read 100,000 a query, and postgres-eio pipelines its 1,000 inserts into one round trip, which libpq and postgres_async cannot. libpq, in C, spends about a third of the CPU a query.
Ontology
- StatementDatabaseruns on
- MigrationDatabasechanges
- Connection poolDatabaseconnects to
- Health checkDatabasechecks
Build with Hypha.
Talk to us
Bring a product or an idea.
Read the code
The components are open: source, tests and documentation.
Read the principles
The argument in full, in seven propositions.
