Releases: piccolo-orm/piccolo
0.44.0
Added the ability to prefetch related objects. Here's an example:
band = await Band.objects(Band.manager).run()
>>> band.manager
<Manager: 1>
If a table has a lot of ForeignKey
columns, there's a useful shortcut, which will return all of the related rows as objects.
concert = await Concert.objects(Concert.all_related()).run()
>>> concert.band_1
<Band: 1>
>>> concert.band_2
<Band: 2>
>>> concert.venue
<Venue: 1>
Thanks to @wmshort for all the input.
0.43.0
Migrations containing Array
, JSON
and JSONB
columns should be more reliable now. More unit tests were added to cover edge cases.
0.42.0
You can now use all_columns
at the root. For example:
await Band.select(
Band.all_columns(),
Band.manager.all_columns()
).run()
You can also exclude certain columns if you like:
await Band.select(
Band.all_columns(exclude=[Band.id]),
Band.manager.all_columns(exclude=[Band.manager.id])
).run()
0.41.1
Fixes a regression where if multiple tables are created in a single migration file, it could potentially fail by applying them in the wrong order.
0.41.0
Fixed a bug where if all_columns
was used two or more levels deep, it would fail. Thanks to @wmshort for reporting this issue.
Here's an example:
Concert.select(
Concert.venue.name,
*Concert.band_1.manager.all_columns()
).run_sync()
Also, the ColumnsDelegate
has now been tweaked, so unpacking of all_columns
is optional.
# This now works the same as the code above (we have omitted the *)
Concert.select(
Concert.venue.name,
Concert.band_1.manager.all_columns()
).run_sync()
0.40.1
Loosen the typing-extensions
requirement, as it was causing issues when installing asyncpg
.
0.40.0
0.39.0
Added to_dict
method to Table
.
If you just use __dict__
on a Table
instance, you get some non-column values. By using to_dict
it's just the column values. Here's an example:
class MyTable(Table):
name = Varchar()
instance = MyTable.objects().first().run_sync()
>>> instance.__dict__
{'_exists_in_db': True, 'id': 1, 'name': 'foo'}
>>> instance.to_dict()
{'id': 1, 'name': 'foo'}
Thanks to @wmshort for the idea, and @aminalaee and @sinisaos for investigating edge cases.
0.38.2
Removed problematic type hint which assumed pytest was installed.
0.38.1
Minor changes to get_or_create
to make sure it handles joins correctly.
instance = (
Band.objects()
.get_or_create(
(Band.name == "My new band")
& (Band.manager.name == "Excellent manager")
)
.run_sync()
)
In this situation, there are two columns called 'name'
- we need to make sure the correct value is applied if the row doesn't exist.