{"id":13726188,"url":"https://github.com/anuragsoni/postgres-protocol","last_synced_at":"2025-03-26T10:32:04.853Z","repository":{"id":51103899,"uuid":"297221882","full_name":"anuragsoni/postgres-protocol","owner":"anuragsoni","description":"IO independent postgres protocol implementation","archived":false,"fork":false,"pushed_at":"2023-05-29T02:22:46.000Z","size":160,"stargazers_count":18,"open_issues_count":0,"forks_count":1,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-03-24T11:02:13.924Z","etag":null,"topics":["ocaml","postgres","postgresql"],"latest_commit_sha":null,"homepage":"","language":"OCaml","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/anuragsoni.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2020-09-21T03:47:25.000Z","updated_at":"2024-11-05T00:29:07.000Z","dependencies_parsed_at":"2024-01-06T02:03:17.979Z","dependency_job_id":"f2ec035f-07b1-44c2-9711-0f7c77a2a43a","html_url":"https://github.com/anuragsoni/postgres-protocol","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anuragsoni%2Fpostgres-protocol","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anuragsoni%2Fpostgres-protocol/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anuragsoni%2Fpostgres-protocol/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anuragsoni%2Fpostgres-protocol/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/anuragsoni","download_url":"https://codeload.github.com/anuragsoni/postgres-protocol/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245637054,"owners_count":20648084,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ocaml","postgres","postgresql"],"created_at":"2024-08-03T01:02:55.229Z","updated_at":"2025-03-26T10:32:04.572Z","avatar_url":"https://github.com/anuragsoni.png","language":"OCaml","funding_links":[],"categories":["OCaml"],"sub_categories":[],"readme":"# Postgres-ocaml\n\nWork-in-progress OCaml implementation of the Postgres frontend/backend protocol. This library implements the wire protocol in OCaml, instead of using C ffi with `libpq`.\n\nOnly postgresql [extended query](https://www.postgresql.org/docs/15/protocol-flow.html) workflow is supported. The library contains the following components:\n\n## [postgres](./postgres/)\n\nThis is the core library that defines all backend/frontend types. This library performs no I/O and is intended as a building block for I/O wrappers using lwt, async, etc. The library also includes a bare bones implementation of [RFC 5802](https://datatracker.ietf.org/doc/html/rfc5802) that covers just enough of the spec to address the needs for using `scram-sha-256` auth mechanism with postgresql.\n\n## [postgres_eio](./postgres_eio/)\n\n[Eio](https://github.com/ocaml-multicore/eio) driver for postgresql.\n\n### Example\n\n```ocaml\nopen Core\nopen Eio.Std\nopen Or_error.Let_syntax\n\nlet make_parameters ids =\n  Sequence.of_list ids\n  |\u003e Sequence.map ~f:(fun id -\u003e\n       let b = Bytes.create 4 in\n       Caml.Bytes.set_int32_be b 0 id;\n       Postgres.Param.create\n         ~parameter:(Bytes.to_string b)\n         Postgres.Format_code.binary)\n  |\u003e Sequence.to_array\n;;\n\nlet run ~sw ~net ~addr ~user ~password ~database =\n  let%bind conn = Postgres_eio.connect ~sw ~net ~user ~password ~database addr in\n  traceln \"Logged in to postgres\";\n  let%bind () =\n    Postgres_eio.prepare conn \"SELECT id, email from users where id IN ($1, $2, $3)\"\n  in\n  let%bind () = Postgres_eio.execute ~on_data_row:ignore conn in\n  let parameters = make_parameters [ 1l; 2l; 3l ] in\n  Postgres_eio.execute conn ~parameters ~on_data_row:(fun data_row -\u003e\n    match data_row with\n    | [| Some id; Some name |] -\u003e traceln \"Id: %s and email: %s\" id name\n    | _ -\u003e assert false)\n;;\n\nlet main ~env ~user ~password ~database =\n  let addr = `Tcp (Eio.Net.Ipaddr.V4.loopback, 5432) in\n  Mirage_crypto_rng_eio.run\n    (module Mirage_crypto_rng.Fortuna)\n    env\n    (fun () -\u003e\n      Switch.run (fun sw -\u003e\n        Or_error.ok_exn\n          (run ~user ~password ~addr ~database ~sw ~net:(Eio.Stdenv.net env))))\n;;\n```\n\n## TODO\n\n* add wrapper to handle parameters in an easier manner\n* Support transactions\n* Support postgres notify/listen channels\n* documentation\n* support TLS encrypted connections\n* TEST!!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanuragsoni%2Fpostgres-protocol","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fanuragsoni%2Fpostgres-protocol","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanuragsoni%2Fpostgres-protocol/lists"}