Adds .update() to Python bindings

pull/51/head
Tpt 4 years ago
parent 535e5e3053
commit 7f1309c94a
  1. 37
      python/src/memory_store.rs
  2. 38
      python/src/sled_store.rs
  3. 17
      python/tests/test_store.py

@ -176,6 +176,43 @@ impl PyMemoryStore {
query_results_to_python(py, results) query_results_to_python(py, results)
} }
/// Executes a `SPARQL 1.1 update <https://www.w3.org/TR/sparql11-update/>`_.
///
/// :param update: the update to execute
/// :type update: str
/// :raises SyntaxError: if the provided update is invalid
///
/// The `LOAD operation <https://www.w3.org/TR/sparql11-update/#load>`_ is not supported yet.
/// The store does not track the existence of empty named graphs.
/// This method has no ACID guarantees.
///
/// ``INSERT DATA`` update:
///
/// >>> store = MemoryStore()
/// >>> store.update('INSERT DATA { <http://example.com> <http://example.com/p> "1" }')
/// >>> list(store)
/// [<Quad subject=<NamedNode value=http://example.com> predicate=<NamedNode value=http://example.com/p> object=<Literal value=1 datatype=<NamedNode value=http://www.w3.org/2001/XMLSchema#string>> graph_name=<DefaultGraph>>]
///
/// ``DELETE DATA`` update:
///
/// >>> store = MemoryStore()
/// >>> store.add(Quad(NamedNode('http://example.com'), NamedNode('http://example.com/p'), Literal('1')))
/// >>> store.update('DELETE DATA { <http://example.com> <http://example.com/p> "1" }')
/// >>> list(store)
/// []
///
/// ``DELETE`` update:
///
/// >>> store = MemoryStore()
/// >>> store.add(Quad(NamedNode('http://example.com'), NamedNode('http://example.com/p'), Literal('1')))
/// >>> store.update('DELETE WHERE { <http://example.com> ?p ?o }')
/// >>> list(store)
/// []
#[text_signature = "($self, update)"]
fn update(&self, update: &str) -> PyResult<()> {
self.inner.update(update).map_err(map_evaluation_error)
}
/// Loads an RDF serialization into the store /// Loads an RDF serialization into the store
/// ///
/// It currently supports the following formats: /// It currently supports the following formats:

@ -191,6 +191,44 @@ impl PySledStore {
query_results_to_python(py, results) query_results_to_python(py, results)
} }
/// Executes a `SPARQL 1.1 update <https://www.w3.org/TR/sparql11-update/>`_.
///
/// :param update: the update to execute
/// :type update: str
/// :raises SyntaxError: if the provided update is invalid
/// :raises IOError: if an I/O error happens while reading the store
///
/// The `LOAD operation <https://www.w3.org/TR/sparql11-update/#load>`_ is not supported yet.
/// The store does not track the existence of empty named graphs.
/// This method has no ACID guarantees.
///
/// ``INSERT DATA`` update:
///
/// >>> store = MemoryStore()
/// >>> store.update('INSERT DATA { <http://example.com> <http://example.com/p> "1" }')
/// >>> list(store)
/// [<Quad subject=<NamedNode value=http://example.com> predicate=<NamedNode value=http://example.com/p> object=<Literal value=1 datatype=<NamedNode value=http://www.w3.org/2001/XMLSchema#string>> graph_name=<DefaultGraph>>]
///
/// ``DELETE DATA`` update:
///
/// >>> store = MemoryStore()
/// >>> store.add(Quad(NamedNode('http://example.com'), NamedNode('http://example.com/p'), Literal('1')))
/// >>> store.update('DELETE DATA { <http://example.com> <http://example.com/p> "1" }')
/// >>> list(store)
/// []
///
/// ``DELETE`` update:
///
/// >>> store = MemoryStore()
/// >>> store.add(Quad(NamedNode('http://example.com'), NamedNode('http://example.com/p'), Literal('1')))
/// >>> store.update('DELETE WHERE { <http://example.com> ?p ?o }')
/// >>> list(store)
/// []
#[text_signature = "($self, update)"]
fn update(&self, update: &str) -> PyResult<()> {
self.inner.update(update).map_err(map_evaluation_error)
}
/// Loads an RDF serialization into the store /// Loads an RDF serialization into the store
/// ///
/// It currently supports the following formats: /// It currently supports the following formats:

@ -146,6 +146,23 @@ class TestAbstractStore(unittest.TestCase, ABC):
) )
self.assertEqual(len(list(results)), 2) self.assertEqual(len(list(results)), 2)
def test_update_insert_data(self):
store = self.store()
store.update('INSERT DATA { <http://foo> <http://foo> <http://foo> }')
self.assertEqual(len(store), 1)
def test_update_delete_data(self):
store = self.store()
store.add(Quad(foo, foo, foo))
store.update('DELETE DATA { <http://foo> <http://foo> <http://foo> }')
self.assertEqual(len(store), 0)
def test_update_delete_where(self):
store = self.store()
store.add(Quad(foo, foo, foo))
store.update('DELETE WHERE { ?v ?v ?v }')
self.assertEqual(len(store), 0)
def test_load_ntriples_to_default_graph(self): def test_load_ntriples_to_default_graph(self):
store = self.store() store = self.store()
store.load( store.load(

Loading…
Cancel
Save