I am using the tiberius
crate for MSSQL Queries in Rust.
use tiberius::{Client, Config, AuthMethod};
use tokio::net::TcpStream;
use tokio_util::compat::TokioAsyncWriteCompatExt;
use anyhow::{ Result, Error };
use std::collections::HashMap;
#[tokio::main]
async fn main() -> Result<(), Error>{
// create connection client and set up connection config
let mut config = Config::new();
config.host("my_server");
config.port(1433);
// use windows trusted authentication to connect
config.authentication(AuthMethod::Integrated);
config.trust_cert();
// create a tcp stream using our configuration
let tcp: TcpStream = TcpStream::connect(config.get_addr()).await?;
tcp.set_nodelay(true)?;
// create a SQL client
let mut client = Client::connect(config, tcp.compat_write()).await?;
let results = client.query("SELECT 'hello' AS foo, 'world' AS bar;", &[])
.await?
.into_results()
.await?;
let mut map: HashMap<String, String> = HashMap::new();
for i in &results[0] {
let foo: String = i.get("foo").unwrap().to_string();
let bar: String = i.get("bar").unwrap().to_string();
map.insert(
foo,
bar,
);
}
Ok(())
}
I am basically running a oneshot query and want to read the values into a HashMap<String, String>
.
I receive the following error in the get()
call:
32 | let foo: String = i.get("foo").unwrap().to_string();
| ^^^ cannot infer type of the type parameter `R` declared on the method `get`
Based on the docs, I am not sure I understand this error.