[−]Trait amadeus::prelude::postgres::_internal::types::ToSql
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 type | Postgres type(s) |
---|---|
bool | BOOL |
i8 | "char" |
i16 | SMALLINT, SMALLSERIAL |
i32 | INT, SERIAL |
u32 | OID |
i64 | BIGINT, BIGSERIAL |
f32 | REAL |
f64 | DOUBLE PRECISION |
String | VARCHAR, CHAR(n), TEXT, CITEXT, NAME |
&str | VARCHAR, CHAR(n), TEXT, CITEXT, NAME |
Vec<u8> | BYTEA |
&[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 type | Postgres type(s) |
---|---|
serialize::json::Json | JSON, JSONB |
serde_json::Value | JSON, JSONB |
time::Timespec | TIMESTAMP, TIMESTAMP WITH TIME ZONE |
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 |
uuid::Uuid | UUID |
bit_vec::BitVec | BIT, VARBIT |
eui48::MacAddress | MACADDR |
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-dimentional Postgres arrays with an index offset of
1.
Required methods
fn to_sql(
&self,
ty: &Type,
out: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
&self,
ty: &Type,
out: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
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 Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
&self,
ty: &Type,
out: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
An adaptor method used internally by Rust-Postgres.
All implementations of this method should be generated by the
to_sql_checked!()
macro.
Implementations on Foreign Types
impl ToSql for DateTime<Local>
fn to_sql(
&self,
type_: &Type,
w: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
&self,
type_: &Type,
w: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
fn accepts(ty: &Type) -> bool
fn to_sql_checked(
&self,
ty: &Type,
out: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
&self,
ty: &Type,
out: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
impl<'a, T> ToSql for &'a T where
T: ToSql,
T: ToSql,
fn to_sql(
&self,
ty: &Type,
out: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
&self,
ty: &Type,
out: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
fn accepts(ty: &Type) -> bool
fn to_sql_checked(
&self,
ty: &Type,
out: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
&self,
ty: &Type,
out: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
impl<T> ToSql for Vec<T> where
T: ToSql,
T: ToSql,
fn to_sql(
&self,
ty: &Type,
w: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
&self,
ty: &Type,
w: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
fn accepts(ty: &Type) -> bool
fn to_sql_checked(
&self,
ty: &Type,
out: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
&self,
ty: &Type,
out: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
impl<'a> ToSql for &'a [u8]
fn to_sql(
&self,
&Type,
w: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
&self,
&Type,
w: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
fn accepts(ty: &Type) -> bool
fn to_sql_checked(
&self,
ty: &Type,
out: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
&self,
ty: &Type,
out: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
impl ToSql for HashMap<String, Option<String>, RandomState>
fn to_sql(
&self,
&Type,
w: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
&self,
&Type,
w: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
fn accepts(ty: &Type) -> bool
fn to_sql_checked(
&self,
ty: &Type,
out: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
&self,
ty: &Type,
out: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
impl<'a> ToSql for Cow<'a, str>
fn to_sql(
&self,
ty: &Type,
w: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
&self,
ty: &Type,
w: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
fn accepts(ty: &Type) -> bool
fn to_sql_checked(
&self,
ty: &Type,
out: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
&self,
ty: &Type,
out: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
impl ToSql for String
fn to_sql(
&self,
ty: &Type,
w: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
&self,
ty: &Type,
w: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
fn accepts(ty: &Type) -> bool
fn to_sql_checked(
&self,
ty: &Type,
out: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
&self,
ty: &Type,
out: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
impl ToSql for i16
fn to_sql(
&self,
&Type,
w: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
&self,
&Type,
w: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
fn accepts(ty: &Type) -> bool
fn to_sql_checked(
&self,
ty: &Type,
out: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
&self,
ty: &Type,
out: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
impl ToSql for f32
fn to_sql(
&self,
&Type,
w: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
&self,
&Type,
w: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
fn accepts(ty: &Type) -> bool
fn to_sql_checked(
&self,
ty: &Type,
out: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
&self,
ty: &Type,
out: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
impl ToSql for i32
fn to_sql(
&self,
&Type,
w: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
&self,
&Type,
w: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
fn accepts(ty: &Type) -> bool
fn to_sql_checked(
&self,
ty: &Type,
out: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
&self,
ty: &Type,
out: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
impl ToSql for i64
fn to_sql(
&self,
&Type,
w: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
&self,
&Type,
w: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
fn accepts(ty: &Type) -> bool
fn to_sql_checked(
&self,
ty: &Type,
out: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
&self,
ty: &Type,
out: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
impl ToSql for f64
fn to_sql(
&self,
&Type,
w: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
&self,
&Type,
w: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
fn accepts(ty: &Type) -> bool
fn to_sql_checked(
&self,
ty: &Type,
out: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
&self,
ty: &Type,
out: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
impl<'a, T> ToSql for &'a [T] where
T: ToSql,
T: ToSql,
fn to_sql(
&self,
ty: &Type,
w: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
&self,
ty: &Type,
w: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
fn accepts(ty: &Type) -> bool
fn to_sql_checked(
&self,
ty: &Type,
out: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
&self,
ty: &Type,
out: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
impl ToSql for Vec<u8>
fn to_sql(
&self,
ty: &Type,
w: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
&self,
ty: &Type,
w: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
fn accepts(ty: &Type) -> bool
fn to_sql_checked(
&self,
ty: &Type,
out: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
&self,
ty: &Type,
out: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
impl ToSql for i8
fn to_sql(
&self,
&Type,
w: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
&self,
&Type,
w: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
fn accepts(ty: &Type) -> bool
fn to_sql_checked(
&self,
ty: &Type,
out: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
&self,
ty: &Type,
out: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
impl ToSql for NaiveDate
fn to_sql(
&self,
&Type,
w: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
&self,
&Type,
w: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
fn accepts(ty: &Type) -> bool
fn to_sql_checked(
&self,
ty: &Type,
out: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
&self,
ty: &Type,
out: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
impl ToSql for DateTime<Utc>
fn to_sql(
&self,
type_: &Type,
w: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
&self,
type_: &Type,
w: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
fn accepts(ty: &Type) -> bool
fn to_sql_checked(
&self,
ty: &Type,
out: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
&self,
ty: &Type,
out: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
impl ToSql for NaiveDateTime
fn to_sql(
&self,
&Type,
w: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
&self,
&Type,
w: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
fn accepts(ty: &Type) -> bool
fn to_sql_checked(
&self,
ty: &Type,
out: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
&self,
ty: &Type,
out: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
impl ToSql for bool
fn to_sql(
&self,
&Type,
w: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
&self,
&Type,
w: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
fn accepts(ty: &Type) -> bool
fn to_sql_checked(
&self,
ty: &Type,
out: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
&self,
ty: &Type,
out: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
impl ToSql for NaiveTime
fn to_sql(
&self,
&Type,
w: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
&self,
&Type,
w: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
fn accepts(ty: &Type) -> bool
fn to_sql_checked(
&self,
ty: &Type,
out: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
&self,
ty: &Type,
out: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
impl ToSql for u32
fn to_sql(
&self,
&Type,
w: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
&self,
&Type,
w: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
fn accepts(ty: &Type) -> bool
fn to_sql_checked(
&self,
ty: &Type,
out: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
&self,
ty: &Type,
out: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
impl<T> ToSql for Option<T> where
T: ToSql,
T: ToSql,
fn to_sql(
&self,
ty: &Type,
out: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
&self,
ty: &Type,
out: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
fn accepts(ty: &Type) -> bool
fn to_sql_checked(
&self,
ty: &Type,
out: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
&self,
ty: &Type,
out: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
impl ToSql for DateTime<FixedOffset>
fn to_sql(
&self,
type_: &Type,
w: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
&self,
type_: &Type,
w: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
fn accepts(ty: &Type) -> bool
fn to_sql_checked(
&self,
ty: &Type,
out: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
&self,
ty: &Type,
out: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
impl<'a> ToSql for &'a str
fn to_sql(
&self,
&Type,
w: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
&self,
&Type,
w: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
fn accepts(ty: &Type) -> bool
fn to_sql_checked(
&self,
ty: &Type,
out: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
&self,
ty: &Type,
out: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
Implementors
impl<T> ToSql for Date<T> where
T: ToSql,
T: ToSql,
fn to_sql(
&self,
ty: &Type,
out: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
&self,
ty: &Type,
out: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
fn accepts(ty: &Type) -> bool
fn to_sql_checked(
&self,
ty: &Type,
out: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
&self,
ty: &Type,
out: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + 'static + Send + Sync>>
impl<T> ToSql for Timestamp<T> where
T: ToSql,
T: ToSql,