Skip to content

Commit

Permalink
Add ordering sequence to params in query (#73)
Browse files Browse the repository at this point in the history
* Add ordering sequence to params

Makes possible to add ordering sequence to Query. Fixes #72

Signed-off-by: Rafik Naccache <rafik@fekr.tech>

* Add :param ordering_sequence:

Signed-off-by: Rafik Naccache <rafik@fekr.tech>

* Fix wrong example for :param ordering_sequence:

Signed-off-by: Rafik Naccache <rafik@fekr.tech>

* fix wrong ordering message construction in query

After more documentation I got to the way to construct to ordering object

Signed-off-by: Rafik Naccache <rafik@fekr.tech>

* remove redundant OR clause to manage ordering_sequence

Signed-off-by: Rafik Naccache <rafik@fekr.tech>
  • Loading branch information
turbopape authored Jul 13, 2021
1 parent 92d8177 commit 41a724b
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion iroha/iroha.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ def command(name, **kwargs):
return command_wrapper

def query(self, name, counter=1, creator_account=None,
created_time=None, page_size=None, first_tx_hash=None,
created_time=None, page_size=None, first_tx_hash=None, ordering_sequence=None,
**kwargs):
"""
Creates a protobuf query with specified set of entities
Expand All @@ -254,6 +254,8 @@ def query(self, name, counter=1, creator_account=None,
:param created_time: query creation timestamp in milliseconds
:param page_size: a non-zero positive number, size of result rowset for queries with pagination
:param first_tx_hash: optional hash of a transaction that will be the beginning of the next page
:param ordering_sequence: an array representing an ordering spec, containing a sequence of fields and directions
example: [[queries_pb2.kCreatedTime, queries_pb2.kAscending],[queries_pb2.kPosition, queries_pb2.kDescending]]
:param kwargs: query arguments as they defined in schema
:return: a proto query
"""
Expand All @@ -269,6 +271,13 @@ def query(self, name, counter=1, creator_account=None,
pagination_meta.page_size = page_size
if first_tx_hash:
pagination_meta.first_tx_hash = first_tx_hash
if ordering_sequence:
ordering = queries_pb2.Ordering()
for ordering_elt in ordering_sequence:
ordering_field = ordering.sequence.add()
ordering_field.field = ordering_elt[0]
ordering_field.direction = ordering_elt[1]
pagination_meta.ordering.CopyFrom(ordering)

meta = queries_pb2.QueryPayloadMeta()
meta.created_time = created_time
Expand Down

0 comments on commit 41a724b

Please sign in to comment.