remodel-core

Data Types

The DataType enum — dialect-agnostic column types that map to concrete SQL expressions per dialect.

DataType is a dialect-agnostic enumeration of the most common SQL column types. The SQL generation layer maps each variant to the appropriate keyword for PostgreSQL, MySQL, or SQLite.

Variants

VariantRust syntaxDescription
IntegerDataType::Integer32-bit signed integer
BigIntDataType::BigInt64-bit signed integer
SmallIntDataType::SmallInt16-bit signed integer
RealDataType::RealIEEE-754 double-precision float
Decimal(p, s)DataType::Decimal(10, 2)Fixed-precision: p digits, s after the decimal point
BooleanDataType::BooleanTrue/false value
Varchar(n)DataType::Varchar(255)Variable-length text up to n characters
Char(n)DataType::Char(10)Fixed-length text of exactly n characters
TextDataType::TextUnbounded text
DateDataType::DateCalendar date (no time)
TimeDataType::TimeTime of day (no date)
TimestampDataType::TimestampDate + time
UuidDataType::UuidUniversally unique identifier
BytesDataType::BytesOpaque binary blob
Custom(s)DataType::Custom("jsonb".into())Verbatim dialect-specific type string

Default values

DataType::default()         // Varchar(255) — sensible default for text columns
DataType::default_key()     // Integer — used by the converter for synthesized PK columns

Dialect mapping

DataTypePostgreSQLMySQLSQLite
IntegerINTEGERINTINTEGER
BigIntBIGINTBIGINTINTEGER
SmallIntSMALLINTSMALLINTINTEGER
RealDOUBLE PRECISIONDOUBLEREAL
Decimal(p,s)NUMERIC(p,s)DECIMAL(p,s)REAL
BooleanBOOLEANTINYINT(1)INTEGER
Varchar(n)VARCHAR(n)VARCHAR(n)TEXT
Char(n)CHAR(n)CHAR(n)TEXT
TextTEXTTEXTTEXT
DateDATEDATETEXT
TimeTIMETIMETEXT
TimestampTIMESTAMPDATETIMETEXT
UuidUUIDCHAR(36)TEXT
BytesBYTEABLOBBLOB
Custom(s)verbatimverbatimverbatim

SQLite is dynamically typed. All date/time types collapse to TEXT, integers collapse to INTEGER, and floats to REAL. If you need precise SQLite column affinities, use Custom.

Using Custom

Custom lets you bypass the abstraction for dialect-specific types:

// PostgreSQL JSONB
m.add_attribute(
    AttributeOwner::Entity(product),
    "metadata",
    DataType::Custom("jsonb".into()),
)?;

// PostGIS geography
m.add_attribute(
    AttributeOwner::Entity(location),
    "coords",
    DataType::Custom("GEOGRAPHY(POINT, 4326)".into()),
)?;

Custom values are emitted verbatim. They are not validated and may produce invalid SQL if the string is not correct for the target dialect.

On this page