pub trait DrizzleSQLiteColumn: Sized {
type SQLType: DataType;
const SQL_TYPE: &'static str;
// 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 Constants
SQLType: The Drizzle SQL type marker used for typed expressionsSQL_TYPE: TheSQLitecolumn affinity ("TEXT","INTEGER","BLOB", etc.)
§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.
Required Associated Constants§
Required Associated Types§
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".