Skip to main content
Prisma Documentation Docs

Search documentation

Type to search this documentation.

On this pageOverview

Fields & types (Prisma ORM v6) (/docs/orm/v6/prisma-client/special-fields-and-types)

For the complete Prisma documentation index, see llms.txt. A markdown version of any docs page is available by appending .md to its URL.

Learn how to use about special fields and types with Prisma Client.

Location: ORM > v6 > Prisma Client > Fields & types

This section covers various special fields and types you can use with Prisma Client.

Decimal fields are represented by the Decimal.js library. The following example demonstrates how to import and use Prisma.Decimal:

TypeScript
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:

TypeScript
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.

BigInt fields are represented by the BigInt type (Node.js 10.4.0+ required). The following example demonstrates how to use the BigInt type:

TypeScript
import { PrismaClient, Prisma } from "@prisma/client";

const newTypes = await prisma.sample.create({
  data: {
    revenue: BigInt(534543543534),
  },
});

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:

JavaScript
JSON.stringify(
  this,
  (key, value) => (typeof value === "bigint" ? value.toString() : value), // return everything else unchanged
);

Bytes fields are represented by the Uint8Array type. The following example demonstrates how to use the Uint8Array type:

TypeScript
import { PrismaClient, Prisma } from "@prisma/client";

const newTypes = await prisma.sample.create({
  data: {
    myField: new Uint8Array([1, 2, 3, 4]),
  },
});

Note that before Prisma v6, Bytes were represented by the Buffer type:

TypeScript
import { PrismaClient, Prisma } from "@prisma/client";

const newTypes = await prisma.sample.create({
  data: {
    myField: Buffer.from([1, 2, 3, 4]),
  },
});

Learn more in the upgrade guide to v6.

[!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:

prisma
model User {
  id        Int       @id @default(autoincrement())
  birthDate DateTime?
}

Here are some examples for creating new records:

TypeScript
await prisma.user.create({
  data: {
    birthDate: new Date("1998"),
  },
});
TypeScript
await prisma.user.create({
  data: {
    birthDate: new Date("1998-12"),
  },
});
TypeScript
await prisma.user.create({
  data: {
    birthDate: new Date("1998-12-24"),
  },
});
TypeScript
await prisma.user.create({
  data: {
    birthDate: new Date("1998-12-24T06:22:33.444Z"),
  },
});

See: Working with Json fields

See: Working with scalar lists / arrays

Working with composite IDs and compound unique constraints

Section titled “Working with composite IDs and compound unique constraints”

See: Working with composite IDs and compound unique constraints

  • Extensions: Extend the functionality of Prisma Client
  • Testing: How to implement unit and integration testing with Prisma ORM
  • Type safety: Prisma Client provides full type safety for queries, even for partial queries or included relations. This page explains how to leverage the generated types and utilities.
  • Write your own SQL: Learn how to use raw SQL queries in Prisma Client.
Suggest an edit

Propose a replacement for this page. The site team reviews it before applying any changes.

Export
Documentation menu