cayley-client 0.1.0.1 → 0.1.1.0
raw patch · 3 files changed
+54/−27 lines, 3 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
- Database.Cayley.Types: instance Eq CayleyConfig
+ Database.Cayley.Types: Gremlin :: QueryLang
+ Database.Cayley.Types: MQL :: QueryLang
+ Database.Cayley.Types: V1 :: APIVersion
+ Database.Cayley.Types: data APIVersion
+ Database.Cayley.Types: data QueryLang
+ Database.Cayley.Types: instance Show APIVersion
+ Database.Cayley.Types: instance Show QueryLang
- Database.Cayley.Types: CayleyConfig :: Int -> String -> String -> String -> CayleyConfig
+ Database.Cayley.Types: CayleyConfig :: Int -> String -> APIVersion -> QueryLang -> CayleyConfig
- Database.Cayley.Types: apiVersion :: CayleyConfig -> String
+ Database.Cayley.Types: apiVersion :: CayleyConfig -> APIVersion
- Database.Cayley.Types: queryLang :: CayleyConfig -> String
+ Database.Cayley.Types: queryLang :: CayleyConfig -> QueryLang
Files
- Database/Cayley/Client.hs +32/−16
- Database/Cayley/Types.hs +19/−8
- cayley-client.cabal +3/−3
Database/Cayley/Client.hs view
@@ -49,7 +49,8 @@ c <- ask r <- apiRequest m ("http://" ++ serverName c ++ "/api/v" ++- apiVersion c ++ "/query/" ++ queryLang c)+ show (apiVersion c) ++ "/query/"+ ++ show (queryLang c)) (serverPort c) (RequestBodyBS q) case r of Just a ->@@ -61,8 +62,8 @@ case A.fromJSON e of A.Success s -> return $ Left s A.Error e -> return $ Left e- Nothing ->- return $ Left "No JSON response from Cayley"+ Nothing -> return $+ Left "No JSON response from Cayley" Nothing -> return $ Left "Can't get any response from Cayley" -- | Write a 'Quad' with the given subject, predicate, object and optional@@ -100,8 +101,9 @@ write m qs = do c <- ask apiRequest- m ("http://" ++ serverName c ++- "/api/v" ++ apiVersion c ++ "/write")+ m ("http://" ++ serverName c+ ++ "/api/v" ++ show (apiVersion c)+ ++ "/write") (serverPort c) (toRequestBody qs) -- | Delete the given list of 'Quad'(s).@@ -112,8 +114,9 @@ delete m qs = do c <- ask apiRequest- m ("http://" ++ serverName c ++- "/api/v" ++ apiVersion c ++ "/delete")+ m ("http://" ++ serverName c+ ++ "/api/v" ++ show (apiVersion c)+ ++ "/delete") (serverPort c) (toRequestBody qs) @@ -123,8 +126,9 @@ where writenq m p = do c <- ask- r <- parseUrl ("http://" ++ serverName c ++ "/api/v"- ++ apiVersion c ++ "/write/file/nquad")+ r <- parseUrl ("http://" ++ serverName c+ ++ "/api/v" ++ show (apiVersion c)+ ++ "/write/file/nquad") >>= \r -> return r { port = serverPort c} t <- liftIO $ try $@@ -145,13 +149,25 @@ -- >Right 9 -- successfulResults :: Maybe A.Value -> IO (Either String Int)-successfulResults v =- case A.fromJSON (fromJust $ fromJust v ^? key "result") of- A.Success s ->- case AT.parse getAmount s of- AT.Done "" a -> return $ Right a- _ -> return $ Left "Can't get amount of successful results"- A.Error e -> return $ Left e+successfulResults m = return $+ case m of+ Just a ->+ case a ^? key "result" of+ Just v ->+ case A.fromJSON v of+ A.Success s ->+ case AT.parse getAmount s of+ AT.Done "" a -> Right a+ _ -> Left "Can't get amount of successful results"+ A.Error e -> Left e+ Nothing ->+ case a ^? key "error" of+ Just e ->+ case A.fromJSON e of+ A.Success s -> Left s+ A.Error e -> Left e+ Nothing -> Left "No JSON response from Cayley"+ Nothing -> Left "Can't get any response from Cayley" where getAmount = do AT.string "Successfully "
Database/Cayley/Types.hs view
@@ -8,19 +8,30 @@ import qualified Data.Text as T import Network.HTTP.Client (Manager) +data APIVersion = V1++instance Show APIVersion where+ show V1 = "1"++data QueryLang = Gremlin | MQL++instance Show QueryLang where+ show Gremlin = "gremlin"+ show MQL = "mql"+ data CayleyConfig = CayleyConfig- { serverPort :: Int -- ^ Default to 64210- , serverName :: String -- ^ Default to "localhost"- , apiVersion :: String -- ^ Default to "1"- , queryLang :: String -- ^ Default to "gremlin"- } deriving (Eq,Show)+ { serverPort :: Int+ , serverName :: String+ , apiVersion :: APIVersion+ , queryLang :: QueryLang+ } deriving (Show) --- | CayleyConfig { serverPort = 64210 , serverName = "localhost" , apiVersion = "1" , queryLang = "gremlin" }+-- | CayleyConfig { serverPort = 64210 , serverName = "localhost" , apiVersion = V1 , queryLang = Gremlin } defaultCayleyConfig = CayleyConfig { serverPort = 64210 , serverName = "localhost"- , apiVersion = "1"- , queryLang = "gremlin"+ , apiVersion = V1+ , queryLang = Gremlin } data CayleyConnection = CayleyConnection (CayleyConfig,Manager)
cayley-client.cabal view
@@ -1,9 +1,9 @@ name: cayley-client-version: 0.1.0.1+version: 0.1.1.0 stability: Experimental synopsis: An Haskell client for Cayley graph database description: cayley-client implements the RESTful API of the Cayley database graph.-homepage: http://mb.cybervisible.fr/cayley-client-for-haskell+homepage: https://github.com/MichelBoucey/cayley-client license: BSD3 license-file: LICENSE author: Michel Boucey@@ -15,7 +15,7 @@ Source-Repository head Type: git- Location: https://github.com/MichelBoucey/cayley-client+ Location: https://github.com/MichelBoucey/cayley-client.git library exposed-modules: Database.Cayley.Client, Database.Cayley.Types, Database.Cayley.Internal