ebook-manager/src/Database.hs

32 lines
806 B
Haskell
Raw Normal View History

2018-08-02 23:59:08 +03:00
{-# Language TypeApplications #-}
{-# Language DataKinds #-}
{-# Language FlexibleContexts #-}
{-# Language ConstraintKinds #-}
module Database
( DBLike
, runDB
, query
, select
2018-08-03 23:36:38 +03:00
, gen
, fromRel
2018-08-05 23:13:49 +03:00
, fromRels
2018-08-03 23:36:38 +03:00
, toRel
, SeldaT )
2018-08-02 23:59:08 +03:00
where
import Data.Generics.Product
import Control.Lens (view)
import Data.Pool (Pool, withResource)
import Database.Selda.Backend (SeldaConnection, runSeldaT, SeldaT)
import Database.Selda (query, select)
2018-08-05 23:13:49 +03:00
import Database.Selda.Generic (gen, fromRel, fromRels, toRel)
2018-08-02 23:59:08 +03:00
import ClassyPrelude
type DBLike r m = (MonadIO m, MonadReader r m, MonadBaseControl IO m, MonadMask m, HasField' "database" r (Pool SeldaConnection))
runDB :: DBLike r m => SeldaT m a -> m a
runDB q = do
pool <- view (field @"database")
withResource pool $ \conn ->
runSeldaT q conn