v0.5.0
Bug Fixes
- Removed relational fields from
update_many
mutation data, updating relational fields fromupdate_many
is not supported yet (prisma/prisma#3143). - Fixed relational ordering typing, this was typed to order by the parent model, not the relational model (#234)
- Fixed ordering typing to signify that only one field can be ordered by at once (pass a list if you need to order by multiple fields)
What's Changed
Dropped support for Python 3.6
Python 3.6 reached its end of life on the 23rd of December 2021. You now need Python 3.7 or higher to use Prisma Client Python.
Grouping records
You can now group records by one or more field values and perform aggregations on each group!
It should be noted that the structure of the returned data is different to most other action methods, returning a TypedDict
instead of a BaseModel
.
For example:
results = await Profile.prisma().group_by(
by=['country'],
sum={
'views': True,
},
)
# [
# {"country": "Canada", "_sum": {"views": 23}},
# {"country": "Scotland", "_sum": {"views": 143}},
# ]
For more examples see the documentation: https://prisma-client-py.readthedocs.io/en/stable/reference/operations/#grouping-records
While the syntax is slightly different the official Prisma documentation is also a good reference: https://www.prisma.io/docs/concepts/components/prisma-client/aggregation-grouping-summarizing#group-by
Improve support for custom generator options
You can now easily (and with full type-safety) define custom options for your own Prisma Generators!
from pydantic import BaseModel
from prisma.generator import GenericGenerator, GenericData, Manifest
# custom options must be defined using a pydantic BaseModel
class Config(BaseModel):
my_option: int
# we don't technically need to define our own Data class
# but it makes typing easier
class Data(GenericData[Config]):
pass
# the GenericGenerator[Data] part is what tells Prisma Client Python to use our
# custom Data class with our custom Config class
class MyGenerator(GenericGenerator[Data]):
def get_manifest(self) -> Manifest:
return Manifest(
name='My Custom Generator Options',
default_output='schema.md',
)
def generate(self, data: Data) -> None:
# generate some assets here
pass
if __name__ == '__main__':
MyGenerator.invoke()
Removal of deprecated arguments
There are two arguments that were deprecated in previous releases that have now been removed:
- The redundant
encoding
argument toBase64.decode()
- The redundant
order
argument toactions.count()
Support for updating unique fields
You can now update fields that are marked as @unique
or @id
:
user = await User.prisma().update(
where={
'email': 'robert@craigie.dev',
},
data={
'email': 'new@craigie.dev',
},
)
Custom CLI binary
You can now easily replace the Prisma CLI binary that Prisma Client Python makes use of by overriding the PRISMA_CLI_BINARY
environment variable. This shouldn't be necessary for the vast majority of users however as some platforms are not officially supported yet, binaries must be built manually in these cases.
Prisma upgrade
The internal Prisma binaries that Prisma Client Python makes use of have been upgraded from v3.7.0 to v3.8.1. For a full changelog see the v3.8.0 release notes.
Miscellaneous changes
- The Prisma Studio CLI entrypoint is not supported, the error message for this has been improved and points out the two solutions.