Thanks to visit codestin.com
Credit goes to github.com

Skip to content

arafat877/ydb-rs-sdk

 
 

Repository files navigation

Rust YDB SDK

Latest Version Released API docs YDB tests

Rust SDK for YDB. Supported rust: 1.56.0 and newer.

Integration tests, with dependency from real YDB database marked as ignored. To run it:

  1. Set YDB_CONNECTION_STRING env
  2. run cargo test -- --include-ignored

Example

use ydb::{ClientBuilder, Query, StaticToken, YdbResult};

#[tokio::main]
async fn main() -> YdbResult<()> {

 // create the driver
 let client = ClientBuilder::from_str("grpc://localhost:2136?database=local")?
    .with_credentials(StaticToken::from("asd"))
    .client()?;

 // wait until the background initialization of the driver finishes
 client.wait().await?;

 // read the query result
 let sum: i32 = client
    .table_client() // create table client
    .retry_transaction(|mut t| async move {
        // the code in transaction can retry a few times if there was a retriable error

        // send the query to the database
        let res = t.query(Query::from("SELECT 1 + 1 AS sum")).await?;

        // read exactly one result from the db
        let field_val: i32 = res.into_only_row()?.remove_field_by_name("sum")?.try_into()?;

        // return result
        return Ok(field_val);
    })
    .await?;

 // this will print "sum: 2"
 println!("sum: {}", sum);
    return Ok(());
}

More examples

Url shorneter application

Many small examples

About

No description, website, or topics provided.

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Rust 99.0%
  • Other 1.0%