Working with Scalar Types
1. Using String Type
| Native Mapping | Postgres | MySQL |
| Default | text | varchar(191) |
@db.VarChar(n) | varchar(n) | varchar(n) |
@db.Text | text | text |
@db.Char(n) | char(n) | char(n) |
2. Using Int Type
| Mapping | Detail |
| Default | 32-bit signed integer |
@db.SmallInt | 16-bit |
@db.Integer | Explicit 32-bit |
| Range | -2,147,483,648 .. 2,147,483,647 |
3. Using BigInt Type
| Aspect | Detail |
| JS type | bigint primitive |
| Serialization | JSON.stringify fails — use .toString() |
| Native | @db.BigInt |
Warning: BigInts do not serialize to JSON by default. Add a global JSON serializer or convert to string before sending over HTTP.
4. Using Float Type
| Mapping | Detail |
| Default | double precision (64-bit IEEE 754) |
@db.Real | 32-bit |
| Precision | Subject to floating-point rounding |
5. Using Decimal Type
| Aspect | Detail |
| JS class | Prisma.Decimal (Decimal.js) |
| Precision | @db.Decimal(precision, scale) |
| Use case | Money, scientific values |
| SQLite | Not supported (use Float/String) |
Example: Decimal arithmetic
import { Prisma } from "@prisma/client";
const total = new Prisma.Decimal("19.99").mul(3);
await prisma.invoice.create({ data: { total } });
6. Using Boolean Type
| Mapping | Detail |
| PG/MySQL | boolean / tinyint(1) |
| Defaults | @default(false) |
| SQL Server | bit |
7. Using DateTime Type
| Mapping | Detail |
| Default | timestamp(3) UTC |
@db.Timestamptz(6) | timestamp with timezone (PG) |
@db.Date | Date only |
@db.Time | Time only |
8. Using Json Type
| Aspect | Detail |
| PG | jsonb (default) |
| MySQL | json |
| SQLite | Stored as text |
| TS type | Prisma.JsonValue |
| Null distinction | Prisma.JsonNull vs Prisma.DbNull |
9. Using Bytes Type
| Aspect | Detail |
| JS type | Uint8Array (Prisma 6+) |
| PG | bytea |
| Use case | Binary blobs, hashes, encrypted payloads |
10. Using Unsupported Type
| Aspect | Detail |
| Syntax | field Unsupported("polygon") |
| Read/Write | Only via raw SQL |
| Use case | PostGIS geometry, custom types |