Releases: piccolo-orm/piccolo
1.16.0
Added custom async TestCase
subclasses, to help with testing.
For example AsyncTransactionTest
, which wraps each test in a transaction automatically:
class TestBandEndpoint(AsyncTransactionTest):
async def test_band_response(self):
"""
Make sure the endpoint returns a 200.
"""
# This data automatically gets removed from the database when the
# test finishes:
band = Band({Band.name: "Pythonistas"})
await band.save()
# Using an API testing client, like httpx:
response = await client.get(f"/bands/{band.id}/")
self.assertEqual(response.status_code, 200)
And AsyncTableTest
, which automatically creates and drops tables:
class TestBand(AsyncTableTest):
# These tables automatically get created and dropped:
tables = [Band]
async def test_band(self):
...
1.15.0
Improved refresh
- it now works with prefetched objects. For example:
>>> band = await Band.objects(Band.manager).first()
>>> band.manager.name
"Guido"
# If the manager has changed in the database, when we refresh the band, the
# manager object will also be updated:
>>> await band.refresh()
>>> band.manager.name
"New name"
Also, improved the error messages when creating a BaseUser
- thanks to @haaavk for this.
1.14.0
Laying the foundations for alterative Postgres database drivers (e.g.psqlpy
). Thanks to @insani7y and @chandr-andr for their help with this.
Warning
The SQL generated by Piccolo changed slightly in this release. Aliases used to be like "manager$name"
but now they are like "manager.name"
(note $
changed to .
). If you are using SelectRaw
in your queries to refer to these columns, then they will need updating. Please let us know if you encounter any other issues.
1.13.1
In Piccolo 1.6.0
we moved some aggregate functions to a new file. We now re-export them from their original location to keep backwards compatibility. Thanks to @sarvesh-deserve for reporting this issue.
1.13.0
Improved LazyTableReference
, to help prevent circular import errors.
1.12.0
1.11.0
Added datetime functions, for example Year
:
>>> from piccolo.query.functions import Year
>>> await Concert.select(Year(Concert.starts, alias="starts_year"))
[{'starts_year': 2024}]
Added the Concat
function, for concatenating strings:
>>> from piccolo.query.functions import Concat
>>> await Band.select(
... Concat(
... Band.name,
... '-',
... Band.manager._.name,
... alias="name_and_manager"
... )
... )
[{"name_and_manager": "Pythonistas-Guido"}]
1.10.0
Added not_any
method for Array
columns. This will return rows where an array doesn't contain the given value. For example:
class MyTable(Table):
array_column = Array(Integer())
>>> await MyTable.select(
... MyTable.array_column
... ).where(
... MyTable.array_column.not_any(1)
... )
[{"array_column": [4, 5, 6]}]
Also fixed a bunch of Pylance linter warnings across the codebase.
1.9.0
Added some math functions, for example Abs
, Ceil
, Floor
and Round
.
>>> from piccolo.query.functions import Round
>>> await Ticket.select(Round(Ticket.price, alias="price"))
[{'price': 50.0}]
Added more operators to QueryString
(multiply, divide, modulus, power), so we can do things like:
>>> await Ticket.select(Round(Ticket.price) * 2)
[{'price': 100.0}]
Fixed some edge cases around defaults for Array
columns.
def get_default():
# This used to fail:
return [datetime.time(hour=8, minute=0)]
class MyTable(Table):
times = Array(Time(), default=get_default)
Fixed some deprecation warnings, and improved CockroachDB array tests.
1.8.0
Added the Cast
function, for performing type conversion.
Here's an example, where we convert a timestamp
to time
:
>>> from piccolo.columns import Time
>>> from piccolo.query.functions import Cast
>>> await Concert.select(Cast(Concert.starts, Time()))
[{'starts': datetime.time(19, 0)}]
A new section was also added to the docs describing functions in more detail.