Skip to content

Commit

Permalink
added get_all to IPC methods
Browse files Browse the repository at this point in the history
  • Loading branch information
msrocka committed Sep 24, 2018
1 parent eea6cec commit 0a77275
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions olca/ipc.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,20 @@ def get(self, model_type: Type[T], model_id: str) -> T:
e.from_json(result)
return e

def get_all(self, model_type: Type[T]) -> Generator[T, None, None]:
"""
Returns a generator for all instances of the given type from the
database. Note that this will first fetch the complete JSON list from
the IPC server and thus should be only used when a small amount of
instances is expected as return value.
"""
params = {'@type': model_type.__name__}
result = self.__post('get/models', params)
for r in result:
e = model_type()
e.from_json(r)
yield e

def find(self, model_type, name: str) -> schema.Ref:
"""Searches for a data set with the given type and name.
Expand Down

0 comments on commit 0a77275

Please sign in to comment.