package pgx

  1. Overview
  2. Docs

Parameters

module Thread : Io

Signature

type t
module Io : sig ... end
val connect : ?ssl:[ `Auto | `No | `Always of Io.ssl_config ] -> ?host:string -> ?port:int -> ?user:string -> ?password:string -> ?database:string -> ?unix_domain_socket_dir:string -> ?verbose:int -> ?max_message_length:int -> unit -> t Io.t

Connect to the database. The normal $PGDATABASE, etc. environment variables are available.

max_message_length is the maximum message length accepted from the back-end. The default is Sys.max_string_length, which means that we will try to read as much data from the back-end as we can, and this may cause us to run out of memory (particularly on 64 bit machines), causing a possible denial of service. You may want to set this to a smaller size to avoid this happening.

val close : t -> unit Io.t

Close the database handle. You must call this after you have finished with the handle, or else you will get leaked file descriptors.

val with_conn : ?ssl:[ `Auto | `No | `Always of Io.ssl_config ] -> ?host:string -> ?port:int -> ?user:string -> ?password:string -> ?database:string -> ?unix_domain_socket_dir:string -> ?verbose:int -> ?max_message_length:int -> (t -> 'a Io.t) -> 'a Io.t

Calls connect, passes the DB handle to the callback, then calls close. This is the preferred way to use this library since it cleans up after itself.

val ping : t -> unit Io.t

Ping the database. If the database is not available, some sort of exception will be thrown.

val alive : t -> bool Io.t

This function is a wrapper of ping that returns a boolean instead of raising an exception.

val begin_work : ?isolation:Isolation.t -> ?access:Access.t -> ?deferrable:bool -> t -> t Io.t

Start a transaction.

val commit : t -> unit Io.t

Commit a transaction. Throws an exception if no transaction is open. Use with_transaction when possible.

val rollback : t -> unit Io.t

Rollback a transaction. Throws an exception if no transaction is open. Use with_transaction when possible.

val with_transaction : ?isolation:Isolation.t -> ?access:Access.t -> ?deferrable:bool -> t -> (t -> 'b Io.t) -> 'b Io.t

with_transaction db ?isolation ?access ?deferrable f wraps your function f inside a transactional block. See begin_work for a description of isolation, access, and deferrable. If f throws an exception, the transaction will be rolled back. Otherwise the transaction will be commited. It is an error to call commit or rollback manually inside of this function.

module Prepared : sig ... end
val execute : ?params:Pgx__.Pgx_value.v option list -> t -> string -> Pgx__.Pgx_value.v option list list Io.t

execute conn ?params query prepares and executes the statement query and returns the result.

val execute_unit : ?params:Pgx__.Pgx_value.v option list -> t -> string -> unit Io.t

execute_unit conn ?params query same as execute, but intended for database calls that have side-affects rather than returning results

val execute_fold : ?params:Pgx__.Pgx_value.v option list -> t -> string -> init:'accum -> f:('accum -> Pgx__.Pgx_value.v option list -> 'accum Io.t) -> 'accum Io.t
val execute_map : ?params:Pgx__.Pgx_value.v option list -> t -> string -> f:(Pgx__.Pgx_value.v option list -> 'a Io.t) -> 'a list Io.t
val execute_iter : ?params:Pgx__.Pgx_value.v option list -> t -> string -> f:(Pgx__.Pgx_value.v option list -> unit Io.t) -> unit Io.t
val execute_many : t -> query:string -> params:Pgx__.Pgx_value.v option list list -> Pgx__.Pgx_value.v option list list list Io.t

Prepares a query as in execute and then executes it once per set of parameters in params. This is more efficient than calling execute in a loop because the query is only prepared once.

val simple_query : t -> string -> Pgx__.Pgx_value.v option list list list Io.t

simple_query conn query executes the command(s) in the given query and returns a list of query results (i.e. if you run two queries, you will get a list with two elements: the results of the first query followed by the results of the second query.

OCaml

Innovation. Community. Security.