on master help sign in
WIP implemented selectSourceRes
commitc5ddc9b703911db1e30fa3c0199f745a09c67838 authorAgentM <agentm@Tatyanas-MacBook.local> dateWed 16 Sep 2015, 13:12 (11 years ago) parent5e4b9b8
1 file changed+19−1
Database/Persist/ProjectM36.hs+19−1
Database/Persist/ProjectM36.hs+19−1
@@ -29,6 +29,7 @@ import Control.Monad.Trans.Either
2929import Database.Persist.Class
3030import qualified Database.Persist.Types as DPT
3131import qualified Data.Set as S
32+import qualified Data.Conduit.List as CL
3233
3334type ProjectM36Backend = C.Connection
3435
@@ -498,5 +499,22 @@ instance PersistQuery C.Connection where
498499 Left err -> Trans.liftIO $ throwIO $ PersistError "count pooped"
499500 Right c -> return c
500501
501− selectSourceRes = undefined
502+ --no select options currently supported (sorting, limiting)
503+ selectSourceRes _ (_:_) = Trans.liftIO $ throwIO $ PersistError "select options not yet supported"
504+ selectSourceRes filters [] = do
505+ conn <- ask
506+ entities <- runEitherT $ do
507+ restrictionPredicate <- hoistEither $ multiFilterAsRestrictionPredicate True filters
508+ let entDef = entityDef $ dummyFromFilters filters
509+ relVarName = unDBName $ entityDB entDef
510+ restrictionExpr = Restrict restrictionPredicate (RelationVariable relVarName)
511+ tupleMapper tuple = Trans.liftIO $ fromPersistValuesThrow entDef tuple
512+ rel <- Trans.liftIO $ C.executeRelationalExpr conn restrictionExpr
513+ case rel of
514+ Left err -> Trans.liftIO $ throwIO $ PersistError (T.pack (show err))
515+ Right (Relation _ tupleSet) -> mapM tupleMapper $ HS.toList tupleSet --refactor to use some relation accessors- here we convert a relation to a matrix, effectively (especially to support future sorting)
516+ case entities of
517+ Left err -> Trans.liftIO $ throwIO $ PersistError (T.pack $ show err)
518+ Right entities' -> return $ return $ CL.sourceList entities'
519+
502520 selectKeysRes = undefined