pub struct StatementHandle { /* private fields */ }Expand description
Tracks one submitted query. Keep the handle to inspect progress, wait for results, or request cancellation.
| Operation | Method |
|---|---|
| Read the last observed status without a request | Self::snapshot |
| Fetch the current status | Self::refresh |
| Wait for results | Self::wait |
| Request cancellation | Self::cancel |
Dropping a wait or refresh future stops local waiting without cancelling execution. Terminal statuses are cached, so waiting again returns the result without another request. Retry temporary read failures on this handle rather than submitting another query.
Implementations§
Source§impl StatementHandle
impl StatementHandle
Sourcepub fn statement_id(&self) -> Uuid
pub fn statement_id(&self) -> Uuid
Examples found in repository?
18async fn main() -> Result<(), Box<dyn std::error::Error>> {
19 let client = common::client()?;
20
21 let result = client.query("SELECT 1 AS ready").await?;
22 let rows = result.into_objects()?;
23 println!("rows: {rows:?}");
24
25 // Keep the handle when an application needs progress, cancellation, or a
26 // durable statement ID before waiting for the result.
27 let mut handle = client.statement("SELECT 2 AS value").submit().await?;
28 let statement_id = handle.statement_id();
29 println!(
30 "statement {statement_id} submitted: {:?}",
31 handle.snapshot()
32 );
33 let status = handle.refresh().await?;
34 println!("statement {statement_id}: {status:?}");
35 let result = handle.wait().await?;
36 println!("handle rows: {:?}", result.into_objects()?);
37 Ok(())
38}Sourcepub fn snapshot(&self) -> Option<&StatementStatus>
pub fn snapshot(&self) -> Option<&StatementStatus>
Returns the status snapshot received by the most recent request without making a network request.
Examples found in repository?
18async fn main() -> Result<(), Box<dyn std::error::Error>> {
19 let client = common::client()?;
20
21 let result = client.query("SELECT 1 AS ready").await?;
22 let rows = result.into_objects()?;
23 println!("rows: {rows:?}");
24
25 // Keep the handle when an application needs progress, cancellation, or a
26 // durable statement ID before waiting for the result.
27 let mut handle = client.statement("SELECT 2 AS value").submit().await?;
28 let statement_id = handle.statement_id();
29 println!(
30 "statement {statement_id} submitted: {:?}",
31 handle.snapshot()
32 );
33 let status = handle.refresh().await?;
34 println!("statement {statement_id}: {status:?}");
35 let result = handle.wait().await?;
36 println!("handle rows: {:?}", result.into_objects()?);
37 Ok(())
38}Sourcepub async fn refresh(&mut self) -> Result<&StatementStatus, Error>
pub async fn refresh(&mut self) -> Result<&StatementStatus, Error>
Fetches a status snapshot, or returns the cached terminal state. Requests on a handle are serialized through its mutable borrow.
Examples found in repository?
18async fn main() -> Result<(), Box<dyn std::error::Error>> {
19 let client = common::client()?;
20
21 let result = client.query("SELECT 1 AS ready").await?;
22 let rows = result.into_objects()?;
23 println!("rows: {rows:?}");
24
25 // Keep the handle when an application needs progress, cancellation, or a
26 // durable statement ID before waiting for the result.
27 let mut handle = client.statement("SELECT 2 AS value").submit().await?;
28 let statement_id = handle.statement_id();
29 println!(
30 "statement {statement_id} submitted: {:?}",
31 handle.snapshot()
32 );
33 let status = handle.refresh().await?;
34 println!("statement {statement_id}: {status:?}");
35 let result = handle.wait().await?;
36 println!("handle rows: {:?}", result.into_objects()?);
37 Ok(())
38}Sourcepub async fn wait(&mut self) -> Result<ResultSet, Error>
pub async fn wait(&mut self) -> Result<ResultSet, Error>
Waits for the statement to terminate and returns its result set. Dropping this future leaves the handle and server execution available.
Examples found in repository?
18async fn main() -> Result<(), Box<dyn std::error::Error>> {
19 let client = common::client()?;
20
21 let result = client.query("SELECT 1 AS ready").await?;
22 let rows = result.into_objects()?;
23 println!("rows: {rows:?}");
24
25 // Keep the handle when an application needs progress, cancellation, or a
26 // durable statement ID before waiting for the result.
27 let mut handle = client.statement("SELECT 2 AS value").submit().await?;
28 let statement_id = handle.statement_id();
29 println!(
30 "statement {statement_id} submitted: {:?}",
31 handle.snapshot()
32 );
33 let status = handle.refresh().await?;
34 println!("statement {statement_id}: {status:?}");
35 let result = handle.wait().await?;
36 println!("handle rows: {:?}", result.into_objects()?);
37 Ok(())
38}Sourcepub async fn cancel(&mut self) -> Result<StatementStatus, Error>
pub async fn cancel(&mut self) -> Result<StatementStatus, Error>
Requests cancellation and caches the observed status. Pending or Running means cancellation has not yet been observed; call wait() to settle it. A completion race returns the full result or original execution failure.