Skip to main content

DrizzleSQLiteColumn

Trait DrizzleSQLiteColumn 

Source
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 expressions
  • SQL_TYPE: The SQLite column affinity ("TEXT", "INTEGER", "BLOB", etc.)

§Required Methods

  • decode: Convert a borrowed SQLite value read from the database into Self
  • encode: Convert self to a SQLiteValue for 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§

Source

const SQL_TYPE: &'static str

SQLite column affinity: "TEXT" or "INTEGER"

Required Associated Types§

Source

type SQLType: DataType

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§

Source

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.

Source

fn encode(&self) -> SQLiteValue<'_>

Convert self to a SQLiteValue for insertion/updates.

Provided Methods§

Source

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".

Implementors§