diff --git a/src/morethantext/mod.rs b/src/morethantext/mod.rs
index eca7685..cb335a4 100644
--- a/src/morethantext/mod.rs
+++ b/src/morethantext/mod.rs
@@ -25,13 +25,23 @@ impl MoreThanText {
match tables.get(&name) {
Some(_) => Err(MTTError::new(format!("table {} already exists", name))),
None => {
- tables.insert(name, Table::new().await);
- Ok(Table::new().await)
+ let table = Table::new().await;
+ tables.insert(name, table.clone());
+ Ok(table)
}
}
}
+
+ pub async fn get_table(&self, name: &str) -> Option
{
+ let tables = self.tables.read().await;
+ match tables.get(name) {
+ Some(tbl) => Some(tbl.clone()),
+ None => None,
+ }
+ }
}
+#[derive(Clone)]
pub struct Table;
impl Table {
@@ -77,6 +87,22 @@ mod database {
}
}
}
+
+ #[async_std::test]
+ async fn get_non_existant_table() {
+ let db = MoreThanText::new().await;
+ let table = db.get_table("missing").await;
+ assert!(table.is_none(), "There should be no table.");
+ }
+
+ #[async_std::test]
+ async fn get_a_table() {
+ let db = MoreThanText::new().await;
+ let name = "here";
+ db.new_table(name).await.unwrap();
+ let table = db.get_table(name).await;
+ assert!(table.is_some(), "Table should be found.");
+ }
}
#[cfg(test)]