on disk_format_proposal help sign in
project-m36/examples/SimpleClient.hs
38 lines 1.7 kB history raw
1import ProjectM36.Client
2import ProjectM36.TupleSet
3import ProjectM36.Relation.Show.Term
5main :: IO ()
6main = do
7 -- 1. create a ConnectionInfo
8 let connInfo = RemoteProcessConnectionInfo "mytestdb" (createNodeId "127.0.0.1" defaultServerPort) emptyNotificationCallback
9 -- 2. conncted to the remote database
10 eConn <- connectProjectM36 connInfo
11 case eConn of
12 Left err -> print err
13 Right conn -> do
14 --3. create a session on the "master" branch
15 eSessionId <- createSessionAtHead conn "master"
16 case eSessionId of
17 Left err -> print err
18 Right sessionId -> do
19 --4. define a new relation variable with a DatabaseContext expression
20 let attrList = [Attribute "name" TextAtomType,
21 Attribute "age" IntAtomType]
22 attrs = attributesFromList attrList
23 mErr1 <- executeDatabaseContextExpr sessionId conn (Define "person" (map NakedAttributeExpr attrList))
24 print mErr1
25 --5. add a tuple to the relation referenced by the relation variable
26 let (Right tupSet) = mkTupleSetFromList attrs [[TextAtom "Bob", IntAtom 45]]
27 mErr2 <- executeDatabaseContextExpr sessionId conn (Insert "person" (MakeStaticRelation attrs tupSet))
28 print mErr2
30 --6. execute a relational algebra query
31 let restrictionPredicate = AttributeEqualityPredicate "name" (NakedAtomExpr (TextAtom "Steve"))
32 eRel <- executeRelationalExpr sessionId conn (Restrict restrictionPredicate (RelationVariable "person" ()))
33 case eRel of
34 Left err -> print err
35 Right rel -> print (showRelation rel)
37 --7. close the connection
38 close conn