toasty_core/schema/app/field/
primitive.rs

1use crate::{schema::db, stmt};
2
3/// The serialization format used to store a field value in the database.
4///
5/// When a field's in-memory type does not map directly to a database column
6/// type, the value is serialized into a format the database can store (e.g.,
7/// a JSON string column).
8///
9/// # Examples
10///
11/// ```
12/// use toasty_core::schema::app::SerializeFormat;
13///
14/// let fmt = SerializeFormat::Json;
15/// ```
16#[derive(Debug, Clone)]
17pub enum SerializeFormat {
18    /// Serialize the value as JSON using `serde_json`.
19    Json,
20}
21
22/// A primitive (non-relation, non-embedded) field type.
23///
24/// Primitive fields map directly to a single database column. They carry the
25/// application-level type, an optional storage-type hint for the database
26/// driver, and an optional serialization format.
27///
28/// # Examples
29///
30/// ```
31/// use toasty_core::schema::app::FieldPrimitive;
32/// use toasty_core::stmt::Type;
33///
34/// let prim = FieldPrimitive {
35///     ty: Type::String,
36///     storage_ty: None,
37///     serialize: None,
38/// };
39/// ```
40#[derive(Debug, Clone)]
41pub struct FieldPrimitive {
42    /// The application-level primitive type of this field.
43    pub ty: stmt::Type,
44
45    /// Optional database storage type hint. When set, the driver uses this
46    /// type instead of inferring one from `ty`.
47    pub storage_ty: Option<db::Type>,
48
49    /// If set, the field value is serialized using the specified format
50    /// before being written to the database.
51    pub serialize: Option<SerializeFormat>,
52}