module PGIP.GraphQL.Resolver.DGraph (resolve) where import PGIP.GraphQL.Resolver.ToResult import PGIP.GraphQL.Result as GraphQLResult import PGIP.GraphQL.Result.DGraph as GraphQLResultDGraph import PGIP.GraphQL.Result.DocumentLink as GraphQLResultDocumentLink import PGIP.GraphQL.Result.OMSSimple as GraphQLResultOMSSimple import PGIP.Shared import Driver.Options import Persistence.Database import Persistence.Schema as DatabaseSchema import Persistence.Schema.Enums as DatabaseSchemaEnums import Persistence.Utils import Database.Esqueleto import Control.Monad.IO.Class (MonadIO (..)) import qualified Control.Monad.Fail as Fail resolve :: HetcatsOpts -> Cache -> String -> IO (Maybe GraphQLResult.Result) resolve :: HetcatsOpts -> Cache -> String -> IO (Maybe Result) resolve opts :: HetcatsOpts opts _ locIdVar :: String locIdVar = DBConfig -> DBMonad (NoLoggingT IO) (Maybe Result) -> IO (Maybe Result) forall (m :: * -> *) a. (MonadIO m, MonadBaseControl IO m, MonadUnliftIO m, MonadFail m) => DBConfig -> DBMonad (NoLoggingT m) a -> m a onDatabase (HetcatsOpts -> DBConfig databaseConfig HetcatsOpts opts) (DBMonad (NoLoggingT IO) (Maybe Result) -> IO (Maybe Result)) -> DBMonad (NoLoggingT IO) (Maybe Result) -> IO (Maybe Result) forall a b. (a -> b) -> a -> b $ String -> DBMonad (NoLoggingT IO) (Maybe Result) forall (m :: * -> *). (MonadIO m, MonadFail m) => String -> DBMonad m (Maybe Result) resolveDB String locIdVar resolveDB :: (MonadIO m, Fail.MonadFail m) => String -> DBMonad m (Maybe GraphQLResult.Result) resolveDB :: String -> DBMonad m (Maybe Result) resolveDB locIdVar :: String locIdVar = do [(Entity Document, Entity LocIdBase)] dgraphL <- SqlQuery (SqlExpr (Entity Document), SqlExpr (Entity LocIdBase)) -> ReaderT SqlBackend m [(Entity Document, Entity LocIdBase)] forall a r (m :: * -> *). (SqlSelect a r, MonadIO m) => SqlQuery a -> SqlReadT m [r] select (SqlQuery (SqlExpr (Entity Document), SqlExpr (Entity LocIdBase)) -> ReaderT SqlBackend m [(Entity Document, Entity LocIdBase)]) -> SqlQuery (SqlExpr (Entity Document), SqlExpr (Entity LocIdBase)) -> ReaderT SqlBackend m [(Entity Document, Entity LocIdBase)] forall a b. (a -> b) -> a -> b $ (InnerJoin (SqlExpr (Entity Document)) (SqlExpr (Entity LocIdBase)) -> SqlQuery (SqlExpr (Entity Document), SqlExpr (Entity LocIdBase))) -> SqlQuery (SqlExpr (Entity Document), SqlExpr (Entity LocIdBase)) forall a b. From a => (a -> SqlQuery b) -> SqlQuery b from ((InnerJoin (SqlExpr (Entity Document)) (SqlExpr (Entity LocIdBase)) -> SqlQuery (SqlExpr (Entity Document), SqlExpr (Entity LocIdBase))) -> SqlQuery (SqlExpr (Entity Document), SqlExpr (Entity LocIdBase))) -> (InnerJoin (SqlExpr (Entity Document)) (SqlExpr (Entity LocIdBase)) -> SqlQuery (SqlExpr (Entity Document), SqlExpr (Entity LocIdBase))) -> SqlQuery (SqlExpr (Entity Document), SqlExpr (Entity LocIdBase)) forall a b. (a -> b) -> a -> b $ \(documents :: SqlExpr (Entity Document) documents `InnerJoin` loc_id_bases :: SqlExpr (Entity LocIdBase) loc_id_bases) -> do SqlExpr (Value Bool) -> SqlQuery () on (SqlExpr (Entity LocIdBase) loc_id_bases SqlExpr (Entity LocIdBase) -> EntityField LocIdBase (Key LocIdBase) -> SqlExpr (Value (Key LocIdBase)) forall typ val. (PersistEntity val, PersistField typ) => SqlExpr (Entity val) -> EntityField val typ -> SqlExpr (Value typ) ^. EntityField LocIdBase (Key LocIdBase) forall typ. (typ ~ Key LocIdBase) => EntityField LocIdBase typ LocIdBaseId SqlExpr (Value (Key LocIdBase)) -> SqlExpr (Value (Key LocIdBase)) -> SqlExpr (Value Bool) forall typ. PersistField typ => SqlExpr (Value typ) -> SqlExpr (Value typ) -> SqlExpr (Value Bool) ==. SqlExpr (Value (Key Document)) -> SqlExpr (Value (Key LocIdBase)) forall a b. SqlExpr (Value a) -> SqlExpr (Value b) coerceId (SqlExpr (Entity Document) documents SqlExpr (Entity Document) -> EntityField Document (Key Document) -> SqlExpr (Value (Key Document)) forall typ val. (PersistEntity val, PersistField typ) => SqlExpr (Entity val) -> EntityField val typ -> SqlExpr (Value typ) ^. EntityField Document (Key Document) forall typ. (typ ~ Key Document) => EntityField Document typ DocumentId)) SqlExpr (Value Bool) -> SqlQuery () where_ (SqlExpr (Entity LocIdBase) loc_id_bases SqlExpr (Entity LocIdBase) -> EntityField LocIdBase String -> SqlExpr (Value String) forall typ val. (PersistEntity val, PersistField typ) => SqlExpr (Entity val) -> EntityField val typ -> SqlExpr (Value typ) ^. EntityField LocIdBase String forall typ. (typ ~ String) => EntityField LocIdBase typ LocIdBaseLocId SqlExpr (Value String) -> SqlExpr (Value String) -> SqlExpr (Value Bool) forall typ. PersistField typ => SqlExpr (Value typ) -> SqlExpr (Value typ) -> SqlExpr (Value Bool) ==. String -> SqlExpr (Value String) forall typ. PersistField typ => typ -> SqlExpr (Value typ) val String locIdVar) (SqlExpr (Entity Document), SqlExpr (Entity LocIdBase)) -> SqlQuery (SqlExpr (Entity Document), SqlExpr (Entity LocIdBase)) forall (m :: * -> *) a. Monad m => a -> m a return (SqlExpr (Entity Document) documents, SqlExpr (Entity LocIdBase) loc_id_bases) case [(Entity Document, Entity LocIdBase)] dgraphL of [] -> Maybe Result -> DBMonad m (Maybe Result) forall (m :: * -> *) a. Monad m => a -> m a return Maybe Result forall a. Maybe a Nothing (documentEntity :: Entity Document documentEntity, locIdBaseEntity :: Entity LocIdBase locIdBaseEntity@(Entity documentKey :: Key LocIdBase documentKey _)) : _ -> do [DocumentLink] documentLinksSourceResults <- Key LocIdBase -> EntityField DocumentLink (Key LocIdBase) -> DBMonad m [DocumentLink] forall (m :: * -> *). MonadIO m => Key LocIdBase -> EntityField DocumentLink (Key LocIdBase) -> DBMonad m [DocumentLink] resolveDocumentLinks Key LocIdBase documentKey EntityField DocumentLink (Key LocIdBase) forall typ. (typ ~ Key LocIdBase) => EntityField DocumentLink typ DocumentLinkSourceId [DocumentLink] documentLinksTargetResults <- Key LocIdBase -> EntityField DocumentLink (Key LocIdBase) -> DBMonad m [DocumentLink] forall (m :: * -> *). MonadIO m => Key LocIdBase -> EntityField DocumentLink (Key LocIdBase) -> DBMonad m [DocumentLink] resolveDocumentLinks Key LocIdBase documentKey EntityField DocumentLink (Key LocIdBase) forall typ. (typ ~ Key LocIdBase) => EntityField DocumentLink typ DocumentLinkTargetId [OMSSimple] omsResults <- Key LocIdBase -> DBMonad m [OMSSimple] forall (m :: * -> *). MonadIO m => Key LocIdBase -> DBMonad m [OMSSimple] resolveOMS Key LocIdBase documentKey case LocIdBase -> LocIdBaseKindType locIdBaseKind (LocIdBase -> LocIdBaseKindType) -> LocIdBase -> LocIdBaseKindType forall a b. (a -> b) -> a -> b $ Entity LocIdBase -> LocIdBase forall record. Entity record -> record entityVal Entity LocIdBase locIdBaseEntity of DatabaseSchemaEnums.Library -> Maybe Result -> DBMonad m (Maybe Result) forall (m :: * -> *) a. Monad m => a -> m a return (Maybe Result -> DBMonad m (Maybe Result)) -> Maybe Result -> DBMonad m (Maybe Result) forall a b. (a -> b) -> a -> b $ Result -> Maybe Result forall a. a -> Maybe a Just (Result -> Maybe Result) -> Result -> Maybe Result forall a b. (a -> b) -> a -> b $ DGraph -> Result GraphQLResult.DGraphResult (DGraph -> Result) -> DGraph -> Result forall a b. (a -> b) -> a -> b $ Library -> DGraph GraphQLResultDGraph.DGLibrary (Library -> DGraph) -> Library -> DGraph forall a b. (a -> b) -> a -> b $ Entity Document -> Entity LocIdBase -> [DocumentLink] -> [DocumentLink] -> [OMSSimple] -> Library libraryToResult Entity Document documentEntity Entity LocIdBase locIdBaseEntity [DocumentLink] documentLinksSourceResults [DocumentLink] documentLinksTargetResults [OMSSimple] omsResults DatabaseSchemaEnums.NativeDocument -> do OMSSimple omsResult <- case [OMSSimple] omsResults of [] -> String -> ReaderT SqlBackend m OMSSimple forall (m :: * -> *) a. MonadFail m => String -> m a Fail.fail ("No OMS found for document " String -> String -> String forall a. [a] -> [a] -> [a] ++ String locIdVar) oms :: OMSSimple oms : _ -> OMSSimple -> ReaderT SqlBackend m OMSSimple forall (m :: * -> *) a. Monad m => a -> m a return OMSSimple oms Maybe Result -> DBMonad m (Maybe Result) forall (m :: * -> *) a. Monad m => a -> m a return (Maybe Result -> DBMonad m (Maybe Result)) -> Maybe Result -> DBMonad m (Maybe Result) forall a b. (a -> b) -> a -> b $ Result -> Maybe Result forall a. a -> Maybe a Just (Result -> Maybe Result) -> Result -> Maybe Result forall a b. (a -> b) -> a -> b $ DGraph -> Result GraphQLResult.DGraphResult (DGraph -> Result) -> DGraph -> Result forall a b. (a -> b) -> a -> b $ NativeDocument -> DGraph GraphQLResultDGraph.DGNativeDocument (NativeDocument -> DGraph) -> NativeDocument -> DGraph forall a b. (a -> b) -> a -> b $ Entity Document -> Entity LocIdBase -> [DocumentLink] -> [DocumentLink] -> OMSSimple -> NativeDocument nativeDocumentToResult Entity Document documentEntity Entity LocIdBase locIdBaseEntity [DocumentLink] documentLinksSourceResults [DocumentLink] documentLinksTargetResults OMSSimple omsResult _ -> String -> DBMonad m (Maybe Result) forall (m :: * -> *) a. MonadFail m => String -> m a Fail.fail ("Bad kind of document in database at locId " String -> String -> String forall a. [a] -> [a] -> [a] ++ String locIdVar) resolveDocumentLinks :: MonadIO m => LocIdBaseId -> EntityField DatabaseSchema.DocumentLink LocIdBaseId -> DBMonad m [GraphQLResultDocumentLink.DocumentLink] resolveDocumentLinks :: Key LocIdBase -> EntityField DocumentLink (Key LocIdBase) -> DBMonad m [DocumentLink] resolveDocumentLinks documentKey :: Key LocIdBase documentKey column :: EntityField DocumentLink (Key LocIdBase) column = do [(Entity LocIdBase, Entity LocIdBase)] documentLinksL <- SqlQuery (SqlExpr (Entity LocIdBase), SqlExpr (Entity LocIdBase)) -> ReaderT SqlBackend m [(Entity LocIdBase, Entity LocIdBase)] forall a r (m :: * -> *). (SqlSelect a r, MonadIO m) => SqlQuery a -> SqlReadT m [r] select (SqlQuery (SqlExpr (Entity LocIdBase), SqlExpr (Entity LocIdBase)) -> ReaderT SqlBackend m [(Entity LocIdBase, Entity LocIdBase)]) -> SqlQuery (SqlExpr (Entity LocIdBase), SqlExpr (Entity LocIdBase)) -> ReaderT SqlBackend m [(Entity LocIdBase, Entity LocIdBase)] forall a b. (a -> b) -> a -> b $ (InnerJoin (InnerJoin (SqlExpr (Entity DocumentLink)) (SqlExpr (Entity LocIdBase))) (SqlExpr (Entity LocIdBase)) -> SqlQuery (SqlExpr (Entity LocIdBase), SqlExpr (Entity LocIdBase))) -> SqlQuery (SqlExpr (Entity LocIdBase), SqlExpr (Entity LocIdBase)) forall a b. From a => (a -> SqlQuery b) -> SqlQuery b from ((InnerJoin (InnerJoin (SqlExpr (Entity DocumentLink)) (SqlExpr (Entity LocIdBase))) (SqlExpr (Entity LocIdBase)) -> SqlQuery (SqlExpr (Entity LocIdBase), SqlExpr (Entity LocIdBase))) -> SqlQuery (SqlExpr (Entity LocIdBase), SqlExpr (Entity LocIdBase))) -> (InnerJoin (InnerJoin (SqlExpr (Entity DocumentLink)) (SqlExpr (Entity LocIdBase))) (SqlExpr (Entity LocIdBase)) -> SqlQuery (SqlExpr (Entity LocIdBase), SqlExpr (Entity LocIdBase))) -> SqlQuery (SqlExpr (Entity LocIdBase), SqlExpr (Entity LocIdBase)) forall a b. (a -> b) -> a -> b $ \ (document_links :: SqlExpr (Entity DocumentLink) document_links `InnerJoin` loc_id_basesSource :: SqlExpr (Entity LocIdBase) loc_id_basesSource `InnerJoin` loc_id_basesTarget :: SqlExpr (Entity LocIdBase) loc_id_basesTarget) -> do SqlExpr (Value Bool) -> SqlQuery () on (SqlExpr (Entity DocumentLink) document_links SqlExpr (Entity DocumentLink) -> EntityField DocumentLink (Key LocIdBase) -> SqlExpr (Value (Key LocIdBase)) forall typ val. (PersistEntity val, PersistField typ) => SqlExpr (Entity val) -> EntityField val typ -> SqlExpr (Value typ) ^. EntityField DocumentLink (Key LocIdBase) forall typ. (typ ~ Key LocIdBase) => EntityField DocumentLink typ DocumentLinkTargetId SqlExpr (Value (Key LocIdBase)) -> SqlExpr (Value (Key LocIdBase)) -> SqlExpr (Value Bool) forall typ. PersistField typ => SqlExpr (Value typ) -> SqlExpr (Value typ) -> SqlExpr (Value Bool) ==. SqlExpr (Entity LocIdBase) loc_id_basesTarget SqlExpr (Entity LocIdBase) -> EntityField LocIdBase (Key LocIdBase) -> SqlExpr (Value (Key LocIdBase)) forall typ val. (PersistEntity val, PersistField typ) => SqlExpr (Entity val) -> EntityField val typ -> SqlExpr (Value typ) ^. EntityField LocIdBase (Key LocIdBase) forall typ. (typ ~ Key LocIdBase) => EntityField LocIdBase typ LocIdBaseId) SqlExpr (Value Bool) -> SqlQuery () on (SqlExpr (Entity DocumentLink) document_links SqlExpr (Entity DocumentLink) -> EntityField DocumentLink (Key LocIdBase) -> SqlExpr (Value (Key LocIdBase)) forall typ val. (PersistEntity val, PersistField typ) => SqlExpr (Entity val) -> EntityField val typ -> SqlExpr (Value typ) ^. EntityField DocumentLink (Key LocIdBase) forall typ. (typ ~ Key LocIdBase) => EntityField DocumentLink typ DocumentLinkSourceId SqlExpr (Value (Key LocIdBase)) -> SqlExpr (Value (Key LocIdBase)) -> SqlExpr (Value Bool) forall typ. PersistField typ => SqlExpr (Value typ) -> SqlExpr (Value typ) -> SqlExpr (Value Bool) ==. SqlExpr (Entity LocIdBase) loc_id_basesSource SqlExpr (Entity LocIdBase) -> EntityField LocIdBase (Key LocIdBase) -> SqlExpr (Value (Key LocIdBase)) forall typ val. (PersistEntity val, PersistField typ) => SqlExpr (Entity val) -> EntityField val typ -> SqlExpr (Value typ) ^. EntityField LocIdBase (Key LocIdBase) forall typ. (typ ~ Key LocIdBase) => EntityField LocIdBase typ LocIdBaseId) SqlExpr (Value Bool) -> SqlQuery () where_ (SqlExpr (Entity DocumentLink) document_links SqlExpr (Entity DocumentLink) -> EntityField DocumentLink (Key LocIdBase) -> SqlExpr (Value (Key LocIdBase)) forall typ val. (PersistEntity val, PersistField typ) => SqlExpr (Entity val) -> EntityField val typ -> SqlExpr (Value typ) ^. EntityField DocumentLink (Key LocIdBase) column SqlExpr (Value (Key LocIdBase)) -> SqlExpr (Value (Key LocIdBase)) -> SqlExpr (Value Bool) forall typ. PersistField typ => SqlExpr (Value typ) -> SqlExpr (Value typ) -> SqlExpr (Value Bool) ==. Key LocIdBase -> SqlExpr (Value (Key LocIdBase)) forall typ. PersistField typ => typ -> SqlExpr (Value typ) val Key LocIdBase documentKey) (SqlExpr (Entity LocIdBase), SqlExpr (Entity LocIdBase)) -> SqlQuery (SqlExpr (Entity LocIdBase), SqlExpr (Entity LocIdBase)) forall (m :: * -> *) a. Monad m => a -> m a return (SqlExpr (Entity LocIdBase) loc_id_basesSource, SqlExpr (Entity LocIdBase) loc_id_basesTarget) [DocumentLink] -> DBMonad m [DocumentLink] forall (m :: * -> *) a. Monad m => a -> m a return ([DocumentLink] -> DBMonad m [DocumentLink]) -> [DocumentLink] -> DBMonad m [DocumentLink] forall a b. (a -> b) -> a -> b $ ((Entity LocIdBase, Entity LocIdBase) -> DocumentLink) -> [(Entity LocIdBase, Entity LocIdBase)] -> [DocumentLink] forall a b. (a -> b) -> [a] -> [b] map ((Entity LocIdBase -> Entity LocIdBase -> DocumentLink) -> (Entity LocIdBase, Entity LocIdBase) -> DocumentLink forall a b c. (a -> b -> c) -> (a, b) -> c uncurry Entity LocIdBase -> Entity LocIdBase -> DocumentLink documentLinkToResult) [(Entity LocIdBase, Entity LocIdBase)] documentLinksL resolveOMS :: MonadIO m => LocIdBaseId -> DBMonad m [GraphQLResultOMSSimple.OMSSimple] resolveOMS :: Key LocIdBase -> DBMonad m [OMSSimple] resolveOMS documentKey :: Key LocIdBase documentKey = do [(Entity OMS, Entity LocIdBase)] omsL <- SqlQuery (SqlExpr (Entity OMS), SqlExpr (Entity LocIdBase)) -> ReaderT SqlBackend m [(Entity OMS, Entity LocIdBase)] forall a r (m :: * -> *). (SqlSelect a r, MonadIO m) => SqlQuery a -> SqlReadT m [r] select (SqlQuery (SqlExpr (Entity OMS), SqlExpr (Entity LocIdBase)) -> ReaderT SqlBackend m [(Entity OMS, Entity LocIdBase)]) -> SqlQuery (SqlExpr (Entity OMS), SqlExpr (Entity LocIdBase)) -> ReaderT SqlBackend m [(Entity OMS, Entity LocIdBase)] forall a b. (a -> b) -> a -> b $ (InnerJoin (InnerJoin (SqlExpr (Entity OMS)) (SqlExpr (Entity LocIdBase))) (SqlExpr (Entity LocIdBase)) -> SqlQuery (SqlExpr (Entity OMS), SqlExpr (Entity LocIdBase))) -> SqlQuery (SqlExpr (Entity OMS), SqlExpr (Entity LocIdBase)) forall a b. From a => (a -> SqlQuery b) -> SqlQuery b from ((InnerJoin (InnerJoin (SqlExpr (Entity OMS)) (SqlExpr (Entity LocIdBase))) (SqlExpr (Entity LocIdBase)) -> SqlQuery (SqlExpr (Entity OMS), SqlExpr (Entity LocIdBase))) -> SqlQuery (SqlExpr (Entity OMS), SqlExpr (Entity LocIdBase))) -> (InnerJoin (InnerJoin (SqlExpr (Entity OMS)) (SqlExpr (Entity LocIdBase))) (SqlExpr (Entity LocIdBase)) -> SqlQuery (SqlExpr (Entity OMS), SqlExpr (Entity LocIdBase))) -> SqlQuery (SqlExpr (Entity OMS), SqlExpr (Entity LocIdBase)) forall a b. (a -> b) -> a -> b $ \ (oms :: SqlExpr (Entity OMS) oms `InnerJoin` loc_id_basesDocument :: SqlExpr (Entity LocIdBase) loc_id_basesDocument `InnerJoin` loc_id_bases :: SqlExpr (Entity LocIdBase) loc_id_bases) -> do SqlExpr (Value Bool) -> SqlQuery () on (SqlExpr (Entity LocIdBase) loc_id_bases SqlExpr (Entity LocIdBase) -> EntityField LocIdBase (Key LocIdBase) -> SqlExpr (Value (Key LocIdBase)) forall typ val. (PersistEntity val, PersistField typ) => SqlExpr (Entity val) -> EntityField val typ -> SqlExpr (Value typ) ^. EntityField LocIdBase (Key LocIdBase) forall typ. (typ ~ Key LocIdBase) => EntityField LocIdBase typ LocIdBaseId SqlExpr (Value (Key LocIdBase)) -> SqlExpr (Value (Key LocIdBase)) -> SqlExpr (Value Bool) forall typ. PersistField typ => SqlExpr (Value typ) -> SqlExpr (Value typ) -> SqlExpr (Value Bool) ==. SqlExpr (Value (Key OMS)) -> SqlExpr (Value (Key LocIdBase)) forall a b. SqlExpr (Value a) -> SqlExpr (Value b) coerceId (SqlExpr (Entity OMS) oms SqlExpr (Entity OMS) -> EntityField OMS (Key OMS) -> SqlExpr (Value (Key OMS)) forall typ val. (PersistEntity val, PersistField typ) => SqlExpr (Entity val) -> EntityField val typ -> SqlExpr (Value typ) ^. EntityField OMS (Key OMS) forall typ. (typ ~ Key OMS) => EntityField OMS typ OMSId)) SqlExpr (Value Bool) -> SqlQuery () on (SqlExpr (Entity LocIdBase) loc_id_basesDocument SqlExpr (Entity LocIdBase) -> EntityField LocIdBase (Key LocIdBase) -> SqlExpr (Value (Key LocIdBase)) forall typ val. (PersistEntity val, PersistField typ) => SqlExpr (Entity val) -> EntityField val typ -> SqlExpr (Value typ) ^. EntityField LocIdBase (Key LocIdBase) forall typ. (typ ~ Key LocIdBase) => EntityField LocIdBase typ LocIdBaseId SqlExpr (Value (Key LocIdBase)) -> SqlExpr (Value (Key LocIdBase)) -> SqlExpr (Value Bool) forall typ. PersistField typ => SqlExpr (Value typ) -> SqlExpr (Value typ) -> SqlExpr (Value Bool) ==. SqlExpr (Entity OMS) oms SqlExpr (Entity OMS) -> EntityField OMS (Key LocIdBase) -> SqlExpr (Value (Key LocIdBase)) forall typ val. (PersistEntity val, PersistField typ) => SqlExpr (Entity val) -> EntityField val typ -> SqlExpr (Value typ) ^. EntityField OMS (Key LocIdBase) forall typ. (typ ~ Key LocIdBase) => EntityField OMS typ OMSDocumentId) SqlExpr (Value Bool) -> SqlQuery () where_ (SqlExpr (Entity LocIdBase) loc_id_basesDocument SqlExpr (Entity LocIdBase) -> EntityField LocIdBase (Key LocIdBase) -> SqlExpr (Value (Key LocIdBase)) forall typ val. (PersistEntity val, PersistField typ) => SqlExpr (Entity val) -> EntityField val typ -> SqlExpr (Value typ) ^. EntityField LocIdBase (Key LocIdBase) forall typ. (typ ~ Key LocIdBase) => EntityField LocIdBase typ LocIdBaseId SqlExpr (Value (Key LocIdBase)) -> SqlExpr (Value (Key LocIdBase)) -> SqlExpr (Value Bool) forall typ. PersistField typ => SqlExpr (Value typ) -> SqlExpr (Value typ) -> SqlExpr (Value Bool) ==. Key LocIdBase -> SqlExpr (Value (Key LocIdBase)) forall typ. PersistField typ => typ -> SqlExpr (Value typ) val Key LocIdBase documentKey) (SqlExpr (Entity OMS), SqlExpr (Entity LocIdBase)) -> SqlQuery (SqlExpr (Entity OMS), SqlExpr (Entity LocIdBase)) forall (m :: * -> *) a. Monad m => a -> m a return (SqlExpr (Entity OMS) oms, SqlExpr (Entity LocIdBase) loc_id_bases) [OMSSimple] -> DBMonad m [OMSSimple] forall (m :: * -> *) a. Monad m => a -> m a return ([OMSSimple] -> DBMonad m [OMSSimple]) -> [OMSSimple] -> DBMonad m [OMSSimple] forall a b. (a -> b) -> a -> b $ ((Entity OMS, Entity LocIdBase) -> OMSSimple) -> [(Entity OMS, Entity LocIdBase)] -> [OMSSimple] forall a b. (a -> b) -> [a] -> [b] map ((Entity OMS -> Entity LocIdBase -> OMSSimple) -> (Entity OMS, Entity LocIdBase) -> OMSSimple forall a b c. (a -> b -> c) -> (a, b) -> c uncurry Entity OMS -> Entity LocIdBase -> OMSSimple omsToResultSimple) [(Entity OMS, Entity LocIdBase)] omsL