use crate::{
database_builder::DatabaseBuilder, error::Error, transaction_builder::TransactionBuilder,
};
#[derive(Debug)]
pub struct Database {
database: idb::Database,
}
impl Database {
pub(crate) fn new(database: idb::Database) -> Self {
Self { database }
}
pub fn builder(name: &str) -> DatabaseBuilder {
DatabaseBuilder::new(name)
}
pub fn name(&self) -> String {
self.database.name()
}
pub fn version(&self) -> Result<u32, Error> {
self.database.version().map_err(Into::into)
}
pub fn transaction(&self) -> TransactionBuilder {
TransactionBuilder::new(self)
}
pub fn close(&self) {
self.database.close();
}
pub async fn delete(name: &str) -> Result<(), Error> {
idb::Factory::new()?.delete(name)?.await.map_err(Into::into)
}
pub(crate) fn as_idb_database(&self) -> &idb::Database {
&self.database
}
}