diff --git a/src/helpers/database.rs b/src/helpers/database.rs index 43124d0..d69fb92 100644 --- a/src/helpers/database.rs +++ b/src/helpers/database.rs @@ -1,8 +1,10 @@ use std::error::Error; -use std::sync::{Mutex, Arc}; -use crate::data::config::DatabaseConfig; +use std::sync::{Arc, Mutex}; + use mysql::Pool; +use crate::data::config::DatabaseConfig; + /// Database access helper /// /// @author Pierre Hubert @@ -25,4 +27,16 @@ pub fn connect(conf: &DatabaseConfig) -> Result<(), Box> { } Ok(()) +} + +/// Get a connection to the database +pub fn get_connection() -> Result> { + let pool: Pool; + + unsafe { + let guard = POOL.as_ref().unwrap().lock(); + pool = guard.unwrap().clone() + } + + Ok(pool.get_conn()?) } \ No newline at end of file