From fb6931f3fe875347d0fad6bee89e68aa46ff4efe Mon Sep 17 00:00:00 2001 From: Iranildo Alves <117860354+IranTheCreator@users.noreply.github.com> Date: Tue, 26 Dec 2023 18:19:21 -0300 Subject: [PATCH 1/2] queryFeature: Last query (inverse of first) I added the functionality that returns the last record in the database, something present in other ORMs and absent in ponyorm, I ran tests on my application and it worked correctly; --- pony/orm/core.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pony/orm/core.py b/pony/orm/core.py index b5555c27..affaeaa9 100644 --- a/pony/orm/core.py +++ b/pony/orm/core.py @@ -5945,6 +5945,18 @@ def first(query): objects = query.without_distinct()[:1] if not objects: return None return objects[0] + def last(query): + translator = query._translator + if translator.order: + pass + elif type(translator.expr_type) is tuple: + query = query.order_by(*[-i-1 for i in range(len(query._translator.expr_type))]) + else: + query = query.order_by(-1) + objects = query.without_distinct()[:1] + if not objects: + return None + return objects[0] @cut_traceback def without_distinct(query): return query._clone(_distinct=False) From 31511974c960ed0f0e67bb3537a31108f7fffbd2 Mon Sep 17 00:00:00 2001 From: Iranildo Alves <117860354+IranTheCreator@users.noreply.github.com> Date: Tue, 26 Dec 2023 18:31:14 -0300 Subject: [PATCH 2/2] queryFeature: Last query (inverse of first)v2 adition of decorator @cut_traceback --- pony/orm/core.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pony/orm/core.py b/pony/orm/core.py index affaeaa9..0665b822 100644 --- a/pony/orm/core.py +++ b/pony/orm/core.py @@ -5945,6 +5945,7 @@ def first(query): objects = query.without_distinct()[:1] if not objects: return None return objects[0] + @cut_traceback def last(query): translator = query._translator if translator.order: