1 use tokio_postgres::{Error, NoTls};
2
3 #[tokio::main]
4 async fn main() -> Result<(), Error> {
5 println!("Hello, GresIQ client!");
6
7 // Connect to the database.
8 let (client, connection) =
9 tokio_postgres::connect("host=localhost user=postgres", NoTls).await?;
10
11 // The connection object performs the actual communication with the database,
12 // so spawn it off to run on its own.
13 tokio::spawn(async move {
14 if let Err(e) = connection.await {
15 eprintln!("connection error: {}", e);
16 }
17 });
18
19 // Now we can execute a simple statement that just returns its parameter.
20 let rows = client.query("SELECT $1::TEXT", &[&"hello world"]).await?;
21
22 // And then check that we got back the same string we sent over.
23 let value: &str = rows[0].get(0);
24 assert_eq!(value, "hello world");
25
26 Ok(())
27 }