This crate provides Sqlx integration for ydb-rs-sdk. It is in under active development.
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
let connection_string = env::var("YDB_CONNECTION_STRING")?;
let pool = YdbPoolOptions::new().connect(&connection_string).await?;
let row: (i32,) = sqlx::query_as("SELECT 1+1").fetch_one(&pool).await?;
assert_eq!(row.0, 2);
Ok(())
}
#[derive(sqlx::FromRow)]
struct UserInfo {
id: u64,
name: String,
age: u32,
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
let connection_string = env::var("YDB_CONNECTION_STRING")?;
let pool = YdbPoolOptions::new().connect(&connection_string).await?;
let users: Vec<UserInfo> =
sqlx::query_as("SELECT * FROM test2 WHERE age > $age AND age < $arg_1")
.bind(with_name("age", 30))
.bind(40)
.fetch_all(&pool)
.await?;
assert!(users.len() > 0);
Ok(())
}
There are two binding available:
- default unnamed - with generated name like
$arg_1
- named by
with_name
function. you can specify name starting with or without$, but in query you should use $ -started name.
Ydb requires that every query params should be declared with DECLARE
clause like this:
DECLARE $age AS Uint32;
SELECT * FROM test2 WHERE age > $age;
The library is do it for you. You specify only query and bind params to it with bind
function.
- Connect to ydb
- Default credentials (using fromEnv)
- Custom credentials with options
- Basic query
- Binding parameters
- Support types
- Numeric
- Bool
- Int8
- Int16
- Int32
- Int64
- Uint8
- Uint16
- Uint32
- Uint64
- Float
- Double
- Decimal
- String types
- String
- Utf8
- Json
- JsonDocument
- Yson
- Uuid
- Date and time
- Date
- Datetime
- Timestamp
- Interval
- Optional
- Numeric
- Prepared statements
- Transactions
- Compile-type checked queries
- Migrations
- Log Statements