#[non_exhaustive]pub enum DataType {
Show 20 variants
Integer(IntegerDataType),
Decimal(DecimalDataType),
Float(FloatDataType),
Boolean(BooleanDataType),
Char(CharDataType),
VarChar(VarCharDataType),
Text(TextDataType),
Binary(BinaryDataType),
VarBinary(VarBinaryDataType),
Date(DateDataType),
Time(TimeDataType),
Timestamp(TimestampDataType),
TimestampTz(TimestampTzDataType),
DateTime(DateTimeDataType),
Interval(IntervalDataType),
Uuid(UuidDataType),
Json(JsonDataType),
Array(ArrayDataType),
Map(MapDataType),
Struct(StructDataType),
}Expand description
Unified data type enumeration covering all supported types across databases.
This is the primary type system for Razeri. Every field, column, and
parameter in a design document is typed using DataType. The enum captures
enough metadata to generate correct DDL for every target while remaining
abstract over platform-specific implementation details.
§Type Categories
| Category | Variants | Example |
|---|---|---|
| Numeric | Integer, Decimal, Float | INT, DECIMAL(19,4), DOUBLE |
| Boolean | Boolean | BOOLEAN, BIT |
| String | Char, VarChar, Text | VARCHAR(100), TEXT |
| Binary | Binary, VarBinary | BYTEA, VARBINARY |
| Date/Time | Date, Time, Timestamp, TimestampTz, DateTime, Interval | DATE, TIMESTAMP |
| Special | Uuid, Json | UUID, JSONB |
| Collection | Array, Map, Struct | INTEGER[], MAP<TEXT,INT>, STRUCT<a INT> |
§Design Principles
- Abstract over database-specific implementations —
DataTypecaptures enough metadata to generate correct DDL for each target, but does not embed platform-specific syntax. - Preserve precision metadata — Decimal types carry precision and scale; string types carry length constraints; timestamp types carry fractional seconds precision.
- Every type renders somewhere — a dialect answers for every variant,
emulating a type it does not have (JSON stored as
NVARCHAR(MAX)on SQL Server, a struct stored asjsonbonPostgreSQL) rather than refusing.
§Usage
use razeri_plugin_contract::DataType;
// Convenience constructors for common types
let id = DataType::bigint();
let name = DataType::varchar(255);
let price = DataType::decimal(19, 4);
let created = DataType::timestamp();
// JSON with binary storage (JSONB in PostgreSQL, VARIANT in Snowflake)
let data = DataType::json();§Cross-Database Mapping
Each variant maps to platform-specific types as documented in the variant
definitions. Dialect plugins resolve the final SQL type string during
rendering; the rendering traits live in this crate’s renderer module.
§The enum is #[non_exhaustive]
New types are added over time, so a match outside this crate needs a
fallback arm. A dialect’s fallback should render the closest type the engine
does have — its JSON or text type — rather than panicking: a type the
dialect has not been taught about is still a column someone declared.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Integer(IntegerDataType)
Signed/unsigned integer (1, 2, 4, or 8 bytes).
Decimal(DecimalDataType)
Exact numeric with fixed precision and scale.
Float(FloatDataType)
Approximate floating-point (4 or 8 bytes).
Boolean(BooleanDataType)
Boolean (true/false).
Char(CharDataType)
Fixed-length character string.
VarChar(VarCharDataType)
Variable-length character string.
Text(TextDataType)
Unbounded text type.
Binary(BinaryDataType)
Fixed-length binary data.
VarBinary(VarBinaryDataType)
Variable-length binary data.
Date(DateDataType)
Date only (year, month, day).
Time(TimeDataType)
Time only (hour, minute, second, optional timezone).
Timestamp(TimestampDataType)
Timestamp without timezone.
TimestampTz(TimestampTzDataType)
Timestamp with timezone.
DateTime(DateTimeDataType)
Combined date and time (legacy).
Interval(IntervalDataType)
Interval/duration.
Uuid(UuidDataType)
UUID/GUID.
Json(JsonDataType)
JSON/semi-structured data.
Array(ArrayDataType)
Array of elements.
Map(MapDataType)
Map/dictionary with key-value pairs.
Struct(StructDataType)
Record with an ordered list of named fields.
Implementations§
Source§impl DataType
impl DataType
Sourcepub const fn is_nested(&self) -> bool
pub const fn is_nested(&self) -> bool
Whether this type holds more than one value inside one column — an array, a map, or a record.
Nested columns are answered differently from scalars in several places: they cannot be part of a key, nothing aggregates them, and an engine with no record type of its own stores them as JSON or text. This is the one question all of those ask, so they ask it the same way.
§Example
use razeri_plugin_contract::{DataType, data_type::ArrayDataType};
assert!(DataType::Array(ArrayDataType::new(DataType::int())).is_nested());
assert!(!DataType::bigint().is_nested());Sourcepub fn tinyint() -> Self
pub fn tinyint() -> Self
Creates a 1-byte signed integer (TINYINT / SMALLINT / Int8).
§Example
use razeri_plugin_contract::DataType;
let ty = DataType::tinyint();
assert!(matches!(ty, DataType::Integer(_)));Sourcepub fn smallint() -> Self
pub fn smallint() -> Self
Creates a 2-byte signed integer (SMALLINT / Int16).
§Example
use razeri_plugin_contract::DataType;
let ty = DataType::smallint();
assert!(matches!(ty, DataType::Integer(_)));Sourcepub fn int() -> Self
pub fn int() -> Self
Creates a 4-byte signed integer (INT / INTEGER / Int32).
§Example
use razeri_plugin_contract::DataType;
let id = DataType::int();
assert!(matches!(id, DataType::Integer(_)));Sourcepub fn bigint() -> Self
pub fn bigint() -> Self
Creates an 8-byte signed integer (BIGINT / Int64).
§Example
use razeri_plugin_contract::DataType;
let id = DataType::bigint();
assert!(matches!(id, DataType::Integer(_)));Sourcepub fn decimal(precision: u8, scale: u8) -> Self
pub fn decimal(precision: u8, scale: u8) -> Self
Creates a DECIMAL(precision, scale) type.
§Panics
Panics if precision is 0 or exceeds 38, or if scale > precision.
§Example
use razeri_plugin_contract::DataType;
let price = DataType::decimal(19, 4);
assert!(matches!(price, DataType::Decimal(_)));use razeri_plugin_contract::DataType;
let _ = DataType::decimal(0, 0); // panics: precision must be 1-38Sourcepub fn float() -> Self
pub fn float() -> Self
Creates a single-precision float (REAL / FLOAT4).
§Example
use razeri_plugin_contract::DataType;
let ty = DataType::float();
assert!(matches!(ty, DataType::Float(_)));Sourcepub fn double() -> Self
pub fn double() -> Self
Creates a double-precision float (DOUBLE PRECISION / DOUBLE).
§Example
use razeri_plugin_contract::DataType;
let ty = DataType::double();
assert!(matches!(ty, DataType::Float(_)));Sourcepub fn boolean() -> Self
pub fn boolean() -> Self
Creates a boolean type (BOOLEAN / BIT).
§Example
use razeri_plugin_contract::DataType;
let ty = DataType::boolean();
assert!(matches!(ty, DataType::Boolean(_)));Sourcepub fn varchar(max_length: u32) -> Self
pub fn varchar(max_length: u32) -> Self
Creates a VARCHAR(max_length) type.
§Example
use razeri_plugin_contract::DataType;
let name = DataType::varchar(255);
assert!(matches!(name, DataType::VarChar(_)));Sourcepub fn text() -> Self
pub fn text() -> Self
Creates an unbounded text type (TEXT / VARCHAR(MAX) / STRING).
§Example
use razeri_plugin_contract::DataType;
let ty = DataType::text();
assert!(matches!(ty, DataType::Text(_)));Sourcepub fn date() -> Self
pub fn date() -> Self
Creates a date-only type (DATE).
§Example
use razeri_plugin_contract::DataType;
let ty = DataType::date();
assert!(matches!(ty, DataType::Date(_)));Sourcepub fn timestamp() -> Self
pub fn timestamp() -> Self
Creates a timestamp without timezone (TIMESTAMP).
§Example
use razeri_plugin_contract::DataType;
let created = DataType::timestamp();
assert!(matches!(created, DataType::Timestamp(_)));Sourcepub fn timestamp_tz() -> Self
pub fn timestamp_tz() -> Self
Creates a timestamp with timezone (TIMESTAMPTZ / DATETIMEOFFSET).
§Example
use razeri_plugin_contract::DataType;
let created_tz = DataType::timestamp_tz();
assert!(matches!(created_tz, DataType::TimestampTz(_)));Sourcepub fn uuid() -> Self
pub fn uuid() -> Self
Creates a UUID type (UUID / UNIQUEIDENTIFIER).
§Example
use razeri_plugin_contract::DataType;
let ty = DataType::uuid();
assert!(matches!(ty, DataType::Uuid(_)));