pub struct JsonDataType {
pub storage_format: JsonStorageFormat,
pub validate_on_insert: bool,
}Expand description
JSON/Semi-structured data type.
Database mapping details:
| Platform | Type | Notes |
|---|---|---|
PostgreSQL | JSON or JSONB | JSONB supports GIN indexing and is faster for queries |
| SQL Server | NVARCHAR(MAX) with JSON functions (2016+), or native JSON (2025+) | |
| Snowflake | VARIANT | Native semi-structured type, supports nested data and arrays |
| Databricks | STRING with JSON functions, or VARIANT | |
ClickHouse | JSON (experimental/production), or String with JSON functions | |
CitusDB | Same as PostgreSQL (JSONB recommended) |
§Storage Formats
- Binary (default): Normalized storage, faster queries, indexable.
Maps to
JSONBinPostgreSQL,VARIANTin Snowflake. - Text: Preserves whitespace, key order, and duplicate keys.
Maps to
JSONinPostgreSQL,NVARCHAR(MAX)in SQL Server.
§Example
use razeri_plugin_contract::DataType;
use razeri_plugin_contract::data_type::{JsonDataType, JsonStorageFormat};
// Binary format (recommended) - uses JSONB in PostgreSQL, VARIANT in Snowflake
let json_binary = JsonDataType::default();
assert_eq!(json_binary.storage_format, JsonStorageFormat::Binary);
// Text format - preserves original formatting
let json_text = JsonDataType::text();
assert_eq!(json_text.storage_format, JsonStorageFormat::Text);
// Via DataType convenience
let data = DataType::json();Fields§
§storage_format: JsonStorageFormatStorage format preference (binary is recommended for most use cases).
validate_on_insert: boolWhether to validate JSON on insert (if supported by the database).
PostgreSQL always validates, some other databases may not.
Implementations§
Source§impl JsonDataType
impl JsonDataType
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new JSON type with binary storage format (JSONB in PostgreSQL).
This is the recommended format for most use cases as it enables:
- Faster query performance
- GIN indexing support (
PostgreSQL) - Normalized storage (no duplicate keys, sorted keys)
§Example
use razeri_plugin_contract::data_type::{JsonDataType, JsonStorageFormat};
let json = JsonDataType::new();
assert_eq!(json.storage_format, JsonStorageFormat::Binary);
assert!(!json.validate_on_insert);Sourcepub fn text() -> Self
pub fn text() -> Self
Creates a JSON type with text storage format.
Use this when you need to preserve:
- Original whitespace formatting
- Original key order
- Duplicate keys (not recommended but sometimes required)
§Example
use razeri_plugin_contract::data_type::{JsonDataType, JsonStorageFormat};
let json = JsonDataType::text();
assert_eq!(json.storage_format, JsonStorageFormat::Text);
assert!(json.validate_on_insert);Sourcepub fn binary() -> Self
pub fn binary() -> Self
Creates a JSON type with binary storage format.
§Example
use razeri_plugin_contract::data_type::{JsonDataType, JsonStorageFormat};
let json = JsonDataType::binary();
assert_eq!(json.storage_format, JsonStorageFormat::Binary);
assert!(json.validate_on_insert);Sourcepub fn with_validation(self, validate: bool) -> Self
pub fn with_validation(self, validate: bool) -> Self
Sets whether to validate JSON on insert.
§Example
use razeri_plugin_contract::data_type::JsonDataType;
let json = JsonDataType::new().with_validation(false);
assert!(!json.validate_on_insert);Trait Implementations§
Source§impl Clone for JsonDataType
impl Clone for JsonDataType
Source§impl Debug for JsonDataType
impl Debug for JsonDataType
Source§impl Default for JsonDataType
impl Default for JsonDataType
impl Eq for JsonDataType
Source§impl Hash for JsonDataType
impl Hash for JsonDataType
Source§impl PartialEq for JsonDataType
impl PartialEq for JsonDataType
impl StructuralPartialEq for JsonDataType
Auto Trait Implementations§
impl Forget for JsonDataType
impl Freeze for JsonDataType
impl Move for JsonDataType
impl RefUnwindSafe for JsonDataType
impl Send for JsonDataType
impl Sync for JsonDataType
impl Unpin for JsonDataType
impl UnsafeUnpin for JsonDataType
impl UnwindSafe for JsonDataType
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more