floz_orm/types.rs
1//! ORM type aliases — semantic DB types that map to SQL.
2//!
3//! These are **transparent type aliases** (zero runtime cost). Users write them
4//! in struct fields; the `#[model]` proc macro reads the **token name** to
5//! determine the SQL column type for DDL generation and migrations.
6//!
7//! | Rust type | SQL (Postgres) | SQL (SQLite) |
8//! |-----------------|----------------------|--------------|
9//! | `Varchar` | VARCHAR(255) | TEXT |
10//! | `Text` | TEXT | TEXT |
11//! | `Timestamp` | TIMESTAMP | TEXT |
12//! | `TimestampTz` | TIMESTAMPTZ | TEXT |
13//! | `Date` | DATE | TEXT |
14//! | `Decimal` | NUMERIC | REAL |
15//! | `Json` | JSON | TEXT |
16//! | `Jsonb` | JSONB | TEXT |
17//! | `Bytes` | BYTEA | BLOB |
18//!
19//! Native Rust types also work: `i32` → INT, `i64` → BIGINT, `bool` → BOOLEAN,
20//! `String` → VARCHAR(255), `f32` → REAL, `f64` → DOUBLE PRECISION.
21
22// ── String types ──
23
24/// Maps to `VARCHAR(255)`. Override length with `#[col(max = N)]`.
25pub type Varchar = String;
26
27/// Maps to `TEXT` — unlimited length string.
28pub type Text = String;
29
30// ── Temporal types ──
31
32/// Maps to `TIMESTAMP` (without time zone).
33pub type Timestamp = chrono::NaiveDateTime;
34
35/// Maps to `TIMESTAMPTZ` (with time zone).
36pub type TimestampTz = chrono::DateTime<chrono::Utc>;
37
38/// Maps to `DATE`.
39pub type Date = chrono::NaiveDate;
40
41// ── Numeric types ──
42
43/// Maps to `NUMERIC`. Override precision/scale with `#[col(precision = N, scale = N)]`.
44pub type Decimal = f64;
45
46// ── Binary / JSON ──
47
48/// Maps to `JSON`.
49pub type Json = serde_json::Value;
50
51/// Maps to `JSONB`.
52pub type Jsonb = serde_json::Value;
53
54/// Maps to `BYTEA` (Postgres) / `BLOB` (SQLite).
55pub type Bytes = Vec<u8>;