[]Trait c3p0_pg::postgres::types::FromSql

pub trait FromSql {
    fn from_sql(
        ty: &Type,
        raw: &[u8]
    ) -> Result<Self, Box<dyn Error + 'static + Send + Sync>>;
fn accepts(ty: &Type) -> bool; fn from_sql_null(
        ty: &Type
    ) -> Result<Self, Box<dyn Error + 'static + Send + Sync>> { ... }
fn from_sql_nullable(
        ty: &Type,
        raw: Option<&[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 typePostgres type(s)
boolBOOL
i8"char"
i16SMALLINT, SMALLSERIAL
i32INT, SERIAL
u32OID
i64BIGINT, BIGSERIAL
f32REAL
f64DOUBLE PRECISION
StringVARCHAR, CHAR(n), TEXT, CITEXT, NAME, UNKNOWN
Vec<u8>BYTEA
HashMap<String, Option<String>>HSTORE

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 feature enables the implementation for the serde_json::Value type.

Rust typePostgres type(s)
serialize::json::JsonJSON, JSONB
serde_json::ValueJSON, JSONB
time::TimespecTIMESTAMP, TIMESTAMP WITH TIME ZONE
chrono::NaiveDateTimeTIMESTAMP
chrono::DateTime<Utc>TIMESTAMP WITH TIME ZONE
chrono::DateTime<Local>TIMESTAMP WITH TIME ZONE
chrono::DateTime<FixedOffset>TIMESTAMP WITH TIME ZONE
chrono::NaiveDateDATE
chrono::NaiveTimeTIME
eui48::MacAddressMACADDR
uuid::UuidUUID
bit_vec::BitVecBIT, VARBIT
eui48::MacAddressMACADDR

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: &[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

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

fn from_sql_nullable(
    ty: &Type,
    raw: Option<&[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 FromSql for i8

impl FromSql for bool

impl<T> FromSql for Option<T> where
    T: FromSql

impl FromSql for u32

impl FromSql for f64

impl FromSql for Vec<u8>

impl FromSql for i64

impl FromSql for HashMap<String, Option<String>, RandomState>

impl<T> FromSql for Vec<T> where
    T: FromSql

impl FromSql for i32

impl FromSql for Value

impl FromSql for i16

impl FromSql for String

impl FromSql for f32

Loading content...

Implementors

impl<T> FromSql for Date<T> where
    T: FromSql

impl<T> FromSql for Timestamp<T> where
    T: FromSql

Loading content...