Allow table.get() to look up rows by column values

table.get() now accepts column=value keyword arguments and returns the
first matching row, so a row can be fetched by a unique column rather
than only by its primary key. Passing both a primary key and keyword
arguments raises ValueError, and calling get() with neither raises
TypeError.

Refs #588
This commit is contained in:
vishalkaay 2026-09-26 01:35:28 +05:30
commit 65b3fc8789
3 changed files with 106 additions and 1 deletions

View file

@ -652,6 +652,13 @@ If the table has a compound primary key you can pass in the primary key values a
>>> db.table("compound_dogs").get(("mixed", 3))
You can also look a record up by one or more column values, passed as keyword arguments. This returns the first matching row, which is useful for fetching a record by a column with a unique constraint rather than by its primary key::
>>> db.table("dogs").get(name="Cleo")
{'id': 1, 'age': 4, 'name': 'Cleo'}
Passing more than one keyword argument matches rows against all of them. You cannot combine a primary key value with keyword arguments in the same call.
If the record does not exist a ``NotFoundError`` will be raised:
.. code-block:: python