This commit is contained in:
Dominik Werder
2021-04-27 11:41:33 +02:00
parent bd9c231310
commit 0b40702b6c
12 changed files with 170 additions and 46 deletions

26
dbconn/src/lib.rs Normal file
View File

@@ -0,0 +1,26 @@
use err::Error;
use netpod::log::*;
use netpod::{Channel, NodeConfig};
use std::sync::Arc;
use tokio_postgres::NoTls;
pub async fn channel_exists(channel: &Channel, node_config: Arc<NodeConfig>) -> Result<bool, Error> {
let d = &node_config.cluster.database;
let uri = format!("postgresql://{}:{}@{}:{}/{}", d.user, d.pass, d.host, 5432, d.name);
let (cl, conn) = tokio_postgres::connect(&uri, NoTls).await?;
let cjh = tokio::spawn(async move {
if let Err(e) = conn.await {
error!("connection error: {}", e);
}
Ok::<_, Error>(())
});
let rows = cl
.query("select rowid from channels where name = $1::text", &[&channel.name])
.await?;
info!("channel_exists {} rows", rows.len());
for row in rows {
info!(" db on channel search: {:?}", row);
}
drop(cjh);
Ok(true)
}