Skip to content
This repository was archived by the owner on Apr 15, 2025. It is now read-only.

v0.6.4

Choose a tag to compare

@RobertCraigie RobertCraigie released this 04 Apr 23:32
· 391 commits to main since this release
b323fbd

What's Changed

Experimental support for the Decimal type

Experimental support for the Decimal type has been added. The reason that support for this type is experimental is due to a missing internal feature in Prisma that means we cannot provide the same guarantees when working with the Decimal API as we can with the API for other types. For example, we cannot:

  • Raise an error if you attempt to pass a Decimal value with a greater precision than the database supports, leading to implicit truncation which may cause confusing errors
  • Set the precision level on the returned decimal.Decimal objects to match the database level, potentially leading to even more confusing errors.

If you need to use Decimal and are happy to work around these potential footguns then you must explicitly specify that you are aware of the limitations by setting a flag in the Prisma Schema:

generator py {
  provider                    = "prisma-client-py"
  enable_experimental_decimal = true
}

model User {
    id      String @id @default(cuid())
    balance Decimal
}

The Decimal type maps to the standard library's Decimal class. All available query operations can be found below:

from decimal import Decimal
from prisma import Prisma

prisma = Prisma()
user = await prisma.user.find_first(
    where={
        'balance': Decimal(1),
        # or
        'balance': {
            'equals': Decimal('1.23823923283'),
            'in': [Decimal('1.3'), Decimal('5.6')],
            'not_in': [Decimal(10), Decimal(20)],
            'gte': Decimal(5),
            'gt': Decimal(11),
            'lt': Decimal(4),
            'lte': Decimal(3),
            'not': Decimal('123456.28'),
        },
    },
)

Updates on the status of support for Decimal will be posted in #106.

Add triple-slash comments to generated models

You can now add comments to your Prisma Schema and have them appear in the docstring for models and fields! For example:

/// The User model
model User {
  /// The user's email address
  email String
}

Will generate a model that looks like this:

class User(BaseModel):
    """The User model"""

    email: str
    """The user's email address"""

Improved import error message if the client has not been generated

If you try to import Prisma or Client before you've run prisma generate then instead of getting an opaque error message:

>>> from prisma import Prisma
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name 'Prisma' from 'prisma' (/prisma/__init__.py)

you will now get an error like this:

>>> from prisma import Prisma
Traceback (most recent call last):
...
RuntimeError: The Client hasn't been generated yet, you must run `prisma generate` before you can use the client.
See https://prisma-client-py.readthedocs.io/en/stable/reference/troubleshooting/#client-has-not-been-generated-yet

The query batcher is now publicly exposed

You can now import the query batcher directly from the root package, making it much easier to type hint and providing support for an alternative API style:

from prisma import Prisma, Batch

prisma = Prisma()
async with Batch(prisma) as batcher:
    ...

def takes_batcher(batcher: Batch) -> None:
    ...

Prisma upgrade

The internal Prisma binaries that Prisma Python makes use of have been upgraded from v3.10.0 to v3.11.1. For a full changelog see the v3.11.0 release notes and v3.11.1 release notes.

Sponsors

This project is now being sponsored by @prisma and @techied. I am so incredibly grateful to both for supporting Prisma Client Python 💜