Skip to main content

Module data_type

Module data_type 

Source
Expand description

Generic data types for cross-database compatibility.

This module defines the unified DataType enum and all component types (integer, decimal, float, boolean, string, binary, date/time, special, and collection types) that serve as the foundation for SQL rendering across all supported database platforms.

§Design Philosophy

  • Abstract over database-specific implementations — DataType captures 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 as jsonb on PostgreSQL) rather than refusing.

§Type Categories

CategoryTypesExample
IntegerIntegerDataTypeINT, BIGINT, TINYINT
DecimalDecimalDataTypeDECIMAL(19,4), DECIMAL(5,2)
FloatFloatDataTypeREAL, DOUBLE
BooleanBooleanDataTypeBOOLEAN, BIT
StringCharDataType, VarCharDataType, TextDataTypeVARCHAR(100), TEXT
BinaryBinaryDataType, VarBinaryDataTypeBYTEA, VARBINARY
Date/TimeDateDataType, TimestampDataType, TimestampTzDataTypeDATE, TIMESTAMP
SpecialUuidDataType, JsonDataTypeUUID, JSONB
CollectionArrayDataType, MapDataType, StructDataTypeINTEGER[], MAP<TEXT,INT>, STRUCT<a INT>

§Usage

Convenience constructors for common types:

use razeri_plugin_contract::DataType;

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

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.

Structs§

ArrayDataType
Array type containing elements of another type.
BinaryDataType
Fixed-length binary data.
BooleanDataType
Boolean data type (true/false).
CharDataType
Fixed-length character string.
DateDataType
Date only (year, month, day) without time component.
DateTimeDataType
Combined date and time for legacy compatibility.
DecimalDataType
Exact numeric type with fixed precision and scale.
FloatDataType
Approximate floating-point numeric type.
IntegerDataType
Integer data type supporting signed/unsigned variants.
JsonDataType
JSON/Semi-structured data type.
MapDataType
Map/Dictionary type with key-value pairs.
StructDataType
Struct/record type: an ordered list of named fields.
StructField
One named field inside a StructDataType, in the order it was declared.
TextDataType
Unbounded text type for large text storage.
TimeDataType
Time only without date component.
TimestampDataType
Timestamp (date and time) without timezone.
TimestampTzDataType
Timestamp with timezone awareness.
UuidDataType
Universally Unique Identifier (UUID/GUID).
VarBinaryDataType
Variable-length binary data.
VarCharDataType
Variable-length character string with optional max length.

Enums§

DataType
Unified data type enumeration covering all supported types across databases.
DataTypeRef
Simplified data type reference used in CAST / TRY_CAST / CONVERT expressions.
FloatPrecision
Floating point precision variants.
IntegerSize
Integer size variants matching common database integer types.
IntervalDataType
Interval/duration type for time spans.
JsonStorageFormat
JSON storage format preference.
StringEncoding
Character encoding for string types.