Fields & types
This section covers various special fields and types you can use with Prisma Client.
Working with Decimal
Decimal
fields are represented by the . 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),},})
The use of the Decimal
field .
Working with BigInt
BigInt
fields are represented by the (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),},})
Serializing BigInt
Prisma 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)
Working with Bytes
Bytes
fields are represented by the type. The following example demonstrates how to use the Buffer
type:
import { PrismaClient, Prisma } from '@prisma/client'const newTypes = await prisma.sample.create({data: {myField: Buffer.from([1, 2, 3, 4]),},})
Working with Json
Working with scalar lists / scalar arrays
Working with composite IDs and compound unique constraints
See: Working with composite IDs and compound unique constraints