Added str/string variation to add table.
This commit is contained in:
parent
07fc00fa93
commit
15ee9f7fa9
@ -16,12 +16,16 @@ impl MoreThanText {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn new_table(&self, name: &str) -> Result<Table, MTTError> {
|
pub async fn new_table<S>(&self, tname: S) -> Result<Table, MTTError>
|
||||||
|
where
|
||||||
|
S: Into<String>,
|
||||||
|
{
|
||||||
let mut tables = self.tables.write().await;
|
let mut tables = self.tables.write().await;
|
||||||
match tables.get(name) {
|
let name = tname.into();
|
||||||
|
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.to_string(), Table::new().await);
|
tables.insert(name, Table::new().await);
|
||||||
Ok(Table::new().await)
|
Ok(Table::new().await)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -41,11 +45,17 @@ mod database {
|
|||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#[async_std::test]
|
#[async_std::test]
|
||||||
async fn create_table() {
|
async fn create_table_with_str() {
|
||||||
let db = MoreThanText::new().await;
|
let db = MoreThanText::new().await;
|
||||||
db.new_table("william").await.unwrap();
|
db.new_table("william").await.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[async_std::test]
|
||||||
|
async fn create_table_with_string() {
|
||||||
|
let db = MoreThanText::new().await;
|
||||||
|
db.new_table("marvin".to_string()).await.unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
#[async_std::test]
|
#[async_std::test]
|
||||||
async fn table_names_are_unique() -> Result<(), String> {
|
async fn table_names_are_unique() -> Result<(), String> {
|
||||||
let db = MoreThanText::new().await;
|
let db = MoreThanText::new().await;
|
||||||
|
Loading…
Reference in New Issue
Block a user