From 9bdd6b389ed5197a869fd202a16077c66bd6a251 Mon Sep 17 00:00:00 2001 From: Roman Zaiev Date: Sat, 21 Nov 2026 23:18:40 +0000 Subject: [PATCH] Install the documentation for agents with postgres-eio An agent writing code with postgres-eio knew only the README and the changelog the package installs: the site's guides, where a pool's options, pipelining and COPY are shown whole, stayed online, and never at the release it builds against. starlight-hypha-agents writes each page as Markdown and llms.txt from the same pages people read, and postgres-eio installs them. An agent reads them only when told to, so the README gives a user the one line for their project's AGENTS.md that sends it there. The docs workflow now builds every pull request and fails if agents/ differs from what the pages write, so the installed pages cannot drift; it deploys from main alone. The theme moves to 0.8.0, which leaves what agents read to that plugin. --- .github/workflows/docs.yml | 35 +++-- AGENTS.md | 15 +- CHANGES.md | 5 + README.md | 12 ++ agents/llms.txt | 25 +++ agents/pages/guide/connection-strings.md | 114 ++++++++++++++ agents/pages/guide/copy.md | 68 ++++++++ agents/pages/guide/errors.md | 122 +++++++++++++++ agents/pages/guide/listen-notify.md | 98 ++++++++++++ agents/pages/guide/performance.md | 17 ++ agents/pages/guide/pipelining.md | 77 +++++++++ agents/pages/guide/pool.md | 136 ++++++++++++++++ agents/pages/guide/queries.md | 189 +++++++++++++++++++++++ agents/pages/guide/several-hosts.md | 84 ++++++++++ agents/pages/guide/tls.md | 101 ++++++++++++ agents/pages/index.md | 56 +++++++ agents/pages/quick-start.md | 76 +++++++++ agents/pages/reference.md | 43 ++++++ docs/astro.config.mjs | 5 + docs/bun.lock | 37 ++++- docs/package.json | 3 +- dune | 10 ++ 22 files changed, 1313 insertions(+), 15 deletions(-) create mode 100644 agents/llms.txt create mode 100644 agents/pages/guide/connection-strings.md create mode 100644 agents/pages/guide/copy.md create mode 100644 agents/pages/guide/errors.md create mode 100644 agents/pages/guide/listen-notify.md create mode 100644 agents/pages/guide/performance.md create mode 100644 agents/pages/guide/pipelining.md create mode 100644 agents/pages/guide/pool.md create mode 100644 agents/pages/guide/queries.md create mode 100644 agents/pages/guide/several-hosts.md create mode 100644 agents/pages/guide/tls.md create mode 100644 agents/pages/index.md create mode 100644 agents/pages/quick-start.md create mode 100644 agents/pages/reference.md diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 63181ca..ca452a6 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -1,28 +1,28 @@ -# The documentation site on GitHub Pages, rebuilt on every push to main: +# The documentation site on GitHub Pages: built on every pull request, which +# fails if agents/ is not what the pages write, and deployed from main. # odoc's reference from the .mli files, then Starlight's pages around it. name: docs on: push: branches: [main] + pull_request: +# A build reads the repository and nothing more; the deploy job alone is +# given the rights to publish. permissions: contents: read - pages: write - id-token: write +# A newer push to a pull request replaces its build; main's deploys queue +# and always finish. concurrency: - group: pages - cancel-in-progress: true + group: pages-${{ github.ref }} + cancel-in-progress: ${{ github.event_name == 'pull_request' }} jobs: - deploy: + build: runs-on: ubuntu-24.04 - environment: - name: github-pages - url: ${{ steps.deployment.outputs.page_url }} steps: - - uses: actions/configure-pages@v6 - uses: actions/checkout@v5 - uses: ocaml/setup-ocaml@v3 with: @@ -38,8 +38,23 @@ jobs: # the token, past its limit for a runner's shared address. env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # The build writes agents/ from the pages: a page changed without it + # differs here. + - run: git add --intent-to-add agents/ && git diff --exit-code agents/ - uses: actions/upload-pages-artifact@v5 with: path: _build/docs + deploy: + needs: build + if: github.ref == 'refs/heads/main' + runs-on: ubuntu-24.04 + permissions: + pages: write + id-token: write + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + steps: + - uses: actions/configure-pages@v6 - uses: actions/deploy-pages@v5 id: deployment diff --git a/AGENTS.md b/AGENTS.md index 2daeecf..ca33d41 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -22,8 +22,8 @@ make release VERSION=1.2.3 # once CHANGES.md names it: tag and release with ope `make test` needs `podman compose`. Without `POSTGRES_EIO_TEST_PG` the cases that need a server are skipped, and the test output says so. `make docs` needs Bun. CI runs `make lint` and `make test` -on OCaml 5.5, and `docs.yml` publishes the site to GitHub Pages on every -push to `main`. +on OCaml 5.5, and `docs.yml` builds the site on every pull request and +publishes it to GitHub Pages from `main`. ## Layout @@ -49,6 +49,10 @@ docs/ the documentation site, a Starlight site in Hypha's look, as @examples/.ml?raw into Starlight's examples/ the programs and modules the site shows, each a whole file, each built +agents/ the documentation for a user's agent, generated by + starlight-hypha-agents from the pages, `make docs`: + llms.txt, the catalogue, and pages/, each page as + Markdown; installed by the postgres-eio package ``` `make docs` builds the site into `_build/docs`, so it adds nothing to the @@ -63,6 +67,13 @@ module. Each rule comes with why it exists and the test that catches a break. +- **`agents/` is generated, never edited.** starlight-hypha-agents writes + it from the site's pages as `make docs` builds them: a page changed is + `make docs` run in the same commit. Why: a user's agent reads what the + release installs, offline, and a page it reads must be the release's. + Test: the docs workflow builds the pages on every pull request and fails + if `agents/` then differs. + - **Every protocol requirement the driver meets has a test case named by its section** of chapter 54 of the Postgres 18 docs (e.g. `54.2.4 ...`). Backend messages are read whole, a byte at a time, and at generated diff --git a/CHANGES.md b/CHANGES.md index b09f44e..e94f00e 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,10 @@ # Changes +## Unreleased + +- postgres-eio installs its documentation for agents: each page of the + site as Markdown, and `llms.txt`, in `$(opam var postgres-eio:doc)`. + ## 0.5.2 (2026-11-10) - postgres-eio is published to open-opam, `opam repo add open-opam diff --git a/README.md b/README.md index 4af4768..6d26d1d 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,18 @@ let () = Postgres_eio.close conn) ``` +## With an agent + +postgres-eio installs its documentation at `$(opam var postgres-eio:doc)`: +each page of the site as Markdown, and `llms.txt`, which lists them. Your +agent reads it when told to, in a line in your project's `AGENTS.md`: + +```md +Before writing code with postgres-eio, read `$(opam var postgres-eio:doc)/llms.txt` and +the pages it lists for the parts you need, and use those parts rather than +writing your own. +``` + ## Contributing See [AGENTS.md](AGENTS.md). diff --git a/agents/llms.txt b/agents/llms.txt new file mode 100644 index 0000000..74667c9 --- /dev/null +++ b/agents/llms.txt @@ -0,0 +1,25 @@ +# postgres-eio + +> The Postgres driver for modern OCaml. + +## Start here + +- [Getting Started](pages/index.md): The Postgres driver for modern OCaml. +- [Quick start](pages/quick-start.md) + +## Guides + +- [Connection strings](pages/guide/connection-strings.md) +- [TLS and signing in](pages/guide/tls.md) +- [Several hosts](pages/guide/several-hosts.md) +- [Queries and values](pages/guide/queries.md) +- [Errors](pages/guide/errors.md) +- [Pool](pages/guide/pool.md) +- [Pipelining and batches](pages/guide/pipelining.md) +- [COPY](pages/guide/copy.md) +- [LISTEN/NOTIFY](pages/guide/listen-notify.md) +- [Performance](pages/guide/performance.md) + +## Reference + +- [Reference](pages/reference.md) diff --git a/agents/pages/guide/connection-strings.md b/agents/pages/guide/connection-strings.md new file mode 100644 index 0000000..1be3713 --- /dev/null +++ b/agents/pages/guide/connection-strings.md @@ -0,0 +1,114 @@ +# Connection strings + +Both libpq forms are accepted: `postgres://user:pass@host:5432/db?sslmode=require` +and `host=db user=app sslmode=require`. A URL may start `postgresql://` too. +Unknown keys are an error, not ignored. + +```ocaml +let url = + Postgres_eio.Conninfo.of_string + "postgres://app:secret@db.internal:5432/shop?sslmode=verify-full" + +let keywords = + Postgres_eio.Conninfo.of_string + "host=db.internal port=5432 user=app password='a secret' dbname=shop \ + sslmode=verify-full" +``` + +`Conninfo.of_string` answers the connection, or a sentence saying what is +wrong with the string. A URL is percent-decoded. A keyword value may be +single-quoted, with backslash escapes, so it can hold a space. An empty +value unsets a key. + +## The keys + +| Key | Values | Default | +|---|---|---| +| `host` | name, address, or a Unix socket directory (starts with `/`); comma-separated for several | `localhost` | +| `hostaddr` | IP address to connect to without a lookup; `host` stays the name TLS verifies | | +| `port` | one for all hosts, or one per host | `5432` | +| `user` | | required | +| `password` | | | +| `dbname` | | `user` | +| `sslmode` | `disable`, `allow`, `prefer`, `require`, `verify-ca`, `verify-full` | `prefer` on this machine, `require` elsewhere | +| `sslrootcert` | PEM file of trusted CAs, for `verify-ca` and `verify-full` | system CAs | +| `sslcert`, `sslkey` | PEM client certificate and unencrypted key | | +| `sslnegotiation` | `postgres`, or `direct` for TLS from the first byte (needs `require` or stronger) | `postgres` | +| `channel_binding` | `disable`, `prefer`, `require` | `prefer` | +| `require_auth` | list of `password`, `md5`, `scram-sha-256`, `none`, or each negated with `!` | all | +| `connect_timeout` | whole seconds per address attempt | the connection's `timeout` (30 s) | +| `application_name` | | | +| `keepalives` | `1`, `0` | `1` | +| `target_session_attrs` | `any`, `read-write`, `read-only`, `primary`, `standby`, `prefer-standby` | `any` | +| `load_balance_hosts` | `disable`, `random` | `disable` | +| `min_protocol_version`, `max_protocol_version` | `3.0`, `3.2`, `latest` | `3.0` | +| `options` | `-c name=value` settings, sent as startup parameters | | + +The TLS keys are explained in [TLS and signing in](tls.md), +and `target_session_attrs` and `load_balance_hosts` in +[several hosts](several-hosts.md). `sslpassword` is not +supported, and is an error like any other unknown key: a client key is read +unencrypted. + +The driver speaks protocol 3.0 and 3.2, over TCP, a Unix socket or TLS. +`max_protocol_version` is `3.0` by default, since many poolers speak only +3.0; `latest` is 3.2. `options` reads `-c name=value`, `-cname=value` and +`--name=value`. `connect_timeout` of `0` or less is absent, as libpq reads +it, and the connection's `timeout` bounds each attempt instead. + +## The environment and .pgpass + +The driver reads no environment variables or files unless you pass them in: + +```ocaml +let from_environment pgpass_contents = + Postgres_eio.Conninfo.of_string + ~defaults:(Postgres_eio.Conninfo.environment Sys.getenv_opt) + "dbname=shop" + |> Result.map (Postgres_eio.Conninfo.passfile pgpass_contents) +``` + +`Conninfo.environment` reads libpq's `PG*` variables for the supported keys +(`PGHOST`, `PGPORT`, `PGUSER`, `PGPASSWORD`, ...), ignoring an empty one, +and hands them to `of_string` as defaults for the keys the string leaves +out. It takes the function that reads a variable, so a test can hand it +another. + +`Conninfo.passfile` takes the contents of a `.pgpass` file and fills each +host's password from it where the string gave none, as libpq does: +`host:port:database:user:password`, `*` wildcards, backslash escapes, first +match wins. Hosts match as written, a socket by its directory. Finding the +file and checking its permissions is the program's: + +```ocaml +(* libpq refuses a .pgpass that others can read; checking that is the + program's, as is finding the file. *) +let contents () = + match Sys.getenv_opt "HOME" with + | None -> "" + | Some home -> ( + match + In_channel.with_open_bin + (Filename.concat home ".pgpass") + In_channel.input_all + with + | contents -> contents + | exception Sys_error _ -> "") +``` + +## Changing a connection + +A connection string is read by its fields (`hosts`, `user`, `database`, +...) and made by `of_string`. Two keys can be changed after: + +```ocaml +let maintenance conninfo = + let conninfo = Postgres_eio.Conninfo.with_database conninfo "postgres" in + Postgres_eio.Conninfo.with_connect_timeout conninfo Mtime.Span.(10 * s) +``` + +`with_database` connects to another database, the empty string meaning the +user's name. `with_connect_timeout` bounds each address attempt by a span. +`to_url` writes a URL that parses back to the same connection, minus the +passwords `.pgpass` gave; it writes `connect_timeout` in whole seconds, +rounded up. diff --git a/agents/pages/guide/copy.md b/agents/pages/guide/copy.md new file mode 100644 index 0000000..b00e70c --- /dev/null +++ b/agents/pages/guide/copy.md @@ -0,0 +1,68 @@ +# COPY + +COPY moves bulk data in both directions, streamed, without holding a whole +table. It takes no parameters. + +## Rows in + +```ocaml +let load conn rows = + Postgres_eio.copy_in_rows conn ~table:"orders" ~columns:[ "id"; "total" ] + (Seq.map + (fun (id, total) -> [| Some id; Some (string_of_int total) |]) + rows) +``` + +`copy_in_rows` runs `COPY "schema"."table" ("a", "b") FROM STDIN` in text +format, escaping each row. Cells follow `columns`' order, `None` for NULL; +empty `columns` means every column, in the table's order. The sequence is +read lazily. Names are quoted as given, so `"Jobs"` is not `jobs`. + +If the producer raises, the COPY is aborted, nothing is written and the +connection stays usable; the exception propagates, and the server is sent +a fixed message, never the exception. A NUL in a name is refused before +anything is sent; a NUL in a value fails the COPY, the connection still +usable. + +## Rows out + +`copy_out_rows` streams a select the other way: + +```ocaml +let sum conn = + Postgres_eio.copy_out_rows conn ~select:"select total from orders" ~init:0 + ~row:(fun sum row -> + match row with + | [| Some total |] -> + sum + Option.value ~default:0 (Postgres_eio.Text.to_int total) + | _ -> sum) +``` + +It runs `COPY (select) TO STDOUT` and decodes each row for `row`, `None` +for NULL, like `query`, for a very large result. + +## Bytes in and out + +`copy_in` and `copy_out` run a COPY statement of your own, in its own +format, CSV say, and move its bytes unchanged: + +```ocaml +let import conn source = + Postgres_eio.copy_in conn + "copy orders (id, total) from stdin with (format csv, header)" source +``` + +```ocaml +let export conn sink = + Postgres_eio.copy_out conn "copy orders to stdout with (format csv)" ~init:() + ~chunk:(fun () data -> Eio.Flow.copy_string data sink) +``` + +`copy_in` streams an Eio source, and `copy_out` folds each chunk into +`chunk` as it arrives. Any other statement is refused, after it has run. +If `chunk` raises, the connection is closed, the statement cancelled at +the server, and the exception propagates. A cancellation of `copy_in` +closes the connection. + +A COPY given to `query` or `script` is refused, and the connection stays +usable. diff --git a/agents/pages/guide/errors.md b/agents/pages/guide/errors.md new file mode 100644 index 0000000..9fe2b87 --- /dev/null +++ b/agents/pages/guide/errors.md @@ -0,0 +1,122 @@ +# Errors + +Every failure is a value. Driver errors and logs never contain parameters, +passwords, sign-in exchanges or message bytes; a server's error is in its +own words, which can quote a value that failed its cast. + +## What failed + +Every failure is a polymorphic variant, so a connection's failures join a +pool's and your own in one result: + +| | | +|---|---| +| `` `Server e `` | the server refused, and said why (`Server_error`) | +| `` `Refused m `` | the driver refused: an unsafe sign-in, an untrusted certificate, a value it cannot send | +| `` `Lost m `` | sent, and no answer came back -- a timeout, a broken socket; the statement may have run, so it is not run again blindly | +| `` `Unsent m `` | connecting failed before anything was sent; connecting again is safe | +| `` `Connection `Closed `` | the connection was closed before the statement was sent | + +Each one says what to do next, so a program matches the ones it handles: + +```ocaml +type outcome = Added | Taken | Unknown | Not_sent | Failed of string + +let add_customer conn ~email = + match + Postgres_eio.execute conn "insert into customers (email) values ($1)" + ~params:[ Some email ] + with + | Ok (_ : Postgres_eio.Tag.t) -> Added + | Error (`Server e) + when String.equal (Postgres_eio.Server_error.sqlstate e) "23505" -> + Taken + | Error (`Lost _) -> Unknown + | Error (`Unsent _ | `Connection `Closed) -> Not_sent + | Error ((`Server _ | `Refused _) as e) -> + Failed (Postgres_eio.error_to_string e) +``` + +`error_to_string` prints any of them as a sentence safe to log. + +## Which close the connection + +A server's error keeps the connection, since the server marks where its +answer ends, and the next statement runs as usual. A failure that leaves +the two sides out of step closes it: a timeout, a broken socket or TLS, or +bytes that break the protocol, and its statement answers `` `Lost ``. An +exception from a `row` function closes it too, and propagates. Every +statement after it answers `` `Connection `Closed `` until `revive` connects again with the same +string and parameters. A pool makes a closed connection again by itself at +its next lend. + +On a timeout, a cancellation, or an exception from a callback, the running +statement is first cancelled at the server, as `cancel` does; the request +is given 5 s, or the connection's timeout if that is shorter. + +## The server's error + +`` `Server e `` holds every field the server sent: + +```ocaml +let explain e = + let constraint_name = + match Postgres_eio.Server_error.constraint_name e with + | Some name -> " (" ^ name ^ ")" + | None -> "" + in + Postgres_eio.Server_error.sqlstate e + ^ ": " + ^ Postgres_eio.Server_error.message e + ^ constraint_name +``` + +| | | +|---|---| +| `Server_error.sqlstate` | the five-character SQLSTATE, e.g. `23505`, a unique violation | +| `Server_error.message` | the primary message, in the server's `lc_messages` | +| `Server_error.detail` | a secondary message, which may quote the row a write was refused for | +| `Server_error.hint` | what the server suggests doing about it | +| `Server_error.constraint_name` | the constraint that refused a write, where one did | +| `Server_error.severity` | `Error`, `Fatal`, which ends the session, `Panic`, which ends every session, ... | +| `Server_error.field` | any field by its code byte: `'R'` is the routine that raised it | + +`Server_error.to_string` writes `ERROR 23505: duplicate key value violates +unique constraint ...`. It leaves out the detail, which quotes the refused +row; a message of class 22 still quotes the value that failed its cast. + +The server's notices are logged on the `postgres-eio` log source, each at +its own level. + +## Joining failures + +A borrow from a pool answers the pool's failures around what the +connection answered; `Result.join` makes them one result, and the +program's own tags join them too: + +```ocaml +let email pool ~customer = + match + Postgres_eio.Pool.use pool (fun conn -> + Postgres_eio.query conn "select email from customers where id = $1" + ~params:[ Some customer ] ~init:None ~row:(fun _ row -> + match row with [| Some email |] -> Some email | _ -> None)) + |> Result.join + with + | Ok (Some email, _tag) -> Ok email + | Ok (None, _tag) -> Error `Not_found + | Error e -> Error e + +let error_to_string = function + | `Not_found -> "no such customer" + | (#Postgres_eio.error | #Postgres_eio.Pool.error) as e -> + Postgres_eio.Pool.error_to_string e +``` + +`Pool.error_to_string` prints a pool's failures and a connection's alike. + +## Exceptions + +Only the program's own exceptions pass through: one raised by a callback +(a `row` function, a COPY source) and Eio's cancellation propagate as they +came. Every failure of the driver's own is a value. diff --git a/agents/pages/guide/listen-notify.md b/agents/pages/guide/listen-notify.md new file mode 100644 index 0000000..9aef4ba --- /dev/null +++ b/agents/pages/guide/listen-notify.md @@ -0,0 +1,98 @@ +# LISTEN/NOTIFY + +A notification is a message a session sends on a channel, delivered to +every session listening on it when the transaction commits. + +## Listening + +```ocaml +let handle payload = print_endline ("order " ^ payload) +let reload () = print_endline "reloading every order" + +let rec follow listener = + match Postgres_eio.Listener.next listener with + | Ok (Notification { payload; _ }) -> + handle payload; + follow listener + | Ok Reconnected -> + reload (); + follow listener + | Error e -> Error e +``` + +A `Listener` is its own connection. It detects a dead server by pinging +it after `keep_alive` (10 s) of silence, reconnects with backoff and listens again, and returns +`Reconnected` because notifications sent meanwhile are lost. `next` can +be raced against a timer, however short its tick: a cancelled wait keeps +the connection and loses nothing, and the ping still comes. + +A program connects a listener, listens on a channel and waits: + +```ocaml +let () = + Eio_main.run @@ fun env -> + Eio.Switch.run @@ fun sw -> + let net = Eio.Stdenv.net env and mono_clock = Eio.Stdenv.mono_clock env in + match Postgres_eio.Conninfo.of_string "postgres://app@localhost/shop" with + | Error e -> prerr_endline e + | Ok conninfo -> ( + match Postgres_eio.Listener.connect ~sw ~net ~mono_clock conninfo with + | Error e -> prerr_endline (Postgres_eio.error_to_string e) + | Ok listener -> + (match Postgres_eio.Listener.listen listener "orders" with + | Error e -> prerr_endline (Postgres_eio.error_to_string e) + | Ok () -> ( + match Postgres_eio.Listener.next listener with + | Ok (Notification { payload; _ }) -> print_endline payload + | Ok Reconnected -> print_endline "reconnected" + | Error e -> prerr_endline (Postgres_eio.error_to_string e))); + Postgres_eio.Listener.close listener) +``` + +`Listener.connect` takes `connect`'s options and `~keep_alive`. +`Listener.listen` quotes the channel: `"Jobs"` hears +`pg_notify('Jobs', ...)`, not an unquoted `NOTIFY Jobs`, which Postgres +folds to `jobs`. `Listener.unlisten` stops one, which is then not listened +to again on reconnect. Notifications arrive in order, each with its +channel, its payload and the `pid` of the session that sent it. + +## Reconnecting + +`next` notices a dead server within `keep_alive` and the connection's +`timeout`, with no fiber in the background. It reconnects at once, then +with backoff from 1 s to 30 s, logging each failure as a `warn`, and +answers `Reconnected`: re-read any state the notifications kept current. A +server that is starting up, which answers with an error of class 57P, is +retried as a failed connection is; any other refusal, of the sign-in or of +`LISTEN`, is returned as an error. After `Listener.close`, `next` answers +`` `Connection `Closed ``. + +## A timer + +```ocaml +let next_within ~clock listener = + Eio.Time.Timeout.run + (Eio.Time.Timeout.v clock Mtime.Span.(1 * s)) + (fun () -> Postgres_eio.Listener.next listener) +``` + +A tick shorter than `keep_alive` does not put the ping off, and a ping +under way when the wait is cancelled is finished first, within the +timeout. + +## Notifying + +```ocaml +let order_placed conn ~id = Postgres_eio.notify conn ~channel:"orders" id +``` + +`notify` runs `select pg_notify(channel, payload)` on any connection. It is +delivered on commit, not on rollback. The channel is case-sensitive, and a +payload of 8000 bytes or more is refused before it is sent. + +## Limits + +A listener that stops reading fills the server's notification queue, after +which every NOTIFY in the database fails. For many subjects, listen on one +channel and route by payload. A pooled connection never listens. LISTEN +does not work through pgbouncer in transaction mode. diff --git a/agents/pages/guide/performance.md b/agents/pages/guide/performance.md new file mode 100644 index 0000000..dba7202 --- /dev/null +++ b/agents/pages/guide/performance.md @@ -0,0 +1,17 @@ +# Performance + +Median time per operation, lower is better, beside `postgres_async`, a +native OCaml driver on Async, and libpq, the C library, through the +`postgresql` bindings. + +| | postgres-eio | postgres_async | libpq | +|---|--:|--:|--:| +| Round trip, `select $1::int` | 329 µs | 582 µs | 287 µs | +| Insert, one round trip each | 337 µs | 594 µs | 296 µs | +| Insert, 1,000 pipelined in one round trip | 5.0 µs | n/a | n/a | +| Read a 100,000-row result, per row | 138 ns | 142 ns | 169 ns | +| Client CPU per round trip | 41 µs | 51 µs | 21 µs | + +Measured with postgres-eio 0.1.0, postgres_async 0.17.0, postgresql 5.4.0. Apple M4 Pro, +Postgres 18.6 in Docker, one connection per driver, text results, median of +three 5 s runs. diff --git a/agents/pages/guide/pipelining.md b/agents/pages/guide/pipelining.md new file mode 100644 index 0000000..c5e089b --- /dev/null +++ b/agents/pages/guide/pipelining.md @@ -0,0 +1,77 @@ +# Pipelining and batches + +A statement normally waits for its answer before the next is sent. A +pipeline sends many and reads their answers after, in one round trip. + +## A pipeline + +```ocaml +let totals conn ids = + let answers = + List.map + (fun id -> + Postgres_eio.Pipeline.query conn + "select total from orders where id = $1" ~params:[ Some id ] ~init:[] + ~row:(fun acc row -> row :: acc)) + ids + in + List.map Postgres_eio.Pipeline.get answers +``` + +`Pipeline.query` and `Pipeline.execute` queue a statement, as `query` and +`execute` run one, and answer a handle to its answer. Nothing is sent until +an answer is asked for; then `Pipeline.get` sends everything queued and +reads answers up to the one asked for, writing while it reads, so no +pipeline is too long. + +```ocaml +let ship conn ids = + List.map + (fun id -> + Postgres_eio.Pipeline.execute conn + "update orders set shipped = true where id = $1" ~params:[ Some id ]) + ids + |> List.map Postgres_eio.Pipeline.get +``` + +Each statement gets its own Sync, so it behaves as if sent alone: a +failure does not stop the next, and inside `begin` and `commit` a failure +aborts the transaction as usual. Answers are read in the order the +statements were sent, across `query`, the pipeline, `execute_many` and +`script`. + +## Draining + +```ocaml +let still_in_transaction conn = + Postgres_eio.Pipeline.drain conn + |> Result.map (fun () -> + match Postgres_eio.status conn with + | Idle -> false + | In_transaction | Failed -> true) +``` + +`Pipeline.drain` sends everything and reads every answer still owed, so +`status` is current. It fails only if the connection failed; a statement's +error stays in its answer. `Pipeline.flush` sends everything without +reading, and whoever reads next gets the answers; it is for a few +statements only, since a pipeline long enough to fill the server's output +buffer stalls until the timeout. + +## A batch + +`execute_many` runs one statement over many parameter lists in one round +trip and one transaction: + +```ocaml +let add_orders conn orders = + Postgres_eio.execute_many conn + "insert into orders (id, total) values ($1, $2)" + ~params: + (List.map + (fun (id, total) -> [ Some id; Some (Postgres_eio.Text.int total) ]) + orders) +``` + +If any run fails, none apply. It answers each run's tag, and discards any +rows. diff --git a/agents/pages/guide/pool.md b/agents/pages/guide/pool.md new file mode 100644 index 0000000..3829342 --- /dev/null +++ b/agents/pages/guide/pool.md @@ -0,0 +1,136 @@ +# Pool + +A pool keeps a fixed number of connections and lends one to each borrower +in turn. All connections open at startup, so a bad configuration fails at +once. A returned connection is reset (open transaction, settings, temporary +tables, locks, `LISTEN`), and the reset costs the next borrower no round +trip. One pool serves borrowers on every domain, and bounds a reconnect's +name lookup by `connect_timeout` on each of them. + +## Making one + +```ocaml +let () = + Eio_main.run @@ fun env -> + Eio.Switch.run @@ fun sw -> + match Postgres_eio.Conninfo.of_string "postgres://app@localhost/shop" with + | Error e -> prerr_endline e + | Ok conninfo -> ( + match + Postgres_eio.Pool.create ~sw ~net:(Eio.Stdenv.net env) + ~mono_clock:(Eio.Stdenv.mono_clock env) + ~size:16 + ~wait:Mtime.Span.(500 * ms) + conninfo + with + | Error e -> prerr_endline (Postgres_eio.error_to_string e) + | Ok pool -> + let stats = Postgres_eio.Pool.stats pool in + Printf.printf "%d connections, %d idle\n" stats.size stats.idle; + Postgres_eio.Pool.close pool) +``` + +`Pool.create` opens every connection as `connect` does, or answers the first +error after closing those already open. It takes `connect`'s options, and +these of its own: + +| Option | Default | | +|---|---|---| +| `~size` | 8 | connections, all opened at startup, and at least one | +| `~wait` | 5 s | how long a borrow waits for a connection to come free | +| `~reset` | `true` | whether a returned connection loses its session state | +| `~max_lifetime` | 30 min, ±10% | a connection older is replaced | +| `~idle_check` | 60 s | a connection idle longer is pinged | + +## Borrowing + +```ocaml +let count pool = + Postgres_eio.Pool.use pool (fun conn -> + Postgres_eio.query conn "select count(*) from orders" ~params:[] + ~init:None ~row:(fun _ row -> + match row with + | [| Some n |] -> Postgres_eio.Text.to_int n + | _ -> None)) +``` + +`Pool.use` returns `` `Pool `Busy `` if no connection frees up within +its `wait` (5 s, or `~wait:Mtime.Span.(500 * ms)`), and `` `Pool `Closed `` at once after `Pool.close`; +`Pool.error_to_string` prints either, and a connection's errors +too, so `Result.join (Pool.use pool f)` is printed by one function. Cancelling a borrower stops it at +once, wherever it waits: its statement is cancelled at the server, so the +transaction rolls back, and its connection is closed and made again at the +next lend. + +`f` runs on the calling fiber, and the connection goes back even if `f` +raises. Pipelined answers left unread are read when the borrow ends. +A wait over 100 ms and a borrow held over 250 ms log a `warn` on the +`postgres-eio.pool` log source. + +## A transaction + +A transaction is `begin` and `commit` on one borrowed connection: + +```ocaml +(* A failure returns before the commit; the transaction left open is rolled + back when the connection goes back. *) +let transfer pool ~from ~into ~amount = + Postgres_eio.Pool.use pool (fun conn -> + let ( let* ) = Result.bind in + let amount = Postgres_eio.Text.int amount in + let* (_ : Postgres_eio.Tag.t) = + Postgres_eio.execute conn "begin" ~params:[] + in + let* (_ : Postgres_eio.Tag.t) = + Postgres_eio.execute conn + "update accounts set balance = balance - $1 where id = $2" + ~params:[ Some amount; Some from ] + in + let* (_ : Postgres_eio.Tag.t) = + Postgres_eio.execute conn + "update accounts set balance = balance + $1 where id = $2" + ~params:[ Some amount; Some into ] + in + Postgres_eio.execute conn "commit" ~params:[]) + |> Result.join +``` + +## A clean connection + +Every lend is clean: no open transaction, no `LISTEN`, the connection's +original timeout, and none of a previous borrower's session state. The +reset sent at give-back is `DISCARD ALL` but for prepared statements and +plans, which every borrower shares through the statement cache: +`set session authorization default`, `select pg_advisory_unlock_all()`, +`close all`, `unlisten *`, `reset all`, `discard temp` and +`discard sequences`. It is sent and not waited for; the next lend reads +its answer, usually already arrived, and makes the connection again if the +session died meanwhile. + +`~reset:false` keeps session state between borrowers, except that an open +transaction is still rolled back and `LISTEN` still ended: a pooled +connection never listens. A [listener](listen-notify.md) +is a connection of its own. + +## Housekeeping + +A fiber on the pool's switch checks idle connections a few times per the +shorter of `idle_check` and `max_lifetime`. A connection past +`max_lifetime` is replaced, the new one connected before the old one is +removed. A connection idle past `idle_check` is pinged with an empty query, +while another is idle, and replaced if the ping fails. A borrowed +connection is never touched. + +```ocaml +let healthy pool = + let stats = Postgres_eio.Pool.stats pool in + stats.idle > 0 || stats.waiting = 0 +``` + +`Pool.stats` answers the pool's `size`, how many of its connections are +`idle`, how many borrows are `waiting`, and how many connections +housekeeping has `replaced`, for a health check. + +`Pool.close` closes idle connections at once and borrowed ones when they +come back, never under a running transaction. A borrow waiting, and every +one after, answers `` `Pool `Closed ``. diff --git a/agents/pages/guide/queries.md b/agents/pages/guide/queries.md new file mode 100644 index 0000000..c0fea06 --- /dev/null +++ b/agents/pages/guide/queries.md @@ -0,0 +1,189 @@ +# Queries and values + +A statement is SQL with `$1`, `$2`, ... for its parameters. `query` folds +its rows, `execute` runs it for its effect, and both answer the statement's +tag. + +## Parameters and rows + +Parameters are sent as text, `None` for NULL, and a cell comes back as +text, `None` for NULL. `Text` writes an OCaml value as Postgres reads it +and reads back what Postgres writes: + +```ocaml +type order = { id : int; total : int; placed_at : Ptime.t } + +let recent conn ~since ~limit = + Postgres_eio.query conn + "select id, total, placed_at from orders where placed_at >= $1 order by \ + placed_at limit $2" + ~params: + [ + Some (Postgres_eio.Text.timestamptz since); + Some (Postgres_eio.Text.int limit); + ] + ~init:[] + ~row:(fun orders row -> + match row with + | [| Some id; Some total; Some placed_at |] -> ( + match + ( Postgres_eio.Text.to_int id, + Postgres_eio.Text.to_int total, + Postgres_eio.Text.to_timestamptz placed_at ) + with + | Some id, Some total, Some placed_at -> + { id; total; placed_at } :: orders + | _ -> orders) + | _ -> orders) + |> Result.map (fun (orders, _tag) -> List.rev orders) +``` + +Rows are folded as they arrive and never buffered. If `row` raises, the +connection is closed, the statement cancelled at the server, and the +exception propagates. + +`columns`, when given, is called once before any row, even with no rows, +with each column's name, type and format. + +NULL is `None`, as a parameter too: + +```ocaml +let forget_phone conn ~customer = + Postgres_eio.execute conn "update customers set phone = $1 where id = $2" + ~params:[ None; Some customer ] +``` + +`execute` discards any rows the statement returns. `script` runs one or +more statements without parameters, by the simple protocol, discarding +their rows: `script conn "create table t (id int); create index on t +(id)"`. + +## Text + +Each encoder writes what Postgres reads, and each decoder answers `None` on +a form it does not read. + +| Type | Write | Read | +|---|---|---| +| integers | `Text.int`, `Text.int64` | `Text.to_int`, `Text.to_int64` | +| `float8` | `Text.float`, 17 digits, so a double round-trips | `Text.to_float` | +| `bool` | `Text.bool` | `Text.to_bool` | +| `bytea` | `Text.bytes`, the hex form | `Value.bytes` | +| `timestamptz` | `Text.timestamptz`, in UTC, to the microsecond | `Text.to_timestamptz` | +| `timestamp` | `Text.timestamp`, the reading in UTC | `Value.timestamp` | +| `date` | `Text.date` | `Text.to_date` | +| `interval` | `Text.interval` | `Text.to_interval` | + +An instant is a `Ptime.t`, a date a `Ptime.date`. A BC date, a year past +9999 and `infinity` read as `None`. An `Interval.t` keeps months, days and +microseconds apart, as Postgres does, since a month is no fixed number of +days and a day, across a change of clocks, no fixed number of hours. + +## Session settings + +Every connection sets the session settings the decoders read text by, over +the database's and the role's defaults: `client_encoding=UTF8`, +`DateStyle=ISO`, `IntervalStyle=postgres` and `extra_float_digits=3`. Text +is UTF-8 in a `LATIN1` database too, and a float reads back to its last +digit. A parameter or an `options` setting that changes one of them is +refused. + +Other settings are startup parameters, given to `connect` as +`~parameters:[ ("statement_timeout", "10s") ]` or in the string's +`options`. They are sent again whenever the connection is made again, so +they last for its life. + +## Text and binary results + +`~binary:true` asks for the binary form of the types `Value` reads, and +text for the rest. `Value`'s decoders read a cell in either form, by its +column, so the same code reads both: + +```ocaml +let placed conn = + let columns = ref [||] in + Postgres_eio.query conn ~binary:true + ~columns:(fun c -> columns := c) + "select total, placed_at from orders" ~params:[] ~init:[] + ~row:(fun placed row -> + match (!columns, row) with + | [| total_column; at_column |], [| Some total; Some at |] -> ( + match + ( Postgres_eio.Value.int total_column total, + Postgres_eio.Value.timestamptz at_column at ) + with + | Some total, Some at -> (total, at) :: placed + | _ -> placed) + | _ -> placed) +``` + +`Value` reads `bool`, `bytea`, `int2`, `int4`, `int8`, `oid`, `text`, +`varchar`, `json`, `jsonb`, `float4`, `float8`, `date`, `timestamp`, +`timestamptz`, `interval` and `uuid`. A type with no reader -- `numeric`, +`time`, a range, `inet` -- is always sent as text, and a decoder reads it +if its text is that decoder's form: `Value.int` reads a `numeric` of `42`. +`Value.text` hands a cell over as text, converting a binary one only for +types whose text depends on no setting. + +Binary needs the columns' types before the statement is bound, which costs +one extra round trip on a statement's first run, and is refused when the +statement cache is off. + +## The statement cache + +A statement is parsed once: its first run sends Parse with the run, at no +extra round trip, and later runs only bind. The cache keeps 256 statements +by their SQL text, the least recently used dropped first; `connect`'s +`~statement_cache` changes the number. If a statement's result type +changed, because its table was altered, it is parsed again and retried +once outside a transaction; inside one, the error is returned. +`DISCARD ALL` or `DEALLOCATE` empties the cache. + +`~statement_cache:0` turns it off, for a pooler without named statements: +pgbouncer before 1.21 in transaction mode. + +## Describing a statement + +`describe` answers a statement's parameter types and result columns +without running it: + +```ocaml +let columns_of conn sql = + Postgres_eio.describe conn sql + |> Result.map (fun (d : Postgres_eio.description) -> + Array.to_list + (Array.map (fun (c : Postgres_eio.Column.t) -> c.name) d.columns)) +``` + +A column is its `name`, its `type_oid`, the row of `pg_type` that is its +type, and its `format`, text or binary. + +## Tags, the session and timeouts + +A statement's tag says what it did: `Tag.command` is `INSERT`, `UPDATE`, +`COMMIT`, ..., and `Tag.rows` the rows changed or returned. After `COMMIT`, +check the command: in an aborted transaction the server answers +`ROLLBACK`. + +```ocaml +let server_version conn = Postgres_eio.parameter conn "server_version" + +let in_transaction conn = + match Postgres_eio.status conn with + | Idle -> false + | In_transaction | Failed -> true +``` + +`parameter` answers the latest value of a setting the server reports, such +as `server_version`, `TimeZone` or `DateStyle`. `status` answers whether the +connection is in a transaction, as of the last answer read. + +`connect`'s `~timeout` (30 s) is the longest the connection waits on the +server for bytes to move, in either direction; the program's own `row` +function is not timed. For work that waits longer, a migration say, +`set_timeout conn ~timeout:None` lifts it. Bound how long a statement runs +with `statement_timeout`. `cancel`, from another fiber, asks the server to +cancel the running statement, which then fails with SQLSTATE 57014. + +A connection is used from one fiber at a time, which may be on any domain; +only `cancel` may be called from another. diff --git a/agents/pages/guide/several-hosts.md b/agents/pages/guide/several-hosts.md new file mode 100644 index 0000000..b779584 --- /dev/null +++ b/agents/pages/guide/several-hosts.md @@ -0,0 +1,84 @@ +# Several hosts + +A connection string can name several hosts, comma-separated, each with its +port or one port for all: `host=a,b port=1,2`, or `postgres://a:1,b:2/`. +The driver tries each address of each host in turn until one answers and +is what `target_session_attrs` asks for, so a connection fails over to the +next host when one is down. + +``` +postgres://app@db1.internal,db2.internal,db3.internal/shop?target_session_attrs=read-write +host=db2.internal,db3.internal user=app dbname=shop target_session_attrs=prefer-standby load_balance_hosts=random +``` + +The first connects to whichever host is the primary now; the second +spreads its connections over the standbys. + +## Failover + +Each host's name is looked up, and each of its addresses tried, bounded by +`connect_timeout` if it is not zero, else by the connection's `timeout`. A +host that does not answer, or is not the kind asked for, is passed over +for the next. When none is left, the connection fails with the last +reason. + +`target_session_attrs` says which kind of host will do: + +| Value | A host that is | +|---|---| +| `any` | any -- the default | +| `read-write` | not a standby, and not `default_transaction_read_only` | +| `read-only` | a standby, or `default_transaction_read_only` | +| `primary` | not a standby | +| `standby` | a standby | +| `prefer-standby` | a standby if any answers, else any host | + +The driver tells them apart by the settings the server reports as it +starts a session, `in_hot_standby` and `default_transaction_read_only`, at +no extra round trip. Postgres 14 and later report both; an older server is +refused for any value but `any` and `prefer-standby`, since it does not say +what it is. + +## Load balancing + +`load_balance_hosts=random` shuffles the hosts, and each host's addresses, +for every connection, so clients spread over them instead of all trying +the first. `disable`, the default, keeps the order given. + +## A pool over several hosts + +A pool makes its connections from the same string, so each one fails over +on its own, and one made again after a host went down finds the next. +Writes and reads can go to pools of their own: + +```ocaml +(* Writes go to whichever host is the primary now, and reads are spread + over the standbys. *) +let primary = + "postgres://app@db1.internal,db2.internal,db3.internal/shop?target_session_attrs=read-write" + +let standbys = + "host=db2.internal,db3.internal user=app dbname=shop \ + target_session_attrs=prefer-standby load_balance_hosts=random" + +let open_pool ~sw env url = + match Postgres_eio.Conninfo.of_string url with + | Error e -> Error e + | Ok conninfo -> + Postgres_eio.Pool.create ~sw ~net:(Eio.Stdenv.net env) + ~mono_clock:(Eio.Stdenv.mono_clock env) + conninfo + |> Result.map_error Postgres_eio.error_to_string + +let () = + Eio_main.run @@ fun env -> + Eio.Switch.run @@ fun sw -> + match (open_pool ~sw env primary, open_pool ~sw env standbys) with + | Ok writes, Ok reads -> + Postgres_eio.Pool.close writes; + Postgres_eio.Pool.close reads + | Error e, _ | _, Error e -> prerr_endline e +``` + +A connection's `revive`, and a pool's lend of a connection that was +closed, connect again by the same search. diff --git a/agents/pages/guide/tls.md b/agents/pages/guide/tls.md new file mode 100644 index 0000000..2bc349e --- /dev/null +++ b/agents/pages/guide/tls.md @@ -0,0 +1,101 @@ +# TLS and signing in + +A connection for production checks the server's certificate, names the +ways it may sign in, and refuses before sending a secret when the server +asks for something else: + +```ocaml +let production = + "host=db.internal user=app dbname=shop sslmode=verify-full \ + sslrootcert=/etc/ssl/db-ca.pem channel_binding=require \ + require_auth=scram-sha-256" + +let () = + Eio_main.run @@ fun env -> + Eio.Switch.run @@ fun sw -> + match Postgres_eio.Conninfo.of_string production with + | Error e -> prerr_endline e + | Ok conninfo -> ( + match + Postgres_eio.connect ~sw ~net:(Eio.Stdenv.net env) + ~mono_clock:(Eio.Stdenv.mono_clock env) + conninfo + with + | Ok conn -> + print_endline "signed in"; + Postgres_eio.close conn + | Error (`Refused m) -> prerr_endline ("not signed in: " ^ m) + | Error e -> prerr_endline (Postgres_eio.error_to_string e)) +``` + +## sslmode + +`sslmode` means what it means to libpq. `require` encrypts and checks no +certificate, so it keeps out a listener but not a server that pretends; +`verify-ca` checks the certificate against `sslrootcert`, and +`verify-full` checks too that it names the host -- the mode for +production. With no `sslmode`, a host on this machine (`localhost`, +127.0.0.0/8, `::1`, a Unix socket) is `prefer`, and any other host is +`require`, so a connection that crosses a network is encrypted unless the +string says `sslmode=disable` or `prefer`. `sslrootcert` is refused with +any mode but `verify-full` and `verify-ca`, or with none, since nothing +else reads it: write `sslmode=verify-full` to check against the file. + +| Mode | The connection | +|---|---| +| `disable` | never TLS | +| `allow` | plain, and TLS only if the server refuses plain | +| `prefer` | TLS if the server offers it and the handshake succeeds, else plain | +| `require` | encrypted, and the server's certificate not checked | +| `verify-ca` | encrypted, and the certificate checked against `sslrootcert`, or the system's authorities when absent | +| `verify-full` | as `verify-ca`, and the certificate checked to name the host | + +The mode is decided for each host by where the connection goes: `hostaddr` +when given, else `host`. With `prefer`, a server that refuses TLS, a +handshake that fails or a sign-in that fails inside TLS is tried again +without it, as libpq does. A Unix socket never uses TLS. + +`sslnegotiation=direct` starts TLS from the first byte, with ALPN +`postgresql`, which saves a round trip. It needs `sslmode=require` or +stronger, and with no `sslmode` every host is `require`. + +## What the driver reads + +The driver reads files only from `sslrootcert`, `sslcert` and `sslkey`, and +the system's authorities only for `verify-ca` or `verify-full` with no +`sslrootcert`. What a connection reads is what its string names. + +`sslcert` is a PEM certificate chain and `sslkey` its key, unencrypted, +for a server that signs in by client certificate. + +## Signing in + +The driver signs in by SCRAM-SHA-256 (RFC 7677), bound to the TLS channel +when the server offers it, by MD5, by client certificate, by trust, or by a +cleartext password inside TLS only. A server that asks for a cleartext +password on a connection that is not encrypted is refused, and the +password is not sent. + +`channel_binding` decides what SCRAM does with the TLS channel: + +| Value | | +|---|---| +| `disable` | never bind | +| `prefer` | bind when the server offers it -- the default | +| `require` | refuse, before sending a secret, a sign-in that is not bound | + +Binding ties the sign-in to the server's certificate, so a server in the +middle that holds another certificate cannot relay it. + +`require_auth` lists the ways the server may ask for, of `password`, +`md5`, `scram-sha-256` and `none` (trust), or each negated with `!`. A +server that asks for another is refused, and nothing is sent. + +A refusal is `` `Refused ``, with a sentence saying what was refused; see +[errors](errors.md). + +## Randomness + +TLS and SCRAM draw from mirage-crypto's default random generator. One the +application set is kept, and where it set none the first connection sets +`Mirage_crypto_rng_unix.use_default`'s. diff --git a/agents/pages/index.md b/agents/pages/index.md new file mode 100644 index 0000000..4ece591 --- /dev/null +++ b/agents/pages/index.md @@ -0,0 +1,56 @@ +# Getting Started + +The Postgres driver for modern OCaml. + +postgres-eio is a Postgres driver for OCaml 5, written for Eio. A connection +that crosses a network is encrypted unless its string says otherwise, and +signs in with SCRAM-SHA-256 and channel binding. One pool serves every +domain, across several hosts, with failover. Statements are cached and +pipelined, COPY streams both ways, rows are folded as they arrive, and a +listener reconnects by itself. Each failure says whether the statement may +have run, so a retry is never blind. + +```ocaml title="main.ml" +let () = + Eio_main.run @@ fun env -> + Eio.Switch.run @@ fun sw -> + match Postgres_eio.Conninfo.of_string "postgres://app@localhost/shop" with + | Error e -> prerr_endline e + | Ok conninfo -> ( + match + Postgres_eio.connect ~sw ~net:(Eio.Stdenv.net env) + ~mono_clock:(Eio.Stdenv.mono_clock env) + conninfo + with + | Error e -> prerr_endline (Postgres_eio.error_to_string e) + | Ok conn -> + (match + 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) + with + | Ok (names, _tag) -> List.iter print_endline names + | Error e -> prerr_endline (Postgres_eio.error_to_string e)); + Postgres_eio.close conn) +``` + +## Install + +It needs opam, with a switch of OCaml 5.5 or later, and a Postgres server +to connect to. + +```sh +opam repo add open-opam https://github.com/open-opam/opam-repository.git +opam install postgres-eio eio_main +``` + +A program runs the driver inside Eio's event loop, which `eio_main` starts, +and names both in its `dune` file: + +```lisp +(libraries postgres-eio eio_main) +``` + +The [quick start](quick-start.md) connects and runs a query, +next. diff --git a/agents/pages/quick-start.md b/agents/pages/quick-start.md new file mode 100644 index 0000000..091424e --- /dev/null +++ b/agents/pages/quick-start.md @@ -0,0 +1,76 @@ +# Quick start + +A program that connects, runs one query with a parameter and prints what +it finds. Put it in `bin/main.ml`: + +```ocaml +let () = + Eio_main.run @@ fun env -> + Eio.Switch.run @@ fun sw -> + match Postgres_eio.Conninfo.of_string "postgres://app@localhost/shop" with + | Error e -> prerr_endline e + | Ok conninfo -> ( + match + Postgres_eio.connect ~sw ~net:(Eio.Stdenv.net env) + ~mono_clock:(Eio.Stdenv.mono_clock env) + conninfo + with + | Error e -> prerr_endline (Postgres_eio.error_to_string e) + | Ok conn -> + (match + 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) + with + | Ok (names, _tag) -> List.iter print_endline names + | Error e -> prerr_endline (Postgres_eio.error_to_string e)); + Postgres_eio.close conn) +``` + +and name its libraries in `bin/dune`: + +```lisp +(executable + (name main) + (libraries postgres-eio eio_main)) +``` + +Run it with `dune exec ./bin/main.exe`. It connects as `app` to the +database `shop` on this machine; the +[connection strings](guide/connection-strings.md) guide says how +to name another. + +## What it does + +`Conninfo.of_string` reads the connection string, and `connect` opens the +connection on the switch `sw`, with the network and the clock Eio hands the +program. The connection is closed when the switch ends, or earlier by +`close`. + +Parameters are `$1`, `$2`, ... with `None` for NULL. Rows are folded as they +arrive and never buffered: `row` is called once for each, with the result +so far, and its last answer is the query's, beside the statement's tag. + +Every failure is a value, so `connect` and `query` answer a `result`, and +`error_to_string` prints any of them. The [errors](guide/errors.md) +guide says what each failure means and what to do about it. + +## A statement for its effect + +A statement run for its effect needs no fold, and answers its tag: + +```ocaml +let add_order conn ~id ~total = + Postgres_eio.execute conn "insert into orders values ($1, $2)" + ~params:[ Some id; Some total ] +``` + +## Next + +- [Queries and values](guide/queries.md): parameters and cells + of every type, text and binary. +- [Pool](guide/pool.md): connections shared by a server's + fibers. +- [TLS and signing in](guide/tls.md): a connection for + production. diff --git a/agents/pages/reference.md b/agents/pages/reference.md new file mode 100644 index 0000000..1af0414 --- /dev/null +++ b/agents/pages/reference.md @@ -0,0 +1,43 @@ +# Reference + +Every module's interface, generated by odoc from its `.mli`, where each +function says what it does, what it refuses and what it defaults to. + +## The package + +| Package | Libraries | What it is | +|---|---|---| +| `postgres-eio` | `postgres-eio` | The driver: connections, the pool, connection strings, and cell values | + +A `dune` file names the library as it is installed (`postgres-eio`); OCaml +code names it as a module (`Postgres_eio`). + +## postgres-eio + +- [`Postgres_eio`](https://hyphatech.github.io/postgres-eio/reference/postgres-eio/Postgres_eio/index.html) + -- connections: connecting, statements, COPY, the session, and + notifications. Within it, + [`Pipeline`](https://hyphatech.github.io/postgres-eio/reference/postgres-eio/Postgres_eio/Pipeline/index.html), + [`Listener`](https://hyphatech.github.io/postgres-eio/reference/postgres-eio/Postgres_eio/Listener/index.html) + and [`Resolver`](https://hyphatech.github.io/postgres-eio/reference/postgres-eio/Postgres_eio/Resolver/index.html). +- [`Pool`](https://hyphatech.github.io/postgres-eio/reference/postgres-eio/Postgres_eio/Pool/index.html) + -- a fixed-size pool that lends every connection in a clean state. +- [`Conninfo`](https://hyphatech.github.io/postgres-eio/reference/postgres-eio/Postgres_eio/Conninfo/index.html) + -- connection strings, the `PG*` variables and `.pgpass`. +- [`Server_error`](https://hyphatech.github.io/postgres-eio/reference/postgres-eio/Postgres_eio/Server_error/index.html) + -- a server's error, every field of it. +- [`Tag`](https://hyphatech.github.io/postgres-eio/reference/postgres-eio/Postgres_eio/Tag/index.html) + -- a statement's command tag. + +The lower layers do no IO and can be used alone: + +- [`Text`](https://hyphatech.github.io/postgres-eio/reference/postgres-eio/Postgres_eio/Text/index.html) + -- values written as Postgres reads them, and read as it writes them. +- [`Value`](https://hyphatech.github.io/postgres-eio/reference/postgres-eio/Postgres_eio/Value/index.html) + -- cells decoded alike from text and binary results. +- [`Column`](https://hyphatech.github.io/postgres-eio/reference/postgres-eio/Postgres_eio/Column/index.html) + -- a result's column, as the server describes it. +- [`Oid`](https://hyphatech.github.io/postgres-eio/reference/postgres-eio/Postgres_eio/Oid/index.html) + -- the identifier of a type, or another row of a system catalogue. +- [`Interval`](https://hyphatech.github.io/postgres-eio/reference/postgres-eio/Postgres_eio/Interval/index.html) + -- an `interval`, its months, days and microseconds kept apart. diff --git a/docs/astro.config.mjs b/docs/astro.config.mjs index 14279b8..e155985 100644 --- a/docs/astro.config.mjs +++ b/docs/astro.config.mjs @@ -2,6 +2,7 @@ import { fileURLToPath } from "node:url"; import { defineConfig } from "astro/config"; import starlight from "@astrojs/starlight"; import links from "starlight-links-validator"; +import agents from "starlight-hypha-agents"; import hypha from "starlight-theme-hypha"; // postgres-eio's documentation site, published to GitHub Pages by @@ -37,6 +38,10 @@ export default defineConfig({ tabs: { "Start here": "rocket", Guides: "book-open", Reference: "library" }, links: [{ label: "Hypha Stack", href: "https://hyphatech.io/stack", icon: "layers" }], }), + // Each page as Markdown and llms.txt, written into agents/ + // by the build, for the postgres-eio package to install; the docs + // workflow holds it to the pages. + agents({ dir: "../agents" }), // The reference is odoc's, in public/, which the validator cannot see. links({ errorOnLocalLinks: false, diff --git a/docs/bun.lock b/docs/bun.lock index 5419e33..44c743d 100644 --- a/docs/bun.lock +++ b/docs/bun.lock @@ -7,8 +7,9 @@ "devDependencies": { "@astrojs/starlight": "~0.42.6", "astro": "^7.3.3", + "starlight-hypha-agents": "github:hyphatech/starlight-hypha-agents#v0.2.0", "starlight-links-validator": "^0.27.0", - "starlight-theme-hypha": "github:hyphatech/starlight-theme-hypha#v0.6.3", + "starlight-theme-hypha": "github:hyphatech/starlight-theme-hypha#v0.8.0", }, }, }, @@ -295,6 +296,10 @@ "@ungap/structured-clone": ["@ungap/structured-clone@1.4.0", "", {}, "sha512-1mEZtMKPM09vDmQt5y7YvmN2+DFTP7Tg0EWXdic8/C6VRnpb33e4ghisCIE3WZjsE2N8mf+QV1Zqh7ZFYLWInQ=="], + "acorn": ["acorn@8.19.0", "", { "bin": { "acorn": "bin/acorn" } }, "sha512-oJlA3XiRm7Cyk6qFD2Jn8ak9B7jSy0qy00ADO3+8dpT0LSjFihQYv4C02LFCSYJV3Q37xYwwRy5m+IpIiUzqWw=="], + + "acorn-jsx": ["acorn-jsx@5.3.2", "", { "peerDependencies": { "acorn": "^6.0.0 || ^7.0.0 || ^8.0.0" } }, "sha512-rq9s+JNhf0IChjtDXxllJ7g41oZk5SlXtp0LHwyA5cejwn7vKmKp4pPri6YEePv2PU65sAsegbXtIinmDFDXgQ=="], + "am-i-vibing": ["am-i-vibing@0.5.0", "", { "dependencies": { "process-ancestry": "^0.1.0" }, "bin": { "am-i-vibing": "dist/cli.mjs" } }, "sha512-KLcsDhqf1XRrJmJr+9I/C0EX2K+sGrAGZFgkmd84c8TJO9zJBu+/kFInjazu1KfJWFhWDKdRWkpBzEs7s35DVA=="], "ansi-escapes": ["ansi-escapes@7.3.0", "", { "dependencies": { "environment": "^1.0.0" } }, "sha512-BvU8nYgGQBxcmMuEeUEmNTvrMVjJNSH7RgW24vXexN4Ven6qCvy4TntnvlnwnMLTVlcRQQdbRY8NKnaIoeWDNg=="], @@ -399,6 +404,10 @@ "es-module-lexer": ["es-module-lexer@3.0.4", "", {}, "sha512-BldNY5mwkVu+cQ5Ymn3e6hB9Sx8XHx4ZevWbiUyZbfKxJxYO27Hf0wfzkxIaD5CAJMaGl3YspKELj0ff/7nCMA=="], + "estree-util-is-identifier-name": ["estree-util-is-identifier-name@3.0.0", "", {}, "sha512-hFtqIDZTIUZ9BXLb8y4pYGyk6+wekIivNVTcmvk8NoOh+VeRn5y6cEHzbURrWbfp1fIqdVipilzj+lfaadNZmg=="], + + "estree-util-visit": ["estree-util-visit@2.0.0", "", { "dependencies": { "@types/estree-jsx": "^1.0.0", "@types/unist": "^3.0.0" } }, "sha512-m5KgiH85xAhhW8Wta0vShLcUvOsh3LLPI2YVwcbio1l7E09NTLL1EyMZFM1OyWowoH0skScNbhOPl4kcBgzTww=="], + "eventemitter3": ["eventemitter3@5.0.4", "", {}, "sha512-mlsTRyGaPBjPedk6Bvw+aqbsXDtoAyAzm5MO7JgU+yVRyMQ5O8bD4Kcci7BS85f93veegeCPkL8R4GLClnjLFw=="], "expressive-code": ["expressive-code@0.44.3", "", { "dependencies": { "@expressive-code/core": "^0.44.3", "@expressive-code/plugin-frames": "^0.44.3", "@expressive-code/plugin-shiki": "^0.44.3", "@expressive-code/plugin-text-markers": "^0.44.3" } }, "sha512-7RGslhJTNt01pdn5I3QmVh5C8ZIiSm0A+ORQ9j9r39oOgJVKjn/7dXl9rMT/SqmFLE6pJkTYI7UjW0BxJnW7OQ=="], @@ -535,8 +544,14 @@ "mdast-util-from-markdown": ["mdast-util-from-markdown@2.1.0", "", { "dependencies": { "@types/mdast": "^4.0.0", "@types/unist": "^3.0.0", "decode-named-character-reference": "^1.0.0", "devlop": "^1.0.0", "mdast-util-to-string": "^4.0.0", "micromark": "^4.0.0", "micromark-util-decode-numeric-character-reference": "^2.0.0", "micromark-util-decode-string": "^2.0.0", "micromark-util-normalize-identifier": "^2.0.0", "micromark-util-symbol": "^2.0.0", "micromark-util-types": "^2.0.0", "unist-util-stringify-position": "^4.0.0" } }, "sha512-KRLgmPaP2H1ul2bpoJkOS+9pAcDAAj9Nu1mqLnh8NLeJG5tlvj42TH80PIGBpROWlRXLk0lDrWNuZCFy/tsB4A=="], + "mdast-util-mdx": ["mdast-util-mdx@3.0.0", "", { "dependencies": { "mdast-util-from-markdown": "^2.0.0", "mdast-util-mdx-expression": "^2.0.0", "mdast-util-mdx-jsx": "^3.0.0", "mdast-util-mdxjs-esm": "^2.0.0", "mdast-util-to-markdown": "^2.0.0" } }, "sha512-JfbYLAW7XnYTTbUsmpu0kdBUVe+yKVJZBItEjwyYJiDJuZ9w4eeaqks4HQO+R7objWgS2ymV60GYpI14Ug554w=="], + + "mdast-util-mdx-expression": ["mdast-util-mdx-expression@2.0.1", "", { "dependencies": { "@types/estree-jsx": "^1.0.0", "@types/hast": "^3.0.0", "@types/mdast": "^4.0.0", "devlop": "^1.0.0", "mdast-util-from-markdown": "^2.0.0", "mdast-util-to-markdown": "^2.0.0" } }, "sha512-J6f+9hUp+ldTZqKRSg7Vw5V6MqjATc+3E4gf3CFNcuZNWD8XdyI6zQ8GqH7f8169MM6P7hMBRDVGnn7oHB9kXQ=="], + "mdast-util-mdx-jsx": ["mdast-util-mdx-jsx@3.2.0", "", { "dependencies": { "@types/estree-jsx": "^1.0.0", "@types/hast": "^3.0.0", "@types/mdast": "^4.0.0", "@types/unist": "^3.0.0", "ccount": "^2.0.0", "devlop": "^1.1.0", "mdast-util-from-markdown": "^2.0.0", "mdast-util-to-markdown": "^2.0.0", "parse-entities": "^4.0.0", "stringify-entities": "^4.0.0", "unist-util-stringify-position": "^4.0.0", "vfile-message": "^4.0.0" } }, "sha512-lj/z8v0r6ZtsN/cGNNtemmmfoLAFZnjMbNyLzBafjzikOM+glrjNHPlf6lQDOTccj9n5b0PPihEBbhneMyGs1Q=="], + "mdast-util-mdxjs-esm": ["mdast-util-mdxjs-esm@2.0.1", "", { "dependencies": { "@types/estree-jsx": "^1.0.0", "@types/hast": "^3.0.0", "@types/mdast": "^4.0.0", "devlop": "^1.0.0", "mdast-util-from-markdown": "^2.0.0", "mdast-util-to-markdown": "^2.0.0" } }, "sha512-EcmOpxsZ96CvlP03NghtH1EsLtr0n9Tm4lPUJUBccV9RwUOneqSycg19n5HGzCf+10LozMRSObtVr3ee1WoHtg=="], + "mdast-util-phrasing": ["mdast-util-phrasing@4.1.0", "", { "dependencies": { "@types/mdast": "^4.0.0", "unist-util-is": "^6.0.0" } }, "sha512-TqICwyvJJpBwvGAMZjj4J2n0X8QWp21b9l0o7eXyVJ25YNWYbJDVIyD1bZXE6WtV6RmKJVYmQAKWa0zWOABz2w=="], "mdast-util-to-hast": ["mdast-util-to-hast@13.2.1", "", { "dependencies": { "@types/hast": "^3.0.0", "@types/mdast": "^4.0.0", "@ungap/structured-clone": "^1.0.0", "devlop": "^1.0.0", "micromark-util-sanitize-uri": "^2.0.0", "trim-lines": "^3.0.0", "unist-util-position": "^5.0.0", "unist-util-visit": "^5.0.0", "vfile": "^6.0.0" } }, "sha512-cctsq2wp5vTsLIcaymblUriiTcZd0CwWtCbLvrOzYCDZoWyMNV8sZ7krj09FSnsiJi3WVsHLM4k6Dq/yaPyCXA=="], @@ -553,10 +568,22 @@ "micromark-extension-directive": ["micromark-extension-directive@4.0.0", "", { "dependencies": { "devlop": "^1.0.0", "micromark-factory-space": "^2.0.0", "micromark-factory-whitespace": "^2.0.0", "micromark-util-character": "^2.0.0", "micromark-util-symbol": "^2.0.0", "micromark-util-types": "^2.0.0", "parse-entities": "^4.0.0" } }, "sha512-/C2nqVmXXmiseSSuCdItCMho7ybwwop6RrrRPk0KbOHW21JKoCldC+8rFOaundDoRBUWBnJJcxeA/Kvi34WQXg=="], + "micromark-extension-mdx-expression": ["micromark-extension-mdx-expression@3.0.1", "", { "dependencies": { "@types/estree": "^1.0.0", "devlop": "^1.0.0", "micromark-factory-mdx-expression": "^2.0.0", "micromark-factory-space": "^2.0.0", "micromark-util-character": "^2.0.0", "micromark-util-events-to-acorn": "^2.0.0", "micromark-util-symbol": "^2.0.0", "micromark-util-types": "^2.0.0" } }, "sha512-dD/ADLJ1AeMvSAKBwO22zG22N4ybhe7kFIZ3LsDI0GlsNr2A3KYxb0LdC1u5rj4Nw+CHKY0RVdnHX8vj8ejm4Q=="], + + "micromark-extension-mdx-jsx": ["micromark-extension-mdx-jsx@3.0.2", "", { "dependencies": { "@types/estree": "^1.0.0", "devlop": "^1.0.0", "estree-util-is-identifier-name": "^3.0.0", "micromark-factory-mdx-expression": "^2.0.0", "micromark-factory-space": "^2.0.0", "micromark-util-character": "^2.0.0", "micromark-util-events-to-acorn": "^2.0.0", "micromark-util-symbol": "^2.0.0", "micromark-util-types": "^2.0.0", "vfile-message": "^4.0.0" } }, "sha512-e5+q1DjMh62LZAJOnDraSSbDMvGJ8x3cbjygy2qFEi7HCeUT4BDKCvMozPozcD6WmOt6sVvYDNBKhFSz3kjOVQ=="], + + "micromark-extension-mdx-md": ["micromark-extension-mdx-md@2.0.0", "", { "dependencies": { "micromark-util-types": "^2.0.0" } }, "sha512-EpAiszsB3blw4Rpba7xTOUptcFeBFi+6PY8VnJ2hhimH+vCQDirWgsMpz7w1XcZE7LVrSAUGb9VJpG9ghlYvYQ=="], + + "micromark-extension-mdxjs": ["micromark-extension-mdxjs@3.0.0", "", { "dependencies": { "acorn": "^8.0.0", "acorn-jsx": "^5.0.0", "micromark-extension-mdx-expression": "^3.0.0", "micromark-extension-mdx-jsx": "^3.0.0", "micromark-extension-mdx-md": "^2.0.0", "micromark-extension-mdxjs-esm": "^3.0.0", "micromark-util-combine-extensions": "^2.0.0", "micromark-util-types": "^2.0.0" } }, "sha512-A873fJfhnJ2siZyUrJ31l34Uqwy4xIFmvPY1oj+Ean5PHcPBYzEsvqvWGaWcfEIr11O5Dlw3p2y0tZWpKHDejQ=="], + + "micromark-extension-mdxjs-esm": ["micromark-extension-mdxjs-esm@3.0.0", "", { "dependencies": { "@types/estree": "^1.0.0", "devlop": "^1.0.0", "micromark-core-commonmark": "^2.0.0", "micromark-util-character": "^2.0.0", "micromark-util-events-to-acorn": "^2.0.0", "micromark-util-symbol": "^2.0.0", "micromark-util-types": "^2.0.0", "unist-util-position-from-estree": "^2.0.0", "vfile-message": "^4.0.0" } }, "sha512-DJFl4ZqkErRpq/dAPyeWp15tGrcrrJho1hKK5uBS70BCtfrIFg81sqcTVu3Ta+KD1Tk5vAtBNElWxtAa+m8K9A=="], + "micromark-factory-destination": ["micromark-factory-destination@2.0.1", "", { "dependencies": { "micromark-util-character": "^2.0.0", "micromark-util-symbol": "^2.0.0", "micromark-util-types": "^2.0.0" } }, "sha512-Xe6rDdJlkmbFRExpTOmRj9N3MaWmbAgdpSrBQvCFqhezUn4AHqJHbaEnfbVYYiexVSs//tqOdY/DxhjdCiJnIA=="], "micromark-factory-label": ["micromark-factory-label@2.0.1", "", { "dependencies": { "devlop": "^1.0.0", "micromark-util-character": "^2.0.0", "micromark-util-symbol": "^2.0.0", "micromark-util-types": "^2.0.0" } }, "sha512-VFMekyQExqIW7xIChcXn4ok29YE3rnuyveW3wZQWWqF4Nv9Wk5rgJ99KzPvHjkmPXF93FXIbBp6YdW3t71/7Vg=="], + "micromark-factory-mdx-expression": ["micromark-factory-mdx-expression@2.0.3", "", { "dependencies": { "@types/estree": "^1.0.0", "devlop": "^1.0.0", "micromark-factory-space": "^2.0.0", "micromark-util-character": "^2.0.0", "micromark-util-events-to-acorn": "^2.0.0", "micromark-util-symbol": "^2.0.0", "micromark-util-types": "^2.0.0", "unist-util-position-from-estree": "^2.0.0", "vfile-message": "^4.0.0" } }, "sha512-kQnEtA3vzucU2BkrIa8/VaSAsP+EJ3CKOvhMuJgOEGg9KDC6OAY6nSnNDVRiVNRqj7Y4SlSzcStaH/5jge8JdQ=="], + "micromark-factory-space": ["micromark-factory-space@2.1.0", "", { "dependencies": { "micromark-util-character": "^2.0.0", "micromark-util-types": "^2.0.0" } }, "sha512-fS8hnLIjnjvdQIj39Geug8wWsR0HrYZ43KShKxNfwT7t2LOHo/LbWZEzEaSOjwtjdCsjoE6syHhonEzW0zv0+Q=="], "micromark-factory-title": ["micromark-factory-title@2.0.1", "", { "dependencies": { "micromark-factory-space": "^2.0.0", "micromark-util-character": "^2.0.0", "micromark-util-symbol": "^2.0.0", "micromark-util-types": "^2.0.0" } }, "sha512-5bZ+3CjhAd9eChYTHsjy6TGxpOFSKgKKJPJxr293jTbfry2KDoWkhBb6TcPVB4NmzaPhMs1Frm9AZH7OD4Cjzw=="], @@ -579,6 +606,8 @@ "micromark-util-encode": ["micromark-util-encode@2.0.1", "", {}, "sha512-c3cVx2y4KqUnwopcO9b/SCdo2O67LwJJ/UyqGfbigahfegL9myoEFoDYZgkT7f36T0bLrM9hZTAaAyH+PCAXjw=="], + "micromark-util-events-to-acorn": ["micromark-util-events-to-acorn@2.0.3", "", { "dependencies": { "@types/estree": "^1.0.0", "@types/unist": "^3.0.0", "devlop": "^1.0.0", "estree-util-visit": "^2.0.0", "micromark-util-symbol": "^2.0.0", "micromark-util-types": "^2.0.0", "vfile-message": "^4.0.0" } }, "sha512-jmsiEIiZ1n7X1Rr5k8wVExBQCg5jy4UXVADItHmNk1zkwEVhBuIUKRu3fqv+hs4nxLISi2DQGlqIOGiFxgbfHg=="], + "micromark-util-html-tag-name": ["micromark-util-html-tag-name@2.0.1", "", {}, "sha512-2cNEiYDhCWKI+Gs9T0Tiysk136SnR13hhO8yW6BGNyhOC4qYFnwF1nKfD3HFAIXA5c45RrIG1ub11GiXeYd1xA=="], "micromark-util-normalize-identifier": ["micromark-util-normalize-identifier@2.0.1", "", { "dependencies": { "micromark-util-symbol": "^2.0.0" } }, "sha512-sxPqmo70LyARJs0w2UclACPUUEqltCkJ6PhKdMIDuJ3gSf/Q+/GIe3WKl0Ijb/GyH9lOpUkRAO2wp0GVkLvS9Q=="], @@ -691,9 +720,11 @@ "space-separated-tokens": ["space-separated-tokens@2.0.2", "", {}, "sha512-PEGlAwrG8yXGXRjW32fGbg66JAlOAwbObuqVoJpv/mRgoWDQfgH1wDPvtzWyUSNAXBGSk8h755YDbbcEy3SH2Q=="], + "starlight-hypha-agents": ["starlight-hypha-agents@github:hyphatech/starlight-hypha-agents#3ee7026", { "dependencies": { "mdast-util-from-markdown": "^2.0.2", "mdast-util-mdx": "^3.0.0", "micromark-extension-mdxjs": "^3.0.0", "yaml": "^2.9.1" }, "peerDependencies": { "@astrojs/starlight": "~0.42.6", "astro": "^7.3.3" } }, "hyphatech-starlight-hypha-agents-3ee7026", "sha512-CRpk3KikuTkpb+Sbq5wMWOibJyR9DScrqijg08vp17qul6BB/GVfYV4XVK9nGVUsGJVjfYgVlCr5j51ZmXHf+A=="], + "starlight-links-validator": ["starlight-links-validator@0.27.0", "", { "dependencies": { "@astrojs/markdown-satteri": "^0.4.0", "github-slugger": "^2.0.0", "hast-util-from-html": "^2.0.3", "is-absolute-url": "^5.0.0", "mdast-util-mdx-jsx": "^3.2.0", "mdast-util-to-hast": "^13.2.1", "picomatch": "^4.0.3", "satteri": "^0.10.3", "terminal-link": "^5.0.0", "unist-util-visit": "^5.1.0", "yaml": "^2.8.3" }, "peerDependencies": { "@astrojs/starlight": ">=0.42.0", "astro": ">=7.2.10" } }, "sha512-UvPl8L9hfWR+yWbLOEtljLmpJCGcM6AVseVy5IO9dmqdOjW4R+Y8FaYyVA5axCC8RvxM5xU7M1WTerpwU8rYbw=="], - "starlight-theme-hypha": ["starlight-theme-hypha@github:hyphatech/starlight-theme-hypha#4df8be9", { "dependencies": { "@fontsource-variable/roboto-slab": "^5.3.0", "@fontsource/inter-tight": "^5.3.0", "@lucide/astro": "1.48.0", "@tailwindcss/vite": "^4.3.3", "tailwindcss": "^4.3.3" }, "peerDependencies": { "@astrojs/starlight": "~0.42.6", "astro": "^7.3.3" } }, "hyphatech-starlight-theme-hypha-4df8be9", "sha512-3ksSin8zktNtDQ9xnP2ihRZkXVaPMTXGxrFykNrXBR3vQT/sQffOD2vpeL+ZvObUP/KmslY4RPWJEnyxwi1npA=="], + "starlight-theme-hypha": ["starlight-theme-hypha@github:hyphatech/starlight-theme-hypha#a105fa6", { "dependencies": { "@fontsource-variable/roboto-slab": "^5.3.0", "@fontsource/inter-tight": "^5.3.0", "@lucide/astro": "1.48.0", "@tailwindcss/vite": "^4.3.3", "tailwindcss": "^4.3.3" }, "peerDependencies": { "@astrojs/starlight": "~0.42.6", "astro": "^7.3.3" } }, "hyphatech-starlight-theme-hypha-a105fa6", "sha512-1lDTrqupxaVND5rueaGZVy2mokekMHaaDHAI3d4TBW8KujgEMRQ3Ftec3+CeXz4vG0NCEd8HCjyW13GBY/eUtQ=="], "std-env": ["std-env@4.3.0", "", {}, "sha512-OtU/EgQ1kIm5KwqQpBC6ZEMXrZRui11w8zgfTWp8cdO9B8OaPsbA8bTHO2P+HNo1VlUTGMVBwPhydu6poeXiag=="], @@ -745,6 +776,8 @@ "unist-util-position": ["unist-util-position@5.0.0", "", { "dependencies": { "@types/unist": "^3.0.0" } }, "sha512-fucsC7HjXvkB5R3kTCO7kUjRdrS0BJt3M/FPxmHMBOm8JQi2BsHAHFsy27E0EolP8rp0NzXsJ+jNPyDWvOJZPA=="], + "unist-util-position-from-estree": ["unist-util-position-from-estree@2.0.0", "", { "dependencies": { "@types/unist": "^3.0.0" } }, "sha512-KaFVRjoqLyF6YXCbVLNad/eS4+OfPQQn2yOd7zF/h5T/CSL2v8NpN6a5TPvtbXthAGw5nG+PuTtq+DdIZr+cRQ=="], + "unist-util-stringify-position": ["unist-util-stringify-position@4.0.0", "", { "dependencies": { "@types/unist": "^3.0.0" } }, "sha512-0ASV06AAoKCDkS2+xw5RXJywruurpbC4JZSm7nr7MOt1ojAzvyyaO+UxZf18j8FCF6kmzCZKcAgN/yu2gm2XgQ=="], "unist-util-visit": ["unist-util-visit@5.2.0", "", { "dependencies": { "@types/unist": "^3.0.0", "unist-util-is": "^6.0.0", "unist-util-visit-parents": "^6.1.0" } }, "sha512-fpsYs/VVoZxfGY9/j3FQpZmN8wdLJaV1Pt38AaJNZu9uKIHcFU3halCdBveEq1HGKO1OEfJY65w1zvoFV1b3qQ=="], diff --git a/docs/package.json b/docs/package.json index 0e2031a..653c1b0 100644 --- a/docs/package.json +++ b/docs/package.json @@ -5,7 +5,8 @@ "devDependencies": { "@astrojs/starlight": "~0.42.6", "astro": "^7.3.3", + "starlight-hypha-agents": "github:hyphatech/starlight-hypha-agents#v0.2.0", "starlight-links-validator": "^0.27.0", - "starlight-theme-hypha": "github:hyphatech/starlight-theme-hypha#v0.6.3" + "starlight-theme-hypha": "github:hyphatech/starlight-theme-hypha#v0.8.0" } } diff --git a/dune b/dune index 84a195a..0842b01 100644 --- a/dune +++ b/dune @@ -6,3 +6,13 @@ (_ (flags (:standard -w +a-4-40-41-42-44-45-48-67-70)))) + +; The documentation for a user's agent, agents/, written from the site's pages +; by `make docs`: installed whole, so $(opam var postgres-eio:doc) holds +; llms.txt and each page. + +(install + (package postgres-eio) + (section doc) + (source_trees + (agents as .)))