Skip to content

Releases: piccolo-orm/piccolo

0.44.0

07 Sep 18:38
Compare
Choose a tag to compare

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

02 Sep 09:07
Compare
Choose a tag to compare

Migrations containing Array, JSON and JSONB columns should be more reliable now. More unit tests were added to cover edge cases.

0.42.0

01 Sep 06:40
Compare
Choose a tag to compare

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

31 Aug 19:27
Compare
Choose a tag to compare

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

31 Aug 12:56
Compare
Choose a tag to compare

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

30 Aug 10:09
Compare
Choose a tag to compare

Loosen the typing-extensions requirement, as it was causing issues when installing asyncpg.

0.40.0

29 Aug 22:31
Compare
Choose a tag to compare

Added nested output option, which makes the response from a select query use nested dictionaries:

>>> await Band.select(Band.name, *Band.manager.all_columns()).output(nested=True).run()
[{'name': 'Pythonistas', 'manager': {'id': 1, 'name': 'Guido'}}]

Thanks to @wmshort for the input.

0.39.0

28 Aug 20:38
Compare
Choose a tag to compare

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

26 Aug 12:28
Compare
Choose a tag to compare

Removed problematic type hint which assumed pytest was installed.

0.38.1

26 Aug 06:31
bf280b1
Compare
Choose a tag to compare

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.