diff --git a/grand/backends/_sqlbackend.py b/grand/backends/_sqlbackend.py index 8d565e3..8a6591d 100644 --- a/grand/backends/_sqlbackend.py +++ b/grand/backends/_sqlbackend.py @@ -671,3 +671,9 @@ def ingest_from_edgelist_dataframe( "edge_count": len(edgelist), "edge_duration": edge_toc, } + + def commit(self): + self._connection.commit() + + def close(self): + self._connection.close() \ No newline at end of file diff --git a/grand/backends/test_backends.py b/grand/backends/test_backends.py index d08fcac..5b345e6 100644 --- a/grand/backends/test_backends.py +++ b/grand/backends/test_backends.py @@ -131,6 +131,29 @@ ), ) +# @pytest.mark.parametrize("backend", backend_test_params) +class TestBackendPersistence: + def test_sqlite_persistence(self): + if not _CAN_IMPORT_SQL: + return + + dbpath = "grand_peristence_test_temp.db" + url = "sqlite:///"+dbpath + + #arrange + backend = SQLBackend(db_url=url, directed=True) + node0 = backend.add_node("A",{"foo":"bar"}) + backend.commit() + backend.close() + #act + backend = SQLBackend(db_url=url, directed=True) + nodes = list(backend.all_nodes_as_iterable()) + #assert + assert node0 in nodes + #cleanup + os.remove(dbpath) + + @pytest.mark.parametrize("backend", backend_test_params) class TestBackend: