[][src]Trait postgres::types::FromSql

pub trait FromSql<'a> {
    fn from_sql(
        ty: &Type,
        raw: &'a [u8]
    ) -> Result<Self, Box<dyn Error + 'static + Send + Sync>>;
fn accepts(ty: &Type) -> bool; default fn from_sql_null(
        ty: &Type
    ) -> Result<Self, Box<dyn Error + 'static + Send + Sync>> { ... }
default fn from_sql_nullable(
        ty: &Type,
        raw: Option<&'a [u8]>
    ) -> Result<Self, Box<dyn Error + 'static + Send + Sync>> { ... } }

A trait for types that can be created from a Postgres value.

Types

The following implementations are provided by this crate, along with the corresponding Postgres types:

Rust type Postgres type(s)
bool BOOL
i8 "char"
i16 SMALLINT, SMALLSERIAL
i32 INT, SERIAL
u32 OID
i64 BIGINT, BIGSERIAL
f32 REAL
f64 DOUBLE PRECISION
&str/String VARCHAR, CHAR(n), TEXT, CITEXT, NAME, UNKNOWN
&[u8]/Vec<u8> BYTEA
HashMap<String, Option<String>> HSTORE
SystemTime TIMESTAMP, TIMESTAMP WITH TIME ZONE

In addition, some implementations are provided for types in third party crates. These are disabled by default; to opt into one of these implementations, activate the Cargo feature corresponding to the crate's name prefixed by with-. For example, the with-serde_json-1 feature enables the implementation for the serde_json::Value type.

Rust type Postgres type(s)
chrono::NaiveDateTime TIMESTAMP
chrono::DateTime<Utc> TIMESTAMP WITH TIME ZONE
chrono::DateTime<Local> TIMESTAMP WITH TIME ZONE
chrono::DateTime<FixedOffset> TIMESTAMP WITH TIME ZONE
chrono::NaiveDate DATE
chrono::NaiveTime TIME
eui48::MacAddress MACADDR
geo_types::Point<f64> POINT
geo_types::Rect<f64> BOX
geo_types::LineString<f64> PATH
serde_json::Value JSON, JSONB
uuid::Uuid UUID
bit_vec::BitVec BIT, VARBIT
eui48::MacAddress MACADDR

Nullability

In addition to the types listed above, FromSql is implemented for Option<T> where T implements FromSql. An Option<T> represents a nullable Postgres value.

Arrays

FromSql is implemented for Vec<T> where T implements FromSql, and corresponds to one-dimensional Postgres arrays.

Required methods

fn from_sql(
    ty: &Type,
    raw: &'a [u8]
) -> Result<Self, Box<dyn Error + 'static + Send + Sync>>

Creates a new value of this type from a buffer of data of the specified Postgres Type in its binary format.

The caller of this method is responsible for ensuring that this type is compatible with the Postgres Type.

fn accepts(ty: &Type) -> bool

Determines if a value of this type can be created from the specified Postgres Type.

Loading content...

Provided methods

default fn from_sql_null(
    ty: &Type
) -> Result<Self, Box<dyn Error + 'static + Send + Sync>>

Creates a new value of this type from a NULL SQL value.

The caller of this method is responsible for ensuring that this type is compatible with the Postgres Type.

The default implementation returns Err(Box::new(WasNull)).

default fn from_sql_nullable(
    ty: &Type,
    raw: Option<&'a [u8]>
) -> Result<Self, Box<dyn Error + 'static + Send + Sync>>

A convenience function that delegates to from_sql and from_sql_null depending on the value of raw.

Loading content...

Implementations on Foreign Types

impl<'a> FromSql<'a> for i32[src]

default fn from_sql_null(
    ty: &Type
) -> Result<Self, Box<dyn Error + 'static + Send + Sync>>
[src]

default fn from_sql_nullable(
    ty: &Type,
    raw: Option<&'a [u8]>
) -> Result<Self, Box<dyn Error + 'static + Send + Sync>>
[src]

impl<'a> FromSql<'a> for DateTime<FixedOffset>[src]

default fn from_sql_null(
    ty: &Type
) -> Result<Self, Box<dyn Error + 'static + Send + Sync>>
[src]

default fn from_sql_nullable(
    ty: &Type,
    raw: Option<&'a [u8]>
) -> Result<Self, Box<dyn Error + 'static + Send + Sync>>
[src]

impl<'a> FromSql<'a> for f32[src]

default fn from_sql_null(
    ty: &Type
) -> Result<Self, Box<dyn Error + 'static + Send + Sync>>
[src]

default fn from_sql_nullable(
    ty: &Type,
    raw: Option<&'a [u8]>
) -> Result<Self, Box<dyn Error + 'static + Send + Sync>>
[src]

impl<'a> FromSql<'a> for NaiveTime[src]

default fn from_sql_null(
    ty: &Type
) -> Result<Self, Box<dyn Error + 'static + Send + Sync>>
[src]

default fn from_sql_nullable(
    ty: &Type,
    raw: Option<&'a [u8]>
) -> Result<Self, Box<dyn Error + 'static + Send + Sync>>
[src]

impl<'a> FromSql<'a> for DateTime<Local>[src]

default fn from_sql_null(
    ty: &Type
) -> Result<Self, Box<dyn Error + 'static + Send + Sync>>
[src]

default fn from_sql_nullable(
    ty: &Type,
    raw: Option<&'a [u8]>
) -> Result<Self, Box<dyn Error + 'static + Send + Sync>>
[src]

impl<'a> FromSql<'a> for SystemTime[src]

default fn from_sql_null(
    ty: &Type
) -> Result<Self, Box<dyn Error + 'static + Send + Sync>>
[src]

default fn from_sql_nullable(
    ty: &Type,
    raw: Option<&'a [u8]>
) -> Result<Self, Box<dyn Error + 'static + Send + Sync>>
[src]

impl<'a> FromSql<'a> for Uuid[src]

default fn from_sql_null(
    ty: &Type
) -> Result<Self, Box<dyn Error + 'static + Send + Sync>>
[src]

default fn from_sql_nullable(
    ty: &Type,
    raw: Option<&'a [u8]>
) -> Result<Self, Box<dyn Error + 'static + Send + Sync>>
[src]

impl<'a> FromSql<'a> for Vec<u8>[src]

default fn from_sql_null(
    ty: &Type
) -> Result<Self, Box<dyn Error + 'static + Send + Sync>>
[src]

default fn from_sql_nullable(
    ty: &Type,
    raw: Option<&'a [u8]>
) -> Result<Self, Box<dyn Error + 'static + Send + Sync>>
[src]

impl<'a> FromSql<'a> for DateTime<Utc>[src]

default fn from_sql_null(
    ty: &Type
) -> Result<Self, Box<dyn Error + 'static + Send + Sync>>
[src]

default fn from_sql_nullable(
    ty: &Type,
    raw: Option<&'a [u8]>
) -> Result<Self, Box<dyn Error + 'static + Send + Sync>>
[src]

impl<'a> FromSql<'a> for Rect<f64>[src]

default fn from_sql_null(
    ty: &Type
) -> Result<Self, Box<dyn Error + 'static + Send + Sync>>
[src]

default fn from_sql_nullable(
    ty: &Type,
    raw: Option<&'a [u8]>
) -> Result<Self, Box<dyn Error + 'static + Send + Sync>>
[src]

impl<'a> FromSql<'a> for u32[src]

default fn from_sql_null(
    ty: &Type
) -> Result<Self, Box<dyn Error + 'static + Send + Sync>>
[src]

default fn from_sql_nullable(
    ty: &Type,
    raw: Option<&'a [u8]>
) -> Result<Self, Box<dyn Error + 'static + Send + Sync>>
[src]

impl<'a> FromSql<'a> for NaiveDateTime[src]

default fn from_sql_null(
    ty: &Type
) -> Result<Self, Box<dyn Error + 'static + Send + Sync>>
[src]

