Skip to main content

DbType

Trait DbType 

Source
pub trait DbType:
    Sized
    + Send
    + Sync
    + 'static {
    const SQL_TYPE: SqlType;
    const NULLABLE: bool = false;

    // Required methods
    fn to_value(&self) -> Value;
    fn from_value(value: Value) -> Result<Self, String>;
}
Expand description

A Rust type that can be stored in a model column.

Required Associated Constants§

Source

const SQL_TYPE: SqlType

Column type family.

Provided Associated Constants§

Source

const NULLABLE: bool = false

Whether the column accepts NULL (true only for Option<T>).

Required Methods§

Source

fn to_value(&self) -> Value

Convert to a bind value.

Source

fn from_value(value: Value) -> Result<Self, String>

Decode from a value read from any backend.

§Errors

A human-readable reason when value has the wrong shape; callers wrap it into QueryError::Decode with the column name.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl DbType for DateTime<Utc>

Source§

const SQL_TYPE: SqlType = SqlType::Timestamp

Source§

fn to_value(&self) -> Value

Source§

fn from_value(value: Value) -> Result<Self, String>

Source§

impl DbType for Decimal

Source§

const SQL_TYPE: SqlType = SqlType::Decimal

Source§

fn to_value(&self) -> Value

Source§

fn from_value(value: Value) -> Result<Self, String>

Source§

impl DbType for IpAddr

Source§

const SQL_TYPE: SqlType = SqlType::IpAddr

Source§

fn to_value(&self) -> Value

Source§

fn from_value(value: Value) -> Result<Self, String>

Source§

impl DbType for NaiveDate

Source§

const SQL_TYPE: SqlType = SqlType::Date

Source§

fn to_value(&self) -> Value

Source§

fn from_value(value: Value) -> Result<Self, String>

Source§

impl DbType for NaiveTime

Source§

const SQL_TYPE: SqlType = SqlType::Time

Source§

fn to_value(&self) -> Value

Source§

fn from_value(value: Value) -> Result<Self, String>

Source§

impl DbType for String

Source§

const SQL_TYPE: SqlType = SqlType::Text

Source§

fn to_value(&self) -> Value

Source§

fn from_value(value: Value) -> Result<Self, String>

Source§

impl DbType for TimeDelta

Source§

const SQL_TYPE: SqlType = SqlType::Duration

Source§

fn to_value(&self) -> Value

Source§

fn from_value(value: Value) -> Result<Self, String>

Source§

impl DbType for Uuid

Source§

const SQL_TYPE: SqlType = SqlType::Uuid

Source§

fn to_value(&self) -> Value

Source§

fn from_value(value: Value) -> Result<Self, String>

Source§

impl DbType for Value

Source§

const SQL_TYPE: SqlType = SqlType::Json

Source§

fn to_value(&self) -> Value

Source§

fn from_value(value: Value) -> Result<Self, String>

Source§

impl DbType for Vec<u8>

Source§

const SQL_TYPE: SqlType = SqlType::Binary

Source§

fn to_value(&self) -> Value

Source§

fn from_value(value: Value) -> Result<Self, String>

Source§

impl DbType for bool

Source§

const SQL_TYPE: SqlType = SqlType::Bool

Source§

fn to_value(&self) -> Value

Source§

fn from_value(value: Value) -> Result<Self, String>

Source§

impl DbType for f32

Source§

const SQL_TYPE: SqlType = SqlType::Real

Source§

fn to_value(&self) -> Value

Source§

fn from_value(value: Value) -> Result<Self, String>

Source§

impl DbType for f64

Source§

const SQL_TYPE: SqlType = SqlType::Double

Source§

fn to_value(&self) -> Value

Source§

fn from_value(value: Value) -> Result<Self, String>

Source§

impl DbType for i16

Source§

const SQL_TYPE: SqlType = SqlType::SmallInt

Source§

fn to_value(&self) -> Value

Source§

fn from_value(value: Value) -> Result<Self, String>

Source§

impl DbType for i32

Source§

const SQL_TYPE: SqlType = SqlType::Integer

Source§

fn to_value(&self) -> Value

Source§

fn from_value(value: Value) -> Result<Self, String>

Source§

impl DbType for i64

Source§

const SQL_TYPE: SqlType = SqlType::BigInt

Source§

fn to_value(&self) -> Value

Source§

fn from_value(value: Value) -> Result<Self, String>

Source§

impl<T: DbType> DbType for Option<T>

Source§

const SQL_TYPE: SqlType = T::SQL_TYPE

Source§

const NULLABLE: bool = true

Source§

fn to_value(&self) -> Value

Source§

fn from_value(value: Value) -> Result<Self, String>

Implementors§

Source§

impl<T: Model> DbType for ForeignKey<T>

Source§

const SQL_TYPE: SqlType = <T::Pk as DbType>::SQL_TYPE