From 8405c18a8288ce572df2efcdb8dcabc6027c6a5b Mon Sep 17 00:00:00 2001 From: Alex Hadley Date: Mon, 27 Feb 2023 14:52:31 -0800 Subject: [PATCH] #14 Begin implementing commit_history range options --- paramdb/_database.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/paramdb/_database.py b/paramdb/_database.py index 2ee4b66..767ea60 100644 --- a/paramdb/_database.py +++ b/paramdb/_database.py @@ -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]