default fn from_sql_nullable(
    ty: &Type,
    raw: Option<&'a [u8]>
) -> Result<Self, Box<dyn Error + 'static + Send + Sync>>
[src]

impl<'a> FromSql<'a> for LineString<f64>[src]

default fn from_sql_null(
    ty: &Type
) -> Result<Self, Box<dyn Error + 'static + Send + Sync>>
[src]

default fn from_sql_nullable(
    ty: &Type,
    raw: Option<&'a [u8]>
) -> Result<Self, Box<dyn Error + 'static + Send + Sync>>
[src]

impl<'a, S> FromSql<'a> for HashMap<String, Option<String>, S> where
    S: Default + BuildHasher
[src]

default fn from_sql_null(
    ty: &Type
) -> Result<Self, Box<dyn Error + 'static + Send + Sync>>
[src]

default fn from_sql_nullable(
    ty: &Type,
    raw: Option<&'a [u8]>
) -> Result<Self, Box<dyn Error + 'static + Send + Sync>>
[src]

impl<'a, T> FromSql<'a> for Vec<T> where
    T: FromSql<'a>, 
[src]

default fn from_sql_null(
    ty: &Type
) -> Result<Self, Box<dyn Error + 'static + Send + Sync>>
[src]

default fn from_sql_nullable(
    ty: &Type,
    raw: Option<&'a [u8]>
) -> Result<Self, Box<dyn Error + 'static + Send + Sync>>
[src]

impl<'a> FromSql<'a> for MacAddress[src]

default fn from_sql_null(
    ty: &Type
) -> Result<Self, Box<dyn Error + 'static + Send + Sync>>
[src]

default fn from_sql_nullable(
    ty: &Type,
    raw: Option<&'a [u8]>
) -> Result<Self, Box<dyn Error + 'static + Send + Sync>>
[src]

impl<'a> FromSql<'a> for String[src]

default fn from_sql_null(
    ty: &Type
) -> Result<Self, Box<dyn Error + 'static + Send + Sync>>
[src]

default fn from_sql_nullable(
    ty: &Type,
    raw: Option<&'a [u8]>
) -> Result<Self, Box<dyn Error + 'static + Send + Sync>>
[src]

impl<'a> FromSql<'a> for BitVec<u32>[src]

default fn from_sql_null(
    ty: &Type
) -> Result<Self, Box<dyn Error + 'static + Send + Sync>>
[src]

default fn from_sql_nullable(
    ty: &Type,
    raw: Option<&'a [u8]>
) -> Result<Self, Box<dyn Error + 'static + Send + Sync>>
[src]

impl<'a> FromSql<'a> for bool[src]

default fn from_sql_null(
    ty: &Type
) -> Result<Self, Box<dyn Error + 'static + Send + Sync>>
[src]

default fn from_sql_nullable(
    ty: &Type,
    raw: Option<&'a [u8]>
) -> Result<Self, Box<dyn Error + 'static + Send + Sync>>
[src]

impl<'a> FromSql<'a> for &'a [u8][src]

default fn from_sql_null(
    ty: &Type
) -> Result<Self, Box<dyn Error + 'static + Send + Sync>>
[src]

default fn from_sql_nullable(
    ty: &Type,
    raw: Option<&'a [u8]>
) -> Result<Self, Box<dyn Error + 'static + Send + Sync>>
[src]

impl<'a> FromSql<'a> for i8[src]

default fn from_sql_null(
    ty: &Type
) -> Result<Self, Box<dyn Error + 'static + Send + Sync>>
[src]

default fn from_sql_nullable(
    ty: &Type,
    raw: Option<&'a [u8]>
) -> Result<Self, Box<dyn Error + 'static + Send + Sync>>
[src]

impl<'a> FromSql<'a> for i64[src]

default fn from_sql_null(
    ty: &Type
) -> Result<Self, Box<dyn Error + 'static + Send + Sync>>
[src]

