Skip to content

Commit

Permalink
#14 Begin implementing commit_history range options
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Hadley committed Feb 27, 2023
1 parent d656ddc commit 8405c18
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions paramdb/_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,14 @@ def load(self, commit_id: int | None = None) -> T:
)
return cast(T, json.loads(_decompress(data), object_hook=_from_dict))

def commit_history(self) -> list[CommitEntry]:
def commit_history(
self, number: int | None = None, *, start: int | None = None
) -> list[CommitEntry]:
"""Retrieve the commit history as a list of :py:class:`CommitEntry`."""
with self._Session() as session:
history_entries = session.execute(
select(_Snapshot.id, _Snapshot.message, _Snapshot.timestamp).order_by(
_Snapshot.id
)
select(_Snapshot.id, _Snapshot.message, _Snapshot.timestamp)
.order_by(desc(_Snapshot.id))
.limit(number)
).mappings()
return [CommitEntry(**row_mapping) for row_mapping in history_entries]

0 comments on commit 8405c18

Please sign in to comment.