ts_sql/from_row.rs
1//! Convert a row to an instance of self.
2
3use postgres::Row;
4
5/// Convert a row to an instance of self.
6pub trait FromRow: Sized {
7 /// Try convert a row to an instance of self.
8 #[track_caller]
9 fn from_row(row: &Row) -> Result<Self, postgres::Error>;
10}
11
12/// Parse a type from a row.
13pub trait ParseFromRow: Sized {
14 /// Parse the row into type `T`.
15 #[track_caller]
16 fn parse<T>(&self) -> Result<T, postgres::Error>
17 where
18 T: FromRow;
19}
20
21impl ParseFromRow for Row {
22 #[track_caller]
23 fn parse<T>(&self) -> Result<T, postgres::Error>
24 where
25 T: FromRow,
26 {
27 T::from_row(self)
28 }
29}