on master help sign in
WIP relationVariablesInSchema working
commit0f9da75c952fa4a25002bc9105cf08dbc6ba9c2d authorAgentM <agentm@themactionfaction.com> dateSun 23 Oct 2016, 02:04 (10 years ago) parentd59899c
2 files changed+33−3
src/lib/ProjectM36/Client.hs+4−2 src/lib/ProjectM36/IsomorphicSchema.hs+29−1
src/lib/ProjectM36/Client.hs+4−2
@@ -634,10 +634,12 @@ transactionGraphAsRelation sessionId conn@(RemoteProcessConnection _ _) = remote
634634relationVariablesAsRelation :: SessionId -> Connection -> IO (Either RelationalError Relation)
635635relationVariablesAsRelation sessionId (InProcessConnection _ _ sessions _ _) = do
636636 atomically $ do
637− eSession <- sessionForSessionId sessionId sessions
637+ eSession <- sessionAndSchema sessionId sessions
638638 case eSession of
639639 Left err -> pure (Left err)
640− Right session -> pure $ R.relationVariablesAsRelation (relationVariables (Sess.concreteDatabaseContext session))
640+ Right (session, schema) -> case Schema.relationVariablesInSchema schema (Sess.concreteDatabaseContext session) of
641+ Left err -> pure (Left err)
642+ Right relvars -> pure $ R.relationVariablesAsRelation relvars
641643
642644relationVariablesAsRelation sessionId conn@(RemoteProcessConnection _ _) = remoteCall conn (RetrieveRelationVariableSummary sessionId)
643645
src/lib/ProjectM36/IsomorphicSchema.hs+29−1
@@ -2,13 +2,15 @@
22module ProjectM36.IsomorphicSchema where
33import ProjectM36.Base
44import ProjectM36.Error
5+import ProjectM36.RelationalExpression
56import Data.Maybe
67import Control.Monad
8+import Control.Monad.State
79import GHC.Generics
810import Data.Binary
911import qualified Data.Map as M
1012import qualified Data.Set as S
11−import Debug.Trace
13+--import Debug.Trace
1214-- isomorphic schemas offer bi-directional functors between two schemas
1315
1416--TODO: note that renaming a relvar should alter any stored isomorphisms as well
@@ -84,6 +86,16 @@ processDatabaseContextExprInSchema schema@(Schema morphs) dbExpr = do
8486 validRelVarNames = isomorphsInRelVarNames morphs
8587 foldM processDbExpr dbExpr morphs
8688
89+-- re-evaluate- it's not possible to display an incdep that may be for a foreign key to a relvar which is not available in the subschema!
90+-- weird compromise: allow inclusion dependencies failures not in the subschema to be propagated- in the worst case, only the inclusion dependency's name is leaked.
91+ {-
92+-- | Convert inclusion dependencies for display in a specific schema.
93+applySchemaToInclusionDependencies :: Schema -> InclusionDependencies -> Either RelationalError InclusionDependencies
94+applySchemaToInclusionDependencies (Schema morphs) incDeps =
95+ let incDepMorph incDep = --check that the mentioned relvars are in fact in the current schema
96+ M.update incDepMorph incDeps
97+ -}
98+
8799
88100-- | Morph a relational expression in one schema to another isomorphic schema.
89101relExprMorph :: SchemaIsomorph -> (RelationalExpr -> Either RelationalError RelationalExpr)
@@ -197,6 +209,22 @@ applyInclusionDependenciesSchemaIsoMorphs :: SchemaIsomorphs -> InclusionDepende
197209--add inc deps for restriction with some automatic name
198210applyInclusionDependenciesSchemaIsoMorphs morphs incDeps = undefined
199211
212+relationVariablesInSchema :: Schema -> DatabaseContext -> Either RelationalError RelationVariables
213+relationVariablesInSchema schema@(Schema morphs) context = if null morphs then --main schema
214+ pure (relationVariables context)
215+ else
216+ foldM transform M.empty morphs
217+ where
218+ transform newRvMap morph = do
219+ let rvNames = isomorphInRelVarNames morph
220+ rvAssocs <- mapM (\rv -> do
221+ expr' <- processRelationalExprInSchema schema (RelationVariable rv ())
222+ rel <- evalState (evalRelationalExpr expr') context
223+ pure (rv, rel)) rvNames
224+ pure (M.union newRvMap (M.fromList rvAssocs))
225+
226+
227+
200228{-
201229proposal
202230data DatabaseContext =