on master help sign in
update examples due to refactoring
commit929580f0a95441f3351ae6f4543ecad25043e591 authorAgentM <agentm@themactionfaction.com> dateSun 3 Apr 2016, 16:47 (11 years ago) parent31bb6a0
2 files changed+10−10
examples/PersistClient.hs+6−5 examples/SimpleClient.hs+4−5
examples/PersistClient.hs+6−5
@@ -3,7 +3,7 @@
33{- A simple example of using the persistent-ProjectM36 driver. -}
44import Database.Persist.ProjectM36 hiding (executeDatabaseContextExpr)
55import ProjectM36.Client
6−import ProjectM36.Atom
6+import ProjectM36.DataTypes.Primitive
77import System.Exit
88import System.IO
99import Database.Persist
@@ -27,10 +27,11 @@ errDie out = hPutStrLn stderr out >> exitFailure
2727
2828defPersonRel :: SessionId -> Connection -> IO ()
2929defPersonRel sessionId conn = do
30− maybeErr <- executeDatabaseContextExpr sessionId conn (Define "person" (attributesFromList [Attribute "name" stringAtomType, Attribute "age" intAtomType, Attribute "id" stringAtomType]))
31− case maybeErr of
32− Nothing -> return ()
33− Just err -> errDie (show err)
30+ let attrList = [Attribute "name" textAtomType, Attribute "age" intAtomType, Attribute "id" textAtomType]
31+ maybeErr <- executeDatabaseContextExpr sessionId conn (Define "person" (map NakedAttributeExpr attrList))
32+ case maybeErr of
33+ Nothing -> return ()
34+ Just err -> errDie (show err)
3435
3536main :: IO ()
3637main = do
examples/SimpleClient.hs+4−5
@@ -21,11 +21,10 @@ main = do
2121 Left err -> putStrLn (show err)
2222 Right sessionId -> do
2323 --4. define a new relation variable with a DatabaseContext expression
24− let attrExprs = [AttributeAndTypeNameExpr "name" (PrimitiveTypeConstructor "Text" textAtomType),
25− AttributeAndTypeNameExpr "age" (PrimitiveTypeConstructor "Int" intAtomType)]
26− attrs = attributesFromList [Attribute "name" textAtomType,
27− Attribute "age" intAtomType]
28− mErr1 <- executeDatabaseContextExpr sessionId conn (Define "person" attrExprs)
24+ let attrList = [Attribute "name" textAtomType,
25+ Attribute "age" intAtomType]
26+ attrs = attributesFromList attrList
27+ mErr1 <- executeDatabaseContextExpr sessionId conn (Define "person" (map NakedAttributeExpr attrList))
2928 putStrLn (show mErr1)
3029 --5. add a tuple to the relation referenced by the relation variable
3130 let (Right tupSet) = mkTupleSetFromList attrs [[textAtom "Bob", intAtom 45]]