summaryrefslogtreecommitdiff
path: root/src-py
diff options
context:
space:
mode:
authorLV-426 <lv-426@taproot.org.il>2014-09-24 02:00:18 +0300
committerLV-426 <lv-426@taproot.org.il>2014-09-24 02:00:18 +0300
commit391d02c6770fd9b7dea5014bfa974f675388c5c6 (patch)
tree784e1718d5409251222ba8e57bfdc9e9108a12c8 /src-py
parent68b2334cd8484ac72814060ced5703a2f94b57d7 (diff)
db_controller.DBO_add_node_set.__init__ - add optional
input_to_DB_property_map property mapping argument
Diffstat (limited to 'src-py')
-rw-r--r--src-py/db_controller.py25
1 files changed, 14 insertions, 11 deletions
diff --git a/src-py/db_controller.py b/src-py/db_controller.py
index 6ad77b01..d7492e95 100644
--- a/src-py/db_controller.py
+++ b/src-py/db_controller.py
@@ -79,20 +79,18 @@ class DBO_add_node_set(DB_op):
"""
DB op: add node set
- @param node_map: type to node list map
+ @param node_map: node-type to node list map
+ @input_to_DB_property_map: optional function which takes a map of input properties and returns a map of DB properties - use to map input schemas to DB schemas
+
"""
- def __init__(self, node_map):
+ def __init__(self, node_map, input_to_DB_property_map=lambda _: _):
super(DBO_add_node_set, self).__init__()
self.node_map = node_map
for type, n_set in self.node_map.items():
q = "create (n:{0} {{prop_dict}}) return id(n)".format(type)
- for n in n_set:
- #
- # any translation between how we accept node data
- # and how we store them should go here
- #
- p = {'prop_dict' : { 'name' : n['name']}}
+ for n_prop_dict in n_set:
+ p = {'prop_dict' : input_to_DB_property_map(n_prop_dict)}
self.add_statement(q, p)
def on_success(self, data):
@@ -140,7 +138,7 @@ class DBO_load_node_id_set(DB_op):
nid = k['row'][0]
id_set.append(nid)
- log.debug('loaded node-set: ids: ' + str(id_set))
+ log.debug('loaded node id set: ' + str(id_set))
return id_set
class DB_Controller:
@@ -150,18 +148,23 @@ class DB_Controller:
def __init__(self, config):
self.config = config
+ def log_committed_queries(self, statement_set):
+ for sp_dict in statement_set['statements']:
+ log.debug('\tq: {0}'.format(sp_dict['statement']))
+
def exec_op(self, op):
"""
execute operation within a DB transaction
"""
tx_base_url = self.config.db_base_url + '/db/data/transaction'
- data = dbu.statement_set_to_REST_form(op.statement_set)
+ statement_set = dbu.statement_set_to_REST_form(op.statement_set)
try:
op.begin(tx_base_url)
tx_url = "{0}/{1}".format(tx_base_url, op.tx_id)
- ret_tx = dbu.post_neo4j(tx_url, data)
+ ret_tx = dbu.post_neo4j(tx_url, statement_set)
op.commit()
+ self.log_committed_queries(statement_set)
return op.on_success(ret_tx)
except Exception as e:
log.error(e.message)