Skip to content
Tutorials Center
My learning

Topics

Lesson 7 of 36 ยท Schema and Models

Prisma Field Types and Attributes

Learn every Prisma scalar type (String, Int, BigInt, Float, Decimal, Boolean, DateTime, Json, Bytes), how they map to TypeScript and why money should not be a Float.

Prisma has a short list of scalar types that work across all databases. Each maps to a column type in your database and to a TypeScript type in the generated client. Choosing the right one early prevents painful migrations later, so it is worth understanding the details, especially for numbers, dates and money.

The scalar types

Prisma type TypeScript type Typical use
String string names, emails, text
Boolean boolean flags
Int number counters, small ids (32-bit)
BigInt bigint very large integers (64-bit), big ids
Float number measurements where tiny rounding errors are fine
Decimal Decimal (from decimal.js) money and exact decimals
DateTime Date timestamps
Json JSON value flexible, schemaless data
Bytes Uint8Array binary data
Unsupported("...") not available in the client database types Prisma cannot model
PRISMA
model Invoice {
  id         BigInt   @id @default(autoincrement())
  number     String   @unique
  quantity   Int
  weightKg   Float
  total      Decimal  @db.Decimal(10, 2)
  paid       Boolean  @default(false)
  issuedAt   DateTime @default(now())
  metadata   Json?
  pdf        Bytes?
}

Int, BigInt and Float

Int is a 32-bit signed integer (about plus or minus 2.1 billion). It is enough for most ids and counters. If a table might exceed that (event logs, analytics), use BigInt. In JavaScript a BigInt is a different type from number (10n), and JSON.stringify cannot serialize it, so convert when sending it in an API response.

Float is a 64-bit floating point number, which stores most decimals only approximately. That is fine for a temperature, but wrong for money, as the next section shows.

Why money is not a Float

Node.js Floating point surprises

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.

With Prisma, Decimal columns are returned as Decimal objects from the decimal.js library (re-exported as Prisma.Decimal). You call .toFixed(2) or .toString() on them, and do arithmetic with .plus(), .times() and so on. Many teams prefer integer cents in an Int column, because plain numbers are simpler to pass around; either choice is correct, and Float is the wrong one.

DateTime

DateTime maps to a timestamp column and to a JavaScript Date. Prisma stores and returns it in UTC. Convert to the user's time zone only when displaying.

PRISMA
model Event {
  id        Int       @id @default(autoincrement())
  title     String
  startsAt  DateTime
  endsAt    DateTime?
  createdAt DateTime  @default(now())
  updatedAt DateTime  @updatedAt
}

When you filter by date you pass Date objects or ISO strings: where: { startsAt: { gte: new Date("2026-01-01") } }.

Node.js Working with dates the Prisma way

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.

Json

A Json field stores any JSON value (object, array, string, number, boolean, null). It is useful for settings, third-party payloads and rarely queried data.

PRISMA
model User {
  id          Int   @id @default(autoincrement())
  preferences Json?
}
TypeScript
await prisma.user.create({
  data: { preferences: { theme: "dark", fontSize: 14 } },
});

The generated type is JsonValue, which is loose, so you must validate or cast when reading (a library such as Zod works well). If you filter or join on a value constantly, it belongs in a real column instead. PostgreSQL and MySQL can filter inside JSON with path filters; SQLite has limited support.

Bytes and Unsupported

Bytes stores binary data (a small thumbnail, a hash). For large files, store them in object storage and keep only the URL in the database. Unsupported("circle") declares a column of a type Prisma cannot model; the column exists, but the client cannot read or write it, and you must use raw SQL.

Native type attributes (@db.*)

Each Prisma type has a default database type, but you can pick a precise one with a @db attribute whose names depend on the database:

PRISMA
model Article {
  id      Int     @id @default(autoincrement())
  title   String  @db.VarChar(200)     // PostgreSQL and MySQL
  body    String  @db.Text
  price   Decimal @db.Decimal(10, 2)   // 10 digits, 2 after the point
  views   Int     @db.SmallInt
}

@db.VarChar(200) limits the title length in the database. Without it, PostgreSQL uses text and MySQL uses VARCHAR(191). Native types are not portable: the @db.* names of PostgreSQL differ from MySQL's. Add them when you know your database is fixed.

Optional versus default for time fields

A common mistake is to make createdAt optional. Prefer DateTime @default(now()): always present, always set by the database, never null. Use optional only for values that genuinely may not exist yet, such as deletedAt or publishedAt.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which Prisma type should you choose for a price that must never be off by a fraction of a cent?

    Float is binary floating point and cannot represent most decimals exactly. Decimal or integer cents are exact.
  2. 2. What JavaScript type does a DateTime field have in the generated client?

    DateTime maps to Date, stored and returned in UTC.
  3. 3. Why can returning a BigInt field straight through JSON.stringify fail?

    JSON.stringify throws on bigint. Convert to string or number before sending it in a response.
  4. 4. When is a Json field a good idea?

    Json suits loosely structured data. Frequently queried values deserve real, typed columns.

Summary

  • Know the scalars: String, Boolean, Int, BigInt, Float, Decimal, DateTime, Json, Bytes.
  • Never use Float for money: use Decimal or integer cents.
  • DateTime is UTC and arrives as a Date; Json is flexible but loosely typed.
  • @db.* attributes choose exact native column types for your database.

Next: Enums, Native Types and Scalar Lists