2020-10-24 13:08:23 +00:00
|
|
|
use crate::db::errors::DataError;
|
|
|
|
use crate::db::variables::Variables;
|
|
|
|
use sled::Db;
|
2020-10-23 20:19:04 +00:00
|
|
|
use std::path::Path;
|
2020-10-15 16:52:08 +00:00
|
|
|
|
2020-10-24 13:08:23 +00:00
|
|
|
pub mod errors;
|
|
|
|
pub mod schema;
|
|
|
|
pub mod variables;
|
2020-10-20 20:54:20 +00:00
|
|
|
|
2020-10-15 16:52:08 +00:00
|
|
|
#[derive(Clone)]
|
|
|
|
pub struct Database {
|
|
|
|
db: Db,
|
2020-10-24 13:08:23 +00:00
|
|
|
pub(crate) variables: Variables,
|
|
|
|
//rooms: Tree,
|
2020-10-20 20:54:20 +00:00
|
|
|
}
|
|
|
|
|
2020-10-15 16:52:08 +00:00
|
|
|
impl Database {
|
2020-10-23 20:19:04 +00:00
|
|
|
pub fn new<P: AsRef<Path>>(path: P) -> Result<Database, DataError> {
|
2020-10-18 15:13:34 +00:00
|
|
|
let db = sled::open(path)?;
|
|
|
|
let variables = db.open_tree("variables")?;
|
2020-10-24 13:08:23 +00:00
|
|
|
//let rooms = db.open_tree("rooms")?;
|
2020-10-18 15:13:34 +00:00
|
|
|
|
|
|
|
Ok(Database {
|
|
|
|
db: db.clone(),
|
2020-10-24 13:08:23 +00:00
|
|
|
variables: Variables(variables),
|
|
|
|
//rooms: rooms,
|
2020-10-18 15:13:34 +00:00
|
|
|
})
|
2020-10-15 16:52:08 +00:00
|
|
|
}
|
|
|
|
}
|