bronzedb_client/
manager.rs1use super::Connection;
2use bronzedb_util::status::Error;
3use std::net::TcpStream;
4
5pub struct BronzeConnManager {
6 db_addr: String,
7}
8
9impl BronzeConnManager {
10 pub fn new(addr: impl Into<String>) -> Self {
11 Self {
12 db_addr: addr.into(),
13 }
14 }
15}
16
17impl r2d2::ManageConnection for BronzeConnManager {
18 type Connection = Connection<TcpStream>;
19 type Error = Error;
20
21 fn connect(&self) -> Result<Self::Connection, Self::Error> {
22 let stream = TcpStream::connect(&self.db_addr)?;
23 Ok(Self::Connection::new(stream))
24 }
25
26 fn is_valid(&self, conn: &mut Self::Connection) -> Result<(), Self::Error> {
27 conn.ping()
28 }
29
30 fn has_broken(&self, conn: &mut Self::Connection) -> bool {
31 match conn.no_response() {
32 Ok(()) => false,
33 Err(_) => true,
34 }
35 }
36}