SQLite Types
Enable the sqlite Cargo feature to use the native SQLx SQLite pool. SQLite uses dynamic typing;
the declared column types below are the schema affinities generated by afastorm, not strict
validation of every stored value.
Model field mapping
| Rust model type | Generated SQLite column type | Notes |
|---|---|---|
bool, i16, i32, i64 | INTEGER | Booleans are bound/decoded through SQLx. |
f32, f64 | REAL | |
String, serde_json::Value | TEXT | JSON is serialized as JSON text and parsed when read. |
Vec<u8> | BLOB | Raw bytes. |
uuid::Uuid (uuid) | TEXT | SQLx SQLite UUID encoding/decoding is used. |
chrono / time date-time types | TEXT | SQLx’s SQLite type support is used. |
Decimal, BigDecimal | TEXT | Text representation avoids SQLite numeric-affinity precision loss; values are parsed on read. |
| IP address/network types | TEXT | Text representation is parsed on read. |
MacAddress | TEXT | Text representation is parsed on read. |
BitVec | TEXT | Stored as a string of 0 and 1 characters. |
Enable each optional type’s matching afastorm feature. ipnetwork, ipnet, mac_address, and
bit-vec also enable the PostgreSQL Cargo feature, but their SQLite text handling is available
when connecting to SQLite.
PgArray<T> and PgRange<T> are PostgreSQL-only. If included in SQLite model metadata, their
columns are declared TEXT; values may be bound as text, but afastorm does not decode them as
SQLite model fields. Do not use them in SQLite models or repositories.
SQLite-specific behavior
- Auto-increment primary keys are declared
INTEGER PRIMARY KEY AUTOINCREMENT. - For
auto_create,auto_update, and soft-delete values, booleans use0/1, integers use Unix seconds, floats use fractional Unix seconds, text usesCURRENT_TIMESTAMP, and JSON stores the timestamp as a JSON string. - SQLite migration generation rejects column type changes and ambiguous/destructive schema changes; write and review those migrations manually.
- SQLite migrations are run in a transaction per migration by the built-in runner.
For general model usage, see Models. For PostgreSQL’s native type mappings, see PostgreSQL Types.