robstewart57/hsparql — pull request #7 by haroldcarr (2014-01-10 04:58:18+00:00)
Title: Added support for SPARQL UPDATE.

An example update:

u :: Query UpdateQuery
u = do
dc <- prefix "dc" (iriRef "http://purl.org/dc/elements/1.1/")
ex <- prefix "ex" (iriRef "http://example/")

ut1 <- updateTriple (ex .:. "book1") (dc .:. "title") (T.pack "A HASKELL book")
ut2 <- updateTriple (ex .:. "book1") (dc .:. "title") (T.pack "Another HASKELL book")
ut3 <- updateTriple (ex .:. "book1") (dc .:. "title") (T.pack "Yet another HASKELL book")

return UpdateQuery { queryUpdate = [ut1,ut2,ut3] }

du :: IO ()
du = do
res <- updateQuery "http://localhost:3030/ds/update" u
putStrLn $ "result: " ++ show (res::Bool)

On the wire this look like:

POST /ds/update HTTP/1.1
Connection: close
Host: 127.0.0.1:3030
Content-Length: 217
Content-Type: application/sparql-update
User-Agent: hsparql-client

PREFIX ex: PREFIX dc: INSERT DATA { ex:book1 dc:title "A HASKELL book" . ex:book1 dc:title "Another HASKELL book" . ex:book1 dc:title "Yet another HASKELL book" . }

The response looks like (using Jena Fuseki):

HTTP/1.1 204 No Content
Fuseki-Request-ID: 27
Access-Control-Allow-Origin: *
Server: Fuseki (1.0.0)
Connection: close

Doing a query shows that all three triples have been added.

TODO:
- QueryGenerator.updateTriple : only allow Terms (right now accepts variables resulting in request time errors
- Support DELETE