Support for selecting fields
This release adds support for selecting fields at the database level!
This currently only works for queries using [model based access](https://prisma-client-py.readthedocs.io/en/stable/reference/model-actions/) either by defining your own model classes or generating them using partial types.
Quick example:
py
from prisma.bases import BaseUser
class UserWithName(BaseUser):
name: str
this query will only select the `name` field at the database level!
user = await UserWithName.prisma().find_first(
where={
'country': 'Scotland',
},
)
print(user.name)
For a more detailed guide see the [docs](https://prisma-client-py.readthedocs.io/en/latest/stable/selecting-fields/).
Support for distinct filters
You can now pass in a `distinct` filter to `find_first()` and `find_many()` queries.
For example, the following query will find all `Profile` records that have a distinct, or unique, `city` field.
py
profiles = await db.profiles.find_many(
distinct=['city'],
)
[
{ city: 'Paris' },
{ city: 'Lyon' },
]
You can also filter by distinct combinations, for example the following query will return all records that have a distinct `city` *and* `country` combination.
py
profiles = await db.profiles.find_many(
distinct=['city', 'country'],
)
[
{ city: 'Paris', country: 'France' },
{ city: 'Paris', country: 'Denmark' },
{ city: 'Lyon', country: 'France' },
]
CLI support for specifying the generator to use
Thanks to yukukotani's [great work](https://github.com/prisma/prisma/pull/16452) on the CLI you can now ergonomically share the same schema between multiple languages, for example with the following schema:
prisma
datasource db {
provider = "sqlite"
url = "file:./dev.db"
}
generator node {
provider = "prisma-client-js"
}
generator python {
provider = "prisma-client-py"
}
model User {
id Int id
name String
}
You can now skip the generation of the Node client with the `--generator` argument:
prisma generate --generator=python
See the `generate` [documentation](https://www.prisma.io/docs/reference/api-reference/command-reference#generate) for more details.
Bug fixes
- [Ensure the SIGINT signal is unblocked before forking the query engine process](https://github.com/RobertCraigie/prisma-client-py/pull/678), thanks to ezorita!
Prisma updates
This release bumps the internal Prisma version from `v4.8.0` to `v4.10.1`
- [Multi-schema support for SQL Server (Preview)](https://www.prisma.io/docs/guides/database/multi-schema)
- [Improved CLI support for connection proxies](https://www.prisma.io/docs/data-platform/data-proxy/prisma-cli-with-data-proxy)
- [Improved introspection support for unsupported features](https://github.com/prisma/prisma/releases/tag/4.10.0#:~:text=Improved%20introspection%20for%20unsupported%20database%20functionality%20%26%20partitioned%20tables)
- [Smaller engine size in the CLI](https://github.com/prisma/prisma/releases/tag/4.10.0#:~:text=Smaller%20engine%20size%20used%20in%20Prisma%20CLI)
For the full release notes, see the [v4.9.0 release notes](https://github.com/prisma/prisma/releases/tag/4.9.0) and the [v4.10.0 release notes](https://github.com/prisma/prisma/releases/tag/4.10.0).
Minimum required type checker version
Before this release there were no explicit compatibility requirements for type checkers. From now on we will only support the latest versions of Mypy and Pyright.
In the next release the mypy plugin will be deprecated and later removed entirely. There is a bug in the plugin API in the latest versions of mypy that completely breaks the plugin and seems impossible to fix. See [683](https://github.com/RobertCraigie/prisma-client-py/issues/683) for more information.
Sponsors
Massive thank you to prisma, techied, exponential-hq and danburonline for their continued support! Thank you to paudrow for becoming a sponsor!
![sponsors](https://user-images.githubusercontent.com/23125036/218282700-659ffe6f-6401-4c3d-b7cf-00011822fcea.png)