mirror of
https://github.com/YGGverse/rssto.git
synced 2026-04-01 17:45:30 +00:00
optimize db api
This commit is contained in:
parent
f48e256fad
commit
ee083dfc45
11 changed files with 215 additions and 192 deletions
|
|
@ -1,13 +1,36 @@
|
|||
#[cfg(feature = "pollable")]
|
||||
pub mod pollable;
|
||||
|
||||
mod connection;
|
||||
pub mod table;
|
||||
#[cfg(feature = "transaction")]
|
||||
mod transaction;
|
||||
|
||||
#[cfg(feature = "transactional")]
|
||||
pub mod transactional;
|
||||
pub use connection::Connection;
|
||||
#[cfg(feature = "transaction")]
|
||||
pub use transaction::Transaction;
|
||||
pub struct Database {
|
||||
pool: mysql::Pool,
|
||||
}
|
||||
|
||||
#[cfg(feature = "pollable")]
|
||||
pub use pollable::Pollable;
|
||||
impl Database {
|
||||
pub fn pool(
|
||||
host: &str,
|
||||
port: u16,
|
||||
user: &str,
|
||||
password: &str,
|
||||
database: &str,
|
||||
) -> Result<Self, mysql::Error> {
|
||||
Ok(Self {
|
||||
pool: mysql::Pool::new(
|
||||
format!("mysql://{user}:{password}@{host}:{port}/{database}").as_str(),
|
||||
)?,
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(feature = "transactional")]
|
||||
pub use transactional::Transactional;
|
||||
pub fn connection(&self) -> Result<Connection, mysql::Error> {
|
||||
Connection::create(&self.pool)
|
||||
}
|
||||
|
||||
#[cfg(feature = "transaction")]
|
||||
pub fn transaction(&self) -> Result<Transaction, mysql::Error> {
|
||||
Transaction::create(&self.pool)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue