-
Notifications
You must be signed in to change notification settings - Fork 4
/
v3_bb8_graph_pool.rs
59 lines (50 loc) · 1.89 KB
/
v3_bb8_graph_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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
cargo run -p nebula-demo-tokio --bin nebula_demo_tokio_v3_bb8_graph_pool 127.0.0.1 9669 root 'password'
*/
use std::env;
use bb8_nebula::{
graph::GraphClientConfiguration, impl_tokio::v3::graph::new_graph_connection_manager,
};
use fbthrift_transport::AsyncTransportConfiguration;
use nebula_client::v3::{GraphQuery as _, GraphTransportResponseHandler};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
run().await
}
async fn run() -> Result<(), Box<dyn std::error::Error>> {
let domain = env::args()
.nth(1)
.unwrap_or_else(|| env::var("DOMAIN").unwrap_or_else(|_| "127.0.0.1".to_owned()));
let port: u16 = env::args()
.nth(2)
.unwrap_or_else(|| env::var("PORT").unwrap_or_else(|_| "9669".to_owned()))
.parse()
.unwrap();
let username = env::args()
.nth(3)
.unwrap_or_else(|| env::var("USERNAME").unwrap_or_else(|_| "root".to_owned()));
let password = env::args()
.nth(4)
.unwrap_or_else(|| env::var("PASSWORD").unwrap_or_else(|_| "password".to_owned()));
let space = env::args().nth(5).or_else(|| env::var("SPACE").ok());
println!("v3_bb8_graph_pool {domain} {port} {username} {password} {space:?}",);
//
let client_configuration =
GraphClientConfiguration::new(domain, port, username, password, space);
let transport_configuration = AsyncTransportConfiguration::new(GraphTransportResponseHandler);
let manager = new_graph_connection_manager(client_configuration, transport_configuration);
let pool = bb8::Pool::builder().max_size(1).build(manager).await?;
//
{
let mut session = pool.get().await?;
let res = session.show_hosts().await?;
println!("{res:?}");
}
//
{
let mut session = pool.get().await?;
let res = session.show_spaces().await?;
println!("{res:?}");
}
Ok(())
}