# Fields & Types

Define your model fields with various scalar types, modifiers, and attributes for complete control over your database schema.

## Scalar Types

Prax provides scalar types that map to native database types and Rust types:

Prax Type | Rust Type | PostgreSQL | MySQL | SQLite
--- | --- | --- | --- | ---
`Int` | i32 | INTEGER | INT | INTEGER
`BigInt` | i64 | BIGINT | BIGINT | INTEGER
`Float` | f64 | DOUBLE PRECISION | DOUBLE | REAL
`Decimal` | rust_decimal::Decimal | DECIMAL | DECIMAL | REAL
`String` | String | TEXT | VARCHAR(191) | TEXT
`Boolean` | bool | BOOLEAN | TINYINT(1) | INTEGER
`DateTime` | chrono::DateTime<Utc> | TIMESTAMP(3) | DATETIME(3) | TEXT
`Json` | serde_json::Value | JSONB | JSON | TEXT
`Bytes` | Vec<u8> | BYTEA | LONGBLOB | BLOB

## Type Modifiers

Modifiers change how field values are handled:

Modifier | Syntax | Rust Type | Description
--- | --- | --- | ---
Required | `String` | String | Must have a value (NOT NULL)
Optional | `String?` | Option<String> | Can be NULL
Array | `String[]` | Vec<String> | List of values
Optional Array | `String[]?` | Option<Vec<String>> | Array that can be NULL

## Field Attributes

Attributes modify field behavior and add constraints:

## Primary Keys

Every model needs a unique identifier. Choose the right primary key strategy for your use case:

#### Auto-Increment

Best for simple applications with a single database. Compact and fast.

#### UUID/CUID/ULID

Best for distributed systems, APIs, or when you need to generate IDs client-side.

## Default Values

Set default values to simplify record creation and ensure data consistency:

## Timestamps

Track when records are created, updated, and deleted:

## JSON Fields

Store flexible, schema-less data in JSON fields:

Note: JSON fields are flexible but lack schema enforcement. Document the expected structure in comments and consider validation in your application layer.

## Array Fields

Store multiple values in a single field (PostgreSQL native support, emulated on other databases):

## Decimal Fields

Use Decimal for exact precision, especially for financial data:

## Binary Data

Store binary data like files, images, or hashes:

## Database-Specific Types

Use `@db.TypeName` to specify native database types for advanced use cases:

## Field Attributes Reference

Attribute | Description
--- | ---
`@id` | Marks field as primary key
`@auto` | Auto-increment (for Int primary keys)
`@unique` | Unique constraint on field
`@default(value)` | Default value (literal, function, or dbgenerated)
`@updatedAt` | Auto-update timestamp on record changes
`@map("name")` | Custom column name in database
`@db.Type` | Specific database column type
`@ignore` | Exclude from generated client
`@relation(...)` | Define relationship to another model