use std::future::IntoFuture;
use xitca_postgres::{Execute, Postgres, iter::AsyncLendingIterator};
use xitca_postgres_codegen::sql;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
let (cli, drv) = Postgres::new("postgres://postgres:postgres@localhost:5432")
.connect()
.await?;
tokio::spawn(drv.into_future());
std::path::Path::new("./samples/test.sql").execute(&cli).await?;
let mut stream = sql!("SELECT * FROM foo WHERE id = $1 AND name = $2", &1i32, &"alice")
.query(&cli)
.await?;
let row = stream.try_next().await?.ok_or("row not found")?;
assert_eq!(row.get::<&str>("name"), "alice");
Ok(())
}