diff --git a/sqlx-core/src/row.rs b/sqlx-core/src/row.rs index 4d2860bc..62cd76db 100644 --- a/sqlx-core/src/row.rs +++ b/sqlx-core/src/row.rs @@ -103,6 +103,19 @@ where self.try_get::(index).unwrap() } + /// Index into the database row and decode a single value. + /// + /// See [`try_get_unchecked`](#method.try_get_unchecked). + #[inline] + fn get_unchecked(&self, index: I) -> T + where + T: Type, + I: ColumnIndex<'c, Self>, + T: Decode<'c, Self::Database>, + { + self.try_get_unchecked::(index).unwrap() + } + /// Index into the database row and decode a single value. /// /// A string index can be used to access a column by name and a `usize` index @@ -126,7 +139,6 @@ where /// [`Decode`]: crate::Error::Decode /// [`ColumnNotFound`]: crate::Error::ColumnNotFound /// [`ColumnIndexOutOfBounds`]: crate::Error::ColumnIndexOutOfBounds - #[inline] fn try_get(&self, index: I) -> crate::Result where T: Type, @@ -150,6 +162,22 @@ where T::decode(value) } + /// Index into the database row and decode a single value. + /// + /// Unlike [`try_get`](#method.try_get), this method does not check that the type + /// being returned from the database is compatible with the Rust type and just blindly tries + /// to decode the value. An example of where this could be useful is decoding a Postgres + /// enumeration as a Rust string (instead of deriving a new Rust enum). + #[inline] + fn try_get_unchecked(&self, index: I) -> crate::Result + where + T: Type, + I: ColumnIndex<'c, Self>, + T: Decode<'c, Self::Database>, + { + self.try_get_raw(index).and_then(T::decode) + } + #[doc(hidden)] fn try_get_raw( &self,