diff options
author | Nicholas Car <nicholas.car@surroundaustralia.com> | 2021-06-27 23:44:04 +1000 |
---|---|---|
committer | Nicholas Car <nicholas.car@surroundaustralia.com> | 2021-06-27 23:44:04 +1000 |
commit | 2a702e726c1ce870de45b29edee70ade0915d72b (patch) | |
tree | 0115dc7334d9b1837643456e79d7e9a716b2187a /examples | |
parent | dc274ef6edfb04b39d53d535b2a75b4f6f9af62f (diff) | |
download | rdflib-2a702e726c1ce870de45b29edee70ade0915d72b.tar.gz |
added tests for BerkeleyDB store
Diffstat (limited to 'examples')
-rw-r--r-- | examples/berkeleydb_example.py | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/examples/berkeleydb_example.py b/examples/berkeleydb_example.py index eec5464e..abeef3ba 100644 --- a/examples/berkeleydb_example.py +++ b/examples/berkeleydb_example.py @@ -1,6 +1,13 @@ """ -A simple example showing how to use a BerkeleyDB store to do on-disk -persistence. +A simple example showing how to use a BerkeleyDB store to do on-disk persistence: + +* creating a ConjunctiveGraph using the BerkeleyDB Store +* adding triples to it +* counting them +* closing the store, emptying the graph +* re-opening the store using the same DB files +* getting the same count of triples as before + """ from rdflib import ConjunctiveGraph, Namespace, Literal @@ -8,21 +15,27 @@ from rdflib.store import NO_STORE, VALID_STORE from tempfile import mktemp + if __name__ == "__main__": path = mktemp() - # Open previously created store, or create it if it doesn't exist yet + # Declare we are using a BerkeleyDB Store graph = ConjunctiveGraph("BerkeleyDB") + # Open previously created store, or create it if it doesn't exist yet + # (always doesn't exist in this example as using temp file location) rt = graph.open(path, create=False) if rt == NO_STORE: # There is no underlying BerkeleyDB infrastructure, so create it + print("Creating new DB") graph.open(path, create=True) else: + print("Using existing DB") assert rt == VALID_STORE, "The underlying store is corrupt" print("Triples in graph before add:", len(graph)) + print("(will always be 0 when using temp file for DB)") # Now we'll add some triples to the graph & commit the changes EG = Namespace("http://example.net/test/") @@ -34,6 +47,7 @@ if __name__ == "__main__": graph.commit() print("Triples in graph after add:", len(graph)) + print("(should be 2)") # display the graph in Turtle print(graph.serialize()) @@ -49,6 +63,7 @@ if __name__ == "__main__": graph.open(path, create=False) print("Triples still in graph:", len(graph)) + print("(should still be 2)") graph.close() |