
# Lightweight database using Ocsipersist

<!--wodoc:aside class="concepts"-->**Concepts**

Persistent tables with Ocsipersist<!--wodoc:end-->

Ocsipersist is a module for persistent references and tables.

For persistent references, Eliom has a higher level interface, called *Eliom references*, and you probably want to use it instead of using Ocsipersist directly. For example persistent Eliom references of scope session group can be used to store information about a user (if the session group corresponds to the user).

Ocsipersist can still be useful for creating persistent key-value tables, if you do not need the full power of a SQL database.

This tutorial shows how to implement a table for storing users and passwords.

We first create a table:

```ocaml
let user_table = Ocsipersist.Polymorphic.open_table "user_table"
```
Then we can easily handle the user management code:

```ocaml
let check_pwd name pwd =
  try%lwt
    lwt saved_password = Ocsipersist.Polymorphic.find user_table name in
    Lwt.return (pwd = saved_password)
  with
    Not_found -> Lwt.return false

let () = Eliom_registration.Action.register
  ~service:create_account_service
  (fun () (name, pwd) -> Ocsipersist.Polymorphic.add user_table name pwd)

let () = Eliom_registration.Action.register
  ~service:connection_service
  (fun () (name, password) ->
    match%lwt check_pwd name password with
      | true -> Eliom_reference.set username (Some name)
      | false -> Lwt.return ())
```
<!--wodoc:aside class="concept"-->**Concept: Ocsipersist**

Ocsipersist implements simple typed key/value tables. It can use different backends (currently sqlite and dbm). For more information see `Ocsipersist.table`. <!--wodoc:end-->
