pub trait DrizzleSQLiteColumn: Sized {
type SQLType: SQLiteAffinity;
const SQL_TYPE: &'static str = <Self::SQLType as SQLiteAffinity>::SQL_TYPE;
// Required methods
fn decode(value: SQLiteValueRef<'_>) -> Result<Self, DrizzleError>;
fn encode(&self) -> SQLiteValue<'_>;
// Provided method
fn encode_owned(self) -> OwnedSQLiteValue { ... }
}Expand description
Trait for custom Rust types that map to a SQLite column.
Generated by #[derive(SQLiteEnum)]. Implement this trait manually for
custom wrappers that should be usable directly in table schemas.
§Associated Types
SQLType: The Drizzle SQL type marker used for typed expressions and, throughSQLiteAffinity, DDL/schema affinity metadata.
§Required Methods
decode: Convert a borrowedSQLitevalue read from the database intoSelfencode: Convert self to aSQLiteValuefor insertion/updates
The blanket From<Self> for SQLiteValue owns the encoded value because
insert/update models may store SQL fragments after the source value is
dropped. Call encode() directly when you need an immediate borrowed value.
Override encode_owned() when consuming self can avoid cloning owned data.
Provided Associated Constants§
Sourceconst SQL_TYPE: &'static str = <Self::SQLType as SQLiteAffinity>::SQL_TYPE
const SQL_TYPE: &'static str = <Self::SQLType as SQLiteAffinity>::SQL_TYPE
SQLite affinity spelling retained for source compatibility with custom column implementations.
Schema generation uses SQLType and
SQLiteAffinity as the authority, so overriding this constant does
not change the generated column type.
Required Associated Types§
Sourcetype SQLType: SQLiteAffinity
type SQLType: SQLiteAffinity
Drizzle SQL type marker for this column.
Use one of the built-in SQLite markers, such as Text, Integer,
Blob, Real, Numeric, or Any.
Required Methods§
Sourcefn decode(value: SQLiteValueRef<'_>) -> Result<Self, DrizzleError>
fn decode(value: SQLiteValueRef<'_>) -> Result<Self, DrizzleError>
Decode a borrowed SQLite value read from the database into Self.
Implementations should reject unsupported storage classes with
DrizzleError::ConversionError.
§Errors
Returns DrizzleError::ConversionError if value cannot be decoded
as this custom column type.
Sourcefn encode(&self) -> SQLiteValue<'_>
fn encode(&self) -> SQLiteValue<'_>
Convert self to a SQLiteValue for insertion/updates.
Provided Methods§
Sourcefn encode_owned(self) -> OwnedSQLiteValue
fn encode_owned(self) -> OwnedSQLiteValue
Convert self to an owned SQLite value for stored bind parameters.
The default implementation owns the borrowed result of encode.
Override this for wrappers that can move an internal string or byte buffer
directly into the SQL parameter.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".