-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
version 0.0.0.14: merge graphs and return properties, refactoring (#21)
* version 0.0.0.13: `ToJSON` and `FromJSON` instances for `Persisted a` * merge graphs * version 0.0.0.14: merge graphs and return properties, refactoring
- Loading branch information
1 parent
1ffc1c2
commit 7d33dfa
Showing
28 changed files
with
722 additions
and
448 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,3 +19,4 @@ cabal.sandbox.config | |
.stack-work/ | ||
cabal.project.local | ||
.HTF/ | ||
*.swo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,13 @@ | ||
module Database.Bolt.Extras | ||
( | ||
module Database.Bolt.Extras.Graph | ||
, module Database.Bolt.Extras.Utils | ||
, module Database.Bolt.Extras.Template | ||
, module Database.Bolt.Extras.Query | ||
, module Database.Bolt.Extras.Persisted | ||
module Database.Bolt.Extras.Internal.Condition | ||
, module Database.Bolt.Extras.Internal.Persisted | ||
, module Database.Bolt.Extras.Internal.Cypher | ||
, module Database.Bolt.Extras.Internal.Types | ||
) where | ||
|
||
import Database.Bolt.Extras.Graph | ||
import Database.Bolt.Extras.Utils | ||
import Database.Bolt.Extras.Template | ||
import Database.Bolt.Extras.Query | ||
import Database.Bolt.Extras.Persisted | ||
import Database.Bolt.Extras.Internal.Condition | ||
import Database.Bolt.Extras.Internal.Cypher | ||
import Database.Bolt.Extras.Internal.Instances () | ||
import Database.Bolt.Extras.Internal.Persisted | ||
import Database.Bolt.Extras.Internal.Types |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,14 @@ | ||
{-# LANGUAGE TemplateHaskell #-} | ||
|
||
module Database.Bolt.Extras.Graph | ||
( | ||
Graph (..) | ||
, emptyGraph | ||
, addNode | ||
, addRelation | ||
module Database.Bolt.Extras.Graph.Internal.AbstractGraph | ||
, module Database.Bolt.Extras.Graph.Internal.Class | ||
, module Database.Bolt.Extras.Graph.Internal.Get | ||
, module Database.Bolt.Extras.Graph.Internal.GraphQuery | ||
, module Database.Bolt.Extras.Graph.Internal.Put | ||
) where | ||
|
||
import Control.Lens (makeLenses, over) | ||
import Data.Map.Strict (Map, insert, notMember) | ||
import Text.Printf (printf) | ||
|
||
-- | 'Graph' contains vertices, that are parameterized by some type @n@, and relations, | ||
-- that parameterized by pair of type @n@. This pair represents vertices, that are connected with this relation. | ||
-- | ||
data Graph n a b = Graph { _vertices :: Map n a | ||
, _relations :: Map (n, n) b | ||
} deriving (Show) | ||
|
||
makeLenses ''Graph | ||
|
||
-- | Creates empty graph. | ||
-- | ||
emptyGraph :: Ord n => Graph n a b | ||
emptyGraph = Graph mempty mempty | ||
|
||
-- | Adds node to graph by it's @name@ and @node@ content. | ||
-- If graph already contains vertex with given @name@, error will be thrown. | ||
-- | ||
addNode :: (Show n, Ord n) => n -> a -> Graph n a b -> Graph n a b | ||
addNode name node graph = if name `notMember` _vertices graph | ||
then over vertices (insert name node) graph | ||
else error . printf "vertex with name %s key already exists" . show $ name | ||
|
||
-- | Adds relation to graph by @startName@ of vertex, @endName@ of vertex, and @rel@ with relation content. | ||
-- If graph already contains relation with given @(startName, endName)@, error will be thrown. | ||
-- | ||
addRelation :: (Show n, Ord n) => n -> n -> b -> Graph n a b -> Graph n a b | ||
addRelation startName endName rel graph = if (startName, endName) `notMember` _relations graph | ||
then over relations (insert (startName, endName) rel) graph | ||
else error $ printf "relation with names (%s, %s) already exists" (show startName) (show endName) | ||
import Database.Bolt.Extras.Graph.Internal.AbstractGraph | ||
import Database.Bolt.Extras.Graph.Internal.Class | ||
import Database.Bolt.Extras.Graph.Internal.Get | ||
import Database.Bolt.Extras.Graph.Internal.GraphQuery | ||
import Database.Bolt.Extras.Graph.Internal.Put |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
{-# LANGUAGE TemplateHaskell #-} | ||
|
||
module Database.Bolt.Extras.Graph.Internal.AbstractGraph | ||
( | ||
Graph (..) | ||
, vertices | ||
, relations | ||
, emptyGraph | ||
, addNode | ||
, addRelation | ||
) where | ||
|
||
import Control.Lens (makeLenses, over) | ||
import Data.Map.Strict (Map, insert, notMember) | ||
import Text.Printf (printf) | ||
|
||
-- | 'Graph' contains vertices, that are parameterized by some type @n@, and relations, | ||
-- that parameterized by pair of type @n@. This pair represents vertices, that are connected with this relation. | ||
-- | ||
data Graph n a b = Graph { _vertices :: Map n a | ||
, _relations :: Map (n, n) b | ||
} deriving (Show) | ||
|
||
makeLenses ''Graph | ||
|
||
-- | Creates empty graph. | ||
-- | ||
emptyGraph :: Ord n => Graph n a b | ||
emptyGraph = Graph mempty mempty | ||
|
||
-- | Adds node to graph by it's @name@ and @node@ content. | ||
-- If graph already contains vertex with given @name@, error will be thrown. | ||
-- | ||
addNode :: (Show n, Ord n) => n -> a -> Graph n a b -> Graph n a b | ||
addNode name node graph = if name `notMember` _vertices graph | ||
then over vertices (insert name node) graph | ||
else error . printf "vertex with name %s key already exists" . show $ name | ||
|
||
-- | Adds relation to graph by @startName@ of vertex, @endName@ of vertex, and @rel@ with relation content. | ||
-- If graph already contains relation with given @(startName, endName)@, error will be thrown. | ||
-- | ||
addRelation :: (Show n, Ord n) => n -> n -> b -> Graph n a b -> Graph n a b | ||
addRelation startName endName rel graph = if (startName, endName) `notMember` _relations graph | ||
then over relations (insert (startName, endName) rel) graph | ||
else error $ printf "relation with names (%s, %s) already exists" (show startName) (show endName) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
module Database.Bolt.Extras.Graph.Internal.Class | ||
( | ||
Requestable (..) | ||
, Returnable (..) | ||
, Extractable (..) | ||
) where | ||
|
||
import Control.Monad.IO.Class (MonadIO) | ||
import Data.Text (Text) | ||
import Database.Bolt (BoltActionT, Record) | ||
|
||
-- | Class describes entity, which can be requested. | ||
-- | ||
class Requestable a where | ||
-- | Condition for BoltId like "ID(a) = b" if BoltId is presented. | ||
maybeBoltIdCond :: a -> Maybe Text | ||
-- | How to convert entity to Cypher. | ||
request :: a -> Text | ||
|
||
-- | Class describes entity, which can be returned. | ||
-- | ||
class Returnable a where | ||
-- | How to return entity in the Cypher. | ||
return' :: a -> Text | ||
|
||
-- | Class describes entity, which can be extracted from records by name. | ||
-- | ||
class Extractable a where | ||
extract :: MonadIO m => Text -> [Record] -> BoltActionT m [a] |
Oops, something went wrong.