-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathconn.rs
More file actions
30 lines (22 loc) · 814 Bytes
/
conn.rs
File metadata and controls
30 lines (22 loc) · 814 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/*
cargo run -p clickhouse-demo-postgres-client --bin clickhouse-demo-postgres-client-conn postgres://default:[email protected]:9005
*/
use std::env;
use clickhouse_postgres_client::{connect, execute, fetch_all};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
run().await
}
async fn run() -> Result<(), Box<dyn std::error::Error>> {
let database_url = env::args().nth(1).unwrap_or_else(|| {
env::var("DATABASE_URL")
.unwrap_or_else(|_| "postgres://default:[email protected]:9005".to_owned())
});
let mut conn = connect(&database_url).await?;
execute("use default", &mut conn).await?;
let rows = fetch_all("show databases", &mut conn).await?;
for row in rows.iter() {
println!("data: {:?}", row.try_get_data());
}
Ok(())
}