Lightweight database using Ocsipersist
Concepts
Persistent tables with Ocsipersist
For maintaining the list of user and password, we do not need the full power of a SQL database, a key/value table is sufficient. Ocsigen has such a simple table mechanism directly integrated: Ocsipersist.
We first create a table holding ocaml values:
let user_table = Ocsipersist.open_table "user_table"
Then we can easily handle the user management code:
let check_pwd name pwd = try_lwt lwt saved_password = Ocsipersist.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.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 ())
Concept: Ocsipersist
Ocsipersist provides simple typed key/value tables. It provides different backends (currently sqlite and dbm) and can be extended. For more informations see Ocsipersist.table.
