Skip to content

1.36.0

Latest

Choose a tag to compare

@dantownsend dantownsend released this 27 Jul 21:53

Advanced Constraints

Added support for composite unique constraints. Many thanks to @atkei for this.

For example:

from piccolo.constraints import Unique

class Album(Table):
    name = Varchar()
    band = ForeignKey(Band)

    unique_name_band = Unique([name, band])

And check constraints:

from piccolo.constraints import Check

class Ticket(Table):
    price = Decimal()

    check_price_positive = Check(price >= 0)

Replaced SelectRaw, GroupByRaw and OrderByRaw with QueryString

In certain situations we allow the user to modify Piccolo queries using custom SQL. This is for advanced situations not covered natively by the ORM.

In the past we used custom classes for this - SelectRaw, OrderByRaw etc.

These classes still work, but you can now just pass in a QueryString instead (the building block of queries in Piccolo).

from piccolo.querystring import QueryString

await Band.select(Band.name).order_by(
    QueryString('random()'),
)

Thanks to @AnayGarodia for adding support for custom SQL in group_by.

Other changes

  • Improved error messages when running migrations (thanks to @pctablet505 and @AnayGarodia for this).
  • Upgraded colorama, so Piccolo works nicer with other libraries also using colorama (thanks to @laravioli for reporting this issue).
  • Fixed a bug using load_json and prefetch together, when the JSON column contains an array value (thanks to @Mekagojira8 for reporting this issue).
  • Fixed bugs with title case column names (thanks to @devzzzero for reporting this).