Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
haskell-gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
159
Issues
159
List
Board
Labels
Milestones
Merge Requests
9
Merge Requests
9
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gargantext
haskell-gargantext
Commits
47ed29c5
Commit
47ed29c5
authored
May 12, 2025
by
Alfredo Di Napoli
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Experiment with Free-Church encoding in DBTx
parent
b0568522
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
4 additions
and
3 deletions
+4
-3
Transactional.hs
src/Gargantext/Database/Transactional.hs
+4
-3
No files found.
src/Gargantext/Database/Transactional.hs
View file @
47ed29c5
...
...
@@ -42,6 +42,7 @@ import Database.PostgreSQL.Simple.Transaction qualified as PG
import
Gargantext.Database.Class
import
Opaleye
import
Prelude
import
Control.Monad.Free.Church
data
DBOperation
=
DBRead
|
DBWrite
...
...
@@ -75,7 +76,7 @@ data DBTransactionOp err (r :: DBOperation) next where
-- | Monadic failure for DB transactions.
DBFail
::
err
->
DBTransactionOp
err
r
next
newtype
DBTx
err
r
a
=
DBTx
{
_DBTx
::
F
ree
(
DBTransactionOp
err
r
)
a
}
newtype
DBTx
err
r
a
=
DBTx
{
_DBTx
::
F
(
DBTransactionOp
err
r
)
a
}
deriving
(
Functor
,
Applicative
,
Monad
)
type
DBQuery
err
r
a
=
DBTx
err
r
a
...
...
@@ -130,7 +131,7 @@ withReadOnlyTransactionM conn action =
runDBTx
::
DBUpdate
err
a
->
DBTxCmd
err
a
runDBTx
(
DBTx
m
)
=
do
pool
<-
view
connPool
withResourceM
pool
$
\
conn
->
withTransactionM
conn
$
foldF
ree
(
evalOp
conn
)
m
withResourceM
pool
$
\
conn
->
withTransactionM
conn
$
foldF
(
evalOp
conn
)
m
-- | /NOTE/ the input type is 'DBReadOnly', i.e. a transaction where /all/
-- the operations are 'DBRead'. This makes impossible to sneak in updates
...
...
@@ -138,7 +139,7 @@ runDBTx (DBTx m) = do
runDBQuery
::
DBReadOnly
err
r
a
->
DBTxCmd
err
a
runDBQuery
(
DBTx
m
)
=
do
pool
<-
view
connPool
withResourceM
pool
$
\
conn
->
withReadOnlyTransactionM
conn
$
foldF
ree
(
evalOp
conn
)
m
withResourceM
pool
$
\
conn
->
withReadOnlyTransactionM
conn
$
foldF
(
evalOp
conn
)
m
-- | The main evaluator, turns our pure operations into side-effects that run into the
-- 'DBCmd'.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment