1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2024-11-22 21:39:21 +00:00

Can get a database instance

This commit is contained in:
Pierre HUBERT 2020-05-21 09:36:10 +02:00
parent bc91caeba4
commit cf7bf3e14f

View File

@ -1,8 +1,10 @@
use std::error::Error; use std::error::Error;
use std::sync::{Mutex, Arc}; use std::sync::{Arc, Mutex};
use crate::data::config::DatabaseConfig;
use mysql::Pool; use mysql::Pool;
use crate::data::config::DatabaseConfig;
/// Database access helper /// Database access helper
/// ///
/// @author Pierre Hubert /// @author Pierre Hubert
@ -26,3 +28,15 @@ pub fn connect(conf: &DatabaseConfig) -> Result<(), Box<dyn Error>> {
Ok(()) Ok(())
} }
/// Get a connection to the database
pub fn get_connection() -> Result<mysql::PooledConn, Box<dyn Error>> {
let pool: Pool;
unsafe {
let guard = POOL.as_ref().unwrap().lock();
pool = guard.unwrap().clone()
}
Ok(pool.get_conn()?)
}