Skip to main content

Module types

Module types 

Source
Expand description

Mapping between Rust field types, SQL column types and Value.

DbType is implemented for every type a model field may have. The Model derive uses DbType::SQL_TYPE and DbType::NULLABLE for migration metadata and DbType::to_value / DbType::from_value for writes and reads.

§Canonical storage forms

Backends without a native column type store a canonical form, and from_value accepts both the native value and that form:

Rust typeNative ValueCanonical fallback
boolBoolInt 0/1
DecimalDecimalText ("12.50"), Int, Float
UuidUuidText (hyphenated) or 16 Bytes
NaiveDateDateText DATE_FORMAT
NaiveTimeTimeText TIME_FORMAT
DateTime<Utc>TimestampText TIMESTAMP_FORMAT (fixed width, so text order = time order)
TimeDeltaInt (microseconds)—
IpAddrText—
serde_json::ValueJsonText holding JSON

Integer and float types also accept Decimal (integral, respectively any value), because PostgreSQL returns numeric for SUM and AVG. On SQLite, declare Decimal columns NUMERIC: the canonical text form would otherwise sort and aggregate as text.

Enums§

SqlType
Portable column type family. Backends map it to concrete DDL.

Constants§

DATE_FORMAT
Text form of dates on backends without a native date type.
TIMESTAMP_FORMAT
Text form of UTC timestamps (always 6 fractional digits and Z).
TIME_FORMAT
Text form of times of day.

Traits§

DbType
A Rust type that can be stored in a model column.

Functions§

canonical_text
Canonical text for values a backend cannot store natively (see module docs).
decode
Decode column column of value as T, naming the column on failure.