summaryrefslogtreecommitdiff
path: root/src-py
diff options
context:
space:
mode:
authorLV-426 <lv-426@taproot.org.il>2014-10-27 12:31:48 +0200
committerLV-426 <lv-426@taproot.org.il>2014-10-27 12:31:48 +0200
commit9b89717dfc286af0127108b221630f9c1d054971 (patch)
treeea1dd3284694084e7e5f5208e04d6293c8bed36b /src-py
parent4ef04b9a1758ccd5bfc6f355a821de852efebe68 (diff)
DBO_rm_node_set & test
Diffstat (limited to 'src-py')
-rw-r--r--src-py/db_controller.py19
-rw-r--r--src-py/test_db_controller.py31
2 files changed, 50 insertions, 0 deletions
diff --git a/src-py/db_controller.py b/src-py/db_controller.py
index 84c0743e..c73a6882 100644
--- a/src-py/db_controller.py
+++ b/src-py/db_controller.py
@@ -316,6 +316,25 @@ class DBO_match_link_id_set(DB_op):
self.add_statement(q, q_params)
+class DBO_rm_node_set(DB_op):
+ def __init__(self, id_set, rm_links=False):
+ super(DBO_rm_node_set, self).__init__()
+
+ if rm_links:
+ q_arr = ['match (n)',
+ 'where n.id in ' + str(id_set),
+ 'optional match (n)-[r]-()',
+ 'delete n,r'
+ ]
+ else:
+ q_arr = ['match (n)',
+ 'where n.id in ' + str(id_set),
+ 'delete n'
+ ]
+
+ q = ' '.join(q_arr) # TODO: use id param upon neo4j support: q_params = {'id_set': id_set}
+ self.add_statement(q)
+
class DB_Controller:
"""
neo4j DB controller
diff --git a/src-py/test_db_controller.py b/src-py/test_db_controller.py
index 54952df1..4b17ad3c 100644
--- a/src-py/test_db_controller.py
+++ b/src-py/test_db_controller.py
@@ -259,6 +259,37 @@ class TestDBController(unittest.TestCase):
op = dbc.DBO_attr_diff_commit(attr_diff)
n_map = self.db_ctl.exec_op(op)
+ def test_rm_node_set(self):
+ n_0_id = rand_id()
+ n_1_id = rand_id()
+ n_2_id = rand_id()
+ n_3_id = rand_id()
+ n_T = 'T_test_rm_node_set'
+
+ n_set = [{'__type': n_T, 'id': n_0_id },
+ {'__type': n_T, 'id': n_1_id },
+ {'__type': n_T, 'id': n_2_id },
+ {'__type': n_T, 'id': n_3_id }]
+ l_set = [{'__type': n_T, '__src': n_2_id, '__dst': n_2_id},
+ {'__type': n_T, '__src': n_2_id, '__dst': n_3_id}]
+
+ topo_diff = Topo_Diff(node_set_add=n_set,
+ link_set_add=l_set)
+
+ op = dbc.DBO_topo_diff_commit(topo_diff)
+ self.db_ctl.exec_op(op)
+
+ op = dbc.DBO_rm_node_set([n_0_id, n_1_id])
+ self.db_ctl.exec_op(op)
+
+ op = dbc.DBO_rm_node_set([n_2_id, n_3_id], rm_links=True)
+ self.db_ctl.exec_op(op)
+
+ # assert all deleted
+ op = dbc.DBO_match_node_id_set(filter_type=n_T)
+ id_set = self.db_ctl.exec_op(op)
+ self.assertEqual(len(id_set), 0)
+
def tearDown(self): pass
if __name__ == "__main__":