Can retrieve a table now.

This commit is contained in:
Jeff Baskin 2022-08-07 09:29:08 -04:00
parent 15ee9f7fa9
commit 07baa7bbec

View File

@ -25,13 +25,23 @@ impl MoreThanText {
match tables.get(&name) { match tables.get(&name) {
Some(_) => Err(MTTError::new(format!("table {} already exists", name))), Some(_) => Err(MTTError::new(format!("table {} already exists", name))),
None => { None => {
tables.insert(name, Table::new().await); let table = Table::new().await;
Ok(Table::new().await) tables.insert(name, table.clone());
} Ok(table)
} }
} }
} }
pub async fn get_table(&self, name: &str) -> Option<Table> {
let tables = self.tables.read().await;
match tables.get(name) {
Some(tbl) => Some(tbl.clone()),
None => None,
}
}
}
#[derive(Clone)]
pub struct Table; pub struct Table;
impl 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)] #[cfg(test)]