Skip to content

Commit d4cc337

Browse files
committed
turned first into a property
1 parent 46d38da commit d4cc337

File tree

4 files changed

+4
-3
lines changed

4 files changed

+4
-3
lines changed

piccolo/extensions/user.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ async def login(cls, username: str, password: str) -> t.Optional[int]:
7272
try:
7373
response = await cls.select.columns(cls.id, cls.password).where(
7474
(cls.username == username)
75-
).first().run()
75+
).first.run()
7676
except ValueError:
7777
# No match found
7878
return None

piccolo/query/mixins.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ def _response_handler(response):
115115

116116
return response[0]
117117

118+
@property
118119
def first(self):
119120
self._limit = Limit(1)
120121
self.response_handler = self._response_handler

piccolo/table.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ def get_related(self, column_name: str):
274274

275275
return references.objects.where(
276276
references.get_column_by_name('id') == getattr(self, column_name)
277-
).first()
277+
).first
278278

279279
def __setitem__(self, key: str, value: t.Any):
280280
setattr(self, key, value)

tests/table/test_select.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ def test_first(self):
238238
Band.name
239239
).order_by(
240240
Band.name
241-
).first().run_sync()
241+
).first.run_sync()
242242

243243
print(f'response = {response}')
244244

0 commit comments

Comments
 (0)