MCPcopy Create free account
hub / github.com/SeaQL/sea-orm / try_get

Method try_get

src/database/mock.rs:215–237  ·  view source on GitHub ↗

Get a value from the [MockRow]

(&self, index: I)

Source from the content-addressed store, hash-verified

213impl MockRow {
214 /// Get a value from the [MockRow]
215 pub fn try_get<T, I: crate::ColIdx>(&self, index: I) -> Result<T, DbErr>
216 where
217 T: ValueType,
218 {
219 if let Some(index) = index.as_str() {
220 T::try_from(
221 self.values
222 .get(index)
223 .ok_or_else(|| query_err(format!("No column for ColIdx {index:?}")))?
224 .clone(),
225 )
226 .map_err(type_err)
227 } else if let Some(index) = index.as_usize() {
228 let (_, value) = self
229 .values
230 .iter()
231 .nth(*index)
232 .ok_or_else(|| query_err(format!("Column at index {index} not found")))?;
233 T::try_from(value.clone()).map_err(type_err)
234 } else {
235 unreachable!("Missing ColIdx implementation for MockRow");
236 }
237 }
238
239 /// An iterator over the keys and values of a mock row
240 pub fn into_column_value_tuples(self) -> impl Iterator<Item = (String, Value)> {

Callers 9

mainFunction · 0.45
exec_freshFunction · 0.45
has_columnMethod · 0.45
has_indexMethod · 0.45
has_tableFunction · 0.45

Calls 4

query_errFunction · 0.85
as_usizeMethod · 0.80
as_strMethod · 0.45
getMethod · 0.45

Tested by 2

mainFunction · 0.36