apps/docs/content/docs/orm/prisma-client/special-fields-and-types/index.mdx
This section covers various special fields and types you can use with Prisma Client.
DecimalDecimal fields are represented by the Decimal.js library. The following example demonstrates how to import and use Prisma.Decimal:
import { PrismaClient, Prisma } from "@prisma/client";
const newTypes = await prisma.sample.create({
data: {
cost: new Prisma.Decimal(24.454545),
},
});
You can also perform arithmetic operations:
import { PrismaClient, Prisma } from "@prisma/client";
const newTypes = await prisma.sample.create({
data: {
cost: new Prisma.Decimal(24.454545).plus(1),
},
});
Prisma.Decimal uses Decimal.js, see Decimal.js docs to learn more.
:::warning
The use of the Decimal field is not currently supported in MongoDB.
:::
BigIntBigInt fields are represented by the BigInt type (Node.js 10.4.0+ required). The following example demonstrates how to use the BigInt type:
import { PrismaClient, Prisma } from "@prisma/client";
const newTypes = await prisma.sample.create({
data: {
revenue: BigInt(534543543534),
},
});
BigIntPrisma Client returns records as plain JavaScript objects. If you attempt to use JSON.stringify on an object that includes a BigInt field, you will see the following error:
Do not know how to serialize a BigInt
To work around this issue, use a customized implementation of JSON.stringify:
JSON.stringify(
this,
(key, value) => (typeof value === "bigint" ? value.toString() : value), // return everything else unchanged
);
BytesBytes fields are represented by the Uint8Array type. The following example demonstrates how to use the Uint8Array type:
import { PrismaClient, Prisma } from "@prisma/client";
const newTypes = await prisma.sample.create({
data: {
myField: new Uint8Array([1, 2, 3, 4]),
},
});
DateTime:::note
There currently is a bug that doesn't allow you to pass in DateTime values as strings and produces a runtime error when you do. DateTime values need to be passed as Date objects (i.e. new Date('2024-12-04') instead of '2024-12-04').
:::
When creating records that have fields of type DateTime, Prisma Client accepts values as Date objects adhering to the ISO 8601 standard.
Consider the following schema:
model User {
id Int @id @default(autoincrement())
birthDate DateTime?
}
Here are some examples for creating new records:
await prisma.user.create({
data: {
birthDate: new Date("1998"),
},
});
await prisma.user.create({
data: {
birthDate: new Date("1998-12"),
},
});
await prisma.user.create({
data: {
birthDate: new Date("1998-12-24"),
},
});
await prisma.user.create({
data: {
birthDate: new Date("1998-12-24T06:22:33.444Z"),
},
});