mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2024-11-22 13: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::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<dyn Error>> {
|
||||
}
|
||||
|
||||
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