Skip to content

Releases: piccolo-orm/piccolo

0.109.0

05 Mar 21:52
ff26a88
Compare
Choose a tag to compare

Joins are now possible without foreign keys using join_on.

For example:

class Manager(Table):
    name = Varchar(unique=True)
    email = Varchar()

class Band(Table):
    name = Varchar()
    manager_name = Varchar()

>>> await Band.select(
...     Band.name,
...     Band.manager_name.join_on(Manager.name).email
... )

0.108.0

01 Mar 15:26
Compare
Choose a tag to compare

Added support for savepoints within transactions.

async with DB.transaction() as transaction:
    await Manager.objects().create(name="Great manager")
    savepoint = await transaction.savepoint()
    await Manager.objects().create(name="Great manager")
    await savepoint.rollback_to()
    # Only the first manager will be inserted.

The behaviour of nested context managers has also been changed slightly.

async with DB.transaction():
    async with DB.transaction():
        # This used to raise an exception

We no longer raise an exception if there are nested transaction context managers, instead the inner ones do nothing.

If you want the existing behaviour:

async with DB.transaction():
    async with DB.transactional(allow_nested=False):
        # TransactionError!

0.107.0

27 Feb 20:40
021d782
Compare
Choose a tag to compare

Added the log_responses option to the database engines. This makes the engine print out the raw response from the database for each query, which is useful during debugging.

# piccolo_conf.py

DB = PostgresEngine(
    config={'database': 'my_database'},
    log_queries=True,
    log_responses=True
)

We also updated the Starlite ASGI template - it now uses the new import paths (thanks to @sinisaos for this).

0.106.0

21 Feb 19:38
7e6012b
Compare
Choose a tag to compare

Joins now work within update queries. For example:

await Band.update({
    Band.name: 'Amazing Band'
}).where(
    Band.manager.name == 'Guido'
)

Other changes:

  • Improved the template used by piccolo app new when creating a new Piccolo app (it now uses table_finder).

0.105.0

07 Jan 16:03
667b8c3
Compare
Choose a tag to compare

Improved the performance of select queries with complex joins. Many thanks to @powellnorma and @sinisaos for their help with this.

0.104.0

02 Jan 20:19
fdb703f
Compare
Choose a tag to compare

Major improvements to Piccolo's typing / auto completion support.

>>> bands = await Band.objects()  # List[Band]

>>> band = await Band.objects().first()  # Optional[Band]

>>> bands = await Band.select().output(as_json=True)  # str

Happy New Year!

0.103.0

22 Dec 22:36
5e5cabc
Compare
Choose a tag to compare

SelectRaw

This allows you to access features in the database which aren't exposed directly by Piccolo. For example, Postgres functions:

from piccolo.query import SelectRaw

>>> await Band.select(
...     Band.name,
...     SelectRaw("log(popularity) AS log_popularity")
... )
[{'name': 'Pythonistas', 'log_popularity': 3.0}]

Large fixtures

Piccolo can now load large fixtures using piccolo fixtures load. The rows are inserted in batches, so the database adapter doesn't raise any errors. Thanks to @lgblkb for reporting this.

0.102.0

17 Dec 00:09
Compare
Choose a tag to compare

Migration file names

The naming convention for migrations has changed slightly. It used to be just a timestamp - for example:

2021-09-06T13-58-23-024723.py

By convention Python files should start with a letter, and only contain a-z, 0-9 and _, so the new format is:

 my_app_2021_09_06T13_58_23_024723.py

Note: You can name a migration file anything you want (it's the ID value inside it which is important), so this change doesn't break anything.

Enhanced Pydantic configuration

We now expose all of Pydantic's configuration options to create_pydantic_model:

class MyPydanticConfig(pydantic.BaseConfig):
    extra = 'forbid'

model = create_pydantic_model(
    table=MyTable,
    pydantic_config_class=MyPydanticConfig
)

Thanks to @waldner for this.

Other changes

  • Fixed a bug with get_or_create and null columns (thanks to @powellnorma for reporting this issue).
  • Updated the Starlite ASGI template, so it uses the latest syntax for mounting Piccolo Admin (thanks to @sinisaos for this, and the Starlite team).

0.101.0

08 Dec 20:29
Compare
Choose a tag to compare

piccolo fixtures load is now more intelligent about how it loads data, to avoid foreign key constraint errors.

0.100.0

07 Dec 20:28
Compare
Choose a tag to compare

Array columns now support choices.

class Ticket(Table):
    class Extras(str, enum.Enum):
        drink = "drink"
        snack = "snack"
        program = "program"

    extras = Array(Varchar(), choices=Extras)

We can then use the Enum in our queries:

>>> await Ticket.insert(
...     Ticket(extras=[Extras.drink, Extras.snack]),
...     Ticket(extras=[Extras.program]),
... )

This will also be supported in Piccolo Admin in the next release.

206292810-23b47d29-ff7f-4d04-8c70-fd5c8d790629