Skip to main content

Encode

Trait Encode 

Source
pub trait Encode<'q, DB>
where DB: Database,
{ // Required method fn encode_by_ref( &self, buf: &mut <DB as Database>::ArgumentBuffer<'q>, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>; // Provided methods fn encode( self, buf: &mut <DB as Database>::ArgumentBuffer<'q>, ) -> Result<IsNull, Box<dyn Error + Sync + Send>> where Self: Sized { ... } fn produces(&self) -> Option<<DB as Database>::TypeInfo> { ... } fn size_hint(&self) -> usize { ... } }
Expand description

Encode a single value to be sent to the database.

Required Methods§

Source

fn encode_by_ref( &self, buf: &mut <DB as Database>::ArgumentBuffer<'q>, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>

Writes the value of self into buf without moving self.

Where possible, make use of encode instead as it can take advantage of re-using memory.

Provided Methods§

Source

fn encode( self, buf: &mut <DB as Database>::ArgumentBuffer<'q>, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>
where Self: Sized,

Writes the value of self into buf in the expected format for the database.

Source

fn produces(&self) -> Option<<DB as Database>::TypeInfo>

Source

fn size_hint(&self) -> usize

Implementations on Foreign Types§

Source§

impl Encode<'_, Postgres> for &str

Source§

fn encode_by_ref( &self, buf: &mut PgArgumentBuffer, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>

Source§

impl Encode<'_, Postgres> for &[u8]

Source§

fn encode_by_ref( &self, buf: &mut PgArgumentBuffer, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>

Source§

impl Encode<'_, Postgres> for Cow<'_, str>

Source§

fn encode_by_ref( &self, buf: &mut PgArgumentBuffer, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>

Source§

impl Encode<'_, Postgres> for bool

Source§

fn encode_by_ref( &self, buf: &mut PgArgumentBuffer, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>

Source§

impl Encode<'_, Postgres> for f32

Source§

fn encode_by_ref( &self, buf: &mut PgArgumentBuffer, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>

Source§

impl Encode<'_, Postgres> for f64

Source§

fn encode_by_ref( &self, buf: &mut PgArgumentBuffer, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>

Source§

impl Encode<'_, Postgres> for i8

Source§

fn encode_by_ref( &self, buf: &mut PgArgumentBuffer, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>

Source§

impl Encode<'_, Postgres> for i16

Source§

fn encode_by_ref( &self, buf: &mut PgArgumentBuffer, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>

Source§

impl Encode<'_, Postgres> for i32

Source§

fn encode_by_ref( &self, buf: &mut PgArgumentBuffer, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>

Source§

impl Encode<'_, Postgres> for i64

Source§

fn encode_by_ref( &self, buf: &mut PgArgumentBuffer, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>

Source§

impl Encode<'_, Postgres> for Box<str>

Source§

fn encode_by_ref( &self, buf: &mut PgArgumentBuffer, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>

Source§

impl Encode<'_, Postgres> for Box<[u8]>

Source§

fn encode_by_ref( &self, buf: &mut PgArgumentBuffer, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>

Source§

impl Encode<'_, Postgres> for String

Source§

fn encode_by_ref( &self, buf: &mut PgArgumentBuffer, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>

Source§

impl Encode<'_, Postgres> for Vec<u8>

Source§

fn encode_by_ref( &self, buf: &mut PgArgumentBuffer, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>

Source§

impl Encode<'_, Postgres> for Duration

Source§

fn encode_by_ref( &self, buf: &mut PgArgumentBuffer, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>

Source§

fn size_hint(&self) -> usize

Source§

impl Encode<'_, Postgres> for TimeDelta

Available on crate feature chrono only.
Source§

fn encode_by_ref( &self, buf: &mut PgArgumentBuffer, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>

Source§

fn size_hint(&self) -> usize

Source§

impl Encode<'_, Postgres> for Duration

Available on crate feature time only.
Source§

fn encode_by_ref( &self, buf: &mut PgArgumentBuffer, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>

Source§

fn size_hint(&self) -> usize

Source§

impl<'q, DB> Encode<'q, DB> for NonZero<i8>
where DB: Database, i8: Encode<'q, DB>,

Source§

fn encode_by_ref( &self, buf: &mut <DB as Database>::ArgumentBuffer<'q>, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>

Source§

fn encode( self, buf: &mut <DB as Database>::ArgumentBuffer<'q>, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>
where NonZero<i8>: Sized,

Source§

fn produces(&self) -> Option<<DB as Database>::TypeInfo>

Source§

impl<'q, DB> Encode<'q, DB> for NonZero<i16>
where DB: Database, i16: Encode<'q, DB>,

Source§

fn encode_by_ref( &self, buf: &mut <DB as Database>::ArgumentBuffer<'q>, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>

Source§

fn encode( self, buf: &mut <DB as Database>::ArgumentBuffer<'q>, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>
where NonZero<i16>: Sized,

Source§

fn produces(&self) -> Option<<DB as Database>::TypeInfo>

Source§

impl<'q, DB> Encode<'q, DB> for NonZero<i32>
where DB: Database, i32: Encode<'q, DB>,

Source§

fn encode_by_ref( &self, buf: &mut <DB as Database>::ArgumentBuffer<'q>, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>

Source§

fn encode( self, buf: &mut <DB as Database>::ArgumentBuffer<'q>, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>
where NonZero<i32>: Sized,

Source§

fn produces(&self) -> Option<<DB as Database>::TypeInfo>

Source§

impl<'q, DB> Encode<'q, DB> for NonZero<i64>
where DB: Database, i64: Encode<'q, DB>,

Source§

fn encode_by_ref( &self, buf: &mut <DB as Database>::ArgumentBuffer<'q>, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>

Source§

fn encode( self, buf: &mut <DB as Database>::ArgumentBuffer<'q>, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>
where NonZero<i64>: Sized,

Source§

fn produces(&self) -> Option<<DB as Database>::TypeInfo>

Source§

impl<'q, DB> Encode<'q, DB> for NonZero<u8>
where DB: Database, u8: Encode<'q, DB>,

Source§

fn encode_by_ref( &self, buf: &mut <DB as Database>::ArgumentBuffer<'q>, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>

Source§

fn encode( self, buf: &mut <DB as Database>::ArgumentBuffer<'q>, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>
where NonZero<u8>: Sized,

Source§

fn produces(&self) -> Option<<DB as Database>::TypeInfo>

Source§

impl<'q, DB> Encode<'q, DB> for NonZero<u16>
where DB: Database, u16: Encode<'q, DB>,

Source§

fn encode_by_ref( &self, buf: &mut <DB as Database>::ArgumentBuffer<'q>, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>

Source§

fn encode( self, buf: &mut <DB as Database>::ArgumentBuffer<'q>, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>
where NonZero<u16>: Sized,

Source§

fn produces(&self) -> Option<<DB as Database>::TypeInfo>

Source§

impl<'q, DB> Encode<'q, DB> for NonZero<u32>
where DB: Database, u32: Encode<'q, DB>,

Source§

fn encode_by_ref( &self, buf: &mut <DB as Database>::ArgumentBuffer<'q>, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>

Source§

fn encode( self, buf: &mut <DB as Database>::ArgumentBuffer<'q>, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>
where NonZero<u32>: Sized,

Source§

fn produces(&self) -> Option<<DB as Database>::TypeInfo>

Source§

impl<'q, DB> Encode<'q, DB> for NonZero<u64>
where DB: Database, u64: Encode<'q, DB>,

Source§

fn encode_by_ref( &self, buf: &mut <DB as Database>::ArgumentBuffer<'q>, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>

Source§

fn encode( self, buf: &mut <DB as Database>::ArgumentBuffer<'q>, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>
where NonZero<u64>: Sized,

Source§

fn produces(&self) -> Option<<DB as Database>::TypeInfo>

Source§

impl<'q, T> Encode<'q, Postgres> for &[T]
where T: Encode<'q, Postgres> + Type<Postgres>,

Source§

fn encode_by_ref( &self, buf: &mut PgArgumentBuffer, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>

Source§

impl<'q, T> Encode<'q, Postgres> for Option<T>
where T: Encode<'q, Postgres> + Type<Postgres> + 'q,

Source§

fn produces(&self) -> Option<<Postgres as Database>::TypeInfo>

Source§

fn encode( self, buf: &mut <Postgres as Database>::ArgumentBuffer<'q>, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>

Source§

fn encode_by_ref( &self, buf: &mut <Postgres as Database>::ArgumentBuffer<'q>, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>

Source§

fn size_hint(&self) -> usize

Source§

impl<'q, T> Encode<'q, Postgres> for Vec<T>
where &'a [T]: for<'a> Encode<'q, Postgres>, T: Encode<'q, Postgres>,

Source§

fn encode_by_ref( &self, buf: &mut PgArgumentBuffer, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>

Source§

impl<'q, T, DB> Encode<'q, DB> for &T
where DB: Database, T: Encode<'q, DB>,

Source§

fn encode( self, buf: &mut <DB as Database>::ArgumentBuffer<'q>, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>

Source§

fn encode_by_ref( &self, buf: &mut <DB as Database>::ArgumentBuffer<'q>, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>

Source§

fn produces(&self) -> Option<<DB as Database>::TypeInfo>

Source§

fn size_hint(&self) -> usize

Source§

impl<'q, T, const N: usize> Encode<'q, Postgres> for [T; N]
where &'a [T]: for<'a> Encode<'q, Postgres>, T: Encode<'q, Postgres>,

Source§

fn encode_by_ref( &self, buf: &mut PgArgumentBuffer, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>

Source§

impl<const N: usize> Encode<'_, Postgres> for [u8; N]

Source§

fn encode_by_ref( &self, buf: &mut PgArgumentBuffer, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>

Implementors§

Source§

impl Encode<'_, Postgres> for BigDecimal

§Note: BigDecimal Has a Larger Range than NUMERIC

BigDecimal can represent values with a far, far greater range than the NUMERIC type in Postgres can.

NUMERIC is limited to 131,072 digits before the decimal point, and 16,384 digits after it. See Section 8.1, Numeric Types of the Postgres manual for details.

Meanwhile, BigDecimal can theoretically represent a value with an arbitrary number of decimal digits, albeit with a maximum of 263 significant figures.

Because encoding in the current API design must be infallible, when attempting to encode a BigDecimal that cannot fit in the wire representation of NUMERIC, SQLx may instead encode a sentinel value that falls outside the allowed range but is still representable.

This will cause the query to return a DatabaseError with code 22P03 (invalid_binary_representation) and the error message invalid scale in external "numeric" value (though this may be subject to change).

However, BigDecimal should be able to decode any NUMERIC value except NaN, for which it has no representation.

Source§

impl Encode<'_, Postgres> for NaiveDate

Source§

impl Encode<'_, Postgres> for NaiveDateTime

Source§

impl Encode<'_, Postgres> for Decimal

Source§

impl Encode<'_, Postgres> for NaiveTime

Source§

impl Encode<'_, Postgres> for Date

Source§

impl Encode<'_, Postgres> for PrimitiveDateTime

Source§

impl Encode<'_, Postgres> for OffsetDateTime

Source§

impl Encode<'_, Postgres> for Time

Source§

impl Encode<'_, Postgres> for Uuid

Source§

impl Encode<'_, Postgres> for Oid

Source§

impl Encode<'_, Postgres> for PgCiText

Source§

impl Encode<'_, Postgres> for PgHstore

Source§

impl Encode<'_, Postgres> for PgInterval

Source§

impl Encode<'_, Postgres> for PgLQuery

Source§

impl Encode<'_, Postgres> for PgLTree

Source§

impl Encode<'_, Postgres> for PgMoney

Source§

impl Encode<'_, Postgres> for PgTimeTz

Source§

impl Encode<'_, Postgres> for PgTimeTz<NaiveTime, FixedOffset>

Source§

impl<'q> Encode<'q, Postgres> for PgCube

Source§

impl<'q> Encode<'q, Postgres> for PgBox

Source§

impl<'q> Encode<'q, Postgres> for PgCircle

Source§

impl<'q> Encode<'q, Postgres> for PgLSeg

Source§

impl<'q> Encode<'q, Postgres> for PgLine

Source§

impl<'q> Encode<'q, Postgres> for PgPath

Source§

impl<'q> Encode<'q, Postgres> for PgPoint

Source§

impl<'q> Encode<'q, Postgres> for PgPolygon

Source§

impl<'q, DB> Encode<'q, DB> for Value
where Json<&'a Value>: for<'a> Encode<'q, DB>, DB: Database,

Source§

impl<'q, T> Encode<'q, Postgres> for PgRange<T>
where T: Encode<'q, Postgres>,

Source§

impl<'q, T> Encode<'q, Postgres> for Json<T>
where T: Serialize,

Source§

impl<'q, T> Encode<'q, Postgres> for Text<T>
where T: Display,

Source§

impl<Tz> Encode<'_, Postgres> for DateTime<Tz>
where Tz: TimeZone,