Commit f9c8ed33 authored by Aurélien Campéas's avatar Aurélien Campéas
Browse files

command/log: add ability to query by serie name

parent 78f4e7d3a976
......@@ -29,11 +29,12 @@ def format_rev(rev):
@click.argument('db-uri')
@click.option('--limit', '-l', default=None)
@click.option('--show-diff', is_flag=True, default=False)
def log(db_uri, limit, show_diff):
@click.option('--serie', '-s', multiple=True)
def log(db_uri, limit, show_diff, serie):
engine = create_engine(db_uri)
tsh = TimeSerie()
for rev in tsh.log(engine, limit=limit, diff=show_diff):
for rev in tsh.log(engine, limit=limit, diff=show_diff, names=serie):
rev['names'] = ','.join(rev['names'])
print(format_rev(rev))
print()
......
......@@ -91,6 +91,10 @@ def test_changeset(engine):
'names': ['ts_values']}
] == log
log = tso.log(engine, names=['ts_othervalues'])
assert len(log) == 1
assert log[0]['rev'] == 1
def test_tstamp_roundtrip(engine):
tso = TimeSerie()
......
......@@ -187,7 +187,7 @@ class TimeSerie(object):
).where(tstable.c.csid == cset.c.id)
return cnx.execute(sql).scalar()
def log(self, cnx, limit=0, diff=False):
def log(self, cnx, limit=0, diff=False, names=None):
"""Build a structure showing the history of all the series in the db,
per changeset, in chronological order.
"""
......@@ -200,6 +200,9 @@ class TimeSerie(object):
if limit:
sql = sql.limit(limit)
if names:
sql = sql.where(reg.c.name.in_(names))
sql = sql.where(cset.c.id == cset_series.c.csid
).where(cset_series.c.serie == reg.c.name)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment