0% found this document useful (0 votes)
2 views8 pages

prisma_types

The document provides a comprehensive overview of various special fields and types used with Prisma Client, including Decimal, BigInt, Bytes, DateTime, and JSON fields. It includes code examples for creating records with these types and notes on specific considerations, such as serialization issues with BigInt and DateTime handling. Additionally, it highlights the limitations regarding the use of Decimal fields with MongoDB and other relevant details for developers working with Prisma ORM.

Uploaded by

Yuri HM
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views8 pages

prisma_types

The document provides a comprehensive overview of various special fields and types used with Prisma Client, including Decimal, BigInt, Bytes, DateTime, and JSON fields. It includes code examples for creating records with these types and notes on specific considerations, such as serialization issues with BigInt and DateTime handling. Additionally, it highlights the limitations regarding the use of Decimal fields with MongoDB and other relevant details for developers working with Prisma ORM.

Uploaded by

Yuri HM
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Skip to main content

Prisma logo Prisma logo


/docsGet Started

ORM
Postgres
Studio
Optimize
Accelerate
Pulse

GuidesExamples

Search

Running a serverless backend? You need a managed connection pool.

ORM
ORM
Overview
Introduction
Prisma ORM in your stack
Databases
Beyond Prisma ORM
Prisma Schema
Overview
Data model
Introspection
PostgreSQL extensions
Prisma Client
Setup & configuration
Queries
Write your own SQL
Fields & types
Composite types
Null and undefined
Working with Json fields
Working with scalar lists
Working with compound IDs and unique constraints
Extensions
Type safety
Testing
Deployment
Observability & logging
Debugging & troubleshooting
Prisma Migrate
Getting started
Understanding Prisma Migrate
Workflows
Tools
Prisma CLI
Prisma Studio
Reference
Prisma Client API
Prisma Schema
Prisma CLI
Errors
Ask AI
Environment variables
Database features matrix
Supported databases
Connection URLs
System requirements
Preview features
More
Under the hood
Upgrade guides
Comparing Prisma ORM
Development environment
Help articles
ORM releases and maturity levels

ORM
Prisma Client

On this page
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 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 .

Working with BigInt​


Overview​

BigInt 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),
},
})

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 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]),
},
})

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

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.

Working with 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:

Jan 01, 1998; 00 h 00 min and 000 ms​

await prisma.user.create({
data: {
birthDate: new Date('1998')
}
})

Dec 01, 1998; 00 h 00 min and 000 ms​

await prisma.user.create({
data: {
birthDate: new Date('1998-12')
}
})

Dec 24, 1998; 00 h 00 min and 000 ms​

await prisma.user.create({
data: {
birthDate: new Date('1998-12-24')
}
})

Dec 24, 1998; 22 h 33 min and 444 ms​

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

Working with Json


See: Working with Json fields

Working with scalar lists / scalar arrays​


See: Working with scalar lists / arrays

Working with composite IDs and compound unique constraints​


See: Working with composite IDs and compound unique constraints
Edit this page on GitHub
Previous
SafeQL & Prisma Client
Next
Composite types

Working with Decimal


Working with BigInt
Overview
Serializing BigInt
Working with Bytes
Working with DateTime
Working with Json
Working with scalar lists / scalar arrays
Working with composite IDs and compound unique constraints
Prisma logo Prisma logo

Product

ORM
Studio
Optimize
Accelerate
Pulse
Pricing
Changelog
Data Platform status ↗

Resources

Docs
Ecosystem
Playground ↗
ORM Benchmarks ↗
Customer stories
Data guide

Contact us

Community
Support
Enterprise
Partners
OSS Friends

Company

About
Blog
Data DX ↗
Careers
Security & Compliance
Legal
Privacy Policy
Terms of Service
Service Level Agreement
Event Code of Conduct

© 2025 Prisma Data, Inc.


gdpr hipaa iso27001 soc

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy