pub struct ResultSet { /* private fields */ }Expand description
The result of a database query.
This behaves essentially like a set of Rows, and each Row is a set of HdbValues.
In fact, result sets with a larger number of rows are not returned from the database
in a single roundtrip. ResultSet automatically fetches outstanding data
as soon as they are required.
The method try_into converts the data from this generic format
in a singe step into your application specific format.
Due to the chunk-wise data transfer, which has to happen asynchronously,
ResultSet cannot implement the synchronous trait std::iter::Iterator.
Use method next_row() as a replacement.
Implementations§
Source§impl ResultSet
impl ResultSet
Sourcepub async fn try_into<'de, T>(self) -> Result<T, HdbError>where
T: Deserialize<'de>,
pub async fn try_into<'de, T>(self) -> Result<T, HdbError>where
T: Deserialize<'de>,
Conveniently translates the complete result set into a rust type that implements
serde::Deserialize and has an adequate structure.
The implementation of this method uses
serde_db::de.
A result set is essentially a two-dimensional structure, given as a list of rows, where each row is a list of fields; the name of each field is given in the metadata of the result set.
The method supports a variety of target data structures, with the only strong limitation that no data loss is supported.
It depends on the dimension of the result set what target data structure you can choose for deserialization:
-
You can always use a
Vec<line_struct>, if the elements ofline_structmatch the field list of the result set. -
If the result set contains only a single line (e.g. because you specified
TOP 1in your select clause), then you can optionally choose to deserialize directly into a plainline_struct. -
If the result set contains only a single column, then you can optionally choose to deserialize directly into a
Vec<plain_field>. -
If the result set contains only a single value (one row with one column), then you can optionally choose to deserialize into a plain
line_struct, or aVec<plain_field>, or aplain_field.
Also the translation of the individual field values provides flexibility.
-
You can e.g. convert values from a nullable column into a plain field, provided that no NULL values are given in the result set.
-
Vice versa, you can use an
Option<plain_field>, even if the column is marked as NOT NULL. -
Similarly, integer types can differ, as long as the concrete values can be assigned without loss.
As usual with serde deserialization, you need to specify the type of your target variable
explicitly, so that try_into() can derive the type it needs to instantiate:
#[derive(Deserialize)]
struct Entity {
...
}
let typed_result: Vec<Entity> = result_set.try_into()?;§Errors
HdbError::Deserialization if the deserialization into the target type is not possible.
Sourcepub async fn into_single_row(self) -> Result<Row, HdbError>
pub async fn into_single_row(self) -> Result<Row, HdbError>
Converts the result set into a single row.
§Errors
HdbError::Usage if the result set contains more than a single row, or is empty.
Sourcepub async fn into_single_value(self) -> Result<HdbValue<'static>, HdbError>
pub async fn into_single_value(self) -> Result<HdbValue<'static>, HdbError>
Converts the result set into a single value.
§Errors
HdbError::Usage if the result set contains more than a single value, or is empty.
Sourcepub fn metadata(&self) -> Arc<ResultSetMetadata>
pub fn metadata(&self) -> Arc<ResultSetMetadata>
Sourcepub async fn total_number_of_rows(&self) -> Result<usize, HdbError>
pub async fn total_number_of_rows(&self) -> Result<usize, HdbError>
Returns the total number of rows in the result set, including those that still need to be fetched from the database, but excluding those that have already been removed from the result set.
This method can be expensive, and it can fail, since it fetches all yet outstanding rows from the database.
§Errors
Several variants of HdbError are possible.
Sourcepub async fn next_row(&mut self) -> Result<Option<Row>, HdbError>
pub async fn next_row(&mut self) -> Result<Option<Row>, HdbError>
Removes the next row and returns it, or Ok(None) if the ResultSet is empty.
Consequently, the ResultSet has one row less after the call.
May need to fetch further rows from the database, which can fail.
let mut rs = connection.query(query_str).await?;
while let Some(row) = rs.next_row().await? {
let entity: Entity = row.try_into()?;
println!("Got entity: {:?}", entity);
}§Errors
Several variants of HdbError are possible.
Sourcepub async fn fetch_all(&self) -> Result<(), HdbError>
pub async fn fetch_all(&self) -> Result<(), HdbError>
Fetches all not yet transported result lines from the server.
Bigger result sets are typically not transported in one roundtrip from the database; the number of roundtrips depends on the total number of rows in the result set and the configured fetch-size of the connection.
Fetching can fail, e.g. if the network connection is broken.
§Errors
Several variants of HdbError are possible.
Sourcepub async fn server_usage(&self) -> ServerUsage
pub async fn server_usage(&self) -> ServerUsage
Provides information about the the server-side resource consumption that
is related to this ResultSet object.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ResultSet
impl !RefUnwindSafe for ResultSet
impl Send for ResultSet
impl Sync for ResultSet
impl Unpin for ResultSet
impl !UnwindSafe for ResultSet
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoCollection<T> for T
impl<T> IntoCollection<T> for T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();Source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();Source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();Source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi Quirk value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();Source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.Source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);