def upsert_table_stat(table_id, key, value, uid=None, commit=True, session=None): table_stat = DataTableStatistics.get(table_id=table_id, key=key, session=session) new_table_stat = DataTableStatistics(table_id=table_id, key=key, value=value, uid=uid) if table_stat: new_table_stat.id = table_stat.id session.merge(new_table_stat) else: session.add(new_table_stat) table_stat = new_table_stat if commit: session.commit() else: session.flush() session.refresh(table_stat) return table_stat
def get_table_stats(table_id): """Get all table stats by id""" with DBSession() as session: verify_data_table_permission(table_id, session=session) return DataTableStatistics.get_all(table_id=table_id, session=session)