This is great, full support for native types has been added in prisma/prisma@v2.15.0!
For example, setting price with two decimal places:
generator client { provider = "prisma-client-js" previewFeatures = ["nativeTypes"] } model Product { name String price Decimal? @mysql.Decimal(10, 2) }
Note that this would now return a Decimal (not native number):
const product = prisma.product.findFirst(); const price = product.price; // This is a `Decimal`, so you should typecast it const discountedPrice = product.price.toNumber() * 0.9;
@db.Decimal in Prisma ("s", "e", "d")
How to use DECIMAL(10,2) in prisma migrate tool? - Stack Overflow
Inserting Float type requires a decimal value (different from 0)
Error for Float type (postgresql)
Full support for native types has been added in prisma/[email protected]
datasource db {
provider = "mysql"
url = env("DATABASE_URL")
}
generator client {
provider = "prisma-client-js"
}
model Product {
id Int @id @default(autoincrement())
code String
price Decimal @db.Decimal(9,2)
}
Currently prisma migrate doesn't support the Decimal type. You can track the issue for custom DB types here
As a workaround, you would have to use a custom migration tool and specify the Decimal field that you require and then run prisma introspect which will get all the fields from your DB and populate the schema.prisma.
It looks like the type you should use is called Int. I'm getting that from this Prisma documentation listing the different field types. The field types available are:
StringBooleanIntBigIntFloatDecimalDateTimeJsonBytesUnsupported
Prisma doesn't have type called Integer, it has a type Int.You can find the type examples here https://www.prisma.io/docs/concepts/components/prisma-schema/data-model