diff --git a/src/database/mock.rs b/src/database/mock.rs index 207abd7f..da12e858 100644 --- a/src/database/mock.rs +++ b/src/database/mock.rs @@ -203,7 +203,7 @@ impl MockDatabaseTrait for MockDatabase { } impl MockRow { - /// Try to get the values of a [MockRow] and fail gracefully on error + /// Get a value from the [MockRow] pub fn try_get(&self, col: &str) -> Result where T: ValueType, @@ -211,6 +211,7 @@ impl MockRow { T::try_from(self.values.get(col).unwrap().clone()).map_err(|e| DbErr::Type(e.to_string())) } + /// Get a value from the [MockRow] based on the order of column name pub fn try_get_by_index(&self, idx: usize) -> Result where T: ValueType, diff --git a/src/executor/query.rs b/src/executor/query.rs index fb9cec06..5806d203 100644 --- a/src/executor/query.rs +++ b/src/executor/query.rs @@ -53,7 +53,7 @@ impl From for DbErr { // QueryResult // impl QueryResult { - /// Get a Row from a Column + /// Get a value from the query result with prefixed column name pub fn try_get(&self, pre: &str, col: &str) -> Result where T: TryGetable, @@ -61,6 +61,7 @@ impl QueryResult { Ok(T::try_get(self, pre, col)?) } + /// Get a value from the query result based on the order in the select expressions pub fn try_get_by_index(&self, idx: usize) -> Result where T: TryGetable, @@ -68,7 +69,7 @@ impl QueryResult { Ok(T::try_get_by_index(self, idx)?) } - /// Perform query operations on multiple Columns + /// Get a tuple value from the query result with prefixed column name pub fn try_get_many(&self, pre: &str, cols: &[String]) -> Result where T: TryGetableMany, @@ -76,6 +77,7 @@ impl QueryResult { Ok(T::try_get_many(self, pre, cols)?) } + /// Get a tuple value from the query result based on the order in the select expressions pub fn try_get_many_by_index(&self) -> Result where T: TryGetableMany, @@ -1175,13 +1177,13 @@ fn try_get_many_with_slice_len_of(len: usize, cols: &[String]) -> Result<(), Try // TryGetableFromJson // -/// Perform a query on multiple columns +/// An interface to get a JSON from the query result #[cfg(feature = "with-json")] pub trait TryGetableFromJson: Sized where for<'de> Self: serde::Deserialize<'de>, { - /// Ensure the type implements this method + /// Get a JSON from the query result with prefixed column name #[allow(unused_variables, unreachable_code)] fn try_get_from_json(res: &QueryResult, pre: &str, col: &str) -> Result { let column = format!("{}{}", pre, col); @@ -1223,6 +1225,7 @@ where } } + /// Get a JSON from the query result based on the order in the select expressions fn try_get_from_json_by_index(res: &QueryResult, idx: usize) -> Result { match &res.row { #[cfg(feature = "sqlx-mysql")] diff --git a/src/executor/select.rs b/src/executor/select.rs index df24e938..bcb5cb22 100644 --- a/src/executor/select.rs +++ b/src/executor/select.rs @@ -41,7 +41,7 @@ pub trait SelectorTrait { fn from_raw_query_result(res: QueryResult) -> Result; } -/// Perform an operation on an entity that can yield a Value +/// Get tuple from query result based on a list of column identifiers #[derive(Debug)] pub struct SelectGetableValue where @@ -52,6 +52,7 @@ where model: PhantomData, } +/// Get tuple from query result based on column index #[derive(Debug)] pub struct SelectGetableTuple where @@ -535,6 +536,7 @@ where } } + /// Get tuple from query result based on column index pub fn into_tuple(query: SelectStatement) -> Selector> where T: TryGetableMany,