
# Module `Eliom_common.Ocsipersist`

Persistent key-value store interface for OCaml. This is an virtual library defining a unified frontend for a number of key-value storage implementations. Implementations of the following backends currently exist: SQLite, DBM, PostgreSQL. You can choose the backend you prefer by installing packages `ocsipersist-sqlite`, `ocsipersist-dbm` or `ocsipersist-pgsql`.

Library `Ocsipersist_settings`, provided by each of the backends, contain the configuration options for your stores.

Packages `ocsipersist-sqlite-config`, `ocsipersist-dbm-config` and `ocsipersist-pgsql-config` add the possibility to configure the corresponding backends from Ocsigen Server's configuration file.

Ocsipersist is used by Eliom for persistent session storages and references.

Ocsipersist defines several interfaces:

- `Ref` is the simpler the use: it provides persistent references
- `Store` is a lower level interface for persistent values
- `Polymorphic` is a polymorphic table, using Mahshal
- `Functorial` is a typed interface for your own data type
Example of use from the toplevel:

```ocaml
# #require "lwt_ppx";;
(* #thread;; if you are using OCaml < 5.0.0 *)
# #require "ocsipersist-sqlite";;
# Ocsipersist.init ();;
# let r = Ocsipersist.Ref.ref ~persistent:"r" 444;;
val r : int Ocsipersist.Ref.t = <abstr>
# Lwt_main.run (let%lwt v = Ocsipersist.Ref.get r in print_int v; Lwt.return_unit);;
444- : unit = ()
```
```ocaml
module Functorial : Ocsipersist_lib.Sigs.FUNCTORIAL
```
Functorial frontent. Allows for custom (de)serialisation functions, which keeps data human-readable in the backend.

```ocaml
module type TABLE = Ocsipersist_lib.Sigs.TABLE
```
Table representation as generated by the functor [`Functorial.Table`](./Eliom_common-Ocsipersist-Functorial-Table.md)

```ocaml
module Polymorphic : Ocsipersist_lib.Sigs.POLYMORPHIC
```
Polymorphic frontent. Relies on [`Marshal`](./../../ocaml-compiler/stdlib/Stdlib-Marshal.md) for (de)serialisation, which means that data will be stored in the backend in a fashion that is not necessarily easily readable by non-OCaml-based life forms. If this is an issue for you, you can rely on the functorial frontend instead.

```ocaml
type 'value table = 'value Polymorphic.table
```
Table representation as generated by the function [`Polymorphic.open_table`](./Eliom_common-Ocsipersist-Polymorphic.md#val-open_table)

```ocaml
module Ref : Ocsipersist_lib.Sigs.REF
```
Simple interface for persistent references. Relies on [`Stdlib.Marshal`](./../../ocaml-compiler/stdlib/Stdlib-Marshal.md) for (de)serialisation, which entails the same limitations as for the [`Polymorphic`](./Eliom_common-Ocsipersist-Polymorphic.md) frontend. If this is an issue you can rely on [`Functorial`](./Eliom_common-Ocsipersist-Functorial.md) frontend instead (see [`TABLE.Variable`](./../../ocsipersist-lib/ocsipersist-lib/Ocsipersist_lib-Sigs-module-type-TABLE-Variable.md)).

```ocaml
module Store : Ocsipersist_lib.Sigs.STORE
```
The variable store allows for the persistent storage of individual variables. Relies on [`Stdlib.Marshal`](./../../ocaml-compiler/stdlib/Stdlib-Marshal.md) for (de)serialisation, which entails the same limitations as for the [`Polymorphic`](./Eliom_common-Ocsipersist-Polymorphic.md) frontend. If this is an issue you can rely on [`Functorial`](./Eliom_common-Ocsipersist-Functorial.md) frontend instead (see [`TABLE.Variable`](./../../ocsipersist-lib/ocsipersist-lib/Ocsipersist_lib-Sigs-module-type-TABLE-Variable.md)).

```ocaml
type store = Store.store
```
```ocaml
type 'a variable = 'a Store.t
```
```ocaml
val init : unit -> unit
```