From 2da67487b5d19dfb9469b0e17153a76e3d739a76 Mon Sep 17 00:00:00 2001 From: Jeff Baskin Date: Mon, 31 Oct 2022 10:01:07 -0400 Subject: [PATCH] Got use to return a database. --- .gitignore | 2 +- src/morethantext/mod.rs | 23 +++++++++++++++-------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index 64fb936..1b6dcef 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ /target -*.swp +*.sw* tests/data diff --git a/src/morethantext/mod.rs b/src/morethantext/mod.rs index b86f85e..9f0df21 100644 --- a/src/morethantext/mod.rs +++ b/src/morethantext/mod.rs @@ -28,15 +28,16 @@ impl MoreThanText { } } - async fn use_database(&self, name: &str) -> Result<(), DBError> { + async fn use_database(&self, name: &str) -> Result { let databases = self.databases.read().await; match databases.get(name) { - Some(_) => Ok(()), + Some(db) => Ok(db.clone()), None => Err(DBError::new("database name not found")), } } } +#[derive(Clone)] struct Database; impl Database { @@ -44,12 +45,9 @@ impl Database { Self {} } - async fn add_column(&self, _name: &str) { - } + async fn add_table(&self, _name: &str) {} } - - #[cfg(test)] mod engine_functions { use super::*; @@ -109,6 +107,15 @@ mod engine_functions { } } } + + #[async_std::test] + async fn create_get_table() { + let db = "thedatabase"; + let mtt = MoreThanText::new().await; + mtt.create_database(db).await.unwrap(); + let dbase = mtt.use_database(db).await.unwrap(); + dbase.add_table("melvin").await; + } } #[cfg(test)] @@ -121,8 +128,8 @@ mod database_functions { } #[async_std::test] - async fn new_ccolumn() { + async fn new_table() { let db = Database::new().await; - db.add_column("fred").await; + db.add_table("fred").await; } }