use inline_postgres as pg; use inline_postgres::prelude::*; #[tokio::main] async fn main() -> Result<(), pg::Error> { let (client, connection) = pg::connect("host=localhost user=postgres", pg::NoTls).await?; // wait for the connection tokio::spawn(async move { if let Err(e) = connection.await { eprintln!("connection error: {}", e); } }); client.exec(stmt!{ CREATE TABLE KID ( NAME VARCHAR(10), AGE INT4 ) }).await?; client.exec(stmt!{ INSERT INTO KID (NAME, AGE) VALUES ("Aang", 12), ("Sokka", 14), ("Toph", 12), ("Zuko", 16) }).await?; let actual_age = 112; client.exec(stmt!{ UPDATE KID SET AGE = {actual_age} WHERE NAME = "Aang" }).await?; let ages = client.fetch(sql! { SELECT SUM(AGE) as [sum: i64] FROM KID }).await?; println!("{}", ages[0].sum); client.exec(stmt! { DROP TABLE KID }).await?; Ok(()) }