summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLV-426 <lv-426@taproot.org.il>2015-01-05 01:07:15 +0200
committerLV-426 <lv-426@taproot.org.il>2015-01-05 01:11:44 +0200
commit78988be0459f7a9005030e6838b34145b4a63b83 (patch)
treea495c0b7f3c8a3705b915c1eba8642b534cc63a3 /src
parent830180d020d6be20c62dd5ca85d9872b81041412 (diff)
DBO_block_chain__list()
Diffstat (limited to 'src')
-rw-r--r--src/server/db_op.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/server/db_op.py b/src/server/db_op.py
index bc10f5dd..1a158f5b 100644
--- a/src/server/db_op.py
+++ b/src/server/db_op.py
@@ -143,6 +143,39 @@ class DBO_block_chain__commit(DB_op):
q_param_set = {'hash_value': hash_value, 'blob_value': blob_obj}
self.add_statement(q, q_param_set)
+class DBO_block_chain__list(DB_op):
+ """
+ Return block chain hash list
+
+ @return: hash list where last list item corresponds to earliest commit
+ """
+
+ def __init__(self, length_lim=None):
+ """
+ @param blob_obj: serializable blob
+ """
+ super(DBO_block_chain__list, self).__init__()
+
+ # FIXME: use cleaner query:
+ # match p=(n:__HEAD)-[r:__Parent*]->(m) return extract(n in nodes(p) | n.hash);
+ q_arr = ["match (n:__HEAD)-[r:__Parent*]->(m)",
+ "return [n.hash] + collect(m.hash)"
+ ]
+
+ if None != length_lim:
+ # inject maxHops limit if available
+ q_arr[0] = "match (n:__HEAD)-[r:__Parent*..%d]->m" % (length_lim),
+
+ q = " ".join(q_arr)
+ self.add_statement(q)
+
+ def process_result_set(self):
+ # optimize for single statement
+ for _, _, r_set in self:
+ for row in r_set:
+ for col in row:
+ return col
+
class DBO_cypher_query(DB_op):
"""
freeform cypher query