Skip to content
Permalink
Browse files

doc: Document atomicity of PostgreSQL interactions

  • Loading branch information
erikd committed Dec 3, 2019
1 parent 98dadd1 commit dfbb9372b9275a423cbb0b042d0d1202d29494b1
Showing with 30 additions and 0 deletions.
  1. +30 −0 doc/webapi-atomic-requests.md
@@ -0,0 +1,30 @@
# Atomicity of PostgreSQL Interactions

Both the webapi and the node which populates the database operate on the database within a
database transaction. All operations on the database from Haskell code is done within functions
which have a type signatures of :
```
ReaderT SqlBackend m a
```
Any function without the `ReaderT SqlBackend` component will not be able to access the database
and any attempt to access the database without the required type signature will result in a compile
error at compile time.

All functions with the required file type are run with the function provided by Haskell's
[Persistent][Persistent] library:
```
runSqlConnWithIsolation action backend Serializable
```
where:
* `runSqlConnWithIsolation` is the function that runs the provided `action` on a connection to
the database within a database transaction.
* `action` is the action to be performed on the database (eg write or query).
* `backend` contains the database connection data.
* `Serializable` specifies the transaction isolation level.

In this case the `Serializable` [PosgresIso][transaction isolation] level is used which is the
*maximum* level of transaction isolation.

[Persistent]: https://hackage.haskell.org/package/persistent
[PosgresIso]: https://www.postgresql.org/docs/current/transaction-iso.html

0 comments on commit dfbb937

Please sign in to comment.
You can’t perform that action at this time.