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