Releases: piccolo-orm/piccolo
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.
0.38.0
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
Added ModelBuilder
, which can be used to generate data for tests (courtesy @aminalaee).
0.36.0
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
- 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 setsPICCOLO_CONF
, so a test database is used. - Added the
get
convenience method (courtesy @aminalaee). It returns the first matching record, orNone
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
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
- Bug fix, where
compare_dicts
was failing in migrations if anyColumn
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
Fix for auto migrations when using custom primary keys (thanks to @adriangb and @aminalaee for investigating this issue).