Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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 typeGenerated SQLite column typeNotes
bool, i16, i32, i64INTEGERBooleans are bound/decoded through SQLx.
f32, f64REAL
String, serde_json::ValueTEXTJSON is serialized as JSON text and parsed when read.
Vec<u8>BLOBRaw bytes.
uuid::Uuid (uuid)TEXTSQLx SQLite UUID encoding/decoding is used.
chrono / time date-time typesTEXTSQLx’s SQLite type support is used.
Decimal, BigDecimalTEXTText representation avoids SQLite numeric-affinity precision loss; values are parsed on read.
IP address/network typesTEXTText representation is parsed on read.
MacAddressTEXTText representation is parsed on read.
BitVecTEXTStored 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 use 0/1, integers use Unix seconds, floats use fractional Unix seconds, text uses CURRENT_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.