Working with Native Database Types
1. Using @db.VarChar
| Aspect | Detail |
|---|---|
| Syntax | name String @db.VarChar(120) |
| Length | Enforced by DB |
| MySQL index limit | Combine with length: in @@index |
2. Using @db.Text
| Aspect | Detail |
|---|---|
| PG | Unlimited text |
| MySQL | 64 KB; use @db.LongText for larger |
| SQL Server | @db.NVarChar(Max) |
3. Using @db.Uuid
| Aspect | Detail |
|---|---|
| PG | Native uuid type, 16 bytes |
| Combine | @default(uuid(7)) @db.Uuid |
| MySQL | Use @db.VarChar(36) or @db.Binary(16) |
4. Using @db.Timestamp
| Variant | Detail |
|---|---|
@db.Timestamp(n) | Precision in fractional seconds (0–6) |
@db.Timestamptz(n) | With timezone (PG) |
| JS | Always Date |
5. Using @db.Date
| Aspect | Detail |
|---|---|
| Storage | YYYY-MM-DD (no time) |
| JS | Returned as Date at 00:00 UTC |
6. Using @db.Time
| Aspect | Detail |
|---|---|
| Storage | HH:MM:SS[.fff] |
| JS | Date with 1970-01-01 base |
7. Using @db.Money
| Aspect | Detail |
|---|---|
| PG | Locale-sensitive monetary type |
| Recommendation | Prefer Decimal @db.Decimal(12,2) instead |
8. Using @db.Xml
| Aspect | Detail |
|---|---|
| Support | PG, SQL Server |
| JS type | string |
9. Using @db.Inet
| Aspect | Detail |
|---|---|
| Support | PostgreSQL only |
| Storage | IPv4/IPv6 address with optional subnet |
| JS | string |
10. Using Database-Specific Types
| Type | DB | Notes |
|---|---|---|
@db.Citext | PG | Case-insensitive text |
@db.JsonB | PG | Binary JSON |
@db.Bit(n) | PG/MySQL | Bit strings |
@db.ObjectId | Mongo | BSON ObjectId |
@db.Oid | PG | Large object reference |