[m-users.] Accessing a Relational Database and Purity

Zoltan Somogyi zoltan.somogyi at runbox.com
Wed Nov 14 13:21:40 AEDT 2018



On Tue, 13 Nov 2018 20:05:41 -0600, X Y <ayrnieu at gmail.com> wrote:
> Just pass io through your C FFI functions, as in
> https://github.com/jrfondren/getr-mercury/blob/master/rusage.m , and
> then add the promise_pure flag.

That is one way. Another approach is to

- define a dummy type named something like db_state,
- pass a di/uo pair of db_state arguments through every predicate
  that accesses the database,
- create a unique db_state at the start of a transaction, and require
  a unique db_state to be given back at the end of transaction.
  This can be done using impure code that implements a pure
  interface, which in this case is a database transaction.

This ensures that all access to the database is part of a transaction.

For much more detail on this, see the paper "Database transactions
in a purely declarative logic programming language", which is available
at http://mercurylang.org/documentation/papers.html#mu_96_45.

Zoltan.


More information about the users mailing list