Eliom/Ocsipersist tutorial: broken documentation?

I’ve played a bit with Eliom, prior to following this tutorial: Client server reactive application with Ocsigen

It looks like Ocsipersist’s API must have changed, since I get the following compilation error:

File "tutoreact_messages.eliom", line 4, characters 13-35:
4 |     let db = Ocsipersist.open_table "messages"
                 ^^^^^^^^^^^^^^^^^^^^^^
Error: Unbound value Ocsipersist.open_table
make: *** [Makefile.os:213: _server/tutoreact_messages.type_mli] Error 2

From the following source file, compiled via make test.byte:

(* ./tutoreact_messages.eliom *)
[%%server
  module Db = struct
    let db = Ocsipersist.open_table "messages"
  end
]

So open_table is not exposed by Ocsipersist.

It’s not clear to me whether some kind of db setup is required prior to compilation, regardless I would expect some kind of runtime error.

$ make db-psql
psql tutoreact
psql (12.13 (Ubuntu 12.13-0ubuntu0.20.04.1))
Type "help" for help.

tutoreact=# \dt
Did not find any relations.
tutoreact=# \c ocsipersist_tutoreact 
You are now connected to database "ocsipersist_tutoreact" as user "benjamin".
ocsipersist_tutoreact=# \dt
                       List of relations
 Schema |                Name                | Type  |  Owner   
--------+------------------------------------+-------+----------
 public | __eliom_session_group_table        | table | benjamin
 public | demo_last_visit                    | table | benjamin
 public | eliom__persistent_refs             | table | benjamin
 public | eliom_persist_cookies_expiry_dates | table | benjamin
 public | eliom_persist_cookies_v5           | table | benjamin
 public | tips_seen1                         | table | benjamin
 public | tips_seen_not_connected1           | table | benjamin
(7 rows)

Can anyone using this tech enlighten me?

Hello @benjamin-thomas,

Indeed, the tutorials have not been completely updated to match the new API of Ocsipersist after the outsourcing of Ocsipersist from Ocsigenserver. A pull request has been opened to fix this:

Thanks for reporting the problem!

Because there is no table in the database tutoreact?

Thanks @ilankri!

I mentioned the state of my db, because I wasn’t sure if the errors I was seeing could somehow be caused by some failing codegen process I wasn’t aware of.

The eliom-distillery template generated this setup on my system:

$ cat tutoreact.sql | grep -F 'CREATE DATABASE'
CREATE DATABASE ocsipersist_tutoreact;

$ grep DB_NAME Makefile.options
DB_NAME               := tutoreact
PSQL_FILE             := $(DB_NAME).sql

So at this point, I haven’t quite figured out where and if I’m supposed to create the messages table but that’s okay.


So, skimming through the source code, I did find this module. However, after seeing this other error and not knowing what to expect I thought I’d ask for help.

File "tutoreact_messages.eliom", lines 7-9, characters 0-3:
7 | module%server Db = struct
8 |   let db = Ocsipersist.Polymorphic.open_table "messages"
9 | end
Error: The type of this module,
       sig val db : '_weak1 Ocsipersist.Polymorphic.table Lwt.t end,
       contains type variables that cannot be generalized

I copy/pasted the module definition from your PR and still get the same compilation error.

Could you explain what’s going on?

$ ocamlc --version
4.14.0
$ eliombuild --version
ocamlbuild 0.14.2

We need to help the type checker by adding a type annotation:

module%server Db = struct
  let db : string Ocsipersist.Polymorphic.table Lwt.t =
    Ocsipersist.Polymorphic.open_table "messages"
end

Note that this type annotation is not needed if we also add the rest of the code. In that case, the type checker can determine the right type on its own.

See OCaml - Polymorphism and its limitations for further information.

Thanks very much! I got it now :slight_smile: