An interface to get a value from the query result
| 35 | |
| 36 | /// An interface to get a value from the query result |
| 37 | pub trait TryGetable: Sized { |
| 38 | /// Get a value from the query result with an ColIdx |
| 39 | fn try_get_by<I: ColIdx>(res: &QueryResult, index: I) -> Result<Self, TryGetError>; |
| 40 | |
| 41 | /// Get a value from the query result with prefixed column name |
| 42 | fn try_get(res: &QueryResult, pre: &str, col: &str) -> Result<Self, TryGetError> { |
| 43 | if pre.is_empty() { |
| 44 | Self::try_get_by(res, col) |
| 45 | } else { |
| 46 | Self::try_get_by(res, format!("{pre}{col}").as_str()) |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | /// Get a value from the query result based on the order in the select expressions |
| 51 | fn try_get_by_index(res: &QueryResult, index: usize) -> Result<Self, TryGetError> { |
| 52 | Self::try_get_by(res, index) |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | impl From<TryGetError> for DbErr { |
| 57 | fn from(e: TryGetError) -> DbErr { |
nothing calls this directly
no outgoing calls
no test coverage detected