package session-postgresql-async

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type

PostgreSQL backend using the Session.S.Future signature with Async.

The default expiry period is one week. The code expects the following table and index to be in pace:

CREATE TABLE IF NOT EXISTS session (
  session_key       char(40),
  expire_date       timestamp (2) with time zone,
  session_data      text
);

CREATE INDEX session_key_idx ON session (session_key);

Note that this module does not do utilize non-blocking IO but instead runs each synchronous operation in a thread.

include Session.S.Future with type t = Postgresql.connection and type +'a io = 'a Async.Deferred.t and type key = string and type value = string and type period = int64
type +'a io = 'a Async.Deferred.t

The type of a blocking computation that will produce a value of type 'a

The type of a handle on the backend.

type key = string

The type of a session key.

type value = string

The type of a session value.

type period = int64

The type of a session expiry period.

val default_period : t -> period

default_period t returns default period after which session keys will expire. Depending on the backend, this value may vary over time.

val generate : ?expiry:period -> ?value:value -> t -> key io

generate ?expiry ?value t will allocate a new session in the backend t and return its associated key. The session will expire expiry seconds from now, defaulting to default_period t if one is not explicitly specified.

The key should be unique, though it may not be in order to allow implementations that use randomness or hashing to conform to this interface.

val clear : t -> key -> unit io

clear t key removes key from the backend t. The backend may choose to persist the session value beyond this call. If it does any subsequent operations involving key behave as if it was not there.

get t key returns the session value, if present and unexpired, together with its expiry period as of now.

val set : ?expiry:period -> t -> key -> value -> unit io

set ?expiry t key value sets the value for the session associated key in backend t and sets the session to expire expiry seconds from now. If expiry is not provided, the expiry period reported by default_period t will be used instead.

val connect : ?host:string -> ?hostaddr:string -> ?port:string -> ?dbname:string -> ?user:string -> ?password:string -> ?options:string -> ?tty:string -> ?requiressl:string -> ?conninfo:string -> ?startonly:bool -> unit -> t Async.Deferred.t

Create a connection to a postgresql database.

This is an alias for the connection constructor. If you have an existing connection to a database with the appropriate tables set up, you are more than welcome to use it.

val set_default_period : t -> period -> unit

set_default_period t period sets the default expiry period of t. This will only affect future operations.

module Pool : sig ... end

PostgreSQL backend using the Session.S.Future siganture with Aysnc, together with connection pooling via a Throttle

OCaml

Innovation. Community. Security.