Be able to "filter()" without specifying props in "select()"
Opened this issue · 2 comments
I would like to write something like this:
api.path('/ip/route').select().where(Key('active') == True)
In other words: be able to filter without being forced to specify props in select(...).
The quick workaround I'm currently using:
class BetterQuery(librouteros.query.Query):
def __iter__(self) -> ResponseIter:
words = []
if self.keys:
keys = ','.join(str(key) for key in self.keys)
keys = f'=.proplist={keys}'
words.append(keys)
cmd = str(self.path.join('print'))
words.extend(self.query)
return iter(self.api.rawCmd(cmd, *words))
And then I can write:
BetterQuery(api.path('/ip/route'), keys=None, api=api).where(Key('active') == True)
I can modify https://github.com/luqasz/librouteros/blob/master/librouteros/api.py#L96 so it will accept 0 or more keys.
Or you can init Query object with empty tuple as keys argument.
Will this be ok ?
Yes, I think that changing "select()" (and "Query.iter") to accept 0 or more keys will make calling code more readable.
Also having a ".where()" directly on "Path" so I can write:
api.path('/ip/route').where(Key('active') == True)
instead of:
api.path('/ip/route').select().where(Key('active') == True)
would be nice I think :)