mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2024-11-26 15:29:21 +00:00
Can get a database instance
This commit is contained in:
parent
bc91caeba4
commit
cf7bf3e14f
@ -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()?)
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user