use crate::connection::LibSqlConnection;
use diesel::connection::SimpleConnection;
use diesel::Connection;
pub struct LibSqlConnectionManager {
database_url: String,
}
impl LibSqlConnectionManager {
pub fn new(database_url: impl Into<String>) -> Self {
Self {
database_url: database_url.into(),
}
}
}
impl r2d2::ManageConnection for LibSqlConnectionManager {
type Connection = LibSqlConnection;
type Error = diesel::ConnectionError;
fn connect(&self) -> Result<LibSqlConnection, Self::Error> {
LibSqlConnection::establish(&self.database_url)
}
fn is_valid(&self, conn: &mut LibSqlConnection) -> Result<(), Self::Error> {
conn.batch_execute("SELECT 1")
.map_err(|e| diesel::ConnectionError::BadConnection(e.to_string()))
}
fn has_broken(&self, _conn: &mut LibSqlConnection) -> bool {
false
}
}