Add projection function
This commit is contained in:
parent
5cd4b03ec9
commit
a01f9c8563
@ -54,11 +54,18 @@ import qualified Data.ByteString as B
|
|||||||
import qualified Data.Text as T
|
import qualified Data.Text as T
|
||||||
import qualified Data.Text.Lazy as TL
|
import qualified Data.Text.Lazy as TL
|
||||||
|
|
||||||
class BackendCompatible sup sub
|
class BackendCompatible sup sub where
|
||||||
|
projectBackend :: sub -> sup
|
||||||
|
|
||||||
|
instance BackendCompatible SqlBackend SqlBackend where
|
||||||
|
projectBackend = id
|
||||||
|
|
||||||
|
instance BackendCompatible SqlBackend SqlReadBackend where
|
||||||
|
projectBackend = unSqlReadBackend
|
||||||
|
|
||||||
|
instance BackendCompatible SqlBackend SqlWriteBackend where
|
||||||
|
projectBackend = unSqlWriteBackend
|
||||||
|
|
||||||
instance BackendCompatible SqlBackend SqlBackend
|
|
||||||
instance BackendCompatible SqlBackend SqlReadBackend
|
|
||||||
instance BackendCompatible SqlBackend SqlWriteBackend
|
|
||||||
|
|
||||||
-- | Finally tagless representation of @esqueleto@'s EDSL.
|
-- | Finally tagless representation of @esqueleto@'s EDSL.
|
||||||
class (Functor query, Applicative query, Monad query) =>
|
class (Functor query, Applicative query, Monad query) =>
|
||||||
|
|||||||
@ -786,13 +786,16 @@ veryUnsafeCoerceSqlExprValueList EEmptyList = throw (UnexpectedCaseErr EmptySqlE
|
|||||||
-- @persistent@'s 'SqlPersistT' monad.
|
-- @persistent@'s 'SqlPersistT' monad.
|
||||||
rawSelectSource :: ( SqlSelect a r
|
rawSelectSource :: ( SqlSelect a r
|
||||||
, MonadIO m1
|
, MonadIO m1
|
||||||
, MonadIO m2 )
|
, MonadIO m2
|
||||||
|
, SqlBackendCanRead backend
|
||||||
|
, BackendCompatible SqlBackend backend)
|
||||||
=> Mode
|
=> Mode
|
||||||
-> SqlQuery a
|
-> SqlQuery a
|
||||||
-> SqlReadT m1 (Acquire (C.Source m2 r))
|
-> R.ReaderT backend m1 (Acquire (C.Source m2 r))
|
||||||
rawSelectSource mode query =
|
rawSelectSource mode query =
|
||||||
do
|
do
|
||||||
conn <- persistBackend <$> R.ask
|
conn <- projectBackend <$> R.ask
|
||||||
|
let _ = conn :: SqlBackend
|
||||||
res <- run conn
|
res <- run conn
|
||||||
return $ (C.$= massage) `fmap` res
|
return $ (C.$= massage) `fmap` res
|
||||||
where
|
where
|
||||||
@ -866,8 +869,11 @@ selectSource query = do
|
|||||||
-- function composition that the @p@ inside the query is of type
|
-- function composition that the @p@ inside the query is of type
|
||||||
-- @SqlExpr (Entity Person)@.
|
-- @SqlExpr (Entity Person)@.
|
||||||
select :: ( SqlSelect a r
|
select :: ( SqlSelect a r
|
||||||
, MonadIO m )
|
, MonadIO m
|
||||||
=> SqlQuery a -> SqlReadT m [r]
|
, SqlBackendCanRead backend
|
||||||
|
, BackendCompatible SqlBackend backend
|
||||||
|
)
|
||||||
|
=> SqlQuery a -> R.ReaderT backend m [r]
|
||||||
select query = do
|
select query = do
|
||||||
res <- rawSelectSource SELECT query
|
res <- rawSelectSource SELECT query
|
||||||
conn <- R.ask
|
conn <- R.ask
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user