Skip to content

Releases: piccolo-orm/piccolo

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.

0.38.0

25 Aug 22:22
Compare
Choose a tag to compare

get_or_create now supports more complex where clauses. For example:

  row = await Band.objects().get_or_create(
      (Band.name == 'Pythonistas') & (Band.popularity == 1000)
  ).run()

And you can find out whether the row was created or not using row._was_created.

Thanks to @wmshort for reporting this issue.

0.37.0

25 Aug 20:28
Compare
Choose a tag to compare

Added ModelBuilder, which can be used to generate data for tests (courtesy @aminalaee).

0.36.0

25 Aug 16:14
Compare
Choose a tag to compare

Fixed an issue where like and ilike clauses required a wildcard (%). For example:

await Manager.select().where(Manager.name.ilike('Guido%')).run()

You can now omit wildcards if you like:

await Manager.select().where(Manager.name.ilike('Guido')).run()

Which would match on 'guido' and 'Guido', but not 'Guidoxyz'.

Thanks to @wmshort for reporting this issue.

0.35.0

25 Aug 11:33
Compare
Choose a tag to compare
  • Improved PrimaryKey deprecation warning (courtesy @tonybaloney).
  • Added piccolo schema generate which creates a Piccolo schema from an existing database.
  • Added piccolo tester run which is a wrapper around pytest, and temporarily sets PICCOLO_CONF, so a test database is used.
  • Added the get convenience method (courtesy @aminalaee). It returns the first matching record, or None if there's no match. For example:
manager = await Manager.objects().get(Manager.name == 'Guido').run()

# This is equivalent to:
manager = await Manager.objects().where(Manager.name == 'Guido').first().run()

0.34.0

22 Aug 19:05
Compare
Choose a tag to compare

Added the get_or_create convenience method (courtesy @aminalaee). Example usage:

manager = await Manager.objects().get_or_create(
    Manager.name == 'Guido'
).run()

0.33.1

22 Aug 09:38
Compare
Choose a tag to compare
  • Bug fix, where compare_dicts was failing in migrations if any Column had an unhashable type as an argument. For example: Array(default=[]). Thanks to @hipertracker for reporting this problem.
  • Increased the minimum version of orjson, so binaries are available for Macs running on Apple silicon (courtesy @hipertracker).

0.33.0

20 Aug 08:26
Compare
Choose a tag to compare

Fix for auto migrations when using custom primary keys (thanks to @adriangb and @aminalaee for investigating this issue).