-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpool.rs
40 lines (31 loc) · 1.07 KB
/
pool.rs
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
31
32
33
34
35
36
37
38
39
40
/*
cargo run -p clickhouse-demo-postgres-client --bin clickhouse-demo-postgres-client-pool postgres://default:xxx@127.0.0.1:9005
*/
use std::env;
use clickhouse_postgres_client::{
execute, fetch_all, ClickhousePgConnectOptions, ClickhousePgPoolOptions,
};
#[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:xxx@127.0.0.1:9005".to_owned())
});
let pool = ClickhousePgPoolOptions::new()
.max_connections(1)
.connect_lazy_with(
database_url
.parse::<ClickhousePgConnectOptions>()?
.into_inner(),
);
let mut pool_conn = pool.acquire().await?;
execute("use default", &mut pool_conn).await?;
let rows = fetch_all("show databases", &mut pool_conn).await?;
for row in rows.iter() {
println!("data: {:?}", row.try_get_data());
}
Ok(())
}