default fn from_sql_nullable(
    ty: &Type,
    raw: Option<&'a [u8]>
) -> Result<Self, Box<dyn Error + 'static + Send + Sync>>
[src]

impl<'a, T> FromSql<'a> for Option<T> where
    T: FromSql<'a>, 
[src]

default fn from_sql_nullable(
    ty: &Type,
    raw: Option<&'a [u8]>
) -> Result<Self, Box<dyn Error + 'static + Send + Sync>>
[src]

impl<'a> FromSql<'a> for Value[src]

default fn from_sql_null(
    ty: &Type
) -> Result<Self, Box<dyn Error + 'static + Send + Sync>>
[src]

default fn from_sql_nullable(
    ty: &Type,
    raw: Option<&'a [u8]>
) -> Result<Self, Box<dyn Error + 'static + Send + Sync>>
[src]

impl<'a> FromSql<'a> for f64[src]

default fn from_sql_null(
    ty: &Type
) -> Result<Self, Box<dyn Error + 'static + Send + Sync>>
[src]

default fn from_sql_nullable(
    ty: &Type,
    raw: Option<&'a [u8]>
) -> Result<Self, Box<dyn Error + 'static + Send + Sync>>
[src]

impl<'a> FromSql<'a> for Point<f64>[src]

default fn from_sql_null(
    ty: &Type
) -> Result<Self, Box<dyn Error + 'static + Send + Sync>>
[src]

default fn from_sql_nullable(
    ty: &Type,
    raw: Option<&'a [u8]>
) -> Result<Self, Box<dyn Error + 'static + Send + Sync>>
[src]

impl<'a> FromSql<'a> for &'a str[src]

default fn from_sql_null(
    ty: &Type
) -> Result<Self, Box<dyn Error + 'static + Send + Sync>>
[src]

default fn from_sql_nullable(
    ty: &Type,
    raw: Option<&'a [u8]>
) -> Result<Self, Box<dyn Error + 'static + Send + Sync>>
[src]

impl<'a> FromSql<'a> for NaiveDate[src]

default fn from_sql_null(
    ty: &Type
) -> Result<Self, Box<dyn Error + 'static + Send + Sync>>
[src]

default fn from_sql_nullable(
    ty: &Type,
    raw: Option<&'a [u8]>
) -> Result<Self, Box<dyn Error + 'static + Send + Sync>>
[src]

impl<'a> FromSql<'a> for i16[src]

default fn from_sql_null(
    ty: &Type
) -> Result<Self, Box<dyn Error + 'static + Send + Sync>>
[src]

default fn from_sql_nullable(
    ty: &Type,
    raw: Option<&'a [u8]>
) -> Result<Self, Box<dyn Error + 'static + Send + Sync>>
[src]

Loading content...

Implementors

impl<'a, T> FromSql<'a> for Date<T> where
    T: FromSql<'a>, 
[src]

default fn from_sql_null(
    ty: &Type
) -> Result<Self, Box<dyn Error + 'static + Send + Sync>>
[src]

default fn from_sql_nullable(
    ty: &Type,
    raw: Option<&'a [u8]>
) -> Result<Self, Box<dyn Error + 'static + Send + Sync>>
[src]

impl<'a, T> FromSql<'a> for Timestamp<T> where
    T: FromSql<'a>, 
[src]

default fn from_sql_null(
    ty: &Type
) -> Result<Self, Box<dyn Error + 'static + Send + Sync>>
[src]

default fn from_sql_nullable(
    ty: &Type,
    raw: Option<&'a [u8]>
) -> Result<Self, Box<dyn Error + 'static + Send + Sync>>
[src]

impl<'a, T> FromSql<'a> for Json<T> where
    T: Deserialize<'a>, 
[src]

default fn from_sql_null(
    ty: &Type
) -> Result<Self, Box<dyn Error + 'static + Send + Sync>>
[src]

default fn from_sql_nullable(
    ty: &Type,
    raw: Option<&'a [u8]>
) -> Result<Self, Box<dyn Error + 'static + Send + Sync>>
[src]

Loading content...