Repodb_postgresql

repodb-postgresql · API reference

val default_cache_size : int

PostgreSQL driver for Repodb.

This package exposes a concrete Repodb.Driver.S implementation backed by the postgresql OCaml bindings. It supports PostgreSQL placeholders, RETURNING, PostgreSQL upsert syntax, binary blobs, UUID values, JSON/JSONB, arrays where Repodb's type layer supports them, and server-side prepared statement caching.

Basic use:

module Repo = Repodb.Repo.Make (Repodb_postgresql.Driver)

  let conninfo = "host=localhost dbname=app user=app password=secret"

  let result =
    Repodb_postgresql.with_connection conninfo (fun conn ->
      Repo.all_query conn (Repodb.Query.from User.table) ~decode:decode_user)

connect accepts libpq-style connection info. Placeholders render as $1, $2, and so on. Errors are represented as strings at the driver boundary; Repodb.Repo recognizes common PostgreSQL constraint messages and converts them to Repodb.Error.db_error.Constraint_violation.

Raw exposes the backend-specific connection and low-level execution hooks used to build Driver. Prefer Driver and repo abstractions unless you are implementing infrastructure such as migrations, diagnostics, or backend tests.

module Raw : sig ... end
module Driver : sig ... end
type connection = Driver.connection
type error = Driver.error
val dialect : Repodb.Driver.dialect
val error_message : Driver.error -> string
val connect : string -> (Driver.connection, Driver.error) result
val close : Driver.connection -> unit
val with_connection : 
  string ->
  (Driver.connection -> ('a, Driver.error) result) ->
  ('a, Driver.error) result
val exec : 
  Driver.connection ->
  string ->
  params:Repodb.Driver.Value.t array ->
  (unit, Driver.error) result
val query : 
  Driver.connection ->
  string ->
  params:Repodb.Driver.Value.t array ->
  (Repodb.Driver.row list, Driver.error) result
val query_one : 
  Driver.connection ->
  string ->
  params:Repodb.Driver.Value.t array ->
  (Repodb.Driver.row option, Driver.error) result
val query_fold : 
  Driver.connection ->
  string ->
  params:Repodb.Driver.Value.t array ->
  init:'a ->
  f:('a -> Repodb.Driver.row -> 'a) ->
  ('a, Driver.error) result
val query_iter : 
  Driver.connection ->
  string ->
  params:Repodb.Driver.Value.t array ->
  f:(Repodb.Driver.row -> unit) ->
  (unit, Driver.error) result
val transaction : 
  Driver.connection ->
  (Driver.connection -> ('a, Driver.error) result) ->
  ('a, Driver.error) result
val placeholder : int -> string
val returning_supported : bool
val upsert_syntax : [ `PostgreSQL | `SQLite | `Standard ]
val last_insert_id : Driver.connection -> (int64, Driver.error) result
val driver : Repodb.Driver.driver