on master help sign in
add SimpleClient example
commit8e8df3439f7d291d90a550d41bd2151b4291e7a3 authorAgentM <agentm@themactionfaction.com> dateTue 17 Nov 2015, 22:58 (11 years ago) parentb56c1d5
2 files changed+43−3
examples/SimpleClient.hs+34 project-m36.cabal+9−3
examples/SimpleClient.hsnew file+34
@@ -0,0 +1,34 @@
1+{-# LANGUAGE OverloadedStrings #-}
2+import ProjectM36.Client
3+import ProjectM36.TupleSet
4+import ProjectM36.Atom
5+import ProjectM36.Base
6+import ProjectM36.Relation.Show.Term
7+
8+main :: IO ()
9+main = do
10+ -- 1. create a ConnectionInfo
11+ let connInfo = RemoteProcessConnectionInfo "mytestdb" (createNodeId "127.0.0.1" defaultServerPort)
12+ -- 2. conncted to the remote database
13+ eConn <- connectProjectM36 connInfo
14+ case eConn of
15+ Left err -> putStrLn (show err)
16+ Right conn -> do
17+ --3. define a new relation variable with a DatabaseContext expression
18+ let attrs = attributesFromList [Attribute "name" stringAtomType, Attribute "age" intAtomType]
19+ mErr1 <- executeDatabaseContextExpr conn (Define "person" attrs)
20+ putStrLn (show mErr1)
21+ --4. add a tuple to the relation referenced by the relation variable
22+ let (Right tupSet) = mkTupleSetFromList attrs [[stringAtom "Bob", intAtom 45]]
23+ mErr2 <- executeDatabaseContextExpr conn (Insert "person" (MakeStaticRelation attrs tupSet))
24+ putStrLn (show mErr2)
25+
26+ --5. execute a relational algebra query
27+ let restrictionPredicate = AttributeEqualityPredicate "name" (NakedAtomExpr (stringAtom "Steve"))
28+ eRel <- executeRelationalExpr conn (Restrict restrictionPredicate (RelationVariable "person"))
29+ case eRel of
30+ Left err -> putStrLn (show err)
31+ Right rel -> putStrLn (show $ showRelation rel)
32+
33+ --6. close the connection
34+ close conn
project-m36.cabal+9−3
@@ -262,10 +262,16 @@ benchmark bench
262262 Build-Depends: base, HUnit, Cabal, containers, hashable, unordered-containers, mtl, vector, vector-binary-instances, time, hashable-time, bytestring, network-transport-tcp, distributed-process, distributed-process-extras, distributed-process-client-server, uuid, stm, deepseq, deepseq-generics, binary, unix, parallel, cassava, attoparsec, gnuplot, directory, temporary, haskeline, parsec, text, base64-bytestring, data-interval, filepath, criterion
263263 GHC-Options: -Wall -rtsopts
264264
265−Test-Suite test-daemon
265+Test-Suite test-server
266266 Default-Language: Haskell2010
267267 type: exitcode-stdio-1.0
268− main-is: test/Daemon/Main.hs
268+ main-is: test/Server/Main.hs
269269 Build-Depends: base, HUnit, Cabal, containers, hashable, unordered-containers, mtl, vector, vector-binary-instances, time, hashable-time, bytestring, network-transport-tcp, distributed-process, distributed-process-extras, distributed-process-client-server, uuid, stm, deepseq, deepseq-generics, binary, unix, parallel, cassava, attoparsec, gnuplot, directory, temporary, haskeline, parsec, text, base64-bytestring, data-interval, filepath, transformers
270270 GHC-Options: -Wall
271− C-sources: ProjectM36/DirectoryFsync.c
271+ C-sources: ProjectM36/DirectoryFsync.c
272+
273+Executable SimpleClient
274+ Default-Language: Haskell2010
275+ Build-Depends: base, HUnit, Cabal, containers, hashable, unordered-containers, mtl, vector, vector-binary-instances, time, hashable-time, bytestring, network-transport-tcp, distributed-process, distributed-process-extras, distributed-process-client-server, uuid, stm, deepseq, deepseq-generics, binary, unix, parallel, cassava, attoparsec, gnuplot, directory, temporary, haskeline, parsec, text, base64-bytestring, data-interval, filepath, transformers
276+ Main-Is: examples/SimpleClient.hs
277+ GHC-Options: -Wall