Install
Start hereYou need opam, OCaml’s package manager, OCaml 5.5 or later, and a Postgres server to connect to. postgres-eio brings dune, the build tool, with it.
1. Install opam
Section titled “1. Install opam”brew install opambash -c "sh <(curl -fsSL https://opam.ocaml.org/install.sh)"winget install Git.Git OCaml.opampostgres-eio should work on Windows, but it is not tested there. If something fails, WSL gives you a Linux to follow the Linux steps in.
2. Set up OCaml
Section titled “2. Set up OCaml”opam initAnswer yes when it offers to set up your shell. This installs the latest OCaml, which takes a few minutes. Then let this terminal see it – a new terminal does by itself:
eval $(opam env)(& opam env) -split '\r?\n' | ForEach-Object { Invoke-Expression $_ }Already had opam?
Check ocaml -version. If it is older than 5.5, make a switch – an
environment of its own – with the latest OCaml:
opam switch create postgres-eio ocaml-base-compilereval $(opam env)3. Install postgres-eio
Section titled “3. Install postgres-eio”opam repo add hypha https://github.com/hyphatech/opam-repository.gitopam install postgres-eioThis installs the driver and everything it needs. A program runs it inside
Eio’s event loop, which eio_main starts, so install that beside it:
opam install eio_mainA program names both in its dune file:
(libraries postgres-eio eio_main)Check it worked
Section titled “Check it worked”$ ocaml -versionThe OCaml toplevel, version 5.5.1
$ opam list postgres-eioIt lists postgres-eio with a version, not --, under Installed.
Your editor
Section titled “Your editor”For completion, types on hover and errors as you type, install the language server, then the OCaml Platform extension in VS Code – or the OCaml support of your editor:
opam install ocaml-lsp-serverThe quick start connects and runs a query, next.
