[][src]Trait postgres::types::ToSql

pub trait ToSql: Debug {
    fn to_sql(
        &self,
        ty: &Type,
        out: &mut BytesMut
    ) -> Result<IsNull, Box<dyn Error + 'static + Sync + Send>>;
fn accepts(ty: &Type) -> bool;
fn to_sql_checked(
        &self,
        ty: &Type,
        out: &mut BytesMut
    ) -> Result<IsNull, Box<dyn Error + 'static + Sync + Send>>; }

A trait for types that can be converted into Postgres values.

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
&str/StringVARCHAR, CHAR(n), TEXT, CITEXT, NAME
&[u8]/Vec<u8>BYTEA
HashMap<String, Option<String>>HSTORE
SystemTimeTIMESTAMP, TIMESTAMP WITH TIME ZONE
IpAddrINET

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 typePostgres type(s)
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
geo_types::Point<f64>POINT
geo_types::Rect<f64>BOX
geo_types::LineString<f64>PATH
serde_json::ValueJSON, JSONB
uuid::UuidUUID
bit_vec::BitVecBIT, VARBIT
eui48::MacAddressMACADDR

Nullability

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

Arrays

ToSql is implemented for Vec<T> and &[T] where T implements ToSql, and corresponds to one-dimensional Postgres arrays with an index offset of 1.

Required methods

fn to_sql(
    &self,
    ty: &Type,
    out: &mut BytesMut
) -> Result<IsNull, Box<dyn Error + 'static + Sync + Send>>

Converts the value of self into the binary format of the specified Postgres Type, appending it to out.

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

The return value indicates if this value should be represented as NULL. If this is the case, implementations must not write anything to out.

fn accepts(ty: &Type) -> bool

Determines if a value of this type can be converted to the specified Postgres Type.

fn to_sql_checked(
    &self,
    ty: &Type,
    out: &mut BytesMut
) -> Result<IsNull, Box<dyn Error + 'static + Sync + Send>>

An adaptor method used internally by Rust-Postgres.

All implementations of this method should be generated by the to_sql_checked!() macro.

Loading content...

Implementations on Foreign Types

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

impl ToSql for DateTime<Local>[src]

impl ToSql for Value[src]

impl ToSql for i64[src]

impl ToSql for MacAddress[src]

impl ToSql for SystemTime[src]

impl ToSql for Uuid[src]

impl<T> ToSql for Vec<T> where
    T: ToSql
[src]

impl ToSql for Rect<f64>[src]

impl<T> ToSql for Option<T> where
    T: ToSql
[src]

impl<'a, T> ToSql for &'a T where
    T: ToSql
[src]

impl ToSql for i16[src]

impl ToSql for LineString<f64>[src]

impl ToSql for DateTime<Utc>[src]

impl ToSql for i32[src]

impl ToSql for Vec<u8>[src]

impl ToSql for u32[src]

impl ToSql for String[src]

impl ToSql for NaiveDate[src]

impl<H> ToSql for HashMap<String, Option<String>, H> where
    H: BuildHasher
[src]

impl ToSql for Uuid[src]

impl ToSql for bool[src]

impl ToSql for f32[src]

impl ToSql for IpAddr[src]

impl ToSql for f64[src]

impl ToSql for i8[src]

impl ToSql for NaiveTime[src]

impl ToSql for DateTime<FixedOffset>[src]

impl<'a> ToSql for Cow<'a, str>[src]

impl<'a, T> ToSql for &'a [T] where
    T: ToSql
[src]

impl ToSql for Point<f64>[src]

impl ToSql for BitVec<u32>[src]

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

impl ToSql for NaiveDateTime[src]

Loading content...

Implementors

impl<T> ToSql for Date<T> where
    T: ToSql
[src]

impl<T> ToSql for Timestamp<T> where
    T: ToSql
[src]

impl<T> ToSql for Json<T> where
    T: Serialize + Debug
[src]

Loading content...