package pgx_async

  1. Overview
  2. Docs
Pgx using Async for IO

Install

Dune Dependency

Authors

Maintainers

Sources

pgx-2.2.tbz
sha256=e50dfb4e9d124d74da0d82f480357f63f947bb469b49c171ffd5f27c3c69c56a
sha512=07592f9c9a123b446f2742cc39bf23751dd0590b8028e7ed14f254c6f2c77a23efc616557aff43775354ff49cf71276ac400cf72d2c4d921fa4473d0b3209b21

Description

Pgx using Async for IO

Published: 27 Oct 2022

README

README.md

PGX is a pure-OCaml PostgreSQL client library, supporting Async, LWT, or synchronous operations.

This library focuses on correctness and safety, with features like:

  • It is nearly impossible to try to execute a prepared statement that hasn't been prepared.

  • Trying to run multiple queries at the same time will work properly (although there's no performance benefit, since we currently don't send queries in parallel).

  • Lots of automated tests.

  • Pgx.Value for parameters and returned data, encouraging people to use the built-in converters instead of trying to handle everything as a string.

  • Async and LWT support are built in, no need to write your own IO module.

  • Mirage OS is supported via Pgx_lwt_mirage

We also provide a relatively high-level interface, like Pgx_async.execute_pipe, which prepares a statement, executes it with the given parameters, returns an Async.Pipe.Reader.t (so you can stream results), and unprepares the statement when the query is finished.

Significant portions of the code come from PG'Ocaml.

Setup

opam install pgx_async # or pgx_lwt_unix or pgx_unix or pgx_lwt_mirage

Examples

See pgx_async/bin/pgx_async_example.ml for a complete example of the high-level functional interface. To translate the example to Lwt, replace Pgx_async with Pgx_lwt and >>| with >|=. To translate it to synchronous IO / standard-library-only, use Pgx_unix and replace both >>| and >>= with |>, or just replace >>| fun () -> with ;.

I.e. in Pgx_unix, you can replace:

Pgx_async.execute ~params "INSERT INTO ..."
>>| fun () ->

... with:

Pgx_unix.execute ~params "INSERT INTO ...";

Dependencies (8)

  1. pgx_value_core = version
  2. pgx = version
  3. ocaml >= "4.08"
  4. conduit-async >= "1.5.0"
  5. async_ssl
  6. async_unix >= "v0.13.0"
  7. async_kernel >= "v0.13.0" & < "v0.17"
  8. dune >= "3.2"

Dev Dependencies (3)

  1. odoc with-doc
  2. base64 with-test & >= "3.0.0"
  3. alcotest-async with-test & >= "1.0.0"

Used by

None

Conflicts

None

OCaml

Innovation. Community. Security.