Skip to main content

DataType

Enum DataType 

Source
#[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

CategoryVariantsExample
NumericInteger, Decimal, FloatINT, DECIMAL(19,4), DOUBLE
BooleanBooleanBOOLEAN, BIT
StringChar, VarChar, TextVARCHAR(100), TEXT
BinaryBinary, VarBinaryBYTEA, VARBINARY
Date/TimeDate, Time, Timestamp, TimestampTz, DateTime, IntervalDATE, TIMESTAMP
SpecialUuid, JsonUUID, JSONB
CollectionArray, Map, StructINTEGER[], MAP<TEXT,INT>, STRUCT<a INT>

§Design Principles

  1. Abstract over database-specific implementations — DataType captures enough metadata to generate correct DDL for each target, but does not embed platform-specific syntax.
  2. Preserve precision metadata — Decimal types carry precision and scale; string types carry length constraints; timestamp types carry fractional seconds precision.
  3. 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 as jsonb on PostgreSQL) 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
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

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

Source

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());
Source

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(_)));
Source

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(_)));
Source

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(_)));
Source

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(_)));
Source

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-38
Source

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(_)));
Source

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(_)));
Source

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(_)));
Source

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(_)));
Source

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(_)));
Source

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(_)));
Source

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(_)));
Source

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(_)));
Source

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(_)));
Source

pub fn json() -> Self

Creates a JSON type with binary storage (JSONB in PostgreSQL, VARIANT in Snowflake).

§Example
use razeri_plugin_contract::DataType;

let data = DataType::json();
assert!(matches!(data, DataType::Json(_)));
Source

pub fn json_text() -> Self

Creates a JSON type with text storage (preserves formatting).

§Example
use razeri_plugin_contract::DataType;

let data = DataType::json_text();
assert!(matches!(data, DataType::Json(_)));

Trait Implementations§

Source§

impl Clone for DataType

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for DataType

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for DataType

Source§

impl PartialEq for DataType

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for DataType

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.