Skip to main content

statement/
statement.rs

1// Copyright 2024 ScopeDB, Inc.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15mod common;
16
17#[tokio::main(flavor = "current_thread")]
